Imported Upstream version 1.8.1p2
[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 #ifdef HAVE_MBR_CHECK_MEMBERSHIP
39 # include <membership.h>
40 #endif
41
42 /*
43  * Info pertaining to the invoking user.
44  */
45 struct sudo_user {
46     struct passwd *pw;
47     struct passwd *_runas_pw;
48     struct group *_runas_gr;
49     struct stat *cmnd_stat;
50     char *name;
51     char *path;
52     char *tty;
53     char *ttypath;
54     char *host;
55     char *shost;
56     char *prompt;
57     char *cmnd;
58     char *cmnd_args;
59     char *cmnd_base;
60     char *cmnd_safe;
61     char *class_name;
62     char *krb5_ccname;
63     int   closefrom;
64     int   ngroups;
65     uid_t uid;
66     uid_t gid;
67     int   lines;
68     int   cols;
69     GETGROUPS_T *groups;
70     char * const * env_vars;
71 #ifdef HAVE_SELINUX
72     char *role;
73     char *type;
74 #endif
75     char *cwd;
76     char *iolog_file;
77 #ifdef HAVE_MBR_CHECK_MEMBERSHIP
78     uuid_t uuid;
79 #endif
80 };
81
82 /*
83  * Return values for sudoers_lookup(), also used as arguments for log_auth()
84  * Note: cannot use '0' as a value here.
85  */
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
94
95 /*
96  * Pseudo-boolean values
97  */
98 #undef TRUE
99 #define TRUE                     1
100 #undef FALSE
101 #define FALSE                    0
102
103 /*
104  * find_path()/load_cmnd() return values
105  */
106 #define FOUND                   0
107 #define NOT_FOUND               1
108 #define NOT_FOUND_DOT           2
109
110 /*
111  * Various modes sudo can be in (based on arguments) in hex
112  */
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
124
125 /* Mode flags */
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
135
136 /*
137  * Used with set_perms()
138  */
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
148
149 /*
150  * Shortcuts for sudo_user contents.
151  */
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)
179
180 #ifdef __TANDEM
181 # define ROOT_UID       65535
182 #else
183 # define ROOT_UID       0
184 #endif
185
186 /*
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
190  * system max.
191  */
192 #define SUDO_PASS_MAX   256
193
194 struct lbuf;
195 struct passwd;
196 struct stat;
197 struct timeval;
198
199 /*
200  * Function prototypes
201  */
202 #define YY_DECL int yylex(void)
203
204 /* goodpath.c */
205 char *sudo_goodpath(const char *, struct stat *);
206
207 /* findpath.c */
208 int find_path(char *, char **, struct stat *, char *, int);
209
210 /* check.c */
211 int check_user(int, int);
212 void remove_timestamp(int);
213 int user_is_exempt(void);
214
215 /* sudo_auth.c */
216 int verify_user(struct passwd *, char *);
217 int auth_begin_session(struct passwd *);
218 int auth_end_session();
219
220 /* parse.c */
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 *);
230
231 /* set_perms.c */
232 void rewind_perms(void);
233 int set_perms(int);
234 void restore_perms(void);
235 int pam_prep_user(struct passwd *);
236
237 /* gram.y */
238 int yyparse(void);
239
240 /* toke.l */
241 YY_DECL;
242
243 /* defaults.c */
244 void dump_defaults(void);
245 void dump_auth_methods(void);
246
247 /* getspwuid.c */
248 char *sudo_getepw(const struct passwd *);
249
250 /* zero_bytes.c */
251 void zero_bytes(volatile void *, size_t);
252
253 /* sudo_nss.c */
254 void display_privs(struct sudo_nss_list *, struct passwd *);
255 int display_cmnd(struct sudo_nss_list *, struct passwd *);
256
257 /* pwutil.c */
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 *);
275
276 /* timestr.c */
277 char *get_timestr(time_t, int);
278
279 /* atobool.c */
280 int atobool(const char *str);
281
282 /* boottime.c */
283 int get_boottime(struct timeval *);
284
285 /* iolog.c */
286 void io_nextid(char *iolog_dir, char sessid[7]);
287
288 /* iolog_path.c */
289 char *expand_iolog_path(const char *prefix, const char *dir, const char *file,
290     char **slashp);
291
292 /* env.c */
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[]);
300
301 /* fmt_string.c */
302 char *fmt_string(const char *, const char *);
303
304 /* sudoers.c */
305 void plugin_cleanup(int);
306 void set_fqdn(void);
307 FILE *open_sudoers(const char *, int, int *);
308
309 /* aix.c */
310 void aix_restoreauthdb(void);
311 void aix_setauthdb(char *user);
312
313 /* group_plugin.c */
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);
318
319 #ifndef _SUDO_MAIN
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;
331 #endif
332
333 /* Some systems don't declare errno in errno.h */
334 #ifndef errno
335 extern int errno;
336 #endif
337
338 #endif /* _SUDO_SUDOERS_H */