Beispiel #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);
        }
Beispiel #2
0
        /// <summary>
        /// Parses symbolic permissions string to RolePermissions.
        /// </summary>
        /// <param name="s">String to parse.</param>
        /// <param name="allowStickyBit">If sticky bit is allowed.</param>
        /// <returns><see cref="RolePermissions"/>.</returns>
        public static RolePermissions ParseSymbolicRolePermissions(string s, bool allowStickyBit = false)
        {
            RolePermissions   rolePermissions   = RolePermissions.None;
            ArgumentException argumentException = DataLakeErrors.RolePermissionsSymbolicInvalidCharacter(s);

            if (s == null)
            {
                throw Errors.ArgumentNull(nameof(s));
            }

            if (s.Length != 3)
            {
                throw DataLakeErrors.RolePermissionsSymbolicInvalidLength(s);
            }

            if (s[0] == 'r')
            {
                rolePermissions |= RolePermissions.Read;
            }
            else if (s[0] != '-')
            {
                throw argumentException;
            }

            if (s[1] == 'w')
            {
                rolePermissions |= RolePermissions.Write;
            }
            else if (s[1] != '-')
            {
                throw argumentException;
            }

            if (s[2] == 'x')
            {
                rolePermissions |= RolePermissions.Execute;
            }
            else if (allowStickyBit)
            {
                if (s[2] == 't')
                {
                    rolePermissions |= RolePermissions.Execute;
                }
                else if (s[2] != 'T' && s[2] != '-')
                {
                    throw argumentException;
                }
            }
            else if (s[2] != '-')
            {
                throw argumentException;
            }

            return(rolePermissions);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="accessControlType">Specifies which role this entry targets.</param>
        /// <param name="defaultScope">Indicates whether this is the default entry for the ACL.</param>
        /// <param name="entityId">Optional entity ID to which this entry applies.</param>
        public RemovePathAccessControlItem(
            AccessControlType accessControlType,
            bool defaultScope = false,
            string entityId   = default)
        {
            if ((accessControlType == AccessControlType.Mask || accessControlType == AccessControlType.Other) &&
                !string.IsNullOrEmpty(entityId))
            {
                throw DataLakeErrors.EntityIdAndInvalidAccessControlType(accessControlType.ToString());
            }

            DefaultScope      = defaultScope;
            AccessControlType = accessControlType;
            EntityId          = entityId;
        }
Beispiel #4
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);
        }
Beispiel #5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="accessControlType">Specifies which role this entry targets.</param>
        /// <param name="permissions">Specifies the permissions granted to this entry.</param>
        /// <param name="defaultScope">Indicates whether this is the default entry for the ACL.</param>
        /// <param name="entityId">Optional entity ID to which this entry applies.</param>
        public PathAccessControlItem(
            AccessControlType accessControlType,
            RolePermissions permissions,
            bool defaultScope = false,
            string entityId   = default)
        {
            if (entityId != null &&
                !(accessControlType == AccessControlType.User || accessControlType == AccessControlType.Group))
            {
                throw DataLakeErrors.EntityIdAndInvalidAccessControlType(accessControlType.ToString());
            }

            DefaultScope      = defaultScope;
            AccessControlType = accessControlType;
            EntityId          = entityId;
            Permissions       = permissions;
        }
        /// <summary>
        /// Parses the provided string into a <see cref="RemovePathAccessControlItem"/>
        /// </summary>
        /// <param name="serializedAccessControl">The string representation of the access control list.</param>
        /// <returns>A <see cref="RemovePathAccessControlItem"/>.</returns>
        public static RemovePathAccessControlItem Parse(string serializedAccessControl)
        {
            if (string.IsNullOrWhiteSpace(serializedAccessControl))
            {
                throw DataLakeErrors.RemovePathAccessControlItemInvalidString(serializedAccessControl);
            }

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

            if (parts.Length < 1 || parts.Length > 3)
            {
                throw DataLakeErrors.RemovePathAccessControlItemInvalidString(serializedAccessControl);
            }

            if (parts.Length == 3 && !parts[0].Equals("default", StringComparison.OrdinalIgnoreCase))
            {
                throw DataLakeErrors.RemovePathAccessControlItemStringInvalidPrefix(serializedAccessControl);
            }

            bool defaultScope = false;

            if (parts[0].Equals("default", StringComparison.OrdinalIgnoreCase))
            {
                defaultScope = true;
                indexOffset  = 1;
            }

            AccessControlType accessControlType = (AccessControlType)Enum.Parse(typeof(AccessControlType), parts[indexOffset], true);

            string entityId = null;

            if ((1 + indexOffset) < parts.Length && !string.IsNullOrEmpty(parts[1 + indexOffset]))
            {
                entityId = parts[1 + indexOffset];
            }

            return(new RemovePathAccessControlItem(accessControlType, defaultScope, entityId));
        }
Beispiel #7
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);
        }