/// <summary> /// Initializes a new instance of the <see cref="InMemoryFileSystemEntry"/> class. /// </summary> /// <param name="parent">The parent entry.</param> /// <param name="name">The name of this entry.</param> /// <param name="permissions">The permissions of this entry.</param> protected InMemoryFileSystemEntry( InMemoryDirectoryEntry parent, string name, IUnixPermissions permissions) { Name = name; Permissions = permissions; Parent = parent; Owner = "owner"; Group = "group"; CreatedTime = DateTimeOffset.Now; }
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)); }
/// <summary> /// Gets the effective access mode for an <paramref name="entity"/> for the given <paramref name="user"/>. /// </summary> /// <param name="permissions">The permissions used to build the access mode.</param> /// <param name="entity">The entity owner information.</param> /// <param name="user">The FTP user to determine the access mode for.</param> /// <returns>The effective access mode for the <paramref name="user"/>.</returns> public static IAccessMode GetAccessModeFor(this IUnixPermissions permissions, IUnixOwner entity, ClaimsPrincipal user) { var isUser = string.Equals(entity.GetOwner(), user.Identity.Name, StringComparison.OrdinalIgnoreCase); var group = entity.GetGroup(); var isGroup = group != null && user.IsInRole(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)); }