home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 217 / DPCS0306DVD.ISO / Toolkit / Internet / FileZilla / Server / FileZilla_Server-0.9.11.exe / source / Permissions.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-08-29  |  5.9 KB  |  171 lines

  1. // FileZilla Server - a Windows ftp server
  2.  
  3. // Copyright (C) 2002-2004 - Tim Kosse <tim.kosse@gmx.de>
  4.  
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9.  
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. // Permissions.h: Schnittstelle fⁿr die Klasse CPermissions.
  20. //
  21. //////////////////////////////////////////////////////////////////////
  22.  
  23. #if !defined(AFX_PERMISSIONS_H__33DEA50E_AA34_4190_9ACD_355BF3D72FE0__INCLUDED_)
  24. #define AFX_PERMISSIONS_H__33DEA50E_AA34_4190_9ACD_355BF3D72FE0__INCLUDED_
  25.  
  26. #if _MSC_VER > 1000
  27. #pragma once
  28. #endif // _MSC_VER > 1000
  29.  
  30. #include "Accounts.h"
  31.  
  32. #define FOP_READ        0x01
  33. #define FOP_WRITE        0x02
  34. #define FOP_DELETE        0x04
  35. #define FOP_APPEND        0x08
  36. #define FOP_CREATENEW    0x10
  37. #define DOP_DELETE        0x20
  38. #define DOP_CREATE        0x40
  39.  
  40. #define PERMISSION_DENIED            0x01
  41. #define PERMISSION_NOTFOUND            0x02
  42. #define PERMISSION_DIRNOTFILE        (0x04 | PERMISSION_DOESALREADYEXIST)
  43. #define PERMISSION_FILENOTDIR        (0x08 | PERMISSION_DOESALREADYEXIST)
  44. #define PERMISSION_DOESALREADYEXIST    0x10
  45. #define PERMISSION_INVALIDNAME        0x20
  46.  
  47. class CMarkupSTL;
  48. class CPermissionsHelperWindow;
  49. class COptions;
  50.  
  51. class CUser : public t_user
  52. {
  53. public:
  54.     CStdString homedir;
  55.  
  56.     // Replace :u and :g (if a group it exists)
  57.     void DoReplacements(CStdString& path) const;
  58.  
  59.     /*
  60.      * t_alias is used in the alias maps.
  61.      * See implementation of PrepareAliasMap for a detailed
  62.      * description
  63.      */
  64.     struct t_alias
  65.     {
  66.         CStdString targetFolder;
  67.         CStdString name;
  68.     };
  69.  
  70.     void PrepareAliasMap();
  71.  
  72.     // GetAliasTarget returns the target of the alias with the specified
  73.     // path and name or returns an empty string if the alias can't be found.
  74.     CStdString GetAliasTarget(CStdString path, CStdString name) const;
  75.  
  76.     std::multimap<CStdString, t_alias> aliasMap;
  77. };
  78.  
  79. struct t_dirlisting
  80. {
  81.     char buffer[8192];
  82.     unsigned int len;
  83.  
  84.     t_dirlisting *pNext;
  85. };
  86.  
  87. class CPermissions  
  88. {
  89. public:
  90.     CPermissions();
  91.     virtual ~CPermissions();
  92.  
  93. protected:
  94.     /*
  95.      * CanonifyPath takes the current and the new server dir as parameter,
  96.      * concats the paths if neccessary and canonifies the dir:
  97.      * - remove dot-segments
  98.      * - convert backslashes into slashes
  99.      * - remove double slashes
  100.      */
  101.     CStdString CanonifyServerDir(CStdString currentDir, CStdString newDir) const;
  102.  
  103. public:
  104.     // Change current directory to the specified directory. Used by CWD and CDUP
  105.     int ChangeCurrentDir(LPCTSTR username, CStdString& currentdir, CStdString &dir);
  106.     
  107.     // Full directory listing with all details. Used by LIST command
  108.     int GetDirectoryListing(LPCTSTR username, CStdString currentDir,
  109.                             CStdString dirToDisplay, t_dirlisting *&pResult,
  110.                             CStdString& physicalDir, CStdString& logicalDir);
  111.  
  112.     // Directory listing with just the filenames. Used by NLST command
  113.     int GetShortDirectoryListing(LPCTSTR username, CStdString currentDir,
  114.                                  CStdString dirToDisplay, t_dirlisting *&pResult,
  115.                                  CStdString& physicalDir, CStdString& logicalDir);
  116.  
  117.     CStdString GetHomeDir(LPCTSTR username, bool physicalPath = false) const;
  118.     CStdString GetHomeDir(const CUser &user, bool physicalPath = false) const;
  119.  
  120.     int CheckDirectoryPermissions(LPCTSTR username, CStdString dirname, CStdString currentdir, int op, CStdString &physicalDir, CStdString &logicalDir);
  121.     int CheckFilePermissions(LPCTSTR username, CStdString filename, CStdString currentdir, int op, CStdString &physicalDir, CStdString &logicalDir);
  122.  
  123.     BOOL GetUser(CStdString username, CUser &userdata) const;
  124.     BOOL CheckUserLogin(LPCTSTR username, LPCTSTR pass, CUser &userdata, BOOL noPasswordCheck = FALSE);
  125.  
  126.     BOOL GetAsCommand(char **pBuffer, DWORD *nBufferLength);
  127.     BOOL ParseUsersCommand(unsigned char *pData, DWORD dwDataLength);
  128.     void AutoCreateDirs(const char *username);
  129.     void ReloadConfig();
  130.  
  131.     int GetFacts(LPCTSTR username, CStdString currentDir, CStdString file, t_dirlisting *&pResult, CStdString &physicalDir, CStdString &logicalDir);
  132.     int GetFact(LPCTSTR username, CStdString currentDir, CStdString file, CStdString& fact, CStdString& logicalName);
  133.     
  134. protected:
  135.     void AddListingEntry(t_dirlisting *&pDir, CStdString name, bool dir, _int64 size, FILETIME *pTime, const t_directory &perms);
  136.     bool Init();
  137.     void UpdateInstances();
  138.  
  139.     void ReadSettings();
  140.  
  141.     void ReadPermissions(CMarkupSTL *pXML, t_group &user, BOOL &bGotHome);
  142.     void SavePermissions(CMarkupSTL *pXML, const t_group &user);
  143.  
  144.     void ReadSpeedLimits(CMarkupSTL *pXML, t_group &group);
  145.     void SaveSpeedLimits(CMarkupSTL *pXML, const t_group &group);
  146.  
  147.     void ReadIpFilter(CMarkupSTL *pXML, t_group &group);
  148.     void SaveIpFilter(CMarkupSTL *pXML, const t_group &group);
  149.  
  150.     void SetKey(CMarkupSTL *pXML, LPCTSTR name, LPCTSTR value);
  151.     void SetKey(CMarkupSTL *pXML, LPCTSTR name, int value);
  152.     
  153.     int GetRealDirectory(CStdString directory, const CUser &user, t_directory &ret, BOOL &truematch);
  154.  
  155.     static CCriticalSectionWrapper m_sync;
  156.     
  157.     typedef std::vector<CUser> t_UsersList; 
  158.     typedef std::vector<t_group> t_GroupsList; 
  159.     static t_UsersList m_sUsersList;
  160.     static t_GroupsList m_sGroupsList;
  161.     t_UsersList m_UsersList;
  162.     t_GroupsList m_GroupsList;
  163.     
  164.     static std::list<CPermissions *> m_sInstanceList;
  165.     CPermissionsHelperWindow *m_pPermissionsHelperWindow;
  166.  
  167.     friend CPermissionsHelperWindow;
  168. };
  169.  
  170. #endif // !defined(AFX_PERMISSIONS_H__33DEA50E_AA34_4190_9ACD_355BF3D72FE0__INCLUDED_)
  171.