Deleted Added
full compact
bsm_wrappers.c (186647) bsm_wrappers.c (191273)
1/*-
1/*-
2 * Copyright (c) 2004 Apple Inc.
2 * Copyright (c) 2004-2009 Apple Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

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

21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

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

21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_wrappers.c#28 $
29 * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_wrappers.c#31 $
30 */
31
32#ifdef __APPLE__
33#define _SYS_AUDIT_H /* Prevent include of sys/audit.h. */
34#endif
35
36#include <sys/param.h>
37#include <sys/stat.h>

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

58 * General purpose audit submission mechanism for userspace.
59 */
60int
61audit_submit(short au_event, au_id_t auid, char status,
62 int reterr, const char *fmt, ...)
63{
64 char text[MAX_AUDITSTRING_LEN];
65 token_t *token;
30 */
31
32#ifdef __APPLE__
33#define _SYS_AUDIT_H /* Prevent include of sys/audit.h. */
34#endif
35
36#include <sys/param.h>
37#include <sys/stat.h>

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

58 * General purpose audit submission mechanism for userspace.
59 */
60int
61audit_submit(short au_event, au_id_t auid, char status,
62 int reterr, const char *fmt, ...)
63{
64 char text[MAX_AUDITSTRING_LEN];
65 token_t *token;
66 long acond;
66 int acond;
67 va_list ap;
68 pid_t pid;
69 int error, afd, subj_ex;
70 struct auditinfo ai;
71 struct auditinfo_addr aia;
72 au_tid_t atid;
73
67 va_list ap;
68 pid_t pid;
69 int error, afd, subj_ex;
70 struct auditinfo ai;
71 struct auditinfo_addr aia;
72 au_tid_t atid;
73
74 if (auditon(A_GETCOND, &acond, sizeof(acond)) < 0) {
74 if (audit_get_cond(&acond) != 0) {
75 /*
76 * If auditon(2) returns ENOSYS, then audit has not been
77 * compiled into the kernel, so just return.
78 */
79 if (errno == ENOSYS)
80 return (0);
81 error = errno;
82 syslog(LOG_AUTH | LOG_ERR, "audit: auditon failed: %s",

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

173 error = errno;
174 syslog(LOG_AUTH | LOG_ERR,
175 "audit: au_write failed: %s", strerror(errno));
176 (void) au_close(afd, AU_TO_NO_WRITE, au_event);
177 errno = error;
178 return (-1);
179 }
180 }
75 /*
76 * If auditon(2) returns ENOSYS, then audit has not been
77 * compiled into the kernel, so just return.
78 */
79 if (errno == ENOSYS)
80 return (0);
81 error = errno;
82 syslog(LOG_AUTH | LOG_ERR, "audit: auditon failed: %s",

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

173 error = errno;
174 syslog(LOG_AUTH | LOG_ERR,
175 "audit: au_write failed: %s", strerror(errno));
176 (void) au_close(afd, AU_TO_NO_WRITE, au_event);
177 errno = error;
178 return (-1);
179 }
180 }
181 token = au_to_return32(status, au_errno_to_bsm(reterr));
181 token = au_to_return32(au_errno_to_bsm(status), reterr);
182 if (token == NULL) {
183 syslog(LOG_AUTH | LOG_ERR,
184 "audit: enable to build return token");
185 (void) au_close(afd, AU_TO_NO_WRITE, au_event);
186 errno = EPERM;
187 return (-1);
188 }
189 if (au_write(afd, token) < 0) {

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

483 if (asidp != NULL)
484 *asidp = (au_asid_t)atoken.val[6];
485 if (tidp != NULL) {
486 audit_set_terminal_host(&tidp->machine);
487 tidp->port = (dev_t)atoken.val[7];
488 }
489}
490#endif /* !__APPLE__ */
182 if (token == NULL) {
183 syslog(LOG_AUTH | LOG_ERR,
184 "audit: enable to build return token");
185 (void) au_close(afd, AU_TO_NO_WRITE, au_event);
186 errno = EPERM;
187 return (-1);
188 }
189 if (au_write(afd, token) < 0) {

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

483 if (asidp != NULL)
484 *asidp = (au_asid_t)atoken.val[6];
485 if (tidp != NULL) {
486 audit_set_terminal_host(&tidp->machine);
487 tidp->port = (dev_t)atoken.val[7];
488 }
489}
490#endif /* !__APPLE__ */
491
492int
493audit_get_cond(int *cond)
494{
495 int ret;
496
497 ret = auditon(A_GETCOND, cond, sizeof(*cond));
498#ifdef A_OLDGETCOND
499 if ((0 != ret) && EINVAL == errno) {
500 long lcond = *cond;
501
502 ret = auditon(A_OLDGETCOND, &lcond, sizeof(lcond));
503 *cond = (int)lcond;
504 }
505#endif
506 return (ret);
507}
508
509int
510audit_set_cond(int *cond)
511{
512 int ret;
513
514 ret = auditon(A_SETCOND, cond, sizeof(*cond));
515#ifdef A_OLDSETCOND
516 if ((0 != ret) && (EINVAL == errno)) {
517 long lcond = (long)*cond;
518
519 ret = auditon(A_OLDSETCOND, &lcond, sizeof(lcond));
520 *cond = (int)lcond;
521 }
522#endif
523 return (ret);
524}
525
526int
527audit_get_policy(int *policy)
528{
529 int ret;
530
531 ret = auditon(A_GETPOLICY, policy, sizeof(*policy));
532#ifdef A_OLDGETPOLICY
533 if ((0 != ret) && (EINVAL == errno)){
534 long lpolicy = (long)*policy;
535
536 ret = auditon(A_OLDGETPOLICY, &lpolicy, sizeof(lpolicy));
537 *policy = (int)lpolicy;
538 }
539#endif
540 return (ret);
541}
542
543int
544audit_set_policy(int *policy)
545{
546 int ret;
547
548 ret = auditon(A_SETPOLICY, policy, sizeof(*policy));
549#ifdef A_OLDSETPOLICY
550 if ((0 != ret) && (EINVAL == errno)){
551 long lpolicy = (long)*policy;
552
553 ret = auditon(A_OLDSETPOLICY, &lpolicy, sizeof(lpolicy));
554 *policy = (int)lpolicy;
555 }
556#endif
557 return (ret);
558}
559
560int
561audit_get_qctrl(au_qctrl_t *qctrl, size_t sz)
562{
563 int ret;
564
565 if (sizeof(*qctrl) != sz) {
566 errno = EINVAL;
567 return (-1);
568 }
569
570 ret = auditon(A_GETQCTRL, qctrl, sizeof(*qctrl));
571#ifdef A_OLDGETQCTRL
572 if ((0 != ret) && (EINVAL == errno)){
573 struct old_qctrl {
574 size_t oq_hiwater;
575 size_t oq_lowater;
576 size_t oq_bufsz;
577 clock_t oq_delay;
578 int oq_minfree;
579 } oq;
580
581 oq.oq_hiwater = (size_t)qctrl->aq_hiwater;
582 oq.oq_lowater = (size_t)qctrl->aq_lowater;
583 oq.oq_bufsz = (size_t)qctrl->aq_bufsz;
584 oq.oq_delay = (clock_t)qctrl->aq_delay;
585 oq.oq_minfree = qctrl->aq_minfree;
586
587 ret = auditon(A_OLDGETQCTRL, &oq, sizeof(oq));
588
589 qctrl->aq_hiwater = (int)oq.oq_hiwater;
590 qctrl->aq_lowater = (int)oq.oq_lowater;
591 qctrl->aq_bufsz = (int)oq.oq_bufsz;
592 qctrl->aq_delay = (int)oq.oq_delay;
593 qctrl->aq_minfree = oq.oq_minfree;
594 }
595#endif /* A_OLDGETQCTRL */
596 return (ret);
597}
598
599int
600audit_set_qctrl(au_qctrl_t *qctrl, size_t sz)
601{
602 int ret;
603
604 if (sizeof(*qctrl) != sz) {
605 errno = EINVAL;
606 return (-1);
607 }
608
609 ret = auditon(A_SETQCTRL, qctrl, sz);
610#ifdef A_OLDSETQCTRL
611 if ((0 != ret) && (EINVAL == errno)) {
612 struct old_qctrl {
613 size_t oq_hiwater;
614 size_t oq_lowater;
615 size_t oq_bufsz;
616 clock_t oq_delay;
617 int oq_minfree;
618 } oq;
619
620 oq.oq_hiwater = (size_t)qctrl->aq_hiwater;
621 oq.oq_lowater = (size_t)qctrl->aq_lowater;
622 oq.oq_bufsz = (size_t)qctrl->aq_bufsz;
623 oq.oq_delay = (clock_t)qctrl->aq_delay;
624 oq.oq_minfree = qctrl->aq_minfree;
625
626 ret = auditon(A_OLDSETQCTRL, &oq, sizeof(oq));
627
628 qctrl->aq_hiwater = (int)oq.oq_hiwater;
629 qctrl->aq_lowater = (int)oq.oq_lowater;
630 qctrl->aq_bufsz = (int)oq.oq_bufsz;
631 qctrl->aq_delay = (int)oq.oq_delay;
632 qctrl->aq_minfree = oq.oq_minfree;
633 }
634#endif /* A_OLDSETQCTRL */
635 return (ret);
636}
637
638int
639audit_send_trigger(int *trigger)
640{
641
642 return (auditon(A_SENDTRIGGER, trigger, sizeof(*trigger)));
643}
644
645int
646audit_get_kaudit(auditinfo_addr_t *aia, size_t sz)
647{
648
649 if (sizeof(*aia) != sz) {
650 errno = EINVAL;
651 return (-1);
652 }
653
654 return (auditon(A_GETKAUDIT, aia, sz));
655}
656
657int
658audit_set_kaudit(auditinfo_addr_t *aia, size_t sz)
659{
660
661 if (sizeof(*aia) != sz) {
662 errno = EINVAL;
663 return (-1);
664 }
665
666 return (auditon(A_SETKAUDIT, aia, sz));
667}
668
669int
670audit_get_class(au_evclass_map_t *evc_map, size_t sz)
671{
672
673 if (sizeof(*evc_map) != sz) {
674 errno = EINVAL;
675 return (-1);
676 }
677
678 return (auditon(A_GETCLASS, evc_map, sz));
679}
680
681int
682audit_set_class(au_evclass_map_t *evc_map, size_t sz)
683{
684
685 if (sizeof(*evc_map) != sz) {
686 errno = EINVAL;
687 return (-1);
688 }
689
690 return (auditon(A_SETCLASS, evc_map, sz));
691}
692
693int
694audit_get_kmask(au_mask_t *kmask, size_t sz)
695{
696 if (sizeof(*kmask) != sz) {
697 errno = EINVAL;
698 return (-1);
699 }
700
701 return (auditon(A_GETKMASK, kmask, sz));
702}
703
704int
705audit_set_kmask(au_mask_t *kmask, size_t sz)
706{
707 if (sizeof(*kmask) != sz) {
708 errno = EINVAL;
709 return (-1);
710 }
711
712 return (auditon(A_SETKMASK, kmask, sz));
713}
714
715int
716audit_get_fsize(au_fstat_t *fstat, size_t sz)
717{
718
719 if (sizeof(*fstat) != sz) {
720 errno = EINVAL;
721 return (-1);
722 }
723
724 return (auditon(A_GETFSIZE, fstat, sz));
725}
726
727int
728audit_set_fsize(au_fstat_t *fstat, size_t sz)
729{
730
731 if (sizeof(*fstat) != sz) {
732 errno = EINVAL;
733 return (-1);
734 }
735
736 return (auditon(A_SETFSIZE, fstat, sz));
737}
738
739int
740audit_set_pmask(auditpinfo_t *api, size_t sz)
741{
742
743 if (sizeof(*api) != sz) {
744 errno = EINVAL;
745 return (-1);
746 }
747
748 return (auditon(A_SETPMASK, api, sz));
749}
750
751int
752audit_get_pinfo(auditpinfo_t *api, size_t sz)
753{
754
755 if (sizeof(*api) != sz) {
756 errno = EINVAL;
757 return (-1);
758 }
759
760 return (auditon(A_GETPINFO, api, sz));
761}
762
763int
764audit_get_pinfo_addr(auditpinfo_addr_t *apia, size_t sz)
765{
766
767 if (sizeof(*apia) != sz) {
768 errno = EINVAL;
769 return (-1);
770 }
771
772 return (auditon(A_GETPINFO_ADDR, apia, sz));
773}
774
775int
776audit_get_sinfo_addr(auditinfo_addr_t *aia, size_t sz)
777{
778
779 if (sizeof(*aia) != sz) {
780 errno = EINVAL;
781 return (-1);
782 }
783
784 return (auditon(A_GETSINFO_ADDR, aia, sz));
785}
786
787int
788audit_get_stat(au_stat_t *stats, size_t sz)
789{
790
791 if (sizeof(*stats) != sz) {
792 errno = EINVAL;
793 return (-1);
794 }
795
796 return (auditon(A_GETSTAT, stats, sz));
797}
798
799int
800audit_set_stat(au_stat_t *stats, size_t sz)
801{
802
803 if (sizeof(*stats) != sz) {
804 errno = EINVAL;
805 return (-1);
806 }
807
808 return (auditon(A_GETSTAT, stats, sz));
809}
810
811int
812audit_get_cwd(char *path, size_t sz)
813{
814
815 return (auditon(A_GETCWD, path, sz));
816}
817
818int
819audit_get_car(char *path, size_t sz)
820{
821
822 return (auditon(A_GETCAR, path, sz));
823}