Add ldif support to testsudoers
This commit is contained in:
@@ -169,8 +169,9 @@ CVTSUDOERS_OBJS = cvtsudoers.o cvtsudoers_json.o cvtsudoers_ldif.o \
|
|||||||
|
|
||||||
REPLAY_OBJS = getdate.o sudoreplay.o iolog_util.lo
|
REPLAY_OBJS = getdate.o sudoreplay.o iolog_util.lo
|
||||||
|
|
||||||
TEST_OBJS = fmtsudoers.lo group_plugin.lo interfaces.lo locale.lo net_ifs.o \
|
TEST_OBJS = fmtsudoers.lo group_plugin.lo interfaces.lo ldap_util.lo \
|
||||||
sudo_printf.o testsudoers.o tsgetgrpw.o
|
locale.lo net_ifs.o parse_ldif.o strlist.o sudo_printf.o \
|
||||||
|
testsudoers.o tsgetgrpw.o
|
||||||
|
|
||||||
TSDUMP_OBJS = tsdump.o sudoers_debug.lo locale.lo
|
TSDUMP_OBJS = tsdump.o sudoers_debug.lo locale.lo
|
||||||
|
|
||||||
|
@@ -55,6 +55,11 @@
|
|||||||
# define YYDEBUG 0
|
# define YYDEBUG 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
enum sudoers_formats {
|
||||||
|
format_ldif,
|
||||||
|
format_sudoers
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Function Prototypes
|
* Function Prototypes
|
||||||
*/
|
*/
|
||||||
@@ -102,6 +107,7 @@ __dso_public int main(int argc, char *argv[]);
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
enum sudoers_formats input_format = format_sudoers;
|
||||||
struct cmndspec *cs;
|
struct cmndspec *cs;
|
||||||
struct privilege *priv;
|
struct privilege *priv;
|
||||||
struct userspec *us;
|
struct userspec *us;
|
||||||
@@ -138,14 +144,11 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
dflag = 0;
|
dflag = 0;
|
||||||
grfile = pwfile = NULL;
|
grfile = pwfile = NULL;
|
||||||
while ((ch = getopt(argc, argv, "dg:G:h:P:p:tu:U:")) != -1) {
|
while ((ch = getopt(argc, argv, "dg:G:h:i:P:p:tu:U:")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'd':
|
case 'd':
|
||||||
dflag = 1;
|
dflag = 1;
|
||||||
break;
|
break;
|
||||||
case 'h':
|
|
||||||
user_host = optarg;
|
|
||||||
break;
|
|
||||||
case 'G':
|
case 'G':
|
||||||
sudoers_gid = (gid_t)sudo_strtoid(optarg, NULL, NULL, &errstr);
|
sudoers_gid = (gid_t)sudo_strtoid(optarg, NULL, NULL, &errstr);
|
||||||
if (errstr != NULL)
|
if (errstr != NULL)
|
||||||
@@ -155,6 +158,19 @@ main(int argc, char *argv[])
|
|||||||
runas_group = optarg;
|
runas_group = optarg;
|
||||||
SET(sudo_user.flags, RUNAS_GROUP_SPECIFIED);
|
SET(sudo_user.flags, RUNAS_GROUP_SPECIFIED);
|
||||||
break;
|
break;
|
||||||
|
case 'h':
|
||||||
|
user_host = optarg;
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
if (strcasecmp(optarg, "ldif") == 0) {
|
||||||
|
input_format = format_ldif;
|
||||||
|
} else if (strcasecmp(optarg, "sudoers") == 0) {
|
||||||
|
input_format = format_sudoers;
|
||||||
|
} else {
|
||||||
|
sudo_warnx(U_("unsupported input format %s"), optarg);
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
pwfile = optarg;
|
pwfile = optarg;
|
||||||
break;
|
break;
|
||||||
@@ -273,16 +289,29 @@ main(int argc, char *argv[])
|
|||||||
} else
|
} else
|
||||||
set_runaspw(runas_user ? runas_user : def_runas_default);
|
set_runaspw(runas_user ? runas_user : def_runas_default);
|
||||||
|
|
||||||
|
/* Parse the policy file. */
|
||||||
sudoers_setlocale(SUDOERS_LOCALE_SUDOERS, NULL);
|
sudoers_setlocale(SUDOERS_LOCALE_SUDOERS, NULL);
|
||||||
if (sudoersparse() != 0 || parse_error) {
|
switch (input_format) {
|
||||||
parse_error = true;
|
case format_ldif:
|
||||||
if (errorlineno != -1)
|
if (!sudoers_parse_ldif(&parsed_policy, stdin, NULL, true))
|
||||||
(void) printf("Parse error in %s near line %d",
|
(void) printf("Parse error in LDIF");
|
||||||
errorfile, errorlineno);
|
|
||||||
else
|
else
|
||||||
(void) printf("Parse error in %s", errorfile);
|
(void) fputs("Parses OK", stdout);
|
||||||
} else {
|
break;
|
||||||
(void) fputs("Parses OK", stdout);
|
case format_sudoers:
|
||||||
|
if (sudoersparse() != 0 || parse_error) {
|
||||||
|
parse_error = true;
|
||||||
|
if (errorlineno != -1)
|
||||||
|
(void) printf("Parse error in %s near line %d",
|
||||||
|
errorfile, errorlineno);
|
||||||
|
else
|
||||||
|
(void) printf("Parse error in %s", errorfile);
|
||||||
|
} else {
|
||||||
|
(void) fputs("Parses OK", stdout);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sudo_fatalx("error: unhandled input %d", input_format);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!update_defaults(&parsed_policy, NULL, SETDEF_ALL, false))
|
if (!update_defaults(&parsed_policy, NULL, SETDEF_ALL, false))
|
||||||
@@ -571,6 +600,6 @@ testsudoers_error(const char *buf)
|
|||||||
static void
|
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] [-i input_format] [-P grfile] [-p pwfile] [-U sudoers_uid] [-u user] <user> <command> [args]\n", getprogname());
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user