diff options
| author | Ed Schouten <ed@FreeBSD.org> | 2012-04-19 21:12:08 +0000 |
|---|---|---|
| committer | Ed Schouten <ed@FreeBSD.org> | 2012-04-19 21:12:08 +0000 |
| commit | 1d2276c873e56ff9139ba60b427420f7fabd9f8a (patch) | |
| tree | 2df3cfa9cc7115e3256a991dcdec9d44761d7ca6 /libexec | |
| parent | 52116a1cb9d765e8cb035c136713c70b7342aa0d (diff) | |
Notes
Diffstat (limited to 'libexec')
| -rw-r--r-- | libexec/ulog-helper/ulog-helper.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/libexec/ulog-helper/ulog-helper.c b/libexec/ulog-helper/ulog-helper.c index 31b40e9e4a2f1..99cd5d2f1fa0c 100644 --- a/libexec/ulog-helper/ulog-helper.c +++ b/libexec/ulog-helper/ulog-helper.c @@ -46,6 +46,28 @@ __FBSDID("$FreeBSD$"); * username. It does allow users to log arbitrary hostnames. */ +static const char * +get_username(void) +{ + const struct passwd *pw; + const char *login; + uid_t uid; + + /* + * Attempt to determine the username corresponding to this login + * session. First, validate the results of getlogin() against + * the password database. If getlogin() returns invalid data, + * return an arbitrary username corresponding to this uid. + */ + uid = getuid(); + if ((login = getlogin()) != NULL && (pw = getpwnam(login)) != NULL && + pw->pw_uid == uid) + return (login); + if ((pw = getpwuid(uid)) != NULL) + return (pw->pw_name); + return (NULL); +} + int main(int argc, char *argv[]) { @@ -57,7 +79,7 @@ main(int argc, char *argv[]) if ((argc == 2 || argc == 3) && strcmp(argv[1], "login") == 0) { /* Username. */ - user = user_from_uid(getuid(), 1); + user = get_username(); if (user == NULL) return (EX_OSERR); |
