Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/logsrvd/regress/logsrvd_conf/logsrvd_conf_test.c
1532 views
1
/*
2
* SPDX-License-Identifier: ISC
3
*
4
* Copyright (c) 2022 Todd C. Miller <[email protected]>
5
*
6
* Permission to use, copy, modify, and distribute this software for any
7
* purpose with or without fee is hereby granted, provided that the above
8
* copyright notice and this permission notice appear in all copies.
9
*
10
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
19
#include <config.h>
20
21
#include <sys/socket.h>
22
23
#ifdef HAVE_STDBOOL_H
24
# include <stdbool.h>
25
#else
26
# include <compat/stdbool.h>
27
#endif /* HAVE_STDBOOL_H */
28
#include <stdio.h>
29
#include <stdlib.h>
30
#include <string.h>
31
#include <unistd.h>
32
33
#include <sudo_compat.h>
34
#include <sudo_util.h>
35
#include <sudo_iolog.h>
36
#include <sudo_queue.h>
37
#include <logsrvd.h>
38
39
sudo_dso_public int main(int argc, char *argv[]);
40
41
sudo_noreturn static void
42
usage(void)
43
{
44
fprintf(stderr, "usage: %s [-v] conf_file\n", getprogname());
45
exit(EXIT_FAILURE);
46
}
47
48
/*
49
* Simple test driver for logsrvd_conf_read().
50
* Just pases the file, errors to standard error.
51
*/
52
int
53
main(int argc, char *argv[])
54
{
55
bool verbose = false;
56
int ch, ntests, errors = 0;
57
58
initprogname(argc > 0 ? argv[0] : "conf_test");
59
60
while ((ch = getopt(argc, argv, "v")) != -1) {
61
switch (ch) {
62
case 'v':
63
verbose = true;
64
break;
65
default:
66
usage();
67
/* NOTREACHED */
68
}
69
}
70
argc -= optind;
71
argv += optind;
72
73
if (argc < 1)
74
usage();
75
76
for (ntests = 0; ntests < argc; ntests++) {
77
const char *path = argv[ntests];
78
if (verbose)
79
printf("reading %s\n", path);
80
if (!logsrvd_conf_read(path))
81
errors++;
82
}
83
logsrvd_conf_cleanup();
84
85
if (ntests != 0) {
86
printf("%s: %d tests run, %d errors, %d%% success rate\n",
87
getprogname(), ntests, errors, (ntests - errors) * 100 / ntests);
88
}
89
return errors;
90
}
91
92