more crond+crontab integrating with loginutil libbb functions and deleted
patch from Thomas Gleixner to init.
Viodz last_patch_108
diff --git a/include/libbb.h b/include/libbb.h
index 6490373..4bfcc7a 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -411,6 +411,7 @@
#define FAIL_DELAY 3
extern void change_identity ( const struct passwd *pw );
+extern const char *change_identity_e2str ( const struct passwd *pw );
extern void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args
#ifdef CONFIG_SELINUX
, security_id_t sid
diff --git a/init/init.c b/init/init.c
index 2f44e13..26bbc34 100644
--- a/init/init.c
+++ b/init/init.c
@@ -829,13 +829,6 @@
got_cont = 1;
}
-/* Reap any zombie processes that are reparented to init */
-static void child_handler(int sig)
-{
- int status;
- while ( wait3(&status, WNOHANG, NULL) > 0 );
-}
-
#endif /* ! DEBUG_INIT */
static void new_init_action(int action, const char *command, const char *cons)
@@ -1076,7 +1069,6 @@
signal(SIGCONT, cont_handler);
signal(SIGSTOP, stop_handler);
signal(SIGTSTP, stop_handler);
- signal(SIGCHLD, child_handler);
/* Turn off rebooting via CTL-ALT-DEL -- we get a
* SIGINT on CAD so we can shut things down gracefully... */
diff --git a/libbb/change_identity.c b/libbb/change_identity.c
index c2b73ee..adebad8 100644
--- a/libbb/change_identity.c
+++ b/libbb/change_identity.c
@@ -40,15 +40,23 @@
/* Become the user and group(s) specified by PW. */
-void change_identity ( const struct passwd *pw )
+const char *change_identity_e2str ( const struct passwd *pw )
{
if ( initgroups ( pw-> pw_name, pw-> pw_gid ) == -1 )
- bb_perror_msg_and_die ( "cannot set groups" );
+ return "cannot set groups";
endgrent ( );
if ( setgid ( pw-> pw_gid ))
- bb_perror_msg_and_die ( "cannot set group id" );
+ return "cannot set group id";
if ( setuid ( pw->pw_uid ))
- bb_perror_msg_and_die ( "cannot set user id" );
+ return "cannot set user id";
+ return NULL;
}
+void change_identity ( const struct passwd *pw )
+{
+ const char *err_msg = change_identity_e2str(pw);
+
+ if(err_msg)
+ bb_perror_msg_and_die ( "%s", err_msg );
+}
diff --git a/miscutils/crond.c b/miscutils/crond.c
index 637e09d..7915b86 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -299,6 +299,7 @@
ChangeUser(const char *user)
{
struct passwd *pas;
+ const char *err_msg;
/*
* Obtain password entry and change privilages
@@ -315,18 +316,9 @@
/*
* Change running state to the user in question
*/
-
- if (initgroups(user, pas->pw_gid) < 0) {
- crondlog("\011initgroups failed: %s %m", user);
- return(-1);
- }
- /* drop all priviledges */
- if (setgid(pas->pw_gid) < 0) {
- crondlog("\011setgid failed: %s %d", user, pas->pw_gid);
- return(-1);
- }
- if (setuid(pas->pw_uid) < 0) {
- crondlog("\011setuid failed: %s %d", user, pas->pw_uid);
+ err_msg = change_identity_e2str(pas);
+ if (err_msg) {
+ crondlog("\011%s for user %s", err_msg, user);
return(-1);
}
if (chdir(pas->pw_dir) < 0) {
diff --git a/miscutils/crontab.c b/miscutils/crontab.c
index 6c4da95..52d08dd 100644
--- a/miscutils/crontab.c
+++ b/miscutils/crontab.c
@@ -333,18 +333,6 @@
wait4(pid, NULL, 0, NULL);
}
-static void
-log(const char *ctl, ...)
-{
- va_list va;
- char buf[1024];
-
- va_start(va, ctl);
- vsnprintf(buf, sizeof(buf), ctl, va);
- syslog(LOG_NOTICE, "%s",buf );
- va_end(va);
-}
-
static int
ChangeUser(const char *user, short dochdir)
{
@@ -355,7 +343,7 @@
*/
if ((pas = getpwnam(user)) == 0) {
- log("failed to get uid for %s", user);
+ bb_perror_msg_and_die("failed to get uid for %s", user);
return(-1);
}
setenv("USER", pas->pw_name, 1);
@@ -365,24 +353,13 @@
/*
* Change running state to the user in question
*/
+ change_identity(pas);
- if (initgroups(user, pas->pw_gid) < 0) {
- log("initgroups failed: %s %m", user);
- return(-1);
- }
- if (setregid(pas->pw_gid, pas->pw_gid) < 0) {
- log("setregid failed: %s %d", user, pas->pw_gid);
- return(-1);
- }
- if (setreuid(pas->pw_uid, pas->pw_uid) < 0) {
- log("setreuid failed: %s %d", user, pas->pw_uid);
- return(-1);
- }
if (dochdir) {
if (chdir(pas->pw_dir) < 0) {
+ bb_perror_msg_and_die("chdir failed: %s %s", user, pas->pw_dir);
if (chdir(TMPDIR) < 0) {
- log("chdir failed: %s %s", user, pas->pw_dir);
- log("chdir failed: %s " TMPDIR, user);
+ bb_perror_msg_and_die("chdir failed: %s %s", user, TMPDIR);
return(-1);
}
}