Debian Codegraph @

tests/probes/xinetd/test_probe_xinetd.c

raw symbols SCIP
1
2 #ifdef HAVE_CONFIG_H
3 #include <config.h>
4 #endif
5
6 #define XINETD_TEST
7 #include <../../../../src/OVAL/probes/unix/xinetd_probe.c>
8
9 #define EMPTYSTR_IF_NULL(val) val ? val : ""
10
11 static char *string_array_cstr(char **string_array)
12 {
13 char buf[8192]; // Ought to be enough for anybody
14 size_t string_array_pos, bufpos = 0;
15 buf[0] = '\0';
16 if (string_array != NULL) {
17 for (string_array_pos = 0; string_array[string_array_pos] && (sizeof(buf) - bufpos - 1) > 1; ++string_array_pos) {
18 bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos - 1, "%s ", string_array[string_array_pos]);
19 }
20 }
21 return strdup(buf);
22 }
23
24 int main (int argc, char *argv[])
25 {
26 xiconf_t *xcfg;
27 xiconf_strans_t *xres;
28
29 char *path, *serv, *prot;
30
31 if (argc != 4) {
32 fprintf(stderr, "Usage: %s <path> <service> <protocol>\n", argv[0]);
33 return (1);
34 }
35
36 path = argv[1];
37 serv = argv[2];
38 prot = argv[3];
39
40 xcfg = xiconf_parse (path, 32);
41
42 if (xcfg == NULL) {
43 fprintf(stderr, "Parse error.\n");
44 return (2);
45 }
46
47 xres = xiconf_getservice (xcfg, serv, prot);
48
49 if (xres == NULL) {
50 fprintf(stderr, "Not found.\n");
51 return (3);
52 } else {
53 register unsigned int l;
54
55 for (l = 0; l < xres->cnt; ++l) {
56 fprintf(stdout,
57 "xiconf_service_t(%s):\n"
58 " type: %s\n"
59 " flags: %s\n"
60 " socket_type: %s\n"
61 " name: %s\n"
62 " protocol: %s\n"
63 " user: %s\n"
64 " server: %s\n"
65 " server_args: %s\n"
66 " only_from: %s\n"
67 " no_access: %s\n"
68 " port: %d\n"
69 " disable: %d\n"
70 " wait: %d\n"
71 " def_disabled: %d\n"
72 " def_enabled: %d\n",
73 EMPTYSTR_IF_NULL(xres->srv[l]->id),
74 EMPTYSTR_IF_NULL(xres->srv[l]->type),
75 string_array_cstr(xres->srv[l]->flags),
76 EMPTYSTR_IF_NULL(xres->srv[l]->socket_type),
77 EMPTYSTR_IF_NULL(xres->srv[l]->name),
78 EMPTYSTR_IF_NULL(xres->srv[l]->protocol),
79 EMPTYSTR_IF_NULL(xres->srv[l]->user),
80 EMPTYSTR_IF_NULL(xres->srv[l]->server),
81 EMPTYSTR_IF_NULL(xres->srv[l]->server_args),
82 string_array_cstr(xres->srv[l]->only_from),
83 string_array_cstr(xres->srv[l]->no_access),
84 xres->srv[l]->port,
85 xres->srv[l]->disable,
86 xres->srv[l]->wait,
87 xres->srv[l]->def_disabled,
88 xres->srv[l]->def_enabled);
89 }
90 }
91
92 return (0);
93 }