Imported Upstream version 1.6.9p14
[debian/sudo] / sudo.h
1 /*
2  * Copyright (c) 1993-1996,1998-2007 Todd C. Miller <Todd.Miller@courtesan.com>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  *
16  * Sponsored in part by the Defense Advanced Research Projects
17  * Agency (DARPA) and Air Force Research Laboratory, Air Force
18  * Materiel Command, USAF, under agreement number F39502-99-1-0512.
19  *
20  * $Sudo: sudo.h,v 1.209.2.14 2008/02/09 14:44:48 millert Exp $
21  */
22
23 #ifndef _SUDO_SUDO_H
24 #define _SUDO_SUDO_H
25
26 #include <pathnames.h>
27 #include <limits.h>
28 #include "compat.h"
29 #include "defaults.h"
30 #include "logging.h"
31
32 /*
33  * Info pertaining to the invoking user.
34  */
35 struct sudo_user {
36     struct passwd *pw;
37     struct passwd *_runas_pw;
38     struct stat *cmnd_stat;
39     char *path;
40     char *shell;
41     char *tty;
42     char *ttypath;
43     char  cwd[PATH_MAX];
44     char *host;
45     char *shost;
46     char **runas;
47     char *prompt;
48     char *cmnd;
49     char *cmnd_args;
50     char *cmnd_base;
51     char *cmnd_safe;
52     char *class_name;
53     int ngroups;
54     GETGROUPS_T *groups;
55     struct list_member *env_vars;
56 #ifdef HAVE_SELINUX
57     char *role;
58     char *type;
59 #endif
60 };
61
62 /*
63  * Return values for sudoers_lookup(), also used as arguments for log_auth()
64  * Note: cannot use '0' as a value here.
65  */
66 /* XXX - VALIDATE_SUCCESS and VALIDATE_FAILURE instead? */
67 #define VALIDATE_ERROR          0x001
68 #define VALIDATE_OK             0x002
69 #define VALIDATE_NOT_OK         0x004
70 #define FLAG_CHECK_USER         0x010
71 #define FLAG_NOPASS             0x020
72 #define FLAG_NO_USER            0x040
73 #define FLAG_NO_HOST            0x080
74 #define FLAG_NO_CHECK           0x100
75 #define FLAG_NOEXEC             0x200
76 #define FLAG_SETENV             0x400
77
78 /*
79  * Pseudo-boolean values
80  */
81 #undef TRUE
82 #define TRUE                     1
83 #undef FALSE
84 #define FALSE                    0
85 #undef IMPLIED
86 #define IMPLIED                  2
87 #undef NOMATCH
88 #define NOMATCH                 -1
89 #undef UNSPEC
90 #define UNSPEC                  -2
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                0x0001
103 #define MODE_EDIT               0x0002
104 #define MODE_VALIDATE           0x0004
105 #define MODE_INVALIDATE         0x0008
106 #define MODE_KILL               0x0010
107 #define MODE_VERSION            0x0020
108 #define MODE_HELP               0x0040
109 #define MODE_LIST               0x0080
110 #define MODE_LISTDEFS           0x0100
111 #define MODE_BACKGROUND         0x0200
112 #define MODE_SHELL              0x0400
113 #define MODE_LOGIN_SHELL        0x0800
114 #define MODE_IMPLIED_SHELL      0x1000
115 #define MODE_RESET_HOME         0x2000
116 #define MODE_PRESERVE_GROUPS    0x4000
117 #define MODE_PRESERVE_ENV       0x8000
118
119 /*
120  * Used with set_perms()
121  */
122 #define PERM_ROOT                0x00
123 #define PERM_USER                0x01
124 #define PERM_FULL_USER           0x02
125 #define PERM_SUDOERS             0x03
126 #define PERM_RUNAS               0x04
127 #define PERM_FULL_RUNAS          0x05
128 #define PERM_TIMESTAMP           0x06
129
130 /*
131  * Shortcuts for sudo_user contents.
132  */
133 #define user_name               (sudo_user.pw->pw_name)
134 #define user_passwd             (sudo_user.pw->pw_passwd)
135 #define user_uid                (sudo_user.pw->pw_uid)
136 #define user_gid                (sudo_user.pw->pw_gid)
137 #define user_dir                (sudo_user.pw->pw_dir)
138 #define user_shell              (sudo_user.shell)
139 #define user_ngroups            (sudo_user.ngroups)
140 #define user_groups             (sudo_user.groups)
141 #define user_tty                (sudo_user.tty)
142 #define user_ttypath            (sudo_user.ttypath)
143 #define user_cwd                (sudo_user.cwd)
144 #define user_runas              (sudo_user.runas)
145 #define user_cmnd               (sudo_user.cmnd)
146 #define user_args               (sudo_user.cmnd_args)
147 #define user_base               (sudo_user.cmnd_base)
148 #define user_stat               (sudo_user.cmnd_stat)
149 #define user_path               (sudo_user.path)
150 #define user_prompt             (sudo_user.prompt)
151 #define user_host               (sudo_user.host)
152 #define user_shost              (sudo_user.shost)
153 #define safe_cmnd               (sudo_user.cmnd_safe)
154 #define login_class             (sudo_user.class_name)
155 #define runas_pw                (sudo_user._runas_pw)
156 #define user_role               (sudo_user.role)
157 #define user_type               (sudo_user.type)
158
159 /*
160  * We used to use the system definition of PASS_MAX or _PASSWD_LEN,
161  * but that caused problems with various alternate authentication
162  * methods.  So, we just define our own and assume that it is >= the
163  * system max.
164  */
165 #define SUDO_PASS_MAX   256
166
167 /*
168  * Flags for lock_file()
169  */
170 #define SUDO_LOCK       1               /* lock a file */
171 #define SUDO_TLOCK      2               /* test & lock a file (non-blocking) */
172 #define SUDO_UNLOCK     4               /* unlock a file */
173
174 /*
175  * Flags for tgetpass()
176  */
177 #define TGP_ECHO        0x01            /* leave echo on when reading passwd */
178 #define TGP_STDIN       0x02            /* read from stdin, not /dev/tty */
179
180 struct passwd;
181 struct timespec;
182 struct timeval;
183
184 /*
185  * Function prototypes
186  */
187 #define YY_DECL int yylex __P((void))
188
189 #ifndef HAVE_CLOSEFROM
190 void closefrom          __P((int));
191 #endif
192 #ifndef HAVE_GETCWD
193 char *getcwd            __P((char *, size_t size));
194 #endif
195 #ifndef HAVE_UTIMES
196 int utimes              __P((const char *, const struct timeval *));
197 #endif
198 #ifdef HAVE_FUTIME
199 int futimes             __P((int, const struct timeval *));
200 #endif
201 #ifndef HAVE_SNPRINTF
202 int snprintf            __P((char *, size_t, const char *, ...))
203                             __printflike(3, 4);
204 #endif
205 #ifndef HAVE_VSNPRINTF
206 int vsnprintf           __P((char *, size_t, const char *, va_list))
207                             __printflike(3, 0);
208 #endif
209 #ifndef HAVE_ASPRINTF
210 int asprintf            __P((char **, const char *, ...))
211                             __printflike(2, 3);
212 #endif
213 #ifndef HAVE_VASPRINTF
214 int vasprintf           __P((char **, const char *, va_list))
215                             __printflike(2, 0);
216 #endif
217 #ifndef HAVE_STRCASECMP
218 int strcasecmp          __P((const char *, const char *));
219 #endif
220 #ifndef HAVE_STRLCAT
221 size_t strlcat          __P((char *, const char *, size_t));
222 #endif
223 #ifndef HAVE_STRLCPY
224 size_t strlcpy          __P((char *, const char *, size_t));
225 #endif
226 #ifndef HAVE_MEMRCHR
227 VOID *memrchr           __P((const VOID *, int, size_t));
228 #endif
229 #ifndef HAVE_MKSTEMP
230 int mkstemp             __P((char *));
231 #endif
232 char *sudo_goodpath     __P((const char *, struct stat *));
233 char *tgetpass          __P((const char *, int, int));
234 int find_path           __P((char *, char **, struct stat *, char *));
235 void check_user         __P((int));
236 void verify_user        __P((struct passwd *, char *));
237 int sudoers_lookup      __P((int));
238 #ifdef HAVE_LDAP
239 int sudo_ldap_check     __P((int));
240 void sudo_ldap_list_matches __P((void));
241 #endif
242 void set_perms          __P((int));
243 void remove_timestamp   __P((int));
244 int check_secureware    __P((char *));
245 void sia_attempt_auth   __P((void));
246 void pam_attempt_auth   __P((void));
247 int yyparse             __P((void));
248 void pass_warn          __P((FILE *));
249 VOID *emalloc           __P((size_t));
250 VOID *emalloc2          __P((size_t, size_t));
251 VOID *erealloc          __P((VOID *, size_t));
252 VOID *erealloc3         __P((VOID *, size_t, size_t));
253 char *estrdup           __P((const char *));
254 int easprintf           __P((char **, const char *, ...))
255                             __printflike(2, 3);
256 int evasprintf          __P((char **, const char *, va_list))
257                             __printflike(2, 0);
258 void efree              __P((VOID *));
259 void dump_defaults      __P((void));
260 void dump_auth_methods  __P((void));
261 void init_envtables     __P((void));
262 int lock_file           __P((int, int));
263 int touch               __P((int, char *, struct timespec *));
264 int user_is_exempt      __P((void));
265 void set_fqdn           __P((void));
266 int set_runaspw         __P((char *));
267 char *sudo_getepw       __P((const struct passwd *));
268 int pam_prep_user       __P((struct passwd *));
269 void zero_bytes         __P((volatile VOID *, size_t));
270 int gettime             __P((struct timespec *));
271 #ifdef HAVE_SELINUX
272 void selinux_exec       __P((char *, char *, char **, char **, int));
273 #endif
274 YY_DECL;
275
276 /* Only provide extern declarations outside of sudo.c. */
277 #ifndef _SUDO_MAIN
278 extern struct sudo_user sudo_user;
279 extern struct passwd *auth_pw;
280
281 extern FILE *sudoers_fp;
282 extern int tgetpass_flags;
283 extern uid_t timestamp_uid;
284 #endif
285 #ifndef errno
286 extern int errno;
287 #endif
288
289 #endif /* _SUDO_SUDO_H */