Deleted Added
full compact
bsm_user.c (185573) bsm_user.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_user.c#18 $
30 * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_user.c#19 $
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_user file into au_user_ent structures.
48 */
49
50static FILE *fp = NULL;
51static char linestr[AU_LINE_MAX];
52static const char *user_delim = ":";
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_user file into au_user_ent structures.
50 */
51
52static FILE *fp = NULL;
53static char linestr[AU_LINE_MAX];
54static const char *user_delim = ":";
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 one line from the audit_user file into the au_user_ent structure.
58 */
59static struct au_user_ent *
60userfromstr(char *str, struct au_user_ent *u)
61{
62 char *username, *always, *never;

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

92 if (fp != NULL)
93 fseek(fp, 0, SEEK_SET);
94}
95
96void
97setauuser(void)
98{
99
59
60/*
61 * Parse one line from the audit_user file into the au_user_ent structure.
62 */
63static struct au_user_ent *
64userfromstr(char *str, struct au_user_ent *u)
65{
66 char *username, *always, *never;

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

96 if (fp != NULL)
97 fseek(fp, 0, SEEK_SET);
98}
99
100void
101setauuser(void)
102{
103
104#ifdef HAVE_PTHREAD_MUTEX_LOCK
100 pthread_mutex_lock(&mutex);
105 pthread_mutex_lock(&mutex);
106#endif
101 setauuser_locked();
107 setauuser_locked();
108#ifdef HAVE_PTHREAD_MUTEX_LOCK
102 pthread_mutex_unlock(&mutex);
109 pthread_mutex_unlock(&mutex);
110#endif
103}
104
105/*
106 * Close the file descriptor
107 */
108void
109endauuser(void)
110{
111
111}
112
113/*
114 * Close the file descriptor
115 */
116void
117endauuser(void)
118{
119
120#ifdef HAVE_PTHREAD_MUTEX_LOCK
112 pthread_mutex_lock(&mutex);
121 pthread_mutex_lock(&mutex);
122#endif
113 if (fp != NULL) {
114 fclose(fp);
115 fp = NULL;
116 }
123 if (fp != NULL) {
124 fclose(fp);
125 fp = NULL;
126 }
127#ifdef HAVE_PTHREAD_MUTEX_LOCK
117 pthread_mutex_unlock(&mutex);
128 pthread_mutex_unlock(&mutex);
129#endif
118}
119
120/*
121 * Enumerate the au_user_ent structures from the file
122 */
123static struct au_user_ent *
124getauuserent_r_locked(struct au_user_ent *u)
125{

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

149 return (u);
150}
151
152struct au_user_ent *
153getauuserent_r(struct au_user_ent *u)
154{
155 struct au_user_ent *up;
156
130}
131
132/*
133 * Enumerate the au_user_ent structures from the file
134 */
135static struct au_user_ent *
136getauuserent_r_locked(struct au_user_ent *u)
137{

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

161 return (u);
162}
163
164struct au_user_ent *
165getauuserent_r(struct au_user_ent *u)
166{
167 struct au_user_ent *up;
168
169#ifdef HAVE_PTHREAD_MUTEX_LOCK
157 pthread_mutex_lock(&mutex);
170 pthread_mutex_lock(&mutex);
171#endif
158 up = getauuserent_r_locked(u);
172 up = getauuserent_r_locked(u);
173#ifdef HAVE_PTHREAD_MUTEX_LOCK
159 pthread_mutex_unlock(&mutex);
174 pthread_mutex_unlock(&mutex);
175#endif
160 return (up);
161}
162
163struct au_user_ent *
164getauuserent(void)
165{
166 static char user_ent_name[AU_USER_NAME_MAX];
167 static struct au_user_ent u;

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

179struct au_user_ent *
180getauusernam_r(struct au_user_ent *u, const char *name)
181{
182 struct au_user_ent *up;
183
184 if (name == NULL)
185 return (NULL);
186
176 return (up);
177}
178
179struct au_user_ent *
180getauuserent(void)
181{
182 static char user_ent_name[AU_USER_NAME_MAX];
183 static struct au_user_ent u;

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

195struct au_user_ent *
196getauusernam_r(struct au_user_ent *u, const char *name)
197{
198 struct au_user_ent *up;
199
200 if (name == NULL)
201 return (NULL);
202
203#ifdef HAVE_PTHREAD_MUTEX_LOCK
187 pthread_mutex_lock(&mutex);
204 pthread_mutex_lock(&mutex);
205#endif
188
189 setauuser_locked();
190 while ((up = getauuserent_r_locked(u)) != NULL) {
191 if (strcmp(name, u->au_name) == 0) {
206
207 setauuser_locked();
208 while ((up = getauuserent_r_locked(u)) != NULL) {
209 if (strcmp(name, u->au_name) == 0) {
210#ifdef HAVE_PTHREAD_MUTEX_LOCK
192 pthread_mutex_unlock(&mutex);
211 pthread_mutex_unlock(&mutex);
212#endif
193 return (u);
194 }
195 }
196
213 return (u);
214 }
215 }
216
217#ifdef HAVE_PTHREAD_MUTEX_LOCK
197 pthread_mutex_unlock(&mutex);
218 pthread_mutex_unlock(&mutex);
219#endif
198 return (NULL);
199
200}
201
202struct au_user_ent *
203getauusernam(const char *name)
204{
205 static char user_ent_name[AU_USER_NAME_MAX];

--- 69 unchanged lines hidden ---
220 return (NULL);
221
222}
223
224struct au_user_ent *
225getauusernam(const char *name)
226{
227 static char user_ent_name[AU_USER_NAME_MAX];

--- 69 unchanged lines hidden ---