|
@@ -6,6 +6,7 @@
|
|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
|
#include <syslog.h>
|
|
|
+#include <unistd.h>
|
|
|
#include <sys/types.h>
|
|
|
#include <pwd.h>
|
|
|
|
|
@@ -18,7 +19,7 @@ CLISH_HOOK_LOG(clish_hook_log)
|
|
|
{
|
|
|
clish_shell_t *this = clish_context__get_shell(clish_context);
|
|
|
struct passwd *user = NULL;
|
|
|
- char *uname = "unknown";
|
|
|
+ char *uname = NULL;
|
|
|
|
|
|
/* Initialization */
|
|
|
if (!line) {
|
|
@@ -28,9 +29,16 @@ CLISH_HOOK_LOG(clish_hook_log)
|
|
|
}
|
|
|
|
|
|
/* Log the given line */
|
|
|
- if ((user = clish_shell__get_user(this)))
|
|
|
- uname = user->pw_name;
|
|
|
- syslog(LOG_INFO, "(%s) %s : %d", uname, line, retcode);
|
|
|
+ /* Try to get username from environment variables
|
|
|
+ * USER and LOGNAME and then from /etc/passwd.
|
|
|
+ */
|
|
|
+ user = clish_shell__get_user(this);
|
|
|
+ if (!(uname = getenv("USER"))) {
|
|
|
+ if (!(uname = getenv("LOGNAME")))
|
|
|
+ uname = user ? user->pw_name : "unknown";
|
|
|
+ }
|
|
|
+ syslog(LOG_INFO, "%u(%s) %s : %d",
|
|
|
+ user ? user->pw_uid : getuid(), uname, line, retcode);
|
|
|
|
|
|
return 0;
|
|
|
}
|