Deleted Added
full compact
bsm_class.c (185573) bsm_class.c (186647)
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 *
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>
31 */
32
33#include <config/config.h>
34
35#include <bsm/libbsm.h>
36
37#include <string.h>
38#ifdef HAVE_PTHREAD_MUTEX_LOCK
38#include <pthread.h>
39#include <pthread.h>
40#endif
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
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
54static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
57static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
58#endif
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
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
136 pthread_mutex_lock(&mutex);
141 pthread_mutex_lock(&mutex);
142#endif
137 cp = getauclassent_r_locked(c);
143 cp = getauclassent_r_locked(c);
144#ifdef HAVE_PTHREAD_MUTEX_LOCK
138 pthread_mutex_unlock(&mutex);
145 pthread_mutex_unlock(&mutex);
146#endif
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
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
155 pthread_mutex_lock(&mutex);
164 pthread_mutex_lock(&mutex);
165#endif
156 cp = getauclassent_r_locked(&c);
166 cp = getauclassent_r_locked(&c);
167#ifdef HAVE_PTHREAD_MUTEX_LOCK
157 pthread_mutex_unlock(&mutex);
168 pthread_mutex_unlock(&mutex);
169#endif
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
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
178 pthread_mutex_lock(&mutex);
191 pthread_mutex_lock(&mutex);
192#endif
179 setauclass_locked();
193 setauclass_locked();
194#ifdef HAVE_PTHREAD_MUTEX_LOCK
180 pthread_mutex_unlock(&mutex);
195 pthread_mutex_unlock(&mutex);
196#endif
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
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
194 pthread_mutex_lock(&mutex);
211 pthread_mutex_lock(&mutex);
212#endif
195 setauclass_locked();
196 while ((cp = getauclassent_r_locked(c)) != NULL) {
197 if (strcmp(name, cp->ac_name) == 0) {
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
198 pthread_mutex_unlock(&mutex);
217 pthread_mutex_unlock(&mutex);
218#endif
199 return (cp);
200 }
201 }
219 return (cp);
220 }
221 }
222#ifdef HAVE_PTHREAD_MUTEX_LOCK
202 pthread_mutex_unlock(&mutex);
223 pthread_mutex_unlock(&mutex);
224#endif
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
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
233 pthread_mutex_lock(&mutex);
256 pthread_mutex_lock(&mutex);
257#endif
234 setauclass_locked();
235 while ((cp = getauclassent_r_locked(c)) != NULL) {
236 if (class_number == cp->ac_class)
237 return (cp);
238 }
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
239 pthread_mutex_unlock(&mutex);
264 pthread_mutex_unlock(&mutex);
265#endif
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 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
266 pthread_mutex_lock(&mutex);
293 pthread_mutex_lock(&mutex);
294#endif
267 if (fp != NULL) {
268 fclose(fp);
269 fp = NULL;
270 }
295 if (fp != NULL) {
296 fclose(fp);
297 fp = NULL;
298 }
299#ifdef HAVE_PTHREAD_MUTEX_LOCK
271 pthread_mutex_unlock(&mutex);
300 pthread_mutex_unlock(&mutex);
301#endif
272}
302}