2
* Copyright (c) 2009-2011 Todd C. Miller <Todd.Miller@courtesan.com>
2
* Copyright (c) 2009-2012 Todd C. Miller <Todd.Miller@courtesan.com>
4
4
* Permission to use, copy, modify, and distribute this software for any
5
5
* purpose with or without fee is hereby granted, provided that the above
20
20
/* API version major/minor */
21
21
#define SUDO_API_VERSION_MAJOR 1
22
#define SUDO_API_VERSION_MINOR 1
22
#define SUDO_API_VERSION_MINOR 2
23
23
#define SUDO_API_MKVERSION(x, y) ((x << 16) | y)
24
24
#define SUDO_API_VERSION SUDO_API_MKVERSION(SUDO_API_VERSION_MAJOR, SUDO_API_VERSION_MINOR)
29
29
#define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \
30
30
*(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \
32
#define SUDO_VERSION_SET_MINOR(vp, n) do { \
32
#define SUDO_API_VERSION_SET_MINOR(vp, n) do { \
33
33
*(vp) = (*(vp) & 0xffff0000) | (n); \
40
40
#define SUDO_CONV_ERROR_MSG 0x0003 /* error message */
41
41
#define SUDO_CONV_INFO_MSG 0x0004 /* informational message */
42
42
#define SUDO_CONV_PROMPT_MASK 0x0005 /* mask user input */
43
#define SUDO_CONV_DEBUG_MSG 0x0006 /* debugging message */
43
44
#define SUDO_CONV_PROMPT_ECHO_OK 0x1000 /* flag: allow echo if no tty */
54
55
struct sudo_conv_reply replies[]);
55
56
typedef int (*sudo_printf_t)(int msg_type, const char *fmt, ...);
59
* Hooks allow a plugin to hook into specific sudo and/or libc functions.
62
/* Hook functions typedefs. */
63
typedef int (*sudo_hook_fn_t)();
64
typedef int (*sudo_hook_fn_setenv_t)(const char *name, const char *value, int overwrite, void *closure);
65
typedef int (*sudo_hook_fn_putenv_t)(char *string, void *closure);
66
typedef int (*sudo_hook_fn_getenv_t)(const char *name, char **value, void *closure);
67
typedef int (*sudo_hook_fn_unsetenv_t)(const char *name, void *closure);
69
/* Hook structure definition. */
73
sudo_hook_fn_t hook_fn;
77
/* Hook API version major/minor */
78
#define SUDO_HOOK_VERSION_MAJOR 1
79
#define SUDO_HOOK_VERSION_MINOR 0
80
#define SUDO_HOOK_MKVERSION(x, y) ((x << 16) | y)
81
#define SUDO_HOOK_VERSION SUDO_HOOK_MKVERSION(SUDO_HOOK_VERSION_MAJOR, SUDO_HOOK_VERSION_MINOR)
83
/* Getters and setters for hook API version */
84
#define SUDO_HOOK_VERSION_GET_MAJOR(v) ((v) >> 16)
85
#define SUDO_HOOK_VERSION_GET_MINOR(v) ((v) & 0xffff)
86
#define SUDO_HOOK_VERSION_SET_MAJOR(vp, n) do { \
87
*(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \
89
#define SUDO_HOOK_VERSION_SET_MINOR(vp, n) do { \
90
*(vp) = (*(vp) & 0xffff0000) | (n); \
94
* Hook function return values.
96
#define SUDO_HOOK_RET_ERROR -1 /* error */
97
#define SUDO_HOOK_RET_NEXT 0 /* go to the next hook in the list */
98
#define SUDO_HOOK_RET_STOP 1 /* stop hook processing for this type */
101
* Hooks for setenv/unsetenv/putenv/getenv.
102
* This allows the plugin to be notified when a PAM module modifies
103
* the environment so it can update the copy of the environment that
104
* is passed to execve().
106
#define SUDO_HOOK_SETENV 1
107
#define SUDO_HOOK_UNSETENV 2
108
#define SUDO_HOOK_PUTENV 3
109
#define SUDO_HOOK_GETENV 4
57
111
/* Policy plugin type and defines */
59
113
struct policy_plugin {
62
116
unsigned int version; /* always SUDO_API_VERSION */
63
117
int (*open)(unsigned int version, sudo_conv_t conversation,
64
118
sudo_printf_t sudo_printf, char * const settings[],
65
char * const user_info[], char * const user_env[]);
119
char * const user_info[], char * const user_env[],
120
char * const plugin_plugins[]);
66
121
void (*close)(int exit_status, int error); /* wait status or error */
67
122
int (*show_version)(int verbose);
68
123
int (*check_policy)(int argc, char * const argv[],
72
127
const char *list_user);
73
128
int (*validate)(void);
74
129
void (*invalidate)(int remove);
75
int (*init_session)(struct passwd *pwd);
130
int (*init_session)(struct passwd *pwd, char **user_env_out[]);
131
void (*register_hooks)(int version, int (*register_hook)(struct sudo_hook *hook));
132
void (*deregister_hooks)(int version, int (*deregister_hook)(struct sudo_hook *hook));
78
135
/* I/O plugin type and defines */
83
140
int (*open)(unsigned int version, sudo_conv_t conversation,
84
141
sudo_printf_t sudo_printf, char * const settings[],
85
142
char * const user_info[], char * const command_info[],
86
int argc, char * const argv[], char * const user_env[]);
143
int argc, char * const argv[], char * const user_env[],
144
char * const plugin_plugins[]);
87
145
void (*close)(int exit_status, int error); /* wait status or error */
88
146
int (*show_version)(int verbose);
89
147
int (*log_ttyin)(const char *buf, unsigned int len);
91
149
int (*log_stdin)(const char *buf, unsigned int len);
92
150
int (*log_stdout)(const char *buf, unsigned int len);
93
151
int (*log_stderr)(const char *buf, unsigned int len);
152
void (*register_hooks)(int version, int (*register_hook)(struct sudo_hook *hook));
153
void (*deregister_hooks)(int version, int (*deregister_hook)(struct sudo_hook *hook));
96
156
/* Sudoers group plugin version major/minor */