aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/lib.c15
-rw-r--r--lib/lib.h1
-rw-r--r--toys/lsb/su.c22
3 files changed, 20 insertions, 18 deletions
diff --git a/lib/lib.c b/lib/lib.c
index d1210f49..8937c57a 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -1462,3 +1462,18 @@ void reset_env(struct passwd *p, int clear)
setenv("USER", p->pw_name, 1);
setenv("LOGNAME", p->pw_name, 1);
}
+
+// Syslog with the openlog/closelog, autodetecting daemon status via no tty
+
+void loggit(int priority, char *format, ...)
+{
+ int i, facility = LOG_DAEMON;
+ va_list va;
+
+ for (i = 0; i<3; i++) facility = LOG_AUTH;
+ openlog(toys.which->name, LOG_PID, facility);
+ va_start(va, format);
+ vsyslog(priority, format, va);
+ va_end(va);
+ closelog();
+}
diff --git a/lib/lib.h b/lib/lib.h
index 87f4150e..9de18413 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -260,6 +260,7 @@ long environ_bytes();
long long millitime(void);
char *format_iso_time(char *buf, size_t len, struct timespec *ts);
void reset_env(struct passwd *p, int clear);
+void loggit(int priority, char *format, ...);
#define HR_SPACE 1 // Space between number and units
#define HR_B 2 // Use "B" for single byte units
diff --git a/toys/lsb/su.c b/toys/lsb/su.c
index c48a0c9f..3d6fd570 100644
--- a/toys/lsb/su.c
+++ b/toys/lsb/su.c
@@ -42,15 +42,6 @@ GLOBALS(
char *c;
)
-static char *snapshot_env(char *name)
-{
- char *s = getenv(name);
-
- if (s) return xmprintf("%s=%s", name, s);
-
- return 0;
-}
-
void su_main()
{
char *name, *passhash = 0, **argu, **argv;
@@ -65,7 +56,7 @@ void su_main()
if (*toys.optargs) name = *(toys.optargs++);
else name = "root";
- loggit(name, 0);
+ loggit(LOG_NOTICE, "%s->%s", getusername(getuid()), name);
if (!(shp = getspnam(name))) perror_exit("no '%s'", name);
if (getuid()) {
@@ -81,17 +72,12 @@ void su_main()
if (FLAG(m)||FLAG(p)) {
unsetenv("IFS");
- setenv("PATH", _PATH_DEFPATHS, 1);
+ setenv("PATH", _PATH_DEFPATH, 1);
} else reset_env(up, FLAG(l));
argv = argu = xmalloc(sizeof(char *)*(toys.optc + 4));
*(argv++) = TT.s ? TT.s : up->pw_shell;
- loggit(name, *argu);
-
- if (FLAG(m)||FLAG(p)) {
- unsetenv("IFS");
- setenv("PATH", _PATH_DEFPATHS, 1);
- } else reset_env(up, FLAG(l));
+ loggit(LOG_NOTICE, "run %s", *argu);
if (FLAG(l)) *(argv++) = "-l";
if (FLAG(c)) {
@@ -102,7 +88,7 @@ void su_main()
xexec(argu);
deny:
- syslog(LOG_NOTICE, "No.", getusername(getuid()), name);
+ syslog(LOG_NOTICE, "No.");
puts("No.");
toys.exitval = 1;
}