1 /* 2 * SPDX-License-Identifier: ISC 3 * 4 * Copyright (c) 1999-2005, 2008-2020 5 * Todd C. Miller <Todd.Miller@sudo.ws> 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 char *sval; /* string value */ 47 enum def_tuple nval;/* numeric value */ 48 }; 49 50 union sudo_defs_val { 51 int 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 sudo_defs_types { 65 char *name; 66 int type; 67 char *desc; 68 struct def_values *values; 69 bool (*callback)(const union sudo_defs_val *); 70 union sudo_defs_val sd_un; 71 }; 72 73 /* 74 * Defaults values to apply before others. 75 */ 76 struct early_default { 77 short idx; 78 short run_callback; 79 }; 80 81 /* 82 * Four types of defaults: strings, integers, and flags. 83 * Also, T_INT, T_TIMESPEC or T_STR may be ANDed with T_BOOL to indicate that 84 * a value is not required. Flags are boolean by nature... 85 */ 86 #undef T_INT 87 #define T_INT 0x001 88 #undef T_UINT 89 #define T_UINT 0x002 90 #undef T_STR 91 #define T_STR 0x003 92 #undef T_FLAG 93 #define T_FLAG 0x004 94 #undef T_MODE 95 #define T_MODE 0x005 96 #undef T_LIST 97 #define T_LIST 0x006 98 #undef T_LOGFAC 99 #define T_LOGFAC 0x007 100 #undef T_LOGPRI 101 #define T_LOGPRI 0x008 102 #undef T_TUPLE 103 #define T_TUPLE 0x009 104 #undef T_TIMESPEC 105 #define T_TIMESPEC 0x010 106 #undef T_TIMEOUT 107 #define T_TIMEOUT 0x011 108 #undef T_MASK 109 #define T_MASK 0x0FF 110 #undef T_BOOL 111 #define T_BOOL 0x100 112 #undef T_PATH 113 #define T_PATH 0x200 114 #undef T_CHPATH 115 #define T_CHPATH 0x400 116 117 /* 118 * Argument to update_defaults() 119 */ 120 #define SETDEF_GENERIC 0x01 121 #define SETDEF_HOST 0x02 122 #define SETDEF_USER 0x04 123 #define SETDEF_RUNAS 0x08 124 #define SETDEF_CMND 0x10 125 #define SETDEF_ALL (SETDEF_GENERIC|SETDEF_HOST|SETDEF_USER|SETDEF_RUNAS|SETDEF_CMND) 126 127 /* 128 * Prototypes 129 */ 130 struct defaults_list; 131 struct sudoers_parse_tree; 132 void dump_default(void); 133 bool init_defaults(void); 134 struct early_default *is_early_default(const char *name); 135 bool run_early_defaults(void); 136 bool set_early_default(const char *var, const char *val, int op, const char *file, int line, int column, bool quiet, struct early_default *early); 137 bool set_default(const char *var, const char *val, int op, const char *file, int line, int column, bool quiet); 138 bool update_defaults(struct sudoers_parse_tree *parse_tree, struct defaults_list *defs, int what, bool quiet); 139 bool check_defaults(struct sudoers_parse_tree *parse_tree, bool quiet); 140 bool append_default(const char *var, const char *val, int op, char *source, struct defaults_list *defs); 141 142 extern struct sudo_defs_types sudo_defs_table[]; 143 144 #endif /* SUDOERS_DEFAULTS_H */ 145