Annotation of embedaddon/sudo/include/sudo_plugin.h, revision 1.1.1.4

1.1       misho       1: /*
1.1.1.3   misho       2:  * Copyright (c) 2009-2013 Todd C. Miller <Todd.Miller@courtesan.com>
1.1       misho       3:  *
                      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.
                     15:  */
                     16: 
                     17: #ifndef _SUDO_PLUGIN_H
                     18: #define _SUDO_PLUGIN_H
                     19: 
                     20: /* API version major/minor */
                     21: #define SUDO_API_VERSION_MAJOR 1
1.1.1.4 ! misho      22: #define SUDO_API_VERSION_MINOR 4
1.1       misho      23: #define SUDO_API_MKVERSION(x, y) ((x << 16) | y)
                     24: #define SUDO_API_VERSION SUDO_API_MKVERSION(SUDO_API_VERSION_MAJOR, SUDO_API_VERSION_MINOR)
                     25: 
                     26: /* Getters and setters for API version */
                     27: #define SUDO_API_VERSION_GET_MAJOR(v) ((v) >> 16)
                     28: #define SUDO_API_VERSION_GET_MINOR(v) ((v) & 0xffff)
                     29: #define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \
                     30:     *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \
                     31: } while(0)
1.1.1.2   misho      32: #define SUDO_API_VERSION_SET_MINOR(vp, n) do { \
1.1       misho      33:     *(vp) = (*(vp) & 0xffff0000) | (n); \
                     34: } while(0)
                     35: 
                     36: /* Conversation function types and defines */
                     37: struct sudo_conv_message {
                     38: #define SUDO_CONV_PROMPT_ECHO_OFF   0x0001  /* do not echo user input */
                     39: #define SUDO_CONV_PROMPT_ECHO_ON    0x0002  /* echo user input */
                     40: #define SUDO_CONV_ERROR_MSG        0x0003  /* error message */
                     41: #define SUDO_CONV_INFO_MSG         0x0004  /* informational message */
                     42: #define SUDO_CONV_PROMPT_MASK      0x0005  /* mask user input */
1.1.1.2   misho      43: #define SUDO_CONV_DEBUG_MSG        0x0006  /* debugging message */
1.1       misho      44: #define SUDO_CONV_PROMPT_ECHO_OK    0x1000  /* flag: allow echo if no tty */
                     45:     int msg_type;
                     46:     int timeout;
                     47:     const char *msg;
                     48: };
                     49: 
1.1.1.4 ! misho      50: /*
        !            51:  * Maximum length of a reply (not including the trailing NUL) when
        !            52:  * conversing with the user.  In practical terms, this is the longest
        !            53:  * password sudo will support.  This means that a buffer of size
        !            54:  * SUDO_CONV_REPL_MAX+1 is guaranteed to be able to hold any reply
        !            55:  * from the conversation function.  It is also useful as a max value
        !            56:  * for memset_s() when clearing passwords returned by the conversation
        !            57:  * function.
        !            58:  */
        !            59: #define SUDO_CONV_REPL_MAX     255
        !            60: 
1.1       misho      61: struct sudo_conv_reply {
                     62:     char *reply;
                     63: };
                     64: 
                     65: typedef int (*sudo_conv_t)(int num_msgs, const struct sudo_conv_message msgs[],
                     66:        struct sudo_conv_reply replies[]);
                     67: typedef int (*sudo_printf_t)(int msg_type, const char *fmt, ...);
                     68: 
1.1.1.2   misho      69: /*
                     70:  * Hooks allow a plugin to hook into specific sudo and/or libc functions.
                     71:  */
                     72: 
                     73: /* Hook functions typedefs. */
                     74: typedef int (*sudo_hook_fn_t)();
                     75: typedef int (*sudo_hook_fn_setenv_t)(const char *name, const char *value, int overwrite, void *closure);
                     76: typedef int (*sudo_hook_fn_putenv_t)(char *string, void *closure);
                     77: typedef int (*sudo_hook_fn_getenv_t)(const char *name, char **value, void *closure);
                     78: typedef int (*sudo_hook_fn_unsetenv_t)(const char *name, void *closure);
                     79: 
                     80: /* Hook structure definition. */
                     81: struct sudo_hook {
                     82:     int hook_version;
                     83:     int hook_type;
                     84:     sudo_hook_fn_t hook_fn;
                     85:     void *closure;
                     86: };
                     87: 
                     88: /* Hook API version major/minor */
                     89: #define SUDO_HOOK_VERSION_MAJOR        1
                     90: #define SUDO_HOOK_VERSION_MINOR        0
                     91: #define SUDO_HOOK_MKVERSION(x, y) ((x << 16) | y)
                     92: #define SUDO_HOOK_VERSION SUDO_HOOK_MKVERSION(SUDO_HOOK_VERSION_MAJOR, SUDO_HOOK_VERSION_MINOR)
                     93: 
                     94: /* Getters and setters for hook API version */
                     95: #define SUDO_HOOK_VERSION_GET_MAJOR(v) ((v) >> 16)
                     96: #define SUDO_HOOK_VERSION_GET_MINOR(v) ((v) & 0xffff)
                     97: #define SUDO_HOOK_VERSION_SET_MAJOR(vp, n) do { \
                     98:     *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \
                     99: } while(0)
                    100: #define SUDO_HOOK_VERSION_SET_MINOR(vp, n) do { \
                    101:     *(vp) = (*(vp) & 0xffff0000) | (n); \
                    102: } while(0)
                    103: 
                    104: /*
                    105:  * Hook function return values.
                    106:  */
                    107: #define SUDO_HOOK_RET_ERROR    -1      /* error */
                    108: #define SUDO_HOOK_RET_NEXT     0       /* go to the next hook in the list */
                    109: #define SUDO_HOOK_RET_STOP     1       /* stop hook processing for this type */
                    110: 
                    111: /*
                    112:  * Hooks for setenv/unsetenv/putenv/getenv.
                    113:  * This allows the plugin to be notified when a PAM module modifies
                    114:  * the environment so it can update the copy of the environment that
                    115:  * is passed to execve().
                    116:  */
                    117: #define SUDO_HOOK_SETENV       1
                    118: #define SUDO_HOOK_UNSETENV     2
                    119: #define SUDO_HOOK_PUTENV       3
                    120: #define SUDO_HOOK_GETENV       4
                    121: 
1.1       misho     122: /* Policy plugin type and defines */
                    123: struct passwd;
                    124: struct policy_plugin {
                    125: #define SUDO_POLICY_PLUGIN     1
                    126:     unsigned int type; /* always SUDO_POLICY_PLUGIN */
                    127:     unsigned int version; /* always SUDO_API_VERSION */
                    128:     int (*open)(unsigned int version, sudo_conv_t conversation,
                    129:        sudo_printf_t sudo_printf, char * const settings[],
1.1.1.2   misho     130:        char * const user_info[], char * const user_env[],
                    131:        char * const plugin_plugins[]);
1.1       misho     132:     void (*close)(int exit_status, int error); /* wait status or error */
                    133:     int (*show_version)(int verbose);
                    134:     int (*check_policy)(int argc, char * const argv[],
                    135:        char *env_add[], char **command_info[],
                    136:        char **argv_out[], char **user_env_out[]);
                    137:     int (*list)(int argc, char * const argv[], int verbose,
                    138:        const char *list_user);
                    139:     int (*validate)(void);
                    140:     void (*invalidate)(int remove);
1.1.1.2   misho     141:     int (*init_session)(struct passwd *pwd, char **user_env_out[]);
                    142:     void (*register_hooks)(int version, int (*register_hook)(struct sudo_hook *hook));
                    143:     void (*deregister_hooks)(int version, int (*deregister_hook)(struct sudo_hook *hook));
1.1       misho     144: };
                    145: 
                    146: /* I/O plugin type and defines */
                    147: struct io_plugin {
                    148: #define SUDO_IO_PLUGIN     2
                    149:     unsigned int type; /* always SUDO_IO_PLUGIN */
                    150:     unsigned int version; /* always SUDO_API_VERSION */
                    151:     int (*open)(unsigned int version, sudo_conv_t conversation,
                    152:        sudo_printf_t sudo_printf, char * const settings[],
                    153:        char * const user_info[], char * const command_info[],
1.1.1.2   misho     154:        int argc, char * const argv[], char * const user_env[],
                    155:        char * const plugin_plugins[]);
1.1       misho     156:     void (*close)(int exit_status, int error); /* wait status or error */
                    157:     int (*show_version)(int verbose);
                    158:     int (*log_ttyin)(const char *buf, unsigned int len);
                    159:     int (*log_ttyout)(const char *buf, unsigned int len);
                    160:     int (*log_stdin)(const char *buf, unsigned int len);
                    161:     int (*log_stdout)(const char *buf, unsigned int len);
                    162:     int (*log_stderr)(const char *buf, unsigned int len);
1.1.1.2   misho     163:     void (*register_hooks)(int version, int (*register_hook)(struct sudo_hook *hook));
                    164:     void (*deregister_hooks)(int version, int (*deregister_hook)(struct sudo_hook *hook));
1.1       misho     165: };
                    166: 
                    167: /* Sudoers group plugin version major/minor */
                    168: #define GROUP_API_VERSION_MAJOR 1
                    169: #define GROUP_API_VERSION_MINOR 0
                    170: #define GROUP_API_VERSION ((GROUP_API_VERSION_MAJOR << 16) | GROUP_API_VERSION_MINOR)
                    171: 
                    172: /* Getters and setters for group version */
                    173: #define GROUP_API_VERSION_GET_MAJOR(v) ((v) >> 16)
                    174: #define GROUP_API_VERSION_GET_MINOR(v) ((v) & 0xffff)
                    175: #define GROUP_API_VERSION_SET_MAJOR(vp, n) do { \
                    176:     *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \
                    177: } while(0)
                    178: #define GROUP_API_VERSION_SET_MINOR(vp, n) do { \
                    179:     *(vp) = (*(vp) & 0xffff0000) | (n); \
                    180: } while(0)
                    181: 
                    182: /*
                    183:  * version: for compatibility checking
                    184:  * group_init: return 1 on success, 0 if unconfigured, -1 on error.
                    185:  * group_cleanup: called to clean up resources used by provider
                    186:  * user_in_group: returns 1 if user is in group, 0 if not.
                    187:  *                note that pwd may be NULL if the user is not in passwd.
                    188:  */
                    189: struct sudoers_group_plugin {
                    190:     unsigned int version;
                    191:     int (*init)(int version, sudo_printf_t sudo_printf, char *const argv[]);
                    192:     void (*cleanup)(void);
                    193:     int (*query)(const char *user, const char *group, const struct passwd *pwd);
                    194: };
                    195: 
                    196: #endif /* _SUDO_PLUGIN_H */

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