1 /*
2  * SPDX-License-Identifier: ISC
3  *
4  * Copyright (c) 2018 Todd C. Miller <Todd.Miller@sudo.ws>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef SUDOERS_CVTSUDOERS_H
20 #define SUDOERS_CVTSUDOERS_H
21 
22 #include "strlist.h"
23 
24 /* Supported input/output formats. */
25 enum sudoers_formats {
26     format_json,
27     format_ldif,
28     format_sudoers
29 };
30 
31 /* Flags for cvtsudoers_config.defaults */
32 #define CVT_DEFAULTS_GLOBAL	0x01
33 #define CVT_DEFAULTS_USER	0x02
34 #define CVT_DEFAULTS_RUNAS	0x04
35 #define CVT_DEFAULTS_HOST	0x08
36 #define CVT_DEFAULTS_CMND	0x10
37 #define CVT_DEFAULTS_ALL	0xff
38 
39 /* Flags for cvtsudoers_config.suppress */
40 #define SUPPRESS_DEFAULTS	0x01
41 #define SUPPRESS_ALIASES	0x02
42 #define SUPPRESS_PRIVS		0x04
43 
44 /* cvtsudoers.conf settings */
45 struct cvtsudoers_config {
46     unsigned int sudo_order;
47     unsigned int order_increment;
48     unsigned int order_padding;
49     unsigned int order_max;
50     short defaults;
51     short suppress;
52     bool expand_aliases;
53     bool store_options;
54     bool prune_matches;
55     char *sudoers_base;
56     char *input_format;
57     char *output_format;
58     char *filter;
59     char *defstr;
60     char *supstr;
61 };
62 
63 /* Initial config settings for above. */
64 #define INITIAL_CONFIG { 1, 1, 0, 0, CVT_DEFAULTS_ALL, 0, false, true, false }
65 
66 #define CONF_BOOL	0
67 #define CONF_UINT	1
68 #define CONF_STR	2
69 
70 struct cvtsudoers_conf_table {
71     const char *conf_str;	/* config file string */
72     int type;			/* CONF_BOOL, CONF_UINT, CONF_STR */
73     void *valp;			/* pointer into cvtsudoers_config */
74 };
75 
76 struct cvtsudoers_filter {
77     struct sudoers_str_list users;
78     struct sudoers_str_list groups;
79     struct sudoers_str_list hosts;
80 };
81 
82 /* cvtsudoers.c */
83 extern struct cvtsudoers_filter *filters;
84 
85 /* cvtsudoers_json.c */
86 bool convert_sudoers_json(struct sudoers_parse_tree *parse_tree, const char *output_file, struct cvtsudoers_config *conf);
87 
88 /* cvtsudoers_ldif.c */
89 bool convert_sudoers_ldif(struct sudoers_parse_tree *parse_tree, const char *output_file, struct cvtsudoers_config *conf);
90 
91 /* cvtsudoers_pwutil.c */
92 struct cache_item *cvtsudoers_make_pwitem(uid_t uid, const char *name);
93 struct cache_item *cvtsudoers_make_gritem(gid_t gid, const char *name);
94 struct cache_item *cvtsudoers_make_gidlist_item(const struct passwd *pw, char * const *unused1, unsigned int type);
95 struct cache_item *cvtsudoers_make_grlist_item(const struct passwd *pw, char * const *unused1);
96 
97 /* stubs.c */
98 void get_hostname(void);
99 
100 #endif /* SUDOERS_CVTSUDOERS_H */
101