forked from sudo-project/sudo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsudo_plugin_python.man.in
More file actions
1905 lines (1902 loc) · 41.3 KB
/
Copy pathsudo_plugin_python.man.in
File metadata and controls
1905 lines (1902 loc) · 41.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.\" Automatically generated from an mdoc input file. Do not edit.
.\"
.\" SPDX-License-Identifier: ISC
.\"
.\" Copyright (c) 2019-2021 Robert Manner <[email protected]>
.\" Copyright (c) 2019-2023 Todd C. Miller <[email protected]>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.TH "SUDO_PLUGIN_PYTHON" "5" "January 16, 2023" "Sudo @PACKAGE_VERSION@" "File Formats Manual"
.nh
.if n .ad l
.SH "NAME"
\fBsudo_plugin_python\fR
\- Sudo Plugin API (Python)
.SH "DESCRIPTION"
Starting with version 1.9,
\fBsudo\fR
plugins can be written in python.
The API closely follows the C
\fBsudo\fR
plugin API described by
sudo_plugin(@mansectform@).
.PP
The supported plugins types are:
.PP
.RS 1n
.PD 0
.TP 3n
\fB\(bu\fR
Policy plugin
.TP 3n
\fB\(bu\fR
I/O plugin
.TP 3n
\fB\(bu\fR
Audit plugin
.TP 3n
\fB\(bu\fR
Approval plugin
.TP 3n
\fB\(bu\fR
Group provider plugin
.RE
.PD
.PP
Python plugin support needs to be explicitly enabled at build time
with the configure option
\(lq--enable-python\(rq.
Python version 3.0 or higher is required.
.SS "Sudo Python Plugin Base"
A plugin written in Python should be a class in a python file that
inherits from
\fIsudo.Plugin\fR.
The
\fIsudo.Plugin\fR
base class has no real purpose other than to identify this class as a plugin.
.PP
The only implemented method is a constructor, which stores the
keyword arguments it receives as fields (member variables) in the object.
This is intended as a convenience to allow you to avoid writing the
constructor yourself.
.PP
For example:
.nf
.sp
.RS 4n
import sudo
class MySudoPlugin(sudo.Plugin):
# example constructor (optional)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# example destructor (optional)
def __del__(self):
pass
.RE
.fi
.PP
Both the constructor and destructor are optional and can be omitted.
.PP
The customized Plugin class should define a few plugin-specific methods.
When the plugin loads,
\fBsudo\fR
will create an instance of this class and call the methods.
The actual methods required depend on the type of the plugin,
but most return an
\fIint\fR
result code, as documented in
sudo_plugin(@mansectform@),
that indicates whether or not the method was successful.
The Python sudo module defines the following constants to improve readability:
.RS 4n
.TS
l l.
.PP
\fBDefine\fR \fBValue\fR
.PP
\fRsudo.RC.OK\fR 1
.PP
\fRsudo.RC.ACCEPT\fR 1
.PP
\fRsudo.RC.REJECT\fR 0
.PP
\fRsudo.RC.ERROR\fR \-1
.PP
\fRsudo.RC.USAGE_ERROR\fR \-2
.TE
.RE
.PP
If a function returns
\fRNone\fR
(for example, if it does not call return),
it will be considered to have returned
\fRsudo.RC.OK\fR.
If an exception is raised (other than sudo.PluginException), the
backtrace will be shown to the user and the plugin function will return
\fRsudo.RC.ERROR\fR.
If that is not acceptable, you must catch the exception and handle it yourself.
.PP
Instead of just returning
\fRsudo.RC.ERROR\fR
or
\fRsudo.RC.REJECT\fR
result code the plugin can also provide a message describing the problem.
This can be done by raising one of the special exceptions:
.nf
.sp
.RS 4n
raise sudo.PluginError("Message")
raise sudo.PluginReject("Message")
.RE
.fi
.PP
This added message will be used by the audit plugins.
Both exceptions inherit from
\fRsudo.PluginException\fR
.SS "Python Plugin Loader"
Running the Python interpreter and bridging between C and Python is
handled by the
\fBsudo\fR
plugin
\fI@python_plugin@\fR.
This shared object can be loaded like any other dynamic
\fBsudo\fR
plugin and should receive the path and the class name of the Python
plugin it is loading as arguments.
.PP
Example usage in
sudo.conf(@mansectform@):
.nf
.sp
.RS 4n
Plugin python_policy @python_plugin@ ModulePath=<path> ClassName=<class>
Plugin python_io @python_plugin@ ModulePath=<path> ClassName=<class>
Plugin python_audit @python_plugin@ ModulePath=<path> ClassName=<class>
Plugin python_approval @python_plugin@ ModulePath=<path> ClassName=<class>
.RE
.fi
.PP
Example group provider plugin usage in the
\fIsudoers\fR
file:
.nf
.sp
.RS 4n
Defaults group_plugin="@python_plugin@ ModulePath=<path> ClassName=<class>"
.RE
.fi
.PP
The plugin arguments are as follows:
.TP 6n
ModulePath
The path of a python file which contains the class of the sudo Python plugin.
It must be either an absolute path or a path relative to the sudo Python plugin
directory,
\fI@plugindir@/python\fR.
The parent directory of
\fIModulePath\fR
will be appended to Python's module search path (there is currently no
way to force Python to load a module from a fully-qualified path).
It is good practice to use a prefix for the module file that is unlikely
to conflict with other installed Python modules, for example,
\fIsudo_policy.py\fR.
Otherwise, if the there is an installed Python module with the same
file name as the sudo Python plugin file (without the directory),
the wrong file will be loaded.
.TP 6n
ClassName
(Optional.) The name of the class implementing the sudo Python plugin.
If not supplied, the one and only sudo.Plugin that is present in the module
will be used.
If there are multiple such plugins in the module (or none), it
will result in an error.
.SS "Policy plugin API"
Policy plugins must be registered in
sudo.conf(@mansectform@).
For example:
.nf
.sp
.RS 4n
Plugin python_policy @python_plugin@ ModulePath=<path> ClassName=<class>
.RE
.fi
.PP
Currently, only a single policy plugin may be specified in
sudo.conf(@mansectform@).
.PP
A policy plugin may have the following member functions:
.TP 6n
\fIconstructor\fR
.nf
.RS 6n
__init__(self, user_env: Tuple[str, ...], settings: Tuple[str, ...],
version: str, user_info: Tuple[str, ...],
plugin_options: Tuple[str, ...])
.RE
.fi
.RS 6n
.sp
Implementing this function is optional.
The default constructor will set the keyword arguments it receives
as member variables in the object.
.sp
The constructor matches the
\fBopen\fR()
function in the C
\fBsudo\fR
plugin API.
.sp
The function arguments are as follows:
.TP 6n
\fIuser_env\fR
The user's environment as a tuple of strings in
\(lqkey=value\(rq
format.
.TP 6n
\fIsettings\fR
A tuple of user-supplied
\fIsudo\fR
settings in the form of
\(lqkey=value\(rq
strings.
.TP 6n
\fIversion\fR
The version of the Python Policy Plugin API.
.TP 6n
\fIuser_info\fR
A tuple of information about the user running the command in the form of
\(lqkey=value\(rq
strings.
.TP 6n
\fIplugin_options\fR
The plugin options passed as arguments in the
sudo.conf(@mansectform@)
plugin registration.
This is a tuple of strings, usually (but not necessarily) in
\(lqkey=value\(rq
format.
.PP
The
\fBsudo.options_as_dict\fR()
convenience function can be used to convert
\(lqkey=value\(rq
pairs to a dictionary.
For a list of recognized keys and their supported values,
see the policy plugin
\fBopen\fR()
documentation in
sudo_plugin(@mansectform@).
.RE
.TP 6n
\fIcheck_policy\fR
.nf
.RS 6n
check_policy(self, argv: Tuple[str, ...], env_add: Tuple[str, ...])
.RE
.fi
.RS 6n
.sp
The
\fBcheck_policy\fR()
function is called by
\fBsudo\fR
to determine whether the user is allowed to run the specified command.
Implementing this function is mandatory for a policy plugin.
.sp
The function arguments are as follows:
.TP 6n
\fIargv\fR
A tuple describing the command the user wishes to run.
.TP 6n
\fIenv_add\fR
Additional environment variables specified by the user on the command line in
the form of a tuple of
\(lqkey=value\(rq
pairs.
The
\fBsudo.options_as_dict\fR()
convenience function can be used to convert them to a dictionary.
.PP
This function should return a result code or a tuple in the following format:
.nf
.sp
.RS 10n
return (rc, command_info_out, argv_out, user_env_out)
.RE
.fi
.sp
The tuple values are as follows:
.TP 6n
\fIrc\fR
The result of the policy check, one of the
\fRsudo.RC.*\fR
constants.
\fRsudo.RC.ACCEPT\fR
if the command is allowed,
\fRsudo.RC.REJECT\fR
if not allowed,
\fRsudo.RC.ERROR\fR
for a general error, or
\fRsudo.RC.USAGE_ERROR\fR
for a usage error.
.TP 6n
\fIcommand_info_out\fR
Optional (only required when the command is accepted).
Information about the command being run in the form of
\(lqkey=value\(rq
strings.
.sp
To accept a command, at the very minimum the plugin must set in the
\fIcommand\fR,
\fIrunas_uid\fR,
and
\fIrunas_gid\fR
keys.
.sp
For a list of recognized keys and supported values,
see the
\fBcheck_policy\fR()
documentation in
sudo_plugin(@mansectform@).
.TP 6n
\fIargv_out\fR
Optional (only required when the command is accepted).
The arguments to pass to the
execve(2)
system call when executing the command.
.TP 6n
\fIuser_env_out\fR
Optional (only required when the command is accepted).
The environment to use when executing the command in the form of a
tuple of strings in
\(lqkey=value\(rq
format.
.PD 0
.PP
.RE
.PD
.TP 6n
\fIinit_session\fR
.nf
.RS 6n
init_session(self, user_pwd: Tuple, user_env: Tuple[str, ...])
.RE
.fi
.RS 6n
.sp
Perform session setup (optional).
The
\fBinit_session\fR()
function is called before
\fBsudo\fR
sets up the
execution environment for the command before any user-ID or group-ID changes.
.sp
The function arguments are as follows:
.TP 6n
\fIuser_pwd\fR
A tuple describing the user's passwd entry.
Convertible to
\fIpwd.struct_passwd or\fR
\fRNone\fR
if the user is not present in the password database.
.sp
Example conversion:
.nf
.RS 12n
user_pwd = pwd.struct_passwd(user_pwd) if user_pwd else None
.RE
.fi
.TP 6n
\fIuser_env\fR
The environment the command will run in.
This is a tuple of strings in
\(lqkey=value\(rq
format.
.PP
This function should return a result code or a tuple in the following format:
.nf
.sp
.RS 10n
return (rc, user_env_out)
.RE
.fi
.sp
The tuple values are as follows:
.TP 6n
\fIrc\fR
The result of the session init, one of the
\fRsudo.RC.*\fR
constants.
\fRsudo.RC.OK\fR
on success, 0 on failure, or
\fRsudo.RC.ERROR\fR
if an error occurred.
.TP 6n
\fIuser_env_out\fR
Optional.
If the
\fBinit_session\fR()
function needs to modify the user environment, it can return the new
environment in
\fIuser_env_out\fR.
If this is omitted, no changes will be made to
\fIuser_env\fR.
.PD 0
.PP
.RE
.PD
.TP 6n
\fIlist\fR
.nf
.RS 6n
list(self, argv: Tuple[str, ...], is_verbose: int, user: str)
.RE
.fi
.RS 6n
.sp
List available privileges for the invoking user.
.sp
The function arguments are as follows:
.TP 6n
\fIargv\fR
If not set to
\fRNone\fR,
an argument vector describing a command the user wishes to check
against the policy.
.TP 6n
\fIis_verbose\fR
Flag indicating whether to list in verbose mode or not.
.TP 6n
\fIuser\fR
The name of a different user to list privileges for if the policy allows it.
If
\fRNone\fR,
the plugin should list the privileges of the invoking user.
.PD 0
.PP
.RE
.PD
.TP 6n
\fIvalidate\fR
.nf
.RS 6n
validate(self)
.RE
.fi
.RS 6n
.sp
For policy plugins that cache authentication credentials, this function is used to validate and cache the credentials (optional).
.RE
.TP 6n
\fIinvalidate\fR
.nf
.RS 6n
invalidate(self, remove: int)
.RE
.fi
.RS 6n
.sp
For policy plugins that cache authentication credentials, this function is used to invalidate the credentials (optional).
.sp
The function arguments are as follows:
.TP 6n
\fIremove\fR
If this flag is set, the plugin may remove the credentials instead of simply
invalidating them.
.PD 0
.PP
.RE
.PD
.TP 6n
\fIshow_version\fR
.nf
.RS 6n
show_version(self, is_verbose: int)
.RE
.fi
.RS 6n
.sp
Display the plugin version information to the user.
The
\fBsudo.log_info\fR()
function should be used.
.sp
The function arguments are as follows:
.TP 6n
\fIis_verbose\fR
A flag to indicate displaying more verbose information.
Currently this is 1 if
\(oqsudo -V\(cq
is run as the root user.
.PD 0
.PP
.RE
.PD
.TP 6n
\fIclose\fR
.br
.nf
.RS 6n
close(self, exit_status: int, error: int)
.RE
.fi
.RS 6n
.sp
Called when a command finishes executing.
.sp
Works the same as the
\fBclose\fR()
function in the C
\fBsudo\fR
plugin API, except that it only gets called if
\fBsudo\fR
attempts to execute the command.
.sp
The function arguments are as follows:
.TP 6n
\fIexit_status\fR
The exit status of the command if was executed, otherwise \-1.
.TP 6n
\fIerror\fR
.br
If the command could not be executed, this is set to the value of
errno set by the
execve(2)
system call, otherwise 0.
.PD 0
.PP
.RE
.PD
.SS "Policy plugin example"
Sudo ships with an example Python policy plugin.
To try it, register it by adding the following lines to
\fI@sysconfdir@/sudo.conf\fR:
.nf
.sp
.RS 0n
Plugin python_policy @python_plugin@ \e
ModulePath=@EXAMPLES@/example_policy_plugin.py \e
ClassName=SudoPolicyPlugin
.RE
.fi
.PP
Only one policy plugin can be enabled at a time so you must disable
any other policy plugin listed in
\fI@sysconfdir@/sudo.conf\fR,
such as
sudoers(@mansectform@).
.SS "I/O plugin API"
I/O plugins must be registered in
sudo.conf(@mansectform@).
For example:
.nf
.sp
.RS 4n
Plugin python_io @python_plugin@ ModulePath=<path> ClassName=<class>
.RE
.fi
.PP
Sudo supports loading multiple I/O plugins.
Currently only 8 python I/O plugins can be loaded at once.
.PP
An I/O plugin may have the following member functions:
.TP 6n
\fIconstructor\fR
.nf
.RS 6n
__init__(self, user_env: Tuple[str, ...], settings: Tuple[str, ...],
version: str, user_info: Tuple[str, ...],
plugin_options: Tuple[str, ...])
.RE
.fi
.RS 6n
.sp
Implementing this function is optional.
The default constructor will set the keyword arguments it receives
as member variables in the object.
.sp
The constructor matches the
\fBopen\fR()
function in the C
\fBsudo\fR
plugin API.
.sp
The function arguments are as follows:
.TP 6n
\fIuser_env\fR
The user's environment as a tuple of strings in
\(lqkey=value\(rq
format.
.TP 6n
\fIsettings\fR
A tuple of user-supplied
\fIsudo\fR
settings in the form of
\(lqkey=value\(rq
strings.
.TP 6n
\fIversion\fR
The version of the Python I/O Plugin API.
.TP 6n
\fIuser_info\fR
A tuple of information about the user running the command in the form of
\(lqkey=value\(rq
strings.
.TP 6n
\fIplugin_options\fR
The plugin options passed as arguments in the
sudo.conf(@mansectform@)
plugin registration.
This is a tuple of strings, usually (but not necessarily) in
\(lqkey=value\(rq
format.
.PP
The
\fBsudo.options_as_dict\fR()
convenience function can be used to convert
\(lqkey=value\(rq
pairs to a dictionary.
For a list of recognized keys and their supported values,
see the I/O plugin
\fBopen\fR()
documentation in
sudo_plugin(@mansectform@).
.RE
.TP 6n
\fIopen\fR
.nf
.RS 6n
open(self, argv: Tuple[str, ...],
command_info: Tuple[str, ...]) -> int
.RE
.fi
.RS 6n
.sp
Receives the command the user wishes to run.
.sp
Works the same as the
\fBopen\fR()
function in the C
\fBsudo\fR
plugin API except that:
.sp
.RS 7n
.PD 0
.TP 3n
\fB\(bu\fR
It only gets called when there is a command to be executed
(and not for a version query for example).
.TP 3n
\fB\(bu\fR
Other arguments of the C API
\fBopen\fR()
function are received through the constructor.
.RE
.sp
The function arguments are as follows:
.PD
.TP 6n
\fIargv\fR
A tuple of the arguments describing the command the user wishes to run.
.TP 6n
\fIcommand_info\fR
Information about the command being run in the form of
\(lqkey=value\(rq
strings.
.PP
The
\fBsudo.options_as_dict\fR()
convenience function can be used to convert
\(lqkey=value\(rq
pairs to a dictionary.
For a list of recognized keys and their supported values,
see the I/O plugin
\fBopen\fR()
documentation in
sudo_plugin(@mansectform@).
.sp
The
\fBopen\fR()
function should return a result code, one of the
\fRsudo.RC.*\fR
constants.
If the function returns
\fRsudo.RC.REJECT\fR,
no I/O will be sent to the plugin.
.RE
.TP 6n
\fIlog_ttyin\fR, \fIlog_ttyout\fR, \fIlog_stdin\fR, \fIlog_stdout\fR, \fIlog_stderr\fR
.nf
.RS 6n
log_ttyin(self, buf: str) -> int
log_ttyout(self, buf: str) -> int
log_stdin(self, buf: str) -> int
log_stdout(self, buf: str) -> int
log_stderr(self, buf: str) -> int
.RE
.fi
.RS 6n
.sp
Receive the user input or output of the terminal device and
application standard input, standard output, or standard error.
See the matching calls in
sudo_plugin(@mansectform@).
.sp
The function arguments are as follows:
.TP 6n
\fIbuf\fR
The input (or output) buffer in the form of a string.
.PP
The function should return a result code, one of the
\fRsudo.RC.*\fR
constants.
.sp
If
\fRsudo.RC.ERROR\fR
is returned, the running command will be terminated and all of the
plugin's logging functions will be disabled.
Other I/O logging plugins will still receive any remaining
input or output that has not yet been processed.
.sp
If an input logging function rejects the data by returning
\fRsudo.RC.REJECT\fR,
the command will be terminated and the data will not be passed to the
command, though it will still be sent to any other I/O logging plugins.
If an output logging function rejects the data by returning
\fRsudo.RC.REJECT\fR,
the command will be terminated and the data will not be written to the
terminal, though it will still be sent to any other I/O logging plugins.
.RE
.TP 6n
\fIchange_winsize\fR
.nf
.RS 6n
change_winsize(self, line: int, cols: int) -> int
.RE
.fi
.RS 6n
.sp
Called whenever the window size of the terminal changes.
The function arguments are as follows:
.TP 6n
\fIline\fR
The number of lines of the terminal.
.TP 6n
\fIcols\fR
The number of columns of the terminal.
.PD 0
.PP
.RE
.PD
.TP 6n
\fIlog_suspend\fR
.nf
.RS 6n
log_suspend(self, signo: int) -> int
.RE
.fi
.RS 6n
Called whenever a command is suspended or resumed.
.sp
The function arguments are as follows:
.TP 6n
\fIsigno\fR
.br
The number of the signal that caused the command to be suspended or
\fRSIGCONT\fR
if the command was resumed.
.PD 0
.PP
.RE
.PD
.TP 6n
\fIshow_version\fR
.nf
.RS 6n
show_version(self, is_verbose: int)
.RE
.fi
.RS 6n
Display the plugin version information to the user.
The
\fBsudo.log_info\fR()
function should be used.
.sp
The function arguments are as follows:
.TP 6n
\fIis_verbose\fR
A flag to indicate displaying more verbose information.
Currently this is 1 if
\(oqsudo -V\(cq
is run as the root user.
.PD 0
.PP
.RE
.PD
.TP 6n
\fIclose\fR
.br
.nf
.RS 6n
close(self, exit_status: int, error: int) -> None
.RE
.fi
.RS 6n
Called when a command finishes execution.
.sp
Works the same as the
\fBclose\fR()
function in the C
\fBsudo\fR
plugin API, except that it only gets called if
\fBsudo\fR
attempts to execute the command.
.sp
The function arguments are as follows:
.TP 6n
\fIexit_status\fR
The exit status of the command if was executed, otherwise \-1.
.TP 6n
\fIerror\fR
.br
If the command could not be executed, this is set to the value of
errno set by the
execve(2)
system call, otherwise 0.
.PD 0
.PP
.RE
.PD
.SS "I/O plugin example"
Sudo ships with a Python I/O plugin example.
To try it, register it by adding the following lines to
\fI@sysconfdir@/sudo.conf\fR:
.nf
.sp
.RS 4n
Plugin python_io @python_plugin@ \e
ModulePath=@EXAMPLES@/example_io_plugin.py \e
ClassName=SudoIOPlugin
.RE
.fi
.SS "Audit plugin API"
Audit plugins must be registered in
sudo.conf(@mansectform@).
For example:
.nf
.sp
.RS 4n
Plugin python_audit @python_plugin@ ModulePath=<path> ClassName=<class>
.RE
.fi
.PP
Sudo supports loading multiple audit plugins.
Currently only 8 python audit plugins can be loaded at once.
.PP
An audit plugin may have the following member functions (all of which are optional):
.TP 6n
\fIconstructor\fR
.nf
.RS 6n
__init__(self, user_env: Tuple[str, ...], settings: Tuple[str, ...],
version: str, user_info: Tuple[str, ...], plugin_options: Tuple[str, ...])
.RE
.fi
.RS 6n
.sp
The default constructor will set the keyword arguments it receives
as member variables in the object.
.sp
The constructor matches the
\fBopen\fR()
function in the C
\fBsudo\fR
plugin API.
.sp
The function arguments are as follows:
.TP 6n
\fIuser_env\fR
The user's environment as a tuple of strings in
\(lqkey=value\(rq
format.
.TP 6n
\fIsettings\fR
A tuple of user-supplied
\fIsudo\fR
settings in the form of
\(lqkey=value\(rq
strings.
.TP 6n
\fIversion\fR
The version of the Python Audit Plugin API.
.TP 6n
\fIuser_info\fR
A tuple of information about the user running the command in the form of
\(lqkey=value\(rq
strings.
.TP 6n
\fIplugin_options\fR
The plugin options passed as arguments in the
sudo.conf(@mansectform@)
plugin registration.
This is a tuple of strings, usually (but not necessarily) in
\(lqkey=value\(rq
format.
.PD 0
.PP
.RE
.PD
.TP 6n
\fIopen\fR
.nf
.RS 6n
open(self, submit_optind: int,
submit_argv: Tuple[str, ...]) -> int
.RE
.fi
.RS 6n
.sp
The function arguments are as follows:
.TP 6n
\fIsubmit_optind\fR
The index into
\fIsubmit_argv\fR
that corresponds to the first entry that is not a command line option.
.TP 6n
\fIsubmit_argv\fR
The argument vector sudo was invoked with, including all command line options.
.PD 0
.PP
.RE
.PD
.TP 6n
\fIclose\fR
.br
.nf
.RS 6n
close(self, status_type: int, status: int) -> None
.RE
.fi
.RS 6n
.sp
Called when sudo is finished, shortly before it exits.
.sp
The function arguments are as follows:
.TP 6n
\fIstatus_type\fR
The type of status being passed.
One of the
\fRsudo.EXIT_REASON.*\fR
constants.
.TP 6n
\fIstatus\fR
Depending on the value of
\fIstatus_type\fR,
this value is either
ignored, the command's exit status as returned by the
wait(2)
system call, the value of
\fIerrno\fR
set by the
execve(2)
system call, or the value of
\fIerrno\fR
resulting from an error in the
\fBsudo\fR
front-end.