]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: Use stpsep() instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Tue, 2 Jul 2024 22:32:12 +0000 (00:32 +0200)
committerSerge Hallyn <serge@hallyn.com>
Tue, 9 Jul 2024 01:25:01 +0000 (20:25 -0500)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
20 files changed:
lib/commonio.c
lib/console.c
lib/fields.c
lib/getdef.c
lib/gshadow.c
lib/hushed.c
lib/loginprompt.c
lib/port.c
lib/setupenv.c
lib/sgetgrent.c
lib/sgetspent.c
lib/shadow.c
lib/ttytype.c
lib/tz.c
src/chgpasswd.c
src/chpasswd.c
src/groupadd.c
src/login_nopam.c
src/newusers.c
src/useradd.c

index 6a9b7752596a954f3e077a28aa4ddf5b3f75faf9..f7bad1329b68b87cc4bdf1a51d13a3afc7dacadd 100644 (file)
@@ -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) {
index 4691fc436cd95034beb2784b5f93718aa48bfae5..7903caa9de5077eb4d1de7e286a643a3ead9e248 100644 (file)
@@ -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;
index 256ee34a20dddf408de8eb468cec294e3427c61d..555f4bedf9f3bafa44d5ebdb4a0531e04623ddcc 100644 (file)
@@ -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]) {
                /*
index d33f45b14e29c75ee97a9704a2e4d01898357605..ce1f98dd75ae58affa92325eb059213d90b16106 100644 (file)
@@ -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.
index e79fb784119e30471f7297986d5a1b232cf55601..3706e50d0a1c631a58c3e7c2ddf3e3f23e78e164 100644 (file)
 #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;
index 3db09abb1a2ba27b4f334ec2570c525bbb471fda..caa687575aa1f5916cbd78fc951d6899056fa80f 100644 (file)
@@ -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);
        }
index 6233625acce38db6b0696bf170c7c580e670fea8..3d5f5eb3dc848a5f38bc18c26d76612414ad4175 100644 (file)
 #include <signal.h>
 
 #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.
index efb85a72f7094948e91ed19277e2bb31435dd65c..136e1ee0f611adee59aa2b272b4c2843afeb074f 100644 (file)
@@ -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;
 
index 6ed08c98ce43ca6a06ced96d551200b5ca94a533..16d8e93ece2cc7aa45cc8b10ccf1c4d2aea6578e 100644 (file)
@@ -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)
index 36137bcf59afc3e9f127e31f364998c2e49325bd..b1202967e0de9e3918abad739e04c944cf8349f0 100644 (file)
@@ -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, ":");
index c693acd08799570972041305accc3a281ea4be56..3ebe427c8261f6f0ec3264c0e917490865dbd20a 100644 (file)
 
 #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
index 3152595c0580844197fccb077062d23086f74f2f..e243ac5a58a76be2ab5f2994641343d43069451c 100644 (file)
@@ -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;
index c0f6de6fed57f7dc1d4186175d42c44b47db20cb..850cb8d8acbc0a135a9fa0a88678d38051515c6d 100644 (file)
@@ -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)) {
index cb04e517310612c97de513da315a114630c18d3f..9506a8b16c92d5698262b6816a534ae1a6bd63d4 100644 (file)
--- a/lib/tz.c
+++ b/lib/tz.c
 
 #include <stdio.h>
 #include <string.h>
+
 #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) {
index 6c1e632dce77eb7e8445124d7a4bdad1b185d2fc..4f87b824fc7a6f5b9a764104b7099f975c149942 100644 (file)
@@ -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);
index 5d87119aac61f81ede94809ad78794b5e774804d..9e12c6eec1b72149558ba6c94b161a8fae81338c 100644 (file)
@@ -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);
index f83bd1f574f6bf3e1c749b496bb854bd08b5f457..1c15f6a45fcbc6f72b46b54c4e8df35546be6e17 100644 (file)
 #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);
                        }
index b9fb647c0b4648646fdfca5252f161d4cc6c6b28..2b19d15153f9065bc6b7f72aa2f50584128d5859 100644 (file)
@@ -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));
index 6a87e3d9cfffccd6cde118ec5a3a08626e101b04..74c8925afefe03e76cdc39fe95cd6bf66d877dce 100644 (file)
@@ -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.
index bb907bab67c85ac18c1dd0c57b8377e988510a65..0464c52fa23926257a03ced47c6b253c543fec6d 100644 (file)
@@ -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);
                                }