Deleted Added
full compact
2c2
< * Copyright (c) 2004 Apple Inc.
---
> * Copyright (c) 2004,2009 Apple Inc.
30c30
< * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#24 $
---
> * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#28 $
36a37
> #include <ctype.h>
67a69,94
> * Audit policy string token table for au_poltostr() and au_strtopol().
> */
> struct audit_polstr {
> long ap_policy;
> const char *ap_str;
> };
>
> static struct audit_polstr au_polstr[] = {
> { AUDIT_CNT, "cnt" },
> { AUDIT_AHLT, "ahlt" },
> { AUDIT_ARGV, "argv" },
> { AUDIT_ARGE, "arge" },
> { AUDIT_SEQ, "seq" },
> { AUDIT_WINDATA, "windata" },
> { AUDIT_USER, "user" },
> { AUDIT_GROUP, "group" },
> { AUDIT_TRAIL, "trail" },
> { AUDIT_PATH, "path" },
> { AUDIT_SCNT, "scnt" },
> { AUDIT_PUBLIC, "public" },
> { AUDIT_ZONENAME, "zonename" },
> { AUDIT_PERZONE, "perzone" },
> { -1, NULL }
> };
>
> /*
114a142,217
> * Convert a given time value with a multiplier (seconds, hours, days, years) to
> * seconds. Return 0 on success.
> */
> static int
> au_timetosec(time_t *seconds, u_long value, char mult)
> {
> if (NULL == seconds)
> return (-1);
>
> switch(mult) {
> case 's':
> /* seconds */
> *seconds = (time_t)value;
> break;
>
> case 'h':
> /* hours */
> *seconds = (time_t)value * 60 * 60;
> break;
>
> case 'd':
> /* days */
> *seconds = (time_t)value * 60 * 60 * 24;
> break;
>
> case 'y':
> /* years. Add a day for each 4th (leap) year. */
> *seconds = (time_t)value * 60 * 60 * 24 * 364 +
> ((time_t)value / 4) * 60 * 60 * 24;
> break;
>
> default:
> return (-1);
> }
> return (0);
> }
>
> /*
> * Convert a given disk space value with a multiplier (bytes, kilobytes,
> * megabytes, gigabytes) to bytes. Return 0 on success.
> */
> static int
> au_spacetobytes(size_t *bytes, u_long value, char mult)
> {
> if (NULL == bytes)
> return (-1);
>
> switch(mult) {
> case 'B':
> case ' ':
> /* Bytes */
> *bytes = (size_t)value;
> break;
>
> case 'K':
> /* Kilobytes */
> *bytes = (size_t)value * 1024;
> break;
>
> case 'M':
> /* Megabytes */
> *bytes = (size_t)value * 1024 * 1024;
> break;
>
> case 'G':
> /* Gigabytes */
> *bytes = (size_t)value * 1024 * 1024 * 1024;
> break;
>
> default:
> return (-1);
> }
> return (0);
> }
>
> /*
122c225,226
< int first;
---
> int first = 1;
> int i = 0;
126d229
< first = 1;
129,136c232,234
< if (policy & AUDIT_CNT) {
< if (strlcat(buf, "cnt", maxsize) >= maxsize)
< return (-1);
< first = 0;
< }
< if (policy & AUDIT_AHLT) {
< if (!first) {
< if (strlcat(buf, ",", maxsize) >= maxsize)
---
> do {
> if (policy & au_polstr[i].ap_policy) {
> if (!first && strlcat(buf, ",", maxsize) >= maxsize)
138,145c236,237
< }
< if (strlcat(buf, "ahlt", maxsize) >= maxsize)
< return (-1);
< first = 0;
< }
< if (policy & AUDIT_ARGV) {
< if (!first) {
< if (strlcat(buf, ",", maxsize) >= maxsize)
---
> if (strlcat(buf, au_polstr[i].ap_str, maxsize) >=
> maxsize)
146a239
> first = 0;
148,250c241,242
< if (strlcat(buf, "argv", maxsize) >= maxsize)
< return (-1);
< first = 0;
< }
< if (policy & AUDIT_ARGE) {
< if (!first) {
< if (strlcat(buf, ",", maxsize) >= maxsize)
< return (-1);
< }
< if (strlcat(buf, "arge", maxsize) >= maxsize)
< return (-1);
< first = 0;
< }
< if (policy & AUDIT_SEQ) {
< if (!first) {
< if (strlcat(buf, ",", maxsize) >= maxsize)
< return (-1);
< }
< if (strlcat(buf, "seq", maxsize) >= maxsize)
< return (-1);
< first = 0;
< }
< if (policy & AUDIT_WINDATA) {
< if (!first) {
< if (strlcat(buf, ",", maxsize) >= maxsize)
< return (-1);
< }
< if (strlcat(buf, "windata", maxsize) >= maxsize)
< return (-1);
< first = 0;
< }
< if (policy & AUDIT_USER) {
< if (!first) {
< if (strlcat(buf, ",", maxsize) >= maxsize)
< return (-1);
< }
< if (strlcat(buf, "user", maxsize) >= maxsize)
< return (-1);
< first = 0;
< }
< if (policy & AUDIT_GROUP) {
< if (!first) {
< if (strlcat(buf, ",", maxsize) >= maxsize)
< return (-1);
< }
< if (strlcat(buf, "group", maxsize) >= maxsize)
< return (-1);
< first = 0;
< }
< if (policy & AUDIT_TRAIL) {
< if (!first) {
< if (strlcat(buf, ",", maxsize) >= maxsize)
< return (-1);
< }
< if (strlcat(buf, "trail", maxsize) >= maxsize)
< return (-1);
< first = 0;
< }
< if (policy & AUDIT_PATH) {
< if (!first) {
< if (strlcat(buf, ",", maxsize) >= maxsize)
< return (-1);
< }
< if (strlcat(buf, "path", maxsize) >= maxsize)
< return (-1);
< first = 0;
< }
< if (policy & AUDIT_SCNT) {
< if (!first) {
< if (strlcat(buf, ",", maxsize) >= maxsize)
< return (-1);
< }
< if (strlcat(buf, "scnt", maxsize) >= maxsize)
< return (-1);
< first = 0;
< }
< if (policy & AUDIT_PUBLIC) {
< if (!first) {
< if (strlcat(buf, ",", maxsize) >= maxsize)
< return (-1);
< }
< if (strlcat(buf, "public", maxsize) >= maxsize)
< return (-1);
< first = 0;
< }
< if (policy & AUDIT_ZONENAME) {
< if (!first) {
< if (strlcat(buf, ",", maxsize) >= maxsize)
< return (-1);
< }
< if (strlcat(buf, "zonename", maxsize) >= maxsize)
< return (-1);
< first = 0;
< }
< if (policy & AUDIT_PERZONE) {
< if (!first) {
< if (strlcat(buf, ",", maxsize) >= maxsize)
< return (-1);
< }
< if (strlcat(buf, "perzone", maxsize) >= maxsize)
< return (-1);
< first = 0;
< }
---
> } while (NULL != au_polstr[++i].ap_str);
>
262a255
> int i, matched;
271,299c264,274
< if (strcmp(string, "cnt") == 0)
< *policy |= AUDIT_CNT;
< else if (strcmp(string, "ahlt") == 0)
< *policy |= AUDIT_AHLT;
< else if (strcmp(string, "argv") == 0)
< *policy |= AUDIT_ARGV;
< else if (strcmp(string, "arge") == 0)
< *policy |= AUDIT_ARGE;
< else if (strcmp(string, "seq") == 0)
< *policy |= AUDIT_SEQ;
< else if (strcmp(string, "winau_fstat") == 0)
< *policy |= AUDIT_WINDATA;
< else if (strcmp(string, "user") == 0)
< *policy |= AUDIT_USER;
< else if (strcmp(string, "group") == 0)
< *policy |= AUDIT_GROUP;
< else if (strcmp(string, "trail") == 0)
< *policy |= AUDIT_TRAIL;
< else if (strcmp(string, "path") == 0)
< *policy |= AUDIT_PATH;
< else if (strcmp(string, "scnt") == 0)
< *policy |= AUDIT_SCNT;
< else if (strcmp(string, "public") == 0)
< *policy |= AUDIT_PUBLIC;
< else if (strcmp(string, "zonename") == 0)
< *policy |= AUDIT_ZONENAME;
< else if (strcmp(string, "perzone") == 0)
< *policy |= AUDIT_PERZONE;
< else {
---
> matched = i = 0;
>
> do {
> if (strcmp(string, au_polstr[i].ap_str) == 0) {
> *policy |= au_polstr[i].ap_policy;
> matched = 1;
> break;
> }
> } while (NULL != au_polstr[++i].ap_str);
>
> if (!matched) {
438,439c413,416
< char *filesz, *dummy;
< long long ll;
---
> char *str;
> size_t val;
> char mult;
> int nparsed;
445c422
< if (getstrfromtype_locked(FILESZ_CONTROL_ENTRY, &filesz) < 0) {
---
> if (getstrfromtype_locked(FILESZ_CONTROL_ENTRY, &str) < 0) {
451c428
< if (filesz == NULL) {
---
> if (str == NULL) {
458,459c435,452
< ll = strtoll(filesz, &dummy, 10);
< if (*dummy != '\0') {
---
>
> /* Trim off any leading white space. */
> while (*str == ' ' || *str == '\t')
> str++;
>
> nparsed = sscanf(str, "%ju%c", (uintmax_t *)&val, &mult);
>
> switch (nparsed) {
> case 1:
> /* If no multiplier then assume 'B' (bytes). */
> mult = 'B';
> /* fall through */
> case 2:
> if (au_spacetobytes(filesz_val, val, mult) == 0)
> break;
> /* fall through */
> default:
> errno = EINVAL;
463d455
< errno = EINVAL;
465a458
>
470c463,464
< if (ll < 0 || (ll > 0 && ll < MIN_AUDIT_FILE_SIZE)) {
---
> if (*filesz_val < 0 || (*filesz_val > 0 &&
> *filesz_val < MIN_AUDIT_FILE_SIZE)) {
473a468
> filesz_val = 0L;
477d471
< *filesz_val = ll;
622c616
< strcpy(auditstr, str);
---
> strlcpy(auditstr, str, len);
627a622,723
>
> /*
> * Set expiration conditions.
> */
> static int
> setexpirecond(time_t *age, size_t *size, u_long value, char mult)
> {
>
> if (isupper(mult) || ' ' == mult)
> return (au_spacetobytes(size, value, mult));
> else
> return (au_timetosec(age, value, mult));
> }
>
> /*
> * Return the expire-after field from the audit control file.
> */
> int
> getacexpire(int *andflg, time_t *age, size_t *size)
> {
> char *str;
> int nparsed;
> u_long val1, val2;
> char mult1, mult2;
> char andor[AU_LINE_MAX];
>
> *age = 0L;
> *size = 0LL;
> *andflg = 0;
>
> #ifdef HAVE_PTHREAD_MUTEX_LOCK
> pthread_mutex_lock(&mutex);
> #endif
> setac_locked();
> if (getstrfromtype_locked(EXPIRE_AFTER_CONTROL_ENTRY, &str) < 0) {
> #ifdef HAVE_PTHREAD_MUTEX_LOCK
> pthread_mutex_unlock(&mutex);
> #endif
> return (-2);
> }
> if (str == NULL) {
> #ifdef HAVE_PTHREAD_MUTEX_LOCK
> pthread_mutex_unlock(&mutex);
> #endif
> return (1);
> }
>
> /* First, trim off any leading white space. */
> while (*str == ' ' || *str == '\t')
> str++;
>
> nparsed = sscanf(str, "%lu%c%[ \tadnorADNOR]%lu%c", &val1, &mult1,
> andor, &val2, &mult2);
>
> switch (nparsed) {
> case 1:
> /* If no multiplier then assume 'B' (Bytes). */
> mult1 = 'B';
> /* fall through */
> case 2:
> /* One expiration condition. */
> if (setexpirecond(age, size, val1, mult1) != 0) {
> #ifdef HAVE_PTHREAD_MUTEX_LOCK
> pthread_mutex_unlock(&mutex);
> #endif
> return (-1);
> }
> break;
>
> case 5:
> /* Two expiration conditions. */
> if (setexpirecond(age, size, val1, mult1) != 0 ||
> setexpirecond(age, size, val2, mult2) != 0) {
> #ifdef HAVE_PTHREAD_MUTEX_LOCK
> pthread_mutex_unlock(&mutex);
> #endif
> return (-1);
> }
> if (strcasestr(andor, "and") != NULL)
> *andflg = 1;
> else if (strcasestr(andor, "or") != NULL)
> *andflg = 0;
> else {
> #ifdef HAVE_PTHREAD_MUTEX_LOCK
> pthread_mutex_unlock(&mutex);
> #endif
> return (-1);
> }
> break;
>
> default:
> #ifdef HAVE_PTHREAD_MUTEX_LOCK
> pthread_mutex_unlock(&mutex);
> #endif
> return (-1);
> }
>
> #ifdef HAVE_PTHREAD_MUTEX_LOCK
> pthread_mutex_unlock(&mutex);
> #endif
> return (0);
> }