summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-02-17 14:30:03 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-02-17 14:30:03 +0000
commit03b4c14bd4815f7d0f4b91d90985dfcd8a352025 (patch)
treee22013535132cf276facc5946e346bc38f277474
parentb3b0753593abaf307c961bd45f5e2385a852a076 (diff)
downloadbusybox-w32-03b4c14bd4815f7d0f4b91d90985dfcd8a352025.tar.gz
busybox-w32-03b4c14bd4815f7d0f4b91d90985dfcd8a352025.tar.bz2
busybox-w32-03b4c14bd4815f7d0f4b91d90985dfcd8a352025.zip
crontab: stop using remove() - use unlink() instead
-rw-r--r--miscutils/crontab.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/miscutils/crontab.c b/miscutils/crontab.c
index a1fe2c5a5..bc7f56a22 100644
--- a/miscutils/crontab.c
+++ b/miscutils/crontab.c
@@ -65,33 +65,26 @@ static void edit_file(const struct passwd *pas, const char *file)
65 65
66static int open_as_user(const struct passwd *pas, const char *file) 66static int open_as_user(const struct passwd *pas, const char *file)
67{ 67{
68 struct fd_pair filedes;
69 pid_t pid; 68 pid_t pid;
70 char c; 69 char c;
71 70
72 xpiped_pair(filedes);
73 pid = vfork(); 71 pid = vfork();
74 if (pid < 0) /* ERROR */ 72 if (pid < 0) /* ERROR */
75 bb_perror_msg_and_die("vfork"); 73 bb_perror_msg_and_die("vfork");
76 if (pid) { /* PARENT */ 74 if (pid) { /* PARENT */
77 int n = safe_read(filedes.rd, &c, 1); 75 if (wait4pid(pid) == 0) {
78 close(filedes.rd); 76 /* exitcode 0: child says it can read */
79 close(filedes.wr);
80 if (n > 0) /* child says it can read */
81 return open(file, O_RDONLY); 77 return open(file, O_RDONLY);
78 }
82 return -1; 79 return -1;
83 } 80 }
84 81
85 /* CHILD */ 82 /* CHILD */
86
87 /* initgroups, setgid, setuid */ 83 /* initgroups, setgid, setuid */
88 change_identity(pas); 84 change_identity(pas);
89 85 /* We just try to read one byte. If it works, file is readable
90 /* We just try to read one byte. If that works, file is readable 86 * under this user. We signal that by exiting with 0. */
91 * under this user. We signal that by sending one byte to parent. */ 87 _exit(safe_read(xopen(file, O_RDONLY), &c, 1) < 0);
92 if (safe_read(xopen(file, O_RDONLY), &c, 1) == 1)
93 safe_write(filedes.wr, &c, 1); /* "papa, I can read!" */
94 _exit(0);
95} 88}
96 89
97int crontab_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 90int crontab_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -180,7 +173,7 @@ int crontab_main(int argc, char **argv)
180 switch (opt_ler) { 173 switch (opt_ler) {
181 174
182 default: /* case OPT_r: Delete */ 175 default: /* case OPT_r: Delete */
183 remove(pas->pw_name); 176 unlink(pas->pw_name);
184 break; 177 break;
185 178
186 case OPT_l: /* List */ 179 case OPT_l: /* List */
@@ -211,13 +204,13 @@ int crontab_main(int argc, char **argv)
211 if (fd >= 0) { 204 if (fd >= 0) {
212 bb_copyfd_eof(STDIN_FILENO, fd); 205 bb_copyfd_eof(STDIN_FILENO, fd);
213 close(fd); 206 close(fd);
214 rename(new_fname, pas->pw_name); 207 xrename(new_fname, pas->pw_name);
215 } else { 208 } else {
216 bb_error_msg("cannot create %s/%s", 209 bb_error_msg("cannot create %s/%s",
217 crontab_dir, new_fname); 210 crontab_dir, new_fname);
218 } 211 }
219 if (tmp_fname) 212 if (tmp_fname)
220 remove(tmp_fname); 213 unlink(tmp_fname);
221 /*free(tmp_fname);*/ 214 /*free(tmp_fname);*/
222 /*free(new_fname);*/ 215 /*free(new_fname);*/
223 216