public UnixDirectoryEntry( [NotNull] UnixDirectoryInfo info, [NotNull] IFtpUser user, [CanBeNull] UnixUserInfo userInfo, IUnixDirectoryEntry parent = null) : base(info) { IsRoot = parent == null; Info = info; if (parent == null) { // Root user IsDeletable = false; } else if (info.Parent == info) { // File system root IsDeletable = false; } else if (userInfo != null && (userInfo.UserId == 0 || userInfo.GroupId == 0)) { IsDeletable = true; } else { IsDeletable = parent.GetEffectivePermissions(user).Write; } }
public PermissionsFact(IFtpUser user, IUnixDirectoryEntry?dir, IUnixDirectoryEntry entry) { var values = new StringBuilder(); var entryPerm = entry.Permissions.GetAccessModeFor(entry, user); if (entryPerm.Write) { values.Append('c'); values.Append('m'); values.Append('p'); } if (dir != null) { var dirPerm = dir.Permissions.GetAccessModeFor(dir, user); if (dirPerm.Write && entryPerm.Write) { if (!entry.IsRoot && entry.IsDeletable) { values.Append('d'); } values.Append('f'); } } if (entryPerm.Read) { values.Append('e'); values.Append('l'); } Value = values.ToString(); }
/// <inheritdoc /> public async Task <IUnixFileSystem> Create(IFtpUser user, bool isAnonymous) { var(driveService, rootItem) = await _serviceProvider.GetUserRootAsync( user.Name, isAnonymous, CancellationToken.None); return(new GoogleDriveFileSystem(driveService, rootItem, _temporaryDataFactory)); }
/// <summary> /// Initializes a new instance of the <see cref="FactsListFormatter"/> class. /// </summary> /// <param name="user">The user to create this formatter for.</param> /// <param name="enumerator">The enumerator for the directory listing to format.</param> /// <param name="activeFacts">The active facts to return for the entries.</param> /// <param name="absoluteName">Returns an absolute entry name.</param> public FactsListFormatter(IFtpUser user, DirectoryListingEnumerator enumerator, ISet <string> activeFacts, bool absoluteName) { _user = user; _enumerator = enumerator; _activeFacts = activeFacts; _absoluteName = absoluteName; }
public PermissionsFact(IFtpUser user, IUnixFileSystem fileSystem, IUnixDirectoryEntry dir, IUnixFileEntry entry) { var values = new StringBuilder(); var entryPerm = entry.Permissions.GetAccessModeFor(entry, user); var dirPerm = dir.Permissions.GetAccessModeFor(dir, user); if (dirPerm.Write) { values.Append('c'); if (entryPerm.Write) { if (fileSystem.SupportsAppend) { values.Append('a'); } values.Append('d'); values.Append('f'); } } if (entryPerm.Read) { values.Append('r'); } if (entryPerm.Write) { values.Append('w'); } Value = values.ToString(); }
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)); }
public UnixFileSystem( IUnixDirectoryEntry root, IFtpUser user, UnixUserInfo?userInfo) { _user = user.CreateClaimsPrincipal(); _userInfo = userInfo; Root = root; }
/// <summary> /// Initializes a new instance of the <see cref="UnixFileSystem"/> class. /// </summary> /// <param name="root">The root directory.</param> /// <param name="user">The current user.</param> /// <param name="userInfo">The user information.</param> public UnixFileSystem( [NotNull] IUnixDirectoryEntry root, [NotNull] IFtpUser user, [CanBeNull] UnixUserInfo userInfo) { _user = user; _userInfo = userInfo; Root = root; }
private static string?GetAuthenticationType(IFtpUser user) { return(user switch { IAnonymousFtpUser _ => "anonymous", IUnixUser _ => "pam", PasswordAuthorization.UnauthenticatedUser _ => null, _ => "custom" });
private string GetUserHome([NotNull] IFtpUser ftpUser) { if (ftpUser is PamFtpUser pamFtpUser) { return(pamFtpUser.HomeDirectory); } return($"/home/{ftpUser.Name}"); }
/// <summary> /// Initializes a new instance of the <see cref="MemberValidationResult"/> class. /// </summary> /// <param name="status">The success status for the validation.</param> /// <param name="user">The validated user.</param> public MemberValidationResult(MemberValidationStatus status, IFtpUser user) { if (status != MemberValidationStatus.Anonymous && status != MemberValidationStatus.AuthenticatedUser) { throw new ArgumentOutOfRangeException(nameof(status), "User object must only be specified when validation was successful."); } Status = status; _user = user ?? throw new ArgumentNullException(nameof(user)); }
public MlstFtpResponse( ISet <string> activeMlstFacts, IFtpUser user, IUnixFileSystem fileSystem, IUnixFileSystemEntry targetEntry, Stack <IUnixDirectoryEntry> path) : base(250, $" {targetEntry.Name}", "End") { _activeMlstFacts = activeMlstFacts; _user = user; _fileSystem = fileSystem; _targetEntry = targetEntry; _path = path; }
/// <inheritdoc/> public Task <IUnixFileSystem> Create(IFtpUser user, bool isAnonymous) { var path = _rootPath; var userId = user.Name; if (_useUserIdAsSubFolder) { if (isAnonymous) { userId = "anonymous"; } path = Path.Combine(path, userId); } return(Task.FromResult <IUnixFileSystem>(new DotNetFileSystem(user.RootPath ?? path, _allowNonEmptyDirectoryDelete, _streamBufferSize))); }
private async Task <IFtpResponse> ExecuteSendAsync( IFtpDataConnection dataConnection, IFtpUser user, IUnixFileSystem fileSystem, Stack <IUnixDirectoryEntry> path, IUnixDirectoryEntry dirEntry, IMlstFactsFeature factsFeature, CancellationToken cancellationToken) { var encoding = Connection.Features.Get <IEncodingFeature>().Encoding; var stream = dataConnection.Stream; using (var writer = new StreamWriter(stream, encoding, 4096, true) { NewLine = "\r\n", }) { var entries = await fileSystem.GetEntriesAsync(dirEntry, cancellationToken).ConfigureAwait(false); var enumerator = new DirectoryListingEnumerator(entries, fileSystem, path, true); var formatter = new FactsListFormatter(user, enumerator, factsFeature.ActiveMlstFacts, false); while (enumerator.MoveNext()) { var name = enumerator.Name; var entry = enumerator.Entry; var line = formatter.Format(entry, name); _logger?.LogTrace(line); await writer.WriteLineAsync(line).ConfigureAwait(false); } await writer.FlushAsync().ConfigureAwait(false); } // Use 250 when the connection stays open. return(new FtpResponse(226, T("Closing data connection."))); }
/// <summary> /// Configure directory entry as owned by given <paramref name="user"/>. /// </summary> /// <param name="user">The user that becomes the new owner of this directory entry.</param> /// <returns>The changed file system entry.</returns> public InMemoryFileSystemEntry WithOwner(IFtpUser user) { Owner = user.Name; return(this); }
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)); }
public DefaultAccountInformation(IFtpUser user, IMembershipProvider authenticatedBy) { User = user; AuthenticatedBy = authenticatedBy; }
public static ClaimsPrincipal CreateClaimsPrincipal(this IFtpUser user) { return(new ClaimsPrincipalUser(user)); }
public DefaultAccountInformation(IFtpUser user) { User = user; }
public ClaimsIdentityUser(IFtpUser user) : base(CreateClaims(user), GetAuthenticationType(user)) { }