Imported Upstream version 1.8.4p4
[debian/sudo] / doc / sudo_plugin.man.in
1 .\" Copyright (c) 2009-2012 Todd C. Miller <Todd.Miller@courtesan.com>
2 .\" 
3 .\" Permission to use, copy, modify, and distribute this software for any
4 .\" purpose with or without fee is hereby granted, provided that the above
5 .\" copyright notice and this permission notice appear in all copies.
6 .\" 
7 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 .\" 
16 .\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14)
17 .\"
18 .\" Standard preamble:
19 .\" ========================================================================
20 .de Sp \" Vertical space (when we can't use .PP)
21 .if t .sp .5v
22 .if n .sp
23 ..
24 .de Vb \" Begin verbatim text
25 .ft CW
26 .nf
27 .ne \\$1
28 ..
29 .de Ve \" End verbatim text
30 .ft R
31 .fi
32 ..
33 .\" Set up some character translations and predefined strings.  \*(-- will
34 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
35 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
36 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
37 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
38 .\" nothing in troff, for use with C<>.
39 .tr \(*W-
40 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
41 .ie n \{\
42 .    ds -- \(*W-
43 .    ds PI pi
44 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
45 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
46 .    ds L" ""
47 .    ds R" ""
48 .    ds C` 
49 .    ds C' 
50 'br\}
51 .el\{\
52 .    ds -- \|\(em\|
53 .    ds PI \(*p
54 .    ds L" ``
55 .    ds R" ''
56 'br\}
57 .\"
58 .\" Escape single quotes in literal strings from groff's Unicode transform.
59 .ie \n(.g .ds Aq \(aq
60 .el       .ds Aq '
61 .\"
62 .\" If the F register is turned on, we'll generate index entries on stderr for
63 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
64 .\" entries marked with X<> in POD.  Of course, you'll have to process the
65 .\" output yourself in some meaningful fashion.
66 .ie \nF \{\
67 .    de IX
68 .    tm Index:\\$1\t\\n%\t"\\$2"
69 ..
70 .    nr % 0
71 .    rr F
72 .\}
73 .el \{\
74 .    de IX
75 ..
76 .\}
77 .\"
78 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
79 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
80 .    \" fudge factors for nroff and troff
81 .if n \{\
82 .    ds #H 0
83 .    ds #V .8m
84 .    ds #F .3m
85 .    ds #[ \f1
86 .    ds #] \fP
87 .\}
88 .if t \{\
89 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
90 .    ds #V .6m
91 .    ds #F 0
92 .    ds #[ \&
93 .    ds #] \&
94 .\}
95 .    \" simple accents for nroff and troff
96 .if n \{\
97 .    ds ' \&
98 .    ds ` \&
99 .    ds ^ \&
100 .    ds , \&
101 .    ds ~ ~
102 .    ds /
103 .\}
104 .if t \{\
105 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
106 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
107 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
108 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
109 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
110 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
111 .\}
112 .    \" troff and (daisy-wheel) nroff accents
113 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
114 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
115 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
116 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
117 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
118 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
119 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
120 .ds ae a\h'-(\w'a'u*4/10)'e
121 .ds Ae A\h'-(\w'A'u*4/10)'E
122 .    \" corrections for vroff
123 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
124 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
125 .    \" for low resolution devices (crt and lpr)
126 .if \n(.H>23 .if \n(.V>19 \
127 \{\
128 .    ds : e
129 .    ds 8 ss
130 .    ds o a
131 .    ds d- d\h'-1'\(ga
132 .    ds D- D\h'-1'\(hy
133 .    ds th \o'bp'
134 .    ds Th \o'LP'
135 .    ds ae ae
136 .    ds Ae AE
137 .\}
138 .rm #[ #] #H #V #F C
139 .\" ========================================================================
140 .\"
141 .IX Title "SUDO_PLUGIN @mansectsu@"
142 .TH SUDO_PLUGIN @mansectsu@ "January  6, 2012" "1.8.4" "MAINTENANCE COMMANDS"
143 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
144 .\" way too many mistakes in technical documents.
145 .if n .ad l
146 .nh
147 .SH "NAME"
148 sudo_plugin \- Sudo Plugin API
149 .SH "DESCRIPTION"
150 .IX Header "DESCRIPTION"
151 Starting with version 1.8, \fBsudo\fR supports a plugin \s-1API\s0
152 for policy and session logging.  By default, the \fIsudoers\fR policy
153 plugin and an associated I/O logging plugin are used.  Via the plugin
154 \&\s-1API\s0, \fBsudo\fR can be configured to use alternate policy and/or I/O
155 logging plugins provided by third parties.  The plugins to be used
156 are specified via the \fI@sysconfdir@/sudo.conf\fR file.
157 .PP
158 The \s-1API\s0 is versioned with a major and minor number.  The minor
159 version number is incremented when additions are made.  The major
160 number is incremented when incompatible changes are made.  A plugin
161 should be check the version passed to it and make sure that the
162 major version matches.
163 .PP
164 The plugin \s-1API\s0 is defined by the \f(CW\*(C`sudo_plugin.h\*(C'\fR header file.
165 .SS "The sudo.conf File"
166 .IX Subsection "The sudo.conf File"
167 The \fI@sysconfdir@/sudo.conf\fR file contains plugin configuration directives.
168 Currently, the only supported keyword is the \f(CW\*(C`Plugin\*(C'\fR directive,
169 which causes a plugin plugin to be loaded.
170 .PP
171 A \f(CW\*(C`Plugin\*(C'\fR line consists of the \f(CW\*(C`Plugin\*(C'\fR keyword, followed by the
172 \&\fIsymbol_name\fR and the \fIpath\fR to the shared object containing the
173 plugin.  The \fIsymbol_name\fR is the name of the \f(CW\*(C`struct policy_plugin\*(C'\fR
174 or \f(CW\*(C`struct io_plugin\*(C'\fR in the plugin shared object.  The \fIpath\fR
175 may be fully qualified or relative.  If not fully qualified it is
176 relative to the \fI@prefix@/libexec\fR directory.  Any additional
177 parameters after the \fIpath\fR are ignored.  Lines that don't begin
178 with \f(CW\*(C`Plugin\*(C'\fR or \f(CW\*(C`Path\*(C'\fR are silently ignored.
179 .PP
180 The same shared object may contain multiple plugins, each with a
181 different symbol name.  The shared object file must be owned by uid
182 0 and only writable by its owner.  Because of ambiguities that arise
183 from composite policies, only a single policy plugin may be specified.
184 This limitation does not apply to I/O plugins.
185 .PP
186 .Vb 10
187 \& #
188 \& # Default @sysconfdir@/sudo.conf file
189 \& #
190 \& # Format:
191 \& #   Plugin plugin_name plugin_path
192 \& #   Path askpass /path/to/askpass
193 \& #
194 \& # The plugin_path is relative to @prefix@/libexec unless
195 \& #   fully qualified.
196 \& # The plugin_name corresponds to a global symbol in the plugin
197 \& #   that contains the plugin interface structure.
198 \& #
199 \& Plugin sudoers_policy sudoers.so
200 \& Plugin sudoers_io sudoers.so
201 .Ve
202 .SS "Policy Plugin \s-1API\s0"
203 .IX Subsection "Policy Plugin API"
204 A policy plugin must declare and populate a \f(CW\*(C`policy_plugin\*(C'\fR struct
205 in the global scope.  This structure contains pointers to the functions
206 that implement the \fBsudo\fR policy checks.  The name of the symbol should
207 be specified in \fI@sysconfdir@/sudo.conf\fR along with a path to the plugin
208 so that \fBsudo\fR can load it.
209 .PP
210 .Vb 10
211 \& struct policy_plugin {
212 \& #define SUDO_POLICY_PLUGIN     1
213 \&     unsigned int type; /* always SUDO_POLICY_PLUGIN */
214 \&     unsigned int version; /* always SUDO_API_VERSION */
215 \&     int (*open)(unsigned int version, sudo_conv_t conversation,
216 \&                 sudo_printf_t plugin_printf, char * const settings[],
217 \&                 char * const user_info[], char * const user_env[]);
218 \&     void (*close)(int exit_status, int error);
219 \&     int (*show_version)(int verbose);
220 \&     int (*check_policy)(int argc, char * const argv[],
221 \&                         char *env_add[], char **command_info[],
222 \&                         char **argv_out[], char **user_env_out[]);
223 \&     int (*list)(int argc, char * const argv[], int verbose,
224 \&                 const char *list_user);
225 \&     int (*validate)(void);
226 \&     void (*invalidate)(int remove);
227 \&     int (*init_session)(struct passwd *pwd);
228 \& };
229 .Ve
230 .PP
231 The policy_plugin struct has the following fields:
232 .IP "type" 4
233 .IX Item "type"
234 The \f(CW\*(C`type\*(C'\fR field should always be set to \s-1SUDO_POLICY_PLUGIN\s0.
235 .IP "version" 4
236 .IX Item "version"
237 The \f(CW\*(C`version\*(C'\fR field should be set to \s-1SUDO_API_VERSION\s0.
238 .Sp
239 This allows \fBsudo\fR to determine the \s-1API\s0 version the plugin was
240 built against.
241 .IP "open" 4
242 .IX Item "open"
243 .Vb 3
244 \& int (*open)(unsigned int version, sudo_conv_t conversation,
245 \&             sudo_printf_t plugin_printf, char * const settings[],
246 \&             char * const user_info[], char * const user_env[]);
247 .Ve
248 .Sp
249 Returns 1 on success, 0 on failure, \-1 if a general error occurred,
250 or \-2 if there was a usage error.  In the latter case, \fBsudo\fR will
251 print a usage message before it exits.  If an error occurs, the
252 plugin may optionally call the conversation or plugin_printf function
253 with \f(CW\*(C`SUDO_CONF_ERROR_MSG\*(C'\fR to present additional error information
254 to the user.
255 .Sp
256 The function arguments are as follows:
257 .RS 4
258 .IP "version" 4
259 .IX Item "version"
260 The version passed in by \fBsudo\fR allows the plugin to determine the
261 major and minor version number of the plugin \s-1API\s0 supported by
262 \&\fBsudo\fR.
263 .IP "conversation" 4
264 .IX Item "conversation"
265 A pointer to the conversation function that can be used by the
266 plugin to interact with the user (see below).
267 Returns 0 on success and \-1 on failure.
268 .IP "plugin_printf" 4
269 .IX Item "plugin_printf"
270 A pointer to a printf-style function that may be used to display
271 informational or error messages (see below).
272 Returns the number of characters printed on success and \-1 on failure.
273 .IP "settings" 4
274 .IX Item "settings"
275 A vector of user-supplied \fBsudo\fR settings in the form of \*(L"name=value\*(R"
276 strings.  The vector is terminated by a \f(CW\*(C`NULL\*(C'\fR pointer.  These
277 settings correspond to flags the user specified when running \fBsudo\fR.
278 As such, they will only be present when the corresponding flag has
279 been specified on the command line.
280 .Sp
281 When parsing \fIsettings\fR, the plugin should split on the \fBfirst\fR
282 equal sign ('=') since the \fIname\fR field will never include one
283 itself but the \fIvalue\fR might.
284 .RS 4
285 .IP "debug_flags=string" 4
286 .IX Item "debug_flags=string"
287 A comma-separated list of debug flags that correspond to \fBsudo\fR's
288 \&\f(CW\*(C`Debug\*(C'\fR entry in \fI@sysconfdir@/sudo.conf\fR, if there is one.  The
289 flags are passed to the plugin as they appear in \fI@sysconfdir@/sudo.conf\fR.
290 The syntax used by \fBsudo\fR and the \fIsudoers\fR plugin is
291 \&\fIsubsystem\fR@\fIpriority\fR but the plugin is free to use a different
292 format so long as it does not include a command \f(CW\*(C`,\*(C'\fR.
293 .Sp
294 For reference, the priorities supported by the \fBsudo\fR front end and
295 \&\fIsudoers\fR are: \fIcrit\fR, \fIerr\fR, \fIwarn\fR, \fInotice\fR, \fIdiag\fR,
296 \&\fIinfo\fR, \fItrace\fR and \fIdebug\fR.
297 .Sp
298 The following subsystems are defined: \fImain\fR, \fImemory\fR, \fIargs\fR,
299 \&\fIexec\fR, \fIpty\fR, \fIutmp\fR, \fIconv\fR, \fIpcomm\fR, \fIutil\fR, \fIlist\fR,
300 \&\fInetif\fR, \fIaudit\fR, \fIedit\fR, \fIselinux\fR, \fIldap\fR, \fImatch\fR, \fIparser\fR,
301 \&\fIalias\fR, \fIdefaults\fR, \fIauth\fR, \fIenv\fR, \fIlogging\fR, \fInss\fR, \fIrbtree\fR,
302 \&\fIperms\fR, \fIplugin\fR.  The subsystem \fIall\fR includes every subsystem.
303 .Sp
304 There is not currently a way to specify a set of debug flags specific
305 to the plugin\*(--the flags are shared by \fBsudo\fR and the plugin.
306 .IP "debug_level=number" 4
307 .IX Item "debug_level=number"
308 This setting has been deprecated in favor of \fIdebug_flags\fR.
309 .IP "runas_user=string" 4
310 .IX Item "runas_user=string"
311 The user name or uid to to run the command as, if specified via the
312 \&\f(CW\*(C`\-u\*(C'\fR flag.
313 .IP "runas_group=string" 4
314 .IX Item "runas_group=string"
315 The group name or gid to to run the command as, if specified via
316 the \f(CW\*(C`\-g\*(C'\fR flag.
317 .IP "prompt=string" 4
318 .IX Item "prompt=string"
319 The prompt to use when requesting a password, if specified via
320 the \f(CW\*(C`\-p\*(C'\fR flag.
321 .IP "set_home=bool" 4
322 .IX Item "set_home=bool"
323 Set to true if the user specified the \f(CW\*(C`\-H\*(C'\fR flag.  If true, set the
324 \&\f(CW\*(C`HOME\*(C'\fR environment variable to the target user's home directory.
325 .IP "preserve_environment=bool" 4
326 .IX Item "preserve_environment=bool"
327 Set to true if the user specified the \f(CW\*(C`\-E\*(C'\fR flag, indicating that
328 the user wishes to preserve the environment.
329 .IP "run_shell=bool" 4
330 .IX Item "run_shell=bool"
331 Set to true if the user specified the \f(CW\*(C`\-s\*(C'\fR flag, indicating that
332 the user wishes to run a shell.
333 .IP "login_shell=bool" 4
334 .IX Item "login_shell=bool"
335 Set to true if the user specified the \f(CW\*(C`\-i\*(C'\fR flag, indicating that
336 the user wishes to run a login shell.
337 .IP "implied_shell=bool" 4
338 .IX Item "implied_shell=bool"
339 If the user does not specify a program on the command line, \fBsudo\fR
340 will pass the plugin the path to the user's shell and set
341 \&\fIimplied_shell\fR to true.  This allows \fBsudo\fR with no arguments
342 to be used similarly to \fIsu\fR\|(1).  If the plugin does not to support
343 this usage, it may return a value of \-2 from the \f(CW\*(C`check_policy\*(C'\fR
344 function, which will cause \fBsudo\fR to print a usage message and
345 exit.
346 .IP "preserve_groups=bool" 4
347 .IX Item "preserve_groups=bool"
348 Set to true if the user specified the \f(CW\*(C`\-P\*(C'\fR flag, indicating that
349 the user wishes to preserve the group vector instead of setting it
350 based on the runas user.
351 .IP "ignore_ticket=bool" 4
352 .IX Item "ignore_ticket=bool"
353 Set to true if the user specified the \f(CW\*(C`\-k\*(C'\fR flag along with a
354 command, indicating that the user wishes to ignore any cached
355 authentication credentials.
356 .IP "noninteractive=bool" 4
357 .IX Item "noninteractive=bool"
358 Set to true if the user specified the \f(CW\*(C`\-n\*(C'\fR flag, indicating that
359 \&\fBsudo\fR should operate in non-interactive mode.  The plugin may
360 reject a command run in non-interactive mode if user interaction
361 is required.
362 .IP "login_class=string" 4
363 .IX Item "login_class=string"
364 \&\s-1BSD\s0 login class to use when setting resource limits and nice value,
365 if specified by the \f(CW\*(C`\-c\*(C'\fR flag.
366 .IP "selinux_role=string" 4
367 .IX Item "selinux_role=string"
368 SELinux role to use when executing the command, if specified by
369 the \f(CW\*(C`\-r\*(C'\fR flag.
370 .IP "selinux_type=string" 4
371 .IX Item "selinux_type=string"
372 SELinux type to use when executing the command, if specified by
373 the \f(CW\*(C`\-t\*(C'\fR flag.
374 .IP "bsdauth_type=string" 4
375 .IX Item "bsdauth_type=string"
376 Authentication type, if specified by the \f(CW\*(C`\-a\*(C'\fR flag, to use on
377 systems where \s-1BSD\s0 authentication is supported.
378 .IP "network_addrs=list" 4
379 .IX Item "network_addrs=list"
380 A space-separated list of \s-1IP\s0 network addresses and netmasks in the
381 form \*(L"addr/netmask\*(R", e.g. \*(L"192.168.1.2/255.255.255.0\*(R".  The address
382 and netmask pairs may be either IPv4 or IPv6, depending on what the
383 operating system supports.  If the address contains a colon (':'),
384 it is an IPv6 address, else it is IPv4.
385 .IP "progname=string" 4
386 .IX Item "progname=string"
387 The command name that sudo was run as, typically \*(L"sudo\*(R" or \*(L"sudoedit\*(R".
388 .IP "sudoedit=bool" 4
389 .IX Item "sudoedit=bool"
390 Set to true when the \f(CW\*(C`\-e\*(C'\fR flag is is specified or if invoked as
391 \&\fBsudoedit\fR.  The plugin shall substitute an editor into \fIargv\fR
392 in the \fIcheck_policy\fR function or return \f(CW\*(C`\-2\*(C'\fR with a usage error
393 if the plugin does not support \fIsudoedit\fR.  For more information,
394 see the \fIcheck_policy\fR section.
395 .IP "closefrom=number" 4
396 .IX Item "closefrom=number"
397 If specified, the user has requested via the \f(CW\*(C`\-C\*(C'\fR flag that \fBsudo\fR
398 close all files descriptors with a value of \fInumber\fR or higher.
399 The plugin may optionally pass this, or another value, back in the
400 \&\fIcommand_info\fR list.
401 .RE
402 .RS 4
403 .Sp
404 Additional settings may be added in the future so the plugin should
405 silently ignore settings that it does not recognize.
406 .RE
407 .IP "user_info" 4
408 .IX Item "user_info"
409 A vector of information about the user running the command in the form of
410 \&\*(L"name=value\*(R" strings.  The vector is terminated by a \f(CW\*(C`NULL\*(C'\fR pointer.
411 .Sp
412 When parsing \fIuser_info\fR, the plugin should split on the \fBfirst\fR
413 equal sign ('=') since the \fIname\fR field will never include one
414 itself but the \fIvalue\fR might.
415 .RS 4
416 .IP "user=string" 4
417 .IX Item "user=string"
418 The name of the user invoking \fBsudo\fR.
419 .IP "uid=uid_t" 4
420 .IX Item "uid=uid_t"
421 The real user \s-1ID\s0 of the user invoking \fBsudo\fR.
422 .IP "gid=gid_t" 4
423 .IX Item "gid=gid_t"
424 The real group \s-1ID\s0 of the user invoking \fBsudo\fR.
425 .IP "groups=list" 4
426 .IX Item "groups=list"
427 The user's supplementary group list formatted as a string of
428 comma-separated group IDs.
429 .IP "cwd=string" 4
430 .IX Item "cwd=string"
431 The user's current working directory.
432 .IP "tty=string" 4
433 .IX Item "tty=string"
434 The path to the user's terminal device.  If the user has no terminal
435 device associated with the session, the value will be empty, as in
436 \&\f(CW\*(C`tty=\*(C'\fR.
437 .IP "host=string" 4
438 .IX Item "host=string"
439 The local machine's hostname as returned by the \f(CW\*(C`gethostname()\*(C'\fR
440 system call.
441 .IP "lines=int" 4
442 .IX Item "lines=int"
443 The number of lines the user's terminal supports.  If there is
444 no terminal device available, a default value of 24 is used.
445 .IP "cols=int" 4
446 .IX Item "cols=int"
447 The number of columns the user's terminal supports.  If there is
448 no terminal device available, a default value of 80 is used.
449 .RE
450 .RS 4
451 .RE
452 .IP "user_env" 4
453 .IX Item "user_env"
454 The user's environment in the form of a \f(CW\*(C`NULL\*(C'\fR\-terminated vector of
455 \&\*(L"name=value\*(R" strings.
456 .Sp
457 When parsing \fIuser_env\fR, the plugin should split on the \fBfirst\fR
458 equal sign ('=') since the \fIname\fR field will never include one
459 itself but the \fIvalue\fR might.
460 .RE
461 .RS 4
462 .RE
463 .IP "close" 4
464 .IX Item "close"
465 .Vb 1
466 \& void (*close)(int exit_status, int error);
467 .Ve
468 .Sp
469 The \f(CW\*(C`close\*(C'\fR function is called when the command being run by \fBsudo\fR
470 finishes.
471 .Sp
472 The function arguments are as follows:
473 .RS 4
474 .IP "exit_status" 4
475 .IX Item "exit_status"
476 The command's exit status, as returned by the \fIwait\fR\|(2) system call.
477 The value of \f(CW\*(C`exit_status\*(C'\fR is undefined if \f(CW\*(C`error\*(C'\fR is non-zero.
478 .IP "error" 4
479 .IX Item "error"
480 If the command could not be executed, this is set to the value of
481 \&\f(CW\*(C`errno\*(C'\fR set by the \fIexecve\fR\|(2) system call.  The plugin is responsible
482 for displaying error information via the conversation or plugin_printf
483 function.  If the command was successfully executed, the value of
484 \&\f(CW\*(C`error\*(C'\fR is 0.
485 .RE
486 .RS 4
487 .RE
488 .IP "show_version" 4
489 .IX Item "show_version"
490 .Vb 1
491 \& int (*show_version)(int verbose);
492 .Ve
493 .Sp
494 The \f(CW\*(C`show_version\*(C'\fR function is called by \fBsudo\fR when the user specifies
495 the \f(CW\*(C`\-V\*(C'\fR option.  The plugin may display its version information
496 to the user via the conversation or plugin_printf function using
497 \&\f(CW\*(C`SUDO_CONV_INFO_MSG\*(C'\fR.  If the user requests detailed version
498 information, the verbose flag will be set.
499 .IP "check_policy" 4
500 .IX Item "check_policy"
501 .Vb 3
502 \& int (*check_policy)(int argc, char * const argv[]
503 \&                     char *env_add[], char **command_info[],
504 \&                     char **argv_out[], char **user_env_out[]);
505 .Ve
506 .Sp
507 The \fIcheck_policy\fR function is called by \fBsudo\fR to determine
508 whether the user is allowed to run the specified commands.
509 .Sp
510 If the \fIsudoedit\fR option was enabled in the \fIsettings\fR array
511 passed to the \fIopen\fR function, the user has requested \fIsudoedit\fR
512 mode.  \fIsudoedit\fR is a mechanism for editing one or more files
513 where an editor is run with the user's credentials instead of with
514 elevated privileges.  \fBsudo\fR achieves this by creating user-writable
515 temporary copies of the files to be edited and then overwriting the
516 originals with the temporary copies after editing is complete.  If
517 the plugin supports \fBsudoedit\fR, it should choose the editor to be
518 used, potentially from a variable in the user's environment, such
519 as \f(CW\*(C`EDITOR\*(C'\fR, and include it in \fIargv_out\fR (note that environment
520 variables may include command line flags).  The files to be edited
521 should be copied from \fIargv\fR into \fIargv_out\fR, separated from the
522 editor and its arguments by a \f(CW"\-\-"\fR element.  The \f(CW"\-\-"\fR will
523 be removed by \fBsudo\fR before the editor is executed.  The plugin
524 should also set \fIsudoedit=true\fR in the \fIcommand_info\fR list.
525 .Sp
526 The \fIcheck_policy\fR function returns 1 if the command is allowed,
527 0 if not allowed, \-1 for a general error, or \-2 for a usage error
528 or if \fBsudoedit\fR was specified but is unsupported by the plugin.
529 In the latter case, \fBsudo\fR will print a usage message before it
530 exits.  If an error occurs, the plugin may optionally call the
531 conversation or plugin_printf function with \f(CW\*(C`SUDO_CONF_ERROR_MSG\*(C'\fR
532 to present additional error information to the user.
533 .Sp
534 The function arguments are as follows:
535 .RS 4
536 .IP "argc" 4
537 .IX Item "argc"
538 The number of elements in \fIargv\fR, not counting the final \f(CW\*(C`NULL\*(C'\fR
539 pointer.
540 .IP "argv" 4
541 .IX Item "argv"
542 The argument vector describing the command the user wishes to run,
543 in the same form as what would be passed to the \fIexecve()\fR system
544 call.  The vector is terminated by a \f(CW\*(C`NULL\*(C'\fR pointer.
545 .IP "env_add" 4
546 .IX Item "env_add"
547 Additional environment variables specified by the user on the command
548 line in the form of a \f(CW\*(C`NULL\*(C'\fR\-terminated vector of \*(L"name=value\*(R"
549 strings.  The plugin may reject the command if one or more variables
550 are not allowed to be set, or it may silently ignore such variables.
551 .Sp
552 When parsing \fIenv_add\fR, the plugin should split on the \fBfirst\fR
553 equal sign ('=') since the \fIname\fR field will never include one
554 itself but the \fIvalue\fR might.
555 .IP "command_info" 4
556 .IX Item "command_info"
557 Information about the command being run in the form of \*(L"name=value\*(R"
558 strings.  These values are used by \fBsudo\fR to set the execution
559 environment when running a command.  The plugin is responsible for
560 creating and populating the vector, which must be terminated with
561 a \f(CW\*(C`NULL\*(C'\fR pointer.  The following values are recognized by \fBsudo\fR:
562 .RS 4
563 .IP "command=string" 4
564 .IX Item "command=string"
565 Fully qualified path to the command to be executed.
566 .IP "runas_uid=uid" 4
567 .IX Item "runas_uid=uid"
568 User \s-1ID\s0 to run the command as.
569 .IP "runas_euid=uid" 4
570 .IX Item "runas_euid=uid"
571 Effective user \s-1ID\s0 to run the command as.
572 If not specified, the value of \fIrunas_uid\fR is used.
573 .IP "runas_gid=gid" 4
574 .IX Item "runas_gid=gid"
575 Group \s-1ID\s0 to run the command as.
576 .IP "runas_egid=gid" 4
577 .IX Item "runas_egid=gid"
578 Effective group \s-1ID\s0 to run the command as.
579 If not specified, the value of \fIrunas_gid\fR is used.
580 .IP "runas_groups=list" 4
581 .IX Item "runas_groups=list"
582 The supplementary group vector to use for the command in the form
583 of a comma-separated list of group IDs.  If \fIpreserve_groups\fR
584 is set, this option is ignored.
585 .IP "login_class=string" 4
586 .IX Item "login_class=string"
587 \&\s-1BSD\s0 login class to use when setting resource limits and nice value
588 (optional).  This option is only set on systems that support login
589 classes.
590 .IP "preserve_groups=bool" 4
591 .IX Item "preserve_groups=bool"
592 If set, \fBsudo\fR will preserve the user's group vector instead of
593 initializing the group vector based on \f(CW\*(C`runas_user\*(C'\fR.
594 .IP "cwd=string" 4
595 .IX Item "cwd=string"
596 The current working directory to change to when executing the command.
597 .IP "noexec=bool" 4
598 .IX Item "noexec=bool"
599 If set, prevent the command from executing other programs.
600 .IP "chroot=string" 4
601 .IX Item "chroot=string"
602 The root directory to use when running the command.
603 .IP "nice=int" 4
604 .IX Item "nice=int"
605 Nice value (priority) to use when executing the command.  The nice
606 value, if specified, overrides the priority associated with the
607 \&\fIlogin_class\fR on \s-1BSD\s0 systems.
608 .IP "umask=octal" 4
609 .IX Item "umask=octal"
610 The file creation mask to use when executing the command.
611 .IP "selinux_role=string" 4
612 .IX Item "selinux_role=string"
613 SELinux role to use when executing the command.
614 .IP "selinux_type=string" 4
615 .IX Item "selinux_type=string"
616 SELinux type to use when executing the command.
617 .IP "timeout=int" 4
618 .IX Item "timeout=int"
619 Command timeout.  If non-zero then when the timeout expires the
620 command will be killed.
621 .IP "sudoedit=bool" 4
622 .IX Item "sudoedit=bool"
623 Set to true when in \fIsudoedit\fR mode.  The plugin may enable
624 \&\fIsudoedit\fR mode even if \fBsudo\fR was not invoked as \fBsudoedit\fR.
625 This allows the plugin to perform command substitution and transparently
626 enable \fIsudoedit\fR when the user attempts to run an editor.
627 .IP "closefrom=number" 4
628 .IX Item "closefrom=number"
629 If specified, \fBsudo\fR will close all files descriptors with a value
630 of \fInumber\fR or higher.
631 .IP "iolog_compress=bool" 4
632 .IX Item "iolog_compress=bool"
633 Set to true if the I/O logging plugins, if any, should compress the
634 log data.  This is a hint to the I/O logging plugin which may choose
635 to ignore it.
636 .IP "iolog_path=string" 4
637 .IX Item "iolog_path=string"
638 Fully qualified path to the file or directory in which I/O log is
639 to be stored.  This is a hint to the I/O logging plugin which may
640 choose to ignore it.  If no I/O logging plugin is loaded, this
641 setting has no effect.
642 .IP "iolog_stdin=bool" 4
643 .IX Item "iolog_stdin=bool"
644 Set to true if the I/O logging plugins, if any, should log the
645 standard input if it is not connected to a terminal device.  This
646 is a hint to the I/O logging plugin which may choose to ignore it.
647 .IP "iolog_stdout=bool" 4
648 .IX Item "iolog_stdout=bool"
649 Set to true if the I/O logging plugins, if any, should log the
650 standard output if it is not connected to a terminal device.  This
651 is a hint to the I/O logging plugin which may choose to ignore it.
652 .IP "iolog_stderr=bool" 4
653 .IX Item "iolog_stderr=bool"
654 Set to true if the I/O logging plugins, if any, should log the
655 standard error if it is not connected to a terminal device.  This
656 is a hint to the I/O logging plugin which may choose to ignore it.
657 .IP "iolog_ttyin=bool" 4
658 .IX Item "iolog_ttyin=bool"
659 Set to true if the I/O logging plugins, if any, should log all
660 terminal input.  This only includes input typed by the user and not
661 from a pipe or redirected from a file.  This is a hint to the I/O
662 logging plugin which may choose to ignore it.
663 .IP "iolog_ttyout=bool" 4
664 .IX Item "iolog_ttyout=bool"
665 Set to true if the I/O logging plugins, if any, should log all
666 terminal output.  This only includes output to the screen, not
667 output to a pipe or file.  This is a hint to the I/O logging plugin
668 which may choose to ignore it.
669 .IP "use_pty=bool" 4
670 .IX Item "use_pty=bool"
671 Allocate a pseudo-tty to run the command in, regardless of whether
672 or not I/O logging is in use.  By default, \fBsudo\fR will only run
673 the command in a pty when an I/O log plugin is loaded.
674 .IP "set_utmp=bool" 4
675 .IX Item "set_utmp=bool"
676 Create a utmp (or utmpx) entry when a pseudo-tty is allocated.  By
677 default, the new entry will be a copy of the user's existing utmp
678 entry (if any), with the tty, time, type and pid fields updated.
679 .IP "utmp_user=string" 4
680 .IX Item "utmp_user=string"
681 User name to use when constructing a new utmp (or utmpx) entry when
682 \&\fIset_utmp\fR is enabled.  This option can be used to set the user
683 field in the utmp entry to the user the command runs as rather than
684 the invoking user.  If not set, \fBsudo\fR will base the new entry on
685 the invoking user's existing entry.
686 .RE
687 .RS 4
688 .Sp
689 Unsupported values will be ignored.
690 .RE
691 .IP "argv_out" 4
692 .IX Item "argv_out"
693 The \f(CW\*(C`NULL\*(C'\fR\-terminated argument vector to pass to the \fIexecve()\fR
694 system call when executing the command.  The plugin is responsible
695 for allocating and populating the vector.
696 .IP "user_env_out" 4
697 .IX Item "user_env_out"
698 The \f(CW\*(C`NULL\*(C'\fR\-terminated environment vector to use when executing the
699 command.  The plugin is responsible for allocating and populating
700 the vector.
701 .RE
702 .RS 4
703 .RE
704 .IP "list" 4
705 .IX Item "list"
706 .Vb 2
707 \& int (*list)(int verbose, const char *list_user,
708 \&             int argc, char * const argv[]);
709 .Ve
710 .Sp
711 List available privileges for the invoking user.  Returns 1 on
712 success, 0 on failure and \-1 on error.  On error, the plugin may
713 optionally call the conversation or plugin_printf function with
714 \&\f(CW\*(C`SUDO_CONF_ERROR_MSG\*(C'\fR to present additional error information to
715 the user.
716 .Sp
717 Privileges should be output via the conversation or plugin_printf
718 function using \f(CW\*(C`SUDO_CONV_INFO_MSG\*(C'\fR.
719 .RS 4
720 .IP "verbose" 4
721 .IX Item "verbose"
722 Flag indicating whether to list in verbose mode or not.
723 .IP "list_user" 4
724 .IX Item "list_user"
725 The name of a different user to list privileges for if the policy
726 allows it.  If \f(CW\*(C`NULL\*(C'\fR, the plugin should list the privileges of
727 the invoking user.
728 .IP "argc" 4
729 .IX Item "argc"
730 The number of elements in \fIargv\fR, not counting the final \f(CW\*(C`NULL\*(C'\fR
731 pointer.
732 .IP "argv" 4
733 .IX Item "argv"
734 If non\-\f(CW\*(C`NULL\*(C'\fR, an argument vector describing a command the user
735 wishes to check against the policy in the same form as what would
736 be passed to the \fIexecve()\fR system call.  If the command is permitted
737 by the policy, the fully-qualified path to the command should be
738 displayed along with any command line arguments.
739 .RE
740 .RS 4
741 .RE
742 .IP "validate" 4
743 .IX Item "validate"
744 .Vb 1
745 \& int (*validate)(void);
746 .Ve
747 .Sp
748 The \f(CW\*(C`validate\*(C'\fR function is called when \fBsudo\fR is run with the
749 \&\f(CW\*(C`\-v\*(C'\fR flag.  For policy plugins such as \fIsudoers\fR that cache
750 authentication credentials, this function will validate and cache
751 the credentials.
752 .Sp
753 The \f(CW\*(C`validate\*(C'\fR function should be \f(CW\*(C`NULL\*(C'\fR if the plugin does not
754 support credential caching.
755 .Sp
756 Returns 1 on success, 0 on failure and \-1 on error.
757 On error, the plugin may optionally call the conversation or plugin_printf
758 function with \f(CW\*(C`SUDO_CONF_ERROR_MSG\*(C'\fR to present additional
759 error information to the user.
760 .IP "invalidate" 4
761 .IX Item "invalidate"
762 .Vb 1
763 \& void (*invalidate)(int remove);
764 .Ve
765 .Sp
766 The \f(CW\*(C`invalidate\*(C'\fR function is called when \fBsudo\fR is called with
767 the \f(CW\*(C`\-k\*(C'\fR or \f(CW\*(C`\-K\*(C'\fR flag.  For policy plugins such as \fIsudoers\fR that
768 cache authentication credentials, this function will invalidate the
769 credentials.  If the \fIremove\fR flag is set, the plugin may remove
770 the credentials instead of simply invalidating them.
771 .Sp
772 The \f(CW\*(C`invalidate\*(C'\fR function should be \f(CW\*(C`NULL\*(C'\fR if the plugin does not
773 support credential caching.
774 .IP "init_session" 4
775 .IX Item "init_session"
776 .Vb 1
777 \& int (*init_session)(struct passwd *pwd);
778 .Ve
779 .Sp
780 The \f(CW\*(C`init_session\*(C'\fR function is called when \fBsudo\fR sets up the
781 execution environment for the command, immediately before the
782 contents of the \fIcommand_info\fR list are applied (before the uid
783 changes).  This can be used to do session setup that is not supported
784 by \fIcommand_info\fR, such as opening the \s-1PAM\s0 session.
785 .Sp
786 The \fIpwd\fR argument points to a passwd struct for the user the
787 command will be run as if the uid the command will run as was found
788 in the password database, otherwise it will be \s-1NULL\s0.
789 .Sp
790 Returns 1 on success, 0 on failure and \-1 on error.
791 On error, the plugin may optionally call the conversation or plugin_printf
792 function with \f(CW\*(C`SUDO_CONF_ERROR_MSG\*(C'\fR to present additional
793 error information to the user.
794 .PP
795 \fIVersion macros\fR
796 .IX Subsection "Version macros"
797 .PP
798 .Vb 8
799 \& #define SUDO_API_VERSION_GET_MAJOR(v) ((v) >> 16)
800 \& #define SUDO_API_VERSION_GET_MINOR(v) ((v) & 0xffff)
801 \& #define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \e
802 \&     *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \e
803 \& } while(0)
804 \& #define SUDO_VERSION_SET_MINOR(vp, n) do { \e
805 \&     *(vp) = (*(vp) & 0xffff0000) | (n); \e
806 \& } while(0)
807 \&
808 \& #define SUDO_API_VERSION_MAJOR 1
809 \& #define SUDO_API_VERSION_MINOR 0
810 \& #define SUDO_API_VERSION ((SUDO_API_VERSION_MAJOR << 16) | \e
811 \&                           SUDO_API_VERSION_MINOR)
812 .Ve
813 .SS "I/O Plugin \s-1API\s0"
814 .IX Subsection "I/O Plugin API"
815 .Vb 10
816 \& struct io_plugin {
817 \& #define SUDO_IO_PLUGIN         2
818 \&     unsigned int type; /* always SUDO_IO_PLUGIN */
819 \&     unsigned int version; /* always SUDO_API_VERSION */
820 \&     int (*open)(unsigned int version, sudo_conv_t conversation
821 \&                 sudo_printf_t plugin_printf, char * const settings[],
822 \&                 char * const user_info[], int argc, char * const argv[],
823 \&                 char * const user_env[]);
824 \&     void (*close)(int exit_status, int error); /* wait status or error */
825 \&     int (*show_version)(int verbose);
826 \&     int (*log_ttyin)(const char *buf, unsigned int len);
827 \&     int (*log_ttyout)(const char *buf, unsigned int len);
828 \&     int (*log_stdin)(const char *buf, unsigned int len);
829 \&     int (*log_stdout)(const char *buf, unsigned int len);
830 \&     int (*log_stderr)(const char *buf, unsigned int len);
831 \& };
832 .Ve
833 .PP
834 When an I/O plugin is loaded, \fBsudo\fR runs the command in a pseudo-tty.
835 This makes it possible to log the input and output from the user's
836 session.  If any of the standard input, standard output or standard
837 error do not correspond to a tty, \fBsudo\fR will open a pipe to capture
838 the I/O for logging before passing it on.
839 .PP
840 The log_ttyin function receives the raw user input from the terminal
841 device (note that this will include input even when echo is disabled,
842 such as when a password is read). The log_ttyout function receives
843 output from the pseudo-tty that is suitable for replaying the user's
844 session at a later time.  The log_stdin, log_stdout and log_stderr
845 functions are only called if the standard input, standard output
846 or standard error respectively correspond to something other than
847 a tty.
848 .PP
849 Any of the logging functions may be set to the \s-1NULL\s0
850 pointer if no logging is to be performed.  If the open function
851 returns \f(CW0\fR, no I/O will be sent to the plugin.
852 .PP
853 The io_plugin struct has the following fields:
854 .IP "type" 4
855 .IX Item "type"
856 The \f(CW\*(C`type\*(C'\fR field should always be set to \s-1SUDO_IO_PLUGIN\s0
857 .IP "version" 4
858 .IX Item "version"
859 The \f(CW\*(C`version\*(C'\fR field should be set to \s-1SUDO_API_VERSION\s0.
860 .Sp
861 This allows \fBsudo\fR to determine the \s-1API\s0 version the plugin was
862 built against.
863 .IP "open" 4
864 .IX Item "open"
865 .Vb 4
866 \& int (*open)(unsigned int version, sudo_conv_t conversation
867 \&             sudo_printf_t plugin_printf, char * const settings[],
868 \&             char * const user_info[], int argc, char * const argv[],
869 \&             char * const user_env[]);
870 .Ve
871 .Sp
872 The \fIopen\fR function is run before the \fIlog_input\fR, \fIlog_output\fR
873 or \fIshow_version\fR functions are called.  It is only called if the
874 version is being requested or the \fIcheck_policy\fR function has
875 returned successfully.  It returns 1 on success, 0 on failure, \-1
876 if a general error occurred, or \-2 if there was a usage error.  In
877 the latter case, \fBsudo\fR will print a usage message before it exits.
878 If an error occurs, the plugin may optionally call the conversation
879 or plugin_printf function with \f(CW\*(C`SUDO_CONF_ERROR_MSG\*(C'\fR to present
880 additional error information to the user.
881 .Sp
882 The function arguments are as follows:
883 .RS 4
884 .IP "version" 4
885 .IX Item "version"
886 The version passed in by \fBsudo\fR allows the plugin to determine the
887 major and minor version number of the plugin \s-1API\s0 supported by
888 \&\fBsudo\fR.
889 .IP "conversation" 4
890 .IX Item "conversation"
891 A pointer to the conversation function that may be used by the
892 \&\fIshow_version\fR function to display version information (see
893 show_version below).  The conversation function may also be used
894 to display additional error message to the user.
895 The conversation function returns 0 on success and \-1 on failure.
896 .IP "plugin_printf" 4
897 .IX Item "plugin_printf"
898 A pointer to a printf-style function that may be used by the
899 \&\fIshow_version\fR function to display version information (see
900 show_version below).  The plugin_printf function may also be used
901 to display additional error message to the user.
902 The plugin_printf function returns number of characters printed on
903 success and \-1 on failure.
904 .IP "settings" 4
905 .IX Item "settings"
906 A vector of user-supplied \fBsudo\fR settings in the form of \*(L"name=value\*(R"
907 strings.  The vector is terminated by a \f(CW\*(C`NULL\*(C'\fR pointer.  These
908 settings correspond to flags the user specified when running \fBsudo\fR.
909 As such, they will only be present when the corresponding flag has
910 been specified on the command line.
911 .Sp
912 When parsing \fIsettings\fR, the plugin should split on the \fBfirst\fR
913 equal sign ('=') since the \fIname\fR field will never include one
914 itself but the \fIvalue\fR might.
915 .Sp
916 See the \*(L"Policy Plugin \s-1API\s0\*(R" section for a list of all possible settings.
917 .IP "user_info" 4
918 .IX Item "user_info"
919 A vector of information about the user running the command in the form of
920 \&\*(L"name=value\*(R" strings.  The vector is terminated by a \f(CW\*(C`NULL\*(C'\fR pointer.
921 .Sp
922 When parsing \fIuser_info\fR, the plugin should split on the \fBfirst\fR
923 equal sign ('=') since the \fIname\fR field will never include one
924 itself but the \fIvalue\fR might.
925 .Sp
926 See the \*(L"Policy Plugin \s-1API\s0\*(R" section for a list of all possible strings.
927 .IP "argc" 4
928 .IX Item "argc"
929 The number of elements in \fIargv\fR, not counting the final \f(CW\*(C`NULL\*(C'\fR
930 pointer.
931 .IP "argv" 4
932 .IX Item "argv"
933 If non\-\f(CW\*(C`NULL\*(C'\fR, an argument vector describing a command the user
934 wishes to run in the same form as what would be passed to the
935 \&\fIexecve()\fR system call.
936 .IP "user_env" 4
937 .IX Item "user_env"
938 The user's environment in the form of a \f(CW\*(C`NULL\*(C'\fR\-terminated vector of
939 \&\*(L"name=value\*(R" strings.
940 .Sp
941 When parsing \fIuser_env\fR, the plugin should split on the \fBfirst\fR
942 equal sign ('=') since the \fIname\fR field will never include one
943 itself but the \fIvalue\fR might.
944 .RE
945 .RS 4
946 .RE
947 .IP "close" 4
948 .IX Item "close"
949 .Vb 1
950 \& void (*close)(int exit_status, int error);
951 .Ve
952 .Sp
953 The \f(CW\*(C`close\*(C'\fR function is called when the command being run by \fBsudo\fR
954 finishes.
955 .Sp
956 The function arguments are as follows:
957 .RS 4
958 .IP "exit_status" 4
959 .IX Item "exit_status"
960 The command's exit status, as returned by the \fIwait\fR\|(2) system call.
961 The value of \f(CW\*(C`exit_status\*(C'\fR is undefined if \f(CW\*(C`error\*(C'\fR is non-zero.
962 .IP "error" 4
963 .IX Item "error"
964 If the command could not be executed, this is set to the value of
965 \&\f(CW\*(C`errno\*(C'\fR set by the \fIexecve\fR\|(2) system call.  If the command was
966 successfully executed, the value of \f(CW\*(C`error\*(C'\fR is 0.
967 .RE
968 .RS 4
969 .RE
970 .IP "show_version" 4
971 .IX Item "show_version"
972 .Vb 1
973 \& int (*show_version)(int verbose);
974 .Ve
975 .Sp
976 The \f(CW\*(C`show_version\*(C'\fR function is called by \fBsudo\fR when the user specifies
977 the \f(CW\*(C`\-V\*(C'\fR option.  The plugin may display its version information
978 to the user via the conversation or plugin_printf function using
979 \&\f(CW\*(C`SUDO_CONV_INFO_MSG\*(C'\fR.  If the user requests detailed version
980 information, the verbose flag will be set.
981 .IP "log_ttyin" 4
982 .IX Item "log_ttyin"
983 .Vb 1
984 \& int (*log_ttyin)(const char *buf, unsigned int len);
985 .Ve
986 .Sp
987 The \fIlog_ttyin\fR function is called whenever data can be read from
988 the user but before it is passed to the running command.  This
989 allows the plugin to reject data if it chooses to (for instance
990 if the input contains banned content).  Returns \f(CW1\fR if the data
991 should be passed to the command, \f(CW0\fR if the data is rejected
992 (which will terminate the command) or \f(CW\*(C`\-1\*(C'\fR if an error occurred.
993 .Sp
994 The function arguments are as follows:
995 .RS 4
996 .IP "buf" 4
997 .IX Item "buf"
998 The buffer containing user input.
999 .IP "len" 4
1000 .IX Item "len"
1001 The length of \fIbuf\fR in bytes.
1002 .RE
1003 .RS 4
1004 .RE
1005 .IP "log_ttyout" 4
1006 .IX Item "log_ttyout"
1007 .Vb 1
1008 \& int (*log_ttyout)(const char *buf, unsigned int len);
1009 .Ve
1010 .Sp
1011 The \fIlog_ttyout\fR function is called whenever data can be read from
1012 the command but before it is written to the user's terminal.  This
1013 allows the plugin to reject data if it chooses to (for instance
1014 if the output contains banned content).  Returns \f(CW1\fR if the data
1015 should be passed to the user, \f(CW0\fR if the data is rejected
1016 (which will terminate the command) or \f(CW\*(C`\-1\*(C'\fR if an error occurred.
1017 .Sp
1018 The function arguments are as follows:
1019 .RS 4
1020 .IP "buf" 4
1021 .IX Item "buf"
1022 The buffer containing command output.
1023 .IP "len" 4
1024 .IX Item "len"
1025 The length of \fIbuf\fR in bytes.
1026 .RE
1027 .RS 4
1028 .RE
1029 .IP "log_stdin" 4
1030 .IX Item "log_stdin"
1031 .Vb 1
1032 \& int (*log_stdin)(const char *buf, unsigned int len);
1033 .Ve
1034 .Sp
1035 The \fIlog_stdin\fR function is only used if the standard input does
1036 not correspond to a tty device.  It is called whenever data can be
1037 read from the standard input but before it is passed to the running
1038 command.  This allows the plugin to reject data if it chooses to
1039 (for instance if the input contains banned content).  Returns \f(CW1\fR
1040 if the data should be passed to the command, \f(CW0\fR if the data is
1041 rejected (which will terminate the command) or \f(CW\*(C`\-1\*(C'\fR if an error
1042 occurred.
1043 .Sp
1044 The function arguments are as follows:
1045 .RS 4
1046 .IP "buf" 4
1047 .IX Item "buf"
1048 The buffer containing user input.
1049 .IP "len" 4
1050 .IX Item "len"
1051 The length of \fIbuf\fR in bytes.
1052 .RE
1053 .RS 4
1054 .RE
1055 .IP "log_stdout" 4
1056 .IX Item "log_stdout"
1057 .Vb 1
1058 \& int (*log_stdout)(const char *buf, unsigned int len);
1059 .Ve
1060 .Sp
1061 The \fIlog_stdout\fR function is only used if the standard output does
1062 not correspond to a tty device.  It is called whenever data can be
1063 read from the command but before it is written to the standard
1064 output.  This allows the plugin to reject data if it chooses to
1065 (for instance if the output contains banned content).  Returns \f(CW1\fR
1066 if the data should be passed to the user, \f(CW0\fR if the data is
1067 rejected (which will terminate the command) or \f(CW\*(C`\-1\*(C'\fR if an error
1068 occurred.
1069 .Sp
1070 The function arguments are as follows:
1071 .RS 4
1072 .IP "buf" 4
1073 .IX Item "buf"
1074 The buffer containing command output.
1075 .IP "len" 4
1076 .IX Item "len"
1077 The length of \fIbuf\fR in bytes.
1078 .RE
1079 .RS 4
1080 .RE
1081 .IP "log_stderr" 4
1082 .IX Item "log_stderr"
1083 .Vb 1
1084 \& int (*log_stderr)(const char *buf, unsigned int len);
1085 .Ve
1086 .Sp
1087 The \fIlog_stderr\fR function is only used if the standard error does
1088 not correspond to a tty device.  It is called whenever data can be
1089 read from the command but before it is written to the standard
1090 error.  This allows the plugin to reject data if it chooses to
1091 (for instance if the output contains banned content).  Returns \f(CW1\fR
1092 if the data should be passed to the user, \f(CW0\fR if the data is
1093 rejected (which will terminate the command) or \f(CW\*(C`\-1\*(C'\fR if an error
1094 occurred.
1095 .Sp
1096 The function arguments are as follows:
1097 .RS 4
1098 .IP "buf" 4
1099 .IX Item "buf"
1100 The buffer containing command output.
1101 .IP "len" 4
1102 .IX Item "len"
1103 The length of \fIbuf\fR in bytes.
1104 .RE
1105 .RS 4
1106 .RE
1107 .PP
1108 \fIVersion macros\fR
1109 .IX Subsection "Version macros"
1110 .PP
1111 Same as for the \*(L"Policy Plugin \s-1API\s0\*(R".
1112 .SS "Conversation \s-1API\s0"
1113 .IX Subsection "Conversation API"
1114 If the plugin needs to interact with the user, it may do so via the
1115 conversation function.  A plugin should not attempt to read directly
1116 from the standard input or the user's tty (neither of which are
1117 guaranteed to exist).  The caller must include a trailing newline
1118 in \f(CW\*(C`msg\*(C'\fR if one is to be printed.
1119 .PP
1120 A printf-style function is also available that can be used to display
1121 informational or error messages to the user, which is usually more
1122 convenient for simple messages where no use input is required.
1123 .PP
1124 .Vb 12
1125 \& struct sudo_conv_message {
1126 \& #define SUDO_CONV_PROMPT_ECHO_OFF  0x0001 /* do not echo user input */
1127 \& #define SUDO_CONV_PROMPT_ECHO_ON   0x0002 /* echo user input */
1128 \& #define SUDO_CONV_ERROR_MSG        0x0003 /* error message */
1129 \& #define SUDO_CONV_INFO_MSG         0x0004 /* informational message */
1130 \& #define SUDO_CONV_PROMPT_MASK      0x0005 /* mask user input */
1131 \& #define SUDO_CONV_DEBUG_MSG        0x0006 /* debugging message */
1132 \& #define SUDO_CONV_PROMPT_ECHO_OK   0x1000 /* flag: allow echo if no tty */
1133 \&     int msg_type;
1134 \&     int timeout;
1135 \&     const char *msg;
1136 \& };
1137 \&
1138 \& struct sudo_conv_reply {
1139 \&     char *reply;
1140 \& };
1141 \&
1142 \& typedef int (*sudo_conv_t)(int num_msgs,
1143 \&              const struct sudo_conv_message msgs[],
1144 \&              struct sudo_conv_reply replies[]);
1145 \&
1146 \& typedef int (*sudo_printf_t)(int msg_type, const char *fmt, ...);
1147 .Ve
1148 .PP
1149 Pointers to the conversation and printf-style functions are passed
1150 in to the plugin's \f(CW\*(C`open\*(C'\fR function when the plugin is initialized.
1151 .PP
1152 To use the conversation function, the plugin must pass an array of
1153 \&\f(CW\*(C`sudo_conv_message\*(C'\fR and \f(CW\*(C`sudo_conv_reply\*(C'\fR structures.  There must
1154 be a \f(CW\*(C`struct sudo_conv_message\*(C'\fR and \f(CW\*(C`struct sudo_conv_reply\*(C'\fR for
1155 each message in the conversation.  The plugin is responsible for
1156 freeing the reply buffer filled in to the \f(CW\*(C`struct sudo_conv_reply\*(C'\fR,
1157 if any.
1158 .PP
1159 The printf-style function uses the same underlying mechanism as the
1160 conversation function but only supports \f(CW\*(C`SUDO_CONV_INFO_MSG\*(C'\fR,
1161 \&\f(CW\*(C`SUDO_CONV_ERROR_MSG\*(C'\fR and \f(CW\*(C`SUDO_CONV_DEBUG_MSG\*(C'\fR for the \fImsg_type\fR
1162 parameter.  It can be more convenient than using the conversation
1163 function if no user reply is needed and supports standard \fIprintf()\fR
1164 escape sequences.
1165 .PP
1166 Unlike, \f(CW\*(C`SUDO_CONV_INFO_MSG\*(C'\fR and \f(CW\*(C`SUDO_CONV_ERROR_MSG\*(C'\fR, messages
1167 sent with the <\s-1SUDO_CONV_DEBUG_MSG\s0> \fImsg_type\fR are not directly
1168 user-visible.  Instead, they are logged to the file specified in
1169 the \f(CW\*(C`Debug\*(C'\fR statement (if any) in the \fI@sysconfdir@/sudo.conf\fR
1170 file.  This allows a plugin to log debugging information and is
1171 intended to be used in conjunction with the \fIdebug_flags\fR setting.
1172 .PP
1173 See the sample plugin for an example of the conversation function usage.
1174 .SS "Sudoers Group Plugin \s-1API\s0"
1175 .IX Subsection "Sudoers Group Plugin API"
1176 The \fIsudoers\fR module supports a plugin interface to allow non-Unix
1177 group lookups.  This can be used to query a group source other than
1178 the standard Unix group database.  A sample group plugin is bundled
1179 with \fBsudo\fR that implements file-based lookups.  Third party group
1180 plugins include a \s-1QAS\s0 \s-1AD\s0 plugin available from Quest Software.
1181 .PP
1182 A group plugin must declare and populate a \f(CW\*(C`sudoers_group_plugin\*(C'\fR
1183 struct in the global scope.  This structure contains pointers to
1184 the functions that implement plugin initialization, cleanup and
1185 group lookup.
1186 .PP
1187 .Vb 8
1188 \& struct sudoers_group_plugin {
1189 \&    unsigned int version;
1190 \&    int (*init)(int version, sudo_printf_t sudo_printf,
1191 \&                char *const argv[]);
1192 \&    void (*cleanup)(void);
1193 \&    int (*query)(const char *user, const char *group,
1194 \&                 const struct passwd *pwd);
1195 \&};
1196 .Ve
1197 .PP
1198 The \f(CW\*(C`sudoers_group_plugin\*(C'\fR struct has the following fields:
1199 .IP "version" 4
1200 .IX Item "version"
1201 The \f(CW\*(C`version\*(C'\fR field should be set to \s-1GROUP_API_VERSION\s0.
1202 .Sp
1203 This allows \fIsudoers\fR to determine the \s-1API\s0 version the group plugin
1204 was built against.
1205 .IP "init" 4
1206 .IX Item "init"
1207 .Vb 2
1208 \& int (*init)(int version, sudo_printf_t plugin_printf,
1209 \&             char *const argv[]);
1210 .Ve
1211 .Sp
1212 The \fIinit\fR function is called after \fIsudoers\fR has been parsed but
1213 before any policy checks.  It returns 1 on success, 0 on failure
1214 (or if the plugin is not configured), and \-1 if a error occurred.
1215 If an error occurs, the plugin may call the plugin_printf function
1216 with \f(CW\*(C`SUDO_CONF_ERROR_MSG\*(C'\fR to present additional error information
1217 to the user.
1218 .Sp
1219 The function arguments are as follows:
1220 .RS 4
1221 .IP "version" 4
1222 .IX Item "version"
1223 The version passed in by \fIsudoers\fR allows the plugin to determine the
1224 major and minor version number of the group plugin \s-1API\s0 supported by
1225 \&\fIsudoers\fR.
1226 .IP "plugin_printf" 4
1227 .IX Item "plugin_printf"
1228 A pointer to a printf-style function that may be used to display
1229 informational or error message to the user.
1230 Returns the number of characters printed on success and \-1 on failure.
1231 .IP "argv" 4
1232 .IX Item "argv"
1233 A NULL-terminated array of arguments generated from the \fIgroup_plugin\fR
1234 option in \fIsudoers\fR.  If no arguments were given, \fIargv\fR will be
1235 \&\s-1NULL\s0.
1236 .RE
1237 .RS 4
1238 .RE
1239 .IP "cleanup" 4
1240 .IX Item "cleanup"
1241 .Vb 1
1242 \& void (*cleanup)();
1243 .Ve
1244 .Sp
1245 The \fIcleanup\fR function is called when \fIsudoers\fR has finished its
1246 group checks.  The plugin should free any memory it has allocated
1247 and close open file handles.
1248 .IP "query" 4
1249 .IX Item "query"
1250 .Vb 2
1251 \& int (*query)(const char *user, const char *group,
1252 \&              const struct passwd *pwd);
1253 .Ve
1254 .Sp
1255 The \fIquery\fR function is used to ask the group plugin whether \fIuser\fR
1256 is a member of \fIgroup\fR.
1257 .Sp
1258 The function arguments are as follows:
1259 .RS 4
1260 .IP "user" 4
1261 .IX Item "user"
1262 The name of the user being looked up in the external group database.
1263 .IP "group" 4
1264 .IX Item "group"
1265 The name of the group being queried.
1266 .IP "pwd" 4
1267 .IX Item "pwd"
1268 The password database entry for \fIuser\fR, if any.  If \fIuser\fR is not
1269 present in the password database, \fIpwd\fR will be \f(CW\*(C`NULL\*(C'\fR.
1270 .RE
1271 .RS 4
1272 .RE
1273 .PP
1274 \fIVersion Macros\fR
1275 .IX Subsection "Version Macros"
1276 .PP
1277 .Vb 5
1278 \& /* Sudoers group plugin version major/minor */
1279 \& #define GROUP_API_VERSION_MAJOR 1
1280 \& #define GROUP_API_VERSION_MINOR 0
1281 \& #define GROUP_API_VERSION ((GROUP_API_VERSION_MAJOR << 16) | \e
1282 \&                            GROUP_API_VERSION_MINOR)
1283 \&
1284 \& /* Getters and setters for group version */
1285 \& #define GROUP_API_VERSION_GET_MAJOR(v) ((v) >> 16)
1286 \& #define GROUP_API_VERSION_GET_MINOR(v) ((v) & 0xffff)
1287 \& #define GROUP_API_VERSION_SET_MAJOR(vp, n) do { \e
1288 \&     *(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \e
1289 \& } while(0)
1290 \& #define GROUP_API_VERSION_SET_MINOR(vp, n) do { \e
1291 \&     *(vp) = (*(vp) & 0xffff0000) | (n); \e
1292 \& } while(0)
1293 .Ve
1294 .SH "SEE ALSO"
1295 .IX Header "SEE ALSO"
1296 \&\fIsudoers\fR\|(@mansectform@), \fIsudo\fR\|(@mansectsu@)
1297 .SH "BUGS"
1298 .IX Header "BUGS"
1299 If you feel you have found a bug in \fBsudo\fR, please submit a bug report
1300 at http://www.sudo.ws/sudo/bugs/
1301 .SH "SUPPORT"
1302 .IX Header "SUPPORT"
1303 Limited free support is available via the sudo-workers mailing list,
1304 see http://www.sudo.ws/mailman/listinfo/sudo\-workers to subscribe or
1305 search the archives.
1306 .SH "DISCLAIMER"
1307 .IX Header "DISCLAIMER"
1308 \&\fBsudo\fR is provided ``\s-1AS\s0 \s-1IS\s0'' and any express or implied warranties,
1309 including, but not limited to, the implied warranties of merchantability
1310 and fitness for a particular purpose are disclaimed.  See the \s-1LICENSE\s0
1311 file distributed with \fBsudo\fR or http://www.sudo.ws/sudo/license.html
1312 for complete details.