Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/plugins/sudoers/defaults.h
1532 views
1
/*
2
* SPDX-License-Identifier: ISC
3
*
4
* Copyright (c) 1999-2005, 2008-2023
5
* Todd C. Miller <[email protected]>
6
*
7
* Permission to use, copy, modify, and distribute this software for any
8
* purpose with or without fee is hereby granted, provided that the above
9
* copyright notice and this permission notice appear in all copies.
10
*
11
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
*
19
* Sponsored in part by the Defense Advanced Research Projects
20
* Agency (DARPA) and Air Force Research Laboratory, Air Force
21
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
22
*/
23
24
#ifndef SUDOERS_DEFAULTS_H
25
#define SUDOERS_DEFAULTS_H
26
27
#include <time.h>
28
#include <def_data.h>
29
#include <sudo_queue.h>
30
31
struct list_member {
32
SLIST_ENTRY(list_member) entries;
33
char *value;
34
};
35
36
SLIST_HEAD(list_members, list_member);
37
38
enum list_ops {
39
add,
40
delete,
41
freeall
42
};
43
44
/* Mapping of tuple string value to enum def_tuple. */
45
struct def_values {
46
const char *sval; /* string value */
47
enum def_tuple nval;/* numeric value */
48
};
49
50
union sudo_defs_val {
51
bool flag;
52
int ival;
53
unsigned int uival;
54
enum def_tuple tuple;
55
char *str;
56
mode_t mode;
57
struct timespec tspec;
58
struct list_members list;
59
};
60
61
/*
62
* Structure describing compile-time and run-time options.
63
*/
64
struct sudoers_context;
65
struct sudo_defs_types {
66
const char *name;
67
int type;
68
const char *desc;
69
struct def_values *values;
70
bool (*callback)(struct sudoers_context *ctx, const char *file, int line, int column, const union sudo_defs_val *, int op);
71
union sudo_defs_val sd_un;
72
};
73
74
/*
75
* Defaults values to apply before others.
76
*/
77
struct early_default {
78
int idx;
79
int run_callback;
80
int line;
81
int column;
82
char *file;
83
};
84
85
/*
86
* Four types of defaults: strings, integers, and flags.
87
* Also, T_INT, T_TIMESPEC or T_STR may be ANDed with T_BOOL to indicate that
88
* a value is not required. Flags are boolean by nature...
89
*/
90
#undef T_INT
91
#define T_INT 0x001
92
#undef T_UINT
93
#define T_UINT 0x002
94
#undef T_STR
95
#define T_STR 0x003
96
#undef T_FLAG
97
#define T_FLAG 0x004
98
#undef T_MODE
99
#define T_MODE 0x005
100
#undef T_LIST
101
#define T_LIST 0x006
102
#undef T_LOGFAC
103
#define T_LOGFAC 0x007
104
#undef T_LOGPRI
105
#define T_LOGPRI 0x008
106
#undef T_TUPLE
107
#define T_TUPLE 0x009
108
#undef T_TIMESPEC
109
#define T_TIMESPEC 0x010
110
#undef T_TIMEOUT
111
#define T_TIMEOUT 0x011
112
#undef T_RLIMIT
113
#define T_RLIMIT 0x012
114
#undef T_PLUGIN
115
#define T_PLUGIN 0x013
116
#undef T_MASK
117
#define T_MASK 0x0FF
118
#undef T_BOOL
119
#define T_BOOL 0x100
120
#undef T_PATH
121
#define T_PATH 0x200
122
#undef T_CHPATH
123
#define T_CHPATH 0x400
124
#undef T_SPACE
125
#define T_SPACE 0x800
126
127
/*
128
* Argument to update_defaults()
129
*/
130
#define SETDEF_GENERIC 0x01
131
#define SETDEF_HOST 0x02
132
#define SETDEF_USER 0x04
133
#define SETDEF_RUNAS 0x08
134
#define SETDEF_CMND 0x10
135
#define SETDEF_ALL (SETDEF_GENERIC|SETDEF_HOST|SETDEF_USER|SETDEF_RUNAS|SETDEF_CMND)
136
137
/*
138
* Convenience macros
139
*/
140
#define iolog_enabled (def_log_stdin || def_log_ttyin || def_log_stdout || def_log_stderr || def_log_ttyout)
141
142
/*
143
* Prototypes
144
*/
145
struct defaults_list;
146
struct sudoers_parse_tree;
147
void dump_default(void);
148
bool init_defaults(void);
149
bool set_default(struct sudoers_context *ctx, const char *var, const char *val, int op, const char *file, int line, int column, bool quiet);
150
bool update_defaults(struct sudoers_context *ctx, struct sudoers_parse_tree *parse_tree, const struct defaults_list *defs, int what, bool quiet);
151
bool check_defaults(const struct sudoers_parse_tree *parse_tree, bool quiet);
152
bool append_default(const char *var, const char *val, int op, char *source, struct defaults_list *defs);
153
bool cb_passprompt_regex(struct sudoers_context *ctx, const char *file, int line, int column, const union sudo_defs_val *sd_un, int op);
154
155
extern struct sudo_defs_types sudo_defs_table[];
156
157
#endif /* SUDOERS_DEFAULTS_H */
158
159