Merge commit 'upstream/1.8.1p2'
[debian/sudo] / src / sudo_plugin_int.h
1 /*
2  * Copyright (c) 2010-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_INT_H
18 #define _SUDO_PLUGIN_INT_H
19
20 /*
21  * All plugin structures start with a type and a version.
22  */
23 struct generic_plugin {
24     unsigned int type;
25     unsigned int version;
26     /* the rest depends on the type... */
27 };
28
29 /*
30  * Backwards-compatible structures for API bumps.
31  */
32 struct io_plugin_1_0 {
33     unsigned int type;
34     unsigned int version;
35     int (*open)(unsigned int version, sudo_conv_t conversation,
36         sudo_printf_t sudo_printf, char * const settings[],
37         char * const user_info[], int argc, char * const argv[],
38         char * const user_env[]);
39     void (*close)(int exit_status, int error);
40     int (*show_version)(int verbose);
41     int (*log_ttyin)(const char *buf, unsigned int len);
42     int (*log_ttyout)(const char *buf, unsigned int len);
43     int (*log_stdin)(const char *buf, unsigned int len);
44     int (*log_stdout)(const char *buf, unsigned int len);
45     int (*log_stderr)(const char *buf, unsigned int len);
46 };
47
48 /*
49  * Sudo plugin internals.
50  */
51
52 struct plugin_info {
53     struct plugin_info *prev; /* required */
54     struct plugin_info *next; /* required */
55     const char *path;
56     const char *symbol_name;
57 };
58 TQ_DECLARE(plugin_info)
59
60 struct plugin_container {
61     struct plugin_container *prev; /* required */
62     struct plugin_container *next; /* required */
63     const char *name;
64     void *handle;
65     union {
66         struct generic_plugin *generic;
67         struct policy_plugin *policy;
68         struct io_plugin *io;
69         struct io_plugin_1_0 *io_1_0;
70     } u;
71 };
72 TQ_DECLARE(plugin_container)
73
74 extern struct plugin_container_list policy_plugins;
75 extern struct plugin_container_list io_plugins;
76
77 int sudo_conversation(int num_msgs, const struct sudo_conv_message msgs[],
78     struct sudo_conv_reply replies[]);
79 int _sudo_printf(int msg_type, const char *fmt, ...);
80
81 int sudo_load_plugins(const char *conf_file,
82     struct plugin_container *policy_plugin,
83     struct plugin_container_list *io_plugins);
84
85 #endif /* _SUDO_PLUGIN_INT_H */