lib/, src/: Use !streq() instead of its pattern
Except for the added (and sorted) includes, the removal of redundant parentheses, and a few non-string cases that I've left out of the change, this patch can be approximated with the following semantic patch: $ cat ~/tmp/spatch/strneq.sp @@ expression s; @@ - '\0' != *s + !streq(s, "") @@ expression s; @@ - '\0' != s[0] + !streq(s, "") @@ expression s; @@ - *s != '\0' + !streq(s, "") @@ expression s; @@ - s[0] != '\0' + !streq(s, "") $ find contrib/ lib* src/ -type f \ | xargs spatch --in-place --sp-file ~/tmp/spatch/strneq.sp; Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Serge Hallyn
parent
7182d6402f
commit
c39305569b
+3
-3
@@ -225,7 +225,7 @@ static char *copy_field (char *in, char *out, char *extra)
|
||||
break;
|
||||
|
||||
if (NULL != extra) {
|
||||
if ('\0' != extra[0]) {
|
||||
if (!streq(extra, "")) {
|
||||
strcat (extra, ",");
|
||||
}
|
||||
|
||||
@@ -543,7 +543,7 @@ static void get_old_fields (const char *gecos)
|
||||
* Anything left over is "slop".
|
||||
*/
|
||||
if ((NULL != cp) && !oflg) {
|
||||
if ('\0' != slop[0]) {
|
||||
if (!streq(slop, "")) {
|
||||
strcat (slop, ",");
|
||||
}
|
||||
|
||||
@@ -702,7 +702,7 @@ int main (int argc, char **argv)
|
||||
}
|
||||
SNPRINTF(new_gecos, "%s,%s,%s,%s%s%s",
|
||||
fullnm, roomno, workph, homeph,
|
||||
('\0' != slop[0]) ? "," : "", slop);
|
||||
(!streq(slop, "")) ? "," : "", slop);
|
||||
|
||||
/* Rewrite the user's gecos in the passwd file */
|
||||
update_gecos (user, new_gecos);
|
||||
|
||||
+1
-1
@@ -179,7 +179,7 @@ static bool is_valid_user_list (const char *users)
|
||||
|
||||
tmpusers = dup = xstrdup(users);
|
||||
|
||||
while (NULL != tmpusers && '\0' != *tmpusers) {
|
||||
while (NULL != tmpusers && !streq(tmpusers, "")) {
|
||||
const char *u;
|
||||
|
||||
u = strsep(&tmpusers, ",");
|
||||
|
||||
+4
-4
@@ -422,7 +422,7 @@ static /*@observer@*/const char *get_failent_user (/*@returned@*/const char *use
|
||||
const char *failent_user = "UNKNOWN";
|
||||
bool log_unkfail_enab = getdef_bool("LOG_UNKFAIL_ENAB");
|
||||
|
||||
if ((NULL != user) && ('\0' != user[0])) {
|
||||
if ((NULL != user) && !streq(user, "")) {
|
||||
if ( log_unkfail_enab
|
||||
|| (getpwnam (user) != NULL)) {
|
||||
failent_user = user;
|
||||
@@ -589,13 +589,13 @@ int main (int argc, char **argv)
|
||||
|
||||
if (hflg) {
|
||||
cp = hostname;
|
||||
} else if ((host != NULL) && (host[0] != '\0')) {
|
||||
} else if ((host != NULL) && !streq(host, "")) {
|
||||
cp = host;
|
||||
} else {
|
||||
cp = "";
|
||||
}
|
||||
|
||||
if ('\0' != *cp) {
|
||||
if (!streq(cp, "")) {
|
||||
SNPRINTF(fromhost, " on '%.100s' from '%.200s'", tty, cp);
|
||||
} else {
|
||||
SNPRINTF(fromhost, " on '%.100s'", tty);
|
||||
@@ -925,7 +925,7 @@ int main (int argc, char **argv)
|
||||
failed = true;
|
||||
}
|
||||
if ( !failed
|
||||
&& !login_access (username, ('\0' != *hostname) ? hostname : tty)) {
|
||||
&& !login_access(username, (!streq(hostname, "")) ? hostname : tty)) {
|
||||
SYSLOG ((LOG_WARN, "LOGIN '%s' REFUSED %s",
|
||||
username, fromhost));
|
||||
failed = true;
|
||||
|
||||
+1
-1
@@ -320,7 +320,7 @@ static bool from_match (const char *tok, const char *string)
|
||||
if (strchr (string, '.') == NULL) {
|
||||
return true;
|
||||
}
|
||||
} else if ( (tok[0] != '\0' && tok[(tok_len = strlen (tok)) - 1] == '.') /* network */
|
||||
} else if ( (!streq(tok, "") && tok[(tok_len = strlen(tok)) - 1] == '.') /* network */
|
||||
&& (strncmp (tok, resolve_hostname (string), tok_len) == 0)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+2
-2
@@ -150,7 +150,7 @@ static void check_perms (const struct group *grp,
|
||||
spw_free (spwd);
|
||||
}
|
||||
|
||||
if (streq(pwd->pw_passwd, "") && (grp->gr_passwd[0] != '\0')) {
|
||||
if (streq(pwd->pw_passwd, "") && !streq(grp->gr_passwd, "")) {
|
||||
needspasswd = true;
|
||||
}
|
||||
|
||||
@@ -786,7 +786,7 @@ int main (int argc, char **argv)
|
||||
cp = getenv ("SHELL");
|
||||
if (!initflag && (NULL != cp)) {
|
||||
prog = cp;
|
||||
} else if ((NULL != pwd->pw_shell) && ('\0' != pwd->pw_shell[0])) {
|
||||
} else if ((NULL != pwd->pw_shell) && !streq(pwd->pw_shell, "")) {
|
||||
prog = pwd->pw_shell;
|
||||
} else {
|
||||
prog = SHELL;
|
||||
|
||||
+6
-6
@@ -282,7 +282,7 @@ static int add_group (const char *name, const char *gid, gid_t *ngid, uid_t uid)
|
||||
/*
|
||||
* Now I have all of the fields required to create the new group.
|
||||
*/
|
||||
if (('\0' != gid[0]) && (!isdigit (gid[0]))) {
|
||||
if (!streq(gid, "") && (!isdigit(gid[0]))) {
|
||||
grent.gr_name = xstrdup (gid);
|
||||
} else {
|
||||
grent.gr_name = xstrdup (name);
|
||||
@@ -355,7 +355,7 @@ static int get_user_id (const char *uid, uid_t *nuid) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if ('\0' != uid[0]) {
|
||||
if (!streq(uid, "")) {
|
||||
const struct passwd *pwd;
|
||||
/* local, no need for xgetpwnam */
|
||||
pwd = getpwnam (uid);
|
||||
@@ -1222,19 +1222,19 @@ int main (int argc, char **argv)
|
||||
Prog, line);
|
||||
fail_exit (EXIT_FAILURE);
|
||||
}
|
||||
if ('\0' != fields[4][0]) {
|
||||
if (!streq(fields[4], "")) {
|
||||
newpw.pw_gecos = fields[4];
|
||||
}
|
||||
|
||||
if ('\0' != fields[5][0]) {
|
||||
if (!streq(fields[5], "")) {
|
||||
newpw.pw_dir = fields[5];
|
||||
}
|
||||
|
||||
if ('\0' != fields[6][0]) {
|
||||
if (!streq(fields[6], "")) {
|
||||
newpw.pw_shell = fields[6];
|
||||
}
|
||||
|
||||
if ( ('\0' != fields[5][0])
|
||||
if ( !streq(fields[5], "")
|
||||
&& (access (newpw.pw_dir, F_OK) != 0)) {
|
||||
/* FIXME: should check for directory */
|
||||
mode_t mode = getdef_num ("HOME_MODE",
|
||||
|
||||
+1
-1
@@ -194,7 +194,7 @@ static int new_password (const struct passwd *pw)
|
||||
* password.
|
||||
*/
|
||||
|
||||
if (!amroot && ('\0' != crypt_passwd[0])) {
|
||||
if (!amroot && !streq(crypt_passwd, "")) {
|
||||
clear = agetpass (_("Old password: "));
|
||||
if (NULL == clear) {
|
||||
return -1;
|
||||
|
||||
+1
-1
@@ -533,7 +533,7 @@ static void check_pw_file (int *errors, bool *changed)
|
||||
* Make sure the login shell is executable
|
||||
*/
|
||||
if ( !quiet
|
||||
&& ('\0' != pwd->pw_shell[0])
|
||||
&& !streq(pwd->pw_shell, "")
|
||||
&& (access (pwd->pw_shell, F_OK) != 0)) {
|
||||
|
||||
/*
|
||||
|
||||
@@ -1087,8 +1087,8 @@ int main (int argc, char **argv)
|
||||
sulog (caller_tty, true, caller_name, name); /* save SU information */
|
||||
if (getdef_bool ("SYSLOG_SU_ENAB")) {
|
||||
SYSLOG ((LOG_INFO, "+ %s %s:%s", caller_tty,
|
||||
('\0' != caller_name[0]) ? caller_name : "???",
|
||||
('\0' != name[0]) ? name : "???"));
|
||||
(!streq(caller_name, "")) ? caller_name : "???",
|
||||
(!streq(name, "")) ? name : "???"));
|
||||
}
|
||||
|
||||
#ifdef USE_PAM
|
||||
@@ -1143,7 +1143,7 @@ int main (int argc, char **argv)
|
||||
AUDIT_USER_ROLE_CHANGE,
|
||||
NULL, /* Prog. name */
|
||||
"su",
|
||||
('\0' != caller_name[0]) ? caller_name : "???",
|
||||
(!streq(caller_name, "")) ? caller_name : "???",
|
||||
AUDIT_NO_ID,
|
||||
"localhost",
|
||||
NULL, /* addr */
|
||||
|
||||
+4
-4
@@ -177,7 +177,7 @@ static bool
|
||||
Uflg = false; /* create a group having the same name as the user */
|
||||
|
||||
#ifdef WITH_SELINUX
|
||||
#define Zflg ('\0' != *user_selinux)
|
||||
#define Zflg (!streq(user_selinux, ""))
|
||||
#endif /* WITH_SELINUX */
|
||||
|
||||
static bool home_added = false;
|
||||
@@ -1268,7 +1268,7 @@ static void process_flags (int argc, char **argv)
|
||||
Dflg = true;
|
||||
break;
|
||||
case 'e':
|
||||
if ('\0' != *optarg) {
|
||||
if (!streq(optarg, "")) {
|
||||
user_expire = strtoday (optarg);
|
||||
if (user_expire < -1) {
|
||||
fprintf (stderr,
|
||||
@@ -1403,7 +1403,7 @@ static void process_flags (int argc, char **argv)
|
||||
break;
|
||||
case 's':
|
||||
if ( ( !VALID (optarg) )
|
||||
|| ( ('\0' != optarg[0])
|
||||
|| ( !streq(optarg, "")
|
||||
&& ('/' != optarg[0])
|
||||
&& ('*' != optarg[0]) )) {
|
||||
fprintf (stderr,
|
||||
@@ -1411,7 +1411,7 @@ static void process_flags (int argc, char **argv)
|
||||
Prog, optarg);
|
||||
exit (E_BAD_ARG);
|
||||
}
|
||||
if ( '\0' != optarg[0]
|
||||
if (!streq(optarg, "")
|
||||
&& '*' != optarg[0]
|
||||
&& !streq(optarg, "/sbin/nologin")
|
||||
&& ( stat(optarg, &st) != 0
|
||||
|
||||
+3
-3
@@ -1154,7 +1154,7 @@ process_flags(int argc, char **argv)
|
||||
break;
|
||||
case 's':
|
||||
if ( ( !VALID (optarg) )
|
||||
|| ( ('\0' != optarg[0])
|
||||
|| ( !streq(optarg, "")
|
||||
&& ('/' != optarg[0])
|
||||
&& ('*' != optarg[0]) )) {
|
||||
fprintf (stderr,
|
||||
@@ -1162,7 +1162,7 @@ process_flags(int argc, char **argv)
|
||||
Prog, optarg);
|
||||
exit (E_BAD_ARG);
|
||||
}
|
||||
if ( '\0' != optarg[0]
|
||||
if (!streq(optarg, "")
|
||||
&& '*' != optarg[0]
|
||||
&& !streq(optarg, "/sbin/nologin")
|
||||
&& ( stat(optarg, &st) != 0
|
||||
@@ -2334,7 +2334,7 @@ int main (int argc, char **argv)
|
||||
|
||||
#ifdef WITH_SELINUX
|
||||
if (Zflg) {
|
||||
if ('\0' != *user_selinux) {
|
||||
if (!streq(user_selinux, "")) {
|
||||
if (set_seuser (user_name, user_selinux, user_selinux_range) != 0) {
|
||||
fprintf (stderr,
|
||||
_("%s: warning: the user name %s to %s SELinux user mapping failed.\n"),
|
||||
|
||||
Reference in New Issue
Block a user