public static IAccessMode GetEffectivePermissions(
            [NotNull] this IUnixDirectoryEntry entry,
            [NotNull] IFtpUser ftpUser)
        {
            var canRead    = false;
            var canWrite   = false;
            var canExecute = false;

            void UpdatePermissions(
                IAccessMode toApply)
            {
                canRead    |= toApply.Read;
                canWrite   |= toApply.Write;
                canExecute |= toApply.Execute;
            }

            if (entry.Owner == ftpUser.Name)
            {
                UpdatePermissions(entry.Permissions.User);
            }

            if (ftpUser.IsInGroup(entry.Group))
            {
                UpdatePermissions(entry.Permissions.Group);
            }

            UpdatePermissions(entry.Permissions.Other);

            return(new GenericAccessMode(canRead, canWrite, canExecute));
        }
Exemplo n.º 2
0
        public static IAccessMode GetAccessModeFor([NotNull] this IUnixPermissions permissions, [NotNull] IUnixOwner entity, [NotNull] IFtpUser user)
        {
            var isUser  = string.Equals(entity.Owner, user.Name, StringComparison.OrdinalIgnoreCase);
            var isGroup = user.IsInGroup(entity.Group);
            var canRead = (isUser && permissions.User.Read) ||
                          (isGroup && permissions.Group.Read) ||
                          permissions.Other.Read;
            var canWrite = (isUser && permissions.User.Write) ||
                           (isGroup && permissions.Group.Write) ||
                           permissions.Other.Write;
            var canExecute = (isUser && permissions.User.Execute) ||
                             (isGroup && permissions.Group.Execute) ||
                             permissions.Other.Execute;

            return(new GenericAccessMode(canRead, canWrite, canExecute));
        }