#include "string/strchr/strchrcnt.h"
#include "string/strcmp/streq.h"
#include "string/strtok/stpsep.h"
+#include "string/strtok/strsep2arr.h"
static /*@null@*/FILE *shadow;
static struct sgrp sgroup = {};
-#define FIELDS 4
-
static /*@null@*/char **
build_list(char *s)
{
static char *dup = NULL;
- char *fields[FIELDS];
- char *cp;
- int i;
+ char *fields[4];
free(dup);
dup = strdup(s);
stpsep(dup, "\n");
- /*
- * There should be exactly 4 colon separated fields. Find
- * all 4 of them and save the starting addresses in fields[].
- */
-
- for (cp = dup, i = 0; (i < FIELDS) && (NULL != cp); i++)
- fields[i] = strsep(&cp, ":");
-
- /*
- * If there was an extra field somehow, or perhaps not enough,
- * the line is invalid.
- */
-
- if (NULL != cp || i != FIELDS)
+ if (STRSEP2ARR(dup, ":", fields) == -1)
return NULL;
sgroup.sg_namp = fields[0];
#include "prototypes.h"
#include "string/strcmp/streq.h"
#include "string/strtok/stpsep.h"
+#include "string/strtok/strsep2arr.h"
-#define NFIELDS 4
-
/*
* list - turn a comma-separated string into an array of (char *)'s
*
static char *dup = NULL;
static struct group grent;
- int i;
- char *cp;
- char *fields[NFIELDS];
+ char *fields[4];
free(dup);
dup = strdup(s);
stpsep(dup, "\n");
- for (cp = dup, i = 0; (i < NFIELDS) && (NULL != cp); i++)
- fields[i] = strsep(&cp, ":");
+ if (STRSEP2ARR(dup, ":", fields) == -1)
+ return NULL;
- if (i < NFIELDS || streq(fields[2], "") || cp != NULL) {
+ if (streq(fields[2], ""))
return NULL;
- }
+
grent.gr_name = fields[0];
grent.gr_passwd = fields[1];
if (get_gid(fields[2], &grent.gr_gid) == -1) {
#include "shadowlog_internal.h"
#include "string/strcmp/streq.h"
#include "string/strtok/stpsep.h"
+#include "string/strtok/strsep2arr.h"
-#define NFIELDS 7
-
/*
* sgetpwent - convert a string to a (struct passwd)
*
static char *dup = NULL;
static struct passwd pwent;
- int i;
- char *cp;
- char *fields[NFIELDS];
+ char *fields[7];
free(dup);
dup = strdup(s);
stpsep(dup, "\n");
- /*
- * Save a pointer to the start of each colon separated
- * field. The fields are converted into NUL terminated strings.
- */
-
- for (cp = dup, i = 0; (i < NFIELDS) && (NULL != cp); i++)
- fields[i] = strsep(&cp, ":");
-
- /* something at the end, columns over shot */
- if ( cp != NULL ) {
- return( NULL );
- }
+ if (STRSEP2ARR(dup, ":", fields) == -1)
+ return NULL;
/*
- * There must be exactly NFIELDS colon separated fields or
- * the entry is invalid. Also, the UID and GID must be non-blank.
+ * The UID and GID must be non-blank.
*/
-
- if (i != NFIELDS)
- return NULL;
if (streq(fields[2], ""))
return NULL;
if (streq(fields[3], ""))
#include "string/ctype/strisascii/strisdigit.h"
#include "string/sprintf/snprintf.h"
#include "string/strcmp/streq.h"
+#include "string/strtok/strsep2arr.h"
#define ID_SIZE 31
{
static struct subordinate_range range;
static char rangebuf[1024];
- int i;
- char *cp;
char *fields[SUBID_NFIELDS];
/*
return NULL; /* fail if too long */
strcpy (rangebuf, line);
- /*
- * Save a pointer to the start of each colon separated
- * field. The fields are converted into NUL terminated strings.
- */
-
- for (cp = rangebuf, i = 0; (i < SUBID_NFIELDS) && (NULL != cp); i++)
- fields[i] = strsep(&cp, ":");
-
- /*
- * There must be exactly SUBID_NFIELDS colon separated fields or
- * the entry is invalid. Also, fields must be non-blank.
- */
- if (i != SUBID_NFIELDS)
+ if (STRSEP2ARR(rangebuf, ":", fields) == -1)
return NULL;
+
if (streq(fields[0], ""))
return NULL;
if (streq(fields[1], ""))
#include "string/strcmp/streq.h"
#include "string/strdup/xstrdup.h"
#include "string/strtok/stpsep.h"
+#include "string/strtok/strsep2arr.h"
/*
{
char buf[BUFSIZ];
char *fields[7];
- int nfields;
- char *cp;
const struct passwd *pw;
struct passwd newpw;
intmax_t line = 0;
fail_exit (EXIT_FAILURE);
}
- /*
- * Break the string into fields and screw around with them.
- * There MUST be 7 colon separated fields, although the
- * values aren't that particular.
- */
- for (cp = buf, nfields = 0; nfields < 7; nfields++) {
- fields[nfields] = strsep(&cp, ":");
- if (cp == NULL)
- break;
- }
- if (nfields != 6) {
+ if (STRSEP2ARR(buf, ":", fields) == -1) {
fprintf (stderr, _("%s: line %jd: invalid line\n"),
Prog, line);
fail_exit (EXIT_FAILURE);