Subversion Repositories public

Rev

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

Rev 51 Rev 55
Line 20... Line 20...
20
#include <stdio.h>
20
#include <stdio.h>
21
#include <unistd.h>
21
#include <unistd.h>
22
#include <sys/stat.h>
22
#include <sys/stat.h>
23
#include <sys/wait.h>
23
#include <sys/wait.h>
24
24
-
 
25
#include "incron.h"
25
#include "incrontab.h"
26
#include "incrontab.h"
26
27
27
28
28
// #define INCRON_DEFAULT_EDITOR "nano" // for vim haters like me ;-)
29
// #define INCRON_DEFAULT_EDITOR "nano" // for vim haters like me ;-)
29
#define INCRON_DEFAULT_EDITOR "vim"
30
#define INCRON_DEFAULT_EDITOR "vim"
30
31
31
32
32
const char* argp_program_version = "incrontab 0.2.2";
33
const char* argp_program_version = INCRON_TAB_NAME " " INCRON_VERSION;
33
const char* argp_program_bug_address = "<bugs@aiken.cz>";
34
const char* argp_program_bug_address = INCRON_BUG_ADDRESS;
34
35
35
static char doc[] = "Table manipulator for incrond (inotify cron daemon)";
36
static char doc[] = "incrontab - incron table manipulator";
36
37
37
static char args_doc[] = "FILE";
38
static char args_doc[] = "FILE";
38
39
39
static struct argp_option options[] = {
40
static struct argp_option options[] = {
40
  {"list",    'l', 0,      0,  "List current table" },
41
  {"list",    'l', 0,      0,  "List the current table" },
41
  {"remove",  'r', 0,      0,  "Remove table completely" },
42
  {"remove",  'r', 0,      0,  "Remove the table completely" },
42
  {"edit",    'e', 0,      0,  "Edit table" },
43
  {"edit",    'e', 0,      0,  "Edit the table" },
43
  {"user",    'u', "USER", 0,  "Override current user" },
44
  {"user",    'u', "USER", 0,  "Override the current user" },
44
  { 0 }
45
  { 0 }
45
};
46
};
46
47
47
/// incrontab operations
48
/// incrontab operations
48
typedef enum
49
typedef enum
Line 111... Line 112...
111
 */
112
 */
112
void unlink_suid(const char* file, uid_t uid)
113
void unlink_suid(const char* file, uid_t uid)
113
{
114
{
114
  uid_t iu = geteuid();
115
  uid_t iu = geteuid();
115
  seteuid(uid);
116
  seteuid(uid);
116
  unlink(file);
117
  if (unlink(file) != 0)
-
 
118
    perror("cannot remove temporary file");
117
  seteuid(iu);
119
  seteuid(iu);
118
}
120
}
119
121
120
/// Copies a file to an user table.
122
/// Copies a file to an user table.
121
/**
123
/**
Line 209... Line 211...
209
 
211
 
210
  char s[NAME_MAX];
212
  char s[NAME_MAX];
211
  strcpy(s, "/tmp/incron.table-XXXXXX");
213
  strcpy(s, "/tmp/incron.table-XXXXXX");
212
 
214
 
213
  uid_t iu = geteuid();
215
  uid_t iu = geteuid();
214
 
216
215
  if (seteuid(uid) != 0) {
217
  if (seteuid(uid) != 0) {
216
    fprintf(stderr, "cannot change effective UID: %s\n", strerror(errno));
218
    fprintf(stderr, "cannot change effective UID to %i: %s\n", (int) uid, strerror(errno));
217
    return false;
219
    return false;
218
  }
220
  }
219
 
221
 
220
  int fd = mkstemp(s);
222
  int fd = mkstemp(s);
221
  if (fd == -1) {
223
  if (fd == -1) {