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

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

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