Deleted Added
full compact
bsm_control.c (185573) bsm_control.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_control.c#23 $
30 * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#24 $
31 */
32
33#include <config/config.h>
34
35#include <bsm/libbsm.h>
36
37#include <errno.h>
38#include <string.h>
31 */
32
33#include <config/config.h>
34
35#include <bsm/libbsm.h>
36
37#include <errno.h>
38#include <string.h>
39#ifdef HAVE_PTHREAD_MUTEX_LOCK
39#include <pthread.h>
40#include <pthread.h>
41#endif
40#include <stdio.h>
41#include <stdlib.h>
42
43#ifndef HAVE_STRLCAT
44#include <compat/strlcat.h>
45#endif
46#ifndef HAVE_STRLCPY
47#include <compat/strlcpy.h>

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

53 */
54static FILE *fp = NULL;
55static char linestr[AU_LINE_MAX];
56static char *delim = ":";
57
58static char inacdir = 0;
59static char ptrmoved = 0;
60
42#include <stdio.h>
43#include <stdlib.h>
44
45#ifndef HAVE_STRLCAT
46#include <compat/strlcat.h>
47#endif
48#ifndef HAVE_STRLCPY
49#include <compat/strlcpy.h>

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

55 */
56static FILE *fp = NULL;
57static char linestr[AU_LINE_MAX];
58static char *delim = ":";
59
60static char inacdir = 0;
61static char ptrmoved = 0;
62
63#ifdef HAVE_PTHREAD_MUTEX_LOCK
61static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
64static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
65#endif
62
63/*
64 * Returns the string value corresponding to the given label from the
65 * configuration file.
66 *
67 * Must be called with mutex held.
68 */
69static int

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

313 if (fp != NULL)
314 fseek(fp, 0, SEEK_SET);
315}
316
317void
318setac(void)
319{
320
66
67/*
68 * Returns the string value corresponding to the given label from the
69 * configuration file.
70 *
71 * Must be called with mutex held.
72 */
73static int

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

317 if (fp != NULL)
318 fseek(fp, 0, SEEK_SET);
319}
320
321void
322setac(void)
323{
324
325#ifdef HAVE_PTHREAD_MUTEX_LOCK
321 pthread_mutex_lock(&mutex);
326 pthread_mutex_lock(&mutex);
327#endif
322 setac_locked();
328 setac_locked();
329#ifdef HAVE_PTHREAD_MUTEX_LOCK
323 pthread_mutex_unlock(&mutex);
330 pthread_mutex_unlock(&mutex);
331#endif
324}
325
326/*
327 * Close the audit_control file.
328 */
329void
330endac(void)
331{
332
332}
333
334/*
335 * Close the audit_control file.
336 */
337void
338endac(void)
339{
340
341#ifdef HAVE_PTHREAD_MUTEX_LOCK
333 pthread_mutex_lock(&mutex);
342 pthread_mutex_lock(&mutex);
343#endif
334 ptrmoved = 1;
335 if (fp != NULL) {
336 fclose(fp);
337 fp = NULL;
338 }
344 ptrmoved = 1;
345 if (fp != NULL) {
346 fclose(fp);
347 fp = NULL;
348 }
349#ifdef HAVE_PTHREAD_MUTEX_LOCK
339 pthread_mutex_unlock(&mutex);
350 pthread_mutex_unlock(&mutex);
351#endif
340}
341
342/*
343 * Return audit directory information from the audit control file.
344 */
345int
346getacdir(char *name, int len)
347{
348 char *dir;
349 int ret = 0;
350
351 /*
352 * Check if another function was called between successive calls to
353 * getacdir.
354 */
352}
353
354/*
355 * Return audit directory information from the audit control file.
356 */
357int
358getacdir(char *name, int len)
359{
360 char *dir;
361 int ret = 0;
362
363 /*
364 * Check if another function was called between successive calls to
365 * getacdir.
366 */
367#ifdef HAVE_PTHREAD_MUTEX_LOCK
355 pthread_mutex_lock(&mutex);
368 pthread_mutex_lock(&mutex);
369#endif
356 if (inacdir && ptrmoved) {
357 ptrmoved = 0;
358 if (fp != NULL)
359 fseek(fp, 0, SEEK_SET);
360 ret = 2;
361 }
362 if (getstrfromtype_locked(DIR_CONTROL_ENTRY, &dir) < 0) {
370 if (inacdir && ptrmoved) {
371 ptrmoved = 0;
372 if (fp != NULL)
373 fseek(fp, 0, SEEK_SET);
374 ret = 2;
375 }
376 if (getstrfromtype_locked(DIR_CONTROL_ENTRY, &dir) < 0) {
377#ifdef HAVE_PTHREAD_MUTEX_LOCK
363 pthread_mutex_unlock(&mutex);
378 pthread_mutex_unlock(&mutex);
379#endif
364 return (-2);
365 }
366 if (dir == NULL) {
380 return (-2);
381 }
382 if (dir == NULL) {
383#ifdef HAVE_PTHREAD_MUTEX_LOCK
367 pthread_mutex_unlock(&mutex);
384 pthread_mutex_unlock(&mutex);
385#endif
368 return (-1);
369 }
370 if (strlen(dir) >= (size_t)len) {
386 return (-1);
387 }
388 if (strlen(dir) >= (size_t)len) {
389#ifdef HAVE_PTHREAD_MUTEX_LOCK
371 pthread_mutex_unlock(&mutex);
390 pthread_mutex_unlock(&mutex);
391#endif
372 return (-3);
373 }
374 strlcpy(name, dir, len);
392 return (-3);
393 }
394 strlcpy(name, dir, len);
395#ifdef HAVE_PTHREAD_MUTEX_LOCK
375 pthread_mutex_unlock(&mutex);
396 pthread_mutex_unlock(&mutex);
397#endif
376 return (ret);
377}
378
379/*
380 * Return the minimum free diskspace value from the audit control file.
381 */
382int
383getacmin(int *min_val)
384{
385 char *min;
386
398 return (ret);
399}
400
401/*
402 * Return the minimum free diskspace value from the audit control file.
403 */
404int
405getacmin(int *min_val)
406{
407 char *min;
408
409#ifdef HAVE_PTHREAD_MUTEX_LOCK
387 pthread_mutex_lock(&mutex);
410 pthread_mutex_lock(&mutex);
411#endif
388 setac_locked();
389 if (getstrfromtype_locked(MINFREE_CONTROL_ENTRY, &min) < 0) {
412 setac_locked();
413 if (getstrfromtype_locked(MINFREE_CONTROL_ENTRY, &min) < 0) {
414#ifdef HAVE_PTHREAD_MUTEX_LOCK
390 pthread_mutex_unlock(&mutex);
415 pthread_mutex_unlock(&mutex);
416#endif
391 return (-2);
392 }
393 if (min == NULL) {
417 return (-2);
418 }
419 if (min == NULL) {
420#ifdef HAVE_PTHREAD_MUTEX_LOCK
394 pthread_mutex_unlock(&mutex);
421 pthread_mutex_unlock(&mutex);
422#endif
395 return (1);
396 }
397 *min_val = atoi(min);
423 return (1);
424 }
425 *min_val = atoi(min);
426#ifdef HAVE_PTHREAD_MUTEX_LOCK
398 pthread_mutex_unlock(&mutex);
427 pthread_mutex_unlock(&mutex);
428#endif
399 return (0);
400}
401
402/*
403 * Return the desired trail rotation size from the audit control file.
404 */
405int
406getacfilesz(size_t *filesz_val)
407{
408 char *filesz, *dummy;
409 long long ll;
410
429 return (0);
430}
431
432/*
433 * Return the desired trail rotation size from the audit control file.
434 */
435int
436getacfilesz(size_t *filesz_val)
437{
438 char *filesz, *dummy;
439 long long ll;
440
441#ifdef HAVE_PTHREAD_MUTEX_LOCK
411 pthread_mutex_lock(&mutex);
442 pthread_mutex_lock(&mutex);
443#endif
412 setac_locked();
413 if (getstrfromtype_locked(FILESZ_CONTROL_ENTRY, &filesz) < 0) {
444 setac_locked();
445 if (getstrfromtype_locked(FILESZ_CONTROL_ENTRY, &filesz) < 0) {
446#ifdef HAVE_PTHREAD_MUTEX_LOCK
414 pthread_mutex_unlock(&mutex);
447 pthread_mutex_unlock(&mutex);
448#endif
415 return (-2);
416 }
417 if (filesz == NULL) {
449 return (-2);
450 }
451 if (filesz == NULL) {
452#ifdef HAVE_PTHREAD_MUTEX_LOCK
418 pthread_mutex_unlock(&mutex);
453 pthread_mutex_unlock(&mutex);
454#endif
419 errno = EINVAL;
420 return (1);
421 }
422 ll = strtoll(filesz, &dummy, 10);
423 if (*dummy != '\0') {
455 errno = EINVAL;
456 return (1);
457 }
458 ll = strtoll(filesz, &dummy, 10);
459 if (*dummy != '\0') {
460#ifdef HAVE_PTHREAD_MUTEX_LOCK
424 pthread_mutex_unlock(&mutex);
461 pthread_mutex_unlock(&mutex);
462#endif
425 errno = EINVAL;
426 return (-1);
427 }
428 /*
429 * The file size must either be 0 or >= MIN_AUDIT_FILE_SIZE. 0
430 * indicates no rotation size.
431 */
432 if (ll < 0 || (ll > 0 && ll < MIN_AUDIT_FILE_SIZE)) {
463 errno = EINVAL;
464 return (-1);
465 }
466 /*
467 * The file size must either be 0 or >= MIN_AUDIT_FILE_SIZE. 0
468 * indicates no rotation size.
469 */
470 if (ll < 0 || (ll > 0 && ll < MIN_AUDIT_FILE_SIZE)) {
471#ifdef HAVE_PTHREAD_MUTEX_LOCK
433 pthread_mutex_unlock(&mutex);
472 pthread_mutex_unlock(&mutex);
473#endif
434 errno = EINVAL;
435 return (-1);
436 }
437 *filesz_val = ll;
474 errno = EINVAL;
475 return (-1);
476 }
477 *filesz_val = ll;
478#ifdef HAVE_PTHREAD_MUTEX_LOCK
438 pthread_mutex_unlock(&mutex);
479 pthread_mutex_unlock(&mutex);
480#endif
439 return (0);
440}
441
442/*
443 * Return the system audit value from the audit contol file.
444 */
445int
446getacflg(char *auditstr, int len)
447{
448 char *str;
449
481 return (0);
482}
483
484/*
485 * Return the system audit value from the audit contol file.
486 */
487int
488getacflg(char *auditstr, int len)
489{
490 char *str;
491
492#ifdef HAVE_PTHREAD_MUTEX_LOCK
450 pthread_mutex_lock(&mutex);
493 pthread_mutex_lock(&mutex);
494#endif
451 setac_locked();
452 if (getstrfromtype_locked(FLAGS_CONTROL_ENTRY, &str) < 0) {
495 setac_locked();
496 if (getstrfromtype_locked(FLAGS_CONTROL_ENTRY, &str) < 0) {
497#ifdef HAVE_PTHREAD_MUTEX_LOCK
453 pthread_mutex_unlock(&mutex);
498 pthread_mutex_unlock(&mutex);
499#endif
454 return (-2);
455 }
456 if (str == NULL) {
500 return (-2);
501 }
502 if (str == NULL) {
503#ifdef HAVE_PTHREAD_MUTEX_LOCK
457 pthread_mutex_unlock(&mutex);
504 pthread_mutex_unlock(&mutex);
505#endif
458 return (1);
459 }
460 if (strlen(str) >= (size_t)len) {
506 return (1);
507 }
508 if (strlen(str) >= (size_t)len) {
509#ifdef HAVE_PTHREAD_MUTEX_LOCK
461 pthread_mutex_unlock(&mutex);
510 pthread_mutex_unlock(&mutex);
511#endif
462 return (-3);
463 }
464 strlcpy(auditstr, str, len);
512 return (-3);
513 }
514 strlcpy(auditstr, str, len);
515#ifdef HAVE_PTHREAD_MUTEX_LOCK
465 pthread_mutex_unlock(&mutex);
516 pthread_mutex_unlock(&mutex);
517#endif
466 return (0);
467}
468
469/*
470 * Return the non attributable flags from the audit contol file.
471 */
472int
473getacna(char *auditstr, int len)
474{
475 char *str;
476
518 return (0);
519}
520
521/*
522 * Return the non attributable flags from the audit contol file.
523 */
524int
525getacna(char *auditstr, int len)
526{
527 char *str;
528
529#ifdef HAVE_PTHREAD_MUTEX_LOCK
477 pthread_mutex_lock(&mutex);
530 pthread_mutex_lock(&mutex);
531#endif
478 setac_locked();
479 if (getstrfromtype_locked(NA_CONTROL_ENTRY, &str) < 0) {
532 setac_locked();
533 if (getstrfromtype_locked(NA_CONTROL_ENTRY, &str) < 0) {
534#ifdef HAVE_PTHREAD_MUTEX_LOCK
480 pthread_mutex_unlock(&mutex);
535 pthread_mutex_unlock(&mutex);
536#endif
481 return (-2);
482 }
483 if (str == NULL) {
537 return (-2);
538 }
539 if (str == NULL) {
540#ifdef HAVE_PTHREAD_MUTEX_LOCK
484 pthread_mutex_unlock(&mutex);
541 pthread_mutex_unlock(&mutex);
542#endif
485 return (1);
486 }
487 if (strlen(str) >= (size_t)len) {
543 return (1);
544 }
545 if (strlen(str) >= (size_t)len) {
546#ifdef HAVE_PTHREAD_MUTEX_LOCK
488 pthread_mutex_unlock(&mutex);
547 pthread_mutex_unlock(&mutex);
548#endif
489 return (-3);
490 }
491 strlcpy(auditstr, str, len);
549 return (-3);
550 }
551 strlcpy(auditstr, str, len);
552#ifdef HAVE_PTHREAD_MUTEX_LOCK
492 pthread_mutex_unlock(&mutex);
553 pthread_mutex_unlock(&mutex);
554#endif
493 return (0);
494}
495
496/*
497 * Return the policy field from the audit control file.
498 */
499int
500getacpol(char *auditstr, size_t len)
501{
502 char *str;
503
555 return (0);
556}
557
558/*
559 * Return the policy field from the audit control file.
560 */
561int
562getacpol(char *auditstr, size_t len)
563{
564 char *str;
565
566#ifdef HAVE_PTHREAD_MUTEX_LOCK
504 pthread_mutex_lock(&mutex);
567 pthread_mutex_lock(&mutex);
568#endif
505 setac_locked();
506 if (getstrfromtype_locked(POLICY_CONTROL_ENTRY, &str) < 0) {
569 setac_locked();
570 if (getstrfromtype_locked(POLICY_CONTROL_ENTRY, &str) < 0) {
571#ifdef HAVE_PTHREAD_MUTEX_LOCK
507 pthread_mutex_unlock(&mutex);
572 pthread_mutex_unlock(&mutex);
573#endif
508 return (-2);
509 }
510 if (str == NULL) {
574 return (-2);
575 }
576 if (str == NULL) {
577#ifdef HAVE_PTHREAD_MUTEX_LOCK
511 pthread_mutex_unlock(&mutex);
578 pthread_mutex_unlock(&mutex);
579#endif
512 return (-1);
513 }
514 if (strlen(str) >= len) {
580 return (-1);
581 }
582 if (strlen(str) >= len) {
583#ifdef HAVE_PTHREAD_MUTEX_LOCK
515 pthread_mutex_unlock(&mutex);
584 pthread_mutex_unlock(&mutex);
585#endif
516 return (-3);
517 }
518 strlcpy(auditstr, str, len);
586 return (-3);
587 }
588 strlcpy(auditstr, str, len);
589#ifdef HAVE_PTHREAD_MUTEX_LOCK
519 pthread_mutex_unlock(&mutex);
590 pthread_mutex_unlock(&mutex);
591#endif
520 return (0);
521}
522
523int
524getachost(char *auditstr, size_t len)
525{
526 char *str;
527
592 return (0);
593}
594
595int
596getachost(char *auditstr, size_t len)
597{
598 char *str;
599
600#ifdef HAVE_PTHREAD_MUTEX_LOCK
528 pthread_mutex_lock(&mutex);
601 pthread_mutex_lock(&mutex);
602#endif
529 setac_locked();
530 if (getstrfromtype_locked(AUDIT_HOST_CONTROL_ENTRY, &str) < 0) {
603 setac_locked();
604 if (getstrfromtype_locked(AUDIT_HOST_CONTROL_ENTRY, &str) < 0) {
605#ifdef HAVE_PTHREAD_MUTEX_LOCK
531 pthread_mutex_unlock(&mutex);
606 pthread_mutex_unlock(&mutex);
607#endif
532 return (-2);
533 }
534 if (str == NULL) {
608 return (-2);
609 }
610 if (str == NULL) {
611#ifdef HAVE_PTHREAD_MUTEX_LOCK
535 pthread_mutex_unlock(&mutex);
612 pthread_mutex_unlock(&mutex);
613#endif
536 return (1);
537 }
538 if (strlen(str) >= len) {
614 return (1);
615 }
616 if (strlen(str) >= len) {
617#ifdef HAVE_PTHREAD_MUTEX_LOCK
539 pthread_mutex_unlock(&mutex);
618 pthread_mutex_unlock(&mutex);
619#endif
540 return (-3);
541 }
542 strcpy(auditstr, str);
620 return (-3);
621 }
622 strcpy(auditstr, str);
623#ifdef HAVE_PTHREAD_MUTEX_LOCK
543 pthread_mutex_unlock(&mutex);
624 pthread_mutex_unlock(&mutex);
625#endif
544 return (0);
545}
626 return (0);
627}