#include <syslog.h>
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
#define IMMEDIATE_CHANGE /* Expire newly created password, must be changed
fflush (stdout);
safeget (foo, sizeof (foo));
- done = bad = correct = (foo[0] == 'y' || foo[0] == 'Y');
+ done = bad = correct = (strprefix(foo, "y") || strprefix(foo, "Y"));
if (bad != 1)
printf ("\nUser [%s] not added\n", usrname);
#include "string/memset/memzero.h"
#include "string/sprintf/snprintf.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
#include "string/strtok/stpsep.h"
static bool name_is_nis (const char *name)
{
- return (('+' == name[0]) || ('-' == name[0]));
+ return strprefix(name, "+") || strprefix(name, "-");
}
#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)
{
/* Some crypt() do not return NULL if the algorithm is not
* supported, and return a DES encrypted password. */
- if ((NULL != salt) && (salt[0] == '$') && (strlen (cp) <= 13))
+ if ((NULL != salt) && strprefix(salt, "$") && (strlen (cp) <= 13))
{
/*@observer@*/const char *method;
switch (salt[1])
#include "string/sprintf/xasprintf.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"
* Break the line into two fields.
*/
name = stpspn(buf, " \t"); /* first nonwhite */
- if (streq(name, "") || *name == '#')
+ if (streq(name, "") || strprefix(name, "#"))
continue; /* comment or empty */
s = stpsep(name, " \t"); /* next field */
/* The "-" is special, not belonging to a strange negative limit.
* It is infinity, in a controlled way.
*/
- if ('-' == value[0]) {
+ if (strprefix(value, "-")) {
limit = RLIM_INFINITY;
} else {
* FIXME: A better (smarter) checking should be done
*/
while (fgets (buf, 1024, fil) != NULL) {
- if (('#' == buf[0]) || ('\n' == buf[0])) {
+ if (strprefix(buf, "#") || strprefix(buf, "\n")) {
continue;
}
MEMZERO(tempbuf);
break;
} else if (streq(name, "*")) {
strcpy (deflimits, tempbuf);
- } else if (name[0] == '@') {
+ } else if (strprefix(name, "@")) {
/* If the user is in the group, the group
* limits apply unless later a line for
* the specific user is found.
#include "shadowlog.h"
#include "string/sprintf/snprintf.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
#include "string/strspn/stpspn.h"
#include "string/strtok/stpsep.h"
}
p = NULL;
while (getline(&line, &len, nssfp) != -1) {
- if (line[0] == '#')
+ if (strprefix(line, "#"))
continue;
if (strlen(line) < 8)
continue;
#include "port.h"
#include "prototypes.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
#include "string/strtok/stpsep.h"
errno = saveerr;
return NULL;
}
- if ('#' == buf[0])
+ if (strprefix(buf, "#"))
goto next;
stpsep(buf, "\n");
#include "shadowlog.h"
#include "string/sprintf/xasprintf.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
#include "string/strdup/xstrdup.h"
#include "string/strspn/stpspn.h"
#include "string/strtok/stpsep.h"
cp = buf;
/* ignore whitespace and comments */
cp = stpspn(cp, " \t");
- if (streq(cp, "") || ('#' == *cp)) {
+ if (streq(cp, "") || strprefix(cp, "#")) {
continue;
}
/*
#include "getdef.h"
#include "prototypes.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
#include "string/strtok/stpsep.h"
return;
}
while (fgets (buf, sizeof buf, fp) == buf) {
- if (buf[0] == '#') {
+ if (strprefix(buf, "#")) {
continue;
}
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
+
#include "prototypes.h"
+#include "string/strcmp/strprefix.h"
/*
static int
rpmatch(const char *response)
{
- if (response[0] == 'y' || response[0] == 'Y')
+ if (strprefix(response, "y") || strprefix(response, "Y"))
return 1;
-
- if (response[0] == 'n' || response[0] == 'n')
+ if (strprefix(response, "n") || strprefix(response, "N"))
return 0;
return -1;
#include "atoi/getnum.h"
#include "atoi/str2i/str2u.h"
#include "defines.h"
-#include "prototypes.h"
-#include "subordinateio.h"
#include "idmapping.h"
+#include "prototypes.h"
#include "shadowlog.h"
+#include "string/strcmp/strprefix.h"
+#include "subordinateio.h"
static const char Prog[] = "check_subid_range";
exit(1);
owner = argv[1];
- check_uids = argv[2][0] == 'u';
+ check_uids = strprefix(argv[2], "u");
if (get_uid(argv[3], &start) == -1)
exit(1);
if (str2ul(&count, argv[4]) == -1)
#include "shadowlog.h"
#include "sssd.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
#ifdef SHADOWGRP
#include "sgroupio.h"
* Skip all NIS entries.
*/
- if ((gre->line[0] == '+') || (gre->line[0] == '-')) {
+ if (strprefix(gre->line, "+") || strprefix(gre->line, "-")) {
continue;
}
#include "string/memset/memzero.h"
#include "string/sprintf/snprintf.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/xstrdup.h"
#include "string/strftime.h"
* clever telnet, and getty holes.
*/
for (arg = 1; arg < argc; arg++) {
- if (argv[arg][0] == '-' && strlen (argv[arg]) > 2) {
+ if (strprefix(argv[arg], "-") && strlen(argv[arg]) > 2) {
usage ();
}
if (streq(argv[arg], "--")) {
else {
cp = getdef_str ("ENV_TZ");
if (NULL != cp) {
- addenv (('/' == *cp) ? tz (cp) : cp, NULL);
+ addenv(strprefix(cp, "/") ? tz(cp) : cp, NULL);
}
}
#endif /* !USE_PAM */
* login, even if they have been
* "pre-authenticated."
*/
- if ( ('!' == user_passwd[0])
- || ('*' == user_passwd[0])) {
+ if ( strprefix(user_passwd, "!")
+ || strprefix(user_passwd, "*")) {
failed = true;
}
addenv ("IFS= \t\n", NULL); /* ... instead, set a safe IFS */
}
- if (pwd->pw_shell[0] == '*') { /* subsystem root */
+ if (strprefix(pwd->pw_shell, "*")) { /* subsystem root */
pwd->pw_shell++; /* skip the '*' */
subsystem (pwd); /* figure out what to execute */
subroot = true; /* say I was here again */
TABLE, lineno));
continue;
}
- if (line[0] == '#') {
+ if (strprefix(line, "#")) {
continue; /* comment line */
}
stpcpy(stprspn(line, " \t"), "");
int err = errno;
SYSLOG ((LOG_ERR, "cannot open %s: %s", TABLE, strerror (err)));
}
- return (!match || (line[0] == '+'))?1:0;
+ return (!match || strprefix(line, "+"))?1:0;
}
/* list_match - match an item against a list of tokens with exceptions */
if (host != NULL) {
return user_match(tok, string) && from_match(host, myhostname());
#if HAVE_INNETGR
- } else if (tok[0] == '@') { /* netgroup */
+ } else if (strprefix(tok, "@")) { /* netgroup */
return (netgroup_match (tok + 1, NULL, string));
#endif
} else if (string_match (tok, string)) { /* ALL or exact match */
* if it matches the head of the string.
*/
#if HAVE_INNETGR
- if (tok[0] == '@') { /* netgroup */
+ if (strprefix(tok, "@")) { /* netgroup */
return (netgroup_match (tok + 1, string, NULL));
} else
#endif
if (string_match (tok, string)) { /* ALL or exact match */
return true;
- } else if (tok[0] == '.') { /* domain: match last fields */
+ } else if (strprefix(tok, ".")) { /* domain: match last fields */
size_t str_len, tok_len;
str_len = strlen (string);
* Do the command line for "newgrp". It's just making sure
* there aren't any flags and getting the new group name.
*/
- if ((argc > 0) && (argv[0][0] == '-')) {
+ if ((argc > 0) && strprefix(argv[0], "-")) {
usage ();
goto failure;
} else if (argv[0] != NULL) {
#include "string/memset/memzero.h"
#include "string/sprintf/xasprintf.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/xstrdup.h"
#include "time/day_to_str.h"
* changed. Passwords which have been inactive too long cannot be
* changed.
*/
- if ( (sp->sp_pwdp[0] == '!')
+ if ( strprefix(sp->sp_pwdp, "!")
|| (exp_status > 1)
|| ( (sp->sp_max >= 0)
&& (sp->sp_min > sp->sp_max))) {
static /*@observer@*/const char *pw_status (const char *pass)
{
- if (*pass == '*' || *pass == '!') {
+ if (strprefix(pass, "*") || strprefix(pass, "!")) {
return "L";
}
if (streq(pass, "")) {
if (dflg)
strcpy(cp, "");
- if (uflg && *cp == '!') {
+ if (uflg && strprefix(cp, "!")) {
if (cp[1] == '\0') {
(void) fprintf (stderr,
_("%s: unlocking the password would result in a passwordless account.\n"
#include "shadowlog.h"
#include "sssd.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
#ifdef WITH_TCB
#include "tcbfuncs.h"
#endif /* WITH_TCB */
* If this is a NIS line, skip it. You can't "know" what NIS
* is going to do without directly asking NIS ...
*/
- if (('+' == pfe->line[0]) || ('-' == pfe->line[0])) {
+ if (strprefix(pfe->line, "+") || strprefix(pfe->line, "-")) {
continue;
}
* If this is a NIS line, skip it. You can't "know" what NIS
* is going to do without directly asking NIS ...
*/
- if (('+' == spe->line[0]) || ('-' == spe->line[0])) {
+ if (strprefix(spe->line, "+") || strprefix(spe->line, "-")) {
continue;
}
#include "string/sprintf/snprintf.h"
#include "string/sprintf/xasprintf.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/xstrdup.h"
* the shell specified in /etc/passwd (not the one specified with
* --shell, which will be the one executed in the chroot later).
*/
- if ('*' == pw->pw_shell[0]) { /* subsystem root required */
+ if (strprefix(pw->pw_shell, "*")) { /* subsystem root required */
subsystem (pw); /* change to the subsystem root */
endpwent (); /* close the old password databases */
endspent ();
#ifndef USE_PAM
cp = getdef_str ("ENV_TZ");
if (NULL != cp) {
- addenv (('/' == *cp) ? tz (cp) : cp, NULL);
+ addenv(strprefix(cp, "/") ? tz(cp) : cp, NULL);
}
/*
#include "defines.h"
#include "prototypes.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"
stpcpy(stprspn(temp, " \t"), "");
p = stpspn(temp, " \t");
- if (*p == '#' || streq(p, ""))
+ if (strprefix(p, "#") || streq(p, ""))
continue;
to_users = strsep(&p, ":");
#include "exitcodes.h"
#include "shadowlog.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
#include "string/strdup/xstrdup.h"
#ifndef USE_PAM
env = getdef_str ("ENV_TZ");
if (NULL != env) {
- addenv (('/' == *env) ? tz (env) : env, NULL);
+ addenv(strprefix(env, "/") ? tz(env) : env, NULL);
}
env = getdef_str ("ENV_HZ");
if (NULL != env) {
#include "string/sprintf/xasprintf.h"
#include "string/strcmp/strcaseeq.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
#include "string/strdup/xstrdup.h"
#include "string/strtok/stpsep.h"
*/
for (cp = strtok(bhome, "/"); cp != NULL; cp = strtok(NULL, "/")) {
/* Avoid turning a relative path into an absolute path. */
- if (bhome[0] == '/' || !streq(path, ""))
+ if (strprefix(bhome, "/") || !streq(path, ""))
strcat(path, "/");
strcat(path, cp);
#include "string/memset/memzero.h"
#include "string/sprintf/xasprintf.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
#include "string/strdup/xstrdup.h"
#include "time/day_to_str.h"
SYSLOG ((LOG_INFO, "lock user '%s' password", user_newname));
xasprintf(&buf, "!%s", pw_pass);
pw_pass = buf;
- } else if (Uflg && pw_pass[0] == '!') {
+ } else if (Uflg && strprefix(pw_pass, "!")) {
if (pw_pass[1] == '\0') {
fprintf (stderr,
_("%s: unlocking the user's password would result in a passwordless account.\n"