From 471a2df3a6b3678f1b5b313195443e7c1f428226 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Sun, 22 Aug 2010 12:49:07 +0000 Subject: [PATCH] * 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. --- ChangeLog | 24 +++++ lib/encrypt.c | 10 +- lib/prototypes.h | 6 +- libmisc/copydir.c | 51 ++++++---- libmisc/obscure.c | 6 +- libmisc/tz.c | 19 ++-- src/passwd.c | 253 ++++++++++++++++++++++++---------------------- src/su.c | 6 +- src/sulogin.c | 20 ++-- src/vipw.c | 2 +- 10 files changed, 222 insertions(+), 175 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8fcc3c7e..74ccce4c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2010-08-22 Nicolas François + + * 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 * src/passwd.c: Fix a const issue. diff --git a/lib/encrypt.c b/lib/encrypt.c index 78132ba4..9cca4f26 100644 --- a/lib/encrypt.c +++ b/lib/encrypt.c @@ -40,7 +40,7 @@ #include "prototypes.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]; char *cp; @@ -60,7 +60,7 @@ char *pw_encrypt (const char *clear, const char *salt) * supported, and return a DES encrypted password. */ if ((NULL != salt) && (salt[0] == '$') && (strlen (cp) <= 13)) { - const char *method; + /*@observer@*/const char *method; switch (salt[1]) { case '1': @@ -79,9 +79,9 @@ char *pw_encrypt (const char *clear, const char *salt) method = &nummethod[0]; } } - fprintf (stderr, - _("crypt method not supported by libcrypt? (%s)\n"), - method); + (void) fprintf (stderr, + _("crypt method not supported by libcrypt? (%s)\n"), + method); exit (EXIT_FAILURE); } diff --git a/lib/prototypes.h b/lib/prototypes.h index 0ed95ded..54356f73 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -127,7 +127,7 @@ extern int selinux_file_context (const char *dst_name); #endif /* encrypt.c */ -extern char *pw_encrypt (const char *, const char *); +extern /*@exposed@*/char *pw_encrypt (const char *, const char *); /* entry.c */ 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 */ #ifndef USE_PAM -extern int obscure (const char *, const char *, const struct passwd *); +extern bool obscure (const char *, const char *, const struct passwd *); #endif /* pam_pass.c */ @@ -363,7 +363,7 @@ extern void ttytype (const char *); /* tz.c */ #ifndef USE_PAM -extern char *tz (const char *); +extern /*@observer@*/const char *tz (const char *); #endif /* ulimit.c */ diff --git a/libmisc/copydir.c b/libmisc/copydir.c index c3d018ed..c4a561da 100644 --- a/libmisc/copydir.c +++ b/libmisc/copydir.c @@ -77,7 +77,7 @@ static int copy_dir (const char *src, const char *dst, uid_t old_uid, uid_t new_uid, gid_t old_gid, gid_t new_gid); #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, unused bool reset_selinux, 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_enabled; - security_context_t scontext = NULL; + /*@null@*/security_context_t scontext = NULL; if (!selinux_checked) { 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; len = name_len - src_len + dst_len + 1; 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; 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 * the destination files. */ - snprintf (src_name, src_len, "%s/%s", - src_root, ent->d_name); - snprintf (dst_name, dst_len, "%s/%s", - dst_root, ent->d_name); + (void) snprintf (src_name, src_len, "%s/%s", + src_root, ent->d_name); + (void) snprintf (dst_name, dst_len, "%s/%s", + dst_root, ent->d_name); err = copy_entry (src_name, dst_name, reset_selinux, @@ -374,7 +374,9 @@ int copy_tree (const char *src_root, const char *dst_root, #ifdef WITH_SELINUX /* Reset SELinux to create files with default contexts */ - setfscreatecon (NULL); + if (setfscreatecon (NULL) != 0) { + err = -1; + } #endif /* WITH_SELINUX */ return err; @@ -509,7 +511,9 @@ static int copy_dir (const char *src, const char *dst, */ #ifdef WITH_SELINUX - selinux_file_context (dst); + if (selinux_file_context (dst) != 0) { + return -1; + } #endif /* WITH_SELINUX */ if ( (mkdir (dst, statp->st_mode) != 0) || (chown_if_needed (dst, statp, @@ -545,11 +549,11 @@ static int copy_dir (const char *src, const char *dst, * return NULL on error. * 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; - while (1) { + while (true) { ssize_t nchars; char *buffer = (char *) malloc (size); if (NULL == buffer) { @@ -563,7 +567,7 @@ static char *readlink_malloc (const char *filename) 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 */ buffer[nchars] = '\0'; 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) { size_t len = strlen (dst_orig) + strlen (oldlink) - strlen (src_orig) + 1; - char *dummy = (char *) malloc (len); - snprintf (dummy, len, "%s%s", - dst_orig, - oldlink + strlen (src_orig)); + char *dummy = (char *) xmalloc (len); + (void) snprintf (dummy, len, "%s%s", + dst_orig, + oldlink + strlen (src_orig)); free (oldlink); oldlink = dummy; } #ifdef WITH_SELINUX - selinux_file_context (dst); + if (selinux_file_context (dst) != 0) { + free (oldlink); + return -1; + } #endif /* WITH_SELINUX */ if ( (symlink (oldlink, dst) != 0) || (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 * - not implemented */ - lutimes (dst, mt); + (void) lutimes (dst, mt); #endif /* HAVE_LUTIMES */ return 0; @@ -701,7 +708,9 @@ static int copy_special (const char *src, const char *dst, int err = 0; #ifdef WITH_SELINUX - selinux_file_context (dst); + if (selinux_file_context (dst) != 0) { + return -1; + } #endif /* WITH_SELINUX */ 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; } #ifdef WITH_SELINUX - selinux_file_context (dst); + if (selinux_file_context (dst) != 0) { + return -1; + } #endif /* WITH_SELINUX */ ofd = open (dst, O_WRONLY | O_CREAT | O_TRUNC, statp->st_mode & 07777); if ( (ofd < 0) diff --git a/libmisc/obscure.c b/libmisc/obscure.c index f3e27548..d4759245 100644 --- a/libmisc/obscure.c +++ b/libmisc/obscure.c @@ -304,15 +304,15 @@ static const char *obscure_msg (const char *old, const char *new, * 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); if (NULL != msg) { printf (_("Bad password: %s. "), msg); - return 0; + return false; } - return 1; + return true; } #else /* !USE_PAM */ diff --git a/libmisc/tz.c b/libmisc/tz.c index e7b0b016..0f727b7b 100644 --- a/libmisc/tz.c +++ b/libmisc/tz.c @@ -49,23 +49,28 @@ * tz() determines the name of the local timezone by reading the * 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]; const char *def_tz = "TZ=CST6CDT"; - if ((fp = fopen (fname, "r")) == NULL || - fgets (tzbuf, (int) sizeof (tzbuf), fp) == NULL) { - if (!(def_tz = getdef_str ("ENV_TZ")) || def_tz[0] == '/') + fp = fopen (fname, "r"); + if ( (NULL == fp) + || (fgets (tzbuf, (int) sizeof (tzbuf), fp) == NULL)) { + def_tz = getdef_str ("ENV_TZ"); + if ((NULL == def_tz) || ('/' == def_tz[0])) { def_tz = "TZ=CST6CDT"; + } strcpy (tzbuf, def_tz); - } else + } else { tzbuf[strlen (tzbuf) - 1] = '\0'; + } - if (fp) + if (NULL != fp) { (void) fclose (fp); + } return tzbuf; } diff --git a/src/passwd.c b/src/passwd.c index c677f082..6c766123 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -131,20 +131,19 @@ static bool do_update_pwd = false; */ /* local function prototypes */ -static void usage (int); +static /*@noreturn@*/void usage (int); #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 void check_password (const struct passwd *, const struct spwd *); -static char *insert_crypt_passwd (const char *, const char *); #endif /* !USE_PAM */ -static char *date_to_str (time_t); -static const char *pw_status (const char *); +static /*@observer@*/const char *date_to_str (time_t); +static /*@observer@*/const char *pw_status (const char *); static void print_status (const struct passwd *); -static void fail_exit (int); -static void oom (void); +static /*@noreturn@*/void fail_exit (int); +static /*@noreturn@*/void oom (void); static char *update_crypt_pw (char *); static void update_noshadow (void); @@ -158,8 +157,9 @@ static int check_selinux_access (const char *changed_user, /* * usage - print command usage and exit */ -static void usage (int status) +static /*@noreturn@*/void usage (int status) { + (void) fputs (_("Usage: passwd [options] [LOGIN]\n" "\n" "Options:\n" @@ -185,7 +185,7 @@ static void usage (int status) } #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 const char *reason; @@ -200,11 +200,11 @@ static int reuse (const char *pass, const struct passwd *pw) reason = FascistHistory (pass, pw->pw_uid); #endif /* !HAVE_LIBCRACK_PW */ if (NULL != reason) { - printf (_("Bad password: %s. "), reason); - return 1; + (void) printf (_("Bad password: %s. "), reason); + return true; } #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 pass[200]; /* New password */ int i; /* Counter for retries */ - int warned; + bool warned; int pass_max_len = -1; const char *method; @@ -232,7 +232,7 @@ static int new_password (const struct passwd *pw) * password. */ - if (!amroot && crypt_passwd[0]) { + if (!amroot && ('\0' != crypt_passwd[0])) { clear = getpass (_("Old password: ")); if (NULL == clear) { return -1; @@ -240,12 +240,14 @@ static int new_password (const struct passwd *pw) cipher = pw_encrypt (clear, crypt_passwd); if (strcmp (cipher, crypt_passwd) != 0) { + strzero (clear); + strzero (cipher); SYSLOG ((LOG_WARN, "incorrect password for %s", - pw->pw_name)); - sleep (1); - fprintf (stderr, - _("Incorrect password for %s.\n"), - pw->pw_name); + pw->pw_name)); + (void) sleep (1); + (void) fprintf (stderr, + _("Incorrect password for %s.\n"), + pw->pw_name); return -1; } STRFCPY (orig, clear); @@ -280,19 +282,19 @@ static int new_password (const struct passwd *pw) } if (!qflg) { if (pass_max_len == -1) { - printf (_( + (void) printf (_( "Enter the new password (minimum of %d characters)\n" "Please use a combination of upper and lower case letters and numbers.\n"), getdef_num ("PASS_MIN_LEN", 5)); } else { - printf (_( + (void) printf (_( "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"), getdef_num ("PASS_MIN_LEN", 5), pass_max_len); } } - warned = 0; + warned = false; for (i = getdef_num ("PASS_CHANGE_TRIES", 5); i > 0; i--) { cp = getpass (_("New password: ")); if (NULL == cp) { @@ -300,13 +302,13 @@ static int new_password (const struct passwd *pw) return -1; } if (warned && (strcmp (pass, cp) != 0)) { - warned = 0; + warned = false; } STRFCPY (pass, cp); strzero (cp); if (!amroot && (!obscure (orig, pass, pw) || reuse (pass, pw))) { - puts (_("Try again.")); + (void) puts (_("Try again.")); continue; } @@ -317,8 +319,8 @@ static int new_password (const struct passwd *pw) */ if (amroot && !warned && getdef_bool ("PASS_ALWAYS_WARN") && (!obscure (orig, pass, pw) || reuse (pass, pw))) { - puts (_("\nWarning: weak password (enter it again to use it anyway).")); - warned++; + (void) puts (_("\nWarning: weak password (enter it again to use it anyway).")); + warned = true; continue; } cp = getpass (_("Re-enter new password: ")); @@ -327,7 +329,7 @@ static int new_password (const struct passwd *pw) return -1; } 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 { strzero (cp); break; @@ -393,9 +395,9 @@ static void check_password (const struct passwd *pw, const struct spwd *sp) || (exp_status > 1) || ( (sp->sp_max >= 0) && (sp->sp_min > sp->sp_max))) { - fprintf (stderr, - _("The password for %s cannot be changed.\n"), - sp->sp_namp); + (void) fprintf (stderr, + _("The password for %s cannot be changed.\n"), + sp->sp_namp); SYSLOG ((LOG_WARN, "password locked for '%s'", sp->sp_namp)); closelog (); 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); if (now < ok) { - fprintf (stderr, - _("The password for %s cannot be changed yet.\n"), - pw->pw_name); + (void) fprintf (stderr, + _("The password for %s cannot be changed yet.\n"), + pw->pw_name); SYSLOG ((LOG_WARN, "now < minimum age for '%s'", pw->pw_name)); closelog (); 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 */ -static char *date_to_str (time_t t) +static /*@observer@*/const char *date_to_str (time_t t) { static char buf[80]; struct tm *tm; tm = gmtime (&t); #ifdef HAVE_STRFTIME - strftime (buf, sizeof buf, "%m/%d/%Y", tm); + (void) strftime (buf, sizeof buf, "%m/%d/%Y", tm); #else /* !HAVE_STRFTIME */ - snprintf (buf, sizeof buf, "%02d/%02d/%04d", - tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900); + (void) snprintf (buf, sizeof buf, "%02d/%02d/%04d", + tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900); #endif /* !HAVE_STRFTIME */ return buf; } -static const char *pw_status (const char *pass) +static /*@observer@*/const char *pw_status (const char *pass) { if (*pass == '*' || *pass == '!') { return "L"; @@ -465,25 +458,26 @@ static void print_status (const struct passwd *pw) sp = getspnam (pw->pw_name); /* local, no need for xgetspnam */ if (NULL != sp) { - printf ("%s %s %s %ld %ld %ld %ld\n", - pw->pw_name, - pw_status (sp->sp_pwdp), - date_to_str (sp->sp_lstchg * SCALE), - (sp->sp_min * SCALE) / DAY, - (sp->sp_max * SCALE) / DAY, - (sp->sp_warn * SCALE) / DAY, - (sp->sp_inact * SCALE) / DAY); + (void) printf ("%s %s %s %ld %ld %ld %ld\n", + pw->pw_name, + pw_status (sp->sp_pwdp), + date_to_str (sp->sp_lstchg * SCALE), + (sp->sp_min * SCALE) / DAY, + (sp->sp_max * SCALE) / DAY, + (sp->sp_warn * SCALE) / DAY, + (sp->sp_inact * SCALE) / DAY); } 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_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 ())); /* continue */ } @@ -491,7 +485,7 @@ static void fail_exit (int status) if (spw_locked) { 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 ())); /* continue */ } @@ -500,9 +494,9 @@ static void fail_exit (int 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); } @@ -510,7 +504,7 @@ static char *update_crypt_pw (char *cp) { #ifndef USE_PAM if (do_update_pwd) { - cp = insert_crypt_passwd (cp, crypt_passwd); + cp = xstrdup (crypt_passwd); } #endif /* !USE_PAM */ @@ -520,10 +514,10 @@ static char *update_crypt_pw (char *cp) if (uflg && *cp == '!') { if (cp[1] == '\0') { - fprintf (stderr, - _("%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"), - Prog); + (void) fprintf (stderr, + _("%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"), + Prog); fail_exit (E_FAILURE); } else { cp++; @@ -547,24 +541,24 @@ static void update_noshadow (void) struct passwd *npw; if (pw_lock () == 0) { - fprintf (stderr, - _("%s: cannot lock %s; try again later.\n"), - Prog, pw_dbname ()); + (void) fprintf (stderr, + _("%s: cannot lock %s; try again later.\n"), + Prog, pw_dbname ()); exit (E_PWDBUSY); } pw_locked = true; if (pw_open (O_RDWR) == 0) { - fprintf (stderr, - _("%s: cannot open %s\n"), - Prog, pw_dbname ()); + (void) fprintf (stderr, + _("%s: cannot open %s\n"), + Prog, pw_dbname ()); SYSLOG ((LOG_WARN, "cannot open %s", pw_dbname ())); fail_exit (E_MISSING); } pw = pw_locate (name); if (NULL == pw) { - fprintf (stderr, - _("%s: user '%s' does not exist in %s\n"), - Prog, name, pw_dbname ()); + (void) fprintf (stderr, + _("%s: user '%s' does not exist in %s\n"), + Prog, name, pw_dbname ()); fail_exit (E_NOPERM); } npw = __pw_dup (pw); @@ -573,20 +567,22 @@ static void update_noshadow (void) } npw->pw_passwd = update_crypt_pw (npw->pw_passwd); if (pw_update (npw) == 0) { - fprintf (stderr, - _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, pw_dbname (), npw->pw_name); + (void) fprintf (stderr, + _("%s: failed to prepare the new %s entry '%s'\n"), + Prog, pw_dbname (), npw->pw_name); fail_exit (E_FAILURE); } if (pw_close () == 0) { - fprintf (stderr, - _("%s: failure while writing changes to %s\n"), - Prog, pw_dbname ()); + (void) fprintf (stderr, + _("%s: failure while writing changes to %s\n"), + Prog, pw_dbname ()); SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ())); fail_exit (E_FAILURE); } 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 ())); /* continue */ } @@ -599,14 +595,16 @@ static void update_shadow (void) struct spwd *nsp; if (spw_lock () == 0) { - fprintf (stderr, - _("%s: cannot lock %s; try again later.\n"), - Prog, spw_dbname ()); + (void) fprintf (stderr, + _("%s: cannot lock %s; try again later.\n"), + Prog, spw_dbname ()); exit (E_PWDBUSY); } spw_locked = true; 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 ())); fail_exit (E_FAILURE); } @@ -616,7 +614,9 @@ static void update_shadow (void) (void) spw_close (); update_noshadow (); 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 ())); /* continue */ } @@ -661,20 +661,22 @@ static void update_shadow (void) } if (spw_update (nsp) == 0) { - fprintf (stderr, - _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, spw_dbname (), nsp->sp_namp); + (void) fprintf (stderr, + _("%s: failed to prepare the new %s entry '%s'\n"), + Prog, spw_dbname (), nsp->sp_namp); fail_exit (E_FAILURE); } if (spw_close () == 0) { - fprintf (stderr, - _("%s: failure while writing changes to %s\n"), - Prog, spw_dbname ()); + (void) fprintf (stderr, + _("%s: failure while writing changes to %s\n"), + Prog, spw_dbname ()); SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ())); fail_exit (E_FAILURE); } 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 ())); /* continue */ } @@ -880,9 +882,9 @@ int main (int argc, char **argv) case 'w': if ( (getlong (optarg, &warn) == 0) || (warn < -1)) { - fprintf (stderr, - _("%s: invalid numeric argument '%s'\n"), - Prog, optarg); + (void) fprintf (stderr, + _("%s: invalid numeric argument '%s'\n"), + Prog, optarg); usage (E_BAD_ARG); } wflg = true; @@ -891,9 +893,9 @@ int main (int argc, char **argv) case 'x': if ( (getlong (optarg, &age_max) == 0) || (age_max < -1)) { - fprintf (stderr, - _("%s: invalid numeric argument '%s'\n"), - Prog, optarg); + (void) fprintf (stderr, + _("%s: invalid numeric argument '%s'\n"), + Prog, optarg); usage (E_BAD_ARG); } xflg = true; @@ -901,7 +903,7 @@ int main (int argc, char **argv) break; case 'h': usage (E_SUCCESS); - break; + /*@notreached@*/break; default: usage (E_BAD_ARG); } @@ -915,8 +917,9 @@ int main (int argc, char **argv) */ pw = get_my_pwent (); if (NULL == pw) { - fprintf (stderr, - _("%s: Cannot determine your user name.\n"), Prog); + (void) fprintf (stderr, + _("%s: Cannot determine your user name.\n"), + Prog); SYSLOG ((LOG_WARN, "Cannot determine the user name of the caller (UID %lu)", (unsigned long) getuid ())); exit (E_NOPERM); @@ -944,7 +947,9 @@ int main (int argc, char **argv) usage (E_USAGE); } if (!amroot) { - fprintf (stderr, _("%s: Permission denied.\n"), Prog); + (void) fprintf (stderr, + _("%s: Permission denied.\n"), + Prog); exit (E_NOPERM); } setpwent (); @@ -984,13 +989,15 @@ int main (int argc, char **argv) } if (anyflag && !amroot) { - fprintf (stderr, _("%s: Permission denied.\n"), Prog); + (void) fprintf (stderr, _("%s: Permission denied.\n"), Prog); exit (E_NOPERM); } pw = xgetpwnam (name); 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); } #ifdef WITH_SELINUX @@ -1001,14 +1008,14 @@ int main (int argc, char **argv) security_context_t user_context = NULL; const char *user = "Unknown user context"; if (getprevcon (&user_context) == 0) { - user = user_context; + user = user_context; /* FIXME: use context_user_get? */ } SYSLOG ((LOG_ALERT, "%s is not authorized to change the password of %s", user, name)); - fprintf(stderr, - _("%s: %s is not authorized to change the password of %s\n"), - Prog, user, name); + (void) fprintf(stderr, + _("%s: %s is not authorized to change the password of %s\n"), + Prog, user, name); if (NULL != user_context) { freecon (user_context); } @@ -1021,12 +1028,12 @@ int main (int argc, char **argv) * check if I'm root. */ if (!amroot && (pw->pw_uid != getuid ())) { - fprintf (stderr, - _("%s: You may not view or modify password information for %s.\n"), - Prog, name); + (void) fprintf (stderr, + _("%s: You may not view or modify password information for %s.\n"), + Prog, name); SYSLOG ((LOG_WARN, - "%s: can't view or modify password information for %s", - Prog, name)); + "%s: can't view or modify password information for %s", + Prog, name)); closelog (); exit (E_NOPERM); } @@ -1062,13 +1069,13 @@ int main (int argc, char **argv) * Let the user know whose password is being changed. */ if (!qflg) { - printf (_("Changing password for %s\n"), name); + (void) printf (_("Changing password for %s\n"), name); } - if (new_password (pw)) { - fprintf (stderr, - _("The password for %s is unchanged.\n"), - name); + if (new_password (pw) != 0) { + (void) fprintf (stderr, + _("The password for %s is unchanged.\n"), + name); closelog (); exit (E_NOPERM); } @@ -1094,7 +1101,7 @@ int main (int argc, char **argv) } #endif /* USE_PAM */ 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)")); closelog (); exit (E_NOPERM); @@ -1113,10 +1120,10 @@ int main (int argc, char **argv) if (!qflg) { if (!anyflag) { #ifndef USE_PAM - printf (_("%s: password changed.\n"), Prog); + (void) printf (_("%s: password changed.\n"), Prog); #endif /* USE_PAM */ } else { - printf (_("%s: password expiry information changed.\n"), Prog); + (void) printf (_("%s: password expiry information changed.\n"), Prog); } } diff --git a/src/su.c b/src/su.c index a844edc8..6d8fecf9 100644 --- a/src/su.c +++ b/src/su.c @@ -112,7 +112,7 @@ static void execve_shell (const char *shellstr, static RETSIGTYPE kill_child (int unused(s)); #else /* !USE_PAM */ static RETSIGTYPE die (int); -static int iswheel (const char *); +static bool iswheel (const char *); #endif /* !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; grp = getgrnam ("wheel"); /* !USE_PAM, no need for xgetgrnam */ if ( (NULL ==grp) || (NULL == grp->gr_mem)) { - return 0; + return false; } return is_on_list (grp->gr_mem, username); } diff --git a/src/sulogin.c b/src/sulogin.c index 22c23bd7..8f3f4549 100644 --- a/src/sulogin.c +++ b/src/sulogin.c @@ -126,7 +126,7 @@ static RETSIGTYPE catch_signals (unused int sig) } } if (access (PASSWD_FILE, F_OK) == -1) { /* must be a password file! */ - puts (_("No password file")); + (void) puts (_("No password file")); #ifdef USE_SYSLOG SYSLOG (LOG_WARN, "No password file\n"); closelog (); @@ -152,7 +152,7 @@ static RETSIGTYPE catch_signals (unused int sig) if (getppid() == 1) { setsid(); if (ioctl(0, TIOCSCTTY, 1) != 0) { - fputs (_("TIOCSCTTY failed"), stderr); + (void) fputs (_("TIOCSCTTY failed"), stderr); } } while (NULL != *envp) { /* add inherited environment, */ @@ -184,7 +184,7 @@ static RETSIGTYPE catch_signals (unused int sig) /* * Fail secure */ - puts (_("No password entry for 'root'")); + (void) puts (_("No password entry for 'root'")); #ifdef USE_SYSLOG SYSLOG (LOG_WARN, "No password entry for 'root'\n"); closelog (); @@ -198,10 +198,10 @@ static RETSIGTYPE catch_signals (unused int sig) */ /* get a password for root */ - cp = getpass (_ - ("\n" - "Type control-d to proceed with normal startup,\n" - "(or give root password for system maintenance):")); + cp = getpass (_( +"\n" +"Type control-d to proceed with normal startup,\n" +"(or give root password for system maintenance):")); /* * XXX - can't enter single user mode if root password is * 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"); closelog (); #endif - puts (""); + (void) puts (""); #ifdef TELINIT execl (PATH_TELINIT, "telinit", RUNLEVEL, (char *) 0); #endif @@ -230,14 +230,14 @@ static RETSIGTYPE catch_signals (unused int sig) SYSLOG (LOG_WARN, "Incorrect root password\n"); #endif sleep (2); - puts (_("Login incorrect")); + (void) puts (_("Login incorrect")); } strzero (pass); (void) alarm (0); (void) signal (SIGALRM, SIG_DFL); environ = newenvp; /* make new environment active */ - puts (_("Entering System Maintenance Mode")); + (void) puts (_("Entering System Maintenance Mode")); #ifdef USE_SYSLOG SYSLOG (LOG_INFO, "System Maintenance Mode\n"); #endif diff --git a/src/vipw.c b/src/vipw.c index 535338ee..d1dd3571 100644 --- a/src/vipw.c +++ b/src/vipw.c @@ -333,7 +333,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void)) #ifdef WITH_SELINUX /* unset the fscreatecon */ if (is_selinux_enabled ()) { - if (setfscreatecon (NULL)) { + if (setfscreatecon (NULL) != 0) { vipwexit (_("setfscreatecon () failed"), errno, 1); } }