mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-22 01:49:11 +00:00
Move common stub functions required by the parser out of visudo.c
and cvtsudoers.c and into stubs.c.
This commit is contained in:
parent
02d917e602
commit
0f3030d502
1
MANIFEST
1
MANIFEST
@ -527,6 +527,7 @@ plugins/sudoers/solaris_audit.c
|
|||||||
plugins/sudoers/solaris_audit.h
|
plugins/sudoers/solaris_audit.h
|
||||||
plugins/sudoers/sssd.c
|
plugins/sudoers/sssd.c
|
||||||
plugins/sudoers/starttime.c
|
plugins/sudoers/starttime.c
|
||||||
|
plugins/sudoers/stubs.c
|
||||||
plugins/sudoers/sudo_nss.c
|
plugins/sudoers/sudo_nss.c
|
||||||
plugins/sudoers/sudo_nss.h
|
plugins/sudoers/sudo_nss.h
|
||||||
plugins/sudoers/sudo_printf.c
|
plugins/sudoers/sudo_printf.c
|
||||||
|
@ -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 \
|
set_perms.lo starttime.lo sudo_nss.lo sudoers.lo \
|
||||||
timestamp.lo @SUDOERS_OBJS@
|
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
|
REPLAY_OBJS = getdate.o sudoreplay.o
|
||||||
|
|
||||||
@ -1166,6 +1166,14 @@ starttime.lo: $(srcdir)/starttime.c $(devdir)/def_data.h \
|
|||||||
$(top_builddir)/pathnames.h
|
$(top_builddir)/pathnames.h
|
||||||
$(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/starttime.c
|
$(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/starttime.c
|
||||||
starttime.o: starttime.lo
|
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 \
|
sudo_auth.lo: $(authdir)/sudo_auth.c $(devdir)/def_data.h \
|
||||||
$(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
|
$(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
|
||||||
$(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
|
$(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
#endif /* HAVE_GETOPT_LONG */
|
#endif /* HAVE_GETOPT_LONG */
|
||||||
|
|
||||||
extern bool convert_sudoers_json(const char *, const char *);
|
extern bool convert_sudoers_json(const char *, const char *);
|
||||||
|
extern void get_hostname(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Globals
|
* Globals
|
||||||
@ -69,7 +70,6 @@ static struct option long_opts[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
__dso_public int main(int argc, char *argv[]);
|
__dso_public int main(int argc, char *argv[]);
|
||||||
static void get_hostname(void);
|
|
||||||
static void help(void) __attribute__((__noreturn__));
|
static void help(void) __attribute__((__noreturn__));
|
||||||
static void usage(int);
|
static void usage(int);
|
||||||
|
|
||||||
@ -187,77 +187,6 @@ open_sudoers(const char *sudoers, bool doedit, bool *keepopen)
|
|||||||
return fopen(sudoers, "r");
|
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
|
static void
|
||||||
usage(int fatal)
|
usage(int fatal)
|
||||||
{
|
{
|
||||||
|
110
plugins/sudoers/stubs.c
Normal file
110
plugins/sudoers/stubs.c
Normal file
@ -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;
|
||||||
|
}
|
@ -85,7 +85,6 @@ TAILQ_HEAD(sudoersfile_list, sudoersfile);
|
|||||||
* Function prototypes
|
* Function prototypes
|
||||||
*/
|
*/
|
||||||
static void quit(int);
|
static void quit(int);
|
||||||
static void get_hostname(void);
|
|
||||||
static int whatnow(void);
|
static int whatnow(void);
|
||||||
static int check_aliases(bool strict, bool quiet);
|
static int check_aliases(bool strict, bool quiet);
|
||||||
static char *get_editor(int *editor_argc, char ***editor_argv);
|
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 usage(int);
|
||||||
static void visudo_cleanup(void);
|
static void visudo_cleanup(void);
|
||||||
|
|
||||||
|
extern void get_hostname(void);
|
||||||
extern void sudoersrestart(FILE *);
|
extern void sudoersrestart(FILE *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -767,49 +767,6 @@ done:
|
|||||||
debug_return_bool(ret);
|
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
|
* Assuming a parse error occurred, prompt the user for what they want
|
||||||
* to do now. Returns the first letter of their choice.
|
* 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);
|
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
|
static bool
|
||||||
alias_remove_recursive(char *name, int type)
|
alias_remove_recursive(char *name, int type)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user