Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/src/sudo_plugin_int.h
1532 views
1
/*
2
* SPDX-License-Identifier: ISC
3
*
4
* Copyright (c) 2010-2020 Todd C. Miller <[email protected]>
5
*
6
* Permission to use, copy, modify, and distribute this software for any
7
* purpose with or without fee is hereby granted, provided that the above
8
* copyright notice and this permission notice appear in all copies.
9
*
10
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
19
#ifndef SUDO_PLUGIN_INT_H
20
#define SUDO_PLUGIN_INT_H
21
22
/*
23
* All plugin structures start with a type and a version.
24
*/
25
struct generic_plugin {
26
unsigned int type;
27
unsigned int version;
28
/* the rest depends on the type... */
29
};
30
31
typedef int (*sudo_conv_1_7_t)(int num_msgs,
32
const struct sudo_conv_message msgs[], struct sudo_conv_reply replies[]);
33
34
/*
35
* Backwards-compatible structures for API bumps.
36
*/
37
struct policy_plugin_1_0 {
38
unsigned int type;
39
unsigned int version;
40
int (*open)(unsigned int version, sudo_conv_1_7_t conversation,
41
sudo_printf_t sudo_plugin_printf, char * const settings[],
42
char * const user_info[], char * const user_env[]);
43
void (*close)(int exit_status, int error); /* wait status or error */
44
int (*show_version)(int verbose);
45
int (*check_policy)(int argc, char * const argv[],
46
char *env_add[], char **command_info[],
47
char **argv_out[], char **user_env_out[]);
48
int (*list)(int argc, char * const argv[], int verbose,
49
const char *user);
50
int (*validate)(void);
51
void (*invalidate)(int rmcred);
52
int (*init_session)(struct passwd *pwd);
53
};
54
struct io_plugin_1_0 {
55
unsigned int type;
56
unsigned int version;
57
int (*open)(unsigned int version, sudo_conv_1_7_t conversation,
58
sudo_printf_t sudo_plugin_printf, char * const settings[],
59
char * const user_info[], int argc, char * const argv[],
60
char * const user_env[]);
61
void (*close)(int exit_status, int error);
62
int (*show_version)(int verbose);
63
int (*log_ttyin)(const char *buf, unsigned int len);
64
int (*log_ttyout)(const char *buf, unsigned int len);
65
int (*log_stdin)(const char *buf, unsigned int len);
66
int (*log_stdout)(const char *buf, unsigned int len);
67
int (*log_stderr)(const char *buf, unsigned int len);
68
};
69
struct io_plugin_1_1 {
70
unsigned int type;
71
unsigned int version;
72
int (*open)(unsigned int version, sudo_conv_1_7_t conversation,
73
sudo_printf_t sudo_plugin_printf, char * const settings[],
74
char * const user_info[], char * const command_info[],
75
int argc, char * const argv[], char * const user_env[]);
76
void (*close)(int exit_status, int error); /* wait status or error */
77
int (*show_version)(int verbose);
78
int (*log_ttyin)(const char *buf, unsigned int len);
79
int (*log_ttyout)(const char *buf, unsigned int len);
80
int (*log_stdin)(const char *buf, unsigned int len);
81
int (*log_stdout)(const char *buf, unsigned int len);
82
int (*log_stderr)(const char *buf, unsigned int len);
83
};
84
85
/*
86
* Sudo plugin internals.
87
*/
88
struct plugin_container {
89
TAILQ_ENTRY(plugin_container) entries;
90
struct sudo_conf_debug_file_list *debug_files;
91
char *name;
92
char *path;
93
char **options;
94
void *handle;
95
int debug_instance;
96
union {
97
struct generic_plugin *generic;
98
struct policy_plugin *policy;
99
struct policy_plugin_1_0 *policy_1_0;
100
struct io_plugin *io;
101
struct io_plugin_1_0 *io_1_0;
102
struct io_plugin_1_1 *io_1_1;
103
struct audit_plugin *audit;
104
struct approval_plugin *approval;
105
} u;
106
};
107
TAILQ_HEAD(plugin_container_list, plugin_container);
108
109
/*
110
* Private implementation of struct sudo_plugin_event.
111
*/
112
struct sudo_plugin_event_int {
113
struct sudo_event private; /* must be first */
114
int debug_instance; /* plugin's debug instance */
115
void *closure; /* actual user closure */
116
sudo_ev_callback_t callback; /* actual user callback */
117
struct sudo_plugin_event public; /* user-visible portion */
118
};
119
120
extern struct plugin_container policy_plugin;
121
extern struct plugin_container_list io_plugins;
122
extern struct plugin_container_list audit_plugins;
123
extern struct plugin_container_list approval_plugins;
124
125
int sudo_conversation(int num_msgs, const struct sudo_conv_message msgs[],
126
struct sudo_conv_reply replies[], struct sudo_conv_callback *callback);
127
int sudo_conversation_1_7(int num_msgs, const struct sudo_conv_message msgs[],
128
struct sudo_conv_reply replies[]);
129
int sudo_conversation_printf(int msg_type, const char * restrict fmt, ...);
130
131
bool sudo_load_plugins(void);
132
133
#endif /* SUDO_PLUGIN_INT_H */
134
135