Imported Upstream version 1.8.2
[debian/sudo] / plugins / sudoers / sudoers.h
1 /*
2  * Copyright (c) 1993-1996, 1998-2005, 2007-2011
3  *      Todd C. Miller <Todd.Miller@courtesan.com>
4  *
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.
8  *
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.
16  *
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.
20  */
21
22 #ifndef _SUDO_SUDOERS_H
23 #define _SUDO_SUDOERS_H
24
25 #include <limits.h>
26
27 #include <pathnames.h>
28 #include "missing.h"
29 #include "error.h"
30 #include "alloc.h"
31 #include "list.h"
32 #include "fileops.h"
33 #include "defaults.h"
34 #include "logging.h"
35 #include "sudo_nss.h"
36 #include "sudo_plugin.h"
37
38 #define DEFAULT_TEXT_DOMAIN     "sudoers"
39 #include "gettext.h"
40
41 /*
42  * Password db and supplementary group IDs with associated group names.
43  */
44 struct group_list {
45     char **groups;
46     GETGROUPS_T *gids;
47     int ngroups;
48     int ngids;
49 };
50
51 /*
52  * Info pertaining to the invoking user.
53  */
54 struct sudo_user {
55     struct passwd *pw;
56     struct passwd *_runas_pw;
57     struct group *_runas_gr;
58     struct stat *cmnd_stat;
59     char *name;
60     char *path;
61     char *tty;
62     char *ttypath;
63     char *host;
64     char *shost;
65     char *prompt;
66     char *cmnd;
67     char *cmnd_args;
68     char *cmnd_base;
69     char *cmnd_safe;
70     char *class_name;
71     char *krb5_ccname;
72     struct group_list *group_list;
73     char * const * env_vars;
74 #ifdef HAVE_SELINUX
75     char *role;
76     char *type;
77 #endif
78     char *cwd;
79     char *iolog_file;
80     int   closefrom;
81     int   lines;
82     int   cols;
83     uid_t uid;
84     uid_t gid;
85 };
86
87 /*
88  * Return values for sudoers_lookup(), also used as arguments for log_auth()
89  * Note: cannot use '0' as a value here.
90  */
91 /* XXX - VALIDATE_SUCCESS and VALIDATE_FAILURE instead? */
92 #define VALIDATE_ERROR          0x001
93 #define VALIDATE_OK             0x002
94 #define VALIDATE_NOT_OK         0x004
95 #define FLAG_CHECK_USER         0x010
96 #define FLAG_NO_USER            0x020
97 #define FLAG_NO_HOST            0x040
98 #define FLAG_NO_CHECK           0x080
99
100 /*
101  * Pseudo-boolean values
102  */
103 #undef TRUE
104 #define TRUE                     1
105 #undef FALSE
106 #define FALSE                    0
107
108 /*
109  * find_path()/load_cmnd() return values
110  */
111 #define FOUND                   0
112 #define NOT_FOUND               1
113 #define NOT_FOUND_DOT           2
114
115 /*
116  * Various modes sudo can be in (based on arguments) in hex
117  */
118 #define MODE_RUN                0x00000001
119 #define MODE_EDIT               0x00000002
120 #define MODE_VALIDATE           0x00000004
121 #define MODE_INVALIDATE         0x00000008
122 #define MODE_KILL               0x00000010
123 #define MODE_VERSION            0x00000020
124 #define MODE_HELP               0x00000040
125 #define MODE_LIST               0x00000080
126 #define MODE_CHECK              0x00000100
127 #define MODE_LISTDEFS           0x00000200
128 #define MODE_MASK               0x0000ffff
129
130 /* Mode flags */
131 #define MODE_BACKGROUND         0x00010000 /* XXX - unused */
132 #define MODE_SHELL              0x00020000
133 #define MODE_LOGIN_SHELL        0x00040000
134 #define MODE_IMPLIED_SHELL      0x00080000
135 #define MODE_RESET_HOME         0x00100000
136 #define MODE_PRESERVE_GROUPS    0x00200000
137 #define MODE_PRESERVE_ENV       0x00400000
138 #define MODE_NONINTERACTIVE     0x00800000
139 #define MODE_IGNORE_TICKET      0x01000000
140
141 /*
142  * Used with set_perms()
143  */
144 #define PERM_INITIAL             0x00
145 #define PERM_ROOT                0x01
146 #define PERM_USER                0x02
147 #define PERM_FULL_USER           0x03
148 #define PERM_SUDOERS             0x04
149 #define PERM_RUNAS               0x05
150 #define PERM_TIMESTAMP           0x06
151 #define PERM_NOEXIT              0x10 /* flag */
152 #define PERM_MASK                0xf0
153
154 /*
155  * Shortcuts for sudo_user contents.
156  */
157 #define user_name               (sudo_user.name)
158 #define user_uid                (sudo_user.uid)
159 #define user_gid                (sudo_user.gid)
160 #define user_passwd             (sudo_user.pw->pw_passwd)
161 #define user_uuid               (sudo_user.uuid)
162 #define user_dir                (sudo_user.pw->pw_dir)
163 #define user_group_list         (sudo_user.group_list)
164 #define user_tty                (sudo_user.tty)
165 #define user_ttypath            (sudo_user.ttypath)
166 #define user_cwd                (sudo_user.cwd)
167 #define user_cmnd               (sudo_user.cmnd)
168 #define user_args               (sudo_user.cmnd_args)
169 #define user_base               (sudo_user.cmnd_base)
170 #define user_stat               (sudo_user.cmnd_stat)
171 #define user_path               (sudo_user.path)
172 #define user_prompt             (sudo_user.prompt)
173 #define user_host               (sudo_user.host)
174 #define user_shost              (sudo_user.shost)
175 #define user_ccname             (sudo_user.krb5_ccname)
176 #define safe_cmnd               (sudo_user.cmnd_safe)
177 #define login_class             (sudo_user.class_name)
178 #define runas_pw                (sudo_user._runas_pw)
179 #define runas_gr                (sudo_user._runas_gr)
180 #define user_role               (sudo_user.role)
181 #define user_type               (sudo_user.type)
182 #define user_closefrom          (sudo_user.closefrom)
183
184 #ifdef __TANDEM
185 # define ROOT_UID       65535
186 #else
187 # define ROOT_UID       0
188 #endif
189
190 /*
191  * We used to use the system definition of PASS_MAX or _PASSWD_LEN,
192  * but that caused problems with various alternate authentication
193  * methods.  So, we just define our own and assume that it is >= the
194  * system max.
195  */
196 #define SUDO_PASS_MAX   256
197
198 struct lbuf;
199 struct passwd;
200 struct stat;
201 struct timeval;
202
203 /*
204  * Function prototypes
205  */
206 #define YY_DECL int yylex(void)
207
208 /* goodpath.c */
209 char *sudo_goodpath(const char *, struct stat *);
210
211 /* findpath.c */
212 int find_path(char *, char **, struct stat *, char *, int);
213
214 /* check.c */
215 int check_user(int, int);
216 void remove_timestamp(int);
217 int user_is_exempt(void);
218
219 /* sudo_auth.c */
220 int verify_user(struct passwd *, char *);
221 int auth_begin_session(struct passwd *);
222 int auth_end_session();
223
224 /* parse.c */
225 int sudo_file_open(struct sudo_nss *);
226 int sudo_file_close(struct sudo_nss *);
227 int sudo_file_setdefs(struct sudo_nss *);
228 int sudo_file_lookup(struct sudo_nss *, int, int);
229 int sudo_file_parse(struct sudo_nss *);
230 int sudo_file_display_cmnd(struct sudo_nss *, struct passwd *);
231 int sudo_file_display_defaults(struct sudo_nss *, struct passwd *, struct lbuf *);
232 int sudo_file_display_bound_defaults(struct sudo_nss *, struct passwd *, struct lbuf *);
233 int sudo_file_display_privs(struct sudo_nss *, struct passwd *, struct lbuf *);
234
235 /* set_perms.c */
236 void rewind_perms(void);
237 int set_perms(int);
238 void restore_perms(void);
239 int pam_prep_user(struct passwd *);
240
241 /* gram.y */
242 int yyparse(void);
243
244 /* toke.l */
245 YY_DECL;
246
247 /* defaults.c */
248 void dump_defaults(void);
249 void dump_auth_methods(void);
250
251 /* getspwuid.c */
252 char *sudo_getepw(const struct passwd *);
253
254 /* zero_bytes.c */
255 void zero_bytes(volatile void *, size_t);
256
257 /* sudo_nss.c */
258 void display_privs(struct sudo_nss_list *, struct passwd *);
259 int display_cmnd(struct sudo_nss_list *, struct passwd *);
260
261 /* pwutil.c */
262 void sudo_setgrent(void);
263 void sudo_endgrent(void);
264 void sudo_setpwent(void);
265 void sudo_endpwent(void);
266 void sudo_setspent(void);
267 void sudo_endspent(void);
268 struct group_list *get_group_list(struct passwd *pw);
269 void set_group_list(const char *, GETGROUPS_T *gids, int ngids);
270 struct passwd *sudo_getpwnam(const char *);
271 struct passwd *sudo_fakepwnam(const char *, gid_t);
272 struct passwd *sudo_getpwuid(uid_t);
273 struct group *sudo_getgrnam(const char *);
274 struct group *sudo_fakegrnam(const char *);
275 struct group *sudo_getgrgid(gid_t);
276 void grlist_addref(struct group_list *);
277 void grlist_delref(struct group_list *);
278 void gr_addref(struct group *);
279 void gr_delref(struct group *);
280 void pw_addref(struct passwd *);
281 void pw_delref(struct passwd *);
282 int user_in_group(struct passwd *, const char *);
283
284 /* timestr.c */
285 char *get_timestr(time_t, int);
286
287 /* atobool.c */
288 int atobool(const char *str);
289
290 /* boottime.c */
291 int get_boottime(struct timeval *);
292
293 /* iolog.c */
294 void io_nextid(char *iolog_dir, char sessid[7]);
295
296 /* iolog_path.c */
297 char *expand_iolog_path(const char *prefix, const char *dir, const char *file,
298     char **slashp);
299
300 /* env.c */
301 char **env_get(void);
302 void env_init(char * const envp[]);
303 void init_envtables(void);
304 void insert_env_vars(char * const envp[]);
305 void read_env_file(const char *, int);
306 void rebuild_env(void);
307 void validate_env_vars(char * const envp[]);
308
309 /* fmt_string.c */
310 char *fmt_string(const char *, const char *);
311
312 /* sudoers.c */
313 void plugin_cleanup(int);
314 void set_fqdn(void);
315 FILE *open_sudoers(const char *, int, int *);
316
317 /* aix.c */
318 void aix_restoreauthdb(void);
319 void aix_setauthdb(char *user);
320
321 /* group_plugin.c */
322 int group_plugin_load(char *plugin_info);
323 void group_plugin_unload(void);
324 int group_plugin_query(const char *user, const char *group,
325     const struct passwd *pwd);
326
327 /* setgroups.c */
328 int sudo_setgroups(int ngids, const GETGROUPS_T *gids);
329
330 #ifndef _SUDO_MAIN
331 extern struct sudo_user sudo_user;
332 extern struct passwd *list_pw;
333 extern const char *sudoers_file;
334 extern mode_t sudoers_mode;
335 extern uid_t sudoers_uid;
336 extern gid_t sudoers_gid;
337 extern int long_list;
338 extern int sudo_mode;
339 extern uid_t timestamp_uid;
340 extern sudo_conv_t sudo_conv;
341 extern sudo_printf_t sudo_printf;
342 #endif
343
344 /* Some systems don't declare errno in errno.h */
345 #ifndef errno
346 extern int errno;
347 #endif
348
349 #endif /* _SUDO_SUDOERS_H */