Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/plugins/python/regress/check_python_examples.c
3866 views
1
/*
2
* SPDX-License-Identifier: ISC
3
*
4
* Copyright (c) 2020 Robert Manner <[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
#include "testhelpers.h"
20
#include <unistd.h>
21
22
#include <sudo_dso.h>
23
24
#define DECL_PLUGIN(type, variable_name) \
25
static struct type *variable_name = NULL; \
26
static struct type variable_name ## _original
27
28
#define RESTORE_PYTHON_PLUGIN(variable_name) \
29
memcpy(variable_name, &(variable_name ## _original), sizeof(variable_name ## _original))
30
31
#define SAVE_PYTHON_PLUGIN(variable_name) \
32
memcpy(&(variable_name ## _original), variable_name, sizeof(variable_name ## _original))
33
34
static const char *python_plugin_so_path = NULL;
35
static void *python_plugin_handle = NULL;
36
DECL_PLUGIN(io_plugin, python_io);
37
DECL_PLUGIN(policy_plugin, python_policy);
38
DECL_PLUGIN(approval_plugin, python_approval);
39
DECL_PLUGIN(audit_plugin, python_audit);
40
DECL_PLUGIN(sudoers_group_plugin, group_plugin);
41
42
static struct passwd example_pwd;
43
static bool verbose;
44
45
static int _init_symbols(void);
46
static int _unlink_symbols(void);
47
48
static void
49
create_plugin_options(const char *module_name, const char *class_name, const char *extra_option)
50
{
51
char opt_module_path[PATH_MAX + 256];
52
char opt_classname[PATH_MAX + 256];
53
snprintf(opt_module_path, sizeof(opt_module_path),
54
"ModulePath=" SRC_DIR "/%s.py", module_name);
55
56
snprintf(opt_classname, sizeof(opt_classname), "ClassName=%s", class_name);
57
58
str_array_free(&data.plugin_options);
59
size_t count = 3 + (extra_option != NULL);
60
data.plugin_options = create_str_array(count, opt_module_path,
61
opt_classname, extra_option, NULL);
62
}
63
64
static void
65
create_io_plugin_options(const char *log_path)
66
{
67
char opt_logpath[PATH_MAX + 16];
68
snprintf(opt_logpath, sizeof(opt_logpath), "LogPath=%s", log_path);
69
create_plugin_options("example_io_plugin", "SudoIOPlugin", opt_logpath);
70
}
71
72
static void
73
create_debugging_plugin_options(void)
74
{
75
create_plugin_options("example_debugging", "DebugDemoPlugin", NULL);
76
}
77
78
static void
79
create_audit_plugin_options(const char *extra_argument)
80
{
81
create_plugin_options("example_audit_plugin", "SudoAuditPlugin", extra_argument);
82
}
83
84
static void
85
create_conversation_plugin_options(void)
86
{
87
char opt_logpath[PATH_MAX + 16];
88
snprintf(opt_logpath, sizeof(opt_logpath), "LogPath=%s", data.tmp_dir);
89
create_plugin_options("example_conversation", "ReasonLoggerIOPlugin", opt_logpath);
90
}
91
92
static void
93
create_policy_plugin_options(void)
94
{
95
create_plugin_options("example_policy_plugin", "SudoPolicyPlugin", NULL);
96
}
97
98
static int
99
init(void)
100
{
101
// always start each test from clean state
102
memset(&data, 0, sizeof(data));
103
104
memset(&example_pwd, 0, sizeof(example_pwd));
105
example_pwd.pw_name = (char *)"pw_name";
106
example_pwd.pw_passwd = (char *)"pw_passwd";
107
example_pwd.pw_gecos = (char *)"pw_gecos";
108
example_pwd.pw_shell = (char *)"pw_shell";
109
example_pwd.pw_dir = (char *)"pw_dir";
110
example_pwd.pw_uid = (uid_t)1001;
111
example_pwd.pw_gid = (gid_t)101;
112
113
VERIFY_TRUE(asprintf(&data.tmp_dir, TEMP_PATH_TEMPLATE) >= 0);
114
VERIFY_NOT_NULL(mkdtemp(data.tmp_dir));
115
116
sudo_conf_clear_paths();
117
118
// some default values for the plugin open:
119
data.settings = create_str_array(1, NULL);
120
data.user_info = create_str_array(1, NULL);
121
data.command_info = create_str_array(1, NULL);
122
data.plugin_argc = 0;
123
data.plugin_argv = create_str_array(1, NULL);
124
data.user_env = create_str_array(1, NULL);
125
126
VERIFY_TRUE(_init_symbols());
127
return true;
128
}
129
130
static int
131
cleanup(int success)
132
{
133
if (!success) {
134
printf("\nThe output of the plugin:\n%s", data.stdout_str);
135
printf("\nThe error output of the plugin:\n%s", data.stderr_str);
136
}
137
138
VERIFY_TRUE(rmdir_recursive(data.tmp_dir));
139
if (data.tmp_dir2) {
140
VERIFY_TRUE(rmdir_recursive(data.tmp_dir2));
141
}
142
143
free(data.tmp_dir);
144
free(data.tmp_dir2);
145
146
str_array_free(&data.settings);
147
str_array_free(&data.user_info);
148
str_array_free(&data.command_info);
149
str_array_free(&data.plugin_argv);
150
str_array_free(&data.user_env);
151
str_array_free(&data.plugin_options);
152
153
return true;
154
}
155
156
static int
157
check_example_io_plugin_version_display(int is_verbose)
158
{
159
const char *errstr = NULL;
160
create_io_plugin_options(data.tmp_dir);
161
162
VERIFY_INT(python_io->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
163
data.user_info, data.command_info, data.plugin_argc, data.plugin_argv, data.user_env,
164
data.plugin_options, &errstr), SUDO_RC_OK);
165
VERIFY_INT(python_io->show_version(is_verbose), SUDO_RC_OK);
166
167
python_io->close(0, 0); // this should not call the python plugin close as there was no command run invocation
168
169
if (is_verbose) {
170
// Note: the exact python version is environment dependent
171
VERIFY_STR_CONTAINS(data.stdout_str, "Python interpreter version:");
172
*strstr(data.stdout_str, "Python interpreter version:") = '\0';
173
VERIFY_STDOUT(expected_path("check_example_io_plugin_version_display_full.stdout"));
174
} else {
175
VERIFY_STDOUT(expected_path("check_example_io_plugin_version_display.stdout"));
176
}
177
178
VERIFY_STDERR(expected_path("check_example_io_plugin_version_display.stderr"));
179
VERIFY_FILE("sudo.log", expected_path("check_example_io_plugin_version_display.stored"));
180
181
return true;
182
}
183
184
static int
185
check_example_io_plugin_command_log(void)
186
{
187
const char *errstr = NULL;
188
create_io_plugin_options(data.tmp_dir);
189
190
str_array_free(&data.plugin_argv);
191
data.plugin_argc = 2;
192
data.plugin_argv = create_str_array(3, "id", "--help", NULL);
193
194
str_array_free(&data.command_info);
195
data.command_info = create_str_array(3, "command=/bin/id", "runas_uid=0", NULL);
196
197
VERIFY_INT(python_io->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
198
data.user_info, data.command_info, data.plugin_argc, data.plugin_argv,
199
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
200
VERIFY_PTR(errstr, NULL);
201
VERIFY_INT(python_io->log_stdin("some standard input", strlen("some standard input"), &errstr), SUDO_RC_OK);
202
VERIFY_PTR(errstr, NULL);
203
VERIFY_INT(python_io->log_stdout("some standard output", strlen("some standard output"), &errstr), SUDO_RC_OK);
204
VERIFY_PTR(errstr, NULL);
205
VERIFY_INT(python_io->log_stderr("some standard error", strlen("some standard error"), &errstr), SUDO_RC_OK);
206
VERIFY_PTR(errstr, NULL);
207
VERIFY_INT(python_io->log_suspend(SIGTSTP, &errstr), SUDO_RC_OK);
208
VERIFY_PTR(errstr, NULL);
209
VERIFY_INT(python_io->log_suspend(SIGCONT, &errstr), SUDO_RC_OK);
210
VERIFY_PTR(errstr, NULL);
211
VERIFY_INT(python_io->change_winsize(200, 100, &errstr), SUDO_RC_OK);
212
VERIFY_PTR(errstr, NULL);
213
VERIFY_INT(python_io->log_ttyin("some tty input", strlen("some tty input"), &errstr), SUDO_RC_OK);
214
VERIFY_PTR(errstr, NULL);
215
VERIFY_INT(python_io->log_ttyout("some tty output", strlen("some tty output"), &errstr), SUDO_RC_OK);
216
VERIFY_PTR(errstr, NULL);
217
218
python_io->close(1, 0); // successful execution, command returned 1
219
220
VERIFY_STDOUT(expected_path("check_example_io_plugin_command_log.stdout"));
221
VERIFY_STDERR(expected_path("check_example_io_plugin_command_log.stderr"));
222
VERIFY_FILE("sudo.log", expected_path("check_example_io_plugin_command_log.stored"));
223
224
return true;
225
}
226
227
typedef struct io_plugin * (io_clone_func)(void);
228
229
static int
230
check_example_io_plugin_command_log_multiple(void)
231
{
232
const char *errstr = NULL;
233
234
// verify multiple python io plugin symbols are available
235
io_clone_func *python_io_clone = (io_clone_func *)sudo_dso_findsym(python_plugin_handle, "python_io_clone");
236
VERIFY_PTR_NE(python_io_clone, NULL);
237
238
struct io_plugin *python_io2 = NULL;
239
240
for (int i = 0; i < 7; ++i) {
241
python_io2 = (*python_io_clone)();
242
VERIFY_PTR_NE(python_io2, NULL);
243
VERIFY_PTR_NE(python_io2, python_io);
244
}
245
246
// open the first plugin and let it log to tmp_dir
247
create_io_plugin_options(data.tmp_dir);
248
249
str_array_free(&data.plugin_argv);
250
data.plugin_argc = 2;
251
data.plugin_argv = create_str_array(3, "id", "--help", NULL);
252
253
str_array_free(&data.command_info);
254
data.command_info = create_str_array(3, "command=/bin/id", "runas_uid=0", NULL);
255
256
VERIFY_INT(python_io->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
257
data.user_info, data.command_info, data.plugin_argc, data.plugin_argv,
258
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
259
VERIFY_PTR(errstr, NULL);
260
261
// For verifying the error message of no more plugin. It should be displayed only once.
262
VERIFY_PTR((*python_io_clone)(), NULL);
263
VERIFY_PTR((*python_io_clone)(), NULL);
264
265
// open the second plugin with another log directory
266
VERIFY_TRUE(asprintf(&data.tmp_dir2, TEMP_PATH_TEMPLATE) >= 0);
267
VERIFY_NOT_NULL(mkdtemp(data.tmp_dir2));
268
create_io_plugin_options(data.tmp_dir2);
269
270
str_array_free(&data.plugin_argv);
271
data.plugin_argc = 1;
272
data.plugin_argv = create_str_array(2, "whoami", NULL);
273
274
str_array_free(&data.command_info);
275
data.command_info = create_str_array(3, "command=/bin/whoami", "runas_uid=1", NULL);
276
277
VERIFY_INT(python_io2->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
278
data.user_info, data.command_info, data.plugin_argc, data.plugin_argv,
279
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
280
VERIFY_PTR(errstr, NULL);
281
282
VERIFY_INT(python_io->log_stdin("stdin for plugin 1", strlen("stdin for plugin 1"), &errstr), SUDO_RC_OK);
283
VERIFY_PTR(errstr, NULL);
284
VERIFY_INT(python_io2->log_stdin("stdin for plugin 2", strlen("stdin for plugin 2"), &errstr), SUDO_RC_OK);
285
VERIFY_PTR(errstr, NULL);
286
VERIFY_INT(python_io->log_stdout("stdout for plugin 1", strlen("stdout for plugin 1"), &errstr), SUDO_RC_OK);
287
VERIFY_PTR(errstr, NULL);
288
VERIFY_INT(python_io2->log_stdout("stdout for plugin 2", strlen("stdout for plugin 2"), &errstr), SUDO_RC_OK);
289
VERIFY_PTR(errstr, NULL);
290
VERIFY_INT(python_io->log_stderr("stderr for plugin 1", strlen("stderr for plugin 1"), &errstr), SUDO_RC_OK);
291
VERIFY_PTR(errstr, NULL);
292
VERIFY_INT(python_io2->log_stderr("stderr for plugin 2", strlen("stderr for plugin 2"), &errstr), SUDO_RC_OK);
293
VERIFY_PTR(errstr, NULL);
294
VERIFY_INT(python_io->log_suspend(SIGTSTP, &errstr), SUDO_RC_OK);
295
VERIFY_PTR(errstr, NULL);
296
VERIFY_INT(python_io2->log_suspend(SIGSTOP, &errstr), SUDO_RC_OK);
297
VERIFY_PTR(errstr, NULL);
298
VERIFY_INT(python_io->log_suspend(SIGCONT, &errstr), SUDO_RC_OK);
299
VERIFY_PTR(errstr, NULL);
300
VERIFY_INT(python_io2->log_suspend(SIGCONT, &errstr), SUDO_RC_OK);
301
VERIFY_PTR(errstr, NULL);
302
VERIFY_INT(python_io->change_winsize(20, 10, &errstr), SUDO_RC_OK);
303
VERIFY_PTR(errstr, NULL);
304
VERIFY_INT(python_io2->change_winsize(30, 40, &errstr), SUDO_RC_OK);
305
VERIFY_PTR(errstr, NULL);
306
VERIFY_INT(python_io->log_ttyin("tty input for plugin 1", strlen("tty input for plugin 1"), &errstr), SUDO_RC_OK);
307
VERIFY_PTR(errstr, NULL);
308
VERIFY_INT(python_io2->log_ttyin("tty input for plugin 2", strlen("tty input for plugin 2"), &errstr), SUDO_RC_OK);
309
VERIFY_PTR(errstr, NULL);
310
VERIFY_INT(python_io->log_ttyout("tty output for plugin 1", strlen("tty output for plugin 1"), &errstr), SUDO_RC_OK);
311
VERIFY_PTR(errstr, NULL);
312
VERIFY_INT(python_io2->log_ttyout("tty output for plugin 2", strlen("tty output for plugin 2"), &errstr), SUDO_RC_OK);
313
VERIFY_PTR(errstr, NULL);
314
315
python_io->close(1, 0); // successful execution, command returned 1
316
python_io2->close(2, 0); // command returned 2
317
318
VERIFY_STDOUT(expected_path("check_example_io_plugin_command_log_multiple.stdout"));
319
VERIFY_STDERR(expected_path("check_example_io_plugin_command_log_multiple.stderr"));
320
VERIFY_FILE("sudo.log", expected_path("check_example_io_plugin_command_log_multiple1.stored"));
321
VERIFY_TRUE(verify_file(data.tmp_dir2, "sudo.log", expected_path("check_example_io_plugin_command_log_multiple2.stored")));
322
323
return true;
324
}
325
326
static int
327
check_example_io_plugin_failed_to_start_command(void)
328
{
329
const char *errstr = NULL;
330
331
create_io_plugin_options(data.tmp_dir);
332
333
str_array_free(&data.plugin_argv);
334
data.plugin_argc = 1;
335
data.plugin_argv = create_str_array(2, "cmd", NULL);
336
337
str_array_free(&data.command_info);
338
data.command_info = create_str_array(3, "command=/usr/share/cmd", "runas_uid=0", NULL);
339
340
VERIFY_INT(python_io->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
341
data.user_info, data.command_info, data.plugin_argc, data.plugin_argv,
342
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
343
VERIFY_PTR(errstr, NULL);
344
345
python_io->close(0, EPERM); // execve returned with error
346
347
VERIFY_STDOUT(expected_path("check_example_io_plugin_failed_to_start_command.stdout"));
348
VERIFY_STDERR(expected_path("check_example_io_plugin_failed_to_start_command.stderr"));
349
VERIFY_FILE("sudo.log", expected_path("check_example_io_plugin_failed_to_start_command.stored"));
350
351
return true;
352
}
353
354
static int
355
check_example_io_plugin_fails_with_python_backtrace(void)
356
{
357
const char *errstr = NULL;
358
359
create_io_plugin_options("/some/not/writable/directory");
360
361
VERIFY_INT(python_io->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
362
data.user_info, data.command_info, data.plugin_argc, data.plugin_argv,
363
data.user_env, data.plugin_options, &errstr), SUDO_RC_ERROR);
364
VERIFY_PTR(errstr, NULL);
365
366
VERIFY_STDOUT(expected_path("check_example_io_plugin_fails_with_python_backtrace.stdout"));
367
VERIFY_STDERR(expected_path("check_example_io_plugin_fails_with_python_backtrace.stderr"));
368
369
python_io->close(0, 0);
370
return true;
371
}
372
373
static int
374
check_io_plugin_reports_error(void)
375
{
376
const char *errstr = NULL;
377
str_array_free(&data.plugin_options);
378
data.plugin_options = create_str_array(
379
3,
380
"ModulePath=" SRC_DIR "/regress/plugin_errorstr.py",
381
"ClassName=ConstructErrorPlugin",
382
NULL
383
);
384
385
VERIFY_INT(python_io->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
386
data.user_info, data.command_info, data.plugin_argc, data.plugin_argv,
387
data.user_env, data.plugin_options, &errstr), SUDO_RC_ERROR);
388
389
VERIFY_STR(errstr, "Something wrong in plugin constructor");
390
errstr = NULL;
391
392
python_io->close(0, 0);
393
394
str_array_free(&data.plugin_options);
395
data.plugin_options = create_str_array(
396
3,
397
"ModulePath=" SRC_DIR "/regress/plugin_errorstr.py",
398
"ClassName=ErrorMsgPlugin",
399
NULL
400
);
401
402
VERIFY_INT(python_io->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
403
data.user_info, data.command_info, data.plugin_argc, data.plugin_argv,
404
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
405
VERIFY_PTR(errstr, NULL);
406
407
VERIFY_INT(python_io->log_stdin("", 0, &errstr), SUDO_RC_ERROR);
408
VERIFY_STR(errstr, "Something wrong in log_stdin");
409
410
errstr = (void *)13;
411
VERIFY_INT(python_io->log_stdout("", 0, &errstr), SUDO_RC_ERROR);
412
VERIFY_STR(errstr, "Something wrong in log_stdout");
413
414
errstr = NULL;
415
VERIFY_INT(python_io->log_stderr("", 0, &errstr), SUDO_RC_ERROR);
416
VERIFY_STR(errstr, "Something wrong in log_stderr");
417
418
errstr = NULL;
419
VERIFY_INT(python_io->log_ttyin("", 0, &errstr), SUDO_RC_ERROR);
420
VERIFY_STR(errstr, "Something wrong in log_ttyin");
421
422
errstr = NULL;
423
VERIFY_INT(python_io->log_ttyout("", 0, &errstr), SUDO_RC_ERROR);
424
VERIFY_STR(errstr, "Something wrong in log_ttyout");
425
426
errstr = NULL;
427
VERIFY_INT(python_io->log_suspend(SIGTSTP, &errstr), SUDO_RC_ERROR);
428
VERIFY_STR(errstr, "Something wrong in log_suspend");
429
430
errstr = NULL;
431
VERIFY_INT(python_io->change_winsize(200, 100, &errstr), SUDO_RC_ERROR);
432
VERIFY_STR(errstr, "Something wrong in change_winsize");
433
434
python_io->close(0, 0);
435
436
VERIFY_STR(data.stderr_str, "");
437
VERIFY_STR(data.stdout_str, "");
438
return true;
439
}
440
441
static int
442
check_example_group_plugin(void)
443
{
444
create_plugin_options("example_group_plugin", "SudoGroupPlugin", NULL);
445
446
VERIFY_INT(group_plugin->init(GROUP_API_VERSION, fake_printf, data.plugin_options), SUDO_RC_OK);
447
448
VERIFY_INT(group_plugin->query("test", "mygroup", NULL), SUDO_RC_OK);
449
VERIFY_INT(group_plugin->query("testuser2", "testgroup", NULL), SUDO_RC_OK);
450
VERIFY_INT(group_plugin->query("testuser2", "mygroup", NULL), SUDO_RC_REJECT);
451
VERIFY_INT(group_plugin->query("test", "testgroup", NULL), SUDO_RC_REJECT);
452
453
group_plugin->cleanup();
454
VERIFY_STR(data.stderr_str, "");
455
VERIFY_STR(data.stdout_str, "");
456
return true;
457
}
458
459
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
460
static const char *
461
create_debug_config(const char *debug_spec)
462
{
463
char *result = NULL;
464
465
static char config_path[PATH_MAX] = "/";
466
snprintf(config_path, sizeof(config_path), "%s/sudo.conf", data.tmp_dir);
467
468
char *content = NULL;
469
if (asprintf(&content, "Debug %s %s/debug.log %s\n",
470
"python_plugin.so", data.tmp_dir, debug_spec) < 0)
471
{
472
puts("Failed to allocate string");
473
goto cleanup;
474
}
475
476
if (fwriteall(config_path, content) != true) {
477
printf("Failed to write '%s'\n", config_path);
478
goto cleanup;
479
}
480
481
result = config_path;
482
483
cleanup:
484
free(content);
485
486
return result;
487
}
488
489
static int
490
check_example_group_plugin_is_able_to_debug(void)
491
{
492
const char *config_path = create_debug_config("py_calls@diag");
493
VERIFY_NOT_NULL(config_path);
494
VERIFY_INT(sudo_conf_read(config_path, SUDO_CONF_ALL), true);
495
496
create_plugin_options("example_group_plugin", "SudoGroupPlugin", NULL);
497
498
group_plugin->init(GROUP_API_VERSION, fake_printf, data.plugin_options);
499
500
group_plugin->query("user", "group", &example_pwd);
501
502
group_plugin->cleanup();
503
504
VERIFY_STR(data.stderr_str, "");
505
VERIFY_STR(data.stdout_str, "");
506
507
VERIFY_LOG_LINES(expected_path("check_example_group_plugin_is_able_to_debug.log"));
508
509
return true;
510
}
511
#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
512
513
static int
514
check_plugin_unload(void)
515
{
516
// You can call this test to avoid having a lot of subinterpreters
517
// (each plugin->open starts one, and only plugin unlink closes)
518
// It only verifies that python was shut down correctly.
519
VERIFY_TRUE(Py_IsInitialized());
520
VERIFY_TRUE(_unlink_symbols());
521
VERIFY_FALSE(Py_IsInitialized()); // python interpreter could be stopped
522
return true;
523
}
524
525
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
526
static int
527
check_example_debugging(const char *debug_spec)
528
{
529
const char *errstr = NULL;
530
const char *config_path = create_debug_config(debug_spec);
531
VERIFY_NOT_NULL(config_path);
532
VERIFY_INT(sudo_conf_read(config_path, SUDO_CONF_ALL), true);
533
534
create_debugging_plugin_options();
535
536
str_array_free(&data.settings);
537
char *debug_flags_setting = NULL;
538
VERIFY_TRUE(asprintf(&debug_flags_setting, "debug_flags=%s/debug.log %s", data.tmp_dir, debug_spec) >= 0);
539
540
data.settings = create_str_array(3, debug_flags_setting, "plugin_path=python_plugin.so", NULL);
541
542
VERIFY_INT(python_io->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
543
data.user_info, data.command_info, data.plugin_argc, data.plugin_argv,
544
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
545
VERIFY_PTR(errstr, NULL);
546
python_io->close(0, 0);
547
548
VERIFY_STR(data.stderr_str, "");
549
VERIFY_STR(data.stdout_str, "");
550
551
VERIFY_LOG_LINES(expected_path("check_example_debugging_%s.log", debug_spec));
552
553
free(debug_flags_setting);
554
return true;
555
}
556
#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
557
558
static int
559
check_loading_fails(const char *name)
560
{
561
const char *errstr = NULL;
562
563
VERIFY_INT(python_io->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
564
data.user_info, data.command_info, data.plugin_argc, data.plugin_argv,
565
data.user_env, data.plugin_options, &errstr), SUDO_RC_ERROR);
566
VERIFY_PTR(errstr, NULL);
567
python_io->close(0, 0);
568
569
VERIFY_STDOUT(expected_path("check_loading_fails_%s.stdout", name));
570
VERIFY_STDERR(expected_path("check_loading_fails_%s.stderr", name));
571
572
return true;
573
}
574
575
static int
576
check_loading_fails_with_missing_path(void)
577
{
578
str_array_free(&data.plugin_options);
579
data.plugin_options = create_str_array(2, "ClassName=DebugDemoPlugin", NULL);
580
return check_loading_fails("missing_path");
581
}
582
583
static int
584
check_loading_succeeds_with_missing_classname(void)
585
{
586
str_array_free(&data.plugin_options);
587
data.plugin_options = create_str_array(2, "ModulePath=" SRC_DIR "/example_debugging.py", NULL);
588
589
const char *errstr = NULL;
590
591
VERIFY_INT(python_io->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
592
data.user_info, data.command_info, data.plugin_argc, data.plugin_argv,
593
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
594
VERIFY_PTR(errstr, NULL);
595
VERIFY_INT(python_io->show_version(1), SUDO_RC_OK);
596
python_io->close(0, 0);
597
598
VERIFY_STDOUT(expected_path("check_loading_succeeds_with_missing_classname.stdout"));
599
VERIFY_STR(data.stderr_str, "");
600
601
return true;
602
}
603
604
static int
605
check_loading_fails_with_missing_classname(void)
606
{
607
str_array_free(&data.plugin_options);
608
data.plugin_options = create_str_array(2, "ModulePath=" SRC_DIR "/regress/plugin_errorstr.py", NULL);
609
return check_loading_fails("missing_classname");
610
}
611
612
static int
613
check_loading_fails_with_wrong_classname(void)
614
{
615
create_plugin_options("example_debugging", "MispelledPluginName", NULL);
616
return check_loading_fails("wrong_classname");
617
}
618
619
static int
620
check_loading_fails_with_wrong_path(void)
621
{
622
str_array_free(&data.plugin_options);
623
data.plugin_options = create_str_array(3, "ModulePath=/wrong_path.py", "ClassName=PluginName", NULL);
624
return check_loading_fails("wrong_path");
625
}
626
627
static int
628
check_example_conversation_plugin_reason_log(int simulate_suspend, const char *description)
629
{
630
const char *errstr = NULL;
631
632
create_conversation_plugin_options();
633
634
str_array_free(&data.plugin_argv); // have a command run
635
data.plugin_argc = 1;
636
data.plugin_argv = create_str_array(2, "/bin/whoami", NULL);
637
638
data.conv_replies[0] = "my fake reason";
639
data.conv_replies[1] = "my real secret reason";
640
641
sudo_conv_t conversation = simulate_suspend ? fake_conversation_with_suspend : fake_conversation;
642
643
VERIFY_INT(python_io->open(SUDO_API_VERSION, conversation, fake_printf, data.settings,
644
data.user_info, data.command_info, data.plugin_argc, data.plugin_argv,
645
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
646
VERIFY_PTR(errstr, NULL);
647
python_io->close(0, 0);
648
649
VERIFY_STDOUT(expected_path("check_example_conversation_plugin_reason_log_%s.stdout", description));
650
VERIFY_STDERR(expected_path("check_example_conversation_plugin_reason_log_%s.stderr", description));
651
VERIFY_CONV(expected_path("check_example_conversation_plugin_reason_log_%s.conversation", description));
652
VERIFY_FILE("sudo_reasons.txt", expected_path("check_example_conversation_plugin_reason_log_%s.stored", description));
653
return true;
654
}
655
656
static int
657
check_example_conversation_plugin_user_interrupts(void)
658
{
659
const char *errstr = NULL;
660
661
create_conversation_plugin_options();
662
663
str_array_free(&data.plugin_argv); // have a command run
664
data.plugin_argc = 1;
665
data.plugin_argv = create_str_array(2, "/bin/whoami", NULL);
666
667
data.conv_replies[0] = NULL; // this simulates user interrupt for the first question
668
669
VERIFY_INT(python_io->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
670
data.user_info, data.command_info, data.plugin_argc, data.plugin_argv,
671
data.user_env, data.plugin_options, &errstr), SUDO_RC_REJECT);
672
python_io->close(0, 0);
673
674
VERIFY_STDOUT(expected_path("check_example_conversation_plugin_user_interrupts.stdout"));
675
VERIFY_STDERR(expected_path("check_example_conversation_plugin_user_interrupts.stderr"));
676
VERIFY_CONV(expected_path("check_example_conversation_plugin_user_interrupts.conversation"));
677
return true;
678
}
679
680
static int
681
check_example_policy_plugin_version_display(int is_verbose)
682
{
683
const char *errstr = NULL;
684
685
create_policy_plugin_options();
686
687
VERIFY_INT(python_policy->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
688
data.user_info, data.user_env, data.plugin_options, &errstr),
689
SUDO_RC_OK);
690
VERIFY_PTR(errstr, NULL);
691
VERIFY_INT(python_policy->show_version(is_verbose), SUDO_RC_OK);
692
693
python_policy->close(0, 0); // this should not call the python plugin close as there was no command run invocation
694
695
if (is_verbose) {
696
// Note: the exact python version is environment dependent
697
VERIFY_STR_CONTAINS(data.stdout_str, "Python interpreter version:");
698
*strstr(data.stdout_str, "Python interpreter version:") = '\0';
699
VERIFY_STDOUT(expected_path("check_example_policy_plugin_version_display_full.stdout"));
700
} else {
701
VERIFY_STDOUT(expected_path("check_example_policy_plugin_version_display.stdout"));
702
}
703
704
VERIFY_STDERR(expected_path("check_example_policy_plugin_version_display.stderr"));
705
706
return true;
707
}
708
709
static int
710
check_example_policy_plugin_accepted_execution(void)
711
{
712
const char *errstr = NULL;
713
714
create_policy_plugin_options();
715
716
str_array_free(&data.plugin_argv);
717
data.plugin_argc = 2;
718
data.plugin_argv = create_str_array(3, "/bin/whoami", "--help", NULL);
719
720
str_array_free(&data.user_env);
721
data.user_env = create_str_array(3, "USER_ENV1=VALUE1", "USER_ENV2=value2", NULL);
722
723
VERIFY_INT(python_policy->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
724
data.user_info, data.user_env, data.plugin_options, &errstr),
725
SUDO_RC_OK);
726
VERIFY_PTR(errstr, NULL);
727
728
char **env_add = create_str_array(3, "REQUESTED_ENV1=VALUE1", "REQUESTED_ENV2=value2", NULL);
729
730
char **argv_out, **user_env_out, **command_info_out; // free to contain garbage
731
732
VERIFY_INT(python_policy->check_policy(data.plugin_argc, data.plugin_argv, env_add,
733
&command_info_out, &argv_out, &user_env_out, &errstr),
734
SUDO_RC_ACCEPT);
735
VERIFY_PTR(errstr, NULL);
736
737
VERIFY_STR_SET(command_info_out, 4, "command=/bin/whoami", "runas_uid=0", "runas_gid=0", NULL);
738
VERIFY_STR_SET(user_env_out, 5, "USER_ENV1=VALUE1", "USER_ENV2=value2",
739
"REQUESTED_ENV1=VALUE1", "REQUESTED_ENV2=value2", NULL);
740
VERIFY_STR_SET(argv_out, 3, "/bin/whoami", "--help", NULL);
741
742
VERIFY_INT(python_policy->init_session(&example_pwd, &user_env_out, &errstr), SUDO_RC_ACCEPT);
743
VERIFY_PTR(errstr, NULL);
744
745
// init session is able to modify the user env:
746
VERIFY_STR_SET(user_env_out, 6, "USER_ENV1=VALUE1", "USER_ENV2=value2",
747
"REQUESTED_ENV1=VALUE1", "REQUESTED_ENV2=value2", "PLUGIN_EXAMPLE_ENV=1", NULL);
748
749
python_policy->close(3, 0); // successful execution returned exit code 3
750
751
VERIFY_STDOUT(expected_path("check_example_policy_plugin_accepted_execution.stdout"));
752
VERIFY_STDERR(expected_path("check_example_policy_plugin_accepted_execution.stderr"));
753
754
str_array_free(&env_add);
755
str_array_free(&user_env_out);
756
str_array_free(&command_info_out);
757
str_array_free(&argv_out);
758
return true;
759
}
760
761
static int
762
check_example_policy_plugin_failed_execution(void)
763
{
764
const char *errstr = NULL;
765
766
create_policy_plugin_options();
767
768
str_array_free(&data.plugin_argv);
769
data.plugin_argc = 2;
770
data.plugin_argv = create_str_array(3, "/bin/id", "--help", NULL);
771
772
VERIFY_INT(python_policy->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
773
data.user_info, data.user_env, data.plugin_options, &errstr),
774
SUDO_RC_OK);
775
VERIFY_PTR(errstr, NULL);
776
777
char **argv_out, **user_env_out, **command_info_out; // free to contain garbage
778
779
VERIFY_INT(python_policy->check_policy(data.plugin_argc, data.plugin_argv, NULL,
780
&command_info_out, &argv_out, &user_env_out, &errstr),
781
SUDO_RC_ACCEPT);
782
VERIFY_PTR(errstr, NULL);
783
784
// pwd is unset (user is not part of /etc/passwd)
785
VERIFY_INT(python_policy->init_session(NULL, &user_env_out, &errstr), SUDO_RC_ACCEPT);
786
VERIFY_PTR(errstr, NULL);
787
788
python_policy->close(12345, ENOENT); // failed to execute
789
790
VERIFY_STDOUT(expected_path("check_example_policy_plugin_failed_execution.stdout"));
791
VERIFY_STDERR(expected_path("check_example_policy_plugin_failed_execution.stderr"));
792
793
str_array_free(&user_env_out);
794
str_array_free(&command_info_out);
795
str_array_free(&argv_out);
796
return true;
797
}
798
799
static int
800
check_example_policy_plugin_denied_execution(void)
801
{
802
const char *errstr = NULL;
803
804
create_policy_plugin_options();
805
806
str_array_free(&data.plugin_argv);
807
data.plugin_argc = 1;
808
data.plugin_argv = create_str_array(2, "/bin/passwd", NULL);
809
810
VERIFY_INT(python_policy->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
811
data.user_info, data.user_env, data.plugin_options, &errstr),
812
SUDO_RC_OK);
813
VERIFY_PTR(errstr, NULL);
814
815
char **argv_out, **user_env_out, **command_info_out; // free to contain garbage
816
817
VERIFY_INT(python_policy->check_policy(data.plugin_argc, data.plugin_argv, NULL,
818
&command_info_out, &argv_out, &user_env_out, &errstr),
819
SUDO_RC_REJECT);
820
821
VERIFY_PTR(command_info_out, NULL);
822
VERIFY_PTR(argv_out, NULL);
823
VERIFY_PTR(user_env_out, NULL);
824
825
python_policy->close(0, 0); // there was no execution
826
827
VERIFY_STDOUT(expected_path("check_example_policy_plugin_denied_execution.stdout"));
828
VERIFY_STDERR(expected_path("check_example_policy_plugin_denied_execution.stderr"));
829
830
return true;
831
}
832
833
static int
834
check_example_policy_plugin_list(void)
835
{
836
const char *errstr = NULL;
837
838
create_policy_plugin_options();
839
840
VERIFY_INT(python_policy->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
841
data.user_info, data.user_env, data.plugin_options, &errstr),
842
SUDO_RC_OK);
843
VERIFY_PTR(errstr, NULL);
844
845
snprintf_append(data.stdout_str, MAX_OUTPUT, "-- minimal --\n");
846
VERIFY_INT(python_policy->list(data.plugin_argc, data.plugin_argv, false, NULL, &errstr), SUDO_RC_OK);
847
VERIFY_PTR(errstr, NULL);
848
849
snprintf_append(data.stdout_str, MAX_OUTPUT, "\n-- minimal (verbose) --\n");
850
VERIFY_INT(python_policy->list(data.plugin_argc, data.plugin_argv, true, NULL, &errstr), SUDO_RC_OK);
851
VERIFY_PTR(errstr, NULL);
852
853
snprintf_append(data.stdout_str, MAX_OUTPUT, "\n-- with user --\n");
854
VERIFY_INT(python_policy->list(data.plugin_argc, data.plugin_argv, false, "testuser", &errstr), SUDO_RC_OK);
855
VERIFY_PTR(errstr, NULL);
856
857
snprintf_append(data.stdout_str, MAX_OUTPUT, "\n-- with user (verbose) --\n");
858
VERIFY_INT(python_policy->list(data.plugin_argc, data.plugin_argv, true, "testuser", &errstr), SUDO_RC_OK);
859
VERIFY_PTR(errstr, NULL);
860
861
snprintf_append(data.stdout_str, MAX_OUTPUT, "\n-- with allowed program --\n");
862
str_array_free(&data.plugin_argv);
863
data.plugin_argc = 3;
864
data.plugin_argv = create_str_array(4, "/bin/id", "some", "arguments", NULL);
865
VERIFY_INT(python_policy->list(data.plugin_argc, data.plugin_argv, false, NULL, &errstr), SUDO_RC_OK);
866
VERIFY_PTR(errstr, NULL);
867
868
snprintf_append(data.stdout_str, MAX_OUTPUT, "\n-- with allowed program (verbose) --\n");
869
VERIFY_INT(python_policy->list(data.plugin_argc, data.plugin_argv, true, NULL, &errstr), SUDO_RC_OK);
870
VERIFY_PTR(errstr, NULL);
871
872
snprintf_append(data.stdout_str, MAX_OUTPUT, "\n-- with denied program --\n");
873
str_array_free(&data.plugin_argv);
874
data.plugin_argc = 1;
875
data.plugin_argv = create_str_array(2, "/bin/passwd", NULL);
876
VERIFY_INT(python_policy->list(data.plugin_argc, data.plugin_argv, false, NULL, &errstr), SUDO_RC_OK);
877
VERIFY_PTR(errstr, NULL);
878
879
snprintf_append(data.stdout_str, MAX_OUTPUT, "\n-- with denied program (verbose) --\n");
880
VERIFY_INT(python_policy->list(data.plugin_argc, data.plugin_argv, true, NULL, &errstr), SUDO_RC_OK);
881
VERIFY_PTR(errstr, NULL);
882
883
python_policy->close(0, 0); // there was no execution
884
885
VERIFY_STDOUT(expected_path("check_example_policy_plugin_list.stdout"));
886
VERIFY_STDERR(expected_path("check_example_policy_plugin_list.stderr"));
887
888
return true;
889
}
890
891
static int
892
check_example_policy_plugin_validate_invalidate(void)
893
{
894
const char *errstr = NULL;
895
896
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
897
// the plugin does not do any meaningful for these, so using log to validate instead
898
const char *config_path = create_debug_config("py_calls@diag");
899
VERIFY_NOT_NULL(config_path);
900
VERIFY_INT(sudo_conf_read(config_path, SUDO_CONF_ALL), true);
901
#endif
902
903
create_policy_plugin_options();
904
905
VERIFY_INT(python_policy->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
906
data.user_info, data.user_env, data.plugin_options, &errstr),
907
SUDO_RC_OK);
908
VERIFY_PTR(errstr, NULL);
909
910
VERIFY_INT(python_policy->validate(&errstr), SUDO_RC_OK);
911
VERIFY_PTR(errstr, NULL);
912
913
python_policy->invalidate(true);
914
python_policy->invalidate(false);
915
916
python_policy->close(0, 0); // no command execution
917
918
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
919
VERIFY_LOG_LINES(expected_path("check_example_policy_plugin_validate_invalidate.log"));
920
#endif
921
VERIFY_STR(data.stderr_str, "");
922
VERIFY_STR(data.stdout_str, "");
923
return true;
924
}
925
926
static int
927
check_policy_plugin_callbacks_are_optional(void)
928
{
929
const char *errstr = NULL;
930
931
create_debugging_plugin_options();
932
933
VERIFY_INT(python_policy->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
934
data.user_info, data.user_env, data.plugin_options, &errstr),
935
SUDO_RC_OK);
936
VERIFY_PTR(errstr, NULL);
937
938
VERIFY_PTR(python_policy->list, NULL);
939
VERIFY_PTR(python_policy->validate, NULL);
940
VERIFY_PTR(python_policy->invalidate, NULL);
941
VERIFY_PTR_NE(python_policy->check_policy, NULL); // (not optional)
942
VERIFY_PTR(python_policy->init_session, NULL);
943
944
// show_version always displays the plugin, but it is optional in the python layer
945
VERIFY_PTR_NE(python_policy->show_version, NULL);
946
VERIFY_INT(python_policy->show_version(1), SUDO_RC_OK);
947
948
python_policy->close(0, 0);
949
return true;
950
}
951
952
static int
953
check_policy_plugin_reports_error(void)
954
{
955
const char *errstr = NULL;
956
str_array_free(&data.plugin_options);
957
data.plugin_options = create_str_array(
958
3,
959
"ModulePath=" SRC_DIR "/regress/plugin_errorstr.py",
960
"ClassName=ConstructErrorPlugin",
961
NULL
962
);
963
964
VERIFY_INT(python_policy->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
965
data.user_info, data.user_env, data.plugin_options, &errstr), SUDO_RC_ERROR);
966
VERIFY_STR(errstr, "Something wrong in plugin constructor");
967
errstr = NULL;
968
969
python_policy->close(0, 0);
970
971
str_array_free(&data.plugin_options);
972
data.plugin_options = create_str_array(
973
3,
974
"ModulePath=" SRC_DIR "/regress/plugin_errorstr.py",
975
"ClassName=ErrorMsgPlugin",
976
NULL
977
);
978
979
data.plugin_argc = 1;
980
str_array_free(&data.plugin_argv);
981
data.plugin_argv = create_str_array(2, "id", NULL);
982
983
VERIFY_INT(python_policy->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
984
data.user_info, data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
985
VERIFY_PTR(errstr, NULL);
986
987
char **command_info_out = NULL;
988
char **argv_out = NULL;
989
char **user_env_out = NULL;
990
991
VERIFY_INT(python_policy->list(data.plugin_argc, data.plugin_argv, true, NULL, &errstr), SUDO_RC_ERROR);
992
VERIFY_STR(errstr, "Something wrong in list");
993
994
errstr = NULL;
995
VERIFY_INT(python_policy->validate(&errstr), SUDO_RC_ERROR);
996
VERIFY_STR(errstr, "Something wrong in validate");
997
998
errstr = NULL;
999
VERIFY_INT(python_policy->check_policy(data.plugin_argc, data.plugin_argv, data.user_env,
1000
&command_info_out, &argv_out, &user_env_out, &errstr),
1001
SUDO_RC_ERROR);
1002
VERIFY_STR(errstr, "Something wrong in check_policy");
1003
1004
errstr = NULL;
1005
VERIFY_INT(python_policy->init_session(&example_pwd, &user_env_out, &errstr), SUDO_RC_ERROR);
1006
VERIFY_STR(errstr, "Something wrong in init_session");
1007
1008
python_policy->close(0, 0);
1009
1010
VERIFY_STR(data.stderr_str, "");
1011
VERIFY_STR(data.stdout_str, "");
1012
return true;
1013
}
1014
1015
static int
1016
check_io_plugin_callbacks_are_optional(void)
1017
{
1018
const char *errstr = NULL;
1019
1020
create_debugging_plugin_options();
1021
1022
VERIFY_INT(python_io->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
1023
data.user_info, data.command_info, data.plugin_argc, data.plugin_argv,
1024
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
1025
VERIFY_PTR(errstr, NULL);
1026
1027
VERIFY_PTR(python_io->log_stdin, NULL);
1028
VERIFY_PTR(python_io->log_stdout, NULL);
1029
VERIFY_PTR(python_io->log_stderr, NULL);
1030
VERIFY_PTR(python_io->log_ttyin, NULL);
1031
VERIFY_PTR(python_io->log_ttyout, NULL);
1032
VERIFY_PTR(python_io->change_winsize, NULL);
1033
1034
// show_version always displays the plugin, but it is optional in the python layer
1035
VERIFY_PTR_NE(python_io->show_version, NULL);
1036
VERIFY_INT(python_io->show_version(1), SUDO_RC_OK);
1037
1038
python_io->close(0, 0);
1039
return true;
1040
}
1041
1042
static int
1043
check_python_plugins_do_not_affect_each_other(void)
1044
{
1045
const char *errstr = NULL;
1046
1047
// We test here that one plugin is not able to effect the environment of another
1048
// This is important so they do not ruin or depend on each other's state.
1049
create_plugin_options("regress/plugin_conflict", "ConflictPlugin", "Path=path_for_first_plugin");
1050
1051
VERIFY_INT(python_io->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
1052
data.user_info, data.command_info, data.plugin_argc, data.plugin_argv,
1053
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
1054
VERIFY_PTR(errstr, NULL);
1055
1056
create_plugin_options("regress/plugin_conflict", "ConflictPlugin", "Path=path_for_second_plugin");
1057
VERIFY_INT(python_policy->open(SUDO_API_VERSION, fake_conversation, fake_printf, data.settings,
1058
data.user_info, data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
1059
VERIFY_PTR(errstr, NULL);
1060
1061
python_io->close(0, 0);
1062
python_policy->close(0, 0);
1063
1064
VERIFY_STDOUT(expected_path("check_python_plugins_do_not_affect_each_other.stdout"));
1065
VERIFY_STR(data.stderr_str, "");
1066
return true;
1067
}
1068
1069
static int
1070
check_example_audit_plugin_receives_accept(void)
1071
{
1072
create_audit_plugin_options("");
1073
const char *errstr = NULL;
1074
1075
str_array_free(&data.plugin_argv);
1076
data.plugin_argv = create_str_array(6, "sudo", "-u", "user", "id", "--help", NULL);
1077
1078
str_array_free(&data.user_env);
1079
data.user_env = create_str_array(3, "KEY1=VALUE1", "KEY2=VALUE2", NULL);
1080
1081
str_array_free(&data.user_info);
1082
data.user_info = create_str_array(3, "user=testuser1", "uid=123", NULL);
1083
1084
VERIFY_INT(python_audit->open(SUDO_API_VERSION, fake_conversation, fake_printf,
1085
data.settings, data.user_info, 3, data.plugin_argv,
1086
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
1087
VERIFY_PTR(errstr, NULL);
1088
1089
str_array_free(&data.command_info);
1090
data.command_info = create_str_array(2, "command=/sbin/id", NULL);
1091
1092
str_array_free(&data.plugin_argv);
1093
data.plugin_argv = create_str_array(3, "id", "--help", NULL);
1094
1095
VERIFY_INT(python_audit->accept("accepter plugin name", SUDO_POLICY_PLUGIN,
1096
data.command_info, data.plugin_argv,
1097
data.user_env, &errstr), SUDO_RC_OK);
1098
VERIFY_PTR(errstr, NULL);
1099
1100
python_audit->close(SUDO_PLUGIN_WAIT_STATUS, W_EXITCODE(2, 0)); // process exited with 2
1101
1102
VERIFY_STDOUT(expected_path("check_example_audit_plugin_receives_accept.stdout"));
1103
VERIFY_STR(data.stderr_str, "");
1104
1105
return true;
1106
}
1107
1108
static int
1109
check_example_audit_plugin_receives_reject(void)
1110
{
1111
create_audit_plugin_options(NULL);
1112
const char *errstr = NULL;
1113
1114
str_array_free(&data.plugin_argv);
1115
data.plugin_argv = create_str_array(3, "sudo", "passwd", NULL);
1116
1117
str_array_free(&data.user_info);
1118
data.user_info = create_str_array(3, "user=root", "uid=0", NULL);
1119
1120
VERIFY_INT(python_audit->open(SUDO_API_VERSION, fake_conversation, fake_printf,
1121
data.settings, data.user_info, 1, data.plugin_argv,
1122
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
1123
VERIFY_PTR(errstr, NULL);
1124
1125
VERIFY_INT(python_audit->reject("rejecter plugin name", SUDO_IO_PLUGIN,
1126
"Rejected just because!", data.command_info,
1127
&errstr), SUDO_RC_OK);
1128
VERIFY_PTR(errstr, NULL);
1129
1130
python_audit->close(SUDO_PLUGIN_NO_STATUS, 0); // program was not run
1131
1132
VERIFY_STDOUT(expected_path("check_example_audit_plugin_receives_reject.stdout"));
1133
VERIFY_STR(data.stderr_str, "");
1134
1135
return true;
1136
}
1137
1138
static int
1139
check_example_audit_plugin_receives_error(void)
1140
{
1141
create_audit_plugin_options("");
1142
const char *errstr = NULL;
1143
1144
str_array_free(&data.plugin_argv);
1145
data.plugin_argv = create_str_array(5, "sudo", "-u", "user", "id", NULL);
1146
1147
VERIFY_INT(python_audit->open(SUDO_API_VERSION, fake_conversation, fake_printf,
1148
data.settings, data.user_info, 3, data.plugin_argv,
1149
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
1150
VERIFY_PTR(errstr, NULL);
1151
1152
str_array_free(&data.command_info);
1153
data.command_info = create_str_array(2, "command=/sbin/id", NULL);
1154
1155
VERIFY_INT(python_audit->error("errorer plugin name", SUDO_AUDIT_PLUGIN,
1156
"Some error has happened", data.command_info,
1157
&errstr), SUDO_RC_OK);
1158
VERIFY_PTR(errstr, NULL);
1159
1160
python_audit->close(SUDO_PLUGIN_SUDO_ERROR, 222);
1161
1162
VERIFY_STDOUT(expected_path("check_example_audit_plugin_receives_error.stdout"));
1163
VERIFY_STR(data.stderr_str, "");
1164
1165
return true;
1166
}
1167
1168
typedef struct audit_plugin * (audit_clone_func)(void);
1169
1170
static int
1171
check_example_audit_plugin_workflow_multiple(void)
1172
{
1173
// verify multiple python audit plugins are available
1174
audit_clone_func *python_audit_clone = (audit_clone_func *)sudo_dso_findsym(
1175
python_plugin_handle, "python_audit_clone");
1176
VERIFY_PTR_NE(python_audit_clone, NULL);
1177
1178
struct audit_plugin *python_audit2 = NULL;
1179
1180
for (int i = 0; i < 7; ++i) {
1181
python_audit2 = (*python_audit_clone)();
1182
VERIFY_PTR_NE(python_audit2, NULL);
1183
VERIFY_PTR_NE(python_audit2, python_audit);
1184
}
1185
1186
const char *errstr = NULL;
1187
1188
str_array_free(&data.plugin_argv);
1189
data.plugin_argv = create_str_array(6, "sudo", "-u", "user", "id", "--help", NULL);
1190
1191
str_array_free(&data.user_env);
1192
data.user_env = create_str_array(3, "KEY1=VALUE1", "KEY2=VALUE2", NULL);
1193
1194
str_array_free(&data.user_info);
1195
data.user_info = create_str_array(3, "user=default", "uid=1000", NULL);
1196
1197
create_audit_plugin_options("Id=1");
1198
VERIFY_INT(python_audit->open(SUDO_API_VERSION, fake_conversation, fake_printf,
1199
data.settings, data.user_info, 3, data.plugin_argv,
1200
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
1201
VERIFY_PTR(errstr, NULL);
1202
1203
// For verifying the error message of no more plugin. It should be displayed only once.
1204
VERIFY_PTR((*python_audit_clone)(), NULL);
1205
VERIFY_PTR((*python_audit_clone)(), NULL);
1206
1207
create_audit_plugin_options("Id=2");
1208
VERIFY_INT(python_audit2->open(SUDO_API_VERSION, fake_conversation, fake_printf,
1209
data.settings, data.user_info, 3, data.plugin_argv,
1210
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
1211
VERIFY_PTR(errstr, NULL);
1212
1213
str_array_free(&data.command_info);
1214
data.command_info = create_str_array(2, "command=/sbin/id", NULL);
1215
1216
str_array_free(&data.plugin_argv);
1217
data.plugin_argv = create_str_array(3, "id", "--help", NULL);
1218
1219
VERIFY_INT(python_audit->accept("accepter plugin name", SUDO_POLICY_PLUGIN,
1220
data.command_info, data.plugin_argv,
1221
data.user_env, &errstr), SUDO_RC_OK);
1222
VERIFY_PTR(errstr, NULL);
1223
1224
VERIFY_INT(python_audit2->accept("accepter plugin name", SUDO_POLICY_PLUGIN,
1225
data.command_info, data.plugin_argv,
1226
data.user_env, &errstr), SUDO_RC_OK);
1227
VERIFY_PTR(errstr, NULL);
1228
1229
python_audit->close(SUDO_PLUGIN_WAIT_STATUS, W_EXITCODE(0, 11)); // process got signal 11
1230
python_audit2->close(SUDO_PLUGIN_WAIT_STATUS, W_EXITCODE(0, 11));
1231
1232
VERIFY_STDOUT(expected_path("check_example_audit_plugin_workflow_multiple.stdout"));
1233
VERIFY_STDERR(expected_path("check_example_audit_plugin_workflow_multiple.stderr"));
1234
1235
return true;
1236
}
1237
1238
static int
1239
check_example_audit_plugin_version_display(void)
1240
{
1241
create_audit_plugin_options(NULL);
1242
const char *errstr = NULL;
1243
1244
str_array_free(&data.user_info);
1245
data.user_info = create_str_array(3, "user=root", "uid=0", NULL);
1246
1247
str_array_free(&data.plugin_argv);
1248
data.plugin_argv = create_str_array(3, "sudo", "-V", NULL);
1249
1250
VERIFY_INT(python_audit->open(SUDO_API_VERSION, fake_conversation, fake_printf,
1251
data.settings, data.user_info, 2, data.plugin_argv,
1252
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
1253
VERIFY_PTR(errstr, NULL);
1254
1255
VERIFY_INT(python_audit->show_version(false), SUDO_RC_OK);
1256
VERIFY_INT(python_audit->show_version(true), SUDO_RC_OK);
1257
1258
python_audit->close(SUDO_PLUGIN_SUDO_ERROR, 222);
1259
1260
VERIFY_STDOUT(expected_path("check_example_audit_plugin_version_display.stdout"));
1261
VERIFY_STR(data.stderr_str, "");
1262
1263
return true;
1264
}
1265
1266
static int
1267
check_audit_plugin_callbacks_are_optional(void)
1268
{
1269
const char *errstr = NULL;
1270
1271
create_debugging_plugin_options();
1272
1273
VERIFY_INT(python_audit->open(SUDO_API_VERSION, fake_conversation, fake_printf,
1274
data.settings, data.user_info, 2, data.plugin_argv,
1275
data.user_env, data.plugin_options, &errstr),
1276
SUDO_RC_OK);
1277
VERIFY_PTR(errstr, NULL);
1278
1279
VERIFY_PTR(python_audit->accept, NULL);
1280
VERIFY_PTR(python_audit->reject, NULL);
1281
VERIFY_PTR(python_audit->error, NULL);
1282
1283
// show_version always displays the plugin, but it is optional in the python layer
1284
VERIFY_PTR_NE(python_audit->show_version, NULL);
1285
VERIFY_INT(python_audit->show_version(1), SUDO_RC_OK);
1286
1287
python_audit->close(SUDO_PLUGIN_NO_STATUS, 0);
1288
return true;
1289
}
1290
1291
static int
1292
check_audit_plugin_reports_error(void)
1293
{
1294
const char *errstr = NULL;
1295
create_plugin_options("regress/plugin_errorstr", "ConstructErrorPlugin", NULL);
1296
1297
VERIFY_INT(python_audit->open(SUDO_API_VERSION, fake_conversation, fake_printf,
1298
data.settings, data.user_info, 0, data.plugin_argv,
1299
data.user_env, data.plugin_options, &errstr), SUDO_RC_ERROR);
1300
1301
VERIFY_STR(errstr, "Something wrong in plugin constructor");
1302
errstr = NULL;
1303
1304
python_audit->close(SUDO_PLUGIN_NO_STATUS, 0);
1305
1306
create_plugin_options("regress/plugin_errorstr", "ErrorMsgPlugin", NULL);
1307
1308
VERIFY_INT(python_audit->open(SUDO_API_VERSION, fake_conversation, fake_printf,
1309
data.settings, data.user_info, 0, data.plugin_argv,
1310
data.user_env, data.plugin_options, &errstr), SUDO_RC_ERROR);
1311
VERIFY_STR(errstr, "Something wrong in open");
1312
1313
errstr = NULL;
1314
VERIFY_INT(python_audit->accept("plugin name", SUDO_POLICY_PLUGIN,
1315
data.command_info, data.plugin_argv,
1316
data.user_env, &errstr), SUDO_RC_ERROR);
1317
VERIFY_STR(errstr, "Something wrong in accept");
1318
1319
errstr = NULL;
1320
VERIFY_INT(python_audit->reject("plugin name", SUDO_POLICY_PLUGIN,
1321
"audit message", data.command_info,
1322
&errstr), SUDO_RC_ERROR);
1323
VERIFY_STR(errstr, "Something wrong in reject");
1324
1325
errstr = NULL;
1326
VERIFY_INT(python_audit->error("plugin name", SUDO_POLICY_PLUGIN,
1327
"audit message", data.command_info,
1328
&errstr), SUDO_RC_ERROR);
1329
VERIFY_STR(errstr, "Something wrong in error");
1330
1331
python_audit->close(SUDO_PLUGIN_NO_STATUS, 0);
1332
1333
VERIFY_STR(data.stderr_str, "");
1334
VERIFY_STR(data.stdout_str, "");
1335
return true;
1336
}
1337
1338
static int
1339
check_example_approval_plugin(const char *date_str, const char *expected_error)
1340
{
1341
const char *errstr = NULL;
1342
1343
create_plugin_options("example_approval_plugin", "BusinessHoursApprovalPlugin", NULL);
1344
1345
VERIFY_INT(python_approval->open(SUDO_API_VERSION, fake_conversation, fake_printf,
1346
data.settings, data.user_info, 0, data.plugin_argv,
1347
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
1348
1349
VERIFY_TRUE(mock_python_datetime_now("example_approval_plugin", date_str));
1350
1351
int expected_rc = (expected_error == NULL) ? SUDO_RC_ACCEPT : SUDO_RC_REJECT;
1352
1353
VERIFY_INT(python_approval->check(data.command_info, data.plugin_argv, data.user_env, &errstr),
1354
expected_rc);
1355
1356
if (expected_error == NULL) {
1357
VERIFY_PTR(errstr, NULL);
1358
VERIFY_STR(data.stdout_str, "");
1359
} else {
1360
VERIFY_STR(errstr, expected_error);
1361
VERIFY_STR_CONTAINS(data.stdout_str, expected_error); // (ends with \n)
1362
}
1363
VERIFY_STR(data.stderr_str, "");
1364
1365
python_approval->close();
1366
1367
return true;
1368
}
1369
1370
typedef struct approval_plugin * (approval_clone_func)(void);
1371
1372
static int
1373
check_multiple_approval_plugin_and_arguments(void)
1374
{
1375
// verify multiple python approval plugins are available
1376
approval_clone_func *python_approval_clone = (approval_clone_func *)sudo_dso_findsym(
1377
python_plugin_handle, "python_approval_clone");
1378
VERIFY_PTR_NE(python_approval_clone, NULL);
1379
1380
struct approval_plugin *python_approval2 = NULL;
1381
1382
for (int i = 0; i < 7; ++i) {
1383
python_approval2 = (*python_approval_clone)();
1384
VERIFY_PTR_NE(python_approval2, NULL);
1385
VERIFY_PTR_NE(python_approval2, python_approval);
1386
}
1387
1388
const char *errstr = NULL;
1389
create_plugin_options("regress/plugin_approval_test", "ApprovalTestPlugin", "Id=1");
1390
1391
str_array_free(&data.plugin_argv);
1392
data.plugin_argv = create_str_array(6, "sudo", "-u", "user", "whoami", "--help", NULL);
1393
1394
str_array_free(&data.user_env);
1395
data.user_env = create_str_array(3, "USER_ENV1=VALUE1", "USER_ENV2=value2", NULL);
1396
1397
str_array_free(&data.user_info);
1398
data.user_info = create_str_array(3, "INFO1=VALUE1", "info2=value2", NULL);
1399
1400
str_array_free(&data.settings);
1401
data.settings = create_str_array(3, "SETTING1=VALUE1", "setting2=value2", NULL);
1402
1403
VERIFY_INT(python_approval->open(SUDO_API_VERSION, fake_conversation, fake_printf,
1404
data.settings, data.user_info, 3, data.plugin_argv,
1405
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
1406
VERIFY_PTR(errstr, NULL);
1407
1408
// For verifying the error message of no more plugin. It should be displayed only once.
1409
VERIFY_PTR((*python_approval_clone)(), NULL);
1410
VERIFY_PTR((*python_approval_clone)(), NULL);
1411
1412
create_plugin_options("regress/plugin_approval_test", "ApprovalTestPlugin", "Id=2");
1413
VERIFY_INT(python_approval2->open(SUDO_API_VERSION, fake_conversation, fake_printf,
1414
data.settings, data.user_info, 3, data.plugin_argv,
1415
data.user_env, data.plugin_options, &errstr), SUDO_RC_OK);
1416
VERIFY_PTR(errstr, NULL);
1417
1418
VERIFY_INT(python_approval->show_version(false), SUDO_RC_OK);
1419
VERIFY_INT(python_approval2->show_version(true), SUDO_RC_OK);
1420
1421
str_array_free(&data.command_info);
1422
data.command_info = create_str_array(3, "CMDINFO1=value1", "CMDINFO2=VALUE2", NULL);
1423
1424
str_array_free(&data.plugin_argv);
1425
data.plugin_argv = create_str_array(3, "whoami", "--help", NULL);
1426
1427
VERIFY_INT(python_approval->check(data.command_info, data.plugin_argv, data.user_env, &errstr),
1428
SUDO_RC_OK);
1429
VERIFY_PTR(errstr, NULL);
1430
1431
VERIFY_INT(python_approval2->check(data.command_info, data.plugin_argv, data.user_env, &errstr),
1432
SUDO_RC_OK);
1433
VERIFY_PTR(errstr, NULL);
1434
1435
python_approval->close();
1436
python_approval2->close();
1437
1438
VERIFY_STDOUT(expected_path("check_multiple_approval_plugin_and_arguments.stdout"));
1439
VERIFY_STDERR(expected_path("check_multiple_approval_plugin_and_arguments.stderr"));
1440
1441
return true;
1442
}
1443
1444
1445
static int
1446
_init_symbols(void)
1447
{
1448
if (python_plugin_handle != NULL) {
1449
// symbols are already loaded, we just restore
1450
RESTORE_PYTHON_PLUGIN(python_io);
1451
RESTORE_PYTHON_PLUGIN(python_policy);
1452
RESTORE_PYTHON_PLUGIN(python_approval);
1453
RESTORE_PYTHON_PLUGIN(python_audit);
1454
RESTORE_PYTHON_PLUGIN(group_plugin);
1455
return true;
1456
}
1457
1458
// we load the symbols
1459
python_plugin_handle = sudo_dso_load(python_plugin_so_path, SUDO_DSO_LAZY|SUDO_DSO_GLOBAL);
1460
VERIFY_PTR_NE(python_plugin_handle, NULL);
1461
1462
python_io = sudo_dso_findsym(python_plugin_handle, "python_io");
1463
VERIFY_PTR_NE(python_io, NULL);
1464
1465
group_plugin = sudo_dso_findsym(python_plugin_handle, "group_plugin");
1466
VERIFY_PTR_NE(group_plugin, NULL);
1467
1468
python_policy = sudo_dso_findsym(python_plugin_handle, "python_policy");
1469
VERIFY_PTR_NE(python_policy, NULL);
1470
1471
python_audit = sudo_dso_findsym(python_plugin_handle, "python_audit");
1472
VERIFY_PTR_NE(python_audit, NULL);
1473
1474
python_approval = sudo_dso_findsym(python_plugin_handle, "python_approval");
1475
VERIFY_PTR_NE(python_approval, NULL);
1476
1477
SAVE_PYTHON_PLUGIN(python_io);
1478
SAVE_PYTHON_PLUGIN(python_policy);
1479
SAVE_PYTHON_PLUGIN(python_approval);
1480
SAVE_PYTHON_PLUGIN(python_audit);
1481
SAVE_PYTHON_PLUGIN(group_plugin);
1482
1483
return true;
1484
}
1485
1486
static int
1487
_unlink_symbols(void)
1488
{
1489
python_io = NULL;
1490
group_plugin = NULL;
1491
python_policy = NULL;
1492
python_approval = NULL;
1493
python_audit = NULL;
1494
VERIFY_INT(sudo_dso_unload(python_plugin_handle), 0);
1495
python_plugin_handle = NULL;
1496
VERIFY_FALSE(Py_IsInitialized());
1497
return true;
1498
}
1499
1500
int
1501
main(int argc, char *argv[])
1502
{
1503
int ch, errors = 0, ntests = 0;
1504
1505
while ((ch = getopt(argc, argv, "v")) != -1) {
1506
switch (ch) {
1507
case 'v':
1508
verbose = true;
1509
break;
1510
default:
1511
fprintf(stderr, "usage: %s [-v]\n", getprogname());
1512
return EXIT_FAILURE;
1513
}
1514
}
1515
argc -= optind;
1516
argv += optind;
1517
1518
if (argc != 1) {
1519
printf("Please specify the python_plugin.so as argument!\n");
1520
return EXIT_FAILURE;
1521
}
1522
python_plugin_so_path = argv[0];
1523
1524
// Unbuffer stdout so we don't miss output during a crash.
1525
setvbuf(stdout, NULL, _IONBF, 0);
1526
1527
RUN_TEST(check_example_io_plugin_version_display(true));
1528
RUN_TEST(check_example_io_plugin_version_display(false));
1529
RUN_TEST(check_example_io_plugin_command_log());
1530
RUN_TEST(check_example_io_plugin_command_log_multiple());
1531
RUN_TEST(check_example_io_plugin_failed_to_start_command());
1532
RUN_TEST(check_example_io_plugin_fails_with_python_backtrace());
1533
RUN_TEST(check_io_plugin_callbacks_are_optional());
1534
RUN_TEST(check_io_plugin_reports_error());
1535
RUN_TEST(check_plugin_unload());
1536
1537
RUN_TEST(check_example_group_plugin());
1538
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
1539
RUN_TEST(check_example_group_plugin_is_able_to_debug());
1540
#endif
1541
RUN_TEST(check_plugin_unload());
1542
1543
RUN_TEST(check_loading_fails_with_missing_path());
1544
RUN_TEST(check_loading_succeeds_with_missing_classname());
1545
RUN_TEST(check_loading_fails_with_missing_classname());
1546
RUN_TEST(check_loading_fails_with_wrong_classname());
1547
RUN_TEST(check_loading_fails_with_wrong_path());
1548
RUN_TEST(check_plugin_unload());
1549
1550
RUN_TEST(check_example_conversation_plugin_reason_log(false, "without_suspend"));
1551
RUN_TEST(check_example_conversation_plugin_reason_log(true, "with_suspend"));
1552
RUN_TEST(check_example_conversation_plugin_user_interrupts());
1553
RUN_TEST(check_plugin_unload());
1554
1555
RUN_TEST(check_example_policy_plugin_version_display(true));
1556
RUN_TEST(check_example_policy_plugin_version_display(false));
1557
RUN_TEST(check_example_policy_plugin_accepted_execution());
1558
RUN_TEST(check_example_policy_plugin_failed_execution());
1559
RUN_TEST(check_example_policy_plugin_denied_execution());
1560
RUN_TEST(check_example_policy_plugin_list());
1561
RUN_TEST(check_example_policy_plugin_validate_invalidate());
1562
RUN_TEST(check_policy_plugin_callbacks_are_optional());
1563
RUN_TEST(check_policy_plugin_reports_error());
1564
RUN_TEST(check_plugin_unload());
1565
1566
RUN_TEST(check_example_audit_plugin_receives_accept());
1567
RUN_TEST(check_example_audit_plugin_receives_reject());
1568
RUN_TEST(check_example_audit_plugin_receives_error());
1569
RUN_TEST(check_example_audit_plugin_workflow_multiple());
1570
RUN_TEST(check_example_audit_plugin_version_display());
1571
RUN_TEST(check_audit_plugin_callbacks_are_optional());
1572
RUN_TEST(check_audit_plugin_reports_error());
1573
RUN_TEST(check_plugin_unload());
1574
1575
// Monday, too early
1576
RUN_TEST(check_example_approval_plugin(
1577
"2020-02-10T07:55:23", "That is not allowed outside the business hours!"));
1578
// Monday, good time
1579
RUN_TEST(check_example_approval_plugin("2020-02-10T08:05:23", NULL));
1580
// Friday, good time
1581
RUN_TEST(check_example_approval_plugin("2020-02-14T17:59:23", NULL));
1582
// Friday, too late
1583
RUN_TEST(check_example_approval_plugin(
1584
"2020-02-10T18:05:23", "That is not allowed outside the business hours!"));
1585
// Saturday
1586
RUN_TEST(check_example_approval_plugin(
1587
"2020-02-15T08:05:23", "That is not allowed on the weekend!"));
1588
RUN_TEST(check_multiple_approval_plugin_and_arguments());
1589
1590
RUN_TEST(check_python_plugins_do_not_affect_each_other());
1591
RUN_TEST(check_plugin_unload());
1592
1593
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
1594
RUN_TEST(check_example_debugging("plugin@err"));
1595
RUN_TEST(check_example_debugging("plugin@info"));
1596
RUN_TEST(check_example_debugging("load@diag"));
1597
RUN_TEST(check_example_debugging("sudo_cb@info"));
1598
RUN_TEST(check_example_debugging("c_calls@diag"));
1599
RUN_TEST(check_example_debugging("c_calls@info"));
1600
RUN_TEST(check_example_debugging("py_calls@diag"));
1601
RUN_TEST(check_example_debugging("py_calls@info"));
1602
RUN_TEST(check_example_debugging("plugin@err"));
1603
RUN_TEST(check_plugin_unload());
1604
#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
1605
1606
if (ntests != 0) {
1607
printf("%s: %d tests run, %d errors, %d%% success rate\n",
1608
getprogname(), ntests, errors, (ntests - errors) * 100 / ntests);
1609
}
1610
1611
return errors;
1612
}
1613
1614