lib/, src/: Use strsep(3) instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Serge Hallyn
parent
8176e309ed
commit
16cb664865
+3
-12
@@ -60,23 +60,14 @@ sgetspent(const char *string)
|
|||||||
* FIELDS different fields.
|
* FIELDS different fields.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (cp = spwbuf, i = 0; ('\0' != *cp) && (i < FIELDS); i++) {
|
for (cp = spwbuf, i = 0; cp != NULL && i < FIELDS; i++)
|
||||||
fields[i] = cp;
|
fields[i] = strsep(&cp, ":");
|
||||||
cp = strchrnul(cp, ':');
|
|
||||||
|
|
||||||
if ('\0' != *cp) {
|
|
||||||
*cp = '\0';
|
|
||||||
cp++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == (FIELDS - 1))
|
if (i == (FIELDS - 1))
|
||||||
fields[i++] = "";
|
fields[i++] = "";
|
||||||
|
|
||||||
if ( ((NULL != cp) && ('\0' != *cp)) ||
|
if (cp != NULL || (i != FIELDS && i != OFIELDS))
|
||||||
((i != FIELDS) && (i != OFIELDS)) ) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start populating the structure. The fields are all in
|
* Start populating the structure. The fields are all in
|
||||||
|
|||||||
+3
-7
@@ -83,17 +83,13 @@ static struct spwd *my_sgetspent (const char *string)
|
|||||||
* FIELDS different fields.
|
* FIELDS different fields.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (cp = spwbuf, i = 0; *cp && i < FIELDS; i++) {
|
for (cp = spwbuf, i = 0; cp != NULL && i < FIELDS; i++)
|
||||||
fields[i] = cp;
|
fields[i] = strsep(&cp, ":");
|
||||||
cp = strchrnul(cp, ':');
|
|
||||||
if (*cp)
|
|
||||||
*cp++ = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == (FIELDS - 1))
|
if (i == (FIELDS - 1))
|
||||||
fields[i++] = empty;
|
fields[i++] = empty;
|
||||||
|
|
||||||
if ((cp && *cp) || (i != FIELDS && i != OFIELDS))
|
if (cp != NULL || (i != FIELDS && i != OFIELDS))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+6
-11
@@ -214,32 +214,27 @@ static void new_fields (void)
|
|||||||
*/
|
*/
|
||||||
static char *copy_field (char *in, char *out, char *extra)
|
static char *copy_field (char *in, char *out, char *extra)
|
||||||
{
|
{
|
||||||
char *cp = NULL;
|
|
||||||
|
|
||||||
while (NULL != in) {
|
while (NULL != in) {
|
||||||
cp = strchr (in, ',');
|
char *f;
|
||||||
if (NULL != cp) {
|
|
||||||
*cp++ = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strchr (in, '=') == NULL) {
|
f = strsep(&in, ",");
|
||||||
|
|
||||||
|
if (strchr(f, '=') == NULL)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if (NULL != extra) {
|
if (NULL != extra) {
|
||||||
if ('\0' != extra[0]) {
|
if ('\0' != extra[0]) {
|
||||||
strcat (extra, ",");
|
strcat (extra, ",");
|
||||||
}
|
}
|
||||||
|
|
||||||
strcat (extra, in);
|
strcat(extra, f);
|
||||||
}
|
}
|
||||||
in = cp;
|
|
||||||
}
|
}
|
||||||
if ((NULL != in) && (NULL != out)) {
|
if ((NULL != in) && (NULL != out)) {
|
||||||
strcpy (out, in);
|
strcpy (out, in);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cp;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+6
-12
@@ -172,28 +172,22 @@ static void catch_signals (int killed)
|
|||||||
*/
|
*/
|
||||||
static bool is_valid_user_list (const char *users)
|
static bool is_valid_user_list (const char *users)
|
||||||
{
|
{
|
||||||
const char *username;
|
|
||||||
char *end;
|
|
||||||
bool is_valid = true;
|
bool is_valid = true;
|
||||||
/*@owned@*/char *tmpusers = xstrdup (users);
|
/*@owned@*/char *tmpusers = xstrdup (users);
|
||||||
|
|
||||||
for (username = tmpusers;
|
while (NULL != tmpusers && '\0' != *tmpusers) {
|
||||||
(NULL != username) && ('\0' != *username);
|
const char *u;
|
||||||
username = end) {
|
|
||||||
end = strchr (username, ',');
|
u = strsep(&tmpusers, ",");
|
||||||
if (NULL != end) {
|
|
||||||
*end = '\0';
|
|
||||||
end++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This user must exist.
|
* This user must exist.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* local, no need for xgetpwnam */
|
/* local, no need for xgetpwnam */
|
||||||
if (getpwnam (username) == NULL) {
|
if (getpwnam(u) == NULL) {
|
||||||
fprintf (stderr, _("%s: user '%s' does not exist\n"),
|
fprintf (stderr, _("%s: user '%s' does not exist\n"),
|
||||||
Prog, username);
|
Prog, u);
|
||||||
is_valid = false;
|
is_valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-5
@@ -1116,13 +1116,9 @@ int main (int argc, char **argv)
|
|||||||
* values aren't that particular.
|
* values aren't that particular.
|
||||||
*/
|
*/
|
||||||
for (cp = buf, nfields = 0; nfields < 7; nfields++) {
|
for (cp = buf, nfields = 0; nfields < 7; nfields++) {
|
||||||
fields[nfields] = cp;
|
fields[nfields] = strsep(&cp, ":");
|
||||||
cp = strchr (cp, ':');
|
|
||||||
if (cp == NULL)
|
if (cp == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
*cp = '\0';
|
|
||||||
cp++;
|
|
||||||
}
|
}
|
||||||
if (nfields != 6) {
|
if (nfields != 6) {
|
||||||
fprintf (stderr, _("%s: line %d: invalid line\n"),
|
fprintf (stderr, _("%s: line %d: invalid line\n"),
|
||||||
|
|||||||
+5
-8
@@ -757,7 +757,6 @@ err_free_new:
|
|||||||
*/
|
*/
|
||||||
static int get_groups (char *list)
|
static int get_groups (char *list)
|
||||||
{
|
{
|
||||||
char *cp;
|
|
||||||
struct group *grp;
|
struct group *grp;
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
int ngroups = 0;
|
int ngroups = 0;
|
||||||
@@ -777,19 +776,18 @@ static int get_groups (char *list)
|
|||||||
* values for group identifiers is permitted.
|
* values for group identifiers is permitted.
|
||||||
*/
|
*/
|
||||||
do {
|
do {
|
||||||
|
char *g;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Strip off a single name from the list
|
* Strip off a single name from the list
|
||||||
*/
|
*/
|
||||||
cp = strchr (list, ',');
|
g = strsep(&list, ",");
|
||||||
if (NULL != cp) {
|
|
||||||
*cp++ = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Names starting with digits are treated as numerical
|
* Names starting with digits are treated as numerical
|
||||||
* GID values, otherwise the string is looked up as is.
|
* GID values, otherwise the string is looked up as is.
|
||||||
*/
|
*/
|
||||||
grp = get_local_group (list);
|
grp = get_local_group(g);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* There must be a match, either by GID value or by
|
* There must be a match, either by GID value or by
|
||||||
@@ -800,10 +798,9 @@ static int get_groups (char *list)
|
|||||||
if (NULL == grp) {
|
if (NULL == grp) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: group '%s' does not exist\n"),
|
_("%s: group '%s' does not exist\n"),
|
||||||
Prog, list);
|
Prog, g);
|
||||||
errors++;
|
errors++;
|
||||||
}
|
}
|
||||||
list = cp;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the group doesn't exist, don't dump core...
|
* If the group doesn't exist, don't dump core...
|
||||||
|
|||||||
+5
-9
@@ -214,7 +214,6 @@ extern int allow_bad_names;
|
|||||||
*/
|
*/
|
||||||
static int get_groups (char *list)
|
static int get_groups (char *list)
|
||||||
{
|
{
|
||||||
char *cp;
|
|
||||||
struct group *grp;
|
struct group *grp;
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
int ngroups = 0;
|
int ngroups = 0;
|
||||||
@@ -234,20 +233,18 @@ static int get_groups (char *list)
|
|||||||
* group identifiers is permitted.
|
* group identifiers is permitted.
|
||||||
*/
|
*/
|
||||||
do {
|
do {
|
||||||
|
char *g;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Strip off a single name from the list
|
* Strip off a single name from the list
|
||||||
*/
|
*/
|
||||||
cp = strchr (list, ',');
|
g = strsep(&list, ",");
|
||||||
if (NULL != cp) {
|
|
||||||
*cp = '\0';
|
|
||||||
cp++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Names starting with digits are treated as numerical GID
|
* Names starting with digits are treated as numerical GID
|
||||||
* values, otherwise the string is looked up as is.
|
* values, otherwise the string is looked up as is.
|
||||||
*/
|
*/
|
||||||
grp = prefix_getgr_nam_gid (list);
|
grp = prefix_getgr_nam_gid(g);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* There must be a match, either by GID value or by
|
* There must be a match, either by GID value or by
|
||||||
@@ -255,10 +252,9 @@ static int get_groups (char *list)
|
|||||||
*/
|
*/
|
||||||
if (NULL == grp) {
|
if (NULL == grp) {
|
||||||
fprintf (stderr, _("%s: group '%s' does not exist\n"),
|
fprintf (stderr, _("%s: group '%s' does not exist\n"),
|
||||||
Prog, list);
|
Prog, g);
|
||||||
errors++;
|
errors++;
|
||||||
}
|
}
|
||||||
list = cp;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the group doesn't exist, don't dump core. Instead,
|
* If the group doesn't exist, don't dump core. Instead,
|
||||||
|
|||||||
Reference in New Issue
Block a user