lib/, src/: Use stpsep() instead of its pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2024-07-08 20:25:01 -05:00
committed by Serge Hallyn
parent 39da15614e
commit d91b22cc2f
20 changed files with 69 additions and 85 deletions
+4 -9
View 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);
+4 -9
View 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);
+3 -4
View File
@@ -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);
}
+6 -6
View 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));
+2 -4
View 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.
+4 -8
View 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);
}