crontab: we indent using tabs
This commit is contained in:
@ -39,10 +39,12 @@ int crontab_main(int ac, char **av)
|
||||
int repFd = 0;
|
||||
int i;
|
||||
char caller[256]; /* user that ran program */
|
||||
char buf[1024];
|
||||
int UserId;
|
||||
|
||||
UserId = getuid();
|
||||
if ((pas = getpwuid(UserId)) == NULL)
|
||||
pas = getpwuid(UserId);
|
||||
if (pas == NULL)
|
||||
bb_perror_msg_and_die("getpwuid");
|
||||
|
||||
safe_strncpy(caller, pas->pw_name, sizeof(caller));
|
||||
@ -66,7 +68,7 @@ int crontab_main(int ac, char **av)
|
||||
break;
|
||||
ptr += 2;
|
||||
|
||||
switch(ptr[-1]) {
|
||||
switch (ptr[-1]) {
|
||||
case 'l':
|
||||
if (ptr[-1] == 'l')
|
||||
option = LIST;
|
||||
@ -113,7 +115,8 @@ int crontab_main(int ac, char **av)
|
||||
* Get password entry
|
||||
*/
|
||||
|
||||
if ((pas = getpwuid(UserId)) == NULL)
|
||||
pas = getpwuid(UserId);
|
||||
if (pas == NULL)
|
||||
bb_perror_msg_and_die("getpwuid");
|
||||
|
||||
/*
|
||||
@ -136,13 +139,13 @@ int crontab_main(int ac, char **av)
|
||||
* Handle options as appropriate
|
||||
*/
|
||||
|
||||
switch(option) {
|
||||
switch (option) {
|
||||
case LIST:
|
||||
{
|
||||
FILE *fi;
|
||||
char buf[1024];
|
||||
|
||||
if ((fi = fopen(pas->pw_name, "r"))) {
|
||||
fi = fopen(pas->pw_name, "r");
|
||||
if (fi) {
|
||||
while (fgets(buf, sizeof(buf), fi) != NULL)
|
||||
fputs(buf, stdout);
|
||||
fclose(fi);
|
||||
@ -157,12 +160,12 @@ int crontab_main(int ac, char **av)
|
||||
int fd;
|
||||
int n;
|
||||
char tmp[128];
|
||||
char buf[1024];
|
||||
|
||||
snprintf(tmp, sizeof(tmp), TMPDIR "/crontab.%d", getpid());
|
||||
fd = xopen3(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600);
|
||||
chown(tmp, getuid(), getgid());
|
||||
if ((fi = fopen(pas->pw_name, "r"))) {
|
||||
fi = fopen(pas->pw_name, "r");
|
||||
if (fi) {
|
||||
while ((n = fread(buf, 1, sizeof(buf), fi)) > 0)
|
||||
write(fd, buf, n);
|
||||
}
|
||||
@ -175,13 +178,13 @@ int crontab_main(int ac, char **av)
|
||||
/* fall through */
|
||||
case REPLACE:
|
||||
{
|
||||
char buf[1024];
|
||||
char path[1024];
|
||||
int fd;
|
||||
int n;
|
||||
|
||||
snprintf(path, sizeof(path), "%s.new", pas->pw_name);
|
||||
if ((fd = open(path, O_CREAT|O_TRUNC|O_APPEND|O_WRONLY, 0600)) >= 0) {
|
||||
fd = open(path, O_CREAT|O_TRUNC|O_APPEND|O_WRONLY, 0600);
|
||||
if (fd >= 0) {
|
||||
while ((n = read(repFd, buf, sizeof(buf))) > 0) {
|
||||
write(fd, buf, n);
|
||||
}
|
||||
@ -237,11 +240,12 @@ static int GetReplaceStream(const char *user, const char *file)
|
||||
|
||||
if (pipe(filedes) < 0) {
|
||||
perror("pipe");
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
if ((pid = fork()) < 0) {
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
perror("fork");
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
if (pid > 0) {
|
||||
/*
|
||||
@ -253,7 +257,7 @@ static int GetReplaceStream(const char *user, const char *file)
|
||||
close(filedes[0]);
|
||||
filedes[0] = -1;
|
||||
}
|
||||
return(filedes[0]);
|
||||
return filedes[0];
|
||||
}
|
||||
|
||||
/*
|
||||
@ -277,9 +281,9 @@ static int GetReplaceStream(const char *user, const char *file)
|
||||
|
||||
static void EditFile(const char *user, const char *file)
|
||||
{
|
||||
int pid;
|
||||
int pid = fork();
|
||||
|
||||
if ((pid = fork()) == 0) {
|
||||
if (pid == 0) {
|
||||
/*
|
||||
* CHILD - change user and run editor
|
||||
*/
|
||||
@ -288,7 +292,8 @@ static void EditFile(const char *user, const char *file)
|
||||
|
||||
if (ChangeUser(user, 1) < 0)
|
||||
exit(0);
|
||||
if ((ptr = getenv("VISUAL")) == NULL || strlen(ptr) > 256)
|
||||
ptr = getenv("VISUAL");
|
||||
if (ptr == NULL || strlen(ptr) > 256)
|
||||
ptr = PATH_VI;
|
||||
|
||||
snprintf(visual, sizeof(visual), "%s %s", ptr, file);
|
||||
@ -313,9 +318,9 @@ static int ChangeUser(const char *user, short dochdir)
|
||||
* Obtain password entry and change privileges
|
||||
*/
|
||||
|
||||
if ((pas = getpwnam(user)) == NULL) {
|
||||
pas = getpwnam(user);
|
||||
if (pas == NULL) {
|
||||
bb_perror_msg_and_die("failed to get uid for %s", user);
|
||||
return(-1);
|
||||
}
|
||||
setenv("USER", pas->pw_name, 1);
|
||||
setenv("HOME", pas->pw_dir, 1);
|
||||
@ -328,9 +333,9 @@ static int ChangeUser(const char *user, short dochdir)
|
||||
|
||||
if (dochdir) {
|
||||
if (chdir(pas->pw_dir) < 0) {
|
||||
bb_perror_msg("chdir failed: %s %s", user, pas->pw_dir);
|
||||
bb_perror_msg("chdir(%s) by %s failed", pas->pw_dir, user);
|
||||
xchdir(TMPDIR);
|
||||
}
|
||||
}
|
||||
return(pas->pw_uid);
|
||||
return pas->pw_uid;
|
||||
}
|
||||
|
Reference in New Issue
Block a user