2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-22 18:08:23 +00:00

Use fmtsudoers functions in testsudoers.

This commit is contained in:
Todd C. Miller 2018-03-06 15:09:21 -07:00
parent 81a373677a
commit e6c0d80fa8
24 changed files with 224 additions and 405 deletions

View File

@ -167,7 +167,7 @@ CVTSUDOERS_OBJS = cvtsudoers.o cvtsudoers_json.o cvtsudoers_ldif.o \
REPLAY_OBJS = getdate.o sudoreplay.o REPLAY_OBJS = getdate.o sudoreplay.o
TEST_OBJS = group_plugin.o interfaces.o locale.o net_ifs.o \ TEST_OBJS = fmtsudoers.o group_plugin.o interfaces.o locale.o net_ifs.o \
sudo_printf.o testsudoers.o tsgetgrpw.o sudo_printf.o testsudoers.o tsgetgrpw.o
TSDUMP_OBJS = tsdump.o sudoers_debug.o locale.o TSDUMP_OBJS = tsdump.o sudoers_debug.o locale.o

View File

@ -1,8 +1,6 @@
Parses OK. Parses OK.
user1 ALL = LOG_INPUT: LOG_OUTPUT: /usr/bin/su - : ALL = NOLOG_INPUT: NOLOG_OUTPUT: /usr/bin/id user1 ALL = LOG_INPUT: LOG_OUTPUT: /usr/bin/su - : ALL = NOLOG_INPUT: NOLOG_OUTPUT: /usr/bin/id
user2 ALL = NOEXEC: NOPASSWD: SETENV: /usr/bin/vi : ALL = EXEC: PASSWD: NOSETENV: /usr/bin/echo user2 ALL = SETENV: NOEXEC: NOPASSWD: /usr/bin/vi : ALL = NOSETENV: EXEC: PASSWD: /usr/bin/echo
user3 ALL = MAIL: /bin/sh : ALL = NOMAIL: /usr/bin/id user3 ALL = MAIL: /bin/sh : ALL = NOMAIL: /usr/bin/id
user4 ALL = FOLLOW: sudoedit /etc/motd : ALL = NOFOLLOW: sudoedit /home/*/* user4 ALL = FOLLOW: sudoedit /etc/motd : ALL = NOFOLLOW: sudoedit /home/*/*

View File

@ -1,4 +1,2 @@
Parses OK. Parses OK.

View File

@ -1,4 +1,2 @@
Parse error in sudoers near line 1. Parse error in sudoers near line 1.

View File

@ -1,4 +1,2 @@
Parse error in sudoers near line 1. Parse error in sudoers near line 1.

View File

@ -1,4 +1,2 @@
Parse error in sudoers near line 1. Parse error in sudoers near line 1.

View File

@ -1,7 +1,6 @@
Parses OK. Parses OK.
Cmnd_Alias LS = sha224:d06a2617c98d377c250edd470fd5e576327748d82915d6e33b5f8db1 /bin/ls
Cmnd_Alias SH = sha256:hOtoe/iK6SlGg7w4BfZBBdSsXjUmTJ5+ts51yjh7vkM= /bin/sh
Cmnd_Alias LS = /bin/ls millert ALL = LS, SH, sha512:srzYEQ2aqzm+it3f74opTMkIImZRLxBARVpb0g9RSouJYdLt7DTRMEY4Ry9NyaOiDoUIplpNjqYH0JMYPVdFnw /bin/kill
Cmnd_Alias SH = /bin/sh
millert ALL = LS, SH, /bin/kill

View File

@ -1,5 +1,3 @@
Parses OK. Parses OK.
user ALL = sudoedit /etc/motd user ALL = sudoedit /etc/motd

View File

@ -1,6 +1,5 @@
Parses OK. Parses OK.
Cmnd_Alias EDIT = sudoedit /etc/motd Cmnd_Alias EDIT = sudoedit /etc/motd
user ALL = EDIT user ALL = EDIT

View File

@ -2,8 +2,7 @@ Parses OK.
Defaults command_timeout=2d8h10m59s Defaults command_timeout=2d8h10m59s
user0 ALL = TIMEOUT=619830 /usr/bin/id, /usr/bin/who, /bin/ls
user0 ALL = TIMEOUT=619830 /usr/bin/id, TIMEOUT=619830 /usr/bin/who, /bin/ls
user1 ALL = TIMEOUT=619830 /usr/bin/id user1 ALL = TIMEOUT=619830 /usr/bin/id
user2 ALL = TIMEOUT=15030 /usr/bin/id user2 ALL = TIMEOUT=15030 /usr/bin/id
user3 ALL = TIMEOUT=630 /usr/bin/id user3 ALL = TIMEOUT=630 /usr/bin/id

View File

@ -2,5 +2,3 @@ Parse error in sudoers near line 4 (problem with defaults entries).
Defaults command_timeout=2d8h10m59ss Defaults command_timeout=2d8h10m59ss
Defaults:root command_timeout=15f Defaults:root command_timeout=15f

View File

@ -1,9 +1,7 @@
Parses OK. Parses OK.
user0 ALL = NOTBEFORE=20170214083000Z NOTAFTER=20170301083000Z /usr/bin/id, /bin/ls
user1 ALL = NOTBEFORE=20170214083000Z /usr/bin/id, NOTAFTER=20170301083000Z /bin/ls
user0 ALL = NOTBEFORE=20170214083000Z NOTAFTER=20170301083000Z /usr/bin/id, NOTBEFORE=20170214083000Z NOTAFTER=20170301083000Z /bin/ls
user1 ALL = NOTBEFORE=20170214083000Z /usr/bin/id, NOTBEFORE=20170214083000Z NOTAFTER=20170301083000Z /bin/ls
user2 ALL = NOTBEFORE=20170214083018Z /usr/bin/id user2 ALL = NOTBEFORE=20170214083018Z /usr/bin/id
user3 ALL = NOTBEFORE=20170214080000Z /usr/bin/id user3 ALL = NOTBEFORE=20170214080000Z /usr/bin/id
user4 ALL = NOTBEFORE=20170214082400Z /usr/bin/id user4 ALL = NOTBEFORE=20170214082400Z /usr/bin/id

View File

@ -1,42 +1,42 @@
Parses OK. Parses OK.
Defaults@somehost set_home Defaults@somehost set_home
Defaults@quoted" set_home Defaults@quoted\" set_home
Defaults:you set_home Defaults:you set_home
Defaults:us" set_home Defaults:us\" set_home
Defaults:%them set_home Defaults:%them set_home
Defaults:%: non UNIX 0 c set_home Defaults:"%: non UNIX 0 c" set_home
Defaults:+net set_home Defaults:+net set_home
Defaults>someone set_home Defaults>someone set_home
Defaults>some one set_home Defaults>"some one" set_home
Runas_Alias RA1 = foo Runas_Alias RA1 = foo
Runas_Alias RA2 = foo" Runas_Alias RA2 = foo\"
Runas_Alias RA3 = foo:bar Runas_Alias RA3 = foo\:bar
Runas_Alias RA4 = foo:bar" Runas_Alias RA4 = foo\:bar\"
User_Alias UA1 = foo User_Alias UA1 = foo
User_Alias UA10 = %:C/non"UNIX"0 c User_Alias UA10 = "%:C/non\"UNIX\"0 c"
User_Alias UA11 = %:C/non_UNIX_0 c User_Alias UA11 = "%:C/non_UNIX_0 c"
User_Alias UA12 = %:C/non\'UNIX_3 c User_Alias UA12 = "%:C/non\'UNIX_3 c"
User_Alias UA2 = foo.bar User_Alias UA2 = foo.bar
User_Alias UA3 = foo" User_Alias UA3 = foo\"
User_Alias UA4 = foo:bar User_Alias UA4 = foo\:bar
User_Alias UA5 = foo:bar" User_Alias UA5 = foo\:bar\"
User_Alias UA6 = %baz User_Alias UA6 = %baz
User_Alias UA7 = %baz.biz User_Alias UA7 = %baz.biz
User_Alias UA8 = %:C/non UNIX 0 c User_Alias UA8 = "%:C/non UNIX 0 c"
User_Alias UA9 = %:C/non\'UNIX\'1 c User_Alias UA9 = "%:C/non\'UNIX\'1 c"
foo hosta = (root) ALL foo hosta = (root) ALL
foo.bar hostb = (root) ALL foo.bar hostb = (root) ALL
foo" hostc = (root) ALL foo\" hostc = (root) ALL
foo:bar hostd = (root) ALL foo\:bar hostd = (root) ALL
foo:bar" hoste = (root) ALL foo\:bar\" hoste = (root) ALL
%baz hosta = (root) ALL %baz hosta = (root) ALL
%baz.biz hostb = (root) ALL %baz.biz hostb = (root) ALL
%:C/non UNIX 0 c hostc = (root) ALL "%:C/non UNIX 0 c" hostc = (root) ALL
%:C/non\'UNIX\'1 c hostd = (root) ALL "%:C/non\'UNIX\'1 c" hostd = (root) ALL
%:C/non"UNIX"0 c hoste = (root) ALL "%:C/non\"UNIX\"0 c" hoste = (root) ALL
%:C/non_UNIX_0 c hostf = (root) ALL "%:C/non_UNIX_0 c" hostf = (root) ALL
%:C/non\'UNIX_3 c hostg = (root) ALL "%:C/non\'UNIX_3 c" hostg = (root) ALL
+netgr hosth = (root) ALL +netgr hosth = (root) ALL

View File

@ -22,5 +22,3 @@ Defaults !fdexec
Defaults fdexec=never Defaults fdexec=never
Defaults fdexec=digest_only Defaults fdexec=digest_only
Defaults fdexec=always Defaults fdexec=always

View File

@ -33,5 +33,3 @@ Defaults syslog_badpri=info
Defaults syslog_badpri=notice Defaults syslog_badpri=notice
Defaults syslog_badpri=warning Defaults syslog_badpri=warning
Defaults syslog_badpri=none Defaults syslog_badpri=none

View File

@ -1,8 +1,6 @@
Parses OK. Parses OK.
user1 ALL = (root) ALL
user2 ALL = (root) ALL
user1 ALL = () ALL user3 ALL = (root) ALL
user2 ALL = () ALL user4 ALL = (root) ALL
user3 ALL = () ALL
user4 ALL = () ALL

View File

@ -1,9 +1,8 @@
Parses OK. Parses OK.
Defaults:FOO env_reset Defaults:FOO env_reset
Defaults:foo,bar env_reset
Defaults:foo, bar env_reset Defaults:foo, bar env_reset
Defaults:foo,bar env_reset Defaults:foo, " bar" env_reset
Defaults:foo, bar env_reset
User_Alias FOO = foo, bar User_Alias FOO = foo, bar

View File

@ -1,6 +1,4 @@
Parse error in sudoers near line 7. Parse error in sudoers near line 7.
User_Alias BAR = bar User_Alias BAR = bar
User_Alias FOO = foo User_Alias FOO = foo

View File

@ -1,4 +1,2 @@
Parse error in sudoers near line 2. Parse error in sudoers near line 2.

View File

@ -5,7 +5,6 @@ Defaults>#123 set_home
Defaults:#123 set_home Defaults:#123 set_home
Defaults>#123 set_home Defaults>#123 set_home
#0 ALL = ALL #0 ALL = ALL
#0 ALL = (#0 : #0) ALL #0 ALL = (#0 : #0) ALL
#0 ALL = ALL #0 ALL = ALL

View File

@ -1,4 +1,2 @@
Parse error in sudoers near line 2. Parse error in sudoers near line 2.

View File

@ -1,7 +1,5 @@
Parse error in sudoers near line 8. Parse error in sudoers near line 8.
User_Alias UA1 = xy User_Alias UA1 = xy
User_Alias UA2 = xy User_Alias UA2 = xy
User_Alias UA3 = x"y User_Alias UA3 = x\"y

View File

@ -1,4 +1,2 @@
Parses OK. Parses OK.

View File

@ -49,6 +49,7 @@
#include "interfaces.h" #include "interfaces.h"
#include "parse.h" #include "parse.h"
#include "sudo_conf.h" #include "sudo_conf.h"
#include "sudo_lbuf.h"
#include <gram.h> #include <gram.h>
#ifdef HAVE_FNMATCH #ifdef HAVE_FNMATCH
@ -64,16 +65,13 @@
/* /*
* Function Prototypes * Function Prototypes
*/ */
int print_alias(void *, void *); static void dump_sudoers(struct sudo_lbuf *lbuf);
void dump_sudoers(void); static void usage(void) __attribute__((__noreturn__));
void print_defaults(void);
void print_privilege(struct privilege *);
void print_userspecs(void);
void usage(void) __attribute__((__noreturn__));
static void set_runaspw(const char *); static void set_runaspw(const char *);
static void set_runasgr(const char *); static void set_runasgr(const char *);
static bool cb_runas_default(const union sudo_defs_val *); static bool cb_runas_default(const union sudo_defs_val *);
static int testsudoers_print(const char *msg); static int testsudoers_error(const char *msg);
static int testsudoers_output(const char *buf);
extern void setgrfile(const char *); extern void setgrfile(const char *);
extern void setgrent(void); extern void setgrent(void);
@ -116,6 +114,7 @@ main(int argc, char *argv[])
const char *errstr; const char *errstr;
int match, host_match, runas_match, cmnd_match; int match, host_match, runas_match, cmnd_match;
int ch, dflag, exitcode = EXIT_FAILURE; int ch, dflag, exitcode = EXIT_FAILURE;
struct sudo_lbuf lbuf;
debug_decl(main, SUDOERS_DEBUG_MAIN) debug_decl(main, SUDOERS_DEBUG_MAIN)
#if defined(SUDO_DEVEL) && defined(__OpenBSD__) #if defined(SUDO_DEVEL) && defined(__OpenBSD__)
@ -133,6 +132,8 @@ main(int argc, char *argv[])
bindtextdomain("sudoers", LOCALEDIR); /* XXX - should have own domain */ bindtextdomain("sudoers", LOCALEDIR); /* XXX - should have own domain */
textdomain("sudoers"); textdomain("sudoers");
sudo_lbuf_init(&lbuf, testsudoers_output, 0, NULL, 0);
/* Initialize the debug subsystem. */ /* Initialize the debug subsystem. */
if (sudo_conf_read(NULL, SUDO_CONF_DEBUG) == -1) if (sudo_conf_read(NULL, SUDO_CONF_DEBUG) == -1)
goto done; goto done;
@ -165,7 +166,7 @@ main(int argc, char *argv[])
grfile = optarg; grfile = optarg;
break; break;
case 't': case 't':
trace_print = testsudoers_print; trace_print = testsudoers_error;
break; break;
case 'U': case 'U':
sudoers_uid = (uid_t)sudo_strtoid(optarg, NULL, NULL, &errstr); sudoers_uid = (uid_t)sudo_strtoid(optarg, NULL, NULL, &errstr);
@ -294,7 +295,7 @@ main(int argc, char *argv[])
if (dflag) { if (dflag) {
(void) putchar('\n'); (void) putchar('\n');
dump_sudoers(); dump_sudoers(&lbuf);
if (argc < 2) { if (argc < 2) {
exitcode = parse_error ? 1 : 0; exitcode = parse_error ? 1 : 0;
goto done; goto done;
@ -308,9 +309,9 @@ main(int argc, char *argv[])
if (userlist_matches(sudo_user.pw, &us->users) != ALLOW) if (userlist_matches(sudo_user.pw, &us->users) != ALLOW)
continue; continue;
TAILQ_FOREACH_REVERSE(priv, &us->privileges, privilege_list, entries) { TAILQ_FOREACH_REVERSE(priv, &us->privileges, privilege_list, entries) {
putchar('\n'); sudo_lbuf_append(&lbuf, "\n");
print_privilege(priv); sudoers_format_privilege(&lbuf, priv, false);
putchar('\n'); sudo_lbuf_print(&lbuf);
host_match = hostlist_matches(sudo_user.pw, &priv->hostlist); host_match = hostlist_matches(sudo_user.pw, &priv->hostlist);
if (host_match == ALLOW) { if (host_match == ALLOW) {
puts("\thost matched"); puts("\thost matched");
@ -342,6 +343,7 @@ main(int argc, char *argv[])
*/ */
exitcode = parse_error ? 1 : (match == ALLOW ? 0 : match + 3); exitcode = parse_error ? 1 : (match == ALLOW ? 0 : match + 3);
done: done:
sudo_lbuf_destroy(&lbuf);
sudo_freepwcache(); sudo_freepwcache();
sudo_freegrcache(); sudo_freegrcache();
sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys, exitcode); sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys, exitcode);
@ -479,244 +481,98 @@ restore_perms(void)
return true; return true;
} }
void static bool
print_member(struct member *m) print_defaults(struct sudo_lbuf *lbuf)
{ {
struct sudo_command *c; struct defaults *def, *next;
debug_decl(print_member, SUDOERS_DEBUG_UTIL)
if (m->negated)
putchar('!');
if (m->type == ALL)
fputs("ALL", stdout);
else if (m->type != COMMAND)
fputs(m->name ? m->name : "", stdout);
else {
c = (struct sudo_command *) m->name;
printf("%s%s%s", c->cmnd, c->args ? " " : "",
c->args ? c->args : "");
}
debug_return;
}
void
print_defaults(void)
{
struct defaults *d;
struct member *m;
debug_decl(print_defaults, SUDOERS_DEBUG_UTIL) debug_decl(print_defaults, SUDOERS_DEBUG_UTIL)
TAILQ_FOREACH(d, &defaults, entries) { TAILQ_FOREACH_SAFE(def, &defaults, entries, next)
(void) fputs("Defaults", stdout); sudoers_format_default_line(lbuf, def, &next, false);
switch (d->type) {
case DEFAULTS_HOST:
putchar('@');
break;
case DEFAULTS_USER:
putchar(':');
break;
case DEFAULTS_RUNAS:
putchar('>');
break;
case DEFAULTS_CMND:
putchar('!');
break;
}
TAILQ_FOREACH(m, d->binding, entries) {
if (m != TAILQ_FIRST(d->binding))
putchar(',');
print_member(m);
}
printf("\t%s%s", d->op == false ? "!" : "", d->var);
if (d->val != NULL) {
printf("%c%s", d->op == true ? '=' : d->op, d->val);
}
putchar('\n');
}
debug_return; debug_return_bool(!sudo_lbuf_error(lbuf));
} }
int static int
print_alias(void *v1, void *v2) print_alias(void *v1, void *v2)
{ {
struct alias *a = (struct alias *)v1; struct alias *a = v1;
struct sudo_lbuf *lbuf = v2;
struct member *m; struct member *m;
struct sudo_command *c;
debug_decl(print_alias, SUDOERS_DEBUG_UTIL) debug_decl(print_alias, SUDOERS_DEBUG_UTIL)
switch (a->type) { sudo_lbuf_append(lbuf, "%s %s = ", alias_type_to_string(a->type),
case HOSTALIAS: a->name);
(void) printf("Host_Alias\t%s = ", a->name);
break;
case CMNDALIAS:
(void) printf("Cmnd_Alias\t%s = ", a->name);
break;
case USERALIAS:
(void) printf("User_Alias\t%s = ", a->name);
break;
case RUNASALIAS:
(void) printf("Runas_Alias\t%s = ", a->name);
break;
}
TAILQ_FOREACH(m, &a->members, entries) { TAILQ_FOREACH(m, &a->members, entries) {
if (m != TAILQ_FIRST(&a->members)) if (m != TAILQ_FIRST(&a->members))
fputs(", ", stdout); sudo_lbuf_append(lbuf, ", ");
if (m->type == COMMAND) { sudoers_format_member(lbuf, m, NULL, UNSPEC);
c = (struct sudo_command *) m->name;
printf("%s%s%s", c->cmnd, c->args ? " " : "",
c->args ? c->args : "");
} else if (m->type == ALL) {
fputs("ALL", stdout);
} else {
fputs(m->name, stdout);
} }
} sudo_lbuf_append(lbuf, "\n");
putchar('\n');
debug_return_int(0); debug_return_int(sudo_lbuf_error(lbuf) ? -1 : 0);
} }
#define TAG_SET(tt) \ static bool
((tt) != UNSPEC && (tt) != IMPLIED) print_aliases(struct sudo_lbuf *lbuf)
#define TAG_CHANGED(t) \
(TAG_SET(cs->tags.t) && cs->tags.t != tags.t)
void
print_privilege(struct privilege *priv)
{ {
struct cmndspec *cs; debug_decl(print_aliases, SUDOERS_DEBUG_UTIL)
struct member *m;
struct cmndtag tags;
debug_decl(print_privilege, SUDOERS_DEBUG_UTIL)
TAILQ_FOREACH(m, &priv->hostlist, entries) { alias_apply(print_alias, lbuf);
if (m != TAILQ_FIRST(&priv->hostlist))
fputs(", ", stdout); debug_return_bool(!sudo_lbuf_error(lbuf));
print_member(m);
}
fputs(" = ", stdout);
TAGS_INIT(tags);
TAILQ_FOREACH(cs, &priv->cmndlist, entries) {
if (cs != TAILQ_FIRST(&priv->cmndlist))
fputs(", ", stdout);
if (cs->runasuserlist != NULL || cs->runasgrouplist != NULL) {
fputs("(", stdout);
if (cs->runasuserlist != NULL) {
TAILQ_FOREACH(m, cs->runasuserlist, entries) {
if (m != TAILQ_FIRST(cs->runasuserlist))
fputs(", ", stdout);
print_member(m);
}
} else if (cs->runasgrouplist == NULL) {
fputs(def_runas_default, stdout);
} else {
fputs(sudo_user.pw->pw_name, stdout);
}
if (cs->runasgrouplist != NULL) {
fputs(" : ", stdout);
TAILQ_FOREACH(m, cs->runasgrouplist, entries) {
if (m != TAILQ_FIRST(cs->runasgrouplist))
fputs(", ", stdout);
print_member(m);
}
}
fputs(") ", stdout);
}
#ifdef HAVE_SELINUX
if (cs->role)
printf("ROLE=%s ", cs->role);
if (cs->type)
printf("TYPE=%s ", cs->type);
#endif /* HAVE_SELINUX */
#ifdef HAVE_PRIV_SET
if (cs->privs)
printf("PRIVS=%s ", cs->privs);
if (cs->limitprivs)
printf("LIMITPRIVS=%s ", cs->limitprivs);
#endif /* HAVE_PRIV_SET */
if (cs->timeout > 0)
printf("TIMEOUT=%d ", cs->timeout);
if (cs->notbefore != UNSPEC) {
struct tm *tm = gmtime(&cs->notbefore);
printf("NOTBEFORE=%04d%02d%02d%02d%02d%02dZ ",
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
}
if (cs->notafter != UNSPEC) {
struct tm *tm = gmtime(&cs->notafter);
printf("NOTAFTER=%04d%02d%02d%02d%02d%02dZ ",
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
}
if (TAG_CHANGED(follow))
printf("%sFOLLOW: ", cs->tags.follow ? "" : "NO");
if (TAG_CHANGED(log_input))
printf("%sLOG_INPUT: ", cs->tags.log_input ? "" : "NO");
if (TAG_CHANGED(log_output))
printf("%sLOG_OUTPUT: ", cs->tags.log_output ? "" : "NO");
if (TAG_CHANGED(noexec))
printf("%sEXEC: ", cs->tags.noexec ? "NO" : "");
if (TAG_CHANGED(nopasswd))
printf("%sPASSWD: ", cs->tags.nopasswd ? "NO" : "");
if (TAG_CHANGED(send_mail))
printf("%sMAIL: ", cs->tags.send_mail ? "" : "NO");
if (TAG_CHANGED(setenv))
printf("%sSETENV: ", cs->tags.setenv ? "" : "NO");
print_member(cs->cmnd);
memcpy(&tags, &cs->tags, sizeof(tags));
}
debug_return;
} }
void static void
print_userspecs(void) dump_sudoers(struct sudo_lbuf *lbuf)
{
struct member *m;
struct userspec *us;
struct privilege *priv;
debug_decl(print_userspecs, SUDOERS_DEBUG_UTIL)
TAILQ_FOREACH(us, &userspecs, entries) {
TAILQ_FOREACH(m, &us->users, entries) {
if (m != TAILQ_FIRST(&us->users))
fputs(", ", stdout);
print_member(m);
}
putchar('\t');
TAILQ_FOREACH(priv, &us->privileges, entries) {
if (priv != TAILQ_FIRST(&us->privileges))
fputs(" : ", stdout);
print_privilege(priv);
}
putchar('\n');
}
debug_return;
}
void
dump_sudoers(void)
{ {
debug_decl(dump_sudoers, SUDOERS_DEBUG_UTIL) debug_decl(dump_sudoers, SUDOERS_DEBUG_UTIL)
print_defaults(); /* Print Defaults */
if (!print_defaults(lbuf))
goto done;
if (lbuf->len > 0) {
sudo_lbuf_print(lbuf);
sudo_lbuf_append(lbuf, "\n");
}
putchar('\n'); /* Print Aliases */
alias_apply(print_alias, NULL); if (!print_aliases(lbuf))
goto done;
if (lbuf->len > 1) {
sudo_lbuf_print(lbuf);
sudo_lbuf_append(lbuf, "\n");
}
putchar('\n'); /* Print User_Specs */
print_userspecs(); if (!sudoers_format_userspecs(lbuf, &userspecs, NULL, false, true))
goto done;
if (lbuf->len > 1) {
sudo_lbuf_print(lbuf);
}
done:
if (sudo_lbuf_error(lbuf)) {
if (errno == ENOMEM)
sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
}
debug_return; debug_return;
} }
static int testsudoers_print(const char *msg) static int
testsudoers_output(const char *buf)
{ {
return fputs(msg, stderr); return fputs(buf, stdout);
} }
void static int
testsudoers_error(const char *buf)
{
return fputs(buf, stderr);
}
static void
usage(void) usage(void)
{ {
(void) fprintf(stderr, "usage: %s [-dt] [-G sudoers_gid] [-g group] [-h host] [-P grfile] [-p pwfile] [-U sudoers_uid] [-u user] <user> <command> [args]\n", getprogname()); (void) fprintf(stderr, "usage: %s [-dt] [-G sudoers_gid] [-g group] [-h host] [-P grfile] [-p pwfile] [-U sudoers_uid] [-u user] <user> <command> [args]\n", getprogname());