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 pid_t pid; 00039 proc_done_cb onDone; 00040 InotifyWatch* pWatch; 00041 } ProcData_t; 00042 00044 typedef std::map<int, UserTable*> FDUT_MAP; 00045 00047 typedef std::map<InotifyWatch*, InCronTabEntry*> IWCE_MAP; 00048 00050 typedef std::deque<ProcData_t> PROC_LIST; 00051 00053 00056 class EventDispatcher 00057 { 00058 public: 00060 00066 EventDispatcher(int iPipeFd, Inotify* pIn, InotifyWatch* pSys, InotifyWatch* pUser); 00067 00069 ~EventDispatcher(); 00070 00072 00075 bool ProcessEvents(); 00076 00078 00081 void Register(UserTable* pTab); 00082 00084 00087 void Unregister(UserTable* pTab); 00088 00090 00093 inline size_t GetSize() const 00094 { 00095 return m_size; 00096 } 00097 00099 00102 inline struct pollfd* GetPollData() 00103 { 00104 return m_pPoll; 00105 } 00106 00107 00108 private: 00109 int m_iPipeFd; 00110 int m_iMgmtFd; 00111 Inotify* m_pIn; 00112 InotifyWatch* m_pSys; 00113 InotifyWatch* m_pUser; 00114 FDUT_MAP m_maps; 00115 size_t m_size; 00116 struct pollfd* m_pPoll; 00117 00119 void Rebuild(); 00120 00122 void ProcessMgmtEvents(); 00123 }; 00124 00125 00127 00132 class UserTable 00133 { 00134 public: 00136 00141 UserTable(EventDispatcher* pEd, const std::string& rUser, bool fSysTable); 00142 00144 virtual ~UserTable(); 00145 00147 00152 void Load(); 00153 00155 00159 void Dispose(); 00160 00162 00165 void OnEvent(InotifyEvent& rEvt); 00166 00168 00172 static void FinishDone(); 00173 00175 00182 bool MayAccess(const std::string& rPath, bool fNoFollow) const; 00183 00185 00188 bool IsSystem() const; 00189 00191 00194 Inotify* GetInotify() 00195 { 00196 return &m_in; 00197 } 00198 00200 00210 inline static bool CheckUser(const char* user) 00211 { 00212 struct passwd* pw = getpwnam(user); 00213 if (pw == NULL) 00214 return false; 00215 00216 return InCronTab::CheckUser(user); 00217 } 00218 00219 private: 00220 Inotify m_in; 00221 EventDispatcher* m_pEd; 00222 std::string m_user; 00223 bool m_fSysTable; 00224 InCronTab m_tab; 00225 IWCE_MAP m_map; 00226 00227 static PROC_LIST s_procList; 00228 00230 00234 InCronTabEntry* FindEntry(InotifyWatch* pWatch); 00235 00237 00243 bool PrepareArgs(const std::string& rCmd, int& argc, char**& argv); 00244 00246 00250 void CleanupArgs(int argc, char** argv); 00251 00252 }; 00253 00254 #endif //_USERTABLE_H_