fix typo in changelog
[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     int   host_fqdn_queried;
47     char **runas;
48     char *prompt;
49     char *cmnd;
50     char *cmnd_args;
51     char *cmnd_base;
52     char *cmnd_safe;
53     char *class_name;
54     int ngroups;
55     GETGROUPS_T *groups;
56     struct list_member *env_vars;
57 #ifdef HAVE_SELINUX
58     char *role;
59     char *type;
60 #endif
61 };
62
63 /*
64  * Return values for sudoers_lookup(), also used as arguments for log_auth()
65  * Note: cannot use '0' as a value here.
66  */
67 /* XXX - VALIDATE_SUCCESS and VALIDATE_FAILURE instead? */
68 #define VALIDATE_ERROR          0x001
69 #define VALIDATE_OK             0x002
70 #define VALIDATE_NOT_OK         0x004
71 #define FLAG_CHECK_USER         0x010
72 #define FLAG_NOPASS             0x020
73 #define FLAG_NO_USER            0x040
74 #define FLAG_NO_HOST            0x080
75 #define FLAG_NO_CHECK           0x100
76 #define FLAG_NOEXEC             0x200
77 #define FLAG_SETENV             0x400
78
79 /*
80  * Pseudo-boolean values
81  */
82 #undef TRUE
83 #define TRUE                     1
84 #undef FALSE
85 #define FALSE                    0
86 #undef IMPLIED
87 #define IMPLIED                  2
88 #undef NOMATCH
89 #define NOMATCH                 -1
90 #undef UNSPEC
91 #define UNSPEC                  -2
92
93 /*
94  * find_path()/load_cmnd() return values
95  */
96 #define FOUND                    1
97 #define NOT_FOUND                0
98 #define NOT_FOUND_DOT           -1
99
100 /*
101  * Various modes sudo can be in (based on arguments) in hex
102  */
103 #define MODE_RUN                0x0001
104 #define MODE_EDIT               0x0002
105 #define MODE_VALIDATE           0x0004
106 #define MODE_INVALIDATE         0x0008
107 #define MODE_KILL               0x0010
108 #define MODE_VERSION            0x0020
109 #define MODE_HELP               0x0040
110 #define MODE_LIST               0x0080
111 #define MODE_LISTDEFS           0x0100
112 #define MODE_BACKGROUND         0x0200
113 #define MODE_SHELL              0x0400
114 #define MODE_LOGIN_SHELL        0x0800
115 #define MODE_IMPLIED_SHELL      0x1000
116 #define MODE_RESET_HOME         0x2000
117 #define MODE_PRESERVE_GROUPS    0x4000
118 #define MODE_PRESERVE_ENV       0x8000
119
120 /*
121  * Used with set_perms()
122  */
123 #define PERM_ROOT                0x00
124 #define PERM_USER                0x01
125 #define PERM_FULL_USER           0x02
126 #define PERM_SUDOERS             0x03
127 #define PERM_RUNAS               0x04
128 #define PERM_FULL_RUNAS          0x05
129 #define PERM_TIMESTAMP           0x06
130
131 /*
132  * Shortcuts for sudo_user contents.
133  */
134 #define user_name               (sudo_user.pw->pw_name)
135 #define user_passwd             (sudo_user.pw->pw_passwd)
136 #define user_uid                (sudo_user.pw->pw_uid)
137 #define user_gid                (sudo_user.pw->pw_gid)
138 #define user_dir                (sudo_user.pw->pw_dir)
139 #define user_shell              (sudo_user.shell)
140 #define user_ngroups            (sudo_user.ngroups)
141 #define user_groups             (sudo_user.groups)
142 #define user_tty                (sudo_user.tty)
143 #define user_ttypath            (sudo_user.ttypath)
144 #define user_cwd                (sudo_user.cwd)
145 #define user_runas              (sudo_user.runas)
146 #define user_cmnd               (sudo_user.cmnd)
147 #define user_args               (sudo_user.cmnd_args)
148 #define user_base               (sudo_user.cmnd_base)
149 #define user_stat               (sudo_user.cmnd_stat)
150 #define user_path               (sudo_user.path)
151 #define user_prompt             (sudo_user.prompt)
152 #define user_host               (sudo_user.host)
153 #define user_shost              (sudo_user.shost)
154 #define safe_cmnd               (sudo_user.cmnd_safe)
155 #define login_class             (sudo_user.class_name)
156 #define runas_pw                (sudo_user._runas_pw)
157 #define user_role               (sudo_user.role)
158 #define user_type               (sudo_user.type)
159
160 /*
161  * We used to use the system definition of PASS_MAX or _PASSWD_LEN,
162  * but that caused problems with various alternate authentication
163  * methods.  So, we just define our own and assume that it is >= the
164  * system max.
165  */
166 #define SUDO_PASS_MAX   256
167
168 /*
169  * Flags for lock_file()
170  */
171 #define SUDO_LOCK       1               /* lock a file */
172 #define SUDO_TLOCK      2               /* test & lock a file (non-blocking) */
173 #define SUDO_UNLOCK     4               /* unlock a file */
174
175 /*
176  * Flags for tgetpass()
177  */
178 #define TGP_ECHO        0x01            /* leave echo on when reading passwd */
179 #define TGP_STDIN       0x02            /* read from stdin, not /dev/tty */
180
181 struct passwd;
182 struct timespec;
183 struct timeval;
184
185 /*
186  * Function prototypes
187  */
188 #define YY_DECL int yylex __P((void))
189
190 #ifndef HAVE_CLOSEFROM
191 void closefrom          __P((int));
192 #endif
193 #ifndef HAVE_GETCWD
194 char *getcwd            __P((char *, size_t size));
195 #endif
196 #ifndef HAVE_UTIMES
197 int utimes              __P((const char *, const struct timeval *));
198 #endif
199 #ifdef HAVE_FUTIME
200 int futimes             __P((int, const struct timeval *));
201 #endif
202 #ifndef HAVE_SNPRINTF
203 int snprintf            __P((char *, size_t, const char *, ...))
204                             __printflike(3, 4);
205 #endif
206 #ifndef HAVE_VSNPRINTF
207 int vsnprintf           __P((char *, size_t, const char *, va_list))
208                             __printflike(3, 0);
209 #endif
210 #ifndef HAVE_ASPRINTF
211 int asprintf            __P((char **, const char *, ...))
212                             __printflike(2, 3);
213 #endif
214 #ifndef HAVE_VASPRINTF
215 int vasprintf           __P((char **, const char *, va_list))
216                             __printflike(2, 0);
217 #endif
218 #ifndef HAVE_STRCASECMP
219 int strcasecmp          __P((const char *, const char *));
220 #endif
221 #ifndef HAVE_STRLCAT
222 size_t strlcat          __P((char *, const char *, size_t));
223 #endif
224 #ifndef HAVE_STRLCPY
225 size_t strlcpy          __P((char *, const char *, size_t));
226 #endif
227 #ifndef HAVE_MEMRCHR
228 VOID *memrchr           __P((const VOID *, int, size_t));
229 #endif
230 #ifndef HAVE_MKSTEMP
231 int mkstemp             __P((char *));
232 #endif
233 char *sudo_goodpath     __P((const char *, struct stat *));
234 char *tgetpass          __P((const char *, int, int));
235 int find_path           __P((char *, char **, struct stat *, char *));
236 void check_user         __P((int));
237 void verify_user        __P((struct passwd *, char *));
238 int sudoers_lookup      __P((int));
239 #ifdef HAVE_LDAP
240 int sudo_ldap_check     __P((int));
241 void sudo_ldap_list_matches __P((void));
242 #endif
243 void set_perms          __P((int));
244 void remove_timestamp   __P((int));
245 int check_secureware    __P((char *));
246 void sia_attempt_auth   __P((void));
247 void pam_attempt_auth   __P((void));
248 int yyparse             __P((void));
249 void pass_warn          __P((FILE *));
250 VOID *emalloc           __P((size_t));
251 VOID *emalloc2          __P((size_t, size_t));
252 VOID *erealloc          __P((VOID *, size_t));
253 VOID *erealloc3         __P((VOID *, size_t, size_t));
254 char *estrdup           __P((const char *));
255 int easprintf           __P((char **, const char *, ...))
256                             __printflike(2, 3);
257 int evasprintf          __P((char **, const char *, va_list))
258                             __printflike(2, 0);
259 void efree              __P((VOID *));
260 void dump_defaults      __P((void));
261 void dump_auth_methods  __P((void));
262 void init_envtables     __P((void));
263 int lock_file           __P((int, int));
264 int touch               __P((int, char *, struct timespec *));
265 int user_is_exempt      __P((void));
266 void set_fqdn           __P((void));
267 int set_runaspw         __P((char *));
268 char *sudo_getepw       __P((const struct passwd *));
269 int pam_prep_user       __P((struct passwd *));
270 void zero_bytes         __P((volatile VOID *, size_t));
271 int gettime             __P((struct timespec *));
272 #ifdef HAVE_SELINUX
273 void selinux_exec       __P((char *, char *, char **, char **, int));
274 #endif
275 YY_DECL;
276
277 /* Only provide extern declarations outside of sudo.c. */
278 #ifndef _SUDO_MAIN
279 extern struct sudo_user sudo_user;
280 extern struct passwd *auth_pw;
281
282 extern FILE *sudoers_fp;
283 extern int tgetpass_flags;
284 extern uid_t timestamp_uid;
285 #endif
286 #ifndef errno
287 extern int errno;
288 #endif
289
290 #endif /* _SUDO_SUDO_H */