IIS FTP 8 自定义身份验证授权规则拒绝访问



我使用 C# 为 IIS FTP 8 创建了一个自定义身份验证器。 我已经正确设置了自定义功能处理程序,以便IIS使用我的DLL,但是当我尝试登录时,我总是得到:

Response:   331 Password required
Command:    PASS ********
Response:   530-User cannot log in, home directory inaccessible.
Response:    Win32 error:   No such interface supported 
Response:    Error details: Authorization rules denied the access.
Response:   530 End

我很确定我已经排除了文件夹权限 - 它尽可能开放。 因此,据我了解该消息 - 它告诉我我没有任何授权规则。 但是似乎没有办法为自定义身份验证器添加一个。 IIS 管理器中的 UI 会清空常规设置功能,因此您无法在其中添加任何设置功能。

我尝试了应用程序cmd:

appcmd.exe set config "mysite" -section:system.ftpServer/security/authorization /+"[accessType='Allow',roles='administrators',permissions='Read, Write']" /commit:apphost

角色(客人,*等)的变化没有成功。

我尝试在applicationHost.config中编辑网站的条目,但是除了Microsoft文档中的这个"非自定义"示例之外,我找不到任何关于将其放在哪里的文档:

<location path="ftp.example.com">
  <system.ftpServer>
    <security>
      <authorization>
        <add accessType="Allow" roles="administrators" permissions="Read, Write" />
      </authorization>

当我在配置中的指定位置添加授权标记时,FTP 服务不会重新启动。

那么,在使用

自定义FTP身份验证提供程序时,究竟如何添加授权规则呢?

为了完整起见,下面是提供程序类的代码。 记下 LogMessage 方法中文本文件的输出。 这向我表明一切正常 - 它只是无法访问用户的主文件夹,因为没有授权规则。

using System;
using System.IO;
using Microsoft.Web.FtpServer;
namespace MyCustomFtpExtension
{
    public class DatabaseAuthenticator : BaseProvider,
        IFtpAuthenticationProvider,
        IFtpRoleProvider, IFtpHomeDirectoryProvider, IFtpPostprocessProvider,
        IFtpLogProvider
    {
        private readonly string _logfile = Path.Combine(@"c:test", "logs", "FtpExtension.log");
        public bool AuthenticateUser(string sessionId, string siteName, string userName, string userPassword,
            out string canonicalUserName)
        {
            canonicalUserName = userName;
            var result = DatabaseHelper.Authenticate(userName, userPassword);
            if (result)
            {
                LogMessage("Login Success: " + userName);  //this message appears
            }
            else
            {
                LogMessage("Login Failure: " + userName);
            }
            return result;
        }
        string IFtpHomeDirectoryProvider.GetUserHomeDirectoryData(
            string sessionId,
            string siteName,
            string userName)
        {
            LogMessage("In ftp home directory");  //this message never appears
            return @"c:temptest";
        }
        public FtpProcessStatus HandlePostprocess(FtpPostprocessParameters postProcessParameters)
        {
            LogMessage("Running Post Process");  //this message never appears
            return FtpProcessStatus.FtpProcessContinue;
        }
        public bool IsUserInRole(string sessionId, string siteName, string userName, string userRole)
        {
            return true; // I don't care about this - if they authenticate, that's all I need.
        }

        //to keep the sample short I took out the log provider - it was copy / paste from Microsoft's example
        //this is a quick and dirty output so I can see what's going on (which isn't much)
        private void LogMessage(string logEntry)
        {
            using (var sw = new StreamWriter(_logfile, true))
            {
                // Retrieve the current date and time for the log entry.
                var dt = DateTime.Now;
                sw.WriteLine("{0}t{1}tMESSAGE:{2}",
                    dt.ToShortDateString(),
                    dt.ToLongTimeString(),
                    logEntry);
                sw.Flush();
            }
        }
    }
}

您需要运行命令来分配库 FIR 主目录提供程序。

AppCmd set site "FTP Site Name" /+ftpServer.customFeatures.providers.[name='CustomFtpAuthDemo',enabled='true']

最新更新