bsm_control.c (189279) | bsm_control.c (191273) |
---|---|
1/*- | 1/*- |
2 * Copyright (c) 2004,2009 Apple Inc. | 2 * Copyright (c) 2004, 2009 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: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. --- 11 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 * | 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: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. --- 11 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_control.c#28 $ | 30 * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#33 $ |
31 */ 32 33#include <config/config.h> 34 35#include <bsm/libbsm.h> 36 37#include <ctype.h> 38#include <errno.h> --- 6 unchanged lines hidden (view full) --- 45 46#ifndef HAVE_STRLCAT 47#include <compat/strlcat.h> 48#endif 49#ifndef HAVE_STRLCPY 50#include <compat/strlcpy.h> 51#endif 52 | 31 */ 32 33#include <config/config.h> 34 35#include <bsm/libbsm.h> 36 37#include <ctype.h> 38#include <errno.h> --- 6 unchanged lines hidden (view full) --- 45 46#ifndef HAVE_STRLCAT 47#include <compat/strlcat.h> 48#endif 49#ifndef HAVE_STRLCPY 50#include <compat/strlcpy.h> 51#endif 52 |
53#include <sys/stat.h> 54 |
|
53/* 54 * Parse the contents of the audit_control file to return the audit control 55 * parameters. These static fields are protected by 'mutex'. 56 */ 57static FILE *fp = NULL; 58static char linestr[AU_LINE_MAX]; 59static char *delim = ":"; 60 --- 154 unchanged lines hidden (view full) --- 215} 216 217/* 218 * Convert a policy to a string. Return -1 on failure, or >= 0 representing 219 * the actual size of the string placed in the buffer (excluding terminating 220 * nul). 221 */ 222ssize_t | 55/* 56 * Parse the contents of the audit_control file to return the audit control 57 * parameters. These static fields are protected by 'mutex'. 58 */ 59static FILE *fp = NULL; 60static char linestr[AU_LINE_MAX]; 61static char *delim = ":"; 62 --- 154 unchanged lines hidden (view full) --- 217} 218 219/* 220 * Convert a policy to a string. Return -1 on failure, or >= 0 representing 221 * the actual size of the string placed in the buffer (excluding terminating 222 * nul). 223 */ 224ssize_t |
223au_poltostr(long policy, size_t maxsize, char *buf) | 225au_poltostr(int policy, size_t maxsize, char *buf) |
224{ 225 int first = 1; 226 int i = 0; 227 228 if (maxsize < 1) 229 return (-1); 230 buf[0] = '\0'; 231 --- 11 unchanged lines hidden (view full) --- 243 return (strlen(buf)); 244} 245 246/* 247 * Convert a string to a policy. Return -1 on failure (with errno EINVAL, 248 * ENOMEM) or 0 on success. 249 */ 250int | 226{ 227 int first = 1; 228 int i = 0; 229 230 if (maxsize < 1) 231 return (-1); 232 buf[0] = '\0'; 233 --- 11 unchanged lines hidden (view full) --- 245 return (strlen(buf)); 246} 247 248/* 249 * Convert a string to a policy. Return -1 on failure (with errno EINVAL, 250 * ENOMEM) or 0 on success. 251 */ 252int |
251au_strtopol(const char *polstr, long *policy) | 253au_strtopol(const char *polstr, int *policy) |
252{ 253 char *bufp, *string; 254 char *buffer; 255 int i, matched; 256 257 *policy = 0; 258 buffer = strdup(polstr); 259 if (buffer == NULL) --- 22 unchanged lines hidden (view full) --- 282} 283 284/* 285 * Rewind the file pointer to beginning. 286 */ 287static void 288setac_locked(void) 289{ | 254{ 255 char *bufp, *string; 256 char *buffer; 257 int i, matched; 258 259 *policy = 0; 260 buffer = strdup(polstr); 261 if (buffer == NULL) --- 22 unchanged lines hidden (view full) --- 284} 285 286/* 287 * Rewind the file pointer to beginning. 288 */ 289static void 290setac_locked(void) 291{ |
292 static time_t lastctime = 0; 293 struct stat sbuf; |
|
290 291 ptrmoved = 1; | 294 295 ptrmoved = 1; |
292 if (fp != NULL) | 296 if (fp != NULL) { 297 /* 298 * Check to see if the file on disk has changed. If so, 299 * force a re-read of the file by closing it. 300 */ 301 if (fstat(fileno(fp), &sbuf) < 0) 302 goto closefp; 303 if (lastctime != sbuf.st_ctime) { 304 lastctime = sbuf.st_ctime; 305closefp: 306 fclose(fp); 307 fp = NULL; 308 return; 309 } 310 |
293 fseek(fp, 0, SEEK_SET); | 311 fseek(fp, 0, SEEK_SET); |
312 } |
|
294} 295 296void 297setac(void) 298{ 299 300#ifdef HAVE_PTHREAD_MUTEX_LOCK 301 pthread_mutex_lock(&mutex); --- 422 unchanged lines hidden --- | 313} 314 315void 316setac(void) 317{ 318 319#ifdef HAVE_PTHREAD_MUTEX_LOCK 320 pthread_mutex_lock(&mutex); --- 422 unchanged lines hidden --- |