Annotation of embedaddon/sudo/plugins/sudoers/sudoers.h, revision 1.1.1.4

1.1       misho       1: /*
1.1.1.4 ! misho       2:  * Copyright (c) 1993-1996, 1998-2005, 2007-2013
1.1       misho       3:  *     Todd C. Miller <Todd.Miller@courtesan.com>
                      4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  *
                     17:  * Sponsored in part by the Defense Advanced Research Projects
                     18:  * Agency (DARPA) and Air Force Research Laboratory, Air Force
                     19:  * Materiel Command, USAF, under agreement number F39502-99-1-0512.
                     20:  */
                     21: 
1.1.1.4 ! misho      22: #ifndef _SUDOERS_SUDOERS_H
        !            23: #define _SUDOERS_SUDOERS_H
1.1       misho      24: 
                     25: #include <limits.h>
1.1.1.2   misho      26: #ifdef HAVE_STDBOOL_H
                     27: # include <stdbool.h>
                     28: #else
                     29: # include "compat/stdbool.h"
                     30: #endif /* HAVE_STDBOOL_H */
1.1       misho      31: 
                     32: #include <pathnames.h>
                     33: #include "missing.h"
                     34: #include "error.h"
                     35: #include "alloc.h"
                     36: #include "list.h"
                     37: #include "fileops.h"
                     38: #include "defaults.h"
                     39: #include "logging.h"
                     40: #include "sudo_nss.h"
                     41: #include "sudo_plugin.h"
1.1.1.2   misho      42: #include "sudo_debug.h"
1.1       misho      43: 
                     44: #define DEFAULT_TEXT_DOMAIN    "sudoers"
                     45: #include "gettext.h"
                     46: 
                     47: /*
                     48:  * Password db and supplementary group IDs with associated group names.
                     49:  */
                     50: struct group_list {
                     51:     char **groups;
                     52:     GETGROUPS_T *gids;
                     53:     int ngroups;
                     54:     int ngids;
                     55: };
                     56: 
                     57: /*
                     58:  * Info pertaining to the invoking user.
                     59:  */
                     60: struct sudo_user {
                     61:     struct passwd *pw;
                     62:     struct passwd *_runas_pw;
                     63:     struct group *_runas_gr;
                     64:     struct stat *cmnd_stat;
                     65:     char *name;
                     66:     char *path;
                     67:     char *tty;
                     68:     char *ttypath;
                     69:     char *host;
                     70:     char *shost;
                     71:     char *prompt;
                     72:     char *cmnd;
                     73:     char *cmnd_args;
                     74:     char *cmnd_base;
                     75:     char *cmnd_safe;
                     76:     char *class_name;
                     77:     char *krb5_ccname;
                     78:     struct group_list *group_list;
                     79:     char * const * env_vars;
                     80: #ifdef HAVE_SELINUX
                     81:     char *role;
                     82:     char *type;
                     83: #endif
1.1.1.3   misho      84: #ifdef HAVE_PRIV_SET
                     85:     char *privs;
                     86:     char *limitprivs;
                     87: #endif
1.1.1.4 ! misho      88:     const char *cwd;
1.1       misho      89:     char *iolog_file;
1.1.1.3   misho      90:     GETGROUPS_T *gids;
                     91:     int   ngids;
1.1       misho      92:     int   closefrom;
                     93:     int   lines;
                     94:     int   cols;
1.1.1.3   misho      95:     int   flags;
1.1.1.4 ! misho      96:     int   max_groups;
        !            97:     mode_t umask;
1.1       misho      98:     uid_t uid;
                     99:     uid_t gid;
1.1.1.4 ! misho     100:     pid_t sid;
1.1       misho     101: };
                    102: 
                    103: /*
1.1.1.3   misho     104:  * sudo_user flag values
                    105:  */
                    106: #define RUNAS_USER_SPECIFIED   0x01
                    107: #define RUNAS_GROUP_SPECIFIED  0x02
                    108: 
                    109: /*
1.1       misho     110:  * Return values for sudoers_lookup(), also used as arguments for log_auth()
                    111:  * Note: cannot use '0' as a value here.
                    112:  */
                    113: /* XXX - VALIDATE_SUCCESS and VALIDATE_FAILURE instead? */
                    114: #define VALIDATE_ERROR          0x001
                    115: #define VALIDATE_OK            0x002
                    116: #define VALIDATE_NOT_OK                0x004
                    117: #define FLAG_CHECK_USER                0x010
                    118: #define FLAG_NO_USER           0x020
                    119: #define FLAG_NO_HOST           0x040
                    120: #define FLAG_NO_CHECK          0x080
1.1.1.3   misho     121: #define FLAG_NON_INTERACTIVE   0x100
                    122: #define FLAG_BAD_PASSWORD      0x200
                    123: #define FLAG_AUTH_ERROR                0x400
1.1       misho     124: 
                    125: /*
                    126:  * find_path()/load_cmnd() return values
                    127:  */
                    128: #define FOUND                   0
                    129: #define NOT_FOUND               1
                    130: #define NOT_FOUND_DOT          2
                    131: 
                    132: /*
                    133:  * Various modes sudo can be in (based on arguments) in hex
                    134:  */
                    135: #define MODE_RUN               0x00000001
                    136: #define MODE_EDIT              0x00000002
                    137: #define MODE_VALIDATE          0x00000004
                    138: #define MODE_INVALIDATE                0x00000008
                    139: #define MODE_KILL              0x00000010
                    140: #define MODE_VERSION           0x00000020
                    141: #define MODE_HELP              0x00000040
                    142: #define MODE_LIST              0x00000080
                    143: #define MODE_CHECK             0x00000100
                    144: #define MODE_LISTDEFS          0x00000200
                    145: #define MODE_MASK              0x0000ffff
                    146: 
                    147: /* Mode flags */
                    148: #define MODE_BACKGROUND                0x00010000 /* XXX - unused */
                    149: #define MODE_SHELL             0x00020000
                    150: #define MODE_LOGIN_SHELL       0x00040000
                    151: #define MODE_IMPLIED_SHELL     0x00080000
                    152: #define MODE_RESET_HOME                0x00100000
                    153: #define MODE_PRESERVE_GROUPS   0x00200000
                    154: #define MODE_PRESERVE_ENV      0x00400000
                    155: #define MODE_NONINTERACTIVE    0x00800000
                    156: #define MODE_IGNORE_TICKET     0x01000000
                    157: 
                    158: /*
                    159:  * Used with set_perms()
                    160:  */
                    161: #define PERM_INITIAL             0x00
                    162: #define PERM_ROOT                0x01
                    163: #define PERM_USER                0x02
                    164: #define PERM_FULL_USER           0x03
                    165: #define PERM_SUDOERS             0x04
                    166: #define PERM_RUNAS               0x05
                    167: #define PERM_TIMESTAMP           0x06
                    168: #define PERM_NOEXIT              0x10 /* flag */
                    169: #define PERM_MASK                0xf0
                    170: 
                    171: /*
                    172:  * Shortcuts for sudo_user contents.
                    173:  */
                    174: #define user_name              (sudo_user.name)
                    175: #define user_uid               (sudo_user.uid)
                    176: #define user_gid               (sudo_user.gid)
1.1.1.4 ! misho     177: #define user_sid               (sudo_user.sid)
        !           178: #define user_umask             (sudo_user.umask)
1.1       misho     179: #define user_passwd            (sudo_user.pw->pw_passwd)
                    180: #define user_dir               (sudo_user.pw->pw_dir)
1.1.1.3   misho     181: #define user_gids              (sudo_user.gids)
                    182: #define user_ngids             (sudo_user.ngids)
1.1       misho     183: #define user_group_list                (sudo_user.group_list)
                    184: #define user_tty               (sudo_user.tty)
                    185: #define user_ttypath           (sudo_user.ttypath)
                    186: #define user_cwd               (sudo_user.cwd)
                    187: #define user_cmnd              (sudo_user.cmnd)
                    188: #define user_args              (sudo_user.cmnd_args)
                    189: #define user_base              (sudo_user.cmnd_base)
                    190: #define user_stat              (sudo_user.cmnd_stat)
                    191: #define user_path              (sudo_user.path)
                    192: #define user_prompt            (sudo_user.prompt)
                    193: #define user_host              (sudo_user.host)
                    194: #define user_shost             (sudo_user.shost)
                    195: #define user_ccname            (sudo_user.krb5_ccname)
                    196: #define safe_cmnd              (sudo_user.cmnd_safe)
                    197: #define login_class            (sudo_user.class_name)
                    198: #define runas_pw               (sudo_user._runas_pw)
                    199: #define runas_gr               (sudo_user._runas_gr)
                    200: #define user_role              (sudo_user.role)
                    201: #define user_type              (sudo_user.type)
                    202: #define user_closefrom         (sudo_user.closefrom)
1.1.1.3   misho     203: #define        runas_privs             (sudo_user.privs)
                    204: #define        runas_limitprivs        (sudo_user.limitprivs)
1.1       misho     205: 
                    206: #ifdef __TANDEM
1.1.1.4 ! misho     207: # define ROOT_UID      65535
1.1       misho     208: #else
1.1.1.4 ! misho     209: # define ROOT_UID      0
1.1       misho     210: #endif
1.1.1.4 ! misho     211: #define ROOT_GID       0
1.1       misho     212: 
                    213: /*
                    214:  * We used to use the system definition of PASS_MAX or _PASSWD_LEN,
                    215:  * but that caused problems with various alternate authentication
                    216:  * methods.  So, we just define our own and assume that it is >= the
                    217:  * system max.
                    218:  */
                    219: #define SUDO_PASS_MAX  256
                    220: 
                    221: struct lbuf;
                    222: struct passwd;
                    223: struct stat;
                    224: struct timeval;
                    225: 
                    226: /*
                    227:  * Function prototypes
                    228:  */
1.1.1.4 ! misho     229: #define YY_DECL int sudoerslex(void)
1.1       misho     230: 
                    231: /* goodpath.c */
1.1.1.2   misho     232: bool sudo_goodpath(const char *, struct stat *);
1.1       misho     233: 
                    234: /* findpath.c */
                    235: int find_path(char *, char **, struct stat *, char *, int);
                    236: 
                    237: /* check.c */
1.1.1.4 ! misho     238: int check_user(int validate, int mode);
1.1.1.2   misho     239: bool user_is_exempt(void);
1.1       misho     240: 
1.1.1.4 ! misho     241: /* prompt.c */
        !           242: char *expand_prompt(const char *old_prompt, const char *user, const char *host);
        !           243: 
        !           244: /* timestamp.c */
        !           245: void remove_timestamp(bool);
        !           246: bool set_lectured(void);
        !           247: 
1.1       misho     248: /* sudo_auth.c */
1.1.1.4 ! misho     249: bool sudo_auth_needs_end_session(void);
1.1.1.3   misho     250: int verify_user(struct passwd *pw, char *prompt, int validated);
1.1.1.2   misho     251: int sudo_auth_begin_session(struct passwd *pw, char **user_env[]);
                    252: int sudo_auth_end_session(struct passwd *pw);
1.1       misho     253: int sudo_auth_init(struct passwd *pw);
                    254: int sudo_auth_cleanup(struct passwd *pw);
                    255: 
                    256: /* parse.c */
                    257: int sudo_file_open(struct sudo_nss *);
                    258: int sudo_file_close(struct sudo_nss *);
                    259: int sudo_file_setdefs(struct sudo_nss *);
                    260: int sudo_file_lookup(struct sudo_nss *, int, int);
                    261: int sudo_file_parse(struct sudo_nss *);
                    262: int sudo_file_display_cmnd(struct sudo_nss *, struct passwd *);
                    263: int sudo_file_display_defaults(struct sudo_nss *, struct passwd *, struct lbuf *);
                    264: int sudo_file_display_bound_defaults(struct sudo_nss *, struct passwd *, struct lbuf *);
                    265: int sudo_file_display_privs(struct sudo_nss *, struct passwd *, struct lbuf *);
                    266: 
                    267: /* set_perms.c */
                    268: void rewind_perms(void);
                    269: int set_perms(int);
                    270: void restore_perms(void);
                    271: int pam_prep_user(struct passwd *);
                    272: 
                    273: /* gram.y */
1.1.1.4 ! misho     274: int sudoersparse(void);
1.1       misho     275: 
                    276: /* toke.l */
                    277: YY_DECL;
1.1.1.2   misho     278: extern const char *sudoers_file;
                    279: extern mode_t sudoers_mode;
                    280: extern uid_t sudoers_uid;
                    281: extern gid_t sudoers_gid;
1.1       misho     282: 
                    283: /* defaults.c */
                    284: void dump_defaults(void);
                    285: void dump_auth_methods(void);
                    286: 
                    287: /* getspwuid.c */
                    288: char *sudo_getepw(const struct passwd *);
                    289: 
                    290: /* zero_bytes.c */
                    291: void zero_bytes(volatile void *, size_t);
                    292: 
                    293: /* sudo_nss.c */
                    294: void display_privs(struct sudo_nss_list *, struct passwd *);
1.1.1.2   misho     295: bool display_cmnd(struct sudo_nss_list *, struct passwd *);
1.1       misho     296: 
                    297: /* pwutil.c */
1.1.1.3   misho     298: __dso_public struct group *sudo_getgrgid(gid_t);
                    299: __dso_public struct group *sudo_getgrnam(const char *);
                    300: __dso_public void sudo_gr_addref(struct group *);
                    301: __dso_public void sudo_gr_delref(struct group *);
                    302: bool user_in_group(struct passwd *, const char *);
                    303: struct group *sudo_fakegrnam(const char *);
                    304: struct group_list *sudo_get_grlist(struct passwd *pw);
                    305: struct passwd *sudo_fakepwnam(const char *, gid_t);
1.1.1.4 ! misho     306: struct passwd *sudo_mkpwent(const char *user, uid_t uid, gid_t gid, const char *home, const char *shell);
1.1.1.3   misho     307: struct passwd *sudo_getpwnam(const char *);
                    308: struct passwd *sudo_getpwuid(uid_t);
1.1       misho     309: void sudo_endgrent(void);
                    310: void sudo_endpwent(void);
                    311: void sudo_endspent(void);
1.1.1.3   misho     312: void sudo_grlist_addref(struct group_list *);
                    313: void sudo_grlist_delref(struct group_list *);
                    314: void sudo_pw_addref(struct passwd *);
                    315: void sudo_pw_delref(struct passwd *);
1.1.1.4 ! misho     316: void sudo_set_grlist(struct passwd *pw, char * const *groups,
        !           317:     char * const *gids);
1.1.1.3   misho     318: void sudo_setgrent(void);
                    319: void sudo_setpwent(void);
                    320: void sudo_setspent(void);
1.1       misho     321: 
                    322: /* timestr.c */
                    323: char *get_timestr(time_t, int);
                    324: 
                    325: /* atobool.c */
                    326: int atobool(const char *str);
                    327: 
                    328: /* boottime.c */
                    329: int get_boottime(struct timeval *);
                    330: 
                    331: /* iolog.c */
1.1.1.4 ! misho     332: int io_set_max_sessid(const char *sessid);
1.1.1.3   misho     333: void io_nextid(char *iolog_dir, char *iolog_dir_fallback, char sessid[7]);
1.1       misho     334: 
                    335: /* iolog_path.c */
                    336: char *expand_iolog_path(const char *prefix, const char *dir, const char *file,
                    337:     char **slashp);
                    338: 
                    339: /* env.c */
                    340: char **env_get(void);
1.1.1.2   misho     341: void env_merge(char * const envp[], bool overwrite);
1.1       misho     342: void env_init(char * const envp[]);
                    343: void init_envtables(void);
                    344: void insert_env_vars(char * const envp[]);
                    345: void read_env_file(const char *, int);
                    346: void rebuild_env(void);
                    347: void validate_env_vars(char * const envp[]);
1.1.1.2   misho     348: int sudo_setenv(const char *var, const char *val, int overwrite);
                    349: int sudo_unsetenv(const char *var);
                    350: char *sudo_getenv(const char *name);
                    351: int sudoers_hook_getenv(const char *name, char **value, void *closure);
                    352: int sudoers_hook_putenv(char *string, void *closure);
                    353: int sudoers_hook_setenv(const char *name, const char *value, int overwrite, void *closure);
                    354: int sudoers_hook_unsetenv(const char *name, void *closure);
1.1       misho     355: 
                    356: /* fmt_string.c */
                    357: char *fmt_string(const char *, const char *);
                    358: 
                    359: /* sudoers.c */
1.1.1.2   misho     360: FILE *open_sudoers(const char *, bool, bool *);
1.1.1.4 ! misho     361: int sudoers_policy_init(void *info, char * const envp[]);
        !           362: int sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[], void *closure);
        !           363: void sudoers_cleanup(void);
        !           364: 
        !           365: /* policy.c */
        !           366: int sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group);
        !           367: int sudoers_policy_exec_setup(char *argv[], char *envp[], mode_t cmnd_umask, char *iolog_path, void *v);
        !           368: extern const char *path_ldap_conf;
        !           369: extern const char *path_ldap_secret;
1.1       misho     370: 
                    371: /* aix.c */
                    372: void aix_restoreauthdb(void);
                    373: void aix_setauthdb(char *user);
                    374: 
                    375: /* group_plugin.c */
                    376: int group_plugin_load(char *plugin_info);
                    377: void group_plugin_unload(void);
                    378: int group_plugin_query(const char *user, const char *group,
                    379:     const struct passwd *pwd);
                    380: 
                    381: /* setgroups.c */
                    382: int sudo_setgroups(int ngids, const GETGROUPS_T *gids);
                    383: 
                    384: #ifndef _SUDO_MAIN
                    385: extern struct sudo_user sudo_user;
                    386: extern struct passwd *list_pw;
                    387: extern int long_list;
                    388: extern int sudo_mode;
                    389: extern uid_t timestamp_uid;
                    390: extern sudo_conv_t sudo_conv;
                    391: #endif
                    392: 
1.1.1.4 ! misho     393: #endif /* _SUDOERS_SUDOERS_H */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>