]> granicus.if.org Git - sudo/commitdiff
Move common stub functions required by the parser out of visudo.c
authorTodd C. Miller <Todd.Miller@sudo.ws>
Fri, 26 Jan 2018 19:51:24 +0000 (12:51 -0700)
committerTodd C. Miller <Todd.Miller@sudo.ws>
Fri, 26 Jan 2018 19:51:24 +0000 (12:51 -0700)
and cvtsudoers.c and into stubs.c.

MANIFEST
plugins/sudoers/Makefile.in
plugins/sudoers/cvtsudoers.c
plugins/sudoers/stubs.c [new file with mode: 0644]
plugins/sudoers/visudo.c

index 0ae165140da76f67fee65414c88561965ceaf2bf..12c77fe8cec54c24008f6525dbee5f7d395f2dc5 100644 (file)
--- 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
index 922b3abb2bd8a5fdad706472b8aea83dd51b2877..76d5f30615a10c6ccb62b873b766f3ceb605d4b7 100644 (file)
@@ -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 \
index 0a6f19c3065aeccd53e7c801857347357f553318..4619306c5ecd79d0354b9b34a179a0b4e7f2cafc 100644 (file)
@@ -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 (file)
index 0000000..bc1c6ea
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2018 Todd C. Miller <Todd.Miller@sudo.ws>
+ *
+ * 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 <config.h>
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif /* HAVE_STRING_H */
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#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;
+}
index f4a3521386afe7b3181cd078a493b36ad5e3e68a..000e3d76f67438b80fcdfd7965b5fac5af958fae 100644 (file)
@@ -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)
 {