コード例 #1
0
ファイル: FsPermission.cs プロジェクト: orf53975/hadoop.net
 private void Set(FsAction u, FsAction g, FsAction o, bool sb)
 {
     useraction  = u;
     groupaction = g;
     otheraction = o;
     stickyBit   = sb;
 }
コード例 #2
0
ファイル: FsPermission.cs プロジェクト: orf53975/hadoop.net
 /// <summary>Copy constructor</summary>
 /// <param name="other">other permission</param>
 public FsPermission(Org.Apache.Hadoop.FS.Permission.FsPermission other)
 {
     this.useraction  = other.useraction;
     this.groupaction = other.groupaction;
     this.otheraction = other.otheraction;
     this.stickyBit   = other.stickyBit;
 }
コード例 #3
0
        /// <summary>
        /// Ensure that when manually specifying permission modes we get
        /// the expected values back out for all combinations
        /// </summary>
        public virtual void TestConvertingPermissions()
        {
            for (short s = 0; s <= 0x3ff; s++)
            {
                Assert.Equal(s, new FsPermission(s).ToShort());
            }
            short s_1 = 0;

            foreach (bool sb in new bool[] { false, true })
            {
                foreach (FsAction u in FsAction.Values())
                {
                    foreach (FsAction g in FsAction.Values())
                    {
                        foreach (FsAction o in FsAction.Values())
                        {
                            // Cover constructor with sticky bit.
                            FsPermission f = new FsPermission(u, g, o, sb);
                            Assert.Equal(s_1, f.ToShort());
                            FsPermission f2 = new FsPermission(f);
                            Assert.Equal(s_1, f2.ToShort());
                            s_1++;
                        }
                    }
                }
            }
        }
コード例 #4
0
 public virtual void TestFsAction()
 {
     //implies
     foreach (FsAction a in FsAction.Values())
     {
         Assert.True(FsAction.All.Implies(a));
     }
     foreach (FsAction a_1 in FsAction.Values())
     {
         Assert.True(a_1 == FsAction.None ? FsAction.None.Implies(a_1) :
                     !FsAction.None.Implies(a_1));
     }
     foreach (FsAction a_2 in FsAction.Values())
     {
         Assert.True(a_2 == FsAction.ReadExecute || a_2 == FsAction.Read ||
                     a_2 == FsAction.Execute || a_2 == FsAction.None ? FsAction.ReadExecute.Implies
                         (a_2) : !FsAction.ReadExecute.Implies(a_2));
     }
     //masks
     Assert.Equal(FsAction.Execute, FsAction.Execute.And(FsAction.ReadExecute
                                                         ));
     Assert.Equal(FsAction.Read, FsAction.Read.And(FsAction.ReadExecute
                                                   ));
     Assert.Equal(FsAction.None, FsAction.Write.And(FsAction.ReadExecute
                                                    ));
     Assert.Equal(FsAction.Read, FsAction.ReadExecute.And(FsAction.
                                                          ReadWrite));
     Assert.Equal(FsAction.None, FsAction.ReadExecute.And(FsAction.
                                                          Write));
     Assert.Equal(FsAction.WriteExecute, FsAction.All.And(FsAction.
                                                          WriteExecute));
 }
コード例 #5
0
ファイル: AclEntry.cs プロジェクト: orf53975/hadoop.net
 /// <summary>Private constructor.</summary>
 /// <param name="type">AclEntryType ACL entry type</param>
 /// <param name="name">String optional ACL entry name</param>
 /// <param name="permission">FsAction set of permissions in the ACL entry</param>
 /// <param name="scope">AclEntryScope scope of the ACL entry</param>
 private AclEntry(AclEntryType type, string name, FsAction permission, AclEntryScope
                  scope)
 {
     this.type       = type;
     this.name       = name;
     this.permission = permission;
     this.scope      = scope;
 }
コード例 #6
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestUMaskParser()
        {
            Configuration conf = new Configuration();

            // Ensure that we get the right octal values back for all legal values
            foreach (FsAction u in FsAction.Values())
            {
                foreach (FsAction g in FsAction.Values())
                {
                    foreach (FsAction o in FsAction.Values())
                    {
                        FsPermission f       = new FsPermission(u, g, o);
                        string       asOctal = string.Format("%1$03o", f.ToShort());
                        conf.Set(FsPermission.UmaskLabel, asOctal);
                        FsPermission fromConf = FsPermission.GetUMask(conf);
                        Assert.Equal(f, fromConf);
                    }
                }
            }
        }
コード例 #7
0
 public virtual void TestSpecialBitsToString()
 {
     foreach (bool sb in new bool[] { false, true })
     {
         foreach (FsAction u in FsAction.Values())
         {
             foreach (FsAction g in FsAction.Values())
             {
                 foreach (FsAction o in FsAction.Values())
                 {
                     FsPermission f       = new FsPermission(u, g, o, sb);
                     string       fString = f.ToString();
                     // Check that sticky bit is represented correctly.
                     if (f.GetStickyBit() && f.GetOtherAction().Implies(FsAction.Execute))
                     {
                         Assert.Equal('t', fString[8]);
                     }
                     else
                     {
                         if (f.GetStickyBit() && !f.GetOtherAction().Implies(FsAction.Execute))
                         {
                             Assert.Equal('T', fString[8]);
                         }
                         else
                         {
                             if (!f.GetStickyBit() && f.GetOtherAction().Implies(FsAction.Execute))
                             {
                                 Assert.Equal('x', fString[8]);
                             }
                             else
                             {
                                 Assert.Equal('-', fString[8]);
                             }
                         }
                     }
                     Assert.Equal(9, fString.Length);
                 }
             }
         }
     }
 }
コード例 #8
0
 /// <summary>Get the effective permission for the AclEntry.</summary>
 /// <remarks>
 /// Get the effective permission for the AclEntry. <br />
 /// Recommended to use this API ONLY if client communicates with the old
 /// NameNode, needs to pass the Permission for the path to get effective
 /// permission, else use
 /// <see cref="GetEffectivePermission(AclEntry)"/>
 /// .
 /// </remarks>
 /// <param name="entry">AclEntry to get the effective action</param>
 /// <param name="permArg">
 /// Permission for the path. However if the client is NOT
 /// communicating with old namenode, then this argument will not have
 /// any preference.
 /// </param>
 /// <returns>Returns the effective permission for the entry.</returns>
 /// <exception cref="System.ArgumentException">
 /// If the client communicating with old
 /// namenode and permission is not passed as an argument.
 /// </exception>
 public virtual FsAction GetEffectivePermission(AclEntry entry, FsPermission permArg
                                                )
 {
     // At least one permission bits should be available.
     Preconditions.CheckArgument(this.permission != null || permArg != null, "Permission bits are not available to calculate effective permission"
                                 );
     if (this.permission != null)
     {
         // permission bits from server response will have the priority for
         // accuracy.
         permArg = this.permission;
     }
     if ((entry.GetName() != null || entry.GetType() == AclEntryType.Group))
     {
         if (entry.GetScope() == AclEntryScope.Access)
         {
             FsAction entryPerm = entry.GetPermission();
             return(entryPerm.And(permArg.GetGroupAction()));
         }
         else
         {
             Preconditions.CheckArgument(this.entries.Contains(entry) && this.entries.Count >=
                                         3, "Passed default ACL entry not found in the list of ACLs");
             // default mask entry for effective permission calculation will be the
             // penultimate entry. This can be mask entry in case of extended ACLs.
             // In case of minimal ACL, this is the owner group entry, and we end up
             // intersecting group FsAction with itself, which is a no-op.
             FsAction defaultMask = this.entries[this.entries.Count - 2].GetPermission();
             FsAction entryPerm   = entry.GetPermission();
             return(entryPerm.And(defaultMask));
         }
     }
     else
     {
         return(entry.GetPermission());
     }
 }
コード例 #9
0
ファイル: FsPermission.cs プロジェクト: orf53975/hadoop.net
 public FsPermission(FsAction u, FsAction g, FsAction o, bool sb)
 {
     //POSIX permission style
     Set(u, g, o, sb);
 }
コード例 #10
0
ファイル: FsPermission.cs プロジェクト: orf53975/hadoop.net
 /// <summary>
 /// Construct by the given
 /// <see cref="FsAction"/>
 /// .
 /// </summary>
 /// <param name="u">user action</param>
 /// <param name="g">group action</param>
 /// <param name="o">other action</param>
 public FsPermission(FsAction u, FsAction g, FsAction o)
     : this(u, g, o, false)
 {
 }
コード例 #11
0
ファイル: AclEntry.cs プロジェクト: orf53975/hadoop.net
        /// <summary>Parses a string representation of an ACL into a AclEntry object.<br /></summary>
        /// <param name="aclStr">
        /// String representation of an ACL.<br />
        /// Example: "user:foo:rw-"
        /// </param>
        /// <param name="includePermission">
        /// for setAcl operations this will be true. i.e. Acl should include
        /// permissions.<br />
        /// But for removeAcl operation it will be false. i.e. Acl should not
        /// contain permissions.<br />
        /// Example: "user:foo,group:bar,mask::"
        /// </param>
        /// <returns>
        /// Returns an
        /// <see cref="AclEntry"/>
        /// object
        /// </returns>
        public static AclEntry ParseAclEntry(string aclStr, bool includePermission)
        {
            AclEntry.Builder builder = new AclEntry.Builder();
            // Here "::" represent one empty string.
            // StringUtils.getStringCollection() will ignore this.
            string[] split = aclStr.Split(":");
            if (split.Length == 0)
            {
                throw new HadoopIllegalArgumentException("Invalid <aclSpec> : " + aclStr);
            }
            int index = 0;

            if ("default".Equals(split[0]))
            {
                // default entry
                index++;
                builder.SetScope(AclEntryScope.Default);
            }
            if (split.Length <= index)
            {
                throw new HadoopIllegalArgumentException("Invalid <aclSpec> : " + aclStr);
            }
            AclEntryType aclType = null;

            try
            {
                aclType = Enum.ValueOf <AclEntryType>(StringUtils.ToUpperCase(split[index]));
                builder.SetType(aclType);
                index++;
            }
            catch (ArgumentException)
            {
                throw new HadoopIllegalArgumentException("Invalid type of acl in <aclSpec> :" + aclStr
                                                         );
            }
            if (split.Length > index)
            {
                string name = split[index];
                if (!name.IsEmpty())
                {
                    builder.SetName(name);
                }
                index++;
            }
            if (includePermission)
            {
                if (split.Length <= index)
                {
                    throw new HadoopIllegalArgumentException("Invalid <aclSpec> : " + aclStr);
                }
                string   permission = split[index];
                FsAction fsAction   = FsAction.GetFsAction(permission);
                if (null == fsAction)
                {
                    throw new HadoopIllegalArgumentException("Invalid permission in <aclSpec> : " + aclStr
                                                             );
                }
                builder.SetPermission(fsAction);
                index++;
            }
            if (split.Length > index)
            {
                throw new HadoopIllegalArgumentException("Invalid <aclSpec> : " + aclStr);
            }
            AclEntry aclEntry = builder.Build();

            return(aclEntry);
        }
コード例 #12
0
ファイル: AclEntry.cs プロジェクト: orf53975/hadoop.net
 /// <summary>Sets the set of permissions in the ACL entry.</summary>
 /// <param name="permission">FsAction set of permissions in the ACL entry</param>
 /// <returns>Builder this builder, for call chaining</returns>
 public virtual AclEntry.Builder SetPermission(FsAction permission)
 {
     this.permission = permission;
     return(this);
 }