Deleted Added
full compact
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 $
30 * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_class.c#15 $
31 */
32
33#include <config/config.h>
34
35#include <bsm/libbsm.h>
36
37#include <string.h>
38#ifdef HAVE_PTHREAD_MUTEX_LOCK
39#include <pthread.h>
40#endif
41#include <stdio.h>
42#include <stdlib.h>
43
44#ifndef HAVE_STRLCPY
45#include <compat/strlcpy.h>
46#endif
47
48/*
49 * Parse the contents of the audit_class file to return struct au_class_ent
50 * entries.
51 */
52static FILE *fp = NULL;
53static char linestr[AU_LINE_MAX];
54static const char *classdelim = ":";
55
56#ifdef HAVE_PTHREAD_MUTEX_LOCK
57static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
58#endif
59
60/*
61 * Parse a single line from the audit_class file passed in str to the struct
62 * au_class_ent elements; store the result in c.
63 */
64static struct au_class_ent *
65classfromstr(char *str, struct au_class_ent *c)
66{

--- 65 unchanged lines hidden (view full) ---

132 return (c);
133}
134
135struct au_class_ent *
136getauclassent_r(struct au_class_ent *c)
137{
138 struct au_class_ent *cp;
139
140#ifdef HAVE_PTHREAD_MUTEX_LOCK
141 pthread_mutex_lock(&mutex);
142#endif
143 cp = getauclassent_r_locked(c);
144#ifdef HAVE_PTHREAD_MUTEX_LOCK
145 pthread_mutex_unlock(&mutex);
146#endif
147 return (cp);
148}
149
150struct au_class_ent *
151getauclassent(void)
152{
153 static char class_ent_name[AU_CLASS_NAME_MAX];
154 static char class_ent_desc[AU_CLASS_DESC_MAX];
155 static struct au_class_ent c, *cp;
156
157 bzero(&c, sizeof(c));
158 bzero(class_ent_name, sizeof(class_ent_name));
159 bzero(class_ent_desc, sizeof(class_ent_desc));
160 c.ac_name = class_ent_name;
161 c.ac_desc = class_ent_desc;
162
163#ifdef HAVE_PTHREAD_MUTEX_LOCK
164 pthread_mutex_lock(&mutex);
165#endif
166 cp = getauclassent_r_locked(&c);
167#ifdef HAVE_PTHREAD_MUTEX_LOCK
168 pthread_mutex_unlock(&mutex);
169#endif
170 return (cp);
171}
172
173/*
174 * Rewind to the beginning of the enumeration.
175 *
176 * Must be called with mutex held.
177 */

--- 4 unchanged lines hidden (view full) ---

182 if (fp != NULL)
183 fseek(fp, 0, SEEK_SET);
184}
185
186void
187setauclass(void)
188{
189
190#ifdef HAVE_PTHREAD_MUTEX_LOCK
191 pthread_mutex_lock(&mutex);
192#endif
193 setauclass_locked();
194#ifdef HAVE_PTHREAD_MUTEX_LOCK
195 pthread_mutex_unlock(&mutex);
196#endif
197}
198
199/*
200 * Return the next au_class_entry having the given class name.
201 */
202struct au_class_ent *
203getauclassnam_r(struct au_class_ent *c, const char *name)
204{
205 struct au_class_ent *cp;
206
207 if (name == NULL)
208 return (NULL);
209
210#ifdef HAVE_PTHREAD_MUTEX_LOCK
211 pthread_mutex_lock(&mutex);
212#endif
213 setauclass_locked();
214 while ((cp = getauclassent_r_locked(c)) != NULL) {
215 if (strcmp(name, cp->ac_name) == 0) {
216#ifdef HAVE_PTHREAD_MUTEX_LOCK
217 pthread_mutex_unlock(&mutex);
218#endif
219 return (cp);
220 }
221 }
222#ifdef HAVE_PTHREAD_MUTEX_LOCK
223 pthread_mutex_unlock(&mutex);
224#endif
225 return (NULL);
226}
227
228struct au_class_ent *
229getauclassnam(const char *name)
230{
231 static char class_ent_name[AU_CLASS_NAME_MAX];
232 static char class_ent_desc[AU_CLASS_DESC_MAX];

--- 14 unchanged lines hidden (view full) ---

247 *
248 * OpenBSM extension.
249 */
250struct au_class_ent *
251getauclassnum_r(struct au_class_ent *c, au_class_t class_number)
252{
253 struct au_class_ent *cp;
254
255#ifdef HAVE_PTHREAD_MUTEX_LOCK
256 pthread_mutex_lock(&mutex);
257#endif
258 setauclass_locked();
259 while ((cp = getauclassent_r_locked(c)) != NULL) {
260 if (class_number == cp->ac_class)
261 return (cp);
262 }
263#ifdef HAVE_PTHREAD_MUTEX_LOCK
264 pthread_mutex_unlock(&mutex);
265#endif
266 return (NULL);
267}
268
269struct au_class_ent *
270getauclassnum(au_class_t class_number)
271{
272 static char class_ent_name[AU_CLASS_NAME_MAX];
273 static char class_ent_desc[AU_CLASS_DESC_MAX];

--- 10 unchanged lines hidden (view full) ---

284
285/*
286 * audit_class processing is complete; close any open files.
287 */
288void
289endauclass(void)
290{
291
292#ifdef HAVE_PTHREAD_MUTEX_LOCK
293 pthread_mutex_lock(&mutex);
294#endif
295 if (fp != NULL) {
296 fclose(fp);
297 fp = NULL;
298 }
299#ifdef HAVE_PTHREAD_MUTEX_LOCK
300 pthread_mutex_unlock(&mutex);
301#endif
302}