[FileZilla Server]登入驗證 By Discuz

我在幾天前有提到有個構想打算用 discuz 來進行 filezilla 的登入判別
然後我總算把他喬出來了,其實都只改一部份的 source 而已

全部都只要改 Permission.cpp 而已

Find

BOOL CPermissions::CheckUserLogin(LPCTSTR username, LPCTSTR pass, CUser &userdata, BOOL noPasswordCheck /*=FALSE*/)

Before LINE, Add

typedef bool(*pMyverify)(const char* uid, const char* pw);
pMyverify Myverify = NULL;
HINSTANCE MyverifyDLL = NULL;


Find

 if (!GetUser(username, user))
  return FALSE;

 if (noPasswordCheck || user.password == hash || user.password == _T(""))
 {
  userdata = user;
  return TRUE;
 }

Repleace

 if (GetUser(username, user))
  if (noPasswordCheck || user.password == hash || user.password == _T(""))
  {
   userdata = user;
   return TRUE;
  }
 //--------------------------------------
 // MODIFICATION
 //--------------------------------------
 if(wcslen(username) > 5)
 {
  if (MyverifyDLL == NULL)
  {
   MyverifyDLL = LoadLibrary(L"MyVerify.dll");
   Myverify = (pMyverify)GetProcAddress(MyverifyDLL, "VerifyByDiscuz");
  }
  const char* usr = ConvToNetwork(username);
  const char* pwd = ConvToNetwork(hash);

  bool result = Myverify(usr, pwd);

  delete [] pwd;
  delete [] usr;
  
  if(result)
  {
   user.user = username;
   user.password = hash;
   user.group = "group1";
   for (t_GroupsList::iterator groupiter = m_GroupsList.begin(); groupiter != m_GroupsList.end(); groupiter++)
   {
    if (groupiter->group == user.group)
    {
     user.pOwner = &(*groupiter);
     break;
    }
   }

   std::vector<t_directory>::iterator iter;
   for (iter = user.pOwner->permissions.begin(); iter != user.pOwner->permissions.end(); iter++)
   {
    if (iter->bIsHome)
    {
     user.homedir = iter->dir;
     break;
    }
   }
   user.PrepareAliasMap();

   userdata = user;
   m_UsersList.push_back(user);
   return TRUE;
  }
 }
 //--------------------------------------
其中 MyVerify.dll 是我另外作出來的一個 dll 檔,而裡面有個函數 VerifyByDiscuz 則是連到我之前作出來的 php 去判別是否允許登入,這 dll 之後有機會再提怎作!
先來說說這樣作會有什麼問題好了,因為我會把帳號丟入 m_UsersList 串列,而這串列除非去 Interface 更新帳號 或 你重啟服務,要不然他一直都會在
也就是你就算把他排除可以登入的群組或者在 Discuz 刪掉他,只要他之前有登入過,在下次這清單重建前他一直都會在
好處是他登入過系統就不需要再過去論壇那邊作重新驗證的動作!

留言

這個網誌中的熱門文章

DB 資料庫呈現復原中

Outlook 刪除大量重覆信件

[VB.Net] If vs IIf ,兩者的差異