From: Karel Zak Date: Mon, 1 Sep 2008 10:41:57 +0000 (+0200) Subject: login: fix warning "dereferencing type-punned pointer will break strict-aliasing... X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53e9eda352e0eabfc5a8f21828a8d5335f4520f0;p=util-linux 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 --- 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) {