atobool -> sudo_strtobool

atoid-> sudo_strtoid
atomode -> sudo_strtomode
This commit is contained in:
Todd C. Miller
2014-06-27 14:53:54 -06:00
parent d6948f5a4a
commit a8fa112a53
24 changed files with 120 additions and 120 deletions

View File

@@ -141,14 +141,14 @@ __dso_public int aix_prep_user(char *user, const char *tty);
__dso_public int aix_restoreauthdb(void);
__dso_public int aix_setauthdb(char *user);
/* atobool.c */
__dso_public int atobool(const char *str);
/* strtobool.c */
__dso_public int sudo_strtobool(const char *str);
/* atoid.c */
__dso_public id_t atoid(const char *str, const char *sep, char **endp, const char **errstr);
/* strtoid.c */
__dso_public id_t sudo_strtoid(const char *str, const char *sep, char **endp, const char **errstr);
/* atomode.c */
__dso_public int atomode(const char *cp, const char **errstr);
/* strtomode.c */
__dso_public int sudo_strtomode(const char *cp, const char **errstr);
/* gidlist.c */
__dso_public int sudo_parse_gids(const char *gidstr, const gid_t *basegid, GETGROUPS_T **gidsp);

View File

@@ -95,10 +95,10 @@ DEVEL = @DEVEL@
SHELL = @SHELL@
LTOBJS = alloc.lo atobool.lo atoid.lo atomode.lo event.lo fatal.lo key_val.lo \
gidlist.lo lbuf.lo locking.lo parseln.lo progname.lo secure_path.lo \
setgroups.lo sudo_conf.lo sudo_debug.lo sudo_dso.lo sudo_printf.lo \
term.lo ttysize.lo @COMMON_OBJS@ @LTLIBOBJS@
LTOBJS = alloc.lo event.lo fatal.lo key_val.lo gidlist.lo lbuf.lo locking.lo \
parseln.lo progname.lo secure_path.lo setgroups.lo strtobool.lo \
strtoid.lo strtomode.lo sudo_conf.lo sudo_debug.lo sudo_dso.lo \
sudo_printf.lo term.lo ttysize.lo @COMMON_OBJS@ @LTLIBOBJS@
ATOFOO_TEST_OBJS = atofoo_test.lo locale_stub.lo
@@ -287,23 +287,11 @@ aix.lo: $(srcdir)/aix.c $(incdir)/compat/stdbool.h $(incdir)/fatal.h \
alloc.lo: $(srcdir)/alloc.c $(incdir)/fatal.h $(incdir)/gettext.h \
$(incdir)/missing.h $(incdir)/sudo_alloc.h $(top_builddir)/config.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/alloc.c
atobool.lo: $(srcdir)/atobool.c $(incdir)/compat/stdbool.h $(incdir)/missing.h \
$(incdir)/sudo_debug.h $(incdir)/sudo_util.h \
$(top_builddir)/config.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/atobool.c
atofoo_test.lo: $(srcdir)/regress/atofoo/atofoo_test.c \
$(incdir)/compat/stdbool.h $(incdir)/fatal.h \
$(incdir)/missing.h $(incdir)/sudo_util.h \
$(top_builddir)/config.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/regress/atofoo/atofoo_test.c
atoid.lo: $(srcdir)/atoid.c $(incdir)/compat/stdbool.h $(incdir)/gettext.h \
$(incdir)/missing.h $(incdir)/sudo_debug.h $(incdir)/sudo_util.h \
$(top_builddir)/config.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/atoid.c
atomode.lo: $(srcdir)/atomode.c $(incdir)/compat/stdbool.h $(incdir)/gettext.h \
$(incdir)/missing.h $(incdir)/sudo_debug.h $(incdir)/sudo_util.h \
$(top_builddir)/config.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/atomode.c
clock_gettime.lo: $(srcdir)/clock_gettime.c $(incdir)/compat/timespec.h \
$(incdir)/missing.h $(top_builddir)/config.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/clock_gettime.c
@@ -441,6 +429,18 @@ strlcpy.lo: $(srcdir)/strlcpy.c $(incdir)/missing.h $(top_builddir)/config.h
strsignal.lo: $(srcdir)/strsignal.c $(incdir)/gettext.h $(incdir)/missing.h \
$(top_builddir)/config.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/strsignal.c
strtobool.lo: $(srcdir)/strtobool.c $(incdir)/compat/stdbool.h \
$(incdir)/missing.h $(incdir)/sudo_debug.h $(incdir)/sudo_util.h \
$(top_builddir)/config.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/strtobool.c
strtoid.lo: $(srcdir)/strtoid.c $(incdir)/compat/stdbool.h $(incdir)/gettext.h \
$(incdir)/missing.h $(incdir)/sudo_debug.h $(incdir)/sudo_util.h \
$(top_builddir)/config.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/strtoid.c
strtomode.lo: $(srcdir)/strtomode.c $(incdir)/compat/stdbool.h \
$(incdir)/gettext.h $(incdir)/missing.h $(incdir)/sudo_debug.h \
$(incdir)/sudo_util.h $(top_builddir)/config.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/strtomode.c
strtonum.lo: $(srcdir)/strtonum.c $(incdir)/gettext.h $(incdir)/missing.h \
$(top_builddir)/config.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/strtonum.c

View File

@@ -73,7 +73,7 @@ sudo_getgrouplist(const char *name, gid_t basegid, gid_t *groups, int *ngroupsp)
if ((grset = getgrset(name)) != NULL) {
const char *errstr;
for (cp = strtok(grset, ","); cp != NULL; cp = strtok(NULL, ",")) {
gid = atoid(cp, NULL, NULL, &errstr);
gid = sudo_strtoid(cp, NULL, NULL, &errstr);
if (errstr == NULL && gid != basegid) {
if (ngroups == grpsize)
goto done;

View File

@@ -73,7 +73,7 @@ sudo_parse_gids(const char *gidstr, const gid_t *basegid, GETGROUPS_T **gidsp)
gids[ngids++] = *basegid;
cp = gidstr;
do {
gids[ngids] = (GETGROUPS_T) atoid(cp, ",", &ep, &errstr);
gids[ngids] = (GETGROUPS_T) sudo_strtoid(cp, ",", &ep, &errstr);
if (errstr != NULL) {
sudo_warnx(U_("%s: %s"), cp, U_(errstr));
free(gids);

View File

@@ -38,11 +38,11 @@
__dso_public int main(int argc, char *argv[]);
/* atobool() tests */
static struct atobool_data {
/* sudo_strtobool() tests */
static struct strtobool_data {
const char *bool_str;
int value;
} atobool_data[] = {
} strtobool_data[] = {
{ "true", true },
{ "false", false },
{ "TrUe", true },
@@ -61,15 +61,15 @@ static struct atobool_data {
};
static int
test_atobool(int *ntests)
test_strtobool(int *ntests)
{
struct atobool_data *d;
struct strtobool_data *d;
int errors = 0;
int value;
for (d = atobool_data; d->bool_str != NULL; d++) {
for (d = strtobool_data; d->bool_str != NULL; d++) {
(*ntests)++;
value = atobool(d->bool_str);
value = sudo_strtobool(d->bool_str);
if (value != d->value) {
sudo_warnx_nodebug("FAIL: %s != %d", d->bool_str, d->value);
errors++;
@@ -79,13 +79,13 @@ test_atobool(int *ntests)
return errors;
}
/* atoid() tests */
static struct atoid_data {
/* sudo_strtoid() tests */
static struct strtoid_data {
const char *idstr;
id_t id;
const char *sep;
const char *ep;
} atoid_data[] = {
} strtoid_data[] = {
{ "0,1", 0, ",", "," },
{ "10", 10, NULL, NULL },
{ "-2", -2, NULL, NULL },
@@ -95,18 +95,18 @@ static struct atoid_data {
};
static int
test_atoid(int *ntests)
test_strtoid(int *ntests)
{
struct atoid_data *d;
struct strtoid_data *d;
const char *errstr;
char *ep;
int errors = 0;
id_t value;
for (d = atoid_data; d->idstr != NULL; d++) {
for (d = strtoid_data; d->idstr != NULL; d++) {
(*ntests)++;
errstr = "some error";
value = atoid(d->idstr, d->sep, &ep, &errstr);
value = sudo_strtoid(d->idstr, d->sep, &ep, &errstr);
if (errstr != NULL) {
if (d->id != (id_t)-1) {
sudo_warnx_nodebug("FAIL: %s: %s", d->idstr, errstr);
@@ -125,11 +125,11 @@ test_atoid(int *ntests)
return errors;
}
/* atomode() tests */
static struct atomode_data {
/* sudo_strtomode() tests */
static struct strtomode_data {
const char *mode_str;
mode_t mode;
} atomode_data[] = {
} strtomode_data[] = {
{ "755", 0755 },
{ "007", 007 },
{ "7", 7 },
@@ -138,17 +138,17 @@ static struct atomode_data {
};
static int
test_atomode(int *ntests)
test_strtomode(int *ntests)
{
struct atomode_data *d;
struct strtomode_data *d;
const char *errstr;
int errors = 0;
mode_t mode;
for (d = atomode_data; d->mode_str != NULL; d++) {
for (d = strtomode_data; d->mode_str != NULL; d++) {
(*ntests)++;
errstr = "some error";
mode = atomode(d->mode_str, &errstr);
mode = sudo_strtomode(d->mode_str, &errstr);
if (errstr != NULL) {
if (d->mode != (mode_t)-1) {
sudo_warnx_nodebug("FAIL: %s: %s", d->mode_str, errstr);
@@ -165,7 +165,7 @@ test_atomode(int *ntests)
}
/*
* Simple tests for atobool(), atoid(), atomode().
* Simple tests for sudo_strtobool(), sudo_strtoid(), sudo_strtomode().
*/
int
main(int argc, char *argv[])
@@ -175,9 +175,9 @@ main(int argc, char *argv[])
initprogname(argc > 0 ? argv[0] : "atofoo");
errors += test_atobool(&ntests);
errors += test_atoid(&ntests);
errors += test_atomode(&ntests);
errors += test_strtobool(&ntests);
errors += test_strtoid(&ntests);
errors += test_strtomode(&ntests);
printf("%s: %d tests run, %d errors, %d%% success rate\n", getprogname(),
ntests, errors, (ntests - errors) * 100 / ntests);

View File

@@ -42,9 +42,9 @@
#include "sudo_util.h"
int
atobool(const char *str)
sudo_strtobool(const char *str)
{
debug_decl(atobool, SUDO_DEBUG_UTIL)
debug_decl(sudo_strtobool, SUDO_DEBUG_UTIL)
switch (*str) {
case '0':

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013 Todd C. Miller <Todd.Miller@courtesan.com>
* Copyright (c) 2013-2014 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -55,12 +55,12 @@
* On error, returns 0 and sets errstr.
*/
id_t
atoid(const char *p, const char *sep, char **endp, const char **errstr)
sudo_strtoid(const char *p, const char *sep, char **endp, const char **errstr)
{
char *ep;
id_t rval = 0;
bool valid = false;
debug_decl(atoid, SUDO_DEBUG_UTIL)
debug_decl(sudo_strtoid, SUDO_DEBUG_UTIL)
if (sep == NULL)
sep = "";

View File

@@ -42,11 +42,11 @@
* On error, returns 0 and sets errstr.
*/
int
atomode(const char *cp, const char **errstr)
sudo_strtomode(const char *cp, const char **errstr)
{
char *ep;
long lval;
debug_decl(atomode, SUDO_DEBUG_UTIL)
debug_decl(sudo_strtomode, SUDO_DEBUG_UTIL)
errno = 0;
lval = strtol(cp, &ep, 8);

View File

@@ -160,7 +160,7 @@ set_variable(const char *entry, const char *conf_file)
static void
set_var_disable_coredump(const char *entry, const char *conf_file)
{
int val = atobool(entry);
int val = sudo_strtobool(entry);
if (val != -1)
sudo_conf_data.disable_coredump = val;
@@ -198,7 +198,7 @@ set_var_max_groups(const char *entry, const char *conf_file)
static void
set_var_probe_interfaces(const char *entry, const char *conf_file)
{
int val = atobool(entry);
int val = sudo_strtobool(entry);
if (val != -1)
sudo_conf_data.probe_interfaces = val;

View File

@@ -22,9 +22,6 @@ _sudo_printf
aix_prep_user
aix_restoreauthdb
aix_setauthdb
atobool
atoid
atomode
closefrom_fallback
getprogname
initprogname
@@ -131,6 +128,9 @@ sudo_snprintf
sudo_strlcat
sudo_strlcpy
sudo_strsignal
sudo_strtobool
sudo_strtoid
sudo_strtomode
sudo_strtonum
sudo_term_cbreak
sudo_term_copy

View File

@@ -123,7 +123,7 @@ next_entry:
if ((colon = strchr(cp = colon, ':')) == NULL)
goto next_entry;
*colon++ = '\0';
id = atoid(cp, NULL, NULL, &errstr);
id = sudo_strtoid(cp, NULL, NULL, &errstr);
if (errstr != NULL)
goto next_entry;
gr.gr_gid = (gid_t)id;

View File

@@ -823,7 +823,7 @@ store_mode(char *val, struct sudo_defs_types *def, int op)
if (op == false) {
def->sd_un.mode = 0777;
} else {
mode = atomode(val, &errstr);
mode = sudo_strtomode(val, &errstr);
if (errstr != NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"%s is %s", val, errstr);

View File

@@ -426,32 +426,32 @@ iolog_deserialize_info(struct iolog_details *details, char * const user_info[],
continue;
}
if (strncmp(*cur, "iolog_stdin=", sizeof("iolog_stdin=") - 1) == 0) {
if (atobool(*cur + sizeof("iolog_stdin=") - 1) == true)
if (sudo_strtobool(*cur + sizeof("iolog_stdin=") - 1) == true)
io_log_files[IOFD_STDIN].enabled = true;
continue;
}
if (strncmp(*cur, "iolog_stdout=", sizeof("iolog_stdout=") - 1) == 0) {
if (atobool(*cur + sizeof("iolog_stdout=") - 1) == true)
if (sudo_strtobool(*cur + sizeof("iolog_stdout=") - 1) == true)
io_log_files[IOFD_STDOUT].enabled = true;
continue;
}
if (strncmp(*cur, "iolog_stderr=", sizeof("iolog_stderr=") - 1) == 0) {
if (atobool(*cur + sizeof("iolog_stderr=") - 1) == true)
if (sudo_strtobool(*cur + sizeof("iolog_stderr=") - 1) == true)
io_log_files[IOFD_STDERR].enabled = true;
continue;
}
if (strncmp(*cur, "iolog_ttyin=", sizeof("iolog_ttyin=") - 1) == 0) {
if (atobool(*cur + sizeof("iolog_ttyin=") - 1) == true)
if (sudo_strtobool(*cur + sizeof("iolog_ttyin=") - 1) == true)
io_log_files[IOFD_TTYIN].enabled = true;
continue;
}
if (strncmp(*cur, "iolog_ttyout=", sizeof("iolog_ttyout=") - 1) == 0) {
if (atobool(*cur + sizeof("iolog_ttyout=") - 1) == true)
if (sudo_strtobool(*cur + sizeof("iolog_ttyout=") - 1) == true)
io_log_files[IOFD_TTYOUT].enabled = true;
continue;
}
if (strncmp(*cur, "iolog_compress=", sizeof("iolog_compress=") - 1) == 0) {
if (atobool(*cur + sizeof("iolog_compress=") - 1) == true)
if (sudo_strtobool(*cur + sizeof("iolog_compress=") - 1) == true)
iolog_compress = true; /* must be global */
continue;
}
@@ -489,7 +489,7 @@ iolog_deserialize_info(struct iolog_details *details, char * const user_info[],
if (runas_euid_str != NULL)
runas_uid_str = runas_euid_str;
if (runas_uid_str != NULL) {
id = atoid(runas_uid_str, NULL, NULL, &errstr);
id = sudo_strtoid(runas_uid_str, NULL, NULL, &errstr);
if (errstr != NULL)
sudo_warnx("runas uid %s: %s", runas_uid_str, U_(errstr));
else
@@ -498,7 +498,7 @@ iolog_deserialize_info(struct iolog_details *details, char * const user_info[],
if (runas_egid_str != NULL)
runas_gid_str = runas_egid_str;
if (runas_gid_str != NULL) {
id = atoid(runas_gid_str, NULL, NULL, &errstr);
id = sudo_strtoid(runas_gid_str, NULL, NULL, &errstr);
if (errstr != NULL)
sudo_warnx("runas gid %s: %s", runas_gid_str, U_(errstr));
else

View File

@@ -1431,7 +1431,7 @@ sudo_ldap_parse_keyword(const char *keyword, const char *value,
*(int *)(cur->valp) = LDAP_DEREF_NEVER;
break;
case CONF_BOOL:
*(int *)(cur->valp) = atobool(value) == true;
*(int *)(cur->valp) = sudo_strtobool(value) == true;
break;
case CONF_INT:
*(int *)(cur->valp) = strtonum(value, INT_MIN, INT_MAX, &errstr);
@@ -1662,7 +1662,7 @@ sudo_ldap_read_config(void)
if (ldap_conf.ssl != NULL) {
if (strcasecmp(ldap_conf.ssl, "start_tls") == 0)
ldap_conf.ssl_mode = SUDO_LDAP_STARTTLS;
else if (atobool(ldap_conf.ssl) == true)
else if (sudo_strtobool(ldap_conf.ssl) == true)
ldap_conf.ssl_mode = SUDO_LDAP_SSL;
}

View File

@@ -811,7 +811,7 @@ userpw_matches(const char *sudoers_user, const char *user, const struct passwd *
debug_decl(userpw_matches, SUDO_DEBUG_MATCH)
if (pw != NULL && *sudoers_user == '#') {
uid = (uid_t) atoid(sudoers_user + 1, NULL, NULL, &errstr);
uid = (uid_t) sudo_strtoid(sudoers_user + 1, NULL, NULL, &errstr);
if (errstr == NULL && uid == pw->pw_uid) {
rc = true;
goto done;
@@ -838,7 +838,7 @@ group_matches(const char *sudoers_group, const struct group *gr)
debug_decl(group_matches, SUDO_DEBUG_MATCH)
if (*sudoers_group == '#') {
gid = (gid_t) atoid(sudoers_group + 1, NULL, NULL, &errstr);
gid = (gid_t) sudo_strtoid(sudoers_group + 1, NULL, NULL, &errstr);
if (errstr == NULL && gid == gr->gr_gid) {
rc = true;
goto done;

View File

@@ -104,7 +104,7 @@ sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group)
}
if (MATCHES(*cur, "sudoers_uid=")) {
p = *cur + sizeof("sudoers_uid=") - 1;
sudoers_uid = (uid_t) atoid(p, NULL, NULL, &errstr);
sudoers_uid = (uid_t) sudo_strtoid(p, NULL, NULL, &errstr);
if (errstr != NULL) {
sudo_warnx(U_("%s: %s"), *cur, U_(errstr));
goto bad;
@@ -113,7 +113,7 @@ sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group)
}
if (MATCHES(*cur, "sudoers_gid=")) {
p = *cur + sizeof("sudoers_gid=") - 1;
sudoers_gid = (gid_t) atoid(p, NULL, NULL, &errstr);
sudoers_gid = (gid_t) sudo_strtoid(p, NULL, NULL, &errstr);
if (errstr != NULL) {
sudo_warnx(U_("%s: %s"), *cur, U_(errstr));
goto bad;
@@ -122,7 +122,7 @@ sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group)
}
if (MATCHES(*cur, "sudoers_mode=")) {
p = *cur + sizeof("sudoers_mode=") - 1;
sudoers_mode = atomode(p, &errstr);
sudoers_mode = sudo_strtomode(p, &errstr);
if (errstr != NULL) {
sudo_warnx(U_("%s: %s"), *cur, U_(errstr));
goto bad;
@@ -173,49 +173,49 @@ sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group)
continue;
}
if (MATCHES(*cur, "set_home=")) {
if (atobool(*cur + sizeof("set_home=") - 1) == true)
if (sudo_strtobool(*cur + sizeof("set_home=") - 1) == true)
SET(flags, MODE_RESET_HOME);
continue;
}
if (MATCHES(*cur, "preserve_environment=")) {
if (atobool(*cur + sizeof("preserve_environment=") - 1) == true)
if (sudo_strtobool(*cur + sizeof("preserve_environment=") - 1) == true)
SET(flags, MODE_PRESERVE_ENV);
continue;
}
if (MATCHES(*cur, "run_shell=")) {
if (atobool(*cur + sizeof("run_shell=") - 1) == true)
if (sudo_strtobool(*cur + sizeof("run_shell=") - 1) == true)
SET(flags, MODE_SHELL);
continue;
}
if (MATCHES(*cur, "login_shell=")) {
if (atobool(*cur + sizeof("login_shell=") - 1) == true) {
if (sudo_strtobool(*cur + sizeof("login_shell=") - 1) == true) {
SET(flags, MODE_LOGIN_SHELL);
def_env_reset = true;
}
continue;
}
if (MATCHES(*cur, "implied_shell=")) {
if (atobool(*cur + sizeof("implied_shell=") - 1) == true)
if (sudo_strtobool(*cur + sizeof("implied_shell=") - 1) == true)
SET(flags, MODE_IMPLIED_SHELL);
continue;
}
if (MATCHES(*cur, "preserve_groups=")) {
if (atobool(*cur + sizeof("preserve_groups=") - 1) == true)
if (sudo_strtobool(*cur + sizeof("preserve_groups=") - 1) == true)
SET(flags, MODE_PRESERVE_GROUPS);
continue;
}
if (MATCHES(*cur, "ignore_ticket=")) {
if (atobool(*cur + sizeof("ignore_ticket=") - 1) == true)
if (sudo_strtobool(*cur + sizeof("ignore_ticket=") - 1) == true)
SET(flags, MODE_IGNORE_TICKET);
continue;
}
if (MATCHES(*cur, "noninteractive=")) {
if (atobool(*cur + sizeof("noninteractive=") - 1) == true)
if (sudo_strtobool(*cur + sizeof("noninteractive=") - 1) == true)
SET(flags, MODE_NONINTERACTIVE);
continue;
}
if (MATCHES(*cur, "sudoedit=")) {
if (atobool(*cur + sizeof("sudoedit=") - 1) == true)
if (sudo_strtobool(*cur + sizeof("sudoedit=") - 1) == true)
SET(flags, MODE_EDIT);
continue;
}
@@ -282,7 +282,7 @@ sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group)
}
if (MATCHES(*cur, "uid=")) {
p = *cur + sizeof("uid=") - 1;
user_uid = (uid_t) atoid(p, NULL, NULL, &errstr);
user_uid = (uid_t) sudo_strtoid(p, NULL, NULL, &errstr);
if (errstr != NULL) {
sudo_warnx(U_("%s: %s"), *cur, U_(errstr));
goto bad;
@@ -291,7 +291,7 @@ sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group)
}
if (MATCHES(*cur, "gid=")) {
p = *cur + sizeof("gid=") - 1;
user_gid = (gid_t) atoid(p, NULL, NULL, &errstr);
user_gid = (gid_t) sudo_strtoid(p, NULL, NULL, &errstr);
if (errstr != NULL) {
sudo_warnx(U_("%s: %s"), *cur, U_(errstr));
goto bad;
@@ -340,7 +340,7 @@ sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group)
}
if (MATCHES(*cur, "sid=")) {
p = *cur + sizeof("sid=") - 1;
sudo_user.sid = (pid_t) atoid(p, NULL, NULL, &errstr);
sudo_user.sid = (pid_t) sudo_strtoid(p, NULL, NULL, &errstr);
if (errstr != NULL) {
sudo_warnx(U_("%s: %s"), *cur, U_(errstr));
goto bad;

View File

@@ -280,7 +280,7 @@ sudo_fakepwnam(const char *user, gid_t gid)
uid_t uid;
debug_decl(sudo_fakepwnam, SUDO_DEBUG_NSS)
uid = (uid_t) atoid(user + 1, NULL, NULL, &errstr);
uid = (uid_t) sudo_strtoid(user + 1, NULL, NULL, &errstr);
if (errstr != NULL) {
sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_DIAG,
"uid %s %s", user, errstr);
@@ -464,7 +464,7 @@ sudo_fakegrnam(const char *group)
for (i = 0; i < 2; i++) {
gritem = sudo_ecalloc(1, len);
gr = &gritem->gr;
gr->gr_gid = (gid_t) atoid(group + 1, NULL, NULL, &errstr);
gr->gr_gid = (gid_t) sudo_strtoid(group + 1, NULL, NULL, &errstr);
gr->gr_name = (char *)(gritem + 1);
memcpy(gr->gr_name, group, name_len + 1);
if (errstr != NULL) {
@@ -651,7 +651,7 @@ user_in_group(const struct passwd *pw, const char *group)
* If it could be a sudo-style group ID check gids first.
*/
if (group[0] == '#') {
gid_t gid = (gid_t) atoid(group + 1, NULL, NULL, &errstr);
gid_t gid = (gid_t) sudo_strtoid(group + 1, NULL, NULL, &errstr);
if (errstr != NULL) {
sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_DIAG,
"gid %s %s", group, errstr);

View File

@@ -152,7 +152,7 @@ main(int argc, char *argv[])
user_name = strdup(line);
break;
case 2:
user_gid = (gid_t)atoid(line, NULL, NULL, &errstr);
user_gid = (gid_t)sudo_strtoid(line, NULL, NULL, &errstr);
if (errstr != NULL)
sudo_fatalx("group ID %s: %s", line, errstr);
break;
@@ -162,7 +162,7 @@ main(int argc, char *argv[])
runas_pw->pw_name = strdup(line);
break;
case 4:
runas_pw->pw_gid = (gid_t)atoid(line, NULL, NULL, &errstr);
runas_pw->pw_gid = (gid_t)sudo_strtoid(line, NULL, NULL, &errstr);
if (errstr != NULL)
sudo_fatalx("group ID %s: %s", line, errstr);
break;

View File

@@ -323,7 +323,7 @@ sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[],
if (*def_timestampowner == '#') {
const char *errstr;
uid_t uid = atoid(def_timestampowner + 1, NULL, NULL, &errstr);
uid_t uid = sudo_strtoid(def_timestampowner + 1, NULL, NULL, &errstr);
if (errstr == NULL)
pw = sudo_getpwuid(uid);
}
@@ -905,7 +905,7 @@ set_runaspw(const char *user, bool quiet)
if (*user == '#') {
const char *errstr;
uid_t uid = atoid(user + 1, NULL, NULL, &errstr);
uid_t uid = sudo_strtoid(user + 1, NULL, NULL, &errstr);
if (errstr == NULL) {
if ((pw = sudo_getpwuid(uid)) == NULL)
pw = sudo_fakepwnam(user, runas_gr ? runas_gr->gr_gid : 0);
@@ -936,7 +936,7 @@ set_runasgr(const char *group, bool quiet)
if (*group == '#') {
const char *errstr;
gid_t gid = atoid(group + 1, NULL, NULL, &errstr);
gid_t gid = sudo_strtoid(group + 1, NULL, NULL, &errstr);
if (errstr == NULL) {
if ((gr = sudo_getgrgid(gid)) == NULL)
gr = sudo_fakegrnam(group);

View File

@@ -153,7 +153,7 @@ main(int argc, char *argv[])
user_host = optarg;
break;
case 'G':
sudoers_gid = (gid_t)atoid(optarg, NULL, NULL, &errstr);
sudoers_gid = (gid_t)sudo_strtoid(optarg, NULL, NULL, &errstr);
if (errstr != NULL)
sudo_fatalx("group ID %s: %s", optarg, errstr);
break;
@@ -170,7 +170,7 @@ main(int argc, char *argv[])
trace_print = testsudoers_print;
break;
case 'U':
sudoers_uid = (uid_t)atoid(optarg, NULL, NULL, &errstr);
sudoers_uid = (uid_t)sudo_strtoid(optarg, NULL, NULL, &errstr);
if (errstr != NULL)
sudo_fatalx("user ID %s: %s", optarg, errstr);
break;
@@ -353,7 +353,7 @@ set_runaspw(const char *user)
if (*user == '#') {
const char *errstr;
uid_t uid = atoid(user + 1, NULL, NULL, &errstr);
uid_t uid = sudo_strtoid(user + 1, NULL, NULL, &errstr);
if (errstr == NULL) {
if ((pw = sudo_getpwuid(uid)) == NULL)
pw = sudo_fakepwnam(user, runas_gr ? runas_gr->gr_gid : 0);
@@ -377,7 +377,7 @@ set_runasgr(const char *group)
if (*group == '#') {
const char *errstr;
gid_t gid = atoid(group + 1, NULL, NULL, &errstr);
gid_t gid = sudo_strtoid(group + 1, NULL, NULL, &errstr);
if (errstr == NULL) {
if ((gr = sudo_getgrgid(gid)) == NULL)
gr = sudo_fakegrnam(group);

View File

@@ -143,14 +143,14 @@ next_entry:
if ((colon = strchr(cp = colon, ':')) == NULL)
goto next_entry;
*colon++ = '\0';
id = atoid(cp, NULL, NULL, &errstr);
id = sudo_strtoid(cp, NULL, NULL, &errstr);
if (errstr != NULL)
goto next_entry;
pw.pw_uid = (uid_t)id;
if ((colon = strchr(cp = colon, ':')) == NULL)
goto next_entry;
*colon++ = '\0';
id = atoid(cp, NULL, NULL, &errstr);
id = sudo_strtoid(cp, NULL, NULL, &errstr);
if (errstr != NULL)
goto next_entry;
pw.pw_gid = (gid_t)id;
@@ -273,7 +273,7 @@ next_entry:
if ((colon = strchr(cp = colon, ':')) == NULL)
goto next_entry;
*colon++ = '\0';
id = atoid(cp, NULL, NULL, &errstr);
id = sudo_strtoid(cp, NULL, NULL, &errstr);
if (errstr != NULL)
goto next_entry;
gr.gr_gid = (gid_t)id;

View File

@@ -375,7 +375,7 @@ print_member_json(FILE *fp, struct member *m, enum word_type word_type,
value.u.string++;
typestr = "nonunixgroup";
if (*value.u.string == '#') {
id = atoid(m->name + 3, NULL, NULL, &errstr);
id = sudo_strtoid(m->name + 3, NULL, NULL, &errstr);
if (errstr != NULL) {
sudo_warnx("internal error: non-Unix group ID %s: \"%s\"",
errstr, m->name);
@@ -388,7 +388,7 @@ print_member_json(FILE *fp, struct member *m, enum word_type word_type,
} else {
typestr = "usergroup";
if (*value.u.string == '#') {
id = atoid(m->name + 2, NULL, NULL, &errstr);
id = sudo_strtoid(m->name + 2, NULL, NULL, &errstr);
if (errstr != NULL) {
sudo_warnx("internal error: group ID %s: \"%s\"",
errstr, m->name);
@@ -422,7 +422,7 @@ print_member_json(FILE *fp, struct member *m, enum word_type word_type,
case TYPE_USERNAME:
typestr = "username";
if (*value.u.string == '#') {
id = atoid(m->name + 1, NULL, NULL, &errstr);
id = sudo_strtoid(m->name + 1, NULL, NULL, &errstr);
if (errstr != NULL) {
sudo_warnx("internal error: user ID %s: \"%s\"",
errstr, m->name);

View File

@@ -135,7 +135,7 @@ sysgroup_query(const char *user, const char *group, const struct passwd *pwd)
grp = sysgroup_getgrnam(group);
if (grp == NULL && group[0] == '#' && group[1] != '\0') {
const char *errstr;
gid_t gid = atoid(group + 1, NULL, NULL, &errstr);
gid_t gid = sudo_strtoid(group + 1, NULL, NULL, &errstr);
if (errstr == NULL)
grp = sysgroup_getgrgid(gid);
}

View File

@@ -562,7 +562,7 @@ command_info_to_details(char * const info[], struct command_details *details)
break;
case 'e':
if (strncmp("exec_background=", info[i], sizeof("exec_background=") - 1) == 0) {
if (atobool(info[i] + sizeof("exec_background=") - 1) == true)
if (sudo_strtobool(info[i] + sizeof("exec_background=") - 1) == true)
SET(details->flags, CD_EXEC_BG);
break;
}
@@ -580,14 +580,14 @@ command_info_to_details(char * const info[], struct command_details *details)
break;
}
if (strncmp("noexec=", info[i], sizeof("noexec=") - 1) == 0) {
if (atobool(info[i] + sizeof("noexec=") - 1) == true)
if (sudo_strtobool(info[i] + sizeof("noexec=") - 1) == true)
SET(details->flags, CD_NOEXEC);
break;
}
break;
case 'p':
if (strncmp("preserve_groups=", info[i], sizeof("preserve_groups=") - 1) == 0) {
if (atobool(info[i] + sizeof("preserve_groups=") - 1) == true)
if (sudo_strtobool(info[i] + sizeof("preserve_groups=") - 1) == true)
SET(details->flags, CD_PRESERVE_GROUPS);
break;
}
@@ -600,7 +600,7 @@ command_info_to_details(char * const info[], struct command_details *details)
case 'r':
if (strncmp("runas_egid=", info[i], sizeof("runas_egid=") - 1) == 0) {
cp = info[i] + sizeof("runas_egid=") - 1;
id = atoid(cp, NULL, NULL, &errstr);
id = sudo_strtoid(cp, NULL, NULL, &errstr);
if (errstr != NULL)
sudo_fatalx(U_("%s: %s"), info[i], U_(errstr));
details->egid = (gid_t)id;
@@ -609,7 +609,7 @@ command_info_to_details(char * const info[], struct command_details *details)
}
if (strncmp("runas_euid=", info[i], sizeof("runas_euid=") - 1) == 0) {
cp = info[i] + sizeof("runas_euid=") - 1;
id = atoid(cp, NULL, NULL, &errstr);
id = sudo_strtoid(cp, NULL, NULL, &errstr);
if (errstr != NULL)
sudo_fatalx(U_("%s: %s"), info[i], U_(errstr));
details->euid = (uid_t)id;
@@ -618,7 +618,7 @@ command_info_to_details(char * const info[], struct command_details *details)
}
if (strncmp("runas_gid=", info[i], sizeof("runas_gid=") - 1) == 0) {
cp = info[i] + sizeof("runas_gid=") - 1;
id = atoid(cp, NULL, NULL, &errstr);
id = sudo_strtoid(cp, NULL, NULL, &errstr);
if (errstr != NULL)
sudo_fatalx(U_("%s: %s"), info[i], U_(errstr));
details->gid = (gid_t)id;
@@ -635,7 +635,7 @@ command_info_to_details(char * const info[], struct command_details *details)
}
if (strncmp("runas_uid=", info[i], sizeof("runas_uid=") - 1) == 0) {
cp = info[i] + sizeof("runas_uid=") - 1;
id = atoid(cp, NULL, NULL, &errstr);
id = sudo_strtoid(cp, NULL, NULL, &errstr);
if (errstr != NULL)
sudo_fatalx(U_("%s: %s"), info[i], U_(errstr));
details->uid = (uid_t)id;
@@ -669,12 +669,12 @@ command_info_to_details(char * const info[], struct command_details *details)
SET_STRING("selinux_role=", selinux_role)
SET_STRING("selinux_type=", selinux_type)
if (strncmp("set_utmp=", info[i], sizeof("set_utmp=") - 1) == 0) {
if (atobool(info[i] + sizeof("set_utmp=") - 1) == true)
if (sudo_strtobool(info[i] + sizeof("set_utmp=") - 1) == true)
SET(details->flags, CD_SET_UTMP);
break;
}
if (strncmp("sudoedit=", info[i], sizeof("sudoedit=") - 1) == 0) {
if (atobool(info[i] + sizeof("sudoedit=") - 1) == true)
if (sudo_strtobool(info[i] + sizeof("sudoedit=") - 1) == true)
SET(details->flags, CD_SUDOEDIT);
break;
}
@@ -692,14 +692,14 @@ command_info_to_details(char * const info[], struct command_details *details)
case 'u':
if (strncmp("umask=", info[i], sizeof("umask=") - 1) == 0) {
cp = info[i] + sizeof("umask=") - 1;
details->umask = atomode(cp, &errstr);
details->umask = sudo_strtomode(cp, &errstr);
if (errstr != NULL)
sudo_fatalx(U_("%s: %s"), info[i], U_(errstr));
SET(details->flags, CD_SET_UMASK);
break;
}
if (strncmp("use_pty=", info[i], sizeof("use_pty=") - 1) == 0) {
if (atobool(info[i] + sizeof("use_pty=") - 1) == true)
if (sudo_strtobool(info[i] + sizeof("use_pty=") - 1) == true)
SET(details->flags, CD_USE_PTY);
break;
}