]> granicus.if.org Git - sudo/commitdiff
Add option for set_perm to not exit on failure and use this in
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 10 May 2009 11:52:13 +0000 (11:52 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 10 May 2009 11:52:13 +0000 (11:52 +0000)
the logging routines.

logging.c
set_perms.c
sudo.h
testsudoers.c

index 2dc0650df4630977e890a4c1323631459e409209..0cecd7cdf63373beb631f6607fd1d478615fe8ca 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -371,7 +371,7 @@ log_error(flags, fmt, va_alist)
 #endif
 
     /* Become root if we are not already to avoid user interference */
-    set_perms(PERM_ROOT);
+    set_perms(PERM_ROOT|PERM_NOEXIT);
 
     /* Expand printf-style format + args. */
     evasprintf(&message, fmt, ap);
@@ -555,10 +555,10 @@ send_mail(line)
                 * (so user cannot kill it) or as the user (for the paranoid).
                 */
 #ifndef NO_ROOT_MAILER
-               set_perms(PERM_ROOT);
+               set_perms(PERM_ROOT|PERM_NOEXIT);
                execve(mpath, argv, root_envp);
 #else
-               set_perms(PERM_FULL_USER);
+               set_perms(PERM_FULL_USER|PERM_NOEXIT);
                execv(mpath, argv);
 #endif /* NO_ROOT_MAILER */
                mysyslog(LOG_ERR, "cannot execute %s: %m", mpath);
index c9cecb77d211165b425658fa1569668ae3a0fe36..c612566117ad2647c2fd649b7f14c7a103fff81f 100644 (file)
@@ -77,14 +77,18 @@ static int current_perm = -1;
  * We only flip the effective gid since it only changes for PERM_SUDOERS.
  * This version of set_perms() works fine with the "stay_setuid" option.
  */
-void
+int
 set_perms(perm)
     int perm;
 {
     const char *errstr;
+    int noexit;
+
+    noexit = ISSET(perm, PERM_NOEXIT);
+    CLR(perm, PERM_MASK);
 
     if (perm == current_perm)
-       return;
+       return(1);
 
     switch (perm) {
        case PERM_ROOT:
@@ -169,10 +173,13 @@ set_perms(perm)
     }
 
     current_perm = perm;
-    return;
+    return(1);
 bad:
-    errorx(1, "%s: %s", errstr,
+    warningx("%s: %s", errstr,
        errno == EAGAIN ? "too many processes" : strerror(errno));
+    if (noexit)
+       return(0);
+    exit(1);
 }
 
 #else
@@ -184,14 +191,18 @@ bad:
  * we are headed for an exec().
  * This version of set_perms() works fine with the "stay_setuid" option.
  */
-void
+int
 set_perms(perm)
     int perm;
 {
     const char *errstr;
+    int noexit;
+
+    noexit = ISSET(perm, PERM_NOEXIT);
+    CLR(perm, PERM_MASK);
 
     if (perm == current_perm)
-       return;
+       return(1);
 
     switch (perm) {
        case PERM_ROOT:
@@ -279,10 +290,13 @@ set_perms(perm)
     }
 
     current_perm = perm;
-    return;
+    return(1);
 bad:
-    errorx(1, "%s: %s", errstr,
+    warningx("%s: %s", errstr,
        errno == EAGAIN ? "too many processes" : strerror(errno));
+    if (noexit)
+       return(0);
+    exit(1);
 }
 
 # else /* !HAVE_SETRESUID && !HAVE_SETREUID */
@@ -292,14 +306,18 @@ bad:
  * Set real and effective uids and gids based on perm.
  * NOTE: does not support the "stay_setuid" option.
  */
-void
+int
 set_perms(perm)
     int perm;
 {
     const char *errstr;
+    int noexit;
+
+    noexit = ISSET(perm, PERM_NOEXIT);
+    CLR(perm, PERM_MASK);
 
     if (perm == current_perm)
-       return;
+       return(1);
 
     /*
      * Since we only have setuid() and seteuid() and semantics
@@ -391,10 +409,13 @@ set_perms(perm)
     }
 
     current_perm = perm;
-    return;
+    return(1);
 bad:
-    errorx(1, "%s: %s", errstr,
+    warningx("%s: %s", errstr,
        errno == EAGAIN ? "too many processes" : strerror(errno));
+    if (noexit)
+       return(0);
+    exit(1);
 }
 
 # else /* !HAVE_SETRESUID && !HAVE_SETREUID && !HAVE_SETEUID */
@@ -404,14 +425,18 @@ bad:
  * NOTE: does not support the "stay_setuid" or timestampowner options.
  *       Also, SUDOERS_UID and SUDOERS_GID are not used.
  */
-void
+int
 set_perms(perm)
     int perm;
 {
     const char *errstr;
+    int noexit;
+
+    noexit = ISSET(perm, PERM_NOEXIT);
+    CLR(perm, PERM_MASK);
 
     if (perm == current_perm)
-       return;
+       return(1);
 
     switch (perm) {
        case PERM_ROOT:
@@ -448,10 +473,13 @@ set_perms(perm)
     }
 
     current_perm = perm;
-    return;
+    return(1);
 bad:
-    errorx(1, "%s: %s", errstr,
+    warningx("%s: %s", errstr,
        errno == EAGAIN ? "too many processes" : strerror(errno));
+    if (noexit)
+       return(0);
+    exit(1);
 }
 #  endif /* HAVE_SETEUID */
 # endif /* HAVE_SETREUID */
diff --git a/sudo.h b/sudo.h
index 77ed89eef6560dd391034ee1e0fb88168bbc7d5b..1a7fcf46474a63d7a3389df64da00862d6c3e84e 100644 (file)
--- a/sudo.h
+++ b/sudo.h
@@ -129,6 +129,8 @@ struct sudo_user {
 #define PERM_RUNAS               0x04
 #define PERM_FULL_RUNAS          0x05
 #define PERM_TIMESTAMP           0x06
+#define PERM_NOEXIT              0x10 /* flag */
+#define PERM_MASK                0xf0
 
 /*
  * Shortcuts for sudo_user contents.
@@ -269,7 +271,7 @@ int sudo_file_display_cmnd __P((struct sudo_nss *, struct passwd *));
 int sudo_file_display_defaults __P((struct sudo_nss *, struct passwd *, struct lbuf *));
 int sudo_file_display_bound_defaults __P((struct sudo_nss *, struct passwd *, struct lbuf *));
 int sudo_file_display_privs __P((struct sudo_nss *, struct passwd *, struct lbuf *));
-void set_perms         __P((int));
+int set_perms          __P((int));
 void remove_timestamp  __P((int));
 int check_secureware   __P((char *));
 void sia_attempt_auth  __P((void));
index ebe930f41f1399eed1a689371143abb0900c864a..95a1389e3d64af43d3c0c2f3722e7749aa0eaab7 100644 (file)
@@ -387,11 +387,11 @@ init_envtables()
     return;
 }
 
-void
+int
 set_perms(perm)
     int perm;
 {
-    return;
+    return(1);
 }
 
 void