Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/plugins/sudoers/cvtsudoers.h
1532 views
1
/*
2
* SPDX-License-Identifier: ISC
3
*
4
* Copyright (c) 2018, 2021-2023 Todd C. Miller <[email protected]>
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_csv,
27
format_json,
28
format_ldif,
29
format_sudoers
30
};
31
32
/* Flags for cvtsudoers_config.defaults */
33
#define CVT_DEFAULTS_GLOBAL 0x01U
34
#define CVT_DEFAULTS_USER 0x02U
35
#define CVT_DEFAULTS_RUNAS 0x04U
36
#define CVT_DEFAULTS_HOST 0x08U
37
#define CVT_DEFAULTS_CMND 0x10U
38
#define CVT_DEFAULTS_ALL 0xffU
39
40
/* Flags for cvtsudoers_config.suppress */
41
#define SUPPRESS_DEFAULTS 0x01U
42
#define SUPPRESS_ALIASES 0x02U
43
#define SUPPRESS_PRIVS 0x04U
44
45
/* cvtsudoers.conf settings */
46
struct cvtsudoers_config {
47
unsigned int sudo_order;
48
unsigned int order_increment;
49
unsigned int order_padding;
50
unsigned int order_max;
51
unsigned int defaults;
52
unsigned int suppress;
53
bool store_options;
54
bool expand_aliases;
55
bool prune_matches;
56
bool match_local;
57
char *sudoers_base;
58
char *input_format;
59
char *output_format;
60
char *filter;
61
char *logfile;
62
char *defstr;
63
char *supstr;
64
char *group_file;
65
char *passwd_file;
66
};
67
68
/* Initial config settings for above. */
69
#define INITIAL_CONFIG { 1, 1, 0, 0, CVT_DEFAULTS_ALL, 0, true }
70
71
#define CONF_BOOL 0
72
#define CONF_UINT 1
73
#define CONF_STR 2
74
75
struct cvtsudoers_conf_table {
76
const char *conf_str; /* config file string */
77
int type; /* CONF_BOOL, CONF_UINT, CONF_STR */
78
void *valp; /* pointer into cvtsudoers_config */
79
};
80
81
struct cvtsudoers_filter {
82
struct sudoers_str_list users;
83
struct sudoers_str_list groups;
84
struct sudoers_str_list hosts;
85
struct sudoers_str_list cmnds;
86
};
87
88
/* cvtsudoers.c */
89
extern struct cvtsudoers_filter *filters;
90
void log_warnx(const char * restrict fmt, ...) sudo_printflike(1, 2);
91
92
/* cvtsudoers_csv.c */
93
bool convert_sudoers_csv(const struct sudoers_parse_tree *parse_tree, const char *output_file, struct cvtsudoers_config *conf);
94
95
/* cvtsudoers_json.c */
96
bool convert_sudoers_json(const struct sudoers_parse_tree *parse_tree, const char *output_file, struct cvtsudoers_config *conf);
97
98
/* cvtsudoers_ldif.c */
99
bool convert_sudoers_ldif(const struct sudoers_parse_tree *parse_tree, const char *output_file, struct cvtsudoers_config *conf);
100
101
/* cvtsudoers_merge.c */
102
struct sudoers_parse_tree *merge_sudoers(struct sudoers_parse_tree_list *parse_trees, struct sudoers_parse_tree *merged_tree);
103
104
/* cvtsudoers_pwutil.c */
105
struct cache_item *cvtsudoers_make_pwitem(uid_t uid, const char *name);
106
struct cache_item *cvtsudoers_make_gritem(gid_t gid, const char *name);
107
struct cache_item *cvtsudoers_make_gidlist_item(const struct passwd *pw, int unusued1, GETGROUPS_T *unused2, char * const *unused3, unsigned int type);
108
struct cache_item *cvtsudoers_make_grlist_item(const struct passwd *pw, char * const *unused1);
109
110
#endif /* SUDOERS_CVTSUDOERS_H */
111
112