[hackers] [ubase] Setup a sane PATH across su(1) || sin

From: <git_AT_suckless.org>
Date: Sat, 19 Oct 2013 20:11:19 +0200

commit 5f3c183b854a16dddca6fc1fa7a5bef8d685539c
Author: sin <sin_AT_2f30.org>
Date: Sat Oct 19 19:07:30 2013 +0100

    Setup a sane PATH across su(1)
    
    Also added a config.h for the basic configuration of ubase.

diff --git a/Makefile b/Makefile
index d9ff21e..cc09ded 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -3,7 +3,7 @@ include config.mk
 .POSIX:
 .SUFFIXES: .c .o
 
-HDR = arg.h grabmntinfo.h proc.h reboot.h util.h
+HDR = arg.h config.h grabmntinfo.h proc.h reboot.h util.h
 LIB = \
         util/agetcwd.o \
         util/apathmax.o \
diff --git a/config.h b/config.h
new file mode 100644
index 0000000..a85d6bd
--- /dev/null
+++ b/config.h
_AT_@ -0,0 +1,4 @@
+/* See LICENSE file for copyright and license details. */
+
+#define ENV_SUPATH "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
+#define ENV_PATH "/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
diff --git a/su.c b/su.c
index 339cba1..2cbc57e 100644
--- a/su.c
+++ b/su.c
_AT_@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include "config.h"
 #include "util.h"
 
 extern char **environ;
_AT_@ -112,6 +113,10 @@ main(int argc, char **argv)
                                 setenv("LOGNAME", pw->pw_name, 1);
                         }
                 }
+ if (strcmp(pw->pw_name, "root") == 0)
+ setenv("PATH", ENV_SUPATH, 1);
+ else
+ setenv("PATH", ENV_PATH, 1);
                 execve(pflag ? getenv("SHELL") : pw->pw_shell,
                        newargv, environ);
         }
_AT_@ -147,7 +152,9 @@ dologin(struct passwd *pw)
                 msetenv("USER", pw->pw_name),
                 msetenv("LOGNAME", pw->pw_name),
                 msetenv("TERM", getenv("TERM")),
- msetenv("PATH", getenv("PATH")),
+ msetenv("PATH",
+ strcmp(pw->pw_name, "root") == 0 ?
+ ENV_SUPATH : ENV_PATH),
                 NULL
         };
         if (chdir(pw->pw_dir) < 0)
Received on Sat Oct 19 2013 - 20:11:19 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 19 2013 - 20:12:14 CEST