Annotation of src/usr.bin/sudo/sudo.h, Revision 1.13
1.1 millert 1: /*
1.10 millert 2: * Copyright (c) 1993-1996,1998-2003 Todd C. Miller <Todd.Miller@courtesan.com>
1.1 millert 3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms, with or without
6: * modification, are permitted provided that the following conditions
7: * are met:
8: *
9: * 1. Redistributions of source code must retain the above copyright
10: * notice, this list of conditions and the following disclaimer.
11: *
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: *
16: * 3. The name of the author may not be used to endorse or promote products
17: * derived from this software without specific prior written permission.
18: *
19: * 4. Products derived from this software may not be called "Sudo" nor
20: * may "Sudo" appear in their names without specific prior written
21: * permission from the author.
22: *
23: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
26: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33: *
1.12 millert 34: * Sponsored in part by the Defense Advanced Research Projects
35: * Agency (DARPA) and Air Force Research Laboratory, Air Force
36: * Materiel Command, USAF, under agreement number F39502-99-1-0512.
37: *
38: * $Sudo: sudo.h,v 1.194 2003/04/16 00:42:10 millert Exp $
1.1 millert 39: */
40:
41: #ifndef _SUDO_SUDO_H
42: #define _SUDO_SUDO_H
43:
44: #include <pathnames.h>
45: #include "compat.h"
46: #include "defaults.h"
47: #include "logging.h"
48:
49: /*
50: * Info pertaining to the invoking user.
51: */
52: struct sudo_user {
53: struct passwd *pw;
1.7 millert 54: struct passwd *_runas_pw;
55: char *path;
56: char *shell;
1.1 millert 57: char *tty;
58: char cwd[MAXPATHLEN];
59: char *host;
60: char *shost;
61: char **runas;
62: char *prompt;
63: char *cmnd_safe;
64: char *cmnd;
65: char *cmnd_args;
1.4 millert 66: char *class_name;
1.1 millert 67: };
68:
69: /*
70: * Return values for sudoers_lookup(), also used as arguments for log_auth()
71: * Note: cannot use '0' as a value here.
72: */
73: /* XXX - VALIDATE_SUCCESS and VALIDATE_FAILURE instead? */
74: #define VALIDATE_ERROR 0x01
75: #define VALIDATE_OK 0x02
76: #define VALIDATE_NOT_OK 0x04
77: #define FLAG_NOPASS 0x10
78: #define FLAG_NO_USER 0x20
79: #define FLAG_NO_HOST 0x40
80: #define FLAG_NO_CHECK 0x80
81:
82: /*
83: * Boolean values
84: */
85: #undef TRUE
86: #define TRUE 1
87: #undef FALSE
88: #define FALSE 0
89:
90: /*
91: * find_path()/load_cmnd() return values
92: */
93: #define FOUND 1
94: #define NOT_FOUND 0
95: #define NOT_FOUND_DOT -1
96:
97: /*
98: * Various modes sudo can be in (based on arguments) in octal
99: */
1.7 millert 100: #define MODE_RUN 000001
101: #define MODE_VALIDATE 000002
102: #define MODE_INVALIDATE 000004
103: #define MODE_KILL 000010
104: #define MODE_VERSION 000020
105: #define MODE_HELP 000040
106: #define MODE_LIST 000100
107: #define MODE_LISTDEFS 000200
108: #define MODE_BACKGROUND 000400
109: #define MODE_SHELL 001000
110: #define MODE_IMPLIED_SHELL 002000
111: #define MODE_RESET_HOME 004000
112: #define MODE_PRESERVE_GROUPS 010000
1.1 millert 113:
114: /*
115: * Used with set_perms()
116: */
117: #define PERM_ROOT 0x00
1.8 millert 118: #define PERM_FULL_ROOT 0x01
119: #define PERM_USER 0x02
1.9 millert 120: #define PERM_FULL_USER 0x03
121: #define PERM_SUDOERS 0x04
122: #define PERM_RUNAS 0x05
1.10 millert 123: #define PERM_TIMESTAMP 0x06
1.1 millert 124:
125: /*
126: * Shortcuts for sudo_user contents.
127: */
128: #define user_name (sudo_user.pw->pw_name)
129: #define user_passwd (sudo_user.pw->pw_passwd)
130: #define user_uid (sudo_user.pw->pw_uid)
131: #define user_gid (sudo_user.pw->pw_gid)
132: #define user_dir (sudo_user.pw->pw_dir)
1.7 millert 133: #define user_shell (sudo_user.shell)
1.1 millert 134: #define user_tty (sudo_user.tty)
135: #define user_cwd (sudo_user.cwd)
136: #define user_runas (sudo_user.runas)
137: #define user_cmnd (sudo_user.cmnd)
138: #define user_args (sudo_user.cmnd_args)
1.7 millert 139: #define user_path (sudo_user.path)
1.1 millert 140: #define user_prompt (sudo_user.prompt)
141: #define user_host (sudo_user.host)
142: #define user_shost (sudo_user.shost)
143: #define safe_cmnd (sudo_user.cmnd_safe)
1.4 millert 144: #define login_class (sudo_user.class_name)
1.7 millert 145: #define runas_pw (sudo_user._runas_pw)
1.1 millert 146:
147: /*
148: * We used to use the system definition of PASS_MAX or _PASSWD_LEN,
149: * but that caused problems with various alternate authentication
150: * methods. So, we just define our own and assume that it is >= the
151: * system max.
152: */
153: #define SUDO_PASS_MAX 256
154:
155: /*
156: * Flags for lock_file()
157: */
158: #define SUDO_LOCK 1 /* lock a file */
159: #define SUDO_TLOCK 2 /* test & lock a file (non-blocking) */
160: #define SUDO_UNLOCK 4 /* unlock a file */
1.3 millert 161:
162: /*
163: * Flags for sudoers_lookup:
164: * PASSWD_NEVER: user never has to give a passwd
165: * PASSWD_ALL: no passwd needed if all entries for host have NOPASSWD flag
166: * PASSWD_ANY: no passwd needed if any entry for host has a NOPASSWD flag
167: * PASSWD_ALWAYS: passwd always needed
168: */
169: #define PWCHECK_NEVER 0x01
170: #define PWCHECK_ALL 0x02
171: #define PWCHECK_ANY 0x04
172: #define PWCHECK_ALWAYS 0x08
1.1 millert 173:
174: /*
1.4 millert 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: /*
1.1 millert 181: * Function prototypes
182: */
183: #define YY_DECL int yylex __P((void))
184:
185: #ifndef HAVE_GETCWD
186: char *getcwd __P((char *, size_t size));
187: #endif
188: #ifndef HAVE_SNPRINTF
189: int snprintf __P((char *, size_t, const char *, ...));
190: #endif
191: #ifndef HAVE_VSNPRINTF
192: int vsnprintf __P((char *, size_t, const char *, va_list));
193: #endif
194: #ifndef HAVE_ASPRINTF
195: int asprintf __P((char **, const char *, ...));
196: #endif
197: #ifndef HAVE_VASPRINTF
198: int vasprintf __P((char **, const char *, va_list));
199: #endif
200: #ifndef HAVE_STRCASECMP
201: int strcasecmp __P((const char *, const char *));
202: #endif
1.10 millert 203: #ifndef HAVE_STRLCAT
204: size_t strlcat __P((char *, const char *, size_t));
205: #endif
206: #ifndef HAVE_STRLCPY
207: size_t strlcpy __P((char *, const char *, size_t));
208: #endif
1.1 millert 209: char *sudo_goodpath __P((const char *));
210: char *tgetpass __P((const char *, int, int));
1.7 millert 211: int find_path __P((char *, char **, char *));
1.1 millert 212: void check_user __P((void));
1.5 millert 213: void verify_user __P((struct passwd *, char *));
1.1 millert 214: int sudoers_lookup __P((int));
1.10 millert 215: void set_perms_nosuid __P((int));
216: void set_perms_posix __P((int));
217: void set_perms_suid __P((int));
1.1 millert 218: void remove_timestamp __P((int));
219: int check_secureware __P((char *));
220: void sia_attempt_auth __P((void));
221: void pam_attempt_auth __P((void));
222: int yyparse __P((void));
223: void pass_warn __P((FILE *));
224: VOID *emalloc __P((size_t));
1.10 millert 225: VOID *emalloc2 __P((size_t, size_t));
1.1 millert 226: VOID *erealloc __P((VOID *, size_t));
1.10 millert 227: VOID *erealloc3 __P((VOID *, size_t, size_t));
1.1 millert 228: char *estrdup __P((const char *));
1.5 millert 229: int easprintf __P((char **, const char *, ...));
230: int evasprintf __P((char **, const char *, va_list));
1.1 millert 231: void dump_defaults __P((void));
232: void dump_auth_methods __P((void));
1.7 millert 233: void init_envtables __P((void));
1.1 millert 234: int lock_file __P((int, int));
235: int touch __P((char *, time_t));
1.4 millert 236: int user_is_exempt __P((void));
1.2 millert 237: void set_fqdn __P((void));
1.4 millert 238: char *sudo_getepw __P((struct passwd *));
1.7 millert 239: int pam_prep_user __P((struct passwd *));
1.13 ! millert 240: void zero_bytes __P((volatile VOID *, size_t));
1.1 millert 241: YY_DECL;
242:
243: /* Only provide extern declarations outside of sudo.c. */
1.11 millert 244: #ifndef _SUDO_MAIN
1.1 millert 245: extern struct sudo_user sudo_user;
1.5 millert 246: extern struct passwd *auth_pw;
1.1 millert 247:
248: extern FILE *sudoers_fp;
1.4 millert 249: extern int tgetpass_flags;
1.10 millert 250: extern uid_t timestamp_uid;
1.7 millert 251:
1.10 millert 252: extern void (*set_perms) __P((int));
1.1 millert 253: #endif
254: extern int errno;
255:
256: #endif /* _SUDO_SUDO_H */