diff --git a/lib/list.c b/lib/list.c index 466bf7bf4..a18c71862 100644 --- a/lib/list.c +++ b/lib/list.c @@ -93,7 +93,7 @@ del_list(/*@returned@*/ /*@only@*/char **list, const char *member) */ for (i = j = 0; list[i] != NULL; i++) { - if (strcmp (list[i], member) != 0) { + if (!streq(list[i], member)) { j++; } } @@ -116,7 +116,7 @@ del_list(/*@returned@*/ /*@only@*/char **list, const char *member) */ for (i = j = 0; list[i] != NULL; i++) { - if (strcmp (list[i], member) != 0) { + if (!streq(list[i], member)) { tmp[j] = list[i]; j++; } diff --git a/lib/salt.c b/lib/salt.c index 8acaa5748..f2432512e 100644 --- a/lib/salt.c +++ b/lib/salt.c @@ -404,7 +404,7 @@ static /*@observer@*/const char *gensalt (size_t salt_size) rounds = SHA_get_salt_rounds (arg); SHA_salt_rounds_to_buf (result, rounds); #endif /* USE_SHA_CRYPT */ - } else if (0 != strcmp (method, "DES")) { + } else if (!streq(method, "DES")) { fprintf (log_get_logfd(), _("Invalid ENCRYPT_METHOD value: '%s'.\n" "Defaulting to DES.\n"), diff --git a/lib/subordinateio.c b/lib/subordinateio.c index 45085481a..9329c455b 100644 --- a/lib/subordinateio.c +++ b/lib/subordinateio.c @@ -197,7 +197,7 @@ static const struct subordinate_range *find_range(struct commonio_db *db, unsigned long first = range->start; unsigned long last = first + range->count - 1; - if (0 != strcmp(range->owner, owner)) + if (!streq(range->owner, owner)) continue; if ((val >= first) && (val <= last)) @@ -208,7 +208,7 @@ static const struct subordinate_range *find_range(struct commonio_db *db, /* * We only do special handling for these two files */ - if ((0 != strcmp(db->filename, SUBUID_FILE)) && (0 != strcmp(db->filename, SUBGID_FILE))) + if (!streq(db->filename, SUBUID_FILE) && !streq(db->filename, SUBGID_FILE)) return NULL; /* @@ -465,7 +465,7 @@ static int remove_range (struct commonio_db *db, last = first + range->count - 1; /* Skip entries with a different owner */ - if (0 != strcmp (range->owner, owner)) { + if (!streq(range->owner, owner)) { continue; } @@ -1062,7 +1062,7 @@ bool new_subid_range(struct subordinate_range *range, enum subid_type id_type, b if (reuse) { while ((r = commonio_next(db)) != NULL) { // TODO account for username vs uid_t - if (0 != strcmp(r->owner, range->owner)) + if (!streq(r->owner, range->owner)) continue; if (r->count >= range->count) { range->count = r->count; diff --git a/lib/tcbfuncs.c b/lib/tcbfuncs.c index c8a6f8d81..6e48db4e6 100644 --- a/lib/tcbfuncs.c +++ b/lib/tcbfuncs.c @@ -342,7 +342,7 @@ static shadowtcb_status move_dir (const char *user_newname, uid_t user_newid) if (NULL == real_new_dir_rel) { goto out_free; } - if ( (strcmp (real_new_dir, newdir) != 0) + if ( !streq(real_new_dir, newdir) && (symlink (real_new_dir_rel, newdir) != 0)) { fprintf (shadow_logfd, _("%s: Cannot create symbolic link %s: %s\n"), diff --git a/src/chgpasswd.c b/src/chgpasswd.c index 1eb7d1a29..2d50337e6 100644 --- a/src/chgpasswd.c +++ b/src/chgpasswd.c @@ -260,18 +260,18 @@ static void check_flags (void) } if (cflg) { - if ( (0 != strcmp (crypt_method, "DES")) - && (0 != strcmp (crypt_method, "MD5")) - && (0 != strcmp (crypt_method, "NONE")) + if ( !streq(crypt_method, "DES") + && !streq(crypt_method, "MD5") + && !streq(crypt_method, "NONE") #ifdef USE_SHA_CRYPT - && (0 != strcmp (crypt_method, "SHA256")) - && (0 != strcmp (crypt_method, "SHA512")) + && !streq(crypt_method, "SHA256") + && !streq(crypt_method, "SHA512") #endif /* USE_SHA_CRYPT */ #ifdef USE_BCRYPT - && (0 != strcmp (crypt_method, "BCRYPT")) + && !streq(crypt_method, "BCRYPT") #endif /* USE_BCRYPT */ #ifdef USE_YESCRYPT - && (0 != strcmp (crypt_method, "YESCRYPT")) + && !streq(crypt_method, "YESCRYPT") #endif /* USE_YESCRYPT */ ) { fprintf (stderr, @@ -490,7 +490,7 @@ int main (int argc, char **argv) newpwd = cp; if ( (!eflg) && ( (NULL == crypt_method) - || (0 != strcmp (crypt_method, "NONE")))) { + || !streq(crypt_method, "NONE"))) { void *arg = NULL; const char *salt; if (md5flg) { @@ -577,7 +577,7 @@ int main (int argc, char **argv) newsg.sg_passwd = cp; } if ( (NULL == sg) - || (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0)) + || !streq(gr->gr_passwd, SHADOW_PASSWD_STRING)) #endif { newgr = *gr; @@ -600,7 +600,7 @@ int main (int argc, char **argv) } } if ( (NULL == sg) - || (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0)) + || !streq(gr->gr_passwd, SHADOW_PASSWD_STRING)) #endif { if (gr_update (&newgr) == 0) { diff --git a/src/chpasswd.c b/src/chpasswd.c index 1074d99f5..dfe507409 100644 --- a/src/chpasswd.c +++ b/src/chpasswd.c @@ -627,7 +627,7 @@ int main (int argc, char **argv) } if ( (NULL == sp) - || (strcmp (pw->pw_passwd, SHADOW_PASSWD_STRING) != 0)) { + || !streq(pw->pw_passwd, SHADOW_PASSWD_STRING)) { newpw = *pw; newpw.pw_passwd = cp; } @@ -647,7 +647,7 @@ int main (int argc, char **argv) } } if ( (NULL == sp) - || (strcmp (pw->pw_passwd, SHADOW_PASSWD_STRING) != 0)) { + || !streq(pw->pw_passwd, SHADOW_PASSWD_STRING)) { if (pw_update (&newpw) == 0) { fprintf (stderr, _("%s: line %d: failed to prepare the new %s entry '%s'\n"), diff --git a/src/groupmod.c b/src/groupmod.c index bedbc6067..ec2e60434 100644 --- a/src/groupmod.c +++ b/src/groupmod.c @@ -155,7 +155,7 @@ static void new_grent (struct group *grent) if ( pflg #ifdef SHADOWGRP && ( (!is_shadow_grp) - || (strcmp (grent->gr_passwd, SHADOW_PASSWD_STRING) != 0)) + || !streq(grent->gr_passwd, SHADOW_PASSWD_STRING)) #endif ) { /* Update the password in group if there is no gshadow diff --git a/src/grpck.c b/src/grpck.c index a97e756c5..405ae6c5e 100644 --- a/src/grpck.c +++ b/src/grpck.c @@ -537,7 +537,7 @@ static void check_grp_file (int *errors, bool *changed) continue; } - if (strcmp (grp->gr_name, ent->gr_name) != 0) { + if (!streq(grp->gr_name, ent->gr_name)) { continue; } @@ -649,7 +649,7 @@ static void check_grp_file (int *errors, bool *changed) /* The group entry has a gshadow counterpart. * Make sure no passwords are in group. */ - if (strcmp (grp->gr_passwd, SHADOW_PASSWD_STRING) != 0) { + if (!streq(grp->gr_passwd, SHADOW_PASSWD_STRING)) { printf (_("group %s has an entry in %s, but its password field in %s is not set to 'x'\n"), grp->gr_name, sgr_file, grp_file); *errors += 1; @@ -739,7 +739,7 @@ static void check_sgr_file (int *errors, bool *changed) continue; } - if (strcmp (sgr->sg_name, ent->sg_name) != 0) { + if (!streq(sgr->sg_name, ent->sg_name)) { continue; } diff --git a/src/grpconv.c b/src/grpconv.c index ea236e4ed..16cd52c9a 100644 --- a/src/grpconv.c +++ b/src/grpconv.c @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -24,18 +25,21 @@ #include #include #include -#include #include "attr.h" -#include "nscd.h" -#include "sssd.h" -#include "prototypes.h" /*@-exitarg@*/ #include "exitcodes.h" +#include "nscd.h" +#include "prototypes.h" +#include "string/strcmp/streq.h" + #ifdef SHADOWGRP #include "groupio.h" #include "sgroupio.h" #include "shadowlog.h" +#include "sssd.h" + + /* * Global variables */ @@ -194,7 +198,7 @@ int main (int argc, char **argv) if (NULL != sg) { /* update existing shadow group entry */ sgent = *sg; - if (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0) + if (!streq(gr->gr_passwd, SHADOW_PASSWD_STRING)) sgent.sg_passwd = gr->gr_passwd; } else { static char *empty = NULL; diff --git a/src/newgrp.c b/src/newgrp.c index 4955ebcef..427ae586a 100644 --- a/src/newgrp.c +++ b/src/newgrp.c @@ -75,7 +75,7 @@ static bool ingroup(const char *name, struct group *gr) look = gr->gr_mem; while (*look && notfound) - notfound = strcmp (*look++, name); + notfound = !streq(*look++, name); return !notfound; } @@ -189,7 +189,7 @@ static void check_perms (const struct group *grp, } if (grp->gr_passwd[0] == '\0' || - strcmp (cpasswd, grp->gr_passwd) != 0) { + !streq(cpasswd, grp->gr_passwd)) { #ifdef WITH_AUDIT SNPRINTF(audit_buf, "authentication new-gid=%lu", (unsigned long) grp->gr_gid); diff --git a/src/newusers.c b/src/newusers.c index eee0d260d..32d224d20 100644 --- a/src/newusers.c +++ b/src/newusers.c @@ -557,7 +557,7 @@ static int add_passwd (struct passwd *pwd, const char *password) * when the entry was created, so this user would have to have had * the password set someplace else. */ - if (strcmp (pwd->pw_passwd, "x") != 0) { + if (!streq(pwd->pw_passwd, "x")) { return update_passwd (pwd, password); } #else /* USE_PAM */ @@ -568,7 +568,7 @@ static int add_passwd (struct passwd *pwd, const char *password) * The password will be updated later for all users using PAM. */ if ( (NULL != sp) - || (strcmp (pwd->pw_passwd, "x") != 0)) { + || !streq(pwd->pw_passwd, "x")) { return 0; } #endif /* USE_PAM */ @@ -754,18 +754,18 @@ static void check_flags (void) #endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */ if (cflg) { - if ( (0 != strcmp (crypt_method, "DES")) - && (0 != strcmp (crypt_method, "MD5")) - && (0 != strcmp (crypt_method, "NONE")) + if ( !streq(crypt_method, "DES") + && !streq(crypt_method, "MD5") + && !streq(crypt_method, "NONE") #ifdef USE_SHA_CRYPT - && (0 != strcmp (crypt_method, "SHA256")) - && (0 != strcmp (crypt_method, "SHA512")) + && !streq(crypt_method, "SHA256") + && !streq(crypt_method, "SHA512") #endif /* USE_SHA_CRYPT */ #ifdef USE_BCRYPT - && (0 != strcmp (crypt_method, "BCRYPT")) + && !streq(crypt_method, "BCRYPT") #endif /* USE_BCRYPT */ #ifdef USE_YESCRYPT - && (0 != strcmp (crypt_method, "YESCRYPT")) + && !streq(crypt_method, "YESCRYPT") #endif /* USE_YESCRYPT */ ) { fprintf (stderr, diff --git a/src/passwd.c b/src/passwd.c index a201e5d0d..e75b0b94f 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -213,7 +213,7 @@ static int new_password (const struct passwd *pw) return -1; } - if (strcmp (cipher, crypt_passwd) != 0) { + if (!streq(cipher, crypt_passwd)) { erase_pass (clear); strzero (cipher); SYSLOG ((LOG_WARN, "incorrect password for %s", @@ -299,7 +299,7 @@ static int new_password (const struct passwd *pw) MEMZERO(pass); return -1; } - if (warned && (strcmp (pass, cp) != 0)) { + if (warned && !streq(pass, cp)) { warned = false; } ret = STRTCPY (pass, cp); @@ -333,7 +333,7 @@ static int new_password (const struct passwd *pw) MEMZERO(pass); return -1; } - if (strcmp (cp, pass) != 0) { + if (!streq(cp, pass)) { erase_pass (cp); (void) fputs (_("They don't match; try again.\n"), stderr); } else { @@ -839,7 +839,7 @@ main(int argc, char **argv) case 'r': /* -r repository (files|nis|nisplus) */ /* only "files" supported for now */ - if (strcmp (optarg, "files") != 0) { + if (!streq(optarg, "files")) { fprintf (stderr, _("%s: repository %s not supported\n"), Prog, optarg); diff --git a/src/pwck.c b/src/pwck.c index 2df5b6c6f..271a2c21b 100644 --- a/src/pwck.c +++ b/src/pwck.c @@ -13,23 +13,26 @@ #ident "$Id$" #include +#include #include #include #include -#include + #include "chkname.h" #include "commonio.h" #include "defines.h" +#include "getdef.h" +#include "nscd.h" #include "prototypes.h" #include "pwio.h" #include "shadowio.h" -#include "getdef.h" -#include "nscd.h" +#include "shadowlog.h" #include "sssd.h" +#include "string/strcmp/streq.h" #ifdef WITH_TCB #include "tcbfuncs.h" #endif /* WITH_TCB */ -#include "shadowlog.h" + /* * Exit codes @@ -447,7 +450,7 @@ static void check_pw_file (int *errors, bool *changed) continue; } - if (strcmp (pwd->pw_name, ent->pw_name) != 0) { + if (!streq(pwd->pw_name, ent->pw_name)) { continue; } @@ -518,7 +521,7 @@ static void check_pw_file (int *errors, bool *changed) /* * Home directory does not exist, give a warning (unless intentional) */ - if (NULL == nonexistent || strcmp (pwd->pw_dir, nonexistent) != 0) { + if (NULL == nonexistent || !streq(pwd->pw_dir, nonexistent)) { printf (_("user '%s': directory '%s' does not exist\n"), pwd->pw_name, pwd->pw_dir); *errors += 1; @@ -644,8 +647,7 @@ static void check_pw_file (int *errors, bool *changed) * Make sure no passwords are in passwd. */ if ( !quiet - && (strcmp (pwd->pw_passwd, - SHADOW_PASSWD_STRING) != 0)) { + && !streq(pwd->pw_passwd, SHADOW_PASSWD_STRING)) { printf (_("user %s has an entry in %s, but its password field in %s is not set to 'x'\n"), pwd->pw_name, spw_dbname (), pw_dbname ()); *errors += 1; @@ -773,7 +775,7 @@ static void check_spw_file (int *errors, bool *changed) continue; } - if (strcmp (spw->sp_namp, ent->sp_namp) != 0) { + if (!streq(spw->sp_namp, ent->sp_namp)) { continue; } diff --git a/src/su.c b/src/su.c index 6c1fdc5bc..67195ea0d 100644 --- a/src/su.c +++ b/src/su.c @@ -681,7 +681,7 @@ static /*@only@*/struct passwd * do_check_perms (void) su_failure (caller_tty, 0 == pw->pw_uid); } tmp_name = item; - if (strcmp (name, tmp_name) != 0) { + if (!streq(name, tmp_name)) { SYSLOG ((LOG_INFO, "Change user from '%s' to '%s' as requested by PAM", name, tmp_name)); diff --git a/src/useradd.c b/src/useradd.c index 9fc3db90a..058b09d92 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -1413,7 +1413,7 @@ static void process_flags (int argc, char **argv) } if ( '\0' != optarg[0] && '*' != optarg[0] - && strcmp(optarg, "/sbin/nologin") != 0 + && !streq(optarg, "/sbin/nologin") && ( stat(optarg, &st) != 0 || S_ISDIR(st.st_mode) || access(optarg, X_OK) != 0)) { diff --git a/src/usermod.c b/src/usermod.c index 4cde39bef..8cff1d67f 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -496,7 +496,7 @@ static void new_pwent (struct passwd *pwent) * used for this account. */ if ( (!is_shadow_pwd) - || (strcmp (pwent->pw_passwd, SHADOW_PASSWD_STRING) != 0)) { + || !streq(pwent->pw_passwd, SHADOW_PASSWD_STRING)) { pwent->pw_passwd = new_pw_passwd (pwent->pw_passwd); } @@ -1164,7 +1164,7 @@ process_flags(int argc, char **argv) } if ( '\0' != optarg[0] && '*' != optarg[0] - && strcmp(optarg, "/sbin/nologin") != 0 + && !streq(optarg, "/sbin/nologin") && ( stat(optarg, &st) != 0 || S_ISDIR(st.st_mode) || access(optarg, X_OK) != 0)) {