From d63e54e6c3aa9acb3015525d22e1d1b19ab4315c Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 1 Sep 2008 12:41:57 +0200 Subject: [PATCH] login: fix warning "dereferencing type-punned pointer will break strict-aliasing rules" This patch fix problems with odd pam_get_iten( ..., void **) API. (tested by gcc-4.1.2-42.el5.i386) Signed-off-by: Karel Zak --- login-utils/login.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/login-utils/login.c b/login-utils/login.c index 23012131..16bbba8d 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -342,6 +342,19 @@ logaudit(const char *tty, const char *username, const char *hostname, # define logaudit(tty, username, hostname, pwd, status) #endif /* HAVE_LIBAUDIT */ +#ifdef HAVE_SECURITY_PAM_MISC_H +/* encapsulate stupid "void **" pam_get_item() API */ +int +get_pam_username(pam_handle_t *pamh, char **name) +{ + const void *item = (void *) *name; + int rc; + rc = pam_get_item(pamh, PAM_USER, &item); + *name = (char *) item; + return rc; +} +#endif + int main(int argc, char **argv) { @@ -591,7 +604,7 @@ main(int argc, char **argv) int failcount=0; /* if we didn't get a user on the command line, set it to NULL */ - pam_get_item(pamh, PAM_USER, (const void **) &username); + get_pam_username(pamh, &username); /* there may be better ways to deal with some of these conditions, but at least this way I don't think we'll @@ -605,7 +618,7 @@ main(int argc, char **argv) (retcode == PAM_USER_UNKNOWN) || (retcode == PAM_CRED_INSUFFICIENT) || (retcode == PAM_AUTHINFO_UNAVAIL))) { - pam_get_item(pamh, PAM_USER, (const void **) &username); + get_pam_username(pamh, &username); syslog(LOG_NOTICE,_("FAILED LOGIN %d FROM %s FOR %s, %s"), failcount, hostname, username, pam_strerror(pamh, retcode)); @@ -618,7 +631,7 @@ main(int argc, char **argv) } if (retcode != PAM_SUCCESS) { - pam_get_item(pamh, PAM_USER, (const void **) &username); + get_pam_username(pamh, &username); if (retcode == PAM_MAXTRIES) syslog(LOG_NOTICE,_("TOO MANY LOGIN TRIES (%d) FROM %s FOR " @@ -654,7 +667,7 @@ main(int argc, char **argv) * Grab the user information out of the password file for future usage * First get the username that we are actually using, though. */ - retcode = pam_get_item(pamh, PAM_USER, (const void **) &username); + retcode = get_pam_username(pamh, &username); PAM_FAIL_CHECK; if (!username || !*username) { -- 2.39.5