Subversion Repositories public

Rev

Rev 65 | Rev 69 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 65 Rev 67
Line 16... Line 16...
16
#ifndef _USERTABLE_H_
16
#ifndef _USERTABLE_H_
17
#define _USERTABLE_H_
17
#define _USERTABLE_H_
18
18
19
#include <map>
19
#include <map>
20
#include <deque>
20
#include <deque>
-
 
21
#include <sys/poll.h>
21
22
22
#include "inotify-cxx.h"
23
#include "inotify-cxx.h"
23
#include "incrontab.h"
24
#include "incrontab.h"
24
25
25
26
26
class UserTable;
27
class UserTable;
27
28
-
 
29
/// User name to user table mapping definition
-
 
30
typedef std::map<std::string, UserTable*> SUT_MAP;
-
 
31
28
/// Callback for calling after a process finishes.
32
/// Callback for calling after a process finishes.
29
typedef void (*proc_done_cb)(InotifyWatch*);
33
typedef void (*proc_done_cb)(InotifyWatch*);
30
34
31
/// Child process data
35
/// Child process data
32
typedef struct
36
typedef struct
Line 34... Line 38...
34
  pid_t pid;            ///< PID
38
  pid_t pid;            ///< PID
35
  proc_done_cb onDone;  ///< function called after process finishes
39
  proc_done_cb onDone;  ///< function called after process finishes
36
  InotifyWatch* pWatch; ///< related watch
40
  InotifyWatch* pWatch; ///< related watch
37
} ProcData_t;
41
} ProcData_t;
38
42
39
/// Watch-to-usertable mapping
43
/// fd-to-usertable mapping
40
typedef std::map<InotifyWatch*, UserTable*> IWUT_MAP;
44
typedef std::map<int, UserTable*> FDUT_MAP;
41
45
42
/// Watch-to-tableentry mapping
46
/// Watch-to-tableentry mapping
43
typedef std::map<InotifyWatch*, InCronTabEntry*> IWCE_MAP;
47
typedef std::map<InotifyWatch*, InCronTabEntry*> IWCE_MAP;
44
48
45
/// Child process list
49
/// Child process list
46
typedef std::deque<ProcData_t> PROC_LIST;
50
typedef std::deque<ProcData_t> PROC_LIST;
47
51
48
/// Event dispatcher class.
52
/// Event dispatcher class.
49
/**
53
/**
50
 * This class distributes inotify events to appropriate user tables.
54
 * This class processes events and distributes them as needed.
51
 */
55
 */
52
class EventDispatcher
56
class EventDispatcher
53
{
57
{
54
public:
58
public:
55
  /// Constructor.
59
  /// Constructor.
56
  /**
60
  /**
-
 
61
   * \param[in] iPipeFd pipe descriptor
57
   * \param[in] pIn inotify object
62
   * \param[in] pIn inotify object for table management
-
 
63
   * \param[in] pSys watch for system tables
-
 
64
   * \param[in] pUser watch for user tables
58
   */
65
   */
59
  EventDispatcher(Inotify* pIn);
66
  EventDispatcher(int iPipeFd, Inotify* pIn, InotifyWatch* pSys, InotifyWatch* pUser);
60
 
67
 
61
  /// Destructor.
68
  /// Destructor.
62
  ~EventDispatcher() {}
69
  ~EventDispatcher();
63
70
64
  /// Dispatches an event.
71
  /// Processes events.
65
  /**
72
  /**
66
   * \param[in] rEvt inotify event
73
   * \return pipe event occurred yes/no
67
   */
74
   */
68
  void DispatchEvent(InotifyEvent& rEvt);
75
  bool ProcessEvents();
69
 
76
 
70
  /// Registers a watch for an user table.
77
  /// Registers an user table.
71
  /**
78
  /**
72
   * \param[in] pWatch inotify watch
-
 
73
   * \param[in] pTab user table
79
   * \param[in] pTab user table
74
   */
80
   */
75
  void Register(InotifyWatch* pWatch, UserTable* pTab);
81
  void Register(UserTable* pTab);
76
 
82
 
77
  /// Unregisters a watch.
83
  /// Unregisters an user table.
78
  /**
84
  /**
79
   * \param[in] pWatch inotify watch
85
   * \param[in] pTab user table
80
   */
86
   */
81
  void Unregister(InotifyWatch* pWatch);
87
  void Unregister(UserTable* pTab);
82
 
88
 
83
  /// Unregisters all watches for an user table.
89
  /// Returns the poll data size.
84
  /**
90
  /**
85
   * \param[in] pTab user table
91
   * \return poll data size
86
   */
92
   */
87
  void UnregisterAll(UserTable* pTab);
93
  inline size_t GetSize() const
88
 
94
  {
89
private:
-
 
90
  Inotify* m_pIn;   ///< inotify object
95
    return m_size;
91
  IWUT_MAP m_maps;  ///< watch-to-usertable mapping
-
 
-
 
96
  }
92
 
97
 
93
  /// Finds an user table for a watch.
98
  /// Returns the poll data.
94
  /**
99
  /**
95
   * \param[in] pW inotify watch
100
   * \return poll data
96
   * \return pointer to the appropriate watch; NULL if no such watch exists
-
 
97
   */
101
   */
-
 
102
  inline struct pollfd* GetPollData()
-
 
103
  {
-
 
104
    return m_pPoll;
-
 
105
  }
-
 
106
 
-
 
107
 
-
 
108
private:
-
 
109
  int m_iPipeFd;    ///< pipe file descriptor
-
 
110
  int m_iMgmtFd;    ///< table management file descriptor
-
 
111
  Inotify* m_pIn;   ///< table management inotify object 
-
 
112
  InotifyWatch* m_pSys;   ///< watch for system tables
-
 
113
  InotifyWatch* m_pUser;  ///< watch for user tables 
-
 
114
  FDUT_MAP m_maps;  ///< watch-to-usertable mapping
-
 
115
  size_t m_size;    ///< poll data size
-
 
116
  struct pollfd* m_pPoll; ///< poll data array
-
 
117
 
98
  UserTable* FindTable(InotifyWatch* pW);
118
  /// Rebuilds the poll array data.
-
 
119
  void Rebuild();
-
 
120
 
-
 
121
  /// Processes events on the table management inotify object. 
-
 
122
  void ProcessMgmtEvents();
99
};
123
};
100
124
101
125
102
/// User table class.
126
/// User table class.
103
/**
127
/**
Line 108... Line 132...
108
class UserTable
132
class UserTable
109
{
133
{
110
public:
134
public:
111
  /// Constructor.
135
  /// Constructor.
112
  /**
136
  /**
113
   * \param[in] pIn inotify object
-
 
114
   * \param[in] pEd event dispatcher
137
   * \param[in] pEd event dispatcher
115
   * \param[in] rUser user name
138
   * \param[in] rUser user name
-
 
139
   * \param[in] fSysTable system table yes/no
116
   */
140
   */
117
        UserTable(Inotify* pIn, EventDispatcher* pEd, const std::string& rUser);
141
        UserTable(EventDispatcher* pEd, const std::string& rUser, bool fSysTable);
118
 
142
 
119
  /// Destructor.
143
  /// Destructor.
120
        virtual ~UserTable();
144
        virtual ~UserTable();
121
 
145
 
122
  /// Loads the table.
146
  /// Loads the table.
Line 155... Line 179...
155
   * \param[in] fNoFollow don't follow a symbolic link
179
   * \param[in] fNoFollow don't follow a symbolic link
156
   * \return true = access granted, false = otherwise
180
   * \return true = access granted, false = otherwise
157
   */
181
   */
158
  bool MayAccess(const std::string& rPath, bool fNoFollow) const;
182
  bool MayAccess(const std::string& rPath, bool fNoFollow) const;
159
 
183
 
-
 
184
  /// Checks whether it is a system table.
-
 
185
  /**
-
 
186
   * \return true = system table, false = user table
-
 
187
   */
-
 
188
  bool IsSystem() const;
-
 
189
 
-
 
190
  /// Returns the related inotify object.
-
 
191
  /**
-
 
192
   * \return related inotify object
-
 
193
   */
-
 
194
  Inotify* GetInotify()
-
 
195
  {
-
 
196
    return &m_in;
-
 
197
  }
-
 
198
 
-
 
199
  /// Checks whether an user exists and has permission to use incron.
-
 
200
  /**
-
 
201
   * It searches for the given user name in the user database.
-
 
202
   * If it failes it returns 'false'. Otherwise it checks
-
 
203
   * permission files for this user (see InCronTab::CheckUser()).
-
 
204
   *
-
 
205
   * \param[in] user user name
-
 
206
   * \return true = user has permission to use incron, false = otherwise
-
 
207
   *
-
 
208
   * \sa InCronTab::CheckUser()
-
 
209
   */
-
 
210
  inline static bool CheckUser(const char* user)
-
 
211
  {
-
 
212
    struct passwd* pw = getpwnam(user);
-
 
213
    if (pw == NULL)
-
 
214
      return false;
-
 
215
     
-
 
216
    return InCronTab::CheckUser(user);
-
 
217
  }
-
 
218
 
160
private:
219
private:
161
  Inotify* m_pIn;         ///< inotify object
220
  Inotify m_in;           ///< inotify object
162
  EventDispatcher* m_pEd; ///< event dispatcher
221
  EventDispatcher* m_pEd; ///< event dispatcher
163
  std::string m_user;     ///< user name
222
  std::string m_user;     ///< user name
-
 
223
  bool m_fSysTable;       ///< system table yes/no
164
  InCronTab m_tab;        ///< incron table
224
  InCronTab m_tab;        ///< incron table
165
  IWCE_MAP m_map;         ///< watch-to-entry mapping
225
  IWCE_MAP m_map;         ///< watch-to-entry mapping
166
226
167
  static PROC_LIST s_procList;  ///< child process list
227
  static PROC_LIST s_procList;  ///< child process list
168
 
228