]> granicus.if.org Git - sudo/commitdiff
Don't call fatal/fatalx in common/*.c
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 25 Mar 2014 22:16:10 +0000 (16:16 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 25 Mar 2014 22:16:10 +0000 (16:16 -0600)
common/aix.c
common/gidlist.c
compat/getgrouplist.c
include/sudo_util.h
src/sudo.c

index c0f2a418b24bee03c1f8060e25b3e673d09545be..ecfb4a5f9532b5569abece43c608f3653f56bba3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2010-2013 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2008, 2010-2014 Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -71,27 +71,27 @@ static struct aix_limit aix_limits[] = {
 };
 
 static int
-aix_getlimit(char *user, char *lim, rlim64_t *valp)
+aix_getlimit(char *user, char *lim, int *valp)
 {
-    int val;
     debug_decl(aix_getlimit, SUDO_DEBUG_UTIL)
 
-    if (getuserattr(user, lim, &val, SEC_INT) != 0)
+    if (getuserattr(user, lim, valp, SEC_INT) != 0)
        debug_return_int(-1);
-    *valp = val;
     debug_return_int(0);
 }
 
-static void
+static int
 aix_setlimits(char *user)
 {
     struct rlimit64 rlim;
-    rlim64_t val;
-    int n;
+    int val;
+    size_t n;
     debug_decl(aix_setlimits, SUDO_DEBUG_UTIL)
 
-    if (setuserdb(S_READ) != 0)
-       fatal(U_("unable to open userdb"));
+    if (setuserdb(S_READ) != 0) {
+       warning(U_("unable to open userdb"));
+       debug_return_int(-1);
+    }
 
     /*
      * For each resource limit, get the soft/hard values for the user
@@ -103,16 +103,16 @@ aix_setlimits(char *user)
         * hard limit has been defined.
         */
        if (aix_getlimit(user, aix_limits[n].hard, &val) == 0) {
-           rlim.rlim_max = val == -1 ? RLIM64_INFINITY : val * aix_limits[n].factor;
+           rlim.rlim_max = val == -1 ? RLIM64_INFINITY : (rlim64_t)val * aix_limits[n].factor;
            if (aix_getlimit(user, aix_limits[n].soft, &val) == 0)
-               rlim.rlim_cur = val == -1 ? RLIM64_INFINITY : val * aix_limits[n].factor;
+               rlim.rlim_cur = val == -1 ? RLIM64_INFINITY : (rlim64_t)val * aix_limits[n].factor;
            else
                rlim.rlim_cur = rlim.rlim_max;  /* soft not specd, use hard */
        } else {
            /* No hard limit set, try soft limit, if it exists. */
            if (aix_getlimit(user, aix_limits[n].soft, &val) == -1)
                continue;
-           rlim.rlim_cur = val == -1 ? RLIM64_INFINITY : val * aix_limits[n].factor;
+           rlim.rlim_cur = val == -1 ? RLIM64_INFINITY : (rlim64_t)val * aix_limits[n].factor;
 
            /* Set hard limit per AIX /etc/security/limits documentation. */
            switch (aix_limits[n].resource) {
@@ -131,7 +131,7 @@ aix_setlimits(char *user)
        (void)setrlimit64(aix_limits[n].resource, &rlim);
     }
     enduserdb();
-    debug_return;
+    debug_return_int(0);
 }
 
 #ifdef HAVE_SETAUTHDB
@@ -140,41 +140,46 @@ aix_setlimits(char *user)
  * set it as the default for the process.  This ensures that password and
  * group lookups are made against the correct source (files, NIS, LDAP, etc).
  */
-void
+int
 aix_setauthdb(char *user)
 {
     char *registry;
     debug_decl(aix_setauthdb, SUDO_DEBUG_UTIL)
 
     if (user != NULL) {
-       if (setuserdb(S_READ) != 0)
-           fatal(U_("unable to open userdb"));
+       if (setuserdb(S_READ) != 0) {
+           warning(U_("unable to open userdb"));
+           debug_return_int(-1);
+       }
        if (getuserattr(user, S_REGISTRY, &registry, SEC_CHAR) == 0) {
-           if (setauthdb(registry, NULL) != 0)
-               fatal(U_("unable to switch to registry \"%s\" for %s"),
+           if (setauthdb(registry, NULL) != 0) {
+               warning(U_("unable to switch to registry \"%s\" for %s"),
                    registry, user);
+               debug_return_int(-1);
+           }
        }
        enduserdb();
     }
-    debug_return;
+    debug_return_int(0);
 }
 
 /*
  * Restore the saved administrative domain, if any.
  */
-void
+int
 aix_restoreauthdb(void)
 {
     debug_decl(aix_setauthdb, SUDO_DEBUG_UTIL)
 
-    if (setauthdb(NULL, NULL) != 0)
-       fatal(U_("unable to restore registry"));
-
-    debug_return;
+    if (setauthdb(NULL, NULL) != 0) {
+       warning(U_("unable to restore registry"));
+       debug_return_int(-1);
+    }
+    debug_return_int(0);
 }
 #endif
 
-void
+int
 aix_prep_user(char *user, const char *tty)
 {
     char *info;
@@ -189,12 +194,14 @@ aix_prep_user(char *user, const char *tty)
 
 #ifdef HAVE_SETAUTHDB
     /* set administrative domain */
-    aix_setauthdb(user);
+    if (aix_setauthdb(user) != 0)
+       debug_return_int(-1);
 #endif
 
     /* set resource limits */
-    aix_setlimits(user);
+    if (aix_setlimits(user) != 0)
+       debug_return_int(-1);
 
-    debug_return;
+    debug_return_int(0);
 }
 #endif /* HAVE_GETUSERATTR */
index 8b112eb5a04636d643d84d6bd2fc01434a0c6a37..4029fa715c00c707c14b8cc1585264f8b1d93bfc 100644 (file)
@@ -43,7 +43,6 @@
  * If a pointer to the base gid is specified, it is stored as the first element
  * in the array.
  * Returns the number of gids in the allocated array.
- * Calls fatalx() on error.
  */
 int
 parse_gid_list(const char *gidstr, const gid_t *basegid, GETGROUPS_T **gidsp)
index 6e035be848c73f4749a8947e71a2742eec726853..fc6c9fd1fb201a51ff6251869fdbb30e4d708e3b 100644 (file)
@@ -1,5 +1,6 @@
 /*
- * Copyright (c) 2010, 2011, 2013 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2010, 2011, 2013, 2014
+ *     Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
 #endif
 
 #include "missing.h"
+#include "sudo_util.h"
 
 #if defined(HAVE_GETGRSET)
 /*
- * BSD-compatible getgrouplist(3) using getgrset(3)
+ * BSD-compatible getgrouplist(3) using AIX getgrset(3)
  */
 int
 getgrouplist(const char *name, gid_t basegid, gid_t *groups, int *ngroupsp)
 {
     char *cp, *grset = NULL;
-    int i, ngroups = 1;
+    int ngroups = 1;
     int grpsize = *ngroupsp;
     int rval = -1;
     gid_t gid;
index c1ded741f1fbcfa8903ea542ff7c5208d6cb3672..61a7180f1e17cec4bb5611353c9c6d22ccb4974d 100644 (file)
 #endif
 
 /* aix.c */
-void aix_prep_user(char *user, const char *tty);
-void aix_restoreauthdb(void);
-void aix_setauthdb(char *user);
+int aix_prep_user(char *user, const char *tty);
+int aix_restoreauthdb(void);
+int aix_setauthdb(char *user);
 
 /* atobool.c */
 int atobool(const char *str);
index 2db2a5e669cfae5e00dfc930a69814c524738f03..a0bb63392fd913fbd89d468d91446d28a1eadfd7 100644 (file)
@@ -887,7 +887,10 @@ exec_setup(struct command_details *details, const char *ptyname, int ptyfd)
 #endif /* HAVE_PRIV_SET */
 
 #ifdef HAVE_GETUSERATTR
-       aix_prep_user(details->pw->pw_name, ptyname ? ptyname : user_details.tty);
+       if (aix_prep_user(details->pw->pw_name, ptyname ? ptyname : user_details.tty) != 0) {
+           /* error message displayed by aix_prep_user */
+           goto done;
+       }
 #endif
 #ifdef HAVE_LOGIN_CAP_H
        if (details->login_class) {