Пример #1
0
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus SetAcl(FSDirectory fsd, string srcArg, IList <AclEntry
                                                                                     > aclSpec)
        {
            string src = srcArg;

            CheckAclsConfigFlag(fsd);
            byte[][]            pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            FSPermissionChecker pc             = fsd.GetPermissionChecker();

            src = fsd.ResolvePath(pc, src, pathComponents);
            INodesInPath iip;

            fsd.WriteLock();
            try
            {
                iip = fsd.GetINodesInPath4Write(src);
                fsd.CheckOwner(pc, iip);
                IList <AclEntry> newAcl = UnprotectedSetAcl(fsd, src, aclSpec, false);
                fsd.GetEditLog().LogSetAcl(src, newAcl);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            return(fsd.GetAuditFileInfo(iip));
        }
Пример #2
0
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus RemoveDefaultAcl(FSDirectory fsd, string srcArg)
        {
            string src = srcArg;

            CheckAclsConfigFlag(fsd);
            FSPermissionChecker pc = fsd.GetPermissionChecker();

            byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            src = fsd.ResolvePath(pc, src, pathComponents);
            INodesInPath iip;

            fsd.WriteLock();
            try
            {
                iip = fsd.GetINodesInPath4Write(FSDirectory.NormalizePath(src), true);
                fsd.CheckOwner(pc, iip);
                INode            inode       = FSDirectory.ResolveLastINode(iip);
                int              snapshotId  = iip.GetLatestSnapshotId();
                IList <AclEntry> existingAcl = AclStorage.ReadINodeLogicalAcl(inode);
                IList <AclEntry> newAcl      = AclTransformation.FilterDefaultAclEntries(existingAcl);
                AclStorage.UpdateINodeAcl(inode, newAcl, snapshotId);
                fsd.GetEditLog().LogSetAcl(src, newAcl);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            return(fsd.GetAuditFileInfo(iip));
        }
Пример #3
0
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus SetOwner(FSDirectory fsd, string src, string username
                                                , string group)
        {
            FSPermissionChecker pc = fsd.GetPermissionChecker();

            byte[][]     pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            INodesInPath iip;

            fsd.WriteLock();
            try
            {
                src = fsd.ResolvePath(pc, src, pathComponents);
                iip = fsd.GetINodesInPath4Write(src);
                fsd.CheckOwner(pc, iip);
                if (!pc.IsSuperUser())
                {
                    if (username != null && !pc.GetUser().Equals(username))
                    {
                        throw new AccessControlException("Non-super user cannot change owner");
                    }
                    if (group != null && !pc.ContainsGroup(group))
                    {
                        throw new AccessControlException("User does not belong to " + group);
                    }
                }
                UnprotectedSetOwner(fsd, src, username, group);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            fsd.GetEditLog().LogSetOwner(src, username, group);
            return(fsd.GetAuditFileInfo(iip));
        }
Пример #4
0
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus RemoveAcl(FSDirectory fsd, string srcArg)
        {
            string src = srcArg;

            CheckAclsConfigFlag(fsd);
            FSPermissionChecker pc = fsd.GetPermissionChecker();

            byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            src = fsd.ResolvePath(pc, src, pathComponents);
            INodesInPath iip;

            fsd.WriteLock();
            try
            {
                iip = fsd.GetINodesInPath4Write(src);
                fsd.CheckOwner(pc, iip);
                UnprotectedRemoveAcl(fsd, iip);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            fsd.GetEditLog().LogSetAcl(src, AclFeature.EmptyEntryList);
            return(fsd.GetAuditFileInfo(iip));
        }
Пример #5
0
        /// <summary>Delete a snapshot of a snapshottable directory</summary>
        /// <param name="snapshotRoot">The snapshottable directory</param>
        /// <param name="snapshotName">The name of the to-be-deleted snapshot</param>
        /// <exception cref="System.IO.IOException"/>
        internal static INode.BlocksMapUpdateInfo DeleteSnapshot(FSDirectory fsd, SnapshotManager
                                                                 snapshotManager, string snapshotRoot, string snapshotName, bool logRetryCache)
        {
            INodesInPath iip = fsd.GetINodesInPath4Write(snapshotRoot);

            if (fsd.IsPermissionEnabled())
            {
                FSPermissionChecker pc = fsd.GetPermissionChecker();
                fsd.CheckOwner(pc, iip);
            }
            INode.BlocksMapUpdateInfo collectedBlocks = new INode.BlocksMapUpdateInfo();
            ChunkedArrayList <INode>  removedINodes   = new ChunkedArrayList <INode>();

            fsd.WriteLock();
            try
            {
                snapshotManager.DeleteSnapshot(iip, snapshotName, collectedBlocks, removedINodes);
                fsd.RemoveFromInodeMap(removedINodes);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            removedINodes.Clear();
            fsd.GetEditLog().LogDeleteSnapshot(snapshotRoot, snapshotName, logRetryCache);
            return(collectedBlocks);
        }
Пример #6
0
 /// <exception cref="Org.Apache.Hadoop.Security.AccessControlException"/>
 private static void CheckXAttrChangeAccess(FSDirectory fsd, INodesInPath iip, XAttr
                                            xAttr, FSPermissionChecker pc)
 {
     if (fsd.IsPermissionEnabled() && xAttr.GetNameSpace() == XAttr.NameSpace.User)
     {
         INode inode = iip.GetLastINode();
         if (inode != null && inode.IsDirectory() && inode.GetFsPermission().GetStickyBit(
                 ))
         {
             if (!pc.IsSuperUser())
             {
                 fsd.CheckOwner(pc, iip);
             }
         }
         else
         {
             fsd.CheckPathAccess(pc, iip, FsAction.Write);
         }
     }
 }
Пример #7
0
        /// <summary>Create a snapshot</summary>
        /// <param name="snapshotRoot">The directory path where the snapshot is taken</param>
        /// <param name="snapshotName">The name of the snapshot</param>
        /// <exception cref="System.IO.IOException"/>
        internal static string CreateSnapshot(FSDirectory fsd, SnapshotManager snapshotManager
                                              , string snapshotRoot, string snapshotName, bool logRetryCache)
        {
            INodesInPath iip = fsd.GetINodesInPath4Write(snapshotRoot);

            if (fsd.IsPermissionEnabled())
            {
                FSPermissionChecker pc = fsd.GetPermissionChecker();
                fsd.CheckOwner(pc, iip);
            }
            if (snapshotName == null || snapshotName.IsEmpty())
            {
                snapshotName = Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.GenerateDefaultSnapshotName
                                   ();
            }
            else
            {
                if (!DFSUtil.IsValidNameForComponent(snapshotName))
                {
                    throw new InvalidPathException("Invalid snapshot name: " + snapshotName);
                }
            }
            string snapshotPath = null;

            VerifySnapshotName(fsd, snapshotName, snapshotRoot);
            fsd.WriteLock();
            try
            {
                snapshotPath = snapshotManager.CreateSnapshot(iip, snapshotRoot, snapshotName);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            fsd.GetEditLog().LogCreateSnapshot(snapshotRoot, snapshotName, logRetryCache);
            return(snapshotPath);
        }
Пример #8
0
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus SetPermission(FSDirectory fsd, string srcArg, FsPermission
                                                     permission)
        {
            string src             = srcArg;
            FSPermissionChecker pc = fsd.GetPermissionChecker();

            byte[][]     pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            INodesInPath iip;

            fsd.WriteLock();
            try
            {
                src = fsd.ResolvePath(pc, src, pathComponents);
                iip = fsd.GetINodesInPath4Write(src);
                fsd.CheckOwner(pc, iip);
                UnprotectedSetPermission(fsd, src, permission);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            fsd.GetEditLog().LogSetPermissions(src, permission);
            return(fsd.GetAuditFileInfo(iip));
        }
Пример #9
0
        /// <exception cref="System.IO.IOException"/>
        internal static void RenameSnapshot(FSDirectory fsd, SnapshotManager snapshotManager
                                            , string path, string snapshotOldName, string snapshotNewName, bool logRetryCache
                                            )
        {
            INodesInPath iip = fsd.GetINodesInPath4Write(path);

            if (fsd.IsPermissionEnabled())
            {
                FSPermissionChecker pc = fsd.GetPermissionChecker();
                fsd.CheckOwner(pc, iip);
            }
            VerifySnapshotName(fsd, snapshotNewName, path);
            fsd.WriteLock();
            try
            {
                snapshotManager.RenameSnapshot(iip, path, snapshotOldName, snapshotNewName);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            fsd.GetEditLog().LogRenameSnapshot(path, snapshotOldName, snapshotNewName, logRetryCache
                                               );
        }