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

1.1       misho       1: /*
                      2:  * Copyright (c) 1993-1996, 1998-2005, 2007-2011
                      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: 
                     22: #ifndef _SUDO_SUDOERS_H
                     23: #define _SUDO_SUDOERS_H
                     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
                     84:     char *cwd;
                     85:     char *iolog_file;
                     86:     int   closefrom;
                     87:     int   lines;
                     88:     int   cols;
                     89:     uid_t uid;
                     90:     uid_t gid;
                     91: };
                     92: 
                     93: /*
                     94:  * Return values for sudoers_lookup(), also used as arguments for log_auth()
                     95:  * Note: cannot use '0' as a value here.
                     96:  */
                     97: /* XXX - VALIDATE_SUCCESS and VALIDATE_FAILURE instead? */
                     98: #define VALIDATE_ERROR          0x001
                     99: #define VALIDATE_OK            0x002
                    100: #define VALIDATE_NOT_OK                0x004
                    101: #define FLAG_CHECK_USER                0x010
                    102: #define FLAG_NO_USER           0x020
                    103: #define FLAG_NO_HOST           0x040
                    104: #define FLAG_NO_CHECK          0x080
                    105: 
                    106: /*
                    107:  * find_path()/load_cmnd() return values
                    108:  */
                    109: #define FOUND                   0
                    110: #define NOT_FOUND               1
                    111: #define NOT_FOUND_DOT          2
                    112: 
                    113: /*
                    114:  * Various modes sudo can be in (based on arguments) in hex
                    115:  */
                    116: #define MODE_RUN               0x00000001
                    117: #define MODE_EDIT              0x00000002
                    118: #define MODE_VALIDATE          0x00000004
                    119: #define MODE_INVALIDATE                0x00000008
                    120: #define MODE_KILL              0x00000010
                    121: #define MODE_VERSION           0x00000020
                    122: #define MODE_HELP              0x00000040
                    123: #define MODE_LIST              0x00000080
                    124: #define MODE_CHECK             0x00000100
                    125: #define MODE_LISTDEFS          0x00000200
                    126: #define MODE_MASK              0x0000ffff
                    127: 
                    128: /* Mode flags */
                    129: #define MODE_BACKGROUND                0x00010000 /* XXX - unused */
                    130: #define MODE_SHELL             0x00020000
                    131: #define MODE_LOGIN_SHELL       0x00040000
                    132: #define MODE_IMPLIED_SHELL     0x00080000
                    133: #define MODE_RESET_HOME                0x00100000
                    134: #define MODE_PRESERVE_GROUPS   0x00200000
                    135: #define MODE_PRESERVE_ENV      0x00400000
                    136: #define MODE_NONINTERACTIVE    0x00800000
                    137: #define MODE_IGNORE_TICKET     0x01000000
                    138: 
                    139: /*
                    140:  * Used with set_perms()
                    141:  */
                    142: #define PERM_INITIAL             0x00
                    143: #define PERM_ROOT                0x01
                    144: #define PERM_USER                0x02
                    145: #define PERM_FULL_USER           0x03
                    146: #define PERM_SUDOERS             0x04
                    147: #define PERM_RUNAS               0x05
                    148: #define PERM_TIMESTAMP           0x06
                    149: #define PERM_NOEXIT              0x10 /* flag */
                    150: #define PERM_MASK                0xf0
                    151: 
                    152: /*
                    153:  * Shortcuts for sudo_user contents.
                    154:  */
                    155: #define user_name              (sudo_user.name)
                    156: #define user_uid               (sudo_user.uid)
                    157: #define user_gid               (sudo_user.gid)
                    158: #define user_passwd            (sudo_user.pw->pw_passwd)
                    159: #define user_uuid              (sudo_user.uuid)
                    160: #define user_dir               (sudo_user.pw->pw_dir)
                    161: #define user_group_list                (sudo_user.group_list)
                    162: #define user_tty               (sudo_user.tty)
                    163: #define user_ttypath           (sudo_user.ttypath)
                    164: #define user_cwd               (sudo_user.cwd)
                    165: #define user_cmnd              (sudo_user.cmnd)
                    166: #define user_args              (sudo_user.cmnd_args)
                    167: #define user_base              (sudo_user.cmnd_base)
                    168: #define user_stat              (sudo_user.cmnd_stat)
                    169: #define user_path              (sudo_user.path)
                    170: #define user_prompt            (sudo_user.prompt)
                    171: #define user_host              (sudo_user.host)
                    172: #define user_shost             (sudo_user.shost)
                    173: #define user_ccname            (sudo_user.krb5_ccname)
                    174: #define safe_cmnd              (sudo_user.cmnd_safe)
                    175: #define login_class            (sudo_user.class_name)
                    176: #define runas_pw               (sudo_user._runas_pw)
                    177: #define runas_gr               (sudo_user._runas_gr)
                    178: #define user_role              (sudo_user.role)
                    179: #define user_type              (sudo_user.type)
                    180: #define user_closefrom         (sudo_user.closefrom)
                    181: 
                    182: #ifdef __TANDEM
                    183: # define ROOT_UID       65535
                    184: #else
                    185: # define ROOT_UID       0
                    186: #endif
                    187: 
                    188: /*
                    189:  * We used to use the system definition of PASS_MAX or _PASSWD_LEN,
                    190:  * but that caused problems with various alternate authentication
                    191:  * methods.  So, we just define our own and assume that it is >= the
                    192:  * system max.
                    193:  */
                    194: #define SUDO_PASS_MAX  256
                    195: 
                    196: struct lbuf;
                    197: struct passwd;
                    198: struct stat;
                    199: struct timeval;
                    200: 
                    201: /*
                    202:  * Function prototypes
                    203:  */
                    204: #define YY_DECL int yylex(void)
                    205: 
                    206: /* goodpath.c */
1.1.1.2 ! misho     207: bool sudo_goodpath(const char *, struct stat *);
1.1       misho     208: 
                    209: /* findpath.c */
                    210: int find_path(char *, char **, struct stat *, char *, int);
                    211: 
                    212: /* check.c */
                    213: int check_user(int, int);
1.1.1.2 ! misho     214: void remove_timestamp(bool);
        !           215: bool user_is_exempt(void);
1.1       misho     216: 
                    217: /* sudo_auth.c */
1.1.1.2 ! misho     218: int verify_user(struct passwd *pw, char *prompt);
        !           219: int sudo_auth_begin_session(struct passwd *pw, char **user_env[]);
        !           220: int sudo_auth_end_session(struct passwd *pw);
1.1       misho     221: int sudo_auth_init(struct passwd *pw);
                    222: int sudo_auth_cleanup(struct passwd *pw);
                    223: 
                    224: /* parse.c */
                    225: int sudo_file_open(struct sudo_nss *);
                    226: int sudo_file_close(struct sudo_nss *);
                    227: int sudo_file_setdefs(struct sudo_nss *);
                    228: int sudo_file_lookup(struct sudo_nss *, int, int);
                    229: int sudo_file_parse(struct sudo_nss *);
                    230: int sudo_file_display_cmnd(struct sudo_nss *, struct passwd *);
                    231: int sudo_file_display_defaults(struct sudo_nss *, struct passwd *, struct lbuf *);
                    232: int sudo_file_display_bound_defaults(struct sudo_nss *, struct passwd *, struct lbuf *);
                    233: int sudo_file_display_privs(struct sudo_nss *, struct passwd *, struct lbuf *);
                    234: 
                    235: /* set_perms.c */
                    236: void rewind_perms(void);
                    237: int set_perms(int);
                    238: void restore_perms(void);
                    239: int pam_prep_user(struct passwd *);
                    240: 
                    241: /* gram.y */
                    242: int yyparse(void);
                    243: 
                    244: /* toke.l */
                    245: YY_DECL;
1.1.1.2 ! misho     246: extern const char *sudoers_file;
        !           247: extern mode_t sudoers_mode;
        !           248: extern uid_t sudoers_uid;
        !           249: extern gid_t sudoers_gid;
1.1       misho     250: 
                    251: /* defaults.c */
                    252: void dump_defaults(void);
                    253: void dump_auth_methods(void);
                    254: 
                    255: /* getspwuid.c */
                    256: char *sudo_getepw(const struct passwd *);
                    257: 
                    258: /* zero_bytes.c */
                    259: void zero_bytes(volatile void *, size_t);
                    260: 
                    261: /* sudo_nss.c */
                    262: void display_privs(struct sudo_nss_list *, struct passwd *);
1.1.1.2 ! misho     263: bool display_cmnd(struct sudo_nss_list *, struct passwd *);
1.1       misho     264: 
                    265: /* pwutil.c */
                    266: void sudo_setgrent(void);
                    267: void sudo_endgrent(void);
                    268: void sudo_setpwent(void);
                    269: void sudo_endpwent(void);
                    270: void sudo_setspent(void);
                    271: void sudo_endspent(void);
                    272: struct group_list *get_group_list(struct passwd *pw);
                    273: void set_group_list(const char *, GETGROUPS_T *gids, int ngids);
                    274: struct passwd *sudo_getpwnam(const char *);
                    275: struct passwd *sudo_fakepwnamid(const char *user, uid_t uid, gid_t gid);
                    276: struct passwd *sudo_fakepwnam(const char *, gid_t);
                    277: struct passwd *sudo_getpwuid(uid_t);
                    278: struct group *sudo_getgrnam(const char *);
                    279: struct group *sudo_fakegrnam(const char *);
                    280: struct group *sudo_getgrgid(gid_t);
                    281: void grlist_addref(struct group_list *);
                    282: void grlist_delref(struct group_list *);
                    283: void gr_addref(struct group *);
                    284: void gr_delref(struct group *);
                    285: void pw_addref(struct passwd *);
                    286: void pw_delref(struct passwd *);
1.1.1.2 ! misho     287: bool user_in_group(struct passwd *, const char *);
1.1       misho     288: 
                    289: /* timestr.c */
                    290: char *get_timestr(time_t, int);
                    291: 
                    292: /* atobool.c */
                    293: int atobool(const char *str);
                    294: 
                    295: /* boottime.c */
                    296: int get_boottime(struct timeval *);
                    297: 
                    298: /* iolog.c */
                    299: void io_nextid(char *iolog_dir, char sessid[7]);
                    300: 
                    301: /* iolog_path.c */
                    302: char *expand_iolog_path(const char *prefix, const char *dir, const char *file,
                    303:     char **slashp);
                    304: 
                    305: /* env.c */
                    306: char **env_get(void);
1.1.1.2 ! misho     307: void env_merge(char * const envp[], bool overwrite);
1.1       misho     308: void env_init(char * const envp[]);
                    309: void init_envtables(void);
                    310: void insert_env_vars(char * const envp[]);
                    311: void read_env_file(const char *, int);
                    312: void rebuild_env(void);
                    313: void validate_env_vars(char * const envp[]);
1.1.1.2 ! misho     314: int sudo_setenv(const char *var, const char *val, int overwrite);
        !           315: int sudo_unsetenv(const char *var);
        !           316: char *sudo_getenv(const char *name);
        !           317: int sudoers_hook_getenv(const char *name, char **value, void *closure);
        !           318: int sudoers_hook_putenv(char *string, void *closure);
        !           319: int sudoers_hook_setenv(const char *name, const char *value, int overwrite, void *closure);
        !           320: int sudoers_hook_unsetenv(const char *name, void *closure);
1.1       misho     321: 
                    322: /* fmt_string.c */
                    323: char *fmt_string(const char *, const char *);
                    324: 
                    325: /* sudoers.c */
                    326: void plugin_cleanup(int);
                    327: void set_fqdn(void);
1.1.1.2 ! misho     328: FILE *open_sudoers(const char *, bool, bool *);
1.1       misho     329: 
                    330: /* aix.c */
                    331: void aix_restoreauthdb(void);
                    332: void aix_setauthdb(char *user);
                    333: 
                    334: /* group_plugin.c */
                    335: int group_plugin_load(char *plugin_info);
                    336: void group_plugin_unload(void);
                    337: int group_plugin_query(const char *user, const char *group,
                    338:     const struct passwd *pwd);
                    339: 
                    340: /* setgroups.c */
                    341: int sudo_setgroups(int ngids, const GETGROUPS_T *gids);
                    342: 
                    343: #ifndef _SUDO_MAIN
                    344: extern struct sudo_user sudo_user;
                    345: extern struct passwd *list_pw;
                    346: extern int long_list;
                    347: extern int sudo_mode;
                    348: extern uid_t timestamp_uid;
                    349: extern sudo_conv_t sudo_conv;
                    350: extern sudo_printf_t sudo_printf;
                    351: #endif
                    352: 
                    353: #endif /* _SUDO_SUDOERS_H */

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