2 * Copyright (c) 2005-2006 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#7 $
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];
84 ret = getacflg(string, PATH_MAX);
88 errx(-1, "getacflg: %d", ret);
90 printf("flags:%s\n", string);
96 errx(-1, "getacmin: %d", ret);
98 printf("min:%d\n", val);
100 ret = getacna(string, PATH_MAX);
104 errx(-1, "getacna: %d", ret);
106 printf("naflags:%s\n", string);
110 ret = getacdir(string, PATH_MAX);
116 errx(-1, "getacdir: %d", ret);
117 printf("dir:%s\n", string);
121 ret = getacpol(string, PATH_MAX);
124 if (au_strtopol(string, &policy) < 0)
125 err(-1, "au_strtopol");
126 if (au_poltostr(policy, PATH_MAX, string2) < 0)
127 err(-1, "au_poltostr");
128 printf("policy:%s\n", string2);
132 printf_classmask(au_class_t classmask)
139 for (i = 0; i < 32; i++) {
140 if (classmask & (2 << i)) {
145 c = getauclassnum(2 << i);
147 printf("%s", c->ac_name);
149 printf("0x%x", 2 << i);
159 while ((ep = getauevent()) != NULL) {
160 printf("%d:%s:%s:", ep->ae_number, ep->ae_name, ep->ae_desc);
161 printf_classmask(ep->ae_class);
169 char event_ent_name[AU_EVENT_NAME_MAX];
170 char event_ent_desc[AU_EVENT_DESC_MAX];
171 au_event_ent_t e, *ep;
173 bzero(&e, sizeof(e));
174 bzero(event_ent_name, sizeof(event_ent_name));
175 bzero(event_ent_desc, sizeof(event_ent_desc));
176 e.ae_name = event_ent_name;
177 e.ae_desc = event_ent_desc;
179 while ((ep = getauevent_r(&e)) != NULL) {
180 printf("%d:%s:%s:", ep->ae_number, ep->ae_name, ep->ae_desc);
181 printf_classmask(ep->ae_class);
191 while ((up = getauuserent()) != NULL) {
192 printf("%s:", up->au_name);
193 // printf_classmask(up->au_always);
195 // printf_classmask(up->au_never);
203 char user_ent_name[AU_USER_NAME_MAX];
204 au_user_ent_t u, *up;
206 bzero(&u, sizeof(u));
207 bzero(user_ent_name, sizeof(user_ent_name));
208 u.au_name = user_ent_name;
210 while ((up = getauuserent_r(&u)) != NULL) {
211 printf("%s:", up->au_name);
212 // printf_classmask(up->au_always);
214 // printf_classmask(up->au_never);
220 main(int argc, char *argv[])
226 if (strcmp(argv[1], "class") == 0)
228 else if (strcmp(argv[1], "class_r") == 0)
230 else if (strcmp(argv[1], "control") == 0)
232 else if (strcmp(argv[1], "event") == 0)
234 else if (strcmp(argv[1], "event_r") == 0)
236 else if (strcmp(argv[1], "user") == 0)
238 else if (strcmp(argv[1], "user_r") == 0)