From 4f5f35fc83067b2c4874fce00ea0b53ef2488489 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 14 Oct 2016 13:21:17 +0200 Subject: login: add xgetpwnam() Signed-off-by: Karel Zak --- login-utils/login.c | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) (limited to 'login-utils/login.c') diff --git a/login-utils/login.c b/login-utils/login.c index 9bc1bd9c4..7f311536e 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -77,6 +77,7 @@ #include "all-io.h" #include "fileutils.h" #include "ttyutils.h" +#include "pwdutils.h" #include "logindefs.h" @@ -107,6 +108,7 @@ struct login_context { char *username; /* from command line or PAM */ struct passwd *pwd; /* user info */ + char *pwdbuf; /* pwd strings */ pam_handle_t *pamh; /* PAM handler */ struct pam_conv conv; /* PAM conversation */ @@ -652,26 +654,6 @@ static void log_syslog(struct login_context *cxt) } } -static struct passwd *get_passwd_entry(const char *username, - char **pwdbuf, - struct passwd *pwd) -{ - struct passwd *res = NULL; - int x; - - if (!pwdbuf || !username) - return NULL; - - *pwdbuf = xrealloc(*pwdbuf, UL_GETPW_BUFSIZ); - - x = getpwnam_r(username, pwd, *pwdbuf, UL_GETPW_BUFSIZ, &res); - if (!res) { - errno = x; - return NULL; - } - return res; -} - /* encapsulate stupid "void **" pam_get_item() API */ static int loginpam_get_username(pam_handle_t *pamh, char **name) { @@ -1129,9 +1111,7 @@ int main(int argc, char **argv) int childArgc = 0; int retcode; struct sigaction act; - - char *pwdbuf = NULL; - struct passwd *pwd = NULL, _pwd; + struct passwd *pwd; struct login_context cxt = { .tty_mode = TTY_MODE, /* tty chmod() */ @@ -1243,7 +1223,8 @@ int main(int argc, char **argv) */ loginpam_acct(&cxt); - if (!(cxt.pwd = get_passwd_entry(cxt.username, &pwdbuf, &_pwd))) { + cxt.pwd = xgetpwnam(cxt.username, &cxt.pwdbuf); + if (!cxt.pwd) { warnx(_("\nSession setup problem, abort.")); syslog(LOG_ERR, _("Invalid user name \"%s\" in %s:%d. Abort."), cxt.username, __FUNCTION__, __LINE__); -- cgit v1.2.3-55-g7522