aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2003-09-03 12:18:42 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2003-09-03 12:18:42 +0000
commit99bd5adf995ee0f83bdda92384137ae810c4c92b (patch)
tree253331bcdcf278ef28a6f67f87faf80786b78e97
parent759d7ececd56e5b25bbfcc54a04bf939d80c7ee9 (diff)
downloadbusybox-w32-99bd5adf995ee0f83bdda92384137ae810c4c92b.tar.gz
busybox-w32-99bd5adf995ee0f83bdda92384137ae810c4c92b.tar.bz2
busybox-w32-99bd5adf995ee0f83bdda92384137ae810c4c92b.zip
more crond+crontab integrating with loginutil libbb functions and deleted
patch from Thomas Gleixner to init. Viodz last_patch_108
-rw-r--r--include/libbb.h1
-rw-r--r--init/init.c8
-rw-r--r--libbb/change_identity.c16
-rw-r--r--miscutils/crond.c16
-rw-r--r--miscutils/crontab.c31
5 files changed, 21 insertions, 51 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 64903732d..4bfcc7a8b 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -411,6 +411,7 @@ void bb_xasprintf(char **string_ptr, const char *format, ...) __attribute__ ((fo
411 411
412#define FAIL_DELAY 3 412#define FAIL_DELAY 3
413extern void change_identity ( const struct passwd *pw ); 413extern void change_identity ( const struct passwd *pw );
414extern const char *change_identity_e2str ( const struct passwd *pw );
414extern void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args 415extern void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args
415#ifdef CONFIG_SELINUX 416#ifdef CONFIG_SELINUX
416 , security_id_t sid 417 , security_id_t sid
diff --git a/init/init.c b/init/init.c
index 2f44e13bf..26bbc3428 100644
--- a/init/init.c
+++ b/init/init.c
@@ -829,13 +829,6 @@ static void cont_handler(int sig)
829 got_cont = 1; 829 got_cont = 1;
830} 830}
831 831
832/* Reap any zombie processes that are reparented to init */
833static void child_handler(int sig)
834{
835 int status;
836 while ( wait3(&status, WNOHANG, NULL) > 0 );
837}
838
839#endif /* ! DEBUG_INIT */ 832#endif /* ! DEBUG_INIT */
840 833
841static void new_init_action(int action, const char *command, const char *cons) 834static void new_init_action(int action, const char *command, const char *cons)
@@ -1076,7 +1069,6 @@ extern int init_main(int argc, char **argv)
1076 signal(SIGCONT, cont_handler); 1069 signal(SIGCONT, cont_handler);
1077 signal(SIGSTOP, stop_handler); 1070 signal(SIGSTOP, stop_handler);
1078 signal(SIGTSTP, stop_handler); 1071 signal(SIGTSTP, stop_handler);
1079 signal(SIGCHLD, child_handler);
1080 1072
1081 /* Turn off rebooting via CTL-ALT-DEL -- we get a 1073 /* Turn off rebooting via CTL-ALT-DEL -- we get a
1082 * SIGINT on CAD so we can shut things down gracefully... */ 1074 * SIGINT on CAD so we can shut things down gracefully... */
diff --git a/libbb/change_identity.c b/libbb/change_identity.c
index c2b73eeb8..adebad8ed 100644
--- a/libbb/change_identity.c
+++ b/libbb/change_identity.c
@@ -40,15 +40,23 @@
40 40
41 41
42/* Become the user and group(s) specified by PW. */ 42/* Become the user and group(s) specified by PW. */
43void change_identity ( const struct passwd *pw ) 43const char *change_identity_e2str ( const struct passwd *pw )
44{ 44{
45 if ( initgroups ( pw-> pw_name, pw-> pw_gid ) == -1 ) 45 if ( initgroups ( pw-> pw_name, pw-> pw_gid ) == -1 )
46 bb_perror_msg_and_die ( "cannot set groups" ); 46 return "cannot set groups";
47 endgrent ( ); 47 endgrent ( );
48 48
49 if ( setgid ( pw-> pw_gid )) 49 if ( setgid ( pw-> pw_gid ))
50 bb_perror_msg_and_die ( "cannot set group id" ); 50 return "cannot set group id";
51 if ( setuid ( pw->pw_uid )) 51 if ( setuid ( pw->pw_uid ))
52 bb_perror_msg_and_die ( "cannot set user id" ); 52 return "cannot set user id";
53 return NULL;
53} 54}
54 55
56void change_identity ( const struct passwd *pw )
57{
58 const char *err_msg = change_identity_e2str(pw);
59
60 if(err_msg)
61 bb_perror_msg_and_die ( "%s", err_msg );
62}
diff --git a/miscutils/crond.c b/miscutils/crond.c
index 637e09dd8..7915b860a 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -299,6 +299,7 @@ static int
299ChangeUser(const char *user) 299ChangeUser(const char *user)
300{ 300{
301 struct passwd *pas; 301 struct passwd *pas;
302 const char *err_msg;
302 303
303 /* 304 /*
304 * Obtain password entry and change privilages 305 * Obtain password entry and change privilages
@@ -315,18 +316,9 @@ ChangeUser(const char *user)
315 /* 316 /*
316 * Change running state to the user in question 317 * Change running state to the user in question
317 */ 318 */
318 319 err_msg = change_identity_e2str(pas);
319 if (initgroups(user, pas->pw_gid) < 0) { 320 if (err_msg) {
320 crondlog("\011initgroups failed: %s %m", user); 321 crondlog("\011%s for user %s", err_msg, user);
321 return(-1);
322 }
323 /* drop all priviledges */
324 if (setgid(pas->pw_gid) < 0) {
325 crondlog("\011setgid failed: %s %d", user, pas->pw_gid);
326 return(-1);
327 }
328 if (setuid(pas->pw_uid) < 0) {
329 crondlog("\011setuid failed: %s %d", user, pas->pw_uid);
330 return(-1); 322 return(-1);
331 } 323 }
332 if (chdir(pas->pw_dir) < 0) { 324 if (chdir(pas->pw_dir) < 0) {
diff --git a/miscutils/crontab.c b/miscutils/crontab.c
index 6c4da95fe..52d08dda3 100644
--- a/miscutils/crontab.c
+++ b/miscutils/crontab.c
@@ -333,18 +333,6 @@ EditFile(const char *user, const char *file)
333 wait4(pid, NULL, 0, NULL); 333 wait4(pid, NULL, 0, NULL);
334} 334}
335 335
336static void
337log(const char *ctl, ...)
338{
339 va_list va;
340 char buf[1024];
341
342 va_start(va, ctl);
343 vsnprintf(buf, sizeof(buf), ctl, va);
344 syslog(LOG_NOTICE, "%s",buf );
345 va_end(va);
346}
347
348static int 336static int
349ChangeUser(const char *user, short dochdir) 337ChangeUser(const char *user, short dochdir)
350{ 338{
@@ -355,7 +343,7 @@ ChangeUser(const char *user, short dochdir)
355 */ 343 */
356 344
357 if ((pas = getpwnam(user)) == 0) { 345 if ((pas = getpwnam(user)) == 0) {
358 log("failed to get uid for %s", user); 346 bb_perror_msg_and_die("failed to get uid for %s", user);
359 return(-1); 347 return(-1);
360 } 348 }
361 setenv("USER", pas->pw_name, 1); 349 setenv("USER", pas->pw_name, 1);
@@ -365,24 +353,13 @@ ChangeUser(const char *user, short dochdir)
365 /* 353 /*
366 * Change running state to the user in question 354 * Change running state to the user in question
367 */ 355 */
356 change_identity(pas);
368 357
369 if (initgroups(user, pas->pw_gid) < 0) {
370 log("initgroups failed: %s %m", user);
371 return(-1);
372 }
373 if (setregid(pas->pw_gid, pas->pw_gid) < 0) {
374 log("setregid failed: %s %d", user, pas->pw_gid);
375 return(-1);
376 }
377 if (setreuid(pas->pw_uid, pas->pw_uid) < 0) {
378 log("setreuid failed: %s %d", user, pas->pw_uid);
379 return(-1);
380 }
381 if (dochdir) { 358 if (dochdir) {
382 if (chdir(pas->pw_dir) < 0) { 359 if (chdir(pas->pw_dir) < 0) {
360 bb_perror_msg_and_die("chdir failed: %s %s", user, pas->pw_dir);
383 if (chdir(TMPDIR) < 0) { 361 if (chdir(TMPDIR) < 0) {
384 log("chdir failed: %s %s", user, pas->pw_dir); 362 bb_perror_msg_and_die("chdir failed: %s %s", user, TMPDIR);
385 log("chdir failed: %s " TMPDIR, user);
386 return(-1); 363 return(-1);
387 } 364 }
388 } 365 }