* lib/pwauth.c: Use a boolean for wipe_clear_pass and use_skey.

* lib/pwauth.c: Added splint annotations.
	* lib/pwauth.c: Added brackets and parenthesis.
	* lib/pwauth.c: Avoid assignments in comparisons.
	* lib/pwauth.c: Avoid implicit conversion of pointers or
	characters to booleans.
This commit is contained in:
nekral-guest 2009-04-23 20:46:01 +00:00
parent 916977c5bb
commit d0d01ffb00
2 changed files with 44 additions and 22 deletions

View File

@ -1,3 +1,12 @@
2009-04-22 Nicolas François <nicolas.francois@centraliens.net>
* lib/pwauth.c: Use a boolean for wipe_clear_pass and use_skey.
* lib/pwauth.c: Added splint annotations.
* lib/pwauth.c: Added brackets and parenthesis.
* lib/pwauth.c: Avoid assignments in comparisons.
* lib/pwauth.c: Avoid implicit conversion of pointers or
characters to booleans.
2009-04-22 Nicolas François <nicolas.francois@centraliens.net> 2009-04-22 Nicolas François <nicolas.francois@centraliens.net>
* src/groupmod.c: Cast ID to ulongs and use ulong formats for IDs. * src/groupmod.c: Cast ID to ulongs and use ulong formats for IDs.

View File

@ -2,7 +2,7 @@
* Copyright (c) 1992 - 1994, Julianne Frances Haugh * Copyright (c) 1992 - 1994, Julianne Frances Haugh
* Copyright (c) 1996 - 2000, Marek Michałkiewicz * Copyright (c) 1996 - 2000, Marek Michałkiewicz
* Copyright (c) 2003 - 2006, Tomasz Kłoczko * Copyright (c) 2003 - 2006, Tomasz Kłoczko
* Copyright (c) 2008 , Nicolas François * Copyright (c) 2008 - 2009, Nicolas François
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -54,8 +54,8 @@ static const char *PROMPT = gettext_noop ("Password: ");
static const char *PROMPT = gettext_noop ("%s's Password: "); static const char *PROMPT = gettext_noop ("%s's Password: ");
#endif #endif
int wipe_clear_pass = 1; bool wipe_clear_pass = true;
char *clear_pass = NULL; /*@null@*/char *clear_pass = NULL;
/* /*
* pw_auth - perform getpass/crypt authentication * pw_auth - perform getpass/crypt authentication
@ -65,8 +65,10 @@ char *clear_pass = NULL;
* compared. * compared.
*/ */
int int pw_auth (const char *cipher,
pw_auth (const char *cipher, const char *user, int reason, const char *input) const char *user,
int reason,
/*@null@*/const char *input)
{ {
char prompt[1024]; char prompt[1024];
char *clear = NULL; char *clear = NULL;
@ -74,7 +76,7 @@ pw_auth (const char *cipher, const char *user, int reason, const char *input)
int retval; int retval;
#ifdef SKEY #ifdef SKEY
int use_skey = 0; bool use_skey = false;
char challenge_info[40]; char challenge_info[40];
struct skey skey; struct skey skey;
#endif #endif
@ -83,15 +85,17 @@ pw_auth (const char *cipher, const char *user, int reason, const char *input)
* There are programs for adding and deleting authentication data. * There are programs for adding and deleting authentication data.
*/ */
if (reason == PW_ADD || reason == PW_DELETE) if ((PW_ADD == reason) || (PW_DELETE == reason)) {
return 0; return 0;
}
/* /*
* There are even programs for changing the user name ... * There are even programs for changing the user name ...
*/ */
if (reason == PW_CHANGE && input != (char *) 0) if ((PW_CHANGE == reason) && (NULL != input)) {
return 0; return 0;
}
/* /*
* WARNING: * WARNING:
@ -102,8 +106,9 @@ pw_auth (const char *cipher, const char *user, int reason, const char *input)
* revisited. * revisited.
*/ */
if (reason == PW_CHANGE && getuid () == 0) if ((PW_CHANGE == reason) && (getuid () == 0)) {
return 0; return 0;
}
/* /*
* WARNING: * WARNING:
@ -114,8 +119,9 @@ pw_auth (const char *cipher, const char *user, int reason, const char *input)
* matter. * matter.
*/ */
if (cipher == (char *) 0 || *cipher == '\0') if ((NULL == cipher) || ('\0' == *cipher)) {
return 0; return 0;
}
#ifdef SKEY #ifdef SKEY
/* /*
@ -132,8 +138,9 @@ pw_auth (const char *cipher, const char *user, int reason, const char *input)
# define skeychallenge(s,u,c) skeychallenge(s,u,c,sizeof(c)) # define skeychallenge(s,u,c) skeychallenge(s,u,c,sizeof(c))
# endif # endif
if (skeychallenge (&skey, user, challenge_info) == 0) if (skeychallenge (&skey, user, challenge_info) == 0) {
use_skey = 1; use_skey = true;
}
#endif #endif
/* /*
@ -141,17 +148,20 @@ pw_auth (const char *cipher, const char *user, int reason, const char *input)
* get the cleartext password for us. * get the cleartext password for us.
*/ */
if (reason != PW_FTP && reason != PW_REXEC && !input) { if ((PW_FTP != reason) && (PW_REXEC != reason) && (NULL == input)) {
if (!(cp = getdef_str ("LOGIN_STRING"))) cp = getdef_str ("LOGIN_STRING");
if (NULL == cp) {
cp = _(PROMPT); cp = _(PROMPT);
}
#ifdef SKEY #ifdef SKEY
if (use_skey) if (use_skey) {
printf ("[%s]\n", challenge_info); printf ("[%s]\n", challenge_info);
}
#endif #endif
snprintf (prompt, sizeof prompt, cp, user); snprintf (prompt, sizeof prompt, cp, user);
clear = getpass (prompt); clear = getpass (prompt);
if (!clear) { if (NULL == clear) {
static char c[1]; static char c[1];
c[0] = '\0'; c[0] = '\0';
@ -177,9 +187,9 @@ pw_auth (const char *cipher, const char *user, int reason, const char *input)
* ...Re-prompt, with echo on. * ...Re-prompt, with echo on.
* -- AR 8/22/1999 * -- AR 8/22/1999
*/ */
if (retval && !input[0] && (use_skey)) { if ((0 != retval) && ('\0' == input[0]) && use_skey) {
clear = getpass (prompt); clear = getpass (prompt);
if (!clear) { if (NULL == clear) {
static char c[1]; static char c[1];
c[0] = '\0'; c[0] = '\0';
@ -188,13 +198,15 @@ pw_auth (const char *cipher, const char *user, int reason, const char *input)
input = clear; input = clear;
} }
if (retval && use_skey) { if ((0 != retval) && use_skey) {
int passcheck = -1; int passcheck = -1;
if (skeyverify (&skey, input) == 0) if (skeyverify (&skey, input) == 0) {
passcheck = skey.n; passcheck = skey.n;
if (passcheck > 0) }
if (passcheck > 0) {
retval = 0; retval = 0;
}
} }
#endif #endif
@ -206,8 +218,9 @@ pw_auth (const char *cipher, const char *user, int reason, const char *input)
*/ */
clear_pass = clear; clear_pass = clear;
if (wipe_clear_pass && clear && *clear) if (wipe_clear_pass && (NULL != clear) && ('\0' != *clear)) {
strzero (clear); strzero (clear);
}
return retval; return retval;
} }
#else /* !USE_PAM */ #else /* !USE_PAM */