usertable.h

Go to the documentation of this file.
00001 
00003 
00016 #ifndef _USERTABLE_H_
00017 #define _USERTABLE_H_
00018 
00019 #include <map>
00020 #include <deque>
00021 #include <sys/poll.h>
00022 
00023 #include "inotify-cxx.h"
00024 #include "incrontab.h"
00025 
00026 
00027 class UserTable;
00028 
00030 typedef std::map<std::string, UserTable*> SUT_MAP;
00031 
00033 typedef void (*proc_done_cb)(InotifyWatch*);
00034 
00036 typedef struct
00037 {
00038   proc_done_cb onDone;  
00039   InotifyWatch* pWatch; 
00040 } ProcData_t;
00041 
00043 typedef std::map<int, UserTable*> FDUT_MAP;
00044 
00046 typedef std::map<InotifyWatch*, IncronTabEntry*> IWCE_MAP;
00047 
00049 typedef std::map<pid_t, ProcData_t> PROC_MAP;
00050 
00052 
00055 class EventDispatcher
00056 {
00057 public:
00059 
00065   EventDispatcher(int iPipeFd, Inotify* pIn, InotifyWatch* pSys, InotifyWatch* pUser);
00066   
00068   ~EventDispatcher();
00069 
00071 
00074   bool ProcessEvents();
00075   
00077 
00080   void Register(UserTable* pTab);
00081   
00083 
00086   void Unregister(UserTable* pTab);
00087   
00089 
00092   inline size_t GetSize() const
00093   {
00094     return m_size;
00095   }
00096   
00098 
00101   inline struct pollfd* GetPollData()
00102   {
00103     return m_pPoll;
00104   }
00105   
00106   
00107 private:
00108   int m_iPipeFd;    
00109   int m_iMgmtFd;    
00110   Inotify* m_pIn;   
00111   InotifyWatch* m_pSys;   
00112   InotifyWatch* m_pUser;  
00113   FDUT_MAP m_maps;  
00114   size_t m_size;    
00115   struct pollfd* m_pPoll; 
00116   
00118   void Rebuild();
00119   
00121   void ProcessMgmtEvents();
00122 };
00123 
00124 
00126 
00131 class UserTable
00132 {
00133 public:
00135 
00140         UserTable(EventDispatcher* pEd, const std::string& rUser, bool fSysTable);
00141   
00143         virtual ~UserTable();
00144   
00146 
00151   void Load();
00152   
00154 
00158   void Dispose();
00159   
00161 
00164   void OnEvent(InotifyEvent& rEvt);
00165   
00167 
00171   static void FinishDone();
00172   
00174 
00181   bool MayAccess(const std::string& rPath, bool fNoFollow) const;
00182   
00184 
00187   bool IsSystem() const;
00188   
00190 
00193   Inotify* GetInotify()
00194   {
00195     return &m_in;
00196   }
00197   
00199 
00209   inline static bool CheckUser(const char* user)
00210   {
00211     struct passwd* pw = getpwnam(user);
00212     if (pw == NULL)
00213       return false;
00214       
00215     return IncronTab::CheckUser(user);
00216   }
00217   
00218 private:
00219   Inotify m_in;           
00220   EventDispatcher* m_pEd; 
00221   std::string m_user;     
00222   bool m_fSysTable;       
00223   IncronTab m_tab;        
00224   IWCE_MAP m_map;         
00225 
00226   static PROC_MAP s_procMap;  
00227   
00229 
00233   IncronTabEntry* FindEntry(InotifyWatch* pWatch);
00234   
00236 
00242   bool PrepareArgs(const std::string& rCmd, int& argc, char**& argv);
00243   
00245 
00249   void CleanupArgs(int argc, char** argv);
00250   
00251 };
00252 
00253 #endif //_USERTABLE_H_

Generated on Sat Jan 27 21:05:47 2007 for incron by  doxygen 1.5.1