簡體   English   中英

IIS FTP 8自定義身份驗證授權規則拒絕訪問

[英]IIS FTP 8 Custom Authentication Authorization rules denied the access

我已經使用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:\temp\test";
        }

        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']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM