]>
git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/ccaudit.cpp
24caac9a1a017d29b93f0ab67f17405c6a04a21e
2 * Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
19 #include <strings.h> // bcopy()
20 #include <unistd.h> // gethostname()
21 #include <netdb.h> // gethostbyname()
22 #include <sys/types.h> // inet_addr()
23 #include <sys/socket.h> // inet_addr()
24 #include <netinet/in.h> // inet_addr()
25 #include <arpa/inet.h> // inet_addr()
27 #include "utilities.h"
28 #include <Security/logging.h>
29 #include <bsm/libbsm.h>
34 namespace CommonCriteria
37 void TerminalId::set(void)
39 if (audit_set_terminal_id(&mTid
) != kAUNoErr
)
41 // If we start seeing the syslog too often, change to secdebug()
42 Syslog::warning("setting terminal ID info failed; using defaults");
48 void AuditSession::registerSession(void)
52 auinfo
.ai_auid
= mAuditId
;
53 auinfo
.ai_asid
= mSessionId
;
54 bcopy(&mTerminalId
.get(), &(auinfo
.ai_termid
), sizeof(auinfo
.ai_termid
));
55 bcopy(&mEventMask
.get(), &(auinfo
.ai_mask
), sizeof(auinfo
.ai_mask
));
57 if (setaudit(&auinfo
) != 0)
61 Syslog::notice("Attempted to initialize auditing, but this kernel that does not support auditing");
64 Syslog::notice("Could not initialize auditing; continuing");
68 void AuditRecord::submit(const short event_code
, const int returnCode
,
71 // If we're not auditing, do nothing
72 if (au_get_state() == AUC_NOAUDIT
)
75 // XXX make this a secdebug, then enable it
76 // Syslog::notice("Submitting authorization audit record");
80 // XXX/gh 3574731: Fix BSM SPI so the const_cast<>s aren't necessary
86 tok
= au_to_text(const_cast<char *>(msg
));
87 ret
= audit_write_success(event_code
, const_cast<token_t
*>(tok
),
88 mAuditId
, mEUid
, mEGid
, mRUid
, mRGid
,
90 const_cast<au_tid_t
*>(&(mTerminalId
.get())));
94 ret
= audit_write_failure(event_code
, const_cast<char *>(msg
),
95 returnCode
, mAuditId
, mEUid
, mEGid
,
96 mRUid
, mRGid
, mPid
, mSessionId
,
97 const_cast<au_tid_t
*>(&(mTerminalId
.get())));
100 MacOSError::throwMe(ret
);
104 } // end namespace CommonCriteria
105 } // end namespace Security