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

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"
1.1.1.5 ! misho      34: #include "fatal.h"
1.1       misho      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;
1.1.1.5 ! misho      71:     char *runhost;
        !            72:     char *srunhost;
1.1       misho      73:     char *prompt;
                     74:     char *cmnd;
                     75:     char *cmnd_args;
                     76:     char *cmnd_base;
                     77:     char *cmnd_safe;
                     78:     char *class_name;
                     79:     char *krb5_ccname;
                     80:     struct group_list *group_list;
                     81:     char * const * env_vars;
                     82: #ifdef HAVE_SELINUX
                     83:     char *role;
                     84:     char *type;
                     85: #endif
1.1.1.3   misho      86: #ifdef HAVE_PRIV_SET
                     87:     char *privs;
                     88:     char *limitprivs;
                     89: #endif
1.1.1.4   misho      90:     const char *cwd;
1.1       misho      91:     char *iolog_file;
1.1.1.3   misho      92:     GETGROUPS_T *gids;
                     93:     int   ngids;
1.1       misho      94:     int   closefrom;
                     95:     int   lines;
                     96:     int   cols;
1.1.1.3   misho      97:     int   flags;
1.1.1.4   misho      98:     int   max_groups;
                     99:     mode_t umask;
1.1       misho     100:     uid_t uid;
                    101:     uid_t gid;
1.1.1.4   misho     102:     pid_t sid;
1.1       misho     103: };
                    104: 
                    105: /*
1.1.1.3   misho     106:  * sudo_user flag values
                    107:  */
                    108: #define RUNAS_USER_SPECIFIED   0x01
                    109: #define RUNAS_GROUP_SPECIFIED  0x02
                    110: 
                    111: /*
1.1       misho     112:  * Return values for sudoers_lookup(), also used as arguments for log_auth()
                    113:  * Note: cannot use '0' as a value here.
                    114:  */
                    115: /* XXX - VALIDATE_SUCCESS and VALIDATE_FAILURE instead? */
                    116: #define VALIDATE_ERROR          0x001
                    117: #define VALIDATE_OK            0x002
                    118: #define VALIDATE_NOT_OK                0x004
                    119: #define FLAG_CHECK_USER                0x010
                    120: #define FLAG_NO_USER           0x020
                    121: #define FLAG_NO_HOST           0x040
                    122: #define FLAG_NO_CHECK          0x080
1.1.1.3   misho     123: #define FLAG_NON_INTERACTIVE   0x100
                    124: #define FLAG_BAD_PASSWORD      0x200
                    125: #define FLAG_AUTH_ERROR                0x400
1.1       misho     126: 
                    127: /*
                    128:  * find_path()/load_cmnd() return values
                    129:  */
                    130: #define FOUND                   0
                    131: #define NOT_FOUND               1
                    132: #define NOT_FOUND_DOT          2
                    133: 
                    134: /*
                    135:  * Various modes sudo can be in (based on arguments) in hex
                    136:  */
                    137: #define MODE_RUN               0x00000001
                    138: #define MODE_EDIT              0x00000002
                    139: #define MODE_VALIDATE          0x00000004
                    140: #define MODE_INVALIDATE                0x00000008
                    141: #define MODE_KILL              0x00000010
                    142: #define MODE_VERSION           0x00000020
                    143: #define MODE_HELP              0x00000040
                    144: #define MODE_LIST              0x00000080
                    145: #define MODE_CHECK             0x00000100
                    146: #define MODE_LISTDEFS          0x00000200
                    147: #define MODE_MASK              0x0000ffff
                    148: 
                    149: /* Mode flags */
                    150: #define MODE_BACKGROUND                0x00010000 /* XXX - unused */
                    151: #define MODE_SHELL             0x00020000
                    152: #define MODE_LOGIN_SHELL       0x00040000
                    153: #define MODE_IMPLIED_SHELL     0x00080000
                    154: #define MODE_RESET_HOME                0x00100000
                    155: #define MODE_PRESERVE_GROUPS   0x00200000
                    156: #define MODE_PRESERVE_ENV      0x00400000
                    157: #define MODE_NONINTERACTIVE    0x00800000
                    158: #define MODE_IGNORE_TICKET     0x01000000
                    159: 
                    160: /*
                    161:  * Used with set_perms()
                    162:  */
                    163: #define PERM_INITIAL             0x00
                    164: #define PERM_ROOT                0x01
                    165: #define PERM_USER                0x02
                    166: #define PERM_FULL_USER           0x03
                    167: #define PERM_SUDOERS             0x04
                    168: #define PERM_RUNAS               0x05
                    169: #define PERM_TIMESTAMP           0x06
                    170: #define PERM_NOEXIT              0x10 /* flag */
                    171: #define PERM_MASK                0xf0
                    172: 
                    173: /*
                    174:  * Shortcuts for sudo_user contents.
                    175:  */
                    176: #define user_name              (sudo_user.name)
                    177: #define user_uid               (sudo_user.uid)
                    178: #define user_gid               (sudo_user.gid)
1.1.1.4   misho     179: #define user_sid               (sudo_user.sid)
                    180: #define user_umask             (sudo_user.umask)
1.1       misho     181: #define user_passwd            (sudo_user.pw->pw_passwd)
                    182: #define user_dir               (sudo_user.pw->pw_dir)
1.1.1.3   misho     183: #define user_gids              (sudo_user.gids)
                    184: #define user_ngids             (sudo_user.ngids)
1.1       misho     185: #define user_group_list                (sudo_user.group_list)
                    186: #define user_tty               (sudo_user.tty)
                    187: #define user_ttypath           (sudo_user.ttypath)
                    188: #define user_cwd               (sudo_user.cwd)
                    189: #define user_cmnd              (sudo_user.cmnd)
                    190: #define user_args              (sudo_user.cmnd_args)
                    191: #define user_base              (sudo_user.cmnd_base)
                    192: #define user_stat              (sudo_user.cmnd_stat)
                    193: #define user_path              (sudo_user.path)
                    194: #define user_prompt            (sudo_user.prompt)
                    195: #define user_host              (sudo_user.host)
                    196: #define user_shost             (sudo_user.shost)
1.1.1.5 ! misho     197: #define user_runhost           (sudo_user.runhost)
        !           198: #define user_srunhost          (sudo_user.srunhost)
1.1       misho     199: #define user_ccname            (sudo_user.krb5_ccname)
                    200: #define safe_cmnd              (sudo_user.cmnd_safe)
                    201: #define login_class            (sudo_user.class_name)
                    202: #define runas_pw               (sudo_user._runas_pw)
                    203: #define runas_gr               (sudo_user._runas_gr)
                    204: #define user_role              (sudo_user.role)
                    205: #define user_type              (sudo_user.type)
                    206: #define user_closefrom         (sudo_user.closefrom)
1.1.1.3   misho     207: #define        runas_privs             (sudo_user.privs)
                    208: #define        runas_limitprivs        (sudo_user.limitprivs)
1.1       misho     209: 
                    210: #ifdef __TANDEM
1.1.1.4   misho     211: # define ROOT_UID      65535
1.1       misho     212: #else
1.1.1.4   misho     213: # define ROOT_UID      0
1.1       misho     214: #endif
1.1.1.4   misho     215: #define ROOT_GID       0
1.1       misho     216: 
                    217: struct lbuf;
                    218: struct passwd;
                    219: struct stat;
                    220: struct timeval;
                    221: 
                    222: /*
                    223:  * Function prototypes
                    224:  */
1.1.1.4   misho     225: #define YY_DECL int sudoerslex(void)
1.1       misho     226: 
                    227: /* goodpath.c */
1.1.1.2   misho     228: bool sudo_goodpath(const char *, struct stat *);
1.1       misho     229: 
                    230: /* findpath.c */
                    231: int find_path(char *, char **, struct stat *, char *, int);
                    232: 
                    233: /* check.c */
1.1.1.4   misho     234: int check_user(int validate, int mode);
1.1.1.2   misho     235: bool user_is_exempt(void);
1.1       misho     236: 
1.1.1.4   misho     237: /* prompt.c */
                    238: char *expand_prompt(const char *old_prompt, const char *user, const char *host);
                    239: 
                    240: /* timestamp.c */
                    241: void remove_timestamp(bool);
                    242: bool set_lectured(void);
                    243: 
1.1       misho     244: /* sudo_auth.c */
1.1.1.4   misho     245: bool sudo_auth_needs_end_session(void);
1.1.1.3   misho     246: int verify_user(struct passwd *pw, char *prompt, int validated);
1.1.1.2   misho     247: int sudo_auth_begin_session(struct passwd *pw, char **user_env[]);
                    248: int sudo_auth_end_session(struct passwd *pw);
1.1       misho     249: int sudo_auth_init(struct passwd *pw);
                    250: int sudo_auth_cleanup(struct passwd *pw);
                    251: 
                    252: /* parse.c */
                    253: int sudo_file_open(struct sudo_nss *);
                    254: int sudo_file_close(struct sudo_nss *);
                    255: int sudo_file_setdefs(struct sudo_nss *);
                    256: int sudo_file_lookup(struct sudo_nss *, int, int);
                    257: int sudo_file_parse(struct sudo_nss *);
                    258: int sudo_file_display_cmnd(struct sudo_nss *, struct passwd *);
                    259: int sudo_file_display_defaults(struct sudo_nss *, struct passwd *, struct lbuf *);
                    260: int sudo_file_display_bound_defaults(struct sudo_nss *, struct passwd *, struct lbuf *);
                    261: int sudo_file_display_privs(struct sudo_nss *, struct passwd *, struct lbuf *);
                    262: 
                    263: /* set_perms.c */
                    264: void rewind_perms(void);
                    265: int set_perms(int);
                    266: void restore_perms(void);
                    267: int pam_prep_user(struct passwd *);
                    268: 
                    269: /* gram.y */
1.1.1.4   misho     270: int sudoersparse(void);
1.1       misho     271: 
                    272: /* toke.l */
                    273: YY_DECL;
1.1.1.2   misho     274: extern const char *sudoers_file;
                    275: extern mode_t sudoers_mode;
                    276: extern uid_t sudoers_uid;
                    277: extern gid_t sudoers_gid;
1.1       misho     278: 
                    279: /* defaults.c */
                    280: void dump_defaults(void);
                    281: void dump_auth_methods(void);
                    282: 
                    283: /* getspwuid.c */
                    284: char *sudo_getepw(const struct passwd *);
                    285: 
                    286: /* sudo_nss.c */
                    287: void display_privs(struct sudo_nss_list *, struct passwd *);
1.1.1.2   misho     288: bool display_cmnd(struct sudo_nss_list *, struct passwd *);
1.1       misho     289: 
                    290: /* pwutil.c */
1.1.1.3   misho     291: __dso_public struct group *sudo_getgrgid(gid_t);
                    292: __dso_public struct group *sudo_getgrnam(const char *);
                    293: __dso_public void sudo_gr_addref(struct group *);
                    294: __dso_public void sudo_gr_delref(struct group *);
                    295: bool user_in_group(struct passwd *, const char *);
                    296: struct group *sudo_fakegrnam(const char *);
                    297: struct group_list *sudo_get_grlist(struct passwd *pw);
                    298: struct passwd *sudo_fakepwnam(const char *, gid_t);
1.1.1.4   misho     299: struct passwd *sudo_mkpwent(const char *user, uid_t uid, gid_t gid, const char *home, const char *shell);
1.1.1.3   misho     300: struct passwd *sudo_getpwnam(const char *);
                    301: struct passwd *sudo_getpwuid(uid_t);
1.1       misho     302: void sudo_endgrent(void);
                    303: void sudo_endpwent(void);
                    304: void sudo_endspent(void);
1.1.1.3   misho     305: void sudo_grlist_addref(struct group_list *);
                    306: void sudo_grlist_delref(struct group_list *);
                    307: void sudo_pw_addref(struct passwd *);
                    308: void sudo_pw_delref(struct passwd *);
1.1.1.4   misho     309: void sudo_set_grlist(struct passwd *pw, char * const *groups,
                    310:     char * const *gids);
1.1.1.3   misho     311: void sudo_setgrent(void);
                    312: void sudo_setpwent(void);
                    313: void sudo_setspent(void);
1.1       misho     314: 
                    315: /* timestr.c */
                    316: char *get_timestr(time_t, int);
                    317: 
                    318: /* atobool.c */
                    319: int atobool(const char *str);
                    320: 
1.1.1.5 ! misho     321: /* atoid.c */
        !           322: int atoid(const char *str, const char *sep, char **endp, const char **errstr);
        !           323: 
1.1       misho     324: /* boottime.c */
                    325: int get_boottime(struct timeval *);
                    326: 
                    327: /* iolog.c */
1.1.1.4   misho     328: int io_set_max_sessid(const char *sessid);
1.1.1.3   misho     329: void io_nextid(char *iolog_dir, char *iolog_dir_fallback, char sessid[7]);
1.1       misho     330: 
                    331: /* iolog_path.c */
                    332: char *expand_iolog_path(const char *prefix, const char *dir, const char *file,
                    333:     char **slashp);
                    334: 
                    335: /* env.c */
                    336: char **env_get(void);
1.1.1.5 ! misho     337: void env_merge(char * const envp[]);
1.1       misho     338: void env_init(char * const envp[]);
                    339: void init_envtables(void);
                    340: void insert_env_vars(char * const envp[]);
                    341: void read_env_file(const char *, int);
                    342: void rebuild_env(void);
                    343: void validate_env_vars(char * const envp[]);
1.1.1.2   misho     344: int sudo_setenv(const char *var, const char *val, int overwrite);
                    345: int sudo_unsetenv(const char *var);
                    346: char *sudo_getenv(const char *name);
                    347: int sudoers_hook_getenv(const char *name, char **value, void *closure);
                    348: int sudoers_hook_putenv(char *string, void *closure);
                    349: int sudoers_hook_setenv(const char *name, const char *value, int overwrite, void *closure);
                    350: int sudoers_hook_unsetenv(const char *name, void *closure);
1.1       misho     351: 
                    352: /* fmt_string.c */
                    353: char *fmt_string(const char *, const char *);
                    354: 
                    355: /* sudoers.c */
1.1.1.2   misho     356: FILE *open_sudoers(const char *, bool, bool *);
1.1.1.4   misho     357: int sudoers_policy_init(void *info, char * const envp[]);
                    358: int sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[], void *closure);
                    359: void sudoers_cleanup(void);
                    360: 
                    361: /* policy.c */
                    362: int sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group);
                    363: int sudoers_policy_exec_setup(char *argv[], char *envp[], mode_t cmnd_umask, char *iolog_path, void *v);
                    364: extern const char *path_ldap_conf;
                    365: extern const char *path_ldap_secret;
1.1       misho     366: 
                    367: /* aix.c */
                    368: void aix_restoreauthdb(void);
                    369: void aix_setauthdb(char *user);
                    370: 
                    371: /* group_plugin.c */
                    372: int group_plugin_load(char *plugin_info);
                    373: void group_plugin_unload(void);
                    374: int group_plugin_query(const char *user, const char *group,
                    375:     const struct passwd *pwd);
                    376: 
                    377: /* setgroups.c */
                    378: int sudo_setgroups(int ngids, const GETGROUPS_T *gids);
                    379: 
1.1.1.5 ! misho     380: /* gidlist.c */
        !           381: int parse_gid_list(const char *gidstr, const gid_t *basegid, GETGROUPS_T **gidsp);
        !           382: 
1.1       misho     383: #ifndef _SUDO_MAIN
                    384: extern struct sudo_user sudo_user;
                    385: extern struct passwd *list_pw;
                    386: extern int long_list;
                    387: extern int sudo_mode;
                    388: extern uid_t timestamp_uid;
                    389: extern sudo_conv_t sudo_conv;
                    390: #endif
                    391: 
1.1.1.4   misho     392: #endif /* _SUDOERS_SUDOERS_H */

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