2 * Copyright (c) 1993-1996, 1998-2005, 2007-2011
3 * Todd C. Miller <Todd.Miller@courtesan.com>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 * Sponsored in part by the Defense Advanced Research Projects
18 * Agency (DARPA) and Air Force Research Laboratory, Air Force
19 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
22 #ifndef _SUDO_SUDOERS_H
23 #define _SUDO_SUDOERS_H
27 #include <pathnames.h>
36 #include "sudo_plugin.h"
38 #ifdef HAVE_MBR_CHECK_MEMBERSHIP
39 # include <membership.h>
43 * Info pertaining to the invoking user.
47 struct passwd *_runas_pw;
48 struct group *_runas_gr;
49 struct stat *cmnd_stat;
70 char * const * env_vars;
77 #ifdef HAVE_MBR_CHECK_MEMBERSHIP
83 * Return values for sudoers_lookup(), also used as arguments for log_auth()
84 * Note: cannot use '0' as a value here.
86 /* XXX - VALIDATE_SUCCESS and VALIDATE_FAILURE instead? */
87 #define VALIDATE_ERROR 0x001
88 #define VALIDATE_OK 0x002
89 #define VALIDATE_NOT_OK 0x004
90 #define FLAG_CHECK_USER 0x010
91 #define FLAG_NO_USER 0x020
92 #define FLAG_NO_HOST 0x040
93 #define FLAG_NO_CHECK 0x080
96 * Pseudo-boolean values
104 * find_path()/load_cmnd() return values
108 #define NOT_FOUND_DOT 2
111 * Various modes sudo can be in (based on arguments) in hex
113 #define MODE_RUN 0x00000001
114 #define MODE_EDIT 0x00000002
115 #define MODE_VALIDATE 0x00000004
116 #define MODE_INVALIDATE 0x00000008
117 #define MODE_KILL 0x00000010
118 #define MODE_VERSION 0x00000020
119 #define MODE_HELP 0x00000040
120 #define MODE_LIST 0x00000080
121 #define MODE_CHECK 0x00000100
122 #define MODE_LISTDEFS 0x00000200
123 #define MODE_MASK 0x0000ffff
126 #define MODE_BACKGROUND 0x00010000 /* XXX - unused */
127 #define MODE_SHELL 0x00020000
128 #define MODE_LOGIN_SHELL 0x00040000
129 #define MODE_IMPLIED_SHELL 0x00080000
130 #define MODE_RESET_HOME 0x00100000
131 #define MODE_PRESERVE_GROUPS 0x00200000
132 #define MODE_PRESERVE_ENV 0x00400000
133 #define MODE_NONINTERACTIVE 0x00800000
134 #define MODE_IGNORE_TICKET 0x01000000
137 * Used with set_perms()
139 #define PERM_INITIAL 0x00
140 #define PERM_ROOT 0x01
141 #define PERM_USER 0x02
142 #define PERM_FULL_USER 0x03
143 #define PERM_SUDOERS 0x04
144 #define PERM_RUNAS 0x05
145 #define PERM_TIMESTAMP 0x06
146 #define PERM_NOEXIT 0x10 /* flag */
147 #define PERM_MASK 0xf0
150 * Shortcuts for sudo_user contents.
152 #define user_name (sudo_user.name)
153 #define user_uid (sudo_user.uid)
154 #define user_gid (sudo_user.gid)
155 #define user_passwd (sudo_user.pw->pw_passwd)
156 #define user_uuid (sudo_user.uuid)
157 #define user_dir (sudo_user.pw->pw_dir)
158 #define user_ngroups (sudo_user.ngroups)
159 #define user_groups (sudo_user.groups)
160 #define user_tty (sudo_user.tty)
161 #define user_ttypath (sudo_user.ttypath)
162 #define user_cwd (sudo_user.cwd)
163 #define user_cmnd (sudo_user.cmnd)
164 #define user_args (sudo_user.cmnd_args)
165 #define user_base (sudo_user.cmnd_base)
166 #define user_stat (sudo_user.cmnd_stat)
167 #define user_path (sudo_user.path)
168 #define user_prompt (sudo_user.prompt)
169 #define user_host (sudo_user.host)
170 #define user_shost (sudo_user.shost)
171 #define user_ccname (sudo_user.krb5_ccname)
172 #define safe_cmnd (sudo_user.cmnd_safe)
173 #define login_class (sudo_user.class_name)
174 #define runas_pw (sudo_user._runas_pw)
175 #define runas_gr (sudo_user._runas_gr)
176 #define user_role (sudo_user.role)
177 #define user_type (sudo_user.type)
178 #define user_closefrom (sudo_user.closefrom)
181 # define ROOT_UID 65535
187 * We used to use the system definition of PASS_MAX or _PASSWD_LEN,
188 * but that caused problems with various alternate authentication
189 * methods. So, we just define our own and assume that it is >= the
192 #define SUDO_PASS_MAX 256
200 * Function prototypes
202 #define YY_DECL int yylex(void)
205 char *sudo_goodpath(const char *, struct stat *);
208 int find_path(char *, char **, struct stat *, char *, int);
211 int check_user(int, int);
212 void remove_timestamp(int);
213 int user_is_exempt(void);
216 int verify_user(struct passwd *, char *);
217 int auth_begin_session(struct passwd *);
218 int auth_end_session();
221 int sudo_file_open(struct sudo_nss *);
222 int sudo_file_close(struct sudo_nss *);
223 int sudo_file_setdefs(struct sudo_nss *);
224 int sudo_file_lookup(struct sudo_nss *, int, int);
225 int sudo_file_parse(struct sudo_nss *);
226 int sudo_file_display_cmnd(struct sudo_nss *, struct passwd *);
227 int sudo_file_display_defaults(struct sudo_nss *, struct passwd *, struct lbuf *);
228 int sudo_file_display_bound_defaults(struct sudo_nss *, struct passwd *, struct lbuf *);
229 int sudo_file_display_privs(struct sudo_nss *, struct passwd *, struct lbuf *);
232 void rewind_perms(void);
234 void restore_perms(void);
235 int pam_prep_user(struct passwd *);
244 void dump_defaults(void);
245 void dump_auth_methods(void);
248 char *sudo_getepw(const struct passwd *);
251 void zero_bytes(volatile void *, size_t);
254 void display_privs(struct sudo_nss_list *, struct passwd *);
255 int display_cmnd(struct sudo_nss_list *, struct passwd *);
258 void sudo_setgrent(void);
259 void sudo_endgrent(void);
260 void sudo_setpwent(void);
261 void sudo_endpwent(void);
262 void sudo_setspent(void);
263 void sudo_endspent(void);
264 struct passwd *sudo_getpwnam(const char *);
265 struct passwd *sudo_fakepwnam(const char *, gid_t);
266 struct passwd *sudo_getpwuid(uid_t);
267 struct group *sudo_getgrnam(const char *);
268 struct group *sudo_fakegrnam(const char *);
269 struct group *sudo_getgrgid(gid_t);
270 void gr_addref(struct group *);
271 void gr_delref(struct group *);
272 void pw_addref(struct passwd *);
273 void pw_delref(struct passwd *);
274 int user_in_group(struct passwd *, const char *);
277 char *get_timestr(time_t, int);
280 int atobool(const char *str);
283 int get_boottime(struct timeval *);
286 void io_nextid(char *iolog_dir, char sessid[7]);
289 char *expand_iolog_path(const char *prefix, const char *dir, const char *file,
293 char **env_get(void);
294 void env_init(char * const envp[]);
295 void init_envtables(void);
296 void insert_env_vars(char * const envp[]);
297 void read_env_file(const char *, int);
298 void rebuild_env(void);
299 void validate_env_vars(char * const envp[]);
302 char *fmt_string(const char *, const char *);
305 void plugin_cleanup(int);
307 FILE *open_sudoers(const char *, int, int *);
310 void aix_restoreauthdb(void);
311 void aix_setauthdb(char *user);
314 int group_plugin_load(char *plugin_info);
315 void group_plugin_unload(void);
316 int group_plugin_query(const char *user, const char *group,
317 const struct passwd *pwd);
320 extern struct sudo_user sudo_user;
321 extern struct passwd *list_pw;
322 extern const char *sudoers_file;
323 extern mode_t sudoers_mode;
324 extern uid_t sudoers_uid;
325 extern gid_t sudoers_gid;
326 extern int long_list;
327 extern int sudo_mode;
328 extern uid_t timestamp_uid;
329 extern sudo_conv_t sudo_conv;
330 extern sudo_printf_t sudo_printf;
333 /* Some systems don't declare errno in errno.h */
338 #endif /* _SUDO_SUDOERS_H */