}
}
for (cp = info->pw_gecos; cp != NULL; cp = strchr (cp, ',')) {
+ char *val;
+
cp = strprefix(cp, ",") ?: cp;
- if (strncmp (cp, "pri=", 4) == 0) {
+ val = strprefix(cp, "pri=");
+ if (val != NULL) {
int inc;
- if (a2si(&inc, cp + 4, NULL, 0, -20, 20) == 0) {
+ if (a2si(&inc, val, NULL, 0, -20, 20) == 0) {
errno = 0;
if ( (nice (inc) != -1)
|| (0 != errno)) {
continue;
}
- if (strncmp (cp, "ulimit=", 7) == 0) {
+
+ val = strprefix(cp, "ulimit=");
+ if (val != NULL) {
int blocks;
- if ( (str2si(&blocks, cp + 7) == -1)
+ if ( (str2si(&blocks, val) == -1)
|| (set_filesize_limit (blocks) != 0)) {
SYSLOG ((LOG_WARN,
"Can't set the ulimit for user %s",
}
continue;
}
- if (strncmp (cp, "umask=", 6) == 0) {
+
+ val = strprefix(cp, "umask=");
+ if (val != NULL) {
mode_t mask;
- if (str2i(mode_t, &mask, cp + 6) == -1) {
+ if (str2i(mode_t, &mask, val) == -1) {
SYSLOG ((LOG_WARN,
"Can't set umask value for user %s",
info->pw_name));
#include "shadowlog.h"
#include "string/sprintf/xasprintf.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
static char *passwd_db_file = NULL;
for (int i = 0; i < argc; i++) {
const char *val;
- val = NULL;
+ val = strprefix(argv[i], "--prefix=");
+
if ( streq(argv[i], "--prefix")
- || ((strncmp (argv[i], "--prefix=", 9) == 0)
- && (val = argv[i] + 9))
+ || val != NULL
|| streq(argv[i], short_opt))
{
if (NULL != prefix) {
#include "prototypes.h"
#include "shadowlog.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
#include <assert.h>
for (int i = 0; i < argc; i++) {
const char *val;
- val = NULL;
+ val = strprefix(argv[i], "--root=");
+
if ( streq(argv[i], "--root")
- || ((strncmp (argv[i], "--root=", 7) == 0)
- && (val = argv[i] + 7))
- || streq(argv[i], short_opt)) {
+ || val != NULL
+ || streq(argv[i], short_opt))
+ {
if (NULL != newroot) {
fprintf (log_get_logfd(),
_("%s: multiple --root options\n"),
return 0;
}
while (fgets (line, sizeof (line), sfile) == line) {
- if (strncmp (line, "Uid:\t", 5) == 0) {
+ if (strprefix(line, "Uid:\t")) {
unsigned long ruid, euid, suid;
assert (uid == (unsigned long) uid);
#include "sizeof.h"
#include "string/strcmp/strcaseeq.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
#include "string/strspn/stprspn.h"
#include "string/strtok/stpsep.h"
static bool from_match (char *tok, const char *string)
{
- size_t tok_len;
-
/*
* If a token has the magic value "ALL" the match always succeeds. Return
* true if the token fully matches the string. If the token is a domain
if (string_match (tok, string)) { /* ALL or exact match */
return true;
} else if (tok[0] == '.') { /* domain: match last fields */
- size_t str_len;
+ size_t str_len, tok_len;
+
str_len = strlen (string);
tok_len = strlen (tok);
if ( (str_len > tok_len)
if (strchr (string, '.') == NULL) {
return true;
}
- } else if ( (!streq(tok, "") && tok[(tok_len = strlen(tok)) - 1] == '.') /* network */
- && (strncmp (tok, resolve_hostname (string), tok_len) == 0)) {
+ } else if ( (!streq(tok, "") && tok[strlen(tok) - 1] == '.') /* network */
+ && strprefix(resolve_hostname(string), tok)) {
return true;
}
return false;
*/
target_str = argv[1];
- if (strlen(target_str) > 3 && strncmp(target_str, "fd:", 3) == 0) {
+ if (strlen(target_str) > 3 && strprefix(target_str, "fd:")) {
/* the user passed in a /proc/pid fd for the process */
target_str = &target_str[3];
proc_dir_fd = get_pidfd_from_fd(target_str);
}
while (NULL != *envp) {
- if (strncmp (*envp, "PATH=", 5) == 0 ||
- strncmp (*envp, "HOME=", 5) == 0 ||
- strncmp (*envp, "SHELL=", 6) == 0 ||
- strncmp (*envp, "TERM=", 5) == 0)
+ if (strprefix(*envp, "PATH=") ||
+ strprefix(*envp, "HOME=") ||
+ strprefix(*envp, "SHELL=") ||
+ strprefix(*envp, "TERM="))
+ {
addenv (*envp, NULL);
+ }
envp++;
}
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+
#include "defines.h"
-#include "prototypes.h"
-#include "subordinateio.h"
#include "getdef.h"
#include "idmapping.h"
+#include "prototypes.h"
#include "shadowlog.h"
+#include "string/strcmp/strprefix.h"
+#include "subordinateio.h"
+
/*
* Global variables
/* Find the process that needs its user namespace
* uid mapping set.
*/
- if (strlen(target_str) > 3 && strncmp(target_str, "fd:", 3) == 0) {
+ if (strlen(target_str) > 3 && strprefix(target_str, "fd:")) {
/* the user passed in a /proc/pid fd for the process */
target_str = &target_str[3];
proc_dir_fd = get_pidfd_from_fd(target_str);