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

1.1     ! misho       1: /*
        !             2:  * Copyright (c) 2009-2011 Todd C. Miller <Todd.Miller@courtesan.com>
        !             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
        !            22: #define SUDO_API_VERSION_MINOR 1
        !            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)
        !            32: #define SUDO_VERSION_SET_MINOR(vp, n) do { \
        !            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 */
        !            43: #define SUDO_CONV_PROMPT_ECHO_OK    0x1000  /* flag: allow echo if no tty */
        !            44:     int msg_type;
        !            45:     int timeout;
        !            46:     const char *msg;
        !            47: };
        !            48: 
        !            49: struct sudo_conv_reply {
        !            50:     char *reply;
        !            51: };
        !            52: 
        !            53: typedef int (*sudo_conv_t)(int num_msgs, const struct sudo_conv_message msgs[],
        !            54:        struct sudo_conv_reply replies[]);
        !            55: typedef int (*sudo_printf_t)(int msg_type, const char *fmt, ...);
        !            56: 
        !            57: /* Policy plugin type and defines */
        !            58: struct passwd;
        !            59: struct policy_plugin {
        !            60: #define SUDO_POLICY_PLUGIN     1
        !            61:     unsigned int type; /* always SUDO_POLICY_PLUGIN */
        !            62:     unsigned int version; /* always SUDO_API_VERSION */
        !            63:     int (*open)(unsigned int version, sudo_conv_t conversation,
        !            64:        sudo_printf_t sudo_printf, char * const settings[],
        !            65:        char * const user_info[], char * const user_env[]);
        !            66:     void (*close)(int exit_status, int error); /* wait status or error */
        !            67:     int (*show_version)(int verbose);
        !            68:     int (*check_policy)(int argc, char * const argv[],
        !            69:        char *env_add[], char **command_info[],
        !            70:        char **argv_out[], char **user_env_out[]);
        !            71:     int (*list)(int argc, char * const argv[], int verbose,
        !            72:        const char *list_user);
        !            73:     int (*validate)(void);
        !            74:     void (*invalidate)(int remove);
        !            75:     int (*init_session)(struct passwd *pwd);
        !            76: };
        !            77: 
        !            78: /* I/O plugin type and defines */
        !            79: struct io_plugin {
        !            80: #define SUDO_IO_PLUGIN     2
        !            81:     unsigned int type; /* always SUDO_IO_PLUGIN */
        !            82:     unsigned int version; /* always SUDO_API_VERSION */
        !            83:     int (*open)(unsigned int version, sudo_conv_t conversation,
        !            84:        sudo_printf_t sudo_printf, char * const settings[],
        !            85:        char * const user_info[], char * const command_info[],
        !            86:        int argc, char * const argv[], char * const user_env[]);
        !            87:     void (*close)(int exit_status, int error); /* wait status or error */
        !            88:     int (*show_version)(int verbose);
        !            89:     int (*log_ttyin)(const char *buf, unsigned int len);
        !            90:     int (*log_ttyout)(const char *buf, unsigned int len);
        !            91:     int (*log_stdin)(const char *buf, unsigned int len);
        !            92:     int (*log_stdout)(const char *buf, unsigned int len);
        !            93:     int (*log_stderr)(const char *buf, unsigned int len);
        !            94: };
        !            95: 
        !            96: /* Sudoers group plugin version major/minor */
        !            97: #define GROUP_API_VERSION_MAJOR 1
        !            98: #define GROUP_API_VERSION_MINOR 0
        !            99: #define GROUP_API_VERSION ((GROUP_API_VERSION_MAJOR << 16) | GROUP_API_VERSION_MINOR)
        !           100: 
        !           101: /* Getters and setters for group version */
        !           102: #define GROUP_API_VERSION_GET_MAJOR(v) ((v) >> 16)
        !           103: #define GROUP_API_VERSION_GET_MINOR(v) ((v) & 0xffff)
        !           104: #define GROUP_API_VERSION_SET_MAJOR(vp, n) do { \
        !           105:     *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \
        !           106: } while(0)
        !           107: #define GROUP_API_VERSION_SET_MINOR(vp, n) do { \
        !           108:     *(vp) = (*(vp) & 0xffff0000) | (n); \
        !           109: } while(0)
        !           110: 
        !           111: /*
        !           112:  * version: for compatibility checking
        !           113:  * group_init: return 1 on success, 0 if unconfigured, -1 on error.
        !           114:  * group_cleanup: called to clean up resources used by provider
        !           115:  * user_in_group: returns 1 if user is in group, 0 if not.
        !           116:  *                note that pwd may be NULL if the user is not in passwd.
        !           117:  */
        !           118: struct sudoers_group_plugin {
        !           119:     unsigned int version;
        !           120:     int (*init)(int version, sudo_printf_t sudo_printf, char *const argv[]);
        !           121:     void (*cleanup)(void);
        !           122:     int (*query)(const char *user, const char *group, const struct passwd *pwd);
        !           123: };
        !           124: 
        !           125: #endif /* _SUDO_PLUGIN_H */

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