summaryrefslogtreecommitdiffstats
path: root/plugins/sudoers/defaults.h
blob: f0bf88ebf42c5b6e5d49bfc63bffc1802c489d77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 * SPDX-License-Identifier: ISC
 *
 * Copyright (c) 1999-2005, 2008-2022
 *	Todd C. Miller <Todd.Miller@sudo.ws>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * Sponsored in part by the Defense Advanced Research Projects
 * Agency (DARPA) and Air Force Research Laboratory, Air Force
 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
 */

#ifndef SUDOERS_DEFAULTS_H
#define SUDOERS_DEFAULTS_H

#include <time.h>
#include <def_data.h>
#include "sudo_queue.h"

struct list_member {
    SLIST_ENTRY(list_member) entries;
    char *value;
};

SLIST_HEAD(list_members, list_member);

enum list_ops {
    add,
    delete,
    freeall
};

/* Mapping of tuple string value to enum def_tuple. */
struct def_values {
    const char *sval;	/* string value */
    enum def_tuple nval;/* numeric value */
};

union sudo_defs_val {
    int flag;
    int ival;
    unsigned int uival;
    enum def_tuple tuple;
    char *str;
    mode_t mode;
    struct timespec tspec;
    struct list_members list;
};

/*
 * Structure describing compile-time and run-time options.
 */
struct sudo_defs_types {
    const char *name;
    int type;
    const char *desc;
    struct def_values *values;
    bool (*callback)(const char *file, int line, int column, const union sudo_defs_val *, int op);
    union sudo_defs_val sd_un;
};

/*
 * Defaults values to apply before others.
 */
struct early_default {
    short idx;
    short run_callback;
    short line;
    short column;
    char *file;
};

/*
 * Four types of defaults: strings, integers, and flags.
 * Also, T_INT, T_TIMESPEC or T_STR may be ANDed with T_BOOL to indicate that
 * a value is not required.  Flags are boolean by nature...
 */
#undef T_INT
#define T_INT		0x001
#undef T_UINT
#define T_UINT		0x002
#undef T_STR
#define T_STR		0x003
#undef T_FLAG
#define T_FLAG		0x004
#undef T_MODE
#define T_MODE		0x005
#undef T_LIST
#define T_LIST		0x006
#undef T_LOGFAC
#define T_LOGFAC	0x007
#undef T_LOGPRI
#define T_LOGPRI	0x008
#undef T_TUPLE
#define T_TUPLE		0x009
#undef T_TIMESPEC
#define T_TIMESPEC	0x010
#undef T_TIMEOUT
#define T_TIMEOUT	0x011
#undef T_RLIMIT
#define T_RLIMIT	0x012
#undef T_MASK
#define T_MASK		0x0FF
#undef T_BOOL
#define T_BOOL		0x100
#undef T_PATH
#define T_PATH		0x200
#undef T_CHPATH
#define T_CHPATH	0x400
#undef T_SPACE
#define T_SPACE		0x800

/*
 * Argument to update_defaults()
 */
#define SETDEF_GENERIC	0x01
#define	SETDEF_HOST	0x02
#define	SETDEF_USER	0x04
#define	SETDEF_RUNAS	0x08
#define	SETDEF_CMND	0x10
#define SETDEF_ALL	(SETDEF_GENERIC|SETDEF_HOST|SETDEF_USER|SETDEF_RUNAS|SETDEF_CMND)

/*
 * Convenience macros
 */
#define iolog_enabled   (def_log_stdin || def_log_ttyin || def_log_stdout || def_log_stderr || def_log_ttyout)

/*
 * Prototypes
 */
struct defaults_list;
struct sudoers_parse_tree;
void dump_default(void);
bool init_defaults(void);
bool set_default(const char *var, const char *val, int op, const char *file, int line, int column, bool quiet);
bool update_defaults(struct sudoers_parse_tree *parse_tree, struct defaults_list *defs, int what, bool quiet);
bool check_defaults(struct sudoers_parse_tree *parse_tree, bool quiet);
bool append_default(const char *var, const char *val, int op, char *source, struct defaults_list *defs);
bool cb_passprompt_regex(const char *file, int line, int column, const union sudo_defs_val *sd_un, int op);

extern struct sudo_defs_types sudo_defs_table[];

#endif /* SUDOERS_DEFAULTS_H */