From: Alejandro Colomar Date: Tue, 2 Jul 2024 22:32:12 +0000 (+0200) Subject: lib/, src/: Use stpsep() instead of its pattern X-Git-Tag: 4.17.0-rc1~130 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d91b22cc2f6d99a7607e7844f91703651578394d;p=thirdparty%2Fshadow.git lib/, src/: Use stpsep() instead of its pattern Signed-off-by: Alejandro Colomar --- diff --git a/lib/commonio.c b/lib/commonio.c index 6a9b77525..f7bad1329 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -36,6 +36,7 @@ #include "shadowlog_internal.h" #include "sssd.h" #include "string/sprintf/snprintf.h" +#include "string/strtok/stpsep.h" /* local function prototypes */ @@ -659,7 +660,7 @@ int commonio_open (struct commonio_db *db, int mode) goto cleanup_buf; } } - stpcpy(strchrnul(buf, '\n'), ""); + stpsep(buf, "\n"); line = strdup (buf); if (NULL == line) { diff --git a/lib/console.c b/lib/console.c index 4691fc436..7903caa9d 100644 --- a/lib/console.c +++ b/lib/console.c @@ -17,8 +17,7 @@ #include "getdef.h" #include "prototypes.h" #include "string/strcpy/strtcpy.h" - -#ident "$Id$" +#include "string/strtok/stpsep.h" /* @@ -76,7 +75,7 @@ static bool is_listed (const char *cfgin, const char *tty, bool def) */ while (fgets (buf, sizeof (buf), fp) != NULL) { - stpcpy(strchrnul(buf, '\n'), ""); + stpsep(buf, "\n"); if (strcmp (buf, tty) == 0) { (void) fclose (fp); return true; diff --git a/lib/fields.c b/lib/fields.c index 256ee34a2..555f4bedf 100644 --- a/lib/fields.c +++ b/lib/fields.c @@ -17,6 +17,7 @@ #include "prototypes.h" #include "string/strchr/strrspn.h" +#include "string/strtok/stpsep.h" /* @@ -80,11 +81,8 @@ void change_field (char *buf, size_t maxsize, const char *prompt) return; } - cp = strchr (newf, '\n'); - if (NULL == cp) { + if (stpsep(newf, "\n") == NULL) return; - } - stpcpy(cp, ""); if ('\0' != newf[0]) { /* diff --git a/lib/getdef.c b/lib/getdef.c index d33f45b14..ce1f98dd7 100644 --- a/lib/getdef.c +++ b/lib/getdef.c @@ -29,9 +29,9 @@ #include "prototypes.h" #include "shadowlog_internal.h" #include "string/sprintf/xasprintf.h" -#include "string/strchr/stpcspn.h" #include "string/strchr/stpspn.h" #include "string/strchr/strrspn.h" +#include "string/strtok/stpsep.h" /* @@ -569,13 +569,12 @@ static void def_load (void) if (*name == '\0' || *name == '#') continue; /* comment or empty */ - s = stpcspn(name, " \t"); /* end of field */ - if (*s == '\0') + s = stpsep(name, " \t"); /* next field */ + if (s == NULL) continue; /* only 1 field?? */ - stpcpy(s++, ""); value = stpspn(s, " \"\t"); /* next nonwhite */ - stpcpy(strchrnul(value, '"'), ""); + stpsep(value, "\""); /* * Store the value in def_table. diff --git a/lib/gshadow.c b/lib/gshadow.c index e79fb7841..3706e50d0 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -20,8 +20,10 @@ #include "alloc/malloc.h" #include "alloc/realloc.h" #include "alloc/x/xrealloc.h" -#include "prototypes.h" #include "defines.h" +#include "prototypes.h" +#include "string/strtok/stpsep.h" + static /*@null@*/FILE *shadow; static /*@null@*//*@only@*/char **members = NULL; @@ -91,7 +93,7 @@ void endsgent (void) } strcpy (sgrbuf, string); - stpcpy(strchrnul(sgrbuf, '\n'), ""); + stpsep(sgrbuf, "\n"); /* * There should be exactly 4 colon separated fields. Find @@ -172,7 +174,7 @@ void endsgent (void) return NULL; } } - stpcpy(strchrnul(buf, '\n'), ""); + stpsep(buf, "\n"); return (sgetsgent (buf)); } return NULL; diff --git a/lib/hushed.c b/lib/hushed.c index 3db09abb1..caa687575 100644 --- a/lib/hushed.c +++ b/lib/hushed.c @@ -21,6 +21,7 @@ #include "getdef.h" #include "prototypes.h" #include "string/sprintf/snprintf.h" +#include "string/strtok/stpsep.h" /* @@ -72,7 +73,7 @@ bool hushed (const char *username) return false; } for (found = false; !found && (fgets (buf, sizeof buf, fp) == buf);) { - stpcpy(strchrnul(buf, '\n'), ""); + stpsep(buf, "\n"); found = (strcmp (buf, pw->pw_shell) == 0) || (strcmp (buf, pw->pw_name) == 0); } diff --git a/lib/loginprompt.c b/lib/loginprompt.c index 6233625ac..3d5f5eb3d 100644 --- a/lib/loginprompt.c +++ b/lib/loginprompt.c @@ -16,10 +16,12 @@ #include #include "attr.h" -#include "memzero.h" -#include "prototypes.h" #include "defines.h" #include "getdef.h" +#include "memzero.h" +#include "prototypes.h" +#include "string/strtok/stpsep.h" + static void login_exit (MAYBE_UNUSED int sig) { @@ -83,11 +85,8 @@ void login_prompt (char *name, int namesize) exit (EXIT_FAILURE); } - cp = strchr (buf, '\n'); - if (NULL == cp) { - exit (EXIT_FAILURE); - } - stpcpy(cp, ""); /* remove \n [ must be there ] */ + if (stpsep(buf, "\n") == NULL) + exit(EXIT_FAILURE); /* * Skip leading whitespace. This makes " username" work right. diff --git a/lib/port.c b/lib/port.c index efb85a72f..136e1ee0f 100644 --- a/lib/port.c +++ b/lib/port.c @@ -19,6 +19,7 @@ #include "defines.h" #include "port.h" #include "prototypes.h" +#include "string/strtok/stpsep.h" static FILE *ports; @@ -142,7 +143,7 @@ next: if ('#' == buf[0]) goto next; - stpcpy(strchrnul(buf, '\n'), ""); + stpsep(buf, "\n"); field = buf; diff --git a/lib/setupenv.c b/lib/setupenv.c index 6ed08c98c..16d8e93ec 100644 --- a/lib/setupenv.c +++ b/lib/setupenv.c @@ -28,6 +28,7 @@ #include "shadowlog.h" #include "string/sprintf/xasprintf.h" #include "string/strdup/xstrdup.h" +#include "string/strtok/stpsep.h" #ifndef USE_PAM @@ -52,11 +53,8 @@ static void read_env_file (const char *filename) return; } while (fgets (buf, (int)(sizeof buf), fp) == buf) { - cp = strrchr (buf, '\n'); - if (NULL == cp) { + if (stpsep(buf, "\n") == NULL) break; - } - stpcpy(cp, ""); cp = buf; /* ignore whitespace and comments */ @@ -71,15 +69,11 @@ static void read_env_file (const char *filename) * (for example, the "export NAME" shell commands) */ name = cp; - while (('\0' != *cp) && !isspace (*cp) && ('=' != *cp)) { - cp++; - } - if ('=' != *cp) { + val = stpsep(cp, "="); + if (val == NULL) + continue; + if (strpbrk(name, " \t") != NULL) continue; - } - /* NUL-terminate the name */ - stpcpy(cp++, ""); - val = cp; #if 0 /* XXX untested, and needs rewrite with fewer goto's :-) */ /* (state, char_type) -> (state, action) diff --git a/lib/sgetgrent.c b/lib/sgetgrent.c index 36137bcf5..b1202967e 100644 --- a/lib/sgetgrent.c +++ b/lib/sgetgrent.c @@ -21,6 +21,7 @@ #include "atoi/getnum.h" #include "defines.h" #include "prototypes.h" +#include "string/strtok/stpsep.h" #define NFIELDS 4 @@ -83,7 +84,7 @@ struct group *sgetgrent (const char *buf) } } strcpy (grpbuf, buf); - stpcpy(strchrnul(grpbuf, '\n'), ""); + stpsep(grpbuf, "\n"); for (cp = grpbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++) grpfields[i] = strsep(&cp, ":"); diff --git a/lib/sgetspent.c b/lib/sgetspent.c index c693acd08..3ebe427c8 100644 --- a/lib/sgetspent.c +++ b/lib/sgetspent.c @@ -21,9 +21,10 @@ #include "atoi/a2i.h" #include "atoi/str2i.h" +#include "defines.h" #include "prototypes.h" #include "shadowlog_internal.h" -#include "defines.h" +#include "string/strtok/stpsep.h" #define FIELDS 9 @@ -54,7 +55,7 @@ sgetspent(const char *string) return NULL; /* fail if too long */ } strcpy (spwbuf, string); - stpcpy(strchrnul(spwbuf, '\n'), ""); + stpsep(spwbuf, "\n"); /* * Tokenize the string into colon separated fields. Allow up to diff --git a/lib/shadow.c b/lib/shadow.c index 3152595c0..e243ac5a5 100644 --- a/lib/shadow.c +++ b/lib/shadow.c @@ -22,6 +22,7 @@ #include "atoi/str2i.h" #include "defines.h" #include "prototypes.h" +#include "string/strtok/stpsep.h" static FILE *shadow; @@ -77,7 +78,7 @@ static struct spwd *my_sgetspent (const char *string) if (strlen (string) >= sizeof spwbuf) return 0; strcpy (spwbuf, string); - stpcpy(strchrnul(spwbuf, '\n'), ""); + stpsep(spwbuf, "\n"); /* * Tokenize the string into colon separated fields. Allow up to @@ -202,7 +203,7 @@ struct spwd *fgetspent (FILE * fp) if (fgets (buf, sizeof buf, fp) != NULL) { - stpcpy(strchrnul(buf, '\n'), ""); + stpsep(buf, "\n"); return my_sgetspent (buf); } return 0; diff --git a/lib/ttytype.c b/lib/ttytype.c index c0f6de6fe..850cb8d8a 100644 --- a/lib/ttytype.c +++ b/lib/ttytype.c @@ -17,6 +17,7 @@ #include "defines.h" #include "getdef.h" #include "prototypes.h" +#include "string/strtok/stpsep.h" /* @@ -49,7 +50,7 @@ void ttytype (const char *line) continue; } - stpcpy(strchrnul(buf, '\n'), ""); + stpsep(buf, "\n"); if ( (sscanf (buf, "%1023s %1023s", type, port) == 2) && (strcmp (line, port) == 0)) { diff --git a/lib/tz.c b/lib/tz.c index cb04e5173..9506a8b16 100644 --- a/lib/tz.c +++ b/lib/tz.c @@ -16,9 +16,12 @@ #include #include + #include "defines.h" -#include "prototypes.h" #include "getdef.h" +#include "prototypes.h" +#include "string/strtok/stpsep.h" + /* * tz - return local timezone name @@ -42,7 +45,7 @@ strcpy (tzbuf, def_tz); } else { - stpcpy(strchrnul(tzbuf, '\n'), ""); + stpsep(tzbuf, "\n"); } if (NULL != fp) { diff --git a/src/chgpasswd.c b/src/chgpasswd.c index 6c1e632dc..4f87b824f 100644 --- a/src/chgpasswd.c +++ b/src/chgpasswd.c @@ -34,6 +34,7 @@ /*@-exitarg@*/ #include "exitcodes.h" #include "shadowlog.h" +#include "string/strtok/stpsep.h" /* @@ -460,10 +461,7 @@ int main (int argc, char **argv) */ while (fgets (buf, (int) sizeof buf, stdin) != NULL) { line++; - cp = strrchr (buf, '\n'); - if (NULL != cp) { - stpcpy(cp, ""); - } else { + if (stpsep(buf, "\n") == NULL) { fprintf (stderr, _("%s: line %d: line too long\n"), Prog, line); errors++; @@ -480,11 +478,8 @@ int main (int argc, char **argv) */ name = buf; - cp = strchr (name, ':'); - if (NULL != cp) { - stpcpy(cp, ""); - cp++; - } else { + cp = stpsep(name, ":"); + if (cp == NULL) { fprintf (stderr, _("%s: line %d: missing new password\n"), Prog, line); diff --git a/src/chpasswd.c b/src/chpasswd.c index 5d87119aa..9e12c6eec 100644 --- a/src/chpasswd.c +++ b/src/chpasswd.c @@ -31,6 +31,7 @@ /*@-exitarg@*/ #include "exitcodes.h" #include "shadowlog.h" +#include "string/strtok/stpsep.h" #define IS_CRYPT_METHOD(str) ((crypt_method != NULL && strcmp(crypt_method, str) == 0) ? true : false) @@ -501,12 +502,8 @@ int main (int argc, char **argv) */ while (fgets (buf, sizeof buf, stdin) != NULL) { line++; - cp = strrchr (buf, '\n'); - if (NULL != cp) { - stpcpy(cp, ""); - } else { + if (stpsep(buf, "\n") == NULL) { if (feof (stdin) == 0) { - // Drop all remaining characters on this line. while (fgets (buf, sizeof buf, stdin) != NULL) { cp = strchr (buf, '\n'); @@ -533,10 +530,8 @@ int main (int argc, char **argv) */ name = buf; - cp = strchr (name, ':'); - if (NULL != cp) { - stpcpy(cp++, ""); - } else { + cp = stpsep(name, ":"); + if (cp == NULL) { fprintf (stderr, _("%s: line %d: missing new password\n"), Prog, line); diff --git a/src/groupadd.c b/src/groupadd.c index f83bd1f57..1c15f6a45 100644 --- a/src/groupadd.c +++ b/src/groupadd.c @@ -33,11 +33,12 @@ #include "nscd.h" #include "sssd.h" #include "prototypes.h" +#include "run_part.h" #ifdef SHADOWGRP #include "sgroupio.h" #endif #include "shadowlog.h" -#include "run_part.h" +#include "string/strtok/stpsep.h" /* @@ -423,15 +424,13 @@ static void process_flags (int argc, char **argv) * example: -K GID_MIN=100 -K GID_MAX=499 * note: -K GID_MIN=10,GID_MAX=499 doesn't work yet */ - cp = strchr (optarg, '='); + cp = stpsep(optarg, "="); if (NULL == cp) { fprintf (stderr, _("%s: -K requires KEY=VALUE\n"), Prog); exit (E_BAD_ARG); } - /* terminate name, point to value */ - stpcpy(cp++, ""); if (putdef_str (optarg, cp, NULL) < 0) { exit (E_BAD_ARG); } diff --git a/src/login_nopam.c b/src/login_nopam.c index b9fb647c0..2b19d1515 100644 --- a/src/login_nopam.c +++ b/src/login_nopam.c @@ -58,6 +58,8 @@ #include "sizeof.h" #include "string/strchr/strrspn.h" +#include "string/strtok/stpsep.h" + #if !defined(MAXHOSTNAMELEN) || (MAXHOSTNAMELEN < 64) #undef MAXHOSTNAMELEN @@ -213,18 +215,16 @@ static bool user_match (const char *tok, const char *string) #ifdef PRIMARY_GROUP_MATCH struct passwd *userinf; #endif - char *at; + char *host; /* * If a token has the magic value "ALL" the match always succeeds. * Otherwise, return true if the token fully matches the username, or if * the token is a group that contains the username. */ - at = strchr (tok + 1, '@'); - if (NULL != at) { /* split user@host pattern */ - stpcpy(at, ""); - return ( user_match (tok, string) - && from_match (at + 1, myhostname ())); + host = stpsep(tok + 1, "@"); /* split user@host pattern */ + if (host != NULL) { + return user_match(tok, string) && from_match(host, myhostname()); #if HAVE_INNETGR } else if (tok[0] == '@') { /* netgroup */ return (netgroup_match (tok + 1, NULL, string)); diff --git a/src/newusers.c b/src/newusers.c index 6a87e3d9c..74c8925af 100644 --- a/src/newusers.c +++ b/src/newusers.c @@ -54,6 +54,7 @@ #include "shadowlog.h" #include "string/sprintf/snprintf.h" #include "string/strdup/xstrdup.h" +#include "string/strtok/stpsep.h" /* @@ -1101,14 +1102,11 @@ int main (int argc, char **argv) */ while (fgets (buf, sizeof buf, stdin) != NULL) { line++; - cp = strrchr (buf, '\n'); - if (cp == NULL && feof (stdin) == 0) { + if (stpsep(buf, "\n") == NULL && feof(stdin) == 0) { fprintf (stderr, _("%s: line %d: line too long\n"), Prog, line); fail_exit (EXIT_FAILURE); } - if (cp != NULL) - stpcpy(cp, ""); /* * Break the string into fields and screw around with them. diff --git a/src/useradd.c b/src/useradd.c index bb907bab6..0464c52fa 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -68,6 +68,7 @@ #include "string/sprintf/snprintf.h" #include "string/sprintf/xasprintf.h" #include "string/strdup/xstrdup.h" +#include "string/strtok/stpsep.h" #ifndef SKEL_DIR @@ -361,7 +362,7 @@ static void get_defaults (void) * values are used, everything else can be ignored. */ while (fgets (buf, sizeof buf, fp) == buf) { - stpcpy(strchrnul(buf, '\n'), ""); + stpsep(buf, "\n"); cp = strchr (buf, '='); if (NULL == cp) { @@ -603,10 +604,7 @@ static int set_defaults (void) } while (fgets (buf, sizeof buf, ifp) == buf) { - cp = strrchr (buf, '\n'); - if (NULL != cp) { - stpcpy(cp, ""); - } else { + if (stpsep(buf, "\n") == NULL) { /* A line which does not end with \n is only valid * at the end of the file. */ @@ -1350,15 +1348,13 @@ static void process_flags (int argc, char **argv) * example: -K UID_MIN=100 -K UID_MAX=499 * note: -K UID_MIN=10,UID_MAX=499 doesn't work yet */ - cp = strchr (optarg, '='); + cp = stpsep(optarg, "="); if (NULL == cp) { fprintf (stderr, _("%s: -K requires KEY=VALUE\n"), Prog); exit (E_BAD_ARG); } - /* terminate name, point to value */ - stpcpy(cp++, ""); if (putdef_str (optarg, cp, NULL) < 0) { exit (E_BAD_ARG); }