Subversion Repositories public

Rev

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

Rev 67 Rev 69
Line 19... Line 19...
19
#include <errno.h>
19
#include <errno.h>
20
20
21
#include "inotify-cxx.h"
21
#include "inotify-cxx.h"
22
22
23
#include "incrontab.h"
23
#include "incrontab.h"
-
 
24
#include "incroncfg.h"
24
25
25
26
/*
26
/// Allowed users
27
/// Allowed users
27
#define INCRON_ALLOW_PATH "/etc/incron.allow"
28
#define INCRON_ALLOW_PATH "/etc/incron.allow"
28
29

29
/// Denied users
30
/// Denied users
30
#define INCRON_DENY_PATH "/etc/incron.deny"
31
#define INCRON_DENY_PATH "/etc/incron.deny"
-
 
32
*/
31
33
32
/*
34
/*
33
 * ALLOW/DENY SEMANTICS
35
 * ALLOW/DENY SEMANTICS
34
 *
36
 *
35
 * If /etc/incron.allow exists ONLY users contained here
37
 * If /etc/incron.allow exists ONLY users contained here
Line 42... Line 44...
42
 *
44
 *
43
 */
45
 */
44
46
45
47
46
48
47
InCronTabEntry::InCronTabEntry()
49
IncronTabEntry::IncronTabEntry()
48
: m_uMask(0),
50
: m_uMask(0),
49
  m_fNoLoop(false)
51
  m_fNoLoop(false)
50
{
52
{
51
 
53
 
52
}
54
}
53
55
54
InCronTabEntry::InCronTabEntry(const std::string& rPath, uint32_t uMask, const std::string& rCmd)
56
IncronTabEntry::IncronTabEntry(const std::string& rPath, uint32_t uMask, const std::string& rCmd)
55
: m_path(rPath),
57
: m_path(rPath),
56
  m_uMask(uMask),
58
  m_uMask(uMask),
57
  m_cmd(rCmd)
59
  m_cmd(rCmd)
58
{
60
{
59
 
61
 
60
}
62
}
61
63
62
std::string InCronTabEntry::ToString() const
64
std::string IncronTabEntry::ToString() const
63
{
65
{
64
  std::ostringstream ss;
66
  std::ostringstream ss;
65
 
67
 
66
  std::string m;
68
  std::string m;
67
 
69
 
Line 76... Line 78...
76
 
78
 
77
  ss << GetSafePath(m_path) << " " << m << " " << m_cmd;
79
  ss << GetSafePath(m_path) << " " << m << " " << m_cmd;
78
  return ss.str();
80
  return ss.str();
79
}
81
}
80
82
81
bool InCronTabEntry::Parse(const std::string& rStr, InCronTabEntry& rEntry)
83
bool IncronTabEntry::Parse(const std::string& rStr, IncronTabEntry& rEntry)
82
{
84
{
83
  unsigned long u;
85
  unsigned long u;
84
  std::string s1, s2, s3;
86
  std::string s1, s2, s3;
85
 
87
 
86
  StringTokenizer tok(rStr, ' ', '\\');
88
  StringTokenizer tok(rStr, ' ', '\\');
Line 121... Line 123...
121
  }
123
  }
122
 
124
 
123
  return true;
125
  return true;
124
}
126
}
125
127
126
std::string InCronTabEntry::GetSafePath(const std::string& rPath)
128
std::string IncronTabEntry::GetSafePath(const std::string& rPath)
127
{
129
{
128
  std::ostringstream stream;
130
  std::ostringstream stream;
129
 
131
 
130
  SIZE len = rPath.length();
132
  SIZE len = rPath.length();
131
  for (SIZE i = 0; i < len; i++) {
133
  for (SIZE i = 0; i < len; i++) {
Line 141... Line 143...
141
  }
143
  }
142
 
144
 
143
  return stream.str();
145
  return stream.str();
144
}
146
}
145
147
146
bool InCronTab::Load(const std::string& rPath)
148
bool IncronTab::Load(const std::string& rPath)
147
{
149
{
148
  m_tab.clear();
150
  m_tab.clear();
149
 
151
 
150
  FILE* f = fopen(rPath.c_str(), "r");
152
  FILE* f = fopen(rPath.c_str(), "r");
151
  if (f == NULL)
153
  if (f == NULL)
152
    return false;
154
    return false;
153
 
155
 
154
  char s[1000];
156
  char s[1000];
155
  InCronTabEntry e;
157
  IncronTabEntry e;
156
  while (fgets(s, 1000, f) != NULL) {
158
  while (fgets(s, 1000, f) != NULL) {
157
    if (InCronTabEntry::Parse(s, e)) {
159
    if (IncronTabEntry::Parse(s, e)) {
158
      m_tab.push_back(e);
160
      m_tab.push_back(e);
159
    }
161
    }
160
  }
162
  }
161
 
163
 
162
  fclose(f);
164
  fclose(f);
163
 
165
 
164
  return true;
166
  return true;
165
}
167
}
166
168
167
bool InCronTab::Save(const std::string& rPath)
169
bool IncronTab::Save(const std::string& rPath)
168
{
170
{
169
  FILE* f = fopen(rPath.c_str(), "w");
171
  FILE* f = fopen(rPath.c_str(), "w");
170
  if (f == NULL)
172
  if (f == NULL)
171
    return false;
173
    return false;
172
 
174
 
173
  std::deque<InCronTabEntry>::iterator it = m_tab.begin();
175
  std::deque<IncronTabEntry>::iterator it = m_tab.begin();
174
  while (it != m_tab.end()) {
176
  while (it != m_tab.end()) {
175
    fputs((*it).ToString().c_str(), f);
177
    fputs((*it).ToString().c_str(), f);
176
    fputs("\n", f);
178
    fputs("\n", f);
177
    it++;
179
    it++;
178
  }
180
  }
Line 180... Line 182...
180
  fclose(f);
182
  fclose(f);
181
 
183
 
182
  return true;
184
  return true;
183
}
185
}
184
186
185
bool InCronTab::CheckUser(const std::string& rUser)
187
bool IncronTab::CheckUser(const std::string& rUser)
186
{
188
{
187
  char s[100], u[100];
189
  char s[100], u[100];
188
 
190
 
-
 
191
  std::string path;
-
 
192
  if (!IncronCfg::GetValue("allowed_users", path))
-
 
193
    throw InotifyException("configuration is corrupted", EINVAL);
-
 
194
 
189
  FILE* f = fopen(INCRON_ALLOW_PATH, "r");
195
  FILE* f = fopen(path.c_str(), "r");
190
  if (f == NULL) {
196
  if (f == NULL) {
191
    if (errno == ENOENT) {
197
    if (errno == ENOENT) {
-
 
198
      if (!IncronCfg::GetValue("denied_users", path))
-
 
199
        throw InotifyException("configuration is corrupted", EINVAL);
-
 
200
     
192
      f = fopen(INCRON_DENY_PATH, "r");
201
      f = fopen(path.c_str(), "r");
193
      if (f == NULL) {
202
      if (f == NULL) {
194
        return errno == ENOENT;
203
        return errno == ENOENT;
195
      }
204
      }
196
      while (fgets(s, 100, f) != NULL) {
205
      while (fgets(s, 100, f) != NULL) {
197
        if (sscanf(s, "%s", u) == 1) {
206
        if (sscanf(s, "%s", u) == 1) {
Line 219... Line 228...
219
 
228
 
220
  fclose(f);
229
  fclose(f);
221
  return false;
230
  return false;
222
}
231
}
223
232
224
std::string InCronTab::GetUserTablePath(const std::string& rUser)
233
std::string IncronTab::GetUserTablePath(const std::string& rUser)
225
{
234
{
226
  std::string s(INCRON_USER_TABLE_BASE);
235
  std::string s;
227
  s.append(rUser);
236
  if (!IncronCfg::GetValue("user_table_dir", s))
-
 
237
    throw InotifyException("configuration is corrupted", EINVAL);
-
 
238
   
228
  return s;
239
  return IncronCfg::BuildPath(s, rUser);
229
}
240
}
230
241
231
std::string InCronTab::GetSystemTablePath(const std::string& rName)
242
std::string IncronTab::GetSystemTablePath(const std::string& rName)
232
{
243
{
233
  std::string s(INCRON_SYS_TABLE_BASE);
244
  std::string s;
234
  s.append(rName);
245
  if (!IncronCfg::GetValue("system_table_dir", s))
-
 
246
    throw InotifyException("configuration is corrupted", EINVAL);
-
 
247
   
235
  return s;
248
  return IncronCfg::BuildPath(s, rName);
236
}
249
}
237
250
238
251
239
252