2 * Copyright (c) 2004,2011,2014 Apple 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.
22 #include <security_utilities/utilities.h>
23 #include <mach/message.h> // audit_token_t
24 #include <bsm/audit.h> // au_tid_t, etc.
25 #include <bsm/audit_kevents.h> // AUE_NULL
28 namespace CommonCriteria
{
34 * For the most part, we won't have a machine ID to initialize the
35 * au_tid_t's machine field. There's no machine ID in the audit token,
36 * for example, since MIG is localhost-only.
38 class TerminalId
: public PodWrapper
<TerminalId
, au_tid_t
>
42 TerminalId(const TerminalId
&t
) { set(t
); }
43 TerminalId(const au_tid_t
&tid
) { set(tid
); }
46 void set(const au_tid_t
&tid
) { port
= tid
.port
; machine
= tid
.machine
; }
50 * audit_token_t provides all the info required for Common Criteria-mandated
51 * auditing. It's defined in <mach/mach_types.defs>. Its values are filled
52 * in by the kernel during a Mach RPC and it should be treated as read-only
57 AuditToken(const audit_token_t
&token
);
60 audit_token_t
auditToken() const { return mAuditToken
; }
61 uid_t
auditId() const { return mAuditId
; }
62 uid_t
euid() const { return mEuid
; }
63 gid_t
egid() const { return mEgid
; }
64 uid_t
ruid() const { return mRuid
; }
65 gid_t
rgid() const { return mRgid
; }
66 pid_t
pid() const { return mPid
; }
67 au_asid_t
sessionId() const { return mSessionId
; }
68 const au_tid_t
&terminalId() const { return mTerminalId
; }
71 audit_token_t mAuditToken
;
77 pid_t mPid
; // of client
79 TerminalId mTerminalId
;
84 * The (new) audit information structure
86 class AuditInfo
: public PodWrapper
<AuditInfo
, auditinfo_addr_t
> {
89 void get(au_asid_t session
);
90 void getPid(pid_t pid
);
92 void create(uint64_t flags
, uid_t auid
= AU_DEFAUDITID
);
94 uid_t
uid() const { return this->ai_auid
; }
95 uint64_t flags() const { return this->ai_flags
; }
96 au_asid_t
sessionId() const { return this->ai_asid
; }
98 static AuditInfo
current() { AuditInfo info
; info
.get(); return info
; }
104 // NB: Qualify all uses of these names with the namespace (CommonCriteria).
105 // Existing source code already follows this convention.
109 errInvalidCredential
= 1111, // try to make easier to find in log
112 errAuthDenied
, // "Auth" --> authorization; named to
113 // avoid conflict with the C symbol
114 // errAuthorizationDenied already in
116 errEndOfExternalErrors
// sentry/placeholder
124 AuditMask(unsigned int s
= AUE_NULL
, unsigned int f
= AUE_NULL
)
126 mMask
.am_success
= s
; mMask
.am_failure
= f
;
129 const au_mask_t
&get(void) const { return mMask
; }
136 // audit session state for the current process; only used by Server
140 AuditSession(au_id_t auid
, au_asid_t sid
)
141 : mAuditId(auid
), mSessionId(sid
) { }
144 // set audit info for this process in kernel
145 void registerSession(void);
147 void auditId(au_id_t auid
) { mAuditId
= auid
; }
148 void eventMask(AuditMask
&mask
) { mEventMask
= mask
; }
149 void terminalId(TerminalId
&tid
) { mTerminalId
= tid
; }
150 void sessionId(au_asid_t sid
) { mSessionId
= sid
; }
152 au_id_t
auditId(void) { return mAuditId
; }
153 AuditMask
&eventMask(void) { return mEventMask
; }
154 TerminalId
&terminalId(void) { return mTerminalId
; }
155 au_asid_t
sessionId(void) { return mSessionId
; }
159 AuditMask mEventMask
;
160 TerminalId mTerminalId
;
161 au_asid_t mSessionId
;
165 // For submitting audit records. Not general-purpose: no ability to
166 // submit arbitrary BSM tokens, for example. However, the SecurityServer
167 // has only limited auditing requirements under Common Criteria.
172 AuditRecord(const AuditToken
&auditToken
)
173 : mAuditToken(auditToken
) { }
174 AuditRecord(const audit_token_t
&auditToken
)
175 : mAuditToken(auditToken
) { }
178 // returnCode == 0 --> success; nonzero returnCode --> failure
179 void submit(const short event_code
, const int returnCode
,
180 const char *msg
= NULL
);
183 AuditToken mAuditToken
;
186 } // end namespace CommonCriteria
187 } // end namespace Security