]>
git.saurik.com Git - apple/security.git/blob - libsecurity_codesigning/lib/cs.h
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 // cs.h - code signing core header
31 #include "codesigning_dtrace.h"
32 #include <Security/CSCommonPriv.h>
33 #include <Security/SecCodePriv.h>
34 #include <Security/SecStaticCodePriv.h>
35 #include <Security/SecRequirementPriv.h>
36 #include <Security/SecCodeSigner.h>
37 #include <Security/SecBasePriv.h>
38 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>
39 #include <security_utilities/globalizer.h>
40 #include <security_utilities/seccfobject.h>
41 #include <security_utilities/cfclass.h>
42 #include <security_utilities/errors.h>
43 #include <security_utilities/sqlite++.h>
44 #include <security_utilities/cfutilities.h>
48 namespace CodeSigning
{
52 // API per-thread globals
55 SecCSFlags flags
; // flags of pending API call
69 ThreadNexus
<PerThread
> perThread
;
71 SecCSFlags
&flags() { return perThread().flags
; }
74 extern ModuleNexus
<CFObjects
> gCFObjects
;
76 static inline SecCSFlags
apiFlags() { return gCFObjects().flags(); }
78 OSStatus
dbError(const SQLite3::Error
&err
);
82 // Code Signing API brackets
89 catch (const UnixError &err) { \
90 switch (err.error) { \
91 case ENOEXEC: return errSecCSBadObjectFormat; \
92 default: return err.osStatus(); \
94 catch (const MacOSError &err) { return err.osStatus(); } \
95 catch (const SQLite3::Error &err) { return dbError(err); } \
96 catch (const CommonError &err) { return SecKeychainErrFromOSStatus(err.osStatus()); } \
97 catch (const std::bad_alloc &) { return memFullErr; } \
98 catch (...) { return errSecCSInternalError; } \
101 #define END_CSAPI_ERRORS \
103 catch (const CSError &err) { return err.cfError(errors); } \
104 catch (const UnixError &err) { \
105 switch (err.error) { \
106 case ENOEXEC: return CSError::cfError(errors, errSecCSBadObjectFormat); \
107 default: return CSError::cfError(errors, err.osStatus()); \
109 catch (const MacOSError &err) { return CSError::cfError(errors, err.osStatus()); } \
110 catch (const SQLite3::Error &err) { return CSError::cfError(errors, dbError(err)); } \
111 catch (const CommonError &err) { return CSError::cfError(errors, SecKeychainErrFromOSStatus(err.osStatus())); } \
112 catch (const std::bad_alloc &) { return CSError::cfError(errors, memFullErr); } \
113 catch (...) { return CSError::cfError(errors, errSecCSInternalError); } \
116 #define END_CSAPI1(bad) } catch (...) { return bad; }
119 #define END_CSAPI_ERRORS1(bad) \
121 catch (const CSError &err) { err.cfError(errors); } \
122 catch (const UnixError &err) { \
123 switch (err.error) { \
124 case ENOEXEC: CSError::cfError(errors, errSecCSBadObjectFormat); \
125 default: CSError::cfError(errors, err.osStatus()); \
127 catch (const MacOSError &err) { CSError::cfError(errors, err.osStatus()); } \
128 catch (const SQLite3::Error &err) { CSError::cfError(errors, dbError(err)); } \
129 catch (const CommonError &err) { CSError::cfError(errors, SecKeychainErrFromOSStatus(err.osStatus())); } \
130 catch (const std::bad_alloc &) { CSError::cfError(errors, memFullErr); } \
131 catch (...) { CSError::cfError(errors, errSecCSInternalError); } \
136 // A version of CodeSigning::Required
139 static inline T
&Required(T
*ptr
)
142 MacOSError::throwMe(errSecCSObjectRequired
);
146 static inline void Required(const void *ptr
)
149 MacOSError::throwMe(errSecCSObjectRequired
);
154 // Check flags against a validity mask
156 static inline void checkFlags(SecCSFlags flags
, SecCSFlags acceptable
= 0)
158 if (flags
& ~acceptable
)
159 MacOSError::throwMe(errSecCSInvalidFlags
);
160 gCFObjects().flags() = flags
;
165 // DTrace USDT function bracket.
167 // DTRACK(PROVIDER_PROBE_PREFIX, arguments-after-this);
169 // PROVIDER_PROBE_PREFIX_START(this, arguments-after-this)
171 // PROVIDER_PROBE_PREFIX_END(this)
173 #define DTRACK(_prefix, _obj, _args...) \
174 if (_prefix ## _START_ENABLED()) _prefix ## _START((_obj), ## _args); \
175 struct _DTFrame ## _prefix { void *me; \
176 _DTFrame ## _prefix(void *m) : me(m) { } \
177 ~_DTFrame ## _prefix() { _prefix ## _END(me); } \
178 } _dtframe##_prefix((_obj));