[hackers] [ubase] Inform the user if exec*() fails || sin

From: <git_AT_suckless.org>
Date: Tue, 03 Jun 2014 13:34:42 +0200

commit da215823a36a86eaaa593098c0244e5d9e5e08bb
Author: sin <sin_AT_2f30.org>
Date: Tue Jun 3 12:29:16 2014 +0100

    Inform the user if exec*() fails

diff --git a/su.c b/su.c
index 2f7eace..8b2d154 100644
--- a/su.c
+++ b/su.c
_AT_@ -16,7 +16,7 @@
 extern char **environ;
 
 static const char *randreply(void);
-static void dologin(struct passwd *);
+static int dologin(struct passwd *);
 
 static void
 usage(void)
_AT_@ -119,7 +119,7 @@ dosu:
                 eprintf("setuid:");
 
         if (lflag) {
- dologin(pw);
+ return dologin(pw);
         } else {
                 newargv = (char *const[]){pw->pw_shell, NULL};
                 if (!pflag) {
_AT_@ -136,8 +136,10 @@ dosu:
                         setenv("PATH", ENV_PATH, 1);
                 execve(pflag ? getenv("SHELL") : pw->pw_shell,
                        newargv, environ);
+ weprintf("execve %s:", pw->pw_shell);
+ return (errno == ENOENT) ? 127 : 126;
         }
- return (errno == ENOENT) ? 127 : 126;
+ return EXIT_SUCCESS;
 }
 
 static const char *
_AT_@ -160,7 +162,7 @@ randreply(void)
         return replies[rand() % LEN(replies)];
 }
 
-static void
+static int
 dologin(struct passwd *pw)
 {
         char *term = getenv("TERM");
_AT_@ -177,4 +179,6 @@ dologin(struct passwd *pw)
         if (chdir(pw->pw_dir) < 0)
                 eprintf("chdir %s:", pw->pw_dir);
         execlp(pw->pw_shell, pw->pw_shell, "-l", NULL);
+ weprintf("execlp %s:", pw->pw_shell);
+ return (errno == ENOENT) ? 127 : 126;
 }
Received on Tue Jun 03 2014 - 13:34:42 CEST

This archive was generated by hypermail 2.3.0 : Tue Jun 03 2014 - 13:36:09 CEST