1/*-
2 * Copyright (c) 2004 Apple Inc.
3 * Copyright (c) 2006 Robert N. M. Watson
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
--- 13 unchanged lines hidden (view full) ---
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_class.c#14 $
31 */
32
33#include <config/config.h>
34
35#include <bsm/libbsm.h>
36
37#include <string.h>
38#include <pthread.h>
39#include <stdio.h>
40#include <stdlib.h>
41
42#ifndef HAVE_STRLCPY
43#include <compat/strlcpy.h>
44#endif
45
46/*
47 * Parse the contents of the audit_class file to return struct au_class_ent
48 * entries.
49 */
50static FILE *fp = NULL;
51static char linestr[AU_LINE_MAX];
52static const char *classdelim = ":";
53
54static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
55
56/*
57 * Parse a single line from the audit_class file passed in str to the struct
58 * au_class_ent elements; store the result in c.
59 */
60static struct au_class_ent *
61classfromstr(char *str, struct au_class_ent *c)
62{
--- 65 unchanged lines hidden (view full) ---
128 return (c);
129}
130
131struct au_class_ent *
132getauclassent_r(struct au_class_ent *c)
133{
134 struct au_class_ent *cp;
135
136 pthread_mutex_lock(&mutex);
137 cp = getauclassent_r_locked(c);
138 pthread_mutex_unlock(&mutex);
139 return (cp);
140}
141
142struct au_class_ent *
143getauclassent(void)
144{
145 static char class_ent_name[AU_CLASS_NAME_MAX];
146 static char class_ent_desc[AU_CLASS_DESC_MAX];
147 static struct au_class_ent c, *cp;
148
149 bzero(&c, sizeof(c));
150 bzero(class_ent_name, sizeof(class_ent_name));
151 bzero(class_ent_desc, sizeof(class_ent_desc));
152 c.ac_name = class_ent_name;
153 c.ac_desc = class_ent_desc;
154
155 pthread_mutex_lock(&mutex);
156 cp = getauclassent_r_locked(&c);
157 pthread_mutex_unlock(&mutex);
158 return (cp);
159}
160
161/*
162 * Rewind to the beginning of the enumeration.
163 *
164 * Must be called with mutex held.
165 */
--- 4 unchanged lines hidden (view full) ---
170 if (fp != NULL)
171 fseek(fp, 0, SEEK_SET);
172}
173
174void
175setauclass(void)
176{
177
178 pthread_mutex_lock(&mutex);
179 setauclass_locked();
180 pthread_mutex_unlock(&mutex);
181}
182
183/*
184 * Return the next au_class_entry having the given class name.
185 */
186struct au_class_ent *
187getauclassnam_r(struct au_class_ent *c, const char *name)
188{
189 struct au_class_ent *cp;
190
191 if (name == NULL)
192 return (NULL);
193
194 pthread_mutex_lock(&mutex);
195 setauclass_locked();
196 while ((cp = getauclassent_r_locked(c)) != NULL) {
197 if (strcmp(name, cp->ac_name) == 0) {
198 pthread_mutex_unlock(&mutex);
199 return (cp);
200 }
201 }
202 pthread_mutex_unlock(&mutex);
203 return (NULL);
204}
205
206struct au_class_ent *
207getauclassnam(const char *name)
208{
209 static char class_ent_name[AU_CLASS_NAME_MAX];
210 static char class_ent_desc[AU_CLASS_DESC_MAX];
--- 14 unchanged lines hidden (view full) ---
225 *
226 * OpenBSM extension.
227 */
228struct au_class_ent *
229getauclassnum_r(struct au_class_ent *c, au_class_t class_number)
230{
231 struct au_class_ent *cp;
232
233 pthread_mutex_lock(&mutex);
234 setauclass_locked();
235 while ((cp = getauclassent_r_locked(c)) != NULL) {
236 if (class_number == cp->ac_class)
237 return (cp);
238 }
239 pthread_mutex_unlock(&mutex);
240 return (NULL);
241}
242
243struct au_class_ent *
244getauclassnum(au_class_t class_number)
245{
246 static char class_ent_name[AU_CLASS_NAME_MAX];
247 static char class_ent_desc[AU_CLASS_DESC_MAX];
--- 10 unchanged lines hidden (view full) ---
258
259/*
260 * audit_class processing is complete; close any open files.
261 */
262void
263endauclass(void)
264{
265
266 pthread_mutex_lock(&mutex);
267 if (fp != NULL) {
268 fclose(fp);
269 fp = NULL;
270 }
271 pthread_mutex_unlock(&mutex);
272}
2 * Copyright (c) 2004 Apple Inc.
3 * Copyright (c) 2006 Robert N. M. Watson
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
--- 13 unchanged lines hidden (view full) ---
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_class.c#14 $
31 */
32
33#include <config/config.h>
34
35#include <bsm/libbsm.h>
36
37#include <string.h>
38#include <pthread.h>
39#include <stdio.h>
40#include <stdlib.h>
41
42#ifndef HAVE_STRLCPY
43#include <compat/strlcpy.h>
44#endif
45
46/*
47 * Parse the contents of the audit_class file to return struct au_class_ent
48 * entries.
49 */
50static FILE *fp = NULL;
51static char linestr[AU_LINE_MAX];
52static const char *classdelim = ":";
53
54static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
55
56/*
57 * Parse a single line from the audit_class file passed in str to the struct
58 * au_class_ent elements; store the result in c.
59 */
60static struct au_class_ent *
61classfromstr(char *str, struct au_class_ent *c)
62{
--- 65 unchanged lines hidden (view full) ---
128 return (c);
129}
130
131struct au_class_ent *
132getauclassent_r(struct au_class_ent *c)
133{
134 struct au_class_ent *cp;
135
136 pthread_mutex_lock(&mutex);
137 cp = getauclassent_r_locked(c);
138 pthread_mutex_unlock(&mutex);
139 return (cp);
140}
141
142struct au_class_ent *
143getauclassent(void)
144{
145 static char class_ent_name[AU_CLASS_NAME_MAX];
146 static char class_ent_desc[AU_CLASS_DESC_MAX];
147 static struct au_class_ent c, *cp;
148
149 bzero(&c, sizeof(c));
150 bzero(class_ent_name, sizeof(class_ent_name));
151 bzero(class_ent_desc, sizeof(class_ent_desc));
152 c.ac_name = class_ent_name;
153 c.ac_desc = class_ent_desc;
154
155 pthread_mutex_lock(&mutex);
156 cp = getauclassent_r_locked(&c);
157 pthread_mutex_unlock(&mutex);
158 return (cp);
159}
160
161/*
162 * Rewind to the beginning of the enumeration.
163 *
164 * Must be called with mutex held.
165 */
--- 4 unchanged lines hidden (view full) ---
170 if (fp != NULL)
171 fseek(fp, 0, SEEK_SET);
172}
173
174void
175setauclass(void)
176{
177
178 pthread_mutex_lock(&mutex);
179 setauclass_locked();
180 pthread_mutex_unlock(&mutex);
181}
182
183/*
184 * Return the next au_class_entry having the given class name.
185 */
186struct au_class_ent *
187getauclassnam_r(struct au_class_ent *c, const char *name)
188{
189 struct au_class_ent *cp;
190
191 if (name == NULL)
192 return (NULL);
193
194 pthread_mutex_lock(&mutex);
195 setauclass_locked();
196 while ((cp = getauclassent_r_locked(c)) != NULL) {
197 if (strcmp(name, cp->ac_name) == 0) {
198 pthread_mutex_unlock(&mutex);
199 return (cp);
200 }
201 }
202 pthread_mutex_unlock(&mutex);
203 return (NULL);
204}
205
206struct au_class_ent *
207getauclassnam(const char *name)
208{
209 static char class_ent_name[AU_CLASS_NAME_MAX];
210 static char class_ent_desc[AU_CLASS_DESC_MAX];
--- 14 unchanged lines hidden (view full) ---
225 *
226 * OpenBSM extension.
227 */
228struct au_class_ent *
229getauclassnum_r(struct au_class_ent *c, au_class_t class_number)
230{
231 struct au_class_ent *cp;
232
233 pthread_mutex_lock(&mutex);
234 setauclass_locked();
235 while ((cp = getauclassent_r_locked(c)) != NULL) {
236 if (class_number == cp->ac_class)
237 return (cp);
238 }
239 pthread_mutex_unlock(&mutex);
240 return (NULL);
241}
242
243struct au_class_ent *
244getauclassnum(au_class_t class_number)
245{
246 static char class_ent_name[AU_CLASS_NAME_MAX];
247 static char class_ent_desc[AU_CLASS_DESC_MAX];
--- 10 unchanged lines hidden (view full) ---
258
259/*
260 * audit_class processing is complete; close any open files.
261 */
262void
263endauclass(void)
264{
265
266 pthread_mutex_lock(&mutex);
267 if (fp != NULL) {
268 fclose(fp);
269 fp = NULL;
270 }
271 pthread_mutex_unlock(&mutex);
272}