2 * Copyright (c) 2005-2009 Robert N. M. Watson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $P4: //depot/projects/trustedbsd/openbsm/tools/audump.c#9 $
29 #include <bsm/libbsm.h>
37 * Simple tool to dump various /etc/security databases using the defined APIs.
44 fprintf(stderr, "usage: audump [class|class_r|control|event|event_r|"
54 while ((cp = getauclassent()) != NULL)
55 printf("0x%08x:%s:%s\n", cp->ac_class, cp->ac_name,
62 char class_ent_name[AU_CLASS_NAME_MAX];
63 char class_ent_desc[AU_CLASS_DESC_MAX];
64 au_class_ent_t c, *cp;
67 bzero(class_ent_name, sizeof(class_ent_name));
68 bzero(class_ent_desc, sizeof(class_ent_desc));
69 c.ac_name = class_ent_name;
70 c.ac_desc = class_ent_desc;
72 while ((cp = getauclassent_r(&c)) != NULL)
73 printf("0x%08x:%s:%s\n", cp->ac_class, cp->ac_name,
80 char string[PATH_MAX], string2[PATH_MAX];
86 ret = getacflg(string, PATH_MAX);
90 errx(-1, "getacflg: %d", ret);
92 printf("flags:%s\n", string);
98 errx(-1, "getacmin: %d", ret);
100 printf("min:%d\n", val);
102 ret = getacna(string, PATH_MAX);
106 errx(-1, "getacna: %d", ret);
108 printf("naflags:%s\n", string);
112 ret = getacdir(string, PATH_MAX);
118 errx(-1, "getacdir: %d", ret);
119 printf("dir:%s\n", string);
123 ret = getacpol(string, PATH_MAX);
126 if (au_strtopol(string, &policy) < 0)
127 err(-1, "au_strtopol");
128 if (au_poltostr(policy, PATH_MAX, string2) < 0)
129 err(-1, "au_poltostr");
130 printf("policy:%s\n", string2);
132 ret = getacfilesz(&size);
134 err(-1, "getacfilesz");
136 err(-1, "getacfilesz: %d", ret);
138 printf("filesz:%ldB\n", size);
141 ret = getachost(string, PATH_MAX);
143 err(-1, "getachost");
145 err(-1, "getachost: %d", ret);
146 if (ret == 0 && ret != 1)
147 printf("host:%s\n", string);
149 ret = getacexpire(&val, &age, &size);
151 err(-1, "getacexpire");
153 err(-1, "getacexpire: %d", ret);
154 if (ret == 0 && ret != 1)
155 printf("expire-after:%ldB %s %lds\n", size,
156 val ? "AND" : "OR", age);
160 printf_classmask(au_class_t classmask)
167 for (i = 0; i < 32; i++) {
168 if (classmask & (1 << i)) {
173 c = getauclassnum(1 << i);
175 printf("%s", c->ac_name);
177 printf("0x%x", 1 << i);
187 while ((ep = getauevent()) != NULL) {
188 printf("%d:%s:%s:", ep->ae_number, ep->ae_name, ep->ae_desc);
189 printf_classmask(ep->ae_class);
197 char event_ent_name[AU_EVENT_NAME_MAX];
198 char event_ent_desc[AU_EVENT_DESC_MAX];
199 au_event_ent_t e, *ep;
201 bzero(&e, sizeof(e));
202 bzero(event_ent_name, sizeof(event_ent_name));
203 bzero(event_ent_desc, sizeof(event_ent_desc));
204 e.ae_name = event_ent_name;
205 e.ae_desc = event_ent_desc;
207 while ((ep = getauevent_r(&e)) != NULL) {
208 printf("%d:%s:%s:", ep->ae_number, ep->ae_name, ep->ae_desc);
209 printf_classmask(ep->ae_class);
219 while ((up = getauuserent()) != NULL) {
220 printf("%s:", up->au_name);
221 // printf_classmask(up->au_always);
223 // printf_classmask(up->au_never);
231 char user_ent_name[AU_USER_NAME_MAX];
232 au_user_ent_t u, *up;
234 bzero(&u, sizeof(u));
235 bzero(user_ent_name, sizeof(user_ent_name));
236 u.au_name = user_ent_name;
238 while ((up = getauuserent_r(&u)) != NULL) {
239 printf("%s:", up->au_name);
240 // printf_classmask(up->au_always);
242 // printf_classmask(up->au_never);
248 main(int argc, char *argv[])
254 if (strcmp(argv[1], "class") == 0)
256 else if (strcmp(argv[1], "class_r") == 0)
258 else if (strcmp(argv[1], "control") == 0)
260 else if (strcmp(argv[1], "event") == 0)
262 else if (strcmp(argv[1], "event_r") == 0)
264 else if (strcmp(argv[1], "user") == 0)
266 else if (strcmp(argv[1], "user_r") == 0)