Move reference-counted string code from sudoers to libsudo_util.
It will be used by sudo_logsrvd too.
This commit is contained in:
2
MANIFEST
2
MANIFEST
@@ -227,6 +227,7 @@ lib/util/pread.c
|
||||
lib/util/progname.c
|
||||
lib/util/pw_dup.c
|
||||
lib/util/pwrite.c
|
||||
lib/util/rcstr.c
|
||||
lib/util/reallocarray.c
|
||||
lib/util/regress/corpus/seed/sudo_conf/sudo.conf.1
|
||||
lib/util/regress/corpus/seed/sudo_conf/sudo.conf.2
|
||||
@@ -657,7 +658,6 @@ plugins/sudoers/prompt.c
|
||||
plugins/sudoers/pwutil.c
|
||||
plugins/sudoers/pwutil.h
|
||||
plugins/sudoers/pwutil_impl.c
|
||||
plugins/sudoers/rcstr.c
|
||||
plugins/sudoers/redblack.c
|
||||
plugins/sudoers/redblack.h
|
||||
plugins/sudoers/regress/check_symbols/check_symbols.c
|
||||
|
@@ -250,6 +250,12 @@ sudo_dso_public ssize_t sudo_parseln_v2(char **buf, size_t *bufsize, unsigned in
|
||||
sudo_dso_public void initprogname(const char *);
|
||||
sudo_dso_public void initprogname2(const char *, const char * const *);
|
||||
|
||||
/* rcstr.c */
|
||||
sudo_dso_public char *sudo_rcstr_dup(const char *src);
|
||||
sudo_dso_public char *sudo_rcstr_alloc(size_t len);
|
||||
sudo_dso_public char *sudo_rcstr_addref(const char *s);
|
||||
sudo_dso_public void sudo_rcstr_delref(const char *s);
|
||||
|
||||
/* roundup.c */
|
||||
sudo_dso_public unsigned int sudo_pow2_roundup_v1(unsigned int len);
|
||||
#define sudo_pow2_roundup(_a) sudo_pow2_roundup_v1((_a))
|
||||
|
@@ -132,7 +132,7 @@ SHELL = @SHELL@
|
||||
|
||||
LTOBJS = basename.lo @DIGEST@ event.lo fatal.lo key_val.lo gethostname.lo \
|
||||
gettime.lo getgrouplist.lo gidlist.lo json.lo lbuf.lo locking.lo \
|
||||
logfac.lo logpri.lo mkdir_parents.lo parseln.lo progname.lo \
|
||||
logfac.lo logpri.lo mkdir_parents.lo parseln.lo progname.lo rcstr.lo \
|
||||
roundup.lo secure_path.lo setgroups.lo strsplit.lo strtobool.lo \
|
||||
strtoid.lo strtomode.lo strtonum.lo sudo_conf.lo \
|
||||
sudo_debug.lo sudo_dso.lo term.lo ttyname_dev.lo \
|
||||
@@ -1125,6 +1125,14 @@ pwrite.i: $(srcdir)/pwrite.c $(incdir)/sudo_compat.h $(top_builddir)/config.h
|
||||
$(CC) -E -o $@ $(CPPFLAGS) $<
|
||||
pwrite.plog: pwrite.i
|
||||
rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/pwrite.c --i-file $< --output-file $@
|
||||
rcstr.lo: $(srcdir)/rcstr.c $(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
|
||||
$(incdir)/sudo_util.h $(top_builddir)/config.h
|
||||
$(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/rcstr.c
|
||||
rcstr.i: $(srcdir)/rcstr.c $(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
|
||||
$(incdir)/sudo_util.h $(top_builddir)/config.h
|
||||
$(CC) -E -o $@ $(CPPFLAGS) $<
|
||||
rcstr.plog: rcstr.i
|
||||
rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/rcstr.c --i-file $< --output-file $@
|
||||
reallocarray.lo: $(srcdir)/reallocarray.c $(incdir)/sudo_compat.h \
|
||||
$(top_builddir)/config.h
|
||||
$(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/reallocarray.c
|
||||
|
@@ -27,7 +27,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "sudoers.h"
|
||||
#include "sudo_compat.h"
|
||||
#include "sudo_debug.h"
|
||||
#include "sudo_util.h"
|
||||
|
||||
/* Trivial reference-counted strings. */
|
||||
struct rcstr {
|
||||
@@ -40,23 +42,23 @@ struct rcstr {
|
||||
* Returns the newly-created string with a refcnt of 1.
|
||||
*/
|
||||
char *
|
||||
rcstr_dup(const char *src)
|
||||
sudo_rcstr_dup(const char *src)
|
||||
{
|
||||
size_t len = strlen(src);
|
||||
char *dst;
|
||||
debug_decl(rcstr_dup, SUDOERS_DEBUG_UTIL);
|
||||
debug_decl(sudo_rcstr_dup, SUDO_DEBUG_UTIL);
|
||||
|
||||
dst = rcstr_alloc(len);
|
||||
dst = sudo_rcstr_alloc(len);
|
||||
memcpy(dst, src, len);
|
||||
dst[len] = '\0';
|
||||
debug_return_ptr(dst);
|
||||
}
|
||||
|
||||
char *
|
||||
rcstr_alloc(size_t len)
|
||||
sudo_rcstr_alloc(size_t len)
|
||||
{
|
||||
struct rcstr *rcs;
|
||||
debug_decl(rcstr_dup, SUDOERS_DEBUG_UTIL);
|
||||
debug_decl(sudo_rcstr_dup, SUDO_DEBUG_UTIL);
|
||||
|
||||
/* Note: sizeof(struct rcstr) includes space for the NUL */
|
||||
rcs = malloc(sizeof(struct rcstr) + len);
|
||||
@@ -70,10 +72,10 @@ rcstr_alloc(size_t len)
|
||||
}
|
||||
|
||||
char *
|
||||
rcstr_addref(const char *s)
|
||||
sudo_rcstr_addref(const char *s)
|
||||
{
|
||||
struct rcstr *rcs;
|
||||
debug_decl(rcstr_dup, SUDOERS_DEBUG_UTIL);
|
||||
debug_decl(sudo_rcstr_dup, SUDO_DEBUG_UTIL);
|
||||
|
||||
if (s == NULL)
|
||||
debug_return_ptr(NULL);
|
||||
@@ -84,10 +86,10 @@ rcstr_addref(const char *s)
|
||||
}
|
||||
|
||||
void
|
||||
rcstr_delref(const char *s)
|
||||
sudo_rcstr_delref(const char *s)
|
||||
{
|
||||
struct rcstr *rcs;
|
||||
debug_decl(rcstr_dup, SUDOERS_DEBUG_UTIL);
|
||||
debug_decl(sudo_rcstr_dup, SUDO_DEBUG_UTIL);
|
||||
|
||||
if (s != NULL) {
|
||||
rcs = __containerof((const void *)s, struct rcstr, str);
|
@@ -113,6 +113,10 @@ sudo_parse_gids_v1
|
||||
sudo_parseln_v1
|
||||
sudo_parseln_v2
|
||||
sudo_pow2_roundup_v1
|
||||
sudo_rcstr_addref
|
||||
sudo_rcstr_alloc
|
||||
sudo_rcstr_delref
|
||||
sudo_rcstr_dup
|
||||
sudo_secure_dir_v1
|
||||
sudo_secure_file_v1
|
||||
sudo_setgroups_v1
|
||||
|
@@ -173,7 +173,7 @@ AUTH_OBJS = sudo_auth.lo @AUTH_OBJS@
|
||||
LIBPARSESUDOERS_OBJS = alias.lo b64_decode.lo defaults.lo digestname.lo \
|
||||
exptilde.lo filedigest.lo gentime.lo gmtoff.lo gram.lo \
|
||||
hexchar.lo match.lo match_addr.lo match_command.lo \
|
||||
match_digest.lo pwutil.lo pwutil_impl.lo rcstr.lo \
|
||||
match_digest.lo pwutil.lo pwutil_impl.lo \
|
||||
redblack.lo strlist.lo sudoers_debug.lo timeout.lo \
|
||||
timestr.lo toke.lo toke_util.lo
|
||||
|
||||
@@ -2512,26 +2512,6 @@ pwutil_impl.i: $(srcdir)/pwutil_impl.c $(devdir)/def_data.h \
|
||||
$(CC) -E -o $@ $(CPPFLAGS) $<
|
||||
pwutil_impl.plog: pwutil_impl.i
|
||||
rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/pwutil_impl.c --i-file $< --output-file $@
|
||||
rcstr.lo: $(srcdir)/rcstr.c $(devdir)/def_data.h $(incdir)/compat/stdbool.h \
|
||||
$(incdir)/sudo_compat.h $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
|
||||
$(incdir)/sudo_eventlog.h $(incdir)/sudo_fatal.h \
|
||||
$(incdir)/sudo_gettext.h $(incdir)/sudo_plugin.h \
|
||||
$(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/defaults.h \
|
||||
$(srcdir)/logging.h $(srcdir)/parse.h $(srcdir)/sudo_nss.h \
|
||||
$(srcdir)/sudoers.h $(srcdir)/sudoers_debug.h \
|
||||
$(top_builddir)/config.h $(top_builddir)/pathnames.h
|
||||
$(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/rcstr.c
|
||||
rcstr.i: $(srcdir)/rcstr.c $(devdir)/def_data.h $(incdir)/compat/stdbool.h \
|
||||
$(incdir)/sudo_compat.h $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
|
||||
$(incdir)/sudo_eventlog.h $(incdir)/sudo_fatal.h \
|
||||
$(incdir)/sudo_gettext.h $(incdir)/sudo_plugin.h \
|
||||
$(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/defaults.h \
|
||||
$(srcdir)/logging.h $(srcdir)/parse.h $(srcdir)/sudo_nss.h \
|
||||
$(srcdir)/sudoers.h $(srcdir)/sudoers_debug.h \
|
||||
$(top_builddir)/config.h $(top_builddir)/pathnames.h
|
||||
$(CC) -E -o $@ $(CPPFLAGS) $<
|
||||
rcstr.plog: rcstr.i
|
||||
rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/rcstr.c --i-file $< --output-file $@
|
||||
redblack.lo: $(srcdir)/redblack.c $(devdir)/def_data.h \
|
||||
$(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
|
||||
$(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
|
||||
|
@@ -146,7 +146,7 @@ alias_add(struct sudoers_parse_tree *parse_tree, char *name, int type,
|
||||
* since it modifies "file" (adds a ref) and "members" (tailq conversion).
|
||||
*/
|
||||
/* a->used = false; */
|
||||
a->file = rcstr_addref(file);
|
||||
a->file = sudo_rcstr_addref(file);
|
||||
a->line = line;
|
||||
a->column = column;
|
||||
HLTQ_TO_TAILQ(&a->members, members, entries);
|
||||
@@ -215,7 +215,7 @@ alias_free(void *v)
|
||||
|
||||
if (a != NULL) {
|
||||
free(a->name);
|
||||
rcstr_delref(a->file);
|
||||
sudo_rcstr_delref(a->file);
|
||||
free_members(&a->members);
|
||||
free(a);
|
||||
}
|
||||
|
@@ -64,7 +64,7 @@ check_alias(struct sudoers_parse_tree *parse_tree, char *name, int type,
|
||||
}
|
||||
fputc('\n', stderr);
|
||||
if (strict && errorfile == NULL) {
|
||||
errorfile = rcstr_addref(file);
|
||||
errorfile = sudo_rcstr_addref(file);
|
||||
errorlineno = line;
|
||||
}
|
||||
}
|
||||
|
@@ -641,8 +641,8 @@ parse_sudoers(const char *input_file, struct cvtsudoers_config *conf)
|
||||
if (sudoersparse() && !parse_error) {
|
||||
sudo_warnx(U_("failed to parse %s file, unknown error"), input_file);
|
||||
parse_error = true;
|
||||
rcstr_delref(errorfile);
|
||||
if ((errorfile = rcstr_dup(input_file)) == NULL)
|
||||
sudo_rcstr_delref(errorfile);
|
||||
if ((errorfile = sudo_rcstr_dup(input_file)) == NULL)
|
||||
sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
||||
}
|
||||
if (parse_error) {
|
||||
|
@@ -3306,8 +3306,8 @@ sudoerserrorf(const char *fmt, ...)
|
||||
/* Save the line the first error occurred on. */
|
||||
if (errorlineno == -1) {
|
||||
errorlineno = this_lineno;
|
||||
rcstr_delref(errorfile);
|
||||
errorfile = rcstr_addref(sudoers);
|
||||
sudo_rcstr_delref(errorfile);
|
||||
errorfile = sudo_rcstr_addref(sudoers);
|
||||
}
|
||||
if (sudoers_warnings && fmt != NULL) {
|
||||
LEXTRACE("<*> ");
|
||||
@@ -3401,7 +3401,7 @@ new_default(char *var, char *val, short op)
|
||||
/* d->binding = NULL */
|
||||
d->line = this_lineno;
|
||||
d->column = sudolinebuf.toke_start + 1;
|
||||
d->file = rcstr_addref(sudoers);
|
||||
d->file = sudo_rcstr_addref(sudoers);
|
||||
HLTQ_INIT(d, entries);
|
||||
|
||||
debug_return_ptr(d);
|
||||
@@ -3533,7 +3533,7 @@ add_userspec(struct member *members, struct privilege *privs)
|
||||
}
|
||||
u->line = this_lineno;
|
||||
u->column = sudolinebuf.toke_start + 1;
|
||||
u->file = rcstr_addref(sudoers);
|
||||
u->file = sudo_rcstr_addref(sudoers);
|
||||
parser_leak_remove(LEAK_MEMBER, members);
|
||||
HLTQ_TO_TAILQ(&u->users, members, entries);
|
||||
parser_leak_remove(LEAK_PRIVILEGE, privs);
|
||||
@@ -3613,7 +3613,7 @@ free_default(struct defaults *def, struct member_list **binding)
|
||||
free(def->binding);
|
||||
}
|
||||
}
|
||||
rcstr_delref(def->file);
|
||||
sudo_rcstr_delref(def->file);
|
||||
free(def->var);
|
||||
free(def->val);
|
||||
free(def);
|
||||
@@ -3737,7 +3737,7 @@ free_userspec(struct userspec *us)
|
||||
free(comment->str);
|
||||
free(comment);
|
||||
}
|
||||
rcstr_delref(us->file);
|
||||
sudo_rcstr_delref(us->file);
|
||||
free(us);
|
||||
|
||||
debug_return;
|
||||
@@ -3795,9 +3795,9 @@ init_parser(const char *path, bool quiet, bool strict)
|
||||
parser_leak_init();
|
||||
init_lexer();
|
||||
|
||||
rcstr_delref(sudoers);
|
||||
sudo_rcstr_delref(sudoers);
|
||||
if (path != NULL) {
|
||||
if ((sudoers = rcstr_dup(path)) == NULL) {
|
||||
if ((sudoers = sudo_rcstr_dup(path)) == NULL) {
|
||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
||||
ret = false;
|
||||
}
|
||||
@@ -3807,7 +3807,7 @@ init_parser(const char *path, bool quiet, bool strict)
|
||||
|
||||
parse_error = false;
|
||||
errorlineno = -1;
|
||||
rcstr_delref(errorfile);
|
||||
sudo_rcstr_delref(errorfile);
|
||||
errorfile = NULL;
|
||||
sudoers_warnings = !quiet;
|
||||
sudoers_strict = strict;
|
||||
|
@@ -1155,8 +1155,8 @@ sudoerserrorf(const char *fmt, ...)
|
||||
/* Save the line the first error occurred on. */
|
||||
if (errorlineno == -1) {
|
||||
errorlineno = this_lineno;
|
||||
rcstr_delref(errorfile);
|
||||
errorfile = rcstr_addref(sudoers);
|
||||
sudo_rcstr_delref(errorfile);
|
||||
errorfile = sudo_rcstr_addref(sudoers);
|
||||
}
|
||||
if (sudoers_warnings && fmt != NULL) {
|
||||
LEXTRACE("<*> ");
|
||||
@@ -1250,7 +1250,7 @@ new_default(char *var, char *val, short op)
|
||||
/* d->binding = NULL */
|
||||
d->line = this_lineno;
|
||||
d->column = sudolinebuf.toke_start + 1;
|
||||
d->file = rcstr_addref(sudoers);
|
||||
d->file = sudo_rcstr_addref(sudoers);
|
||||
HLTQ_INIT(d, entries);
|
||||
|
||||
debug_return_ptr(d);
|
||||
@@ -1382,7 +1382,7 @@ add_userspec(struct member *members, struct privilege *privs)
|
||||
}
|
||||
u->line = this_lineno;
|
||||
u->column = sudolinebuf.toke_start + 1;
|
||||
u->file = rcstr_addref(sudoers);
|
||||
u->file = sudo_rcstr_addref(sudoers);
|
||||
parser_leak_remove(LEAK_MEMBER, members);
|
||||
HLTQ_TO_TAILQ(&u->users, members, entries);
|
||||
parser_leak_remove(LEAK_PRIVILEGE, privs);
|
||||
@@ -1462,7 +1462,7 @@ free_default(struct defaults *def, struct member_list **binding)
|
||||
free(def->binding);
|
||||
}
|
||||
}
|
||||
rcstr_delref(def->file);
|
||||
sudo_rcstr_delref(def->file);
|
||||
free(def->var);
|
||||
free(def->val);
|
||||
free(def);
|
||||
@@ -1586,7 +1586,7 @@ free_userspec(struct userspec *us)
|
||||
free(comment->str);
|
||||
free(comment);
|
||||
}
|
||||
rcstr_delref(us->file);
|
||||
sudo_rcstr_delref(us->file);
|
||||
free(us);
|
||||
|
||||
debug_return;
|
||||
@@ -1644,9 +1644,9 @@ init_parser(const char *path, bool quiet, bool strict)
|
||||
parser_leak_init();
|
||||
init_lexer();
|
||||
|
||||
rcstr_delref(sudoers);
|
||||
sudo_rcstr_delref(sudoers);
|
||||
if (path != NULL) {
|
||||
if ((sudoers = rcstr_dup(path)) == NULL) {
|
||||
if ((sudoers = sudo_rcstr_dup(path)) == NULL) {
|
||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
||||
ret = false;
|
||||
}
|
||||
@@ -1656,7 +1656,7 @@ init_parser(const char *path, bool quiet, bool strict)
|
||||
|
||||
parse_error = false;
|
||||
errorlineno = -1;
|
||||
rcstr_delref(errorfile);
|
||||
sudo_rcstr_delref(errorfile);
|
||||
errorfile = NULL;
|
||||
sudoers_warnings = !quiet;
|
||||
sudoers_strict = strict;
|
||||
|
@@ -437,7 +437,7 @@ sudo_ldap_parse_options(LDAP *ld, LDAPMessage *entry, struct defaults_list *defs
|
||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
||||
goto done;
|
||||
}
|
||||
if ((source = rcstr_dup(cp)) == NULL) {
|
||||
if ((source = sudo_rcstr_dup(cp)) == NULL) {
|
||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
||||
free(cp);
|
||||
goto done;
|
||||
@@ -458,7 +458,7 @@ sudo_ldap_parse_options(LDAP *ld, LDAPMessage *entry, struct defaults_list *defs
|
||||
ret = true;
|
||||
|
||||
done:
|
||||
rcstr_delref(source);
|
||||
sudo_rcstr_delref(source);
|
||||
if (cn)
|
||||
ldap_memfree(cn);
|
||||
ldap_value_free_len(bv);
|
||||
@@ -1251,7 +1251,7 @@ ldap_to_sudoers(LDAP *ld, struct ldap_result *lres,
|
||||
/* We only have a single userspec */
|
||||
if ((us = calloc(1, sizeof(*us))) == NULL)
|
||||
goto oom;
|
||||
us->file = rcstr_dup("LDAP");
|
||||
us->file = sudo_rcstr_dup("LDAP");
|
||||
TAILQ_INIT(&us->users);
|
||||
TAILQ_INIT(&us->privileges);
|
||||
STAILQ_INIT(&us->comments);
|
||||
|
@@ -262,7 +262,7 @@ sudo_ldap_add_default(const char *var, const char *val, int op,
|
||||
goto oom;
|
||||
}
|
||||
def->file = source;
|
||||
rcstr_addref(source);
|
||||
sudo_rcstr_addref(source);
|
||||
TAILQ_INSERT_TAIL(defs, def, entries);
|
||||
debug_return_bool(true);
|
||||
|
||||
@@ -514,7 +514,7 @@ sudo_ldap_role_to_priv(const char *cn, void *hosts, void *runasusers,
|
||||
if (store_options) {
|
||||
/* Use sudoRole in place of file name in defaults. */
|
||||
size_t slen = sizeof("sudoRole") + strlen(priv->ldap_role);
|
||||
if ((source = rcstr_alloc(slen)) == NULL)
|
||||
if ((source = sudo_rcstr_alloc(slen)) == NULL)
|
||||
goto oom;
|
||||
(void)snprintf(source, slen, "sudoRole %s", priv->ldap_role);
|
||||
}
|
||||
@@ -604,7 +604,7 @@ sudo_ldap_role_to_priv(const char *cn, void *hosts, void *runasusers,
|
||||
}
|
||||
}
|
||||
}
|
||||
rcstr_delref(source);
|
||||
sudo_rcstr_delref(source);
|
||||
if (opt != NULL) {
|
||||
/* Defer oom until we drop the ref on source. */
|
||||
goto oom;
|
||||
|
@@ -363,7 +363,7 @@ sss_to_sudoers(struct sudo_sss_handle *handle,
|
||||
/* We only have a single userspec */
|
||||
if ((us = calloc(1, sizeof(*us))) == NULL)
|
||||
goto oom;
|
||||
us->file = rcstr_dup("SSSD");
|
||||
us->file = sudo_rcstr_dup("SSSD");
|
||||
TAILQ_INIT(&us->users);
|
||||
TAILQ_INIT(&us->privileges);
|
||||
STAILQ_INIT(&us->comments);
|
||||
@@ -441,7 +441,7 @@ sudo_sss_parse_options(struct sudo_sss_handle *handle, struct sss_sudo_rule *rul
|
||||
char *cp;
|
||||
if (asprintf(&cp, "sudoRole %s", cn_array[0]) == -1)
|
||||
goto oom;
|
||||
source = rcstr_dup(cp);
|
||||
source = sudo_rcstr_dup(cp);
|
||||
free(cp);
|
||||
if (source == NULL)
|
||||
goto oom;
|
||||
@@ -450,7 +450,7 @@ sudo_sss_parse_options(struct sudo_sss_handle *handle, struct sss_sudo_rule *rul
|
||||
cn_array = NULL;
|
||||
}
|
||||
if (source == NULL) {
|
||||
if ((source = rcstr_dup("sudoRole UNKNOWN")) == NULL)
|
||||
if ((source = sudo_rcstr_dup("sudoRole UNKNOWN")) == NULL)
|
||||
goto oom;
|
||||
}
|
||||
|
||||
@@ -470,7 +470,7 @@ oom:
|
||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
||||
|
||||
done:
|
||||
rcstr_delref(source);
|
||||
sudo_rcstr_delref(source);
|
||||
handle->fn_free_values(val_array);
|
||||
debug_return_bool(ret);
|
||||
}
|
||||
|
@@ -457,12 +457,6 @@ bool sudoers_gc_remove(enum sudoers_gc_types type, void *ptr);
|
||||
void sudoers_gc_init(void);
|
||||
void sudoers_gc_run(void);
|
||||
|
||||
/* rcstr.c */
|
||||
char *rcstr_dup(const char *src);
|
||||
char *rcstr_alloc(size_t len);
|
||||
char *rcstr_addref(const char *s);
|
||||
void rcstr_delref(const char *s);
|
||||
|
||||
/* strlcpy_unesc.c */
|
||||
size_t strlcpy_unescape(char *dst, const char *src, size_t size);
|
||||
|
||||
|
@@ -5084,16 +5084,16 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
|
||||
continue;
|
||||
}
|
||||
len = strlen(dirpath) + 1 + NAMLEN(dent);
|
||||
if ((path = rcstr_alloc(len)) == NULL)
|
||||
if ((path = sudo_rcstr_alloc(len)) == NULL)
|
||||
goto oom;
|
||||
(void)snprintf(path, len + 1, "%s/%s", dirpath, dent->d_name);
|
||||
if (stat(path, &sb) != 0 || !S_ISREG(sb.st_mode)) {
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
continue;
|
||||
}
|
||||
pl = malloc(sizeof(*pl));
|
||||
if (pl == NULL) {
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
goto oom;
|
||||
}
|
||||
pl->path = path;
|
||||
@@ -5102,7 +5102,7 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
|
||||
max_paths <<= 1;
|
||||
tmp = reallocarray(paths, max_paths, sizeof(*paths));
|
||||
if (tmp == NULL) {
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
free(pl);
|
||||
goto oom;
|
||||
}
|
||||
@@ -5125,7 +5125,7 @@ bad:
|
||||
if (dir != NULL)
|
||||
closedir(dir);
|
||||
for (i = 0; i < count; i++) {
|
||||
rcstr_delref(paths[i]->path);
|
||||
sudo_rcstr_delref(paths[i]->path);
|
||||
free(paths[i]);
|
||||
}
|
||||
free(paths);
|
||||
@@ -5180,10 +5180,10 @@ init_lexer(void)
|
||||
idepth--;
|
||||
while ((pl = SLIST_FIRST(&istack[idepth].more)) != NULL) {
|
||||
SLIST_REMOVE_HEAD(&istack[idepth].more, entries);
|
||||
rcstr_delref(pl->path);
|
||||
sudo_rcstr_delref(pl->path);
|
||||
free(pl);
|
||||
}
|
||||
rcstr_delref(istack[idepth].path);
|
||||
sudo_rcstr_delref(istack[idepth].path);
|
||||
if (idepth && !istack[idepth].keepopen)
|
||||
fclose(istack[idepth].bs->yy_input_file);
|
||||
sudoers_delete_buffer(istack[idepth].bs);
|
||||
@@ -5246,7 +5246,7 @@ expand_include(const char *opath)
|
||||
}
|
||||
|
||||
/* Make a copy of the fully-qualified path and return it. */
|
||||
path = pp = rcstr_alloc(len + dirlen);
|
||||
path = pp = sudo_rcstr_alloc(len + dirlen);
|
||||
if (path == NULL) {
|
||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
||||
sudoerserror(NULL);
|
||||
@@ -5302,7 +5302,7 @@ push_include(const char *opath, bool isdir)
|
||||
if (sudoers_warnings)
|
||||
sudo_warnx(U_("%s: %s"), path, U_("too many levels of includes"));
|
||||
sudoerserror(NULL);
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
debug_return_bool(false);
|
||||
}
|
||||
istacksize += SUDOERS_STACK_INCREMENT;
|
||||
@@ -5310,7 +5310,7 @@ push_include(const char *opath, bool isdir)
|
||||
if (new_istack == NULL) {
|
||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
||||
sudoerserror(NULL);
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
debug_return_bool(false);
|
||||
}
|
||||
istack = new_istack;
|
||||
@@ -5346,19 +5346,19 @@ push_include(const char *opath, bool isdir)
|
||||
}
|
||||
}
|
||||
/* A missing or insecure include dir is not a fatal error. */
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
debug_return_bool(true);
|
||||
}
|
||||
count = switch_dir(&istack[idepth], path);
|
||||
if (count <= 0) {
|
||||
/* switch_dir() called sudoerserror() for us */
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
debug_return_bool(count ? false : true);
|
||||
}
|
||||
|
||||
/* Parse the first dir entry we can open, leave the rest for later. */
|
||||
do {
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
if ((pl = SLIST_FIRST(&istack[idepth].more)) == NULL) {
|
||||
/* Unable to open any files in include dir, not an error. */
|
||||
debug_return_bool(true);
|
||||
@@ -5371,7 +5371,7 @@ push_include(const char *opath, bool isdir)
|
||||
if ((fp = open_sudoers(path, true, &keepopen)) == NULL) {
|
||||
/* The error was already printed by open_sudoers() */
|
||||
sudoerserror(NULL);
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
debug_return_bool(false);
|
||||
}
|
||||
}
|
||||
@@ -5415,7 +5415,7 @@ pop_include(void)
|
||||
if (fp != NULL) {
|
||||
sudolinebuf.len = sudolinebuf.off = 0;
|
||||
sudolinebuf.toke_start = sudolinebuf.toke_end = 0;
|
||||
rcstr_delref(sudoers);
|
||||
sudo_rcstr_delref(sudoers);
|
||||
sudoers = pl->path;
|
||||
sudolineno = 1;
|
||||
sudoers_switch_to_buffer(sudoers_create_buffer(fp, YY_BUF_SIZE));
|
||||
@@ -5423,7 +5423,7 @@ pop_include(void)
|
||||
break;
|
||||
}
|
||||
/* Unable to open path in include dir, go to next one. */
|
||||
rcstr_delref(pl->path);
|
||||
sudo_rcstr_delref(pl->path);
|
||||
free(pl);
|
||||
}
|
||||
/* If no path list, just pop the last dir on the stack. */
|
||||
@@ -5432,7 +5432,7 @@ pop_include(void)
|
||||
sudoers_switch_to_buffer(istack[idepth].bs);
|
||||
free(sudolinebuf.buf);
|
||||
sudolinebuf = istack[idepth].line;
|
||||
rcstr_delref(sudoers);
|
||||
sudo_rcstr_delref(sudoers);
|
||||
sudoers = istack[idepth].path;
|
||||
sudolineno = istack[idepth].lineno;
|
||||
keepopen = istack[idepth].keepopen;
|
||||
|
@@ -889,16 +889,16 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
|
||||
continue;
|
||||
}
|
||||
len = strlen(dirpath) + 1 + NAMLEN(dent);
|
||||
if ((path = rcstr_alloc(len)) == NULL)
|
||||
if ((path = sudo_rcstr_alloc(len)) == NULL)
|
||||
goto oom;
|
||||
(void)snprintf(path, len + 1, "%s/%s", dirpath, dent->d_name);
|
||||
if (stat(path, &sb) != 0 || !S_ISREG(sb.st_mode)) {
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
continue;
|
||||
}
|
||||
pl = malloc(sizeof(*pl));
|
||||
if (pl == NULL) {
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
goto oom;
|
||||
}
|
||||
pl->path = path;
|
||||
@@ -907,7 +907,7 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
|
||||
max_paths <<= 1;
|
||||
tmp = reallocarray(paths, max_paths, sizeof(*paths));
|
||||
if (tmp == NULL) {
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
free(pl);
|
||||
goto oom;
|
||||
}
|
||||
@@ -930,7 +930,7 @@ bad:
|
||||
if (dir != NULL)
|
||||
closedir(dir);
|
||||
for (i = 0; i < count; i++) {
|
||||
rcstr_delref(paths[i]->path);
|
||||
sudo_rcstr_delref(paths[i]->path);
|
||||
free(paths[i]);
|
||||
}
|
||||
free(paths);
|
||||
@@ -985,10 +985,10 @@ init_lexer(void)
|
||||
idepth--;
|
||||
while ((pl = SLIST_FIRST(&istack[idepth].more)) != NULL) {
|
||||
SLIST_REMOVE_HEAD(&istack[idepth].more, entries);
|
||||
rcstr_delref(pl->path);
|
||||
sudo_rcstr_delref(pl->path);
|
||||
free(pl);
|
||||
}
|
||||
rcstr_delref(istack[idepth].path);
|
||||
sudo_rcstr_delref(istack[idepth].path);
|
||||
if (idepth && !istack[idepth].keepopen)
|
||||
fclose(istack[idepth].bs->yy_input_file);
|
||||
sudoers_delete_buffer(istack[idepth].bs);
|
||||
@@ -1051,7 +1051,7 @@ expand_include(const char *opath)
|
||||
}
|
||||
|
||||
/* Make a copy of the fully-qualified path and return it. */
|
||||
path = pp = rcstr_alloc(len + dirlen);
|
||||
path = pp = sudo_rcstr_alloc(len + dirlen);
|
||||
if (path == NULL) {
|
||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
||||
sudoerserror(NULL);
|
||||
@@ -1107,7 +1107,7 @@ push_include(const char *opath, bool isdir)
|
||||
if (sudoers_warnings)
|
||||
sudo_warnx(U_("%s: %s"), path, U_("too many levels of includes"));
|
||||
sudoerserror(NULL);
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
debug_return_bool(false);
|
||||
}
|
||||
istacksize += SUDOERS_STACK_INCREMENT;
|
||||
@@ -1115,7 +1115,7 @@ push_include(const char *opath, bool isdir)
|
||||
if (new_istack == NULL) {
|
||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
||||
sudoerserror(NULL);
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
debug_return_bool(false);
|
||||
}
|
||||
istack = new_istack;
|
||||
@@ -1151,19 +1151,19 @@ push_include(const char *opath, bool isdir)
|
||||
}
|
||||
}
|
||||
/* A missing or insecure include dir is not a fatal error. */
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
debug_return_bool(true);
|
||||
}
|
||||
count = switch_dir(&istack[idepth], path);
|
||||
if (count <= 0) {
|
||||
/* switch_dir() called sudoerserror() for us */
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
debug_return_bool(count ? false : true);
|
||||
}
|
||||
|
||||
/* Parse the first dir entry we can open, leave the rest for later. */
|
||||
do {
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
if ((pl = SLIST_FIRST(&istack[idepth].more)) == NULL) {
|
||||
/* Unable to open any files in include dir, not an error. */
|
||||
debug_return_bool(true);
|
||||
@@ -1176,7 +1176,7 @@ push_include(const char *opath, bool isdir)
|
||||
if ((fp = open_sudoers(path, true, &keepopen)) == NULL) {
|
||||
/* The error was already printed by open_sudoers() */
|
||||
sudoerserror(NULL);
|
||||
rcstr_delref(path);
|
||||
sudo_rcstr_delref(path);
|
||||
debug_return_bool(false);
|
||||
}
|
||||
}
|
||||
@@ -1220,7 +1220,7 @@ pop_include(void)
|
||||
if (fp != NULL) {
|
||||
sudolinebuf.len = sudolinebuf.off = 0;
|
||||
sudolinebuf.toke_start = sudolinebuf.toke_end = 0;
|
||||
rcstr_delref(sudoers);
|
||||
sudo_rcstr_delref(sudoers);
|
||||
sudoers = pl->path;
|
||||
sudolineno = 1;
|
||||
sudoers_switch_to_buffer(sudoers_create_buffer(fp, YY_BUF_SIZE));
|
||||
@@ -1228,7 +1228,7 @@ pop_include(void)
|
||||
break;
|
||||
}
|
||||
/* Unable to open path in include dir, go to next one. */
|
||||
rcstr_delref(pl->path);
|
||||
sudo_rcstr_delref(pl->path);
|
||||
free(pl);
|
||||
}
|
||||
/* If no path list, just pop the last dir on the stack. */
|
||||
@@ -1237,7 +1237,7 @@ pop_include(void)
|
||||
sudoers_switch_to_buffer(istack[idepth].bs);
|
||||
free(sudolinebuf.buf);
|
||||
sudolinebuf = istack[idepth].line;
|
||||
rcstr_delref(sudoers);
|
||||
sudo_rcstr_delref(sudoers);
|
||||
sudoers = istack[idepth].path;
|
||||
sudolineno = istack[idepth].lineno;
|
||||
keepopen = istack[idepth].keepopen;
|
||||
|
@@ -550,14 +550,14 @@ check_defaults_and_aliases(bool strict, bool quiet)
|
||||
|
||||
if (!check_defaults(&parsed_policy, quiet)) {
|
||||
struct defaults *d;
|
||||
rcstr_delref(errorfile);
|
||||
sudo_rcstr_delref(errorfile);
|
||||
errorfile = NULL;
|
||||
errorlineno = -1;
|
||||
/* XXX - should edit all files with errors */
|
||||
TAILQ_FOREACH(d, &parsed_policy.defaults, entries) {
|
||||
if (d->error) {
|
||||
/* Defaults parse error, set errorfile/errorlineno. */
|
||||
errorfile = rcstr_addref(d->file);
|
||||
errorfile = sudo_rcstr_addref(d->file);
|
||||
errorlineno = d->line;
|
||||
break;
|
||||
}
|
||||
@@ -604,8 +604,8 @@ reparse_sudoers(char *editor, int editor_argc, char **editor_argv,
|
||||
sudo_warnx(U_("unable to parse temporary file (%s), unknown error"),
|
||||
sp->tpath);
|
||||
parse_error = true;
|
||||
rcstr_delref(errorfile);
|
||||
if ((errorfile = rcstr_dup(sp->path)) == NULL)
|
||||
sudo_rcstr_delref(errorfile);
|
||||
if ((errorfile = sudo_rcstr_dup(sp->path)) == NULL)
|
||||
sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
||||
}
|
||||
fclose(sudoersin);
|
||||
@@ -921,8 +921,8 @@ check_syntax(const char *file, bool quiet, bool strict, bool oldperms)
|
||||
if (!quiet)
|
||||
sudo_warnx(U_("failed to parse %s file, unknown error"), file);
|
||||
parse_error = true;
|
||||
rcstr_delref(errorfile);
|
||||
if ((errorfile = rcstr_dup(file)) == NULL)
|
||||
sudo_rcstr_delref(errorfile);
|
||||
if ((errorfile = sudo_rcstr_dup(file)) == NULL)
|
||||
sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
||||
}
|
||||
if (!parse_error) {
|
||||
|
Reference in New Issue
Block a user