From: Todd C. Miller Date: Fri, 26 Jan 2018 19:51:24 +0000 (-0700) Subject: Move common stub functions required by the parser out of visudo.c X-Git-Tag: SUDO_1_8_23^2~182 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0f3030d5020f9bf843237b2e6b6601de648ad253;p=sudo Move common stub functions required by the parser out of visudo.c and cvtsudoers.c and into stubs.c. --- diff --git a/MANIFEST b/MANIFEST index 0ae165140..12c77fe8c 100644 --- a/MANIFEST +++ b/MANIFEST @@ -527,6 +527,7 @@ plugins/sudoers/solaris_audit.c plugins/sudoers/solaris_audit.h plugins/sudoers/sssd.c plugins/sudoers/starttime.c +plugins/sudoers/stubs.c plugins/sudoers/sudo_nss.c plugins/sudoers/sudo_nss.h plugins/sudoers/sudo_printf.c diff --git a/plugins/sudoers/Makefile.in b/plugins/sudoers/Makefile.in index 922b3abb2..76d5f3061 100644 --- a/plugins/sudoers/Makefile.in +++ b/plugins/sudoers/Makefile.in @@ -159,9 +159,9 @@ SUDOERS_OBJS = $(AUTH_OBJS) boottime.lo check.lo editor.lo env.lo \ set_perms.lo starttime.lo sudo_nss.lo sudoers.lo \ timestamp.lo @SUDOERS_OBJS@ -VISUDO_OBJS = editor.o find_path.o goodpath.o locale.o sudo_printf.o visudo.o +VISUDO_OBJS = editor.o find_path.o goodpath.o locale.o stubs.o sudo_printf.o visudo.o -CVTSUDOERS_OBJS = cvtsudoers.o cvtsudoers_json.o locale.o sudo_printf.o +CVTSUDOERS_OBJS = cvtsudoers.o cvtsudoers_json.o locale.o stubs.o sudo_printf.o REPLAY_OBJS = getdate.o sudoreplay.o @@ -1166,6 +1166,14 @@ starttime.lo: $(srcdir)/starttime.c $(devdir)/def_data.h \ $(top_builddir)/pathnames.h $(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/starttime.c starttime.o: starttime.lo +stubs.o: $(srcdir)/stubs.c $(devdir)/def_data.h $(incdir)/compat/stdbool.h \ + $(incdir)/sudo_compat.h $(incdir)/sudo_conf.h $(incdir)/sudo_debug.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)/interfaces.h $(srcdir)/logging.h \ + $(srcdir)/sudo_nss.h $(srcdir)/sudoers.h $(srcdir)/sudoers_debug.h \ + $(top_builddir)/config.h $(top_builddir)/pathnames.h + $(CC) -c $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/stubs.c sudo_auth.lo: $(authdir)/sudo_auth.c $(devdir)/def_data.h \ $(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \ $(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \ diff --git a/plugins/sudoers/cvtsudoers.c b/plugins/sudoers/cvtsudoers.c index 0a6f19c30..4619306c5 100644 --- a/plugins/sudoers/cvtsudoers.c +++ b/plugins/sudoers/cvtsudoers.c @@ -50,6 +50,7 @@ #endif /* HAVE_GETOPT_LONG */ extern bool convert_sudoers_json(const char *, const char *); +extern void get_hostname(void); /* * Globals @@ -69,7 +70,6 @@ static struct option long_opts[] = { }; __dso_public int main(int argc, char *argv[]); -static void get_hostname(void); static void help(void) __attribute__((__noreturn__)); static void usage(int); @@ -187,77 +187,6 @@ open_sudoers(const char *sudoers, bool doedit, bool *keepopen) return fopen(sudoers, "r"); } -/* XXX - Common stubs belong in their own file */ - -/* STUB */ -bool -init_envtables(void) -{ - return true; -} - -/* STUB */ -bool -user_is_exempt(void) -{ - return false; -} - -/* STUB */ -void -sudo_setspent(void) -{ - return; -} - -/* STUB */ -void -sudo_endspent(void) -{ - return; -} - -/* STUB */ -int -group_plugin_query(const char *user, const char *group, const struct passwd *pw) -{ - return false; -} - -/* STUB */ -struct interface_list * -get_interfaces(void) -{ - static struct interface_list dummy = SLIST_HEAD_INITIALIZER(interfaces); - return &dummy; -} - -/* - * Look up the hostname and set user_host and user_shost. - */ -static void -get_hostname(void) -{ - char *p; - debug_decl(get_hostname, SUDOERS_DEBUG_UTIL) - - if ((user_host = sudo_gethostname()) != NULL) { - if ((p = strchr(user_host, '.'))) { - *p = '\0'; - if ((user_shost = strdup(user_host)) == NULL) - sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory")); - *p = '.'; - } else { - user_shost = user_host; - } - } else { - user_host = user_shost = "localhost"; - } - user_runhost = user_host; - user_srunhost = user_shost; - debug_return; -} - static void usage(int fatal) { diff --git a/plugins/sudoers/stubs.c b/plugins/sudoers/stubs.c new file mode 100644 index 000000000..bc1c6eacc --- /dev/null +++ b/plugins/sudoers/stubs.c @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2018 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * Stub versions of functions needed by the parser. + * Required to link cvtsudoers and visudo. + */ + +#include + +#include +#include +#include +#ifdef HAVE_STRING_H +# include +#endif /* HAVE_STRING_H */ +#ifdef HAVE_STRINGS_H +# include +#endif /* HAVE_STRINGS_H */ + +#include +#include + +#include "sudoers.h" +#include "interfaces.h" + +/* STUB */ +bool +init_envtables(void) +{ + return true; +} + +/* STUB */ +bool +user_is_exempt(void) +{ + return false; +} + +/* STUB */ +void +sudo_setspent(void) +{ + return; +} + +/* STUB */ +void +sudo_endspent(void) +{ + return; +} + +/* STUB */ +int +group_plugin_query(const char *user, const char *group, const struct passwd *pw) +{ + return false; +} + +/* STUB */ +struct interface_list * +get_interfaces(void) +{ + static struct interface_list dummy = SLIST_HEAD_INITIALIZER(interfaces); + return &dummy; +} + +/* + * Look up the hostname and set user_host and user_shost. + */ +void +get_hostname(void) +{ + char *cp; + debug_decl(get_hostname, SUDOERS_DEBUG_UTIL) + + if ((user_host = sudo_gethostname()) != NULL) { + if ((cp = strchr(user_host, '.'))) { + *cp = '\0'; + if ((user_shost = strdup(user_host)) == NULL) + sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory")); + *cp = '.'; + } else { + user_shost = user_host; + } + } else { + user_host = user_shost = strdup("localhost"); + if (user_host == NULL) + sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory")); + } + user_runhost = user_host; + user_srunhost = user_shost; + + debug_return; +} diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index f4a352138..000e3d76f 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -85,7 +85,6 @@ TAILQ_HEAD(sudoersfile_list, sudoersfile); * Function prototypes */ static void quit(int); -static void get_hostname(void); static int whatnow(void); static int check_aliases(bool strict, bool quiet); static char *get_editor(int *editor_argc, char ***editor_argv); @@ -101,6 +100,7 @@ static void help(void) __attribute__((__noreturn__)); static void usage(int); static void visudo_cleanup(void); +extern void get_hostname(void); extern void sudoersrestart(FILE *); /* @@ -767,49 +767,6 @@ done: debug_return_bool(ret); } -/* STUB */ -bool -init_envtables(void) -{ - return true; -} - -/* STUB */ -bool -user_is_exempt(void) -{ - return false; -} - -/* STUB */ -void -sudo_setspent(void) -{ - return; -} - -/* STUB */ -void -sudo_endspent(void) -{ - return; -} - -/* STUB */ -int -group_plugin_query(const char *user, const char *group, const struct passwd *pw) -{ - return false; -} - -/* STUB */ -struct interface_list * -get_interfaces(void) -{ - static struct interface_list dummy = SLIST_HEAD_INITIALIZER(interfaces); - return &dummy; -} - /* * Assuming a parse error occurred, prompt the user for what they want * to do now. Returns the first letter of their choice. @@ -1048,32 +1005,6 @@ open_sudoers(const char *path, bool doedit, bool *keepopen) debug_return_ptr(fp); } -/* - * Look up the hostname and set user_host and user_shost. - */ -static void -get_hostname(void) -{ - char *p; - debug_decl(get_hostname, SUDOERS_DEBUG_UTIL) - - if ((user_host = sudo_gethostname()) != NULL) { - if ((p = strchr(user_host, '.'))) { - *p = '\0'; - if ((user_shost = strdup(user_host)) == NULL) - sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory")); - *p = '.'; - } else { - user_shost = user_host; - } - } else { - user_host = user_shost = "localhost"; - } - user_runhost = user_host; - user_srunhost = user_shost; - debug_return; -} - static bool alias_remove_recursive(char *name, int type) {