* libmisc/obscure.c, lib/prototypes.h (obscure): Return a bool

instead of an int.
	* libmisc/obscure.c, libmisc/tz.c, src/passwd.c, lib/encrypt.c,
	libmisc/copydir.c, lib/prototypes.h: Add splint annotations.
	* libmisc/tz.c: Fix some const issues.
	* libmisc/tz.c: Avoid multi-statements lines.
	* libmisc/tz.c: Add brackets.
	* libmisc/copydir.c: Do not check *printf/*puts return value.
	* libmisc/copydir.c: Fail if we cannot set or reset the SELinux
	fscreate context.
	* libmisc/copydir.c: Use xmalloc instead of malloc.
	* libmisc/copydir.c: Do not check lutimes return value
	* src/vipw.c: Avoid implicit conversion of integer to boolean.
	* src/su.c (iswheel): Return a bool instead of an int.
	* src/passwd.c: Remove insert_crypt_passwd(). Use xstrdup instead.
	* src/passwd.c: Return constant strings when sufficient.
	* src/passwd.c: Do not check *printf/*puts return value.
	* src/passwd.c: Avoid implicit conversion of character to boolean.
	* src/passwd.c: Do not check sleep return value.
	* src/sulogin.c: Do not check *printf/*puts return value.
	* lib/encrypt.c: Do not check fprintf return value.
This commit is contained in:
nekral-guest 2010-08-22 12:49:07 +00:00
parent 7e398a169b
commit 471a2df3a6
10 changed files with 222 additions and 175 deletions

View File

@ -1,3 +1,27 @@
2010-08-22 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/obscure.c, lib/prototypes.h (obscure): Return a bool
instead of an int.
* libmisc/obscure.c, libmisc/tz.c, src/passwd.c, lib/encrypt.c,
libmisc/copydir.c, lib/prototypes.h: Add splint annotations.
* libmisc/tz.c: Fix some const issues.
* libmisc/tz.c: Avoid multi-statements lines.
* libmisc/tz.c: Add brackets.
* libmisc/copydir.c: Do not check *printf/*puts return value.
* libmisc/copydir.c: Fail if we cannot set or reset the SELinux
fscreate context.
* libmisc/copydir.c: Use xmalloc instead of malloc.
* libmisc/copydir.c: Do not check lutimes return value
* src/vipw.c: Avoid implicit conversion of integer to boolean.
* src/su.c (iswheel): Return a bool instead of an int.
* src/passwd.c: Remove insert_crypt_passwd(). Use xstrdup instead.
* src/passwd.c: Return constant strings when sufficient.
* src/passwd.c: Do not check *printf/*puts return value.
* src/passwd.c: Avoid implicit conversion of character to boolean.
* src/passwd.c: Do not check sleep return value.
* src/sulogin.c: Do not check *printf/*puts return value.
* lib/encrypt.c: Do not check fprintf return value.
2010-08-21 Nicolas François <nicolas.francois@centraliens.net> 2010-08-21 Nicolas François <nicolas.francois@centraliens.net>
* src/passwd.c: Fix a const issue. * src/passwd.c: Fix a const issue.

View File

@ -40,7 +40,7 @@
#include "prototypes.h" #include "prototypes.h"
#include "defines.h" #include "defines.h"
char *pw_encrypt (const char *clear, const char *salt) /*@exposed@*/char *pw_encrypt (const char *clear, const char *salt)
{ {
static char cipher[128]; static char cipher[128];
char *cp; char *cp;
@ -60,7 +60,7 @@ char *pw_encrypt (const char *clear, const char *salt)
* supported, and return a DES encrypted password. */ * supported, and return a DES encrypted password. */
if ((NULL != salt) && (salt[0] == '$') && (strlen (cp) <= 13)) if ((NULL != salt) && (salt[0] == '$') && (strlen (cp) <= 13))
{ {
const char *method; /*@observer@*/const char *method;
switch (salt[1]) switch (salt[1])
{ {
case '1': case '1':
@ -79,9 +79,9 @@ char *pw_encrypt (const char *clear, const char *salt)
method = &nummethod[0]; method = &nummethod[0];
} }
} }
fprintf (stderr, (void) fprintf (stderr,
_("crypt method not supported by libcrypt? (%s)\n"), _("crypt method not supported by libcrypt? (%s)\n"),
method); method);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }

View File

@ -127,7 +127,7 @@ extern int selinux_file_context (const char *dst_name);
#endif #endif
/* encrypt.c */ /* encrypt.c */
extern char *pw_encrypt (const char *, const char *); extern /*@exposed@*/char *pw_encrypt (const char *, const char *);
/* entry.c */ /* entry.c */
extern void pw_entry (const char *, struct passwd *); extern void pw_entry (const char *, struct passwd *);
@ -250,7 +250,7 @@ extern int do_pam_passwd_non_interractive (const char *pam_service,
/* obscure.c */ /* obscure.c */
#ifndef USE_PAM #ifndef USE_PAM
extern int obscure (const char *, const char *, const struct passwd *); extern bool obscure (const char *, const char *, const struct passwd *);
#endif #endif
/* pam_pass.c */ /* pam_pass.c */
@ -363,7 +363,7 @@ extern void ttytype (const char *);
/* tz.c */ /* tz.c */
#ifndef USE_PAM #ifndef USE_PAM
extern char *tz (const char *); extern /*@observer@*/const char *tz (const char *);
#endif #endif
/* ulimit.c */ /* ulimit.c */

View File

@ -77,7 +77,7 @@ static int copy_dir (const char *src, const char *dst,
uid_t old_uid, uid_t new_uid, uid_t old_uid, uid_t new_uid,
gid_t old_gid, gid_t new_gid); gid_t old_gid, gid_t new_gid);
#ifdef S_IFLNK #ifdef S_IFLNK
static char *readlink_malloc (const char *filename); static /*@null@*/char *readlink_malloc (const char *filename);
static int copy_symlink (const char *src, const char *dst, static int copy_symlink (const char *src, const char *dst,
unused bool reset_selinux, unused bool reset_selinux,
const struct stat *statp, const struct timeval mt[], const struct stat *statp, const struct timeval mt[],
@ -123,7 +123,7 @@ int selinux_file_context (const char *dst_name)
{ {
static bool selinux_checked = false; static bool selinux_checked = false;
static bool selinux_enabled; static bool selinux_enabled;
security_context_t scontext = NULL; /*@null@*/security_context_t scontext = NULL;
if (!selinux_checked) { if (!selinux_checked) {
selinux_enabled = is_selinux_enabled () > 0; selinux_enabled = is_selinux_enabled () > 0;
@ -236,7 +236,7 @@ static /*@exposed@*/ /*@null@*/struct link_name *check_link (const char *name, c
lp->ln_count = sb->st_nlink; lp->ln_count = sb->st_nlink;
len = name_len - src_len + dst_len + 1; len = name_len - src_len + dst_len + 1;
lp->ln_name = (char *) xmalloc (len); lp->ln_name = (char *) xmalloc (len);
snprintf (lp->ln_name, len, "%s%s", dst_orig, name + src_len); (void) snprintf (lp->ln_name, len, "%s%s", dst_orig, name + src_len);
lp->ln_next = links; lp->ln_next = links;
links = lp; links = lp;
@ -342,10 +342,10 @@ int copy_tree (const char *src_root, const char *dst_root,
* Build the filename for both the source and * Build the filename for both the source and
* the destination files. * the destination files.
*/ */
snprintf (src_name, src_len, "%s/%s", (void) snprintf (src_name, src_len, "%s/%s",
src_root, ent->d_name); src_root, ent->d_name);
snprintf (dst_name, dst_len, "%s/%s", (void) snprintf (dst_name, dst_len, "%s/%s",
dst_root, ent->d_name); dst_root, ent->d_name);
err = copy_entry (src_name, dst_name, err = copy_entry (src_name, dst_name,
reset_selinux, reset_selinux,
@ -374,7 +374,9 @@ int copy_tree (const char *src_root, const char *dst_root,
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
/* Reset SELinux to create files with default contexts */ /* Reset SELinux to create files with default contexts */
setfscreatecon (NULL); if (setfscreatecon (NULL) != 0) {
err = -1;
}
#endif /* WITH_SELINUX */ #endif /* WITH_SELINUX */
return err; return err;
@ -509,7 +511,9 @@ static int copy_dir (const char *src, const char *dst,
*/ */
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
selinux_file_context (dst); if (selinux_file_context (dst) != 0) {
return -1;
}
#endif /* WITH_SELINUX */ #endif /* WITH_SELINUX */
if ( (mkdir (dst, statp->st_mode) != 0) if ( (mkdir (dst, statp->st_mode) != 0)
|| (chown_if_needed (dst, statp, || (chown_if_needed (dst, statp,
@ -545,11 +549,11 @@ static int copy_dir (const char *src, const char *dst,
* return NULL on error. * return NULL on error.
* The return string shall be freed by the caller. * The return string shall be freed by the caller.
*/ */
static char *readlink_malloc (const char *filename) static /*@null@*/char *readlink_malloc (const char *filename)
{ {
size_t size = 1024; size_t size = 1024;
while (1) { while (true) {
ssize_t nchars; ssize_t nchars;
char *buffer = (char *) malloc (size); char *buffer = (char *) malloc (size);
if (NULL == buffer) { if (NULL == buffer) {
@ -563,7 +567,7 @@ static char *readlink_malloc (const char *filename)
return NULL; return NULL;
} }
if ( (size_t) nchars < size) { /* The buffer was large enough */ if ((size_t) nchars < size) { /* The buffer was large enough */
/* readlink does not nul-terminate */ /* readlink does not nul-terminate */
buffer[nchars] = '\0'; buffer[nchars] = '\0';
return buffer; return buffer;
@ -616,16 +620,19 @@ static int copy_symlink (const char *src, const char *dst,
*/ */
if (strncmp (oldlink, src_orig, strlen (src_orig)) == 0) { if (strncmp (oldlink, src_orig, strlen (src_orig)) == 0) {
size_t len = strlen (dst_orig) + strlen (oldlink) - strlen (src_orig) + 1; size_t len = strlen (dst_orig) + strlen (oldlink) - strlen (src_orig) + 1;
char *dummy = (char *) malloc (len); char *dummy = (char *) xmalloc (len);
snprintf (dummy, len, "%s%s", (void) snprintf (dummy, len, "%s%s",
dst_orig, dst_orig,
oldlink + strlen (src_orig)); oldlink + strlen (src_orig));
free (oldlink); free (oldlink);
oldlink = dummy; oldlink = dummy;
} }
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
selinux_file_context (dst); if (selinux_file_context (dst) != 0) {
free (oldlink);
return -1;
}
#endif /* WITH_SELINUX */ #endif /* WITH_SELINUX */
if ( (symlink (oldlink, dst) != 0) if ( (symlink (oldlink, dst) != 0)
|| (lchown_if_needed (dst, statp, || (lchown_if_needed (dst, statp,
@ -648,7 +655,7 @@ static int copy_symlink (const char *src, const char *dst,
* it returns ENOSYS on many system * it returns ENOSYS on many system
* - not implemented * - not implemented
*/ */
lutimes (dst, mt); (void) lutimes (dst, mt);
#endif /* HAVE_LUTIMES */ #endif /* HAVE_LUTIMES */
return 0; return 0;
@ -701,7 +708,9 @@ static int copy_special (const char *src, const char *dst,
int err = 0; int err = 0;
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
selinux_file_context (dst); if (selinux_file_context (dst) != 0) {
return -1;
}
#endif /* WITH_SELINUX */ #endif /* WITH_SELINUX */
if ( (mknod (dst, statp->st_mode & ~07777, statp->st_rdev) != 0) if ( (mknod (dst, statp->st_mode & ~07777, statp->st_rdev) != 0)
@ -756,7 +765,9 @@ static int copy_file (const char *src, const char *dst,
return -1; return -1;
} }
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
selinux_file_context (dst); if (selinux_file_context (dst) != 0) {
return -1;
}
#endif /* WITH_SELINUX */ #endif /* WITH_SELINUX */
ofd = open (dst, O_WRONLY | O_CREAT | O_TRUNC, statp->st_mode & 07777); ofd = open (dst, O_WRONLY | O_CREAT | O_TRUNC, statp->st_mode & 07777);
if ( (ofd < 0) if ( (ofd < 0)

View File

@ -304,15 +304,15 @@ static const char *obscure_msg (const char *old, const char *new,
* check passwords. * check passwords.
*/ */
int obscure (const char *old, const char *new, const struct passwd *pwdp) bool obscure (const char *old, const char *new, const struct passwd *pwdp)
{ {
const char *msg = obscure_msg (old, new, pwdp); const char *msg = obscure_msg (old, new, pwdp);
if (NULL != msg) { if (NULL != msg) {
printf (_("Bad password: %s. "), msg); printf (_("Bad password: %s. "), msg);
return 0; return false;
} }
return 1; return true;
} }
#else /* !USE_PAM */ #else /* !USE_PAM */

View File

@ -49,23 +49,28 @@
* tz() determines the name of the local timezone by reading the * tz() determines the name of the local timezone by reading the
* contents of the file named by ``fname''. * contents of the file named by ``fname''.
*/ */
char *tz (const char *fname) /*@observer@*/const char *tz (const char *fname)
{ {
FILE *fp = 0; FILE *fp = NULL;
static char tzbuf[BUFSIZ]; static char tzbuf[BUFSIZ];
const char *def_tz = "TZ=CST6CDT"; const char *def_tz = "TZ=CST6CDT";
if ((fp = fopen (fname, "r")) == NULL || fp = fopen (fname, "r");
fgets (tzbuf, (int) sizeof (tzbuf), fp) == NULL) { if ( (NULL == fp)
if (!(def_tz = getdef_str ("ENV_TZ")) || def_tz[0] == '/') || (fgets (tzbuf, (int) sizeof (tzbuf), fp) == NULL)) {
def_tz = getdef_str ("ENV_TZ");
if ((NULL == def_tz) || ('/' == def_tz[0])) {
def_tz = "TZ=CST6CDT"; def_tz = "TZ=CST6CDT";
}
strcpy (tzbuf, def_tz); strcpy (tzbuf, def_tz);
} else } else {
tzbuf[strlen (tzbuf) - 1] = '\0'; tzbuf[strlen (tzbuf) - 1] = '\0';
}
if (fp) if (NULL != fp) {
(void) fclose (fp); (void) fclose (fp);
}
return tzbuf; return tzbuf;
} }

View File

@ -131,20 +131,19 @@ static bool do_update_pwd = false;
*/ */
/* local function prototypes */ /* local function prototypes */
static void usage (int); static /*@noreturn@*/void usage (int);
#ifndef USE_PAM #ifndef USE_PAM
static int reuse (const char *, const struct passwd *); static bool reuse (const char *, const struct passwd *);
static int new_password (const struct passwd *); static int new_password (const struct passwd *);
static void check_password (const struct passwd *, const struct spwd *); static void check_password (const struct passwd *, const struct spwd *);
static char *insert_crypt_passwd (const char *, const char *);
#endif /* !USE_PAM */ #endif /* !USE_PAM */
static char *date_to_str (time_t); static /*@observer@*/const char *date_to_str (time_t);
static const char *pw_status (const char *); static /*@observer@*/const char *pw_status (const char *);
static void print_status (const struct passwd *); static void print_status (const struct passwd *);
static void fail_exit (int); static /*@noreturn@*/void fail_exit (int);
static void oom (void); static /*@noreturn@*/void oom (void);
static char *update_crypt_pw (char *); static char *update_crypt_pw (char *);
static void update_noshadow (void); static void update_noshadow (void);
@ -158,8 +157,9 @@ static int check_selinux_access (const char *changed_user,
/* /*
* usage - print command usage and exit * usage - print command usage and exit
*/ */
static void usage (int status) static /*@noreturn@*/void usage (int status)
{ {
(void)
fputs (_("Usage: passwd [options] [LOGIN]\n" fputs (_("Usage: passwd [options] [LOGIN]\n"
"\n" "\n"
"Options:\n" "Options:\n"
@ -185,7 +185,7 @@ static void usage (int status)
} }
#ifndef USE_PAM #ifndef USE_PAM
static int reuse (const char *pass, const struct passwd *pw) static bool reuse (const char *pass, const struct passwd *pw)
{ {
#ifdef HAVE_LIBCRACK_HIST #ifdef HAVE_LIBCRACK_HIST
const char *reason; const char *reason;
@ -200,11 +200,11 @@ static int reuse (const char *pass, const struct passwd *pw)
reason = FascistHistory (pass, pw->pw_uid); reason = FascistHistory (pass, pw->pw_uid);
#endif /* !HAVE_LIBCRACK_PW */ #endif /* !HAVE_LIBCRACK_PW */
if (NULL != reason) { if (NULL != reason) {
printf (_("Bad password: %s. "), reason); (void) printf (_("Bad password: %s. "), reason);
return 1; return true;
} }
#endif /* HAVE_LIBCRACK_HIST */ #endif /* HAVE_LIBCRACK_HIST */
return 0; return false;
} }
/* /*
@ -219,7 +219,7 @@ static int new_password (const struct passwd *pw)
char orig[200]; /* Original password */ char orig[200]; /* Original password */
char pass[200]; /* New password */ char pass[200]; /* New password */
int i; /* Counter for retries */ int i; /* Counter for retries */
int warned; bool warned;
int pass_max_len = -1; int pass_max_len = -1;
const char *method; const char *method;
@ -232,7 +232,7 @@ static int new_password (const struct passwd *pw)
* password. * password.
*/ */
if (!amroot && crypt_passwd[0]) { if (!amroot && ('\0' != crypt_passwd[0])) {
clear = getpass (_("Old password: ")); clear = getpass (_("Old password: "));
if (NULL == clear) { if (NULL == clear) {
return -1; return -1;
@ -240,12 +240,14 @@ static int new_password (const struct passwd *pw)
cipher = pw_encrypt (clear, crypt_passwd); cipher = pw_encrypt (clear, crypt_passwd);
if (strcmp (cipher, crypt_passwd) != 0) { if (strcmp (cipher, crypt_passwd) != 0) {
strzero (clear);
strzero (cipher);
SYSLOG ((LOG_WARN, "incorrect password for %s", SYSLOG ((LOG_WARN, "incorrect password for %s",
pw->pw_name)); pw->pw_name));
sleep (1); (void) sleep (1);
fprintf (stderr, (void) fprintf (stderr,
_("Incorrect password for %s.\n"), _("Incorrect password for %s.\n"),
pw->pw_name); pw->pw_name);
return -1; return -1;
} }
STRFCPY (orig, clear); STRFCPY (orig, clear);
@ -280,19 +282,19 @@ static int new_password (const struct passwd *pw)
} }
if (!qflg) { if (!qflg) {
if (pass_max_len == -1) { if (pass_max_len == -1) {
printf (_( (void) printf (_(
"Enter the new password (minimum of %d characters)\n" "Enter the new password (minimum of %d characters)\n"
"Please use a combination of upper and lower case letters and numbers.\n"), "Please use a combination of upper and lower case letters and numbers.\n"),
getdef_num ("PASS_MIN_LEN", 5)); getdef_num ("PASS_MIN_LEN", 5));
} else { } else {
printf (_( (void) printf (_(
"Enter the new password (minimum of %d, maximum of %d characters)\n" "Enter the new password (minimum of %d, maximum of %d characters)\n"
"Please use a combination of upper and lower case letters and numbers.\n"), "Please use a combination of upper and lower case letters and numbers.\n"),
getdef_num ("PASS_MIN_LEN", 5), pass_max_len); getdef_num ("PASS_MIN_LEN", 5), pass_max_len);
} }
} }
warned = 0; warned = false;
for (i = getdef_num ("PASS_CHANGE_TRIES", 5); i > 0; i--) { for (i = getdef_num ("PASS_CHANGE_TRIES", 5); i > 0; i--) {
cp = getpass (_("New password: ")); cp = getpass (_("New password: "));
if (NULL == cp) { if (NULL == cp) {
@ -300,13 +302,13 @@ static int new_password (const struct passwd *pw)
return -1; return -1;
} }
if (warned && (strcmp (pass, cp) != 0)) { if (warned && (strcmp (pass, cp) != 0)) {
warned = 0; warned = false;
} }
STRFCPY (pass, cp); STRFCPY (pass, cp);
strzero (cp); strzero (cp);
if (!amroot && (!obscure (orig, pass, pw) || reuse (pass, pw))) { if (!amroot && (!obscure (orig, pass, pw) || reuse (pass, pw))) {
puts (_("Try again.")); (void) puts (_("Try again."));
continue; continue;
} }
@ -317,8 +319,8 @@ static int new_password (const struct passwd *pw)
*/ */
if (amroot && !warned && getdef_bool ("PASS_ALWAYS_WARN") if (amroot && !warned && getdef_bool ("PASS_ALWAYS_WARN")
&& (!obscure (orig, pass, pw) || reuse (pass, pw))) { && (!obscure (orig, pass, pw) || reuse (pass, pw))) {
puts (_("\nWarning: weak password (enter it again to use it anyway).")); (void) puts (_("\nWarning: weak password (enter it again to use it anyway)."));
warned++; warned = true;
continue; continue;
} }
cp = getpass (_("Re-enter new password: ")); cp = getpass (_("Re-enter new password: "));
@ -327,7 +329,7 @@ static int new_password (const struct passwd *pw)
return -1; return -1;
} }
if (strcmp (cp, pass) != 0) { if (strcmp (cp, pass) != 0) {
fputs (_("They don't match; try again.\n"), stderr); (void) fputs (_("They don't match; try again.\n"), stderr);
} else { } else {
strzero (cp); strzero (cp);
break; break;
@ -393,9 +395,9 @@ static void check_password (const struct passwd *pw, const struct spwd *sp)
|| (exp_status > 1) || (exp_status > 1)
|| ( (sp->sp_max >= 0) || ( (sp->sp_max >= 0)
&& (sp->sp_min > sp->sp_max))) { && (sp->sp_min > sp->sp_max))) {
fprintf (stderr, (void) fprintf (stderr,
_("The password for %s cannot be changed.\n"), _("The password for %s cannot be changed.\n"),
sp->sp_namp); sp->sp_namp);
SYSLOG ((LOG_WARN, "password locked for '%s'", sp->sp_namp)); SYSLOG ((LOG_WARN, "password locked for '%s'", sp->sp_namp));
closelog (); closelog ();
exit (E_NOPERM); exit (E_NOPERM);
@ -410,42 +412,33 @@ static void check_password (const struct passwd *pw, const struct spwd *sp)
ok = last + (sp->sp_min > 0 ? sp->sp_min * SCALE : 0); ok = last + (sp->sp_min > 0 ? sp->sp_min * SCALE : 0);
if (now < ok) { if (now < ok) {
fprintf (stderr, (void) fprintf (stderr,
_("The password for %s cannot be changed yet.\n"), _("The password for %s cannot be changed yet.\n"),
pw->pw_name); pw->pw_name);
SYSLOG ((LOG_WARN, "now < minimum age for '%s'", pw->pw_name)); SYSLOG ((LOG_WARN, "now < minimum age for '%s'", pw->pw_name));
closelog (); closelog ();
exit (E_NOPERM); exit (E_NOPERM);
} }
} }
} }
/*
* insert_crypt_passwd - add an "old-style" password to authentication
* string result now malloced to avoid overflow, just in case. --marekm
*/
static char *insert_crypt_passwd (const char *string, const char *passwd)
{
return xstrdup (passwd);
}
#endif /* !USE_PAM */ #endif /* !USE_PAM */
static char *date_to_str (time_t t) static /*@observer@*/const char *date_to_str (time_t t)
{ {
static char buf[80]; static char buf[80];
struct tm *tm; struct tm *tm;
tm = gmtime (&t); tm = gmtime (&t);
#ifdef HAVE_STRFTIME #ifdef HAVE_STRFTIME
strftime (buf, sizeof buf, "%m/%d/%Y", tm); (void) strftime (buf, sizeof buf, "%m/%d/%Y", tm);
#else /* !HAVE_STRFTIME */ #else /* !HAVE_STRFTIME */
snprintf (buf, sizeof buf, "%02d/%02d/%04d", (void) snprintf (buf, sizeof buf, "%02d/%02d/%04d",
tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900); tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
#endif /* !HAVE_STRFTIME */ #endif /* !HAVE_STRFTIME */
return buf; return buf;
} }
static const char *pw_status (const char *pass) static /*@observer@*/const char *pw_status (const char *pass)
{ {
if (*pass == '*' || *pass == '!') { if (*pass == '*' || *pass == '!') {
return "L"; return "L";
@ -465,25 +458,26 @@ static void print_status (const struct passwd *pw)
sp = getspnam (pw->pw_name); /* local, no need for xgetspnam */ sp = getspnam (pw->pw_name); /* local, no need for xgetspnam */
if (NULL != sp) { if (NULL != sp) {
printf ("%s %s %s %ld %ld %ld %ld\n", (void) printf ("%s %s %s %ld %ld %ld %ld\n",
pw->pw_name, pw->pw_name,
pw_status (sp->sp_pwdp), pw_status (sp->sp_pwdp),
date_to_str (sp->sp_lstchg * SCALE), date_to_str (sp->sp_lstchg * SCALE),
(sp->sp_min * SCALE) / DAY, (sp->sp_min * SCALE) / DAY,
(sp->sp_max * SCALE) / DAY, (sp->sp_max * SCALE) / DAY,
(sp->sp_warn * SCALE) / DAY, (sp->sp_warn * SCALE) / DAY,
(sp->sp_inact * SCALE) / DAY); (sp->sp_inact * SCALE) / DAY);
} else { } else {
printf ("%s %s\n", pw->pw_name, pw_status (pw->pw_passwd)); (void) printf ("%s %s\n",
pw->pw_name, pw_status (pw->pw_passwd));
} }
} }
static void fail_exit (int status) static /*@noreturn@*/void fail_exit (int status)
{ {
if (pw_locked) { if (pw_locked) {
if (pw_unlock () == 0) { if (pw_unlock () == 0) {
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); (void) fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ())); SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
/* continue */ /* continue */
} }
@ -491,7 +485,7 @@ static void fail_exit (int status)
if (spw_locked) { if (spw_locked) {
if (spw_unlock () == 0) { if (spw_unlock () == 0) {
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); (void) fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ())); SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
/* continue */ /* continue */
} }
@ -500,9 +494,9 @@ static void fail_exit (int status)
exit (status); exit (status);
} }
static void oom (void) static /*@noreturn@*/void oom (void)
{ {
fprintf (stderr, _("%s: out of memory\n"), Prog); (void) fprintf (stderr, _("%s: out of memory\n"), Prog);
fail_exit (E_FAILURE); fail_exit (E_FAILURE);
} }
@ -510,7 +504,7 @@ static char *update_crypt_pw (char *cp)
{ {
#ifndef USE_PAM #ifndef USE_PAM
if (do_update_pwd) { if (do_update_pwd) {
cp = insert_crypt_passwd (cp, crypt_passwd); cp = xstrdup (crypt_passwd);
} }
#endif /* !USE_PAM */ #endif /* !USE_PAM */
@ -520,10 +514,10 @@ static char *update_crypt_pw (char *cp)
if (uflg && *cp == '!') { if (uflg && *cp == '!') {
if (cp[1] == '\0') { if (cp[1] == '\0') {
fprintf (stderr, (void) fprintf (stderr,
_("%s: unlocking the password would result in a passwordless account.\n" _("%s: unlocking the password would result in a passwordless account.\n"
"You should set a password with usermod -p to unlock the password of this account.\n"), "You should set a password with usermod -p to unlock the password of this account.\n"),
Prog); Prog);
fail_exit (E_FAILURE); fail_exit (E_FAILURE);
} else { } else {
cp++; cp++;
@ -547,24 +541,24 @@ static void update_noshadow (void)
struct passwd *npw; struct passwd *npw;
if (pw_lock () == 0) { if (pw_lock () == 0) {
fprintf (stderr, (void) fprintf (stderr,
_("%s: cannot lock %s; try again later.\n"), _("%s: cannot lock %s; try again later.\n"),
Prog, pw_dbname ()); Prog, pw_dbname ());
exit (E_PWDBUSY); exit (E_PWDBUSY);
} }
pw_locked = true; pw_locked = true;
if (pw_open (O_RDWR) == 0) { if (pw_open (O_RDWR) == 0) {
fprintf (stderr, (void) fprintf (stderr,
_("%s: cannot open %s\n"), _("%s: cannot open %s\n"),
Prog, pw_dbname ()); Prog, pw_dbname ());
SYSLOG ((LOG_WARN, "cannot open %s", pw_dbname ())); SYSLOG ((LOG_WARN, "cannot open %s", pw_dbname ()));
fail_exit (E_MISSING); fail_exit (E_MISSING);
} }
pw = pw_locate (name); pw = pw_locate (name);
if (NULL == pw) { if (NULL == pw) {
fprintf (stderr, (void) fprintf (stderr,
_("%s: user '%s' does not exist in %s\n"), _("%s: user '%s' does not exist in %s\n"),
Prog, name, pw_dbname ()); Prog, name, pw_dbname ());
fail_exit (E_NOPERM); fail_exit (E_NOPERM);
} }
npw = __pw_dup (pw); npw = __pw_dup (pw);
@ -573,20 +567,22 @@ static void update_noshadow (void)
} }
npw->pw_passwd = update_crypt_pw (npw->pw_passwd); npw->pw_passwd = update_crypt_pw (npw->pw_passwd);
if (pw_update (npw) == 0) { if (pw_update (npw) == 0) {
fprintf (stderr, (void) fprintf (stderr,
_("%s: failed to prepare the new %s entry '%s'\n"), _("%s: failed to prepare the new %s entry '%s'\n"),
Prog, pw_dbname (), npw->pw_name); Prog, pw_dbname (), npw->pw_name);
fail_exit (E_FAILURE); fail_exit (E_FAILURE);
} }
if (pw_close () == 0) { if (pw_close () == 0) {
fprintf (stderr, (void) fprintf (stderr,
_("%s: failure while writing changes to %s\n"), _("%s: failure while writing changes to %s\n"),
Prog, pw_dbname ()); Prog, pw_dbname ());
SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ())); SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
fail_exit (E_FAILURE); fail_exit (E_FAILURE);
} }
if (pw_unlock () == 0) { if (pw_unlock () == 0) {
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); (void) fprintf (stderr,
_("%s: failed to unlock %s\n"),
Prog, pw_dbname ());
SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ())); SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
/* continue */ /* continue */
} }
@ -599,14 +595,16 @@ static void update_shadow (void)
struct spwd *nsp; struct spwd *nsp;
if (spw_lock () == 0) { if (spw_lock () == 0) {
fprintf (stderr, (void) fprintf (stderr,
_("%s: cannot lock %s; try again later.\n"), _("%s: cannot lock %s; try again later.\n"),
Prog, spw_dbname ()); Prog, spw_dbname ());
exit (E_PWDBUSY); exit (E_PWDBUSY);
} }
spw_locked = true; spw_locked = true;
if (spw_open (O_RDWR) == 0) { if (spw_open (O_RDWR) == 0) {
fprintf (stderr, _("%s: cannot open %s\n"), Prog, spw_dbname ()); (void) fprintf (stderr,
_("%s: cannot open %s\n"),
Prog, spw_dbname ());
SYSLOG ((LOG_WARN, "cannot open %s", spw_dbname ())); SYSLOG ((LOG_WARN, "cannot open %s", spw_dbname ()));
fail_exit (E_FAILURE); fail_exit (E_FAILURE);
} }
@ -616,7 +614,9 @@ static void update_shadow (void)
(void) spw_close (); (void) spw_close ();
update_noshadow (); update_noshadow ();
if (spw_unlock () == 0) { if (spw_unlock () == 0) {
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); (void) fprintf (stderr,
_("%s: failed to unlock %s\n"),
Prog, spw_dbname ());
SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ())); SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
/* continue */ /* continue */
} }
@ -661,20 +661,22 @@ static void update_shadow (void)
} }
if (spw_update (nsp) == 0) { if (spw_update (nsp) == 0) {
fprintf (stderr, (void) fprintf (stderr,
_("%s: failed to prepare the new %s entry '%s'\n"), _("%s: failed to prepare the new %s entry '%s'\n"),
Prog, spw_dbname (), nsp->sp_namp); Prog, spw_dbname (), nsp->sp_namp);
fail_exit (E_FAILURE); fail_exit (E_FAILURE);
} }
if (spw_close () == 0) { if (spw_close () == 0) {
fprintf (stderr, (void) fprintf (stderr,
_("%s: failure while writing changes to %s\n"), _("%s: failure while writing changes to %s\n"),
Prog, spw_dbname ()); Prog, spw_dbname ());
SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ())); SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
fail_exit (E_FAILURE); fail_exit (E_FAILURE);
} }
if (spw_unlock () == 0) { if (spw_unlock () == 0) {
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); (void) fprintf (stderr,
_("%s: failed to unlock %s\n"),
Prog, spw_dbname ());
SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ())); SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
/* continue */ /* continue */
} }
@ -880,9 +882,9 @@ int main (int argc, char **argv)
case 'w': case 'w':
if ( (getlong (optarg, &warn) == 0) if ( (getlong (optarg, &warn) == 0)
|| (warn < -1)) { || (warn < -1)) {
fprintf (stderr, (void) fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"), _("%s: invalid numeric argument '%s'\n"),
Prog, optarg); Prog, optarg);
usage (E_BAD_ARG); usage (E_BAD_ARG);
} }
wflg = true; wflg = true;
@ -891,9 +893,9 @@ int main (int argc, char **argv)
case 'x': case 'x':
if ( (getlong (optarg, &age_max) == 0) if ( (getlong (optarg, &age_max) == 0)
|| (age_max < -1)) { || (age_max < -1)) {
fprintf (stderr, (void) fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"), _("%s: invalid numeric argument '%s'\n"),
Prog, optarg); Prog, optarg);
usage (E_BAD_ARG); usage (E_BAD_ARG);
} }
xflg = true; xflg = true;
@ -901,7 +903,7 @@ int main (int argc, char **argv)
break; break;
case 'h': case 'h':
usage (E_SUCCESS); usage (E_SUCCESS);
break; /*@notreached@*/break;
default: default:
usage (E_BAD_ARG); usage (E_BAD_ARG);
} }
@ -915,8 +917,9 @@ int main (int argc, char **argv)
*/ */
pw = get_my_pwent (); pw = get_my_pwent ();
if (NULL == pw) { if (NULL == pw) {
fprintf (stderr, (void) fprintf (stderr,
_("%s: Cannot determine your user name.\n"), Prog); _("%s: Cannot determine your user name.\n"),
Prog);
SYSLOG ((LOG_WARN, "Cannot determine the user name of the caller (UID %lu)", SYSLOG ((LOG_WARN, "Cannot determine the user name of the caller (UID %lu)",
(unsigned long) getuid ())); (unsigned long) getuid ()));
exit (E_NOPERM); exit (E_NOPERM);
@ -944,7 +947,9 @@ int main (int argc, char **argv)
usage (E_USAGE); usage (E_USAGE);
} }
if (!amroot) { if (!amroot) {
fprintf (stderr, _("%s: Permission denied.\n"), Prog); (void) fprintf (stderr,
_("%s: Permission denied.\n"),
Prog);
exit (E_NOPERM); exit (E_NOPERM);
} }
setpwent (); setpwent ();
@ -984,13 +989,15 @@ int main (int argc, char **argv)
} }
if (anyflag && !amroot) { if (anyflag && !amroot) {
fprintf (stderr, _("%s: Permission denied.\n"), Prog); (void) fprintf (stderr, _("%s: Permission denied.\n"), Prog);
exit (E_NOPERM); exit (E_NOPERM);
} }
pw = xgetpwnam (name); pw = xgetpwnam (name);
if (NULL == pw) { if (NULL == pw) {
fprintf (stderr, _("%s: user '%s' does not exist\n"), Prog, name); (void) fprintf (stderr,
_("%s: user '%s' does not exist\n"),
Prog, name);
exit (E_NOPERM); exit (E_NOPERM);
} }
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
@ -1001,14 +1008,14 @@ int main (int argc, char **argv)
security_context_t user_context = NULL; security_context_t user_context = NULL;
const char *user = "Unknown user context"; const char *user = "Unknown user context";
if (getprevcon (&user_context) == 0) { if (getprevcon (&user_context) == 0) {
user = user_context; user = user_context; /* FIXME: use context_user_get? */
} }
SYSLOG ((LOG_ALERT, SYSLOG ((LOG_ALERT,
"%s is not authorized to change the password of %s", "%s is not authorized to change the password of %s",
user, name)); user, name));
fprintf(stderr, (void) fprintf(stderr,
_("%s: %s is not authorized to change the password of %s\n"), _("%s: %s is not authorized to change the password of %s\n"),
Prog, user, name); Prog, user, name);
if (NULL != user_context) { if (NULL != user_context) {
freecon (user_context); freecon (user_context);
} }
@ -1021,12 +1028,12 @@ int main (int argc, char **argv)
* check if I'm root. * check if I'm root.
*/ */
if (!amroot && (pw->pw_uid != getuid ())) { if (!amroot && (pw->pw_uid != getuid ())) {
fprintf (stderr, (void) fprintf (stderr,
_("%s: You may not view or modify password information for %s.\n"), _("%s: You may not view or modify password information for %s.\n"),
Prog, name); Prog, name);
SYSLOG ((LOG_WARN, SYSLOG ((LOG_WARN,
"%s: can't view or modify password information for %s", "%s: can't view or modify password information for %s",
Prog, name)); Prog, name));
closelog (); closelog ();
exit (E_NOPERM); exit (E_NOPERM);
} }
@ -1062,13 +1069,13 @@ int main (int argc, char **argv)
* Let the user know whose password is being changed. * Let the user know whose password is being changed.
*/ */
if (!qflg) { if (!qflg) {
printf (_("Changing password for %s\n"), name); (void) printf (_("Changing password for %s\n"), name);
} }
if (new_password (pw)) { if (new_password (pw) != 0) {
fprintf (stderr, (void) fprintf (stderr,
_("The password for %s is unchanged.\n"), _("The password for %s is unchanged.\n"),
name); name);
closelog (); closelog ();
exit (E_NOPERM); exit (E_NOPERM);
} }
@ -1094,7 +1101,7 @@ int main (int argc, char **argv)
} }
#endif /* USE_PAM */ #endif /* USE_PAM */
if (setuid (0) != 0) { if (setuid (0) != 0) {
fputs (_("Cannot change ID to root.\n"), stderr); (void) fputs (_("Cannot change ID to root.\n"), stderr);
SYSLOG ((LOG_ERR, "can't setuid(0)")); SYSLOG ((LOG_ERR, "can't setuid(0)"));
closelog (); closelog ();
exit (E_NOPERM); exit (E_NOPERM);
@ -1113,10 +1120,10 @@ int main (int argc, char **argv)
if (!qflg) { if (!qflg) {
if (!anyflag) { if (!anyflag) {
#ifndef USE_PAM #ifndef USE_PAM
printf (_("%s: password changed.\n"), Prog); (void) printf (_("%s: password changed.\n"), Prog);
#endif /* USE_PAM */ #endif /* USE_PAM */
} else { } else {
printf (_("%s: password expiry information changed.\n"), Prog); (void) printf (_("%s: password expiry information changed.\n"), Prog);
} }
} }

View File

@ -112,7 +112,7 @@ static void execve_shell (const char *shellstr,
static RETSIGTYPE kill_child (int unused(s)); static RETSIGTYPE kill_child (int unused(s));
#else /* !USE_PAM */ #else /* !USE_PAM */
static RETSIGTYPE die (int); static RETSIGTYPE die (int);
static int iswheel (const char *); static bool iswheel (const char *);
#endif /* !USE_PAM */ #endif /* !USE_PAM */
#ifndef USE_PAM #ifndef USE_PAM
@ -138,14 +138,14 @@ static RETSIGTYPE die (int killed)
} }
} }
static int iswheel (const char *username) static bool iswheel (const char *username)
{ {
struct group *grp; struct group *grp;
grp = getgrnam ("wheel"); /* !USE_PAM, no need for xgetgrnam */ grp = getgrnam ("wheel"); /* !USE_PAM, no need for xgetgrnam */
if ( (NULL ==grp) if ( (NULL ==grp)
|| (NULL == grp->gr_mem)) { || (NULL == grp->gr_mem)) {
return 0; return false;
} }
return is_on_list (grp->gr_mem, username); return is_on_list (grp->gr_mem, username);
} }

View File

@ -126,7 +126,7 @@ static RETSIGTYPE catch_signals (unused int sig)
} }
} }
if (access (PASSWD_FILE, F_OK) == -1) { /* must be a password file! */ if (access (PASSWD_FILE, F_OK) == -1) { /* must be a password file! */
puts (_("No password file")); (void) puts (_("No password file"));
#ifdef USE_SYSLOG #ifdef USE_SYSLOG
SYSLOG (LOG_WARN, "No password file\n"); SYSLOG (LOG_WARN, "No password file\n");
closelog (); closelog ();
@ -152,7 +152,7 @@ static RETSIGTYPE catch_signals (unused int sig)
if (getppid() == 1) { if (getppid() == 1) {
setsid(); setsid();
if (ioctl(0, TIOCSCTTY, 1) != 0) { if (ioctl(0, TIOCSCTTY, 1) != 0) {
fputs (_("TIOCSCTTY failed"), stderr); (void) fputs (_("TIOCSCTTY failed"), stderr);
} }
} }
while (NULL != *envp) { /* add inherited environment, */ while (NULL != *envp) { /* add inherited environment, */
@ -184,7 +184,7 @@ static RETSIGTYPE catch_signals (unused int sig)
/* /*
* Fail secure * Fail secure
*/ */
puts (_("No password entry for 'root'")); (void) puts (_("No password entry for 'root'"));
#ifdef USE_SYSLOG #ifdef USE_SYSLOG
SYSLOG (LOG_WARN, "No password entry for 'root'\n"); SYSLOG (LOG_WARN, "No password entry for 'root'\n");
closelog (); closelog ();
@ -198,10 +198,10 @@ static RETSIGTYPE catch_signals (unused int sig)
*/ */
/* get a password for root */ /* get a password for root */
cp = getpass (_ cp = getpass (_(
("\n" "\n"
"Type control-d to proceed with normal startup,\n" "Type control-d to proceed with normal startup,\n"
"(or give root password for system maintenance):")); "(or give root password for system maintenance):"));
/* /*
* XXX - can't enter single user mode if root password is * XXX - can't enter single user mode if root password is
* empty. I think this doesn't happen very often :-). But * empty. I think this doesn't happen very often :-). But
@ -213,7 +213,7 @@ static RETSIGTYPE catch_signals (unused int sig)
SYSLOG (LOG_INFO, "Normal startup\n"); SYSLOG (LOG_INFO, "Normal startup\n");
closelog (); closelog ();
#endif #endif
puts (""); (void) puts ("");
#ifdef TELINIT #ifdef TELINIT
execl (PATH_TELINIT, "telinit", RUNLEVEL, (char *) 0); execl (PATH_TELINIT, "telinit", RUNLEVEL, (char *) 0);
#endif #endif
@ -230,14 +230,14 @@ static RETSIGTYPE catch_signals (unused int sig)
SYSLOG (LOG_WARN, "Incorrect root password\n"); SYSLOG (LOG_WARN, "Incorrect root password\n");
#endif #endif
sleep (2); sleep (2);
puts (_("Login incorrect")); (void) puts (_("Login incorrect"));
} }
strzero (pass); strzero (pass);
(void) alarm (0); (void) alarm (0);
(void) signal (SIGALRM, SIG_DFL); (void) signal (SIGALRM, SIG_DFL);
environ = newenvp; /* make new environment active */ environ = newenvp; /* make new environment active */
puts (_("Entering System Maintenance Mode")); (void) puts (_("Entering System Maintenance Mode"));
#ifdef USE_SYSLOG #ifdef USE_SYSLOG
SYSLOG (LOG_INFO, "System Maintenance Mode\n"); SYSLOG (LOG_INFO, "System Maintenance Mode\n");
#endif #endif

View File

@ -333,7 +333,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void))
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
/* unset the fscreatecon */ /* unset the fscreatecon */
if (is_selinux_enabled ()) { if (is_selinux_enabled ()) {
if (setfscreatecon (NULL)) { if (setfscreatecon (NULL) != 0) {
vipwexit (_("setfscreatecon () failed"), errno, 1); vipwexit (_("setfscreatecon () failed"), errno, 1);
} }
} }