Rename fmt_string -> sudo_new_key_val to better describe its function.
This commit is contained in:
2
MANIFEST
2
MANIFEST
@@ -94,7 +94,6 @@ lib/util/event_poll.c
|
||||
lib/util/event_select.c
|
||||
lib/util/fatal.c
|
||||
lib/util/fileops.c
|
||||
lib/util/fmt_string.c
|
||||
lib/util/fnmatch.c
|
||||
lib/util/getaddrinfo.c
|
||||
lib/util/getcwd.c
|
||||
@@ -105,6 +104,7 @@ lib/util/gidlist.c
|
||||
lib/util/glob.c
|
||||
lib/util/inet_pton.c
|
||||
lib/util/isblank.c
|
||||
lib/util/key_val.c
|
||||
lib/util/lbuf.c
|
||||
lib/util/memrchr.c
|
||||
lib/util/memset_s.c
|
||||
|
@@ -150,8 +150,8 @@ __dso_public id_t atoid(const char *str, const char *sep, char **endp, const cha
|
||||
/* atomode.c */
|
||||
__dso_public int atomode(const char *cp, const char **errstr);
|
||||
|
||||
/* fmt_string.h */
|
||||
__dso_public char *fmt_string(const char *var, const char *value);
|
||||
/* key_val.c */
|
||||
__dso_public char *sudo_new_key_val(const char *key, const char *value);
|
||||
|
||||
/* gidlist.c */
|
||||
__dso_public int parse_gid_list(const char *gidstr, const gid_t *basegid, GETGROUPS_T **gidsp);
|
||||
|
@@ -96,7 +96,7 @@ DEVEL = @DEVEL@
|
||||
SHELL = @SHELL@
|
||||
|
||||
LTOBJS = alloc.lo atobool.lo atoid.lo atomode.lo event.lo fatal.lo fileops.lo \
|
||||
fmt_string.lo gidlist.lo lbuf.lo progname.lo secure_path.lo \
|
||||
key_val.lo gidlist.lo lbuf.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@
|
||||
|
||||
@@ -334,14 +334,9 @@ fatal.lo: $(srcdir)/fatal.c $(incdir)/alloc.h $(incdir)/compat/stdbool.h \
|
||||
$(incdir)/fatal.h $(incdir)/gettext.h $(incdir)/missing.h \
|
||||
$(incdir)/queue.h $(incdir)/sudo_plugin.h $(top_builddir)/config.h
|
||||
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/fatal.c
|
||||
fileops.lo: $(srcdir)/fileops.c $(incdir)/compat/stdbool.h \
|
||||
$(incdir)/compat/timespec.h $(incdir)/fileops.h \
|
||||
fileops.lo: $(srcdir)/fileops.c $(incdir)/compat/stdbool.h $(incdir)/fileops.h \
|
||||
$(incdir)/missing.h $(incdir)/sudo_debug.h $(top_builddir)/config.h
|
||||
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/fileops.c
|
||||
fmt_string.lo: $(srcdir)/fmt_string.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)/fmt_string.c
|
||||
fnm_test.lo: $(srcdir)/regress/fnmatch/fnm_test.c $(incdir)/compat/fnmatch.h \
|
||||
$(incdir)/missing.h $(top_builddir)/config.h
|
||||
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/regress/fnmatch/fnm_test.c
|
||||
@@ -382,6 +377,10 @@ hltq_test.lo: $(srcdir)/regress/tailq/hltq_test.c $(incdir)/compat/stdbool.h \
|
||||
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/regress/tailq/hltq_test.c
|
||||
isblank.lo: $(srcdir)/isblank.c $(incdir)/missing.h $(top_builddir)/config.h
|
||||
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/isblank.c
|
||||
key_val.lo: $(srcdir)/key_val.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)/key_val.c
|
||||
lbuf.lo: $(srcdir)/lbuf.c $(incdir)/alloc.h $(incdir)/fatal.h $(incdir)/lbuf.h \
|
||||
$(incdir)/missing.h $(incdir)/sudo_debug.h $(top_builddir)/config.h
|
||||
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/lbuf.c
|
||||
|
@@ -42,20 +42,21 @@
|
||||
#include "sudo_util.h"
|
||||
|
||||
/*
|
||||
* Allocate storage for a name=value string and return it.
|
||||
* Create a new key=value pair and return it.
|
||||
* The caller is responsible for freeing the string.
|
||||
*/
|
||||
char *
|
||||
fmt_string(const char *var, const char *val)
|
||||
sudo_new_key_val(const char *key, const char *val)
|
||||
{
|
||||
size_t var_len = strlen(var);
|
||||
size_t key_len = strlen(key);
|
||||
size_t val_len = strlen(val);
|
||||
char *cp, *str;
|
||||
debug_decl(fmt_string, SUDO_DEBUG_UTIL)
|
||||
debug_decl(sudo_new_key_val, SUDO_DEBUG_UTIL)
|
||||
|
||||
cp = str = malloc(var_len + 1 + val_len + 1);
|
||||
if (str != NULL) {
|
||||
memcpy(cp, var, var_len);
|
||||
cp += var_len;
|
||||
cp = str = malloc(key_len + 1 + val_len + 1);
|
||||
if (str != NULL) {
|
||||
memcpy(cp, key, key_len);
|
||||
cp += key_len;
|
||||
*cp++ = '=';
|
||||
memcpy(cp, val, val_len);
|
||||
cp += val_len;
|
@@ -40,7 +40,6 @@ fatal_callback_deregister
|
||||
fatal_callback_register
|
||||
fatal_nodebug
|
||||
fatalx_nodebug
|
||||
fmt_string
|
||||
get_ttysize
|
||||
getprogname
|
||||
initprogname
|
||||
@@ -120,6 +119,7 @@ sudo_memrchr
|
||||
sudo_memset_s
|
||||
sudo_mkdtemp
|
||||
sudo_mkstemps
|
||||
sudo_new_key_val
|
||||
sudo_parseln
|
||||
sudo_printf
|
||||
sudo_pw_dup
|
||||
|
@@ -82,29 +82,6 @@ static uid_t runas_uid = ROOT_UID;
|
||||
static gid_t runas_gid = -1;
|
||||
static int use_sudoedit = false;
|
||||
|
||||
/*
|
||||
* Allocate storage for a name=value string and return it.
|
||||
*/
|
||||
static char *
|
||||
fmt_string(const char *var, const char *val)
|
||||
{
|
||||
size_t var_len = strlen(var);
|
||||
size_t val_len = strlen(val);
|
||||
char *cp, *str;
|
||||
|
||||
cp = str = malloc(var_len + 1 + val_len + 1);
|
||||
if (str != NULL) {
|
||||
memcpy(cp, var, var_len);
|
||||
cp += var_len;
|
||||
*cp++ = '=';
|
||||
memcpy(cp, val, val_len);
|
||||
cp += val_len;
|
||||
*cp = '\0';
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Plugin policy open function.
|
||||
*/
|
||||
@@ -244,7 +221,7 @@ build_command_info(const char *command)
|
||||
command_info = calloc(32, sizeof(char *));
|
||||
if (command_info == NULL)
|
||||
return NULL;
|
||||
if ((command_info[i++] = fmt_string("command", command)) == NULL ||
|
||||
if ((command_info[i++] = sudo_new_key_val("command", command)) == NULL ||
|
||||
asprintf(&command_info[i++], "runas_euid=%ld", (long)runas_uid) == -1 ||
|
||||
asprintf(&command_info[i++], "runas_uid=%ld", (long)runas_uid) == -1) {
|
||||
return NULL;
|
||||
|
@@ -401,7 +401,7 @@ sudoers_policy_exec_setup(char *argv[], char *envp[], mode_t cmnd_umask,
|
||||
/* Increase the length of command_info as needed, it is *not* checked. */
|
||||
command_info = ecalloc(32, sizeof(char **));
|
||||
|
||||
command_info[info_len++] = fmt_string("command", safe_cmnd);
|
||||
command_info[info_len++] = sudo_new_key_val("command", safe_cmnd);
|
||||
if (def_log_input || def_log_output) {
|
||||
if (iolog_path)
|
||||
command_info[info_len++] = iolog_path;
|
||||
@@ -425,7 +425,7 @@ sudoers_policy_exec_setup(char *argv[], char *envp[], mode_t cmnd_umask,
|
||||
command_info[info_len++] = estrdup("sudoedit=true");
|
||||
if (ISSET(sudo_mode, MODE_LOGIN_SHELL)) {
|
||||
/* Set cwd to run user's homedir. */
|
||||
command_info[info_len++] = fmt_string("cwd", runas_pw->pw_dir);
|
||||
command_info[info_len++] = sudo_new_key_val("cwd", runas_pw->pw_dir);
|
||||
}
|
||||
if (def_stay_setuid) {
|
||||
easprintf(&command_info[info_len++], "runas_uid=%u",
|
||||
@@ -494,24 +494,24 @@ sudoers_policy_exec_setup(char *argv[], char *envp[], mode_t cmnd_umask,
|
||||
if (def_use_pty)
|
||||
command_info[info_len++] = estrdup("use_pty=true");
|
||||
if (def_utmp_runas)
|
||||
command_info[info_len++] = fmt_string("utmp_user", runas_pw->pw_name);
|
||||
command_info[info_len++] = sudo_new_key_val("utmp_user", runas_pw->pw_name);
|
||||
if (cmnd_umask != 0777)
|
||||
easprintf(&command_info[info_len++], "umask=0%o", (unsigned int)cmnd_umask);
|
||||
#ifdef HAVE_LOGIN_CAP_H
|
||||
if (def_use_loginclass)
|
||||
command_info[info_len++] = fmt_string("login_class", login_class);
|
||||
command_info[info_len++] = sudo_new_key_val("login_class", login_class);
|
||||
#endif /* HAVE_LOGIN_CAP_H */
|
||||
#ifdef HAVE_SELINUX
|
||||
if (user_role != NULL)
|
||||
command_info[info_len++] = fmt_string("selinux_role", user_role);
|
||||
command_info[info_len++] = sudo_new_key_val("selinux_role", user_role);
|
||||
if (user_type != NULL)
|
||||
command_info[info_len++] = fmt_string("selinux_type", user_type);
|
||||
command_info[info_len++] = sudo_new_key_val("selinux_type", user_type);
|
||||
#endif /* HAVE_SELINUX */
|
||||
#ifdef HAVE_PRIV_SET
|
||||
if (runas_privs != NULL)
|
||||
command_info[info_len++] = fmt_string("runas_privs", runas_privs);
|
||||
command_info[info_len++] = sudo_new_key_val("runas_privs", runas_privs);
|
||||
if (runas_limitprivs != NULL)
|
||||
command_info[info_len++] = fmt_string("runas_limitprivs", runas_limitprivs);
|
||||
command_info[info_len++] = sudo_new_key_val("runas_limitprivs", runas_limitprivs);
|
||||
#endif /* HAVE_SELINUX */
|
||||
|
||||
/* Fill in exec environment info */
|
||||
|
@@ -297,8 +297,8 @@ parse_args.o: $(srcdir)/parse_args.c $(incdir)/alloc.h \
|
||||
$(incdir)/sudo_util.h $(srcdir)/sudo.h $(top_builddir)/config.h \
|
||||
$(top_builddir)/pathnames.h ./sudo_usage.h
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/parse_args.c
|
||||
preload.o: $(srcdir)/preload.c $(incdir)/sudo_dso.h $(incdir)/sudo_plugin.h \
|
||||
$(top_builddir)/config.h
|
||||
preload.o: $(srcdir)/preload.c $(incdir)/missing.h $(incdir)/sudo_dso.h \
|
||||
$(incdir)/sudo_plugin.h $(top_builddir)/config.h
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/preload.c
|
||||
preserve_fds.o: $(srcdir)/preserve_fds.c $(incdir)/alloc.h \
|
||||
$(incdir)/compat/stdbool.h $(incdir)/fatal.h \
|
||||
|
@@ -109,7 +109,7 @@ disable_execute(char *const envp[])
|
||||
# ifdef RTLD_PRELOAD_DEFAULT
|
||||
easprintf(&preload, "%s=%s%s%s", RTLD_PRELOAD_VAR, sudo_conf_noexec_path(), RTLD_PRELOAD_DELIM, RTLD_PRELOAD_DEFAULT);
|
||||
# else
|
||||
preload = fmt_string(RTLD_PRELOAD_VAR, sudo_conf_noexec_path());
|
||||
preload = sudo_new_key_val(RTLD_PRELOAD_VAR, sudo_conf_noexec_path());
|
||||
# endif
|
||||
if (preload == NULL)
|
||||
fatal(NULL);
|
||||
|
@@ -501,7 +501,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
|
||||
if (sudo_settings[i].value) {
|
||||
sudo_debug_printf(SUDO_DEBUG_INFO, "settings: %s=%s",
|
||||
sudo_settings[i].name, sudo_settings[i].value);
|
||||
settings[j] = fmt_string(sudo_settings[i].name,
|
||||
settings[j] = sudo_new_key_val(sudo_settings[i].name,
|
||||
sudo_settings[i].value);
|
||||
if (settings[j] == NULL)
|
||||
fatal(NULL);
|
||||
|
@@ -464,7 +464,7 @@ get_user_info(struct user_details *ud)
|
||||
if (pw == NULL)
|
||||
fatalx(U_("unknown uid %u: who are you?"), (unsigned int)ud->uid);
|
||||
|
||||
user_info[i] = fmt_string("user", pw->pw_name);
|
||||
user_info[i] = sudo_new_key_val("user", pw->pw_name);
|
||||
if (user_info[i] == NULL)
|
||||
fatal(NULL);
|
||||
ud->username = user_info[i] + sizeof("user=") - 1;
|
||||
@@ -490,14 +490,14 @@ get_user_info(struct user_details *ud)
|
||||
user_info[++i] = cp;
|
||||
|
||||
if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
||||
user_info[++i] = fmt_string("cwd", cwd);
|
||||
user_info[++i] = sudo_new_key_val("cwd", cwd);
|
||||
if (user_info[i] == NULL)
|
||||
fatal(NULL);
|
||||
ud->cwd = user_info[i] + sizeof("cwd=") - 1;
|
||||
}
|
||||
|
||||
if ((cp = get_process_ttyname()) != NULL) {
|
||||
user_info[++i] = fmt_string("tty", cp);
|
||||
user_info[++i] = sudo_new_key_val("tty", cp);
|
||||
if (user_info[i] == NULL)
|
||||
fatal(NULL);
|
||||
ud->tty = user_info[i] + sizeof("tty=") - 1;
|
||||
@@ -508,7 +508,7 @@ get_user_info(struct user_details *ud)
|
||||
host[sizeof(host) - 1] = '\0';
|
||||
else
|
||||
strlcpy(host, "localhost", sizeof(host));
|
||||
user_info[++i] = fmt_string("host", host);
|
||||
user_info[++i] = sudo_new_key_val("host", host);
|
||||
if (user_info[i] == NULL)
|
||||
fatal(NULL);
|
||||
ud->host = user_info[i] + sizeof("host=") - 1;
|
||||
|
Reference in New Issue
Block a user