2 * Copyright (c) 1993-1996,1998-2007 Todd C. Miller <Todd.Miller@courtesan.com>
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.
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.
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.
20 * $Sudo: sudo.h,v 1.209.2.13 2007/11/27 23:41:23 millert Exp $
26 #include <pathnames.h>
33 * Info pertaining to the invoking user.
37 struct passwd *_runas_pw;
38 struct stat *cmnd_stat;
46 int host_fqdn_queried;
56 struct list_member *env_vars;
60 * Return values for sudoers_lookup(), also used as arguments for log_auth()
61 * Note: cannot use '0' as a value here.
63 /* XXX - VALIDATE_SUCCESS and VALIDATE_FAILURE instead? */
64 #define VALIDATE_ERROR 0x001
65 #define VALIDATE_OK 0x002
66 #define VALIDATE_NOT_OK 0x004
67 #define FLAG_CHECK_USER 0x010
68 #define FLAG_NOPASS 0x020
69 #define FLAG_NO_USER 0x040
70 #define FLAG_NO_HOST 0x080
71 #define FLAG_NO_CHECK 0x100
72 #define FLAG_NOEXEC 0x200
73 #define FLAG_SETENV 0x400
76 * Pseudo-boolean values
90 * find_path()/load_cmnd() return values
94 #define NOT_FOUND_DOT -1
97 * Various modes sudo can be in (based on arguments) in hex
99 #define MODE_RUN 0x0001
100 #define MODE_EDIT 0x0002
101 #define MODE_VALIDATE 0x0004
102 #define MODE_INVALIDATE 0x0008
103 #define MODE_KILL 0x0010
104 #define MODE_VERSION 0x0020
105 #define MODE_HELP 0x0040
106 #define MODE_LIST 0x0080
107 #define MODE_LISTDEFS 0x0100
108 #define MODE_BACKGROUND 0x0200
109 #define MODE_SHELL 0x0400
110 #define MODE_LOGIN_SHELL 0x0800
111 #define MODE_IMPLIED_SHELL 0x1000
112 #define MODE_RESET_HOME 0x2000
113 #define MODE_PRESERVE_GROUPS 0x4000
114 #define MODE_PRESERVE_ENV 0x8000
117 * Used with set_perms()
119 #define PERM_ROOT 0x00
120 #define PERM_USER 0x01
121 #define PERM_FULL_USER 0x02
122 #define PERM_SUDOERS 0x03
123 #define PERM_RUNAS 0x04
124 #define PERM_FULL_RUNAS 0x05
125 #define PERM_TIMESTAMP 0x06
128 * Shortcuts for sudo_user contents.
130 #define user_name (sudo_user.pw->pw_name)
131 #define user_passwd (sudo_user.pw->pw_passwd)
132 #define user_uid (sudo_user.pw->pw_uid)
133 #define user_gid (sudo_user.pw->pw_gid)
134 #define user_dir (sudo_user.pw->pw_dir)
135 #define user_shell (sudo_user.shell)
136 #define user_ngroups (sudo_user.ngroups)
137 #define user_groups (sudo_user.groups)
138 #define user_tty (sudo_user.tty)
139 #define user_ttypath (sudo_user.ttypath)
140 #define user_cwd (sudo_user.cwd)
141 #define user_runas (sudo_user.runas)
142 #define user_cmnd (sudo_user.cmnd)
143 #define user_args (sudo_user.cmnd_args)
144 #define user_base (sudo_user.cmnd_base)
145 #define user_stat (sudo_user.cmnd_stat)
146 #define user_path (sudo_user.path)
147 #define user_prompt (sudo_user.prompt)
148 #define user_host (sudo_user.host)
149 #define user_shost (sudo_user.shost)
150 #define safe_cmnd (sudo_user.cmnd_safe)
151 #define login_class (sudo_user.class_name)
152 #define runas_pw (sudo_user._runas_pw)
155 * We used to use the system definition of PASS_MAX or _PASSWD_LEN,
156 * but that caused problems with various alternate authentication
157 * methods. So, we just define our own and assume that it is >= the
160 #define SUDO_PASS_MAX 256
163 * Flags for lock_file()
165 #define SUDO_LOCK 1 /* lock a file */
166 #define SUDO_TLOCK 2 /* test & lock a file (non-blocking) */
167 #define SUDO_UNLOCK 4 /* unlock a file */
170 * Flags for tgetpass()
172 #define TGP_ECHO 0x01 /* leave echo on when reading passwd */
173 #define TGP_STDIN 0x02 /* read from stdin, not /dev/tty */
180 * Function prototypes
182 #define YY_DECL int yylex __P((void))
184 #ifndef HAVE_CLOSEFROM
185 void closefrom __P((int));
188 char *getcwd __P((char *, size_t size));
191 int utimes __P((const char *, const struct timeval *));
194 int futimes __P((int, const struct timeval *));
196 #ifndef HAVE_SNPRINTF
197 int snprintf __P((char *, size_t, const char *, ...))
200 #ifndef HAVE_VSNPRINTF
201 int vsnprintf __P((char *, size_t, const char *, va_list))
204 #ifndef HAVE_ASPRINTF
205 int asprintf __P((char **, const char *, ...))
208 #ifndef HAVE_VASPRINTF
209 int vasprintf __P((char **, const char *, va_list))
212 #ifndef HAVE_STRCASECMP
213 int strcasecmp __P((const char *, const char *));
216 size_t strlcat __P((char *, const char *, size_t));
219 size_t strlcpy __P((char *, const char *, size_t));
222 VOID *memrchr __P((const VOID *, int, size_t));
225 int mkstemp __P((char *));
227 char *sudo_goodpath __P((const char *, struct stat *));
228 char *tgetpass __P((const char *, int, int));
229 int find_path __P((char *, char **, struct stat *, char *));
230 void check_user __P((int));
231 void verify_user __P((struct passwd *, char *));
232 int sudoers_lookup __P((int));
234 int sudo_ldap_check __P((int));
235 void sudo_ldap_list_matches __P((void));
237 void set_perms __P((int));
238 void remove_timestamp __P((int));
239 int check_secureware __P((char *));
240 void sia_attempt_auth __P((void));
241 void pam_attempt_auth __P((void));
242 int yyparse __P((void));
243 void pass_warn __P((FILE *));
244 VOID *emalloc __P((size_t));
245 VOID *emalloc2 __P((size_t, size_t));
246 VOID *erealloc __P((VOID *, size_t));
247 VOID *erealloc3 __P((VOID *, size_t, size_t));
248 char *estrdup __P((const char *));
249 int easprintf __P((char **, const char *, ...))
251 int evasprintf __P((char **, const char *, va_list))
253 void efree __P((VOID *));
254 void dump_defaults __P((void));
255 void dump_auth_methods __P((void));
256 void init_envtables __P((void));
257 int lock_file __P((int, int));
258 int touch __P((int, char *, struct timespec *));
259 int user_is_exempt __P((void));
260 void set_fqdn __P((void));
261 int set_runaspw __P((char *));
262 char *sudo_getepw __P((const struct passwd *));
263 int pam_prep_user __P((struct passwd *));
264 void zero_bytes __P((volatile VOID *, size_t));
265 int gettime __P((struct timespec *));
268 /* Only provide extern declarations outside of sudo.c. */
270 extern struct sudo_user sudo_user;
271 extern struct passwd *auth_pw;
273 extern FILE *sudoers_fp;
274 extern int tgetpass_flags;
275 extern uid_t timestamp_uid;
281 #endif /* _SUDO_SUDO_H */