Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/commonio.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "string/sprintf/aprintf.h"
#include "string/sprintf/snprintf.h"
#include "string/strcmp/streq.h"
#include "string/strcmp/strprefix.h"
#include "string/strtok/stpsep.h"


Expand Down Expand Up @@ -519,7 +518,7 @@ static void add_one_entry (struct commonio_db *db,

static bool name_is_nis (const char *name)
{
return strprefix(name, "+") || strprefix(name, "-");
return !!strspn(name, "+-");
}


Expand Down Expand Up @@ -730,8 +729,7 @@ commonio_sort (struct commonio_db *db, int (*cmp) (const void *, const void *))
(NULL != ptr)
#if KEEP_NIS_AT_END
&& ((NULL == ptr->line)
|| (('+' != ptr->line[0])
&& ('-' != ptr->line[0])))
|| !strspn(ptr->line, "+-"))
#endif
;
ptr = ptr->next) {
Expand Down
4 changes: 2 additions & 2 deletions lib/encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

#include <unistd.h>
#include <stdio.h>
#include <string.h>

#include "prototypes.h"
#include "defines.h"
#include "shadowlog_internal.h"
#include "string/strcmp/strprefix.h"


/*@exposed@*//*@null@*/char *pw_encrypt (const char *clear, const char *salt)
Expand All @@ -37,7 +37,7 @@

/* Some crypt() do not return NULL if the algorithm is not
* supported, and return a DES encrypted password. */
if ((NULL != salt) && strprefix(salt, "$") && (strlen (cp) <= 13))
if ((NULL != salt) && strspn(salt, "$") && (strlen (cp) <= 13))
{
/*@observer@*/const char *method;
switch (salt[1])
Expand Down
3 changes: 1 addition & 2 deletions lib/getdef.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "string/sprintf/aprintf.h"
#include "string/strcmp/strcaseeq.h"
#include "string/strcmp/streq.h"
#include "string/strcmp/strprefix.h"
#include "string/strspn/stpspn.h"
#include "string/strspn/stprspn.h"
#include "string/strtok/stpsep.h"
Expand Down Expand Up @@ -566,7 +565,7 @@ static void def_load (void)
* Break the line into two fields.
*/
name = stpspn(buf, " \t"); /* first nonwhite */
if (streq(name, "") || strprefix(name, "#"))
if (!strcspn(name, "#"))
continue; /* comment or empty */

s = stpsep(name, " \t"); /* next field */
Expand Down
3 changes: 2 additions & 1 deletion lib/getrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <ctype.h>
#include <stdlib.h>
#include <string.h>

#include "atoi/a2i/a2u.h"
#include "defines.h"
Expand Down Expand Up @@ -38,7 +39,7 @@ getrange(const char *range,
*has_min = false;
*has_max = false;

if ('-' == range[0]) {
if (strspn(range, "-")) {
end = range + 1;
goto parse_max;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/hushed.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool hushed (const char *username)
* file exists in the user's home directory.
*/

if (hushfile[0] != '/') {
if (!strspn(hushfile, "/")) {
SNPRINTF(buf, "%s/%s", pw->pw_dir, hushfile);
return (access (buf, F_OK) == 0);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/limits.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static int setrlimit_value (unsigned int resource,
/* The "-" is special, not belonging to a strange negative limit.
* It is infinity, in a controlled way.
*/
if (strprefix(value, "-")) {
if (strspn(value, "-")) {
limit = RLIM_INFINITY;

} else {
Expand Down Expand Up @@ -369,9 +369,9 @@ static int setup_user_limits (const char *uname)
* FIXME: A better (smarter) checking should be done
*/
while (fgets (buf, 1024, fil) != NULL) {
if (strprefix(buf, "#") || strprefix(buf, "\n")) {
if (!strcspn(buf, "#\n"))
continue;
Comment on lines 371 to 373
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds me of a future patch set which will check after every call to fgets(3) that there exists a \n character, and removes it. This code is bad, in the sense that it doesn't detect files with too long lines.

}

MEMZERO(tempbuf);
/* a valid line should have a username, then spaces,
* then limits
Expand Down Expand Up @@ -400,7 +400,7 @@ static int setup_user_limits (const char *uname)
break;
} else if (streq(name, "*")) {
strcpy (deflimits, tempbuf);
} else if (strprefix(name, "@")) {
} else if (strspn(name, "@")) {
/* If the user is in the group, the group
* limits apply unless later a line for
* the specific user is found.
Expand Down
3 changes: 1 addition & 2 deletions lib/nss.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "string/sprintf/snprintf.h"
#include "string/strcmp/strcaseprefix.h"
#include "string/strcmp/streq.h"
#include "string/strcmp/strprefix.h"
#include "string/strspn/stpspn.h"
#include "string/strtok/stpsep.h"

Expand Down Expand Up @@ -81,7 +80,7 @@ nss_init(const char *nsswitch_path) {
}
p = NULL;
while (getline(&line, &len, nssfp) != -1) {
if (strprefix(line, "#"))
if (!strcspn(line, "#"))
continue;
if (strlen(line) < 8)
continue;
Expand Down
5 changes: 2 additions & 3 deletions lib/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "port.h"
#include "prototypes.h"
#include "string/strcmp/streq.h"
#include "string/strcmp/strprefix.h"
#include "string/strtok/stpsep.h"
#include "string/strtok/strsep2ls.h"

Expand Down Expand Up @@ -52,7 +51,7 @@ static int portcmp (const char *pattern, const char *port)
if (streq(orig, "SU"))
return 1;

return !strprefix(pattern, "*");
return !strspn(pattern, "*");
}

/*
Expand Down Expand Up @@ -143,7 +142,7 @@ getportent(void)
errno = saveerr;
return NULL;
}
if (strprefix(buf, "#"))
if (strspn(buf, "#"))
goto next;

stpsep(buf, "\n");
Expand Down
3 changes: 2 additions & 1 deletion lib/prefix_flag.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <paths.h>
#include <stdio.h>
#include <string.h>

#include <assert.h>

Expand Down Expand Up @@ -104,7 +105,7 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char **
return ""; /* if prefix is "/" then we ignore the flag option */
/* should we prevent symbolic link from being used as a prefix? */

if ( prefix[0] != '/') {
if (!strspn(prefix, "/")) {
fprintf (log_get_logfd(),
_("%s: prefix must be an absolute path\n"),
log_get_progname());
Expand Down
3 changes: 2 additions & 1 deletion lib/root_flag.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#ident "$Id$"

#include <stdio.h>
#include <string.h>

#include "defines.h"
/*@-exitarg@*/
Expand Down Expand Up @@ -81,7 +82,7 @@ static void change_root (const char* newroot)
exit (EXIT_FAILURE);
}

if ('/' != newroot[0]) {
if (!strspn(newroot, "/")) {
fprintf (log_get_logfd(),
_("%s: invalid chroot path '%s', only absolute paths are supported.\n"),
log_get_progname(), newroot);
Expand Down
13 changes: 7 additions & 6 deletions lib/setupenv.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

#ident "$Id$"

#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <ctype.h>

#include "prototypes.h"
#include "defines.h"
Expand All @@ -28,11 +28,12 @@
#include "shadowlog.h"
#include "string/sprintf/aprintf.h"
#include "string/strcmp/streq.h"
#include "string/strcmp/strprefix.h"
#include "string/strdup/strdup.h"
#include "string/strspn/stpspn.h"
#include "string/strtok/stpsep.h"

#include <assert.h>


#ifndef USE_PAM
static void
Expand Down Expand Up @@ -62,9 +63,9 @@ static void read_env_file (const char *filename)
cp = buf;
/* ignore whitespace and comments */
cp = stpspn(cp, " \t");
if (streq(cp, "") || strprefix(cp, "#")) {
if (!strcspn(cp, "#"))
continue;
}

/*
* ignore lines which don't follow the name=value format
* (for example, the "export NAME" shell commands)
Expand Down
7 changes: 4 additions & 3 deletions lib/sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

#include "config.h"

#ident "$Id$"

#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>

#include "prototypes.h"
#include "defines.h"

#define MAX_SUBROOT2 "maximum subsystem depth reached\n"
#define BAD_SUBROOT2 "invalid root `%s' for user `%s'\n"
#define NO_SUBROOT2 "no subsystem root `%s' for user `%s'\n"
Expand Down Expand Up @@ -45,7 +46,7 @@ void subsystem (const struct passwd *pw)
* The new root directory must begin with a "/" character.
*/

if (pw->pw_dir[0] != '/') {
if (!strspn(pw->pw_dir, "/")) {
printf (_("Invalid root directory '%s'\n"), pw->pw_dir);
SYSLOG ((LOG_WARN, BAD_SUBROOT2, pw->pw_dir, pw->pw_name));
closelog ();
Expand Down
3 changes: 1 addition & 2 deletions lib/ttytype.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ void ttytype (const char *line)
return;
}
while (fgets (buf, sizeof buf, fp) == buf) {
if (strprefix(buf, "#")) {
if (strspn(buf, "#"))
continue;
}

stpsep(buf, "\n");

Expand Down
5 changes: 2 additions & 3 deletions lib/yesno.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <stdlib.h>

#include "prototypes.h"
#include "string/strcmp/strcaseprefix.h"


/*
Expand Down Expand Up @@ -78,9 +77,9 @@ yes_or_no(bool read_only)
static int
rpmatch(const char *response)
{
if (strcaseprefix(response, "y"))
if (strspn(response, "yY"))
return 1;
if (strcaseprefix(response, "n"))
if (strspn(response, "nN"))
return 0;

return -1;
Expand Down
4 changes: 2 additions & 2 deletions src/check_subid_range.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
Expand All @@ -18,7 +19,6 @@
#include "idmapping.h"
#include "prototypes.h"
#include "shadowlog.h"
#include "string/strcmp/strprefix.h"
#include "subordinateio.h"


Expand All @@ -40,7 +40,7 @@ main(int argc, char **argv)
exit(1);

owner = argv[1];
check_uids = strprefix(argv[2], "u");
check_uids = strspn(argv[2], "u");
if (get_uid(argv[3], &start) == -1)
exit(1);
if (str2ul(&count, argv[4]) == -1)
Expand Down
3 changes: 2 additions & 1 deletion src/chsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <getopt.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>

#include "chkname.h"
Expand Down Expand Up @@ -547,7 +548,7 @@ int main (int argc, char **argv)
fail_exit (1, process_selinux);
}
if (!streq(loginsh, "")
&& (loginsh[0] != '/'
&& (!strspn(loginsh, "/")
|| is_restricted_shell (loginsh)
|| (access (loginsh, X_OK) != 0)))
{
Expand Down
8 changes: 3 additions & 5 deletions src/grpck.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
#include "config.h"

#include <fcntl.h>
#include <getopt.h>
#include <grp.h>
#include <paths.h>
#include <pwd.h>
#include <stdio.h>
#include <getopt.h>
#include <string.h>

#include "chkname.h"
#include "commonio.h"
Expand All @@ -28,7 +29,6 @@
#include "shadowlog.h"
#include "sssd.h"
#include "string/strcmp/streq.h"
#include "string/strcmp/strprefix.h"

#ifdef SHADOWGRP
#include "sgroupio.h"
Expand Down Expand Up @@ -490,10 +490,8 @@ static void check_grp_file (bool *errors, bool *changed, struct option_flags *fl
/*
* Skip all NIS entries.
*/

if (strprefix(gre->line, "+") || strprefix(gre->line, "-")) {
if (strspn(gre->line, "+-"))
continue;
}

/*
* Start with the entries that are completely corrupt. They
Expand Down
Loading
Loading