]> granicus.if.org Git - sudo/commitdiff
Avoid strerror() when possible and just rely on warning/error
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 9 Nov 2012 21:32:29 +0000 (16:32 -0500)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 9 Nov 2012 21:32:29 +0000 (16:32 -0500)
to handle errno in the proper locale.

plugins/sudoers/find_path.c
plugins/sudoers/group_plugin.c
plugins/sudoers/iolog.c
plugins/sudoers/policy.c
plugins/sudoers/sudoers.c
plugins/sudoers/timestamp.c

index 208b88e40e090bb31731307c33ca2a3acaca90b6..ff1bd096dc6435c18ee67692ebb2d548a69e22c5 100644 (file)
@@ -65,8 +65,10 @@ find_path(char *infile, char **outfile, struct stat *sbp, char *path,
     int len;                   /* length parameter */
     debug_decl(find_path, SUDO_DEBUG_UTIL)
 
-    if (strlen(infile) >= PATH_MAX)
-       errorx(1, _("%s: %s"), infile, strerror(ENAMETOOLONG));
+    if (strlen(infile) >= PATH_MAX) {
+       errno = ENAMETOOLONG;
+       error(1, "%s", infile);
+    }
 
     /*
      * If we were given a fully qualified or relative path
@@ -104,8 +106,10 @@ find_path(char *infile, char **outfile, struct stat *sbp, char *path,
         * Resolve the path and exit the loop if found.
         */
        len = snprintf(command, sizeof(command), "%s/%s", path, infile);
-       if (len <= 0 || len >= sizeof(command))
-           errorx(1, _("%s: %s"), infile, strerror(ENAMETOOLONG));
+       if (len <= 0 || len >= sizeof(command)) {
+           errno = ENAMETOOLONG;
+           error(1, "%s", infile);
+       }
        if ((found = sudo_goodpath(command, sbp)))
            break;
 
@@ -119,8 +123,10 @@ find_path(char *infile, char **outfile, struct stat *sbp, char *path,
      */
     if (!found && checkdot) {
        len = snprintf(command, sizeof(command), "./%s", infile);
-       if (len <= 0 || len >= sizeof(command))
-           errorx(1, _("%s: %s"), infile, strerror(ENAMETOOLONG));
+       if (len <= 0 || len >= sizeof(command)) {
+           errno = ENAMETOOLONG;
+           error(1, "%s", infile);
+       }
        found = sudo_goodpath(command, sbp);
        if (found && ignore_dot)
            debug_return_int(NOT_FOUND_DOT);
index 660832c2276ca73f2039e01a2fe1a6fb911735c9..53f18b24b8e2f9a72d05f7c6ae595801524c9b66 100644 (file)
@@ -88,9 +88,9 @@ group_plugin_load(char *plugin_info)
            (*plugin_info != '/') ? _PATH_SUDO_PLUGIN_DIR : "", plugin_info);
     }
     if (len <= 0 || len >= sizeof(path)) {
-       warningx(N_("%s%s: %s"),
-           (*plugin_info != '/') ? _PATH_SUDO_PLUGIN_DIR : "", plugin_info,
-           strerror(ENAMETOOLONG));
+       errno = ENAMETOOLONG;
+       warning("%s%s",
+           (*plugin_info != '/') ? _PATH_SUDO_PLUGIN_DIR : "", plugin_info);
        goto done;
     }
 
index bd526caa554b0a30f277cd816784a45f6d946188..f88b7c204f63dd4b7f2118249a9a7eaa5ffebbe4 100644 (file)
@@ -121,7 +121,8 @@ mkdir_parents(char *path)
            if (mkdir(path, S_IRWXU) != 0)
                log_fatal(USE_ERRNO, N_("unable to mkdir %s"), path);
        } else if (!S_ISDIR(sb.st_mode)) {
-           log_fatal(0, N_("%s: %s"), path, strerror(ENOTDIR));
+           errno = ENOTDIR;
+           log_fatal(USE_ERRNO, "%s", path);
        }
        *slash = '/';
     }
index 4ec8bc38f6ad3283bb193f64f218b74d13212808..3f6684cf05315a89ba3a69c1c23fff5c97767f58 100644 (file)
@@ -40,6 +40,7 @@
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif /* HAVE_UNISTD_H */
+#include <errno.h>
 #include <grp.h>
 #include <pwd.h>
 #include <setjmp.h>
@@ -493,8 +494,10 @@ sudoers_policy_close(int exit_status, int error_code)
     }
 
     /* We do not currently log the exit status. */
-    if (error_code)
-       warningx(N_("unable to execute %s: %s"), safe_cmnd, strerror(error_code));
+    if (error_code) {
+       errno = error_code;
+       warning(N_("unable to execute %s"), safe_cmnd);
+    }
 
     /* Close the session we opened in sudoers_policy_init_session(). */
     if (ISSET(sudo_mode, MODE_RUN|MODE_EDIT))
index a76f12055327cb983ca5a2ca68f25e825b13817d..ae85138e71aa012a829ad1b1576cadb5da735c8f 100644 (file)
@@ -685,8 +685,10 @@ set_cmnd(void)
            }
        }
     }
-    if (strlen(user_cmnd) >= PATH_MAX)
-       errorx(1, _("%s: %s"), user_cmnd, strerror(ENAMETOOLONG));
+    if (strlen(user_cmnd) >= PATH_MAX) {
+       errno = ENAMETOOLONG;
+       error(1, "%s", user_cmnd);
+    }
 
     if ((user_base = strrchr(user_cmnd, '/')) != NULL)
        user_base++;
index 84f1f2cef8835882ac7f61f925f157cb5228ba5a..cd2c8c6f16e452f1c9dcf056298ef5ac8de2a08a 100644 (file)
@@ -400,8 +400,7 @@ remove_timestamp(bool remove)
                status = rmdir(timestampdir);
            if (status == -1 && errno != ENOENT) {
                log_error(0,
-                   N_("unable to remove %s (%s), will reset to the epoch"),
-                   path, strerror(errno));
+                   N_("unable to remove %s, will reset to the epoch"), path);
                remove = false;
            }
        }