Example #1
0
        private async Task ExecuteWithChangedFsId(
            FtpExecutionContext context,
            ClaimsPrincipal unixUser,
            FtpCommandExecutionDelegate next)
        {
            var userId  = ConvertToLong(unixUser.FindFirst(FtpClaimTypes.UserId)?.Value) ?? uint.MaxValue;
            var groupId = ConvertToLong(unixUser.FindFirst(FtpClaimTypes.GroupId)?.Value) ?? uint.MaxValue;

            using (var contextThread = new AsyncContextThread())
            {
                await contextThread.Factory.Run(
                    async() =>
                {
                    using (new UnixFileSystemIdChanger(
                               _logger,
                               userId,
                               groupId,
                               _serverUser.UserId,
                               _serverUser.GroupId))
                    {
                        await next(context).ConfigureAwait(true);
                    }
                })
                .ConfigureAwait(true);

                await contextThread.JoinAsync().ConfigureAwait(false);
            }
        }
Example #2
0
        /// <inheritdoc />
        public Task InvokeAsync(FtpExecutionContext context, FtpCommandExecutionDelegate next)
        {
            var connection = context.Connection;
            var authInfo   = connection.Features.Get <IAuthorizationInformationFeature>();

            if (!(authInfo.User is IUnixUser unixUser))
            {
                return(next(context));
            }

            var fsInfo = connection.Features.Get <IFileSystemFeature>();

            if (!(fsInfo.FileSystem is UnixFileSystem))
            {
                return(next(context));
            }

            return(ExecuteWithChangedFsId(context, unixUser, next));
        }
Example #3
0
        private async Task ExecuteWithChangedFsId(
            [NotNull] FtpExecutionContext context,
            [NotNull] IUnixUser unixUser,
            [NotNull] FtpCommandExecutionDelegate next)
        {
            var contextThread = new AsyncContextThread();
            await contextThread.Factory.Run(
                async() =>
            {
                using (new UnixFileSystemIdChanger(
                           _logger,
                           unixUser.UserId,
                           unixUser.GroupId,
                           _serverUser.UserId,
                           _serverUser.GroupId))
                {
                    await next(context).ConfigureAwait(true);
                }
            })
            .ConfigureAwait(true);

            await contextThread.JoinAsync().ConfigureAwait(false);
        }