Exemplo n.º 1
0
        internal static int ToInt(AclEntry aclEntry)
        {
            long aclEntryInt = 0;

            aclEntryInt = Org.Apache.Hadoop.Hdfs.Server.Namenode.AclEntryStatusFormat.Scope.Bits
                          .Combine((int)(aclEntry.GetScope()), aclEntryInt);
            aclEntryInt = Org.Apache.Hadoop.Hdfs.Server.Namenode.AclEntryStatusFormat.Type.Bits
                          .Combine((int)(aclEntry.GetType()), aclEntryInt);
            aclEntryInt = Org.Apache.Hadoop.Hdfs.Server.Namenode.AclEntryStatusFormat.Permission
                          .Bits.Combine((int)(aclEntry.GetPermission()), aclEntryInt);
            if (aclEntry.GetName() != null)
            {
                aclEntryInt = Org.Apache.Hadoop.Hdfs.Server.Namenode.AclEntryStatusFormat.NamedEntryCheck
                              .Bits.Combine(1, aclEntryInt);
                if (aclEntry.GetType() == AclEntryType.User)
                {
                    int userId = SerialNumberManager.Instance.GetUserSerialNumber(aclEntry.GetName());
                    aclEntryInt = Org.Apache.Hadoop.Hdfs.Server.Namenode.AclEntryStatusFormat.Name.Bits
                                  .Combine(userId, aclEntryInt);
                }
                else
                {
                    if (aclEntry.GetType() == AclEntryType.Group)
                    {
                        int groupId = SerialNumberManager.Instance.GetGroupSerialNumber(aclEntry.GetName(
                                                                                            ));
                        aclEntryInt = Org.Apache.Hadoop.Hdfs.Server.Namenode.AclEntryStatusFormat.Name.Bits
                                      .Combine(groupId, aclEntryInt);
                    }
                }
            }
            return((int)aclEntryInt);
        }
Exemplo n.º 2
0
        /// <summary>Merges the entries of the ACL spec into the existing ACL.</summary>
        /// <remarks>
        /// Merges the entries of the ACL spec into the existing ACL.  If necessary,
        /// recalculates the mask entries.  If necessary, default entries may be
        /// inferred by copying the permissions of the corresponding access entries.
        /// </remarks>
        /// <param name="existingAcl">List<AclEntry> existing ACL</param>
        /// <param name="inAclSpec">List<AclEntry> ACL spec containing entries to merge</param>
        /// <returns>List<AclEntry> new ACL</returns>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.AclException">if validation fails
        ///     </exception>
        public static IList <AclEntry> MergeAclEntries(IList <AclEntry> existingAcl, IList <
                                                           AclEntry> inAclSpec)
        {
            AclTransformation.ValidatedAclSpec aclSpec = new AclTransformation.ValidatedAclSpec
                                                             (inAclSpec);
            AList <AclEntry> aclBuilder                    = Lists.NewArrayListWithCapacity(MaxEntries);
            IList <AclEntry> foundAclSpecEntries           = Lists.NewArrayListWithCapacity(MaxEntries);
            EnumMap <AclEntryScope, AclEntry> providedMask = Maps.NewEnumMap <AclEntryScope>();
            EnumSet <AclEntryScope>           maskDirty    = EnumSet.NoneOf <AclEntryScope>();
            EnumSet <AclEntryScope>           scopeDirty   = EnumSet.NoneOf <AclEntryScope>();

            foreach (AclEntry existingEntry in existingAcl)
            {
                AclEntry aclSpecEntry = aclSpec.FindByKey(existingEntry);
                if (aclSpecEntry != null)
                {
                    foundAclSpecEntries.AddItem(aclSpecEntry);
                    scopeDirty.AddItem(aclSpecEntry.GetScope());
                    if (aclSpecEntry.GetType() == AclEntryType.Mask)
                    {
                        providedMask[aclSpecEntry.GetScope()] = aclSpecEntry;
                        maskDirty.AddItem(aclSpecEntry.GetScope());
                    }
                    else
                    {
                        aclBuilder.AddItem(aclSpecEntry);
                    }
                }
                else
                {
                    if (existingEntry.GetType() == AclEntryType.Mask)
                    {
                        providedMask[existingEntry.GetScope()] = existingEntry;
                    }
                    else
                    {
                        aclBuilder.AddItem(existingEntry);
                    }
                }
            }
            // ACL spec entries that were not replacements are new additions.
            foreach (AclEntry newEntry in aclSpec)
            {
                if (Sharpen.Collections.BinarySearch(foundAclSpecEntries, newEntry, AclEntryComparator
                                                     ) < 0)
                {
                    scopeDirty.AddItem(newEntry.GetScope());
                    if (newEntry.GetType() == AclEntryType.Mask)
                    {
                        providedMask[newEntry.GetScope()] = newEntry;
                        maskDirty.AddItem(newEntry.GetScope());
                    }
                    else
                    {
                        aclBuilder.AddItem(newEntry);
                    }
                }
            }
            CopyDefaultsIfNeeded(aclBuilder);
            CalculateMasks(aclBuilder, providedMask, maskDirty, scopeDirty);
            return(BuildAndValidateAcl(aclBuilder));
        }