[BACK]Return to sudo.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / sudo

Annotation of src/usr.bin/sudo/sudo.h, Revision 1.20

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