man pages get built in the build- directories
[debian/sudo] / sudo.h
1 /*
2  * Copyright (c) 1993-1996, 1998-2005, 2007-2008
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  * $Sudo: sudo.h,v 1.269 2008/11/25 17:01:34 millert Exp $
22  */
23
24 #ifndef _SUDO_SUDO_H
25 #define _SUDO_SUDO_H
26
27 #include <pathnames.h>
28 #include <limits.h>
29 #include "compat.h"
30 #include "defaults.h"
31 #include "error.h"
32 #include "list.h"
33 #include "logging.h"
34 #include "sudo_nss.h"
35
36 /*
37  * Info pertaining to the invoking user.
38  */
39 struct sudo_user {
40     struct passwd *pw;
41     struct passwd *_runas_pw;
42     struct group *_runas_gr;
43     struct stat *cmnd_stat;
44     char *path;
45     char *shell;
46     char *tty;
47     char *ttypath;
48     char *host;
49     char *shost;
50     int   host_fqdn_queried;
51     char **runas;
52     char *prompt;
53     char *cmnd;
54     char *cmnd_args;
55     char *cmnd_base;
56     char *cmnd_safe;
57     char *class_name;
58     char *krb5_ccname;
59     char *display;
60     char *askpass;
61     int   ngroups;
62     GETGROUPS_T *groups;
63     struct list_member *env_vars;
64 #ifdef HAVE_SELINUX
65     char *role;
66     char *type;
67 #endif
68     char  cwd[PATH_MAX];
69 };
70
71 /*
72  * Return values for sudoers_lookup(), also used as arguments for log_auth()
73  * Note: cannot use '0' as a value here.
74  */
75 /* XXX - VALIDATE_SUCCESS and VALIDATE_FAILURE instead? */
76 #define VALIDATE_ERROR          0x001
77 #define VALIDATE_OK             0x002
78 #define VALIDATE_NOT_OK         0x004
79 #define FLAG_CHECK_USER         0x010
80 #define FLAG_NO_USER            0x020
81 #define FLAG_NO_HOST            0x040
82 #define FLAG_NO_CHECK           0x080
83
84 /*
85  * Pseudo-boolean values
86  */
87 #undef TRUE
88 #define TRUE                     1
89 #undef FALSE
90 #define FALSE                    0
91
92 /*
93  * find_path()/load_cmnd() return values
94  */
95 #define FOUND                    1
96 #define NOT_FOUND                0
97 #define NOT_FOUND_DOT           -1
98
99 /*
100  * Various modes sudo can be in (based on arguments) in hex
101  */
102 #define MODE_RUN                0x00000001
103 #define MODE_EDIT               0x00000002
104 #define MODE_VALIDATE           0x00000004
105 #define MODE_INVALIDATE         0x00000008
106 #define MODE_KILL               0x00000010
107 #define MODE_VERSION            0x00000020
108 #define MODE_HELP               0x00000040
109 #define MODE_LIST               0x00000080
110 #define MODE_CHECK              0x00000100
111 #define MODE_LISTDEFS           0x00000200
112 #define MODE_MASK               0x0000ffff
113
114 /* Mode flags */
115 #define MODE_BACKGROUND         0x00010000
116 #define MODE_SHELL              0x00020000
117 #define MODE_LOGIN_SHELL        0x00040000
118 #define MODE_IMPLIED_SHELL      0x00080000
119 #define MODE_RESET_HOME         0x00100000
120 #define MODE_PRESERVE_GROUPS    0x00200000
121 #define MODE_PRESERVE_ENV       0x00400000
122 #define MODE_NONINTERACTIVE     0x00800000
123
124 /*
125  * Used with set_perms()
126  */
127 #define PERM_ROOT                0x00
128 #define PERM_USER                0x01
129 #define PERM_FULL_USER           0x02
130 #define PERM_SUDOERS             0x03
131 #define PERM_RUNAS               0x04
132 #define PERM_FULL_RUNAS          0x05
133 #define PERM_TIMESTAMP           0x06
134
135 /*
136  * Shortcuts for sudo_user contents.
137  */
138 #define user_name               (sudo_user.pw->pw_name)
139 #define user_passwd             (sudo_user.pw->pw_passwd)
140 #define user_uid                (sudo_user.pw->pw_uid)
141 #define user_gid                (sudo_user.pw->pw_gid)
142 #define user_dir                (sudo_user.pw->pw_dir)
143 #define user_shell              (sudo_user.shell)
144 #define user_ngroups            (sudo_user.ngroups)
145 #define user_groups             (sudo_user.groups)
146 #define user_tty                (sudo_user.tty)
147 #define user_ttypath            (sudo_user.ttypath)
148 #define user_cwd                (sudo_user.cwd)
149 #define user_cmnd               (sudo_user.cmnd)
150 #define user_args               (sudo_user.cmnd_args)
151 #define user_base               (sudo_user.cmnd_base)
152 #define user_stat               (sudo_user.cmnd_stat)
153 #define user_path               (sudo_user.path)
154 #define user_prompt             (sudo_user.prompt)
155 #define user_host               (sudo_user.host)
156 #define user_shost              (sudo_user.shost)
157 #define user_ccname             (sudo_user.krb5_ccname)
158 #define user_display            (sudo_user.display)
159 #define user_askpass            (sudo_user.askpass)
160 #define safe_cmnd               (sudo_user.cmnd_safe)
161 #define login_class             (sudo_user.class_name)
162 #define runas_pw                (sudo_user._runas_pw)
163 #define runas_gr                (sudo_user._runas_gr)
164 #define user_role               (sudo_user.role)
165 #define user_type               (sudo_user.type)
166
167 /*
168  * We used to use the system definition of PASS_MAX or _PASSWD_LEN,
169  * but that caused problems with various alternate authentication
170  * methods.  So, we just define our own and assume that it is >= the
171  * system max.
172  */
173 #define SUDO_PASS_MAX   256
174
175 /*
176  * Flags for lock_file()
177  */
178 #define SUDO_LOCK       1               /* lock a file */
179 #define SUDO_TLOCK      2               /* test & lock a file (non-blocking) */
180 #define SUDO_UNLOCK     4               /* unlock a file */
181
182 /*
183  * Flags for tgetpass()
184  */
185 #define TGP_ECHO        0x01            /* leave echo on when reading passwd */
186 #define TGP_STDIN       0x02            /* read from stdin, not /dev/tty */
187 #define TGP_ASKPASS     0x04            /* read from askpass helper program */
188
189 struct lbuf;
190 struct passwd;
191 struct timespec;
192 struct timeval;
193
194 /*
195  * Function prototypes
196  */
197 #define YY_DECL int yylex __P((void))
198
199 #ifndef HAVE_CLOSEFROM
200 void closefrom          __P((int));
201 #endif
202 #ifndef HAVE_GETCWD
203 char *getcwd            __P((char *, size_t size));
204 #endif
205 #ifndef HAVE_UTIMES
206 int utimes              __P((const char *, const struct timeval *));
207 #endif
208 #ifdef HAVE_FUTIME
209 int futimes             __P((int, const struct timeval *));
210 #endif
211 #ifndef HAVE_SNPRINTF
212 int snprintf            __P((char *, size_t, const char *, ...))
213                             __printflike(3, 4);
214 #endif
215 #ifndef HAVE_VSNPRINTF
216 int vsnprintf           __P((char *, size_t, const char *, va_list))
217                             __printflike(3, 0);
218 #endif
219 #ifndef HAVE_ASPRINTF
220 int asprintf            __P((char **, const char *, ...))
221                             __printflike(2, 3);
222 #endif
223 #ifndef HAVE_VASPRINTF
224 int vasprintf           __P((char **, const char *, va_list))
225                             __printflike(2, 0);
226 #endif
227 #ifndef HAVE_STRCASECMP
228 int strcasecmp          __P((const char *, const char *));
229 #endif
230 #ifndef HAVE_STRLCAT
231 size_t strlcat          __P((char *, const char *, size_t));
232 #endif
233 #ifndef HAVE_STRLCPY
234 size_t strlcpy          __P((char *, const char *, size_t));
235 #endif
236 #ifndef HAVE_MEMRCHR
237 void *memrchr           __P((const void *, int, size_t));
238 #endif
239 #ifndef HAVE_MKSTEMP
240 int mkstemp             __P((char *));
241 #endif
242 char *sudo_goodpath     __P((const char *, struct stat *));
243 char *tgetpass          __P((const char *, int, int));
244 int find_path           __P((char *, char **, struct stat *, char *));
245 int tty_present         __P((void));
246 void check_user         __P((int, int));
247 void verify_user        __P((struct passwd *, char *));
248 #ifdef HAVE_LDAP
249 int sudo_ldap_open      __P((struct sudo_nss *));
250 int sudo_ldap_close     __P((struct sudo_nss *));
251 int sudo_ldap_setdefs   __P((struct sudo_nss *));
252 int sudo_ldap_lookup    __P((struct sudo_nss *, int, int));
253 int sudo_ldap_parse     __P((struct sudo_nss *));
254 int sudo_ldap_display_cmnd __P((struct sudo_nss *, struct passwd *));
255 int sudo_ldap_display_defaults __P((struct sudo_nss *, struct passwd *, struct lbuf *));
256 int sudo_ldap_display_bound_defaults __P((struct sudo_nss *, struct passwd *, struct lbuf *));
257 int sudo_ldap_display_privs __P((struct sudo_nss *, struct passwd *, struct lbuf *));
258 #endif
259 int sudo_file_open      __P((struct sudo_nss *));
260 int sudo_file_close     __P((struct sudo_nss *));
261 int sudo_file_setdefs   __P((struct sudo_nss *));
262 int sudo_file_lookup    __P((struct sudo_nss *, int, int));
263 int sudo_file_parse     __P((struct sudo_nss *));
264 int sudo_file_display_cmnd __P((struct sudo_nss *, struct passwd *));
265 int sudo_file_display_defaults __P((struct sudo_nss *, struct passwd *, struct lbuf *));
266 int sudo_file_display_bound_defaults __P((struct sudo_nss *, struct passwd *, struct lbuf *));
267 int sudo_file_display_privs __P((struct sudo_nss *, struct passwd *, struct lbuf *));
268 void set_perms          __P((int));
269 void remove_timestamp   __P((int));
270 int check_secureware    __P((char *));
271 void sia_attempt_auth   __P((void));
272 void pam_attempt_auth   __P((void));
273 int yyparse             __P((void));
274 void pass_warn          __P((FILE *));
275 void *emalloc           __P((size_t));
276 void *emalloc2          __P((size_t, size_t));
277 void *erealloc          __P((void *, size_t));
278 void *erealloc3         __P((void *, size_t, size_t));
279 char *estrdup           __P((const char *));
280 int easprintf           __P((char **, const char *, ...))
281                             __printflike(2, 3);
282 int evasprintf          __P((char **, const char *, va_list))
283                             __printflike(2, 0);
284 void efree              __P((void *));
285 void dump_defaults      __P((void));
286 void dump_auth_methods  __P((void));
287 void init_envtables     __P((void));
288 void read_env_file      __P((const char *, int));
289 int lock_file           __P((int, int));
290 int touch               __P((int, char *, struct timespec *));
291 int user_is_exempt      __P((void));
292 void set_fqdn           __P((void));
293 char *sudo_getepw       __P((const struct passwd *));
294 int pam_prep_user       __P((struct passwd *));
295 void zero_bytes         __P((volatile void *, size_t));
296 int gettime             __P((struct timespec *));
297 FILE *open_sudoers      __P((const char *, int *));
298 void display_privs      __P((struct sudo_nss_list *, struct passwd *));
299 int display_cmnd        __P((struct sudo_nss_list *, struct passwd *));
300 int get_ttycols         __P((void));
301 char *sudo_parseln      __P((FILE *));
302 void sudo_setenv        __P((const char *, const char *, int));
303 void sudo_unsetenv      __P((const char *));
304 void sudo_setgrent      __P((void));
305 void sudo_endgrent      __P((void));
306 void sudo_setpwent      __P((void));
307 void sudo_endpwent      __P((void));
308 void sudo_setspent      __P((void));
309 void sudo_endspent      __P((void));
310 void cleanup            __P((int));
311 struct passwd *sudo_getpwnam __P((const char *));
312 struct passwd *sudo_fakepwnam __P((const char *, gid_t));
313 struct passwd *sudo_getpwuid __P((uid_t));
314 struct group *sudo_getgrnam __P((const char *));
315 struct group *sudo_fakegrnam __P((const char *));
316 struct group *sudo_getgrgid __P((gid_t));
317 #ifdef HAVE_SELINUX
318 void selinux_exec __P((char *, char *, char **, int));
319 #endif
320 #ifdef HAVE_GETUSERATTR
321 void aix_setlimits __P((char *));
322 #endif
323 YY_DECL;
324
325 /* Only provide extern declarations outside of sudo.c. */
326 #ifndef _SUDO_MAIN
327 extern struct sudo_user sudo_user;
328 extern struct passwd *auth_pw, *list_pw;
329
330 extern int tgetpass_flags;
331 extern int long_list;
332 extern uid_t timestamp_uid;
333 #endif
334 #ifndef errno
335 extern int errno;
336 #endif
337
338 #endif /* _SUDO_SUDO_H */