示例#1
0
        /// <summary>
        /// Parses a string in octal format to PathPermissions.
        /// </summary>
        /// <param name="s">Octal string to parse.</param>
        /// <returns><see cref="PathPermissions"/>.</returns>
        public static PathPermissions ParseOctalPermissions(string s)
        {
            if (s == null)
            {
                return(null);
            }

            if (s.Length != 4)
            {
                throw DataLakeErrors.PathPermissionsOctalInvalidLength(s);
            }

            var pathPermissions = new PathPermissions();

            if (s[0] == '0')
            {
                pathPermissions.StickyBit = false;
            }
            else if (s[0] == '1')
            {
                pathPermissions.StickyBit = true;
            }
            else
            {
                throw DataLakeErrors.PathPermissionsOctalInvalidFirstDigit(s);
            }

            pathPermissions.Owner = PathAccessControlExtensions.ParseOctalRolePermissions(s[1]);
            pathPermissions.Group = PathAccessControlExtensions.ParseOctalRolePermissions(s[2]);
            pathPermissions.Other = PathAccessControlExtensions.ParseOctalRolePermissions(s[3]);

            return(pathPermissions);
        }
示例#2
0
        /// <summary>
        /// Parses a symbolic string to PathPermissions.
        /// </summary>
        /// <param name="s">String to parse.</param>
        /// <returns><see cref="PathPermissions"/>.</returns>
        public static PathPermissions ParseSymbolicPermissions(string s)
        {
            if (s == null)
            {
                return(null);
            }

            if (s.Length != 9 && s.Length != 10)
            {
                throw DataLakeErrors.PathPermissionsSymbolicInvalidLength(s);
            }

            var pathPermissions = new PathPermissions();

            // Set sticky bit
            if (char.ToLower(s[8], CultureInfo.InvariantCulture) == 't')
            {
                pathPermissions.StickyBit = true;
            }
            else
            {
                pathPermissions.StickyBit = false;
            }

            // Set extended info in ACL
            if (s.Length == 10)
            {
                if (s[9] == '+')
                {
                    pathPermissions.ExtendedAcls = true;
                }
                else
                {
                    throw Errors.InvalidFormat(nameof(s));
                }
            }
            else
            {
                pathPermissions.ExtendedAcls = false;
            }

            pathPermissions.Owner = PathAccessControlExtensions.ParseSymbolicRolePermissions(s.Substring(0, 3), allowStickyBit: false);
            pathPermissions.Group = PathAccessControlExtensions.ParseSymbolicRolePermissions(s.Substring(3, 3), allowStickyBit: false);
            pathPermissions.Other = PathAccessControlExtensions.ParseSymbolicRolePermissions(s.Substring(6, 3), allowStickyBit: true);

            return(pathPermissions);
        }
示例#3
0
        /// <summary>
        /// Parses the provided string into a <see cref="PathAccessControlItem"/>
        /// </summary>
        /// <param name="s">The string representation of the access control list.</param>
        /// <returns>A <see cref="PathAccessControlItem"/>.</returns>
        public static PathAccessControlItem Parse(string s)
        {
            if (s == null)
            {
                return(null);
            }

            PathAccessControlItem entry = new PathAccessControlItem();

            string[] parts       = s.Split(':');
            int      indexOffset = 0;

            if (parts.Length < 3 || parts.Length > 4)
            {
                throw DataLakeErrors.PathAccessControlItemStringInvalidLength(s);
            }

            if (parts.Length == 4)
            {
                if (!parts[0].Equals("default", StringComparison.OrdinalIgnoreCase))
                {
                    throw DataLakeErrors.PathAccessControlItemStringInvalidPrefix(s);
                }
                entry.DefaultScope = true;
                indexOffset        = 1;
            }
            entry.AccessControlType = ParseAccesControlType(parts[indexOffset]);

            if (!string.IsNullOrEmpty(parts[1 + indexOffset]))
            {
                entry.EntityId = parts[1 + indexOffset];
            }

            entry.Permissions = PathAccessControlExtensions.ParseSymbolicRolePermissions(parts[2 + indexOffset], false);
            return(entry);
        }