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 @@ -37,7 +37,6 @@
#include "string/sprintf/aprintf.h"
#include "string/sprintf/stprintf.h"
#include "string/strcmp/streq.h"
#include "string/strcmp/strprefix.h"
#include "string/strtok/stpsep.h"

#undef NDEBUG
Expand Down Expand Up @@ -488,7 +487,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 @@ -684,8 +683,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
2 changes: 1 addition & 1 deletion lib/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ is_listed(const char *cfgin, const char *tty, bool def)
* console devices upon which root logins are allowed.
*/

if (*cons != '/') {
if (!strspn(cons, "/")) {
char *pbuf;

strtcpy_a(buf, cons);
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.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
9 changes: 4 additions & 5 deletions lib/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void initenv (void)

void addenv (const char *string, /*@null@*/const char *value)
{
char *cp, *newstring;
char *newstring;
size_t i, n;

if (NULL != value) {
Expand All @@ -88,20 +88,19 @@ void addenv (const char *string, /*@null@*/const char *value)
* just ignore the whole string.
*/

cp = strchr (newstring, '=');
if (NULL == cp) {
if (!strchr(newstring, '=')) {
free(newstring);
return;
}

n = (size_t) (cp - newstring);
n = strcspn(newstring, "=");

/*
* If this environment variable is already set, change its value.
*/
for (i = 0; i < newenvc; i++) {
if ( (strncmp (newstring, newenvp[i], n) == 0)
&& (('=' == newenvp[i][n]) || ('\0' == newenvp[i][n]))) {
&& !strcspn(newenvp[i] + n, "=")) {
break;
}
}
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 @@ -567,7 +566,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.h"
#include "defines.h"
Expand Down Expand Up @@ -39,7 +40,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 @@ -61,7 +61,7 @@ bool hushed (const char *username)
* file exists in the user's home directory.
*/

if (hushfile[0] != '/') {
if (!strspn(hushfile, "/")) {
stprintf_a(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 @@ -60,7 +60,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 @@ -363,9 +363,9 @@ static int setup_user_limits (const char *uname)
* FIXME: a better (smarter) checking should be done
*/
while (fgets_a(buf, fil) != NULL) {
if (strprefix(buf, "#") || strprefix(buf, "\n")) {
if (!strcspn(buf, "#\n"))
continue;
}

memzero_a(tempbuf);
/* a valid line should have a username, then spaces,
* then limits
Expand Down Expand Up @@ -394,7 +394,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/stprintf.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 @@ -84,7 +83,7 @@ nss_init(const char *nsswitch_path) {
fprintf(log_get_logfd(), "%s: Non-text file.\n", nsswitch_path);
goto null_subid;
}
if (strprefix(line, "#"))
if (!strcspn(line, "#"))
continue;
if (strlen(line) < 7)
continue;
Expand Down
18 changes: 9 additions & 9 deletions lib/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "prototypes.h"
#include "string/ctype/isascii.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 @@ -54,7 +53,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 @@ -145,7 +144,7 @@ getportent(void)
errno = saveerr;
return NULL;
}
if (strprefix(buf, "#"))
if (strspn(buf, "#"))
goto next;

stpsep(buf, "\n");
Expand Down Expand Up @@ -266,21 +265,22 @@ getportent(void)
dtime = dtime * 10 + cp[i] - '0';
}

if (('-' != cp[i]) || (dtime > 2400) || ((dtime % 100) > 59)) {
if (!strspn(cp + i, "-"))
goto next;
}
if (dtime > 2400 || (dtime % 100) > 59)
goto next;

port.pt_times[j].t_start = dtime;
cp = cp + i + 1;

for (dtime = 0, i = 0; isdigit_c(cp[i]); i++) {
dtime = dtime * 10 + cp[i] - '0';
}

if ( ((',' != cp[i]) && ('\0' != cp[i]))
|| (dtime > 2400)
|| ((dtime % 100) > 59)) {
if (strcspn(cp + i, ","))
goto next;
if (dtime > 2400 || (dtime % 100) > 59)
goto next;
}

port.pt_times[j].t_end = dtime;
cp = cp + i + 1;
Expand Down
3 changes: 2 additions & 1 deletion lib/prefix_flag.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

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

#include "atoi/getnum.h"
#include "defines.h"
Expand Down Expand Up @@ -100,7 +101,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 @@ -80,7 +81,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
10 changes: 6 additions & 4 deletions lib/setupenv.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
#include <ctype.h>
#include <pwd.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>

#include "prototypes.h"
#include "defines.h"
Expand All @@ -27,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 @@ -61,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 @@ -50,9 +50,8 @@ void ttytype (const char *line)
return;
}
while (fgets_a(buf, fp) != NULL) {
if (strprefix(buf, "#")) {
if (strspn(buf, "#"))
continue;
}

stpsep(buf, "\n");

Expand Down
2 changes: 1 addition & 1 deletion lib/utmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ is_my_tty(const char tty[UTX_LINESIZE])
char my_tty[countof(full_tty)];

stpcpy(full_tty, "");
if (tty[0] != '/')
if (!strspn(tty, "/"))
strcpy (full_tty, "/dev/");
strncat(full_tty, tty, UTX_LINESIZE);

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
Loading
Loading