Mirror of git://git.busybox.net/busybox with our patches on top
Source
xxxxxxxxxx
if ((fd = open(path, O_CREAT|O_TRUNC|O_APPEND|O_WRONLY, 0600)) >= 0) {
/*
* CRONTAB
*
* usually setuid root, -c option only works if getuid() == geteuid()
*
* Copyright 1994 Matthew Dillon (dillon@apollo.west.oic.com)
* May be distributed under the GNU General Public License
*
* Vladimir Oleynik <dzo@simtreas.ru> (C) 2002 to be used in busybox
*
*/
/* location of vi */
static const char *CDir = CRONTABS;
static void EditFile(const char *user, const char *file);
static int GetReplaceStream(const char *user, const char *file);
static int ChangeUser(const char *user, short dochdir);
int
crontab_main(int ac, char **av)
{
enum { NONE, EDIT, LIST, REPLACE, DELETE } option = NONE;
const struct passwd *pas;
const char *repFile = NULL;
int repFd = 0;
int i;
char caller[256]; /* user that ran program */
int UserId;
UserId = getuid();
if ((pas = getpwuid(UserId)) == NULL)
bb_perror_msg_and_die("getpwuid");
strncpy(caller, pas->pw_name, sizeof(caller));
i = 1;
if (ac > 1) {
if (av[1][0] == '-' && av[1][1] == 0) {
option = REPLACE;
++i;
} else if (av[1][0] != '-') {
option = REPLACE;
++i;
repFile = av[1];
}
}
for (; i < ac; ++i) {
char *ptr = av[i];
if (*ptr != '-')
break;
ptr += 2;
switch(ptr[-1]) {
case 'l':
if (ptr[-1] == 'l')
option = LIST;
/* fall through */
case 'e':