]> git.saurik.com Git - apple/security.git/blob - SecurityServer/sstransit.h
Security-54.tar.gz
[apple/security.git] / SecurityServer / sstransit.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
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
8 * using this file.
9 *
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.
16 */
17
18
19 //
20 // sstransit - SecurityServer client library transition code.
21 //
22 // These are the functions that implement CssmClient methods in terms of
23 // MIG IPC client calls, plus their supporting machinery.
24 //
25 // WARNING! HERE BE DRAGONS!
26 // This code involves moderately arcane magic including (but not limited to)
27 // dancing macros paired off with self-maintaining stack objects. Don't take
28 // anything for granted! Be very afraid of ALL-CAPS names. Your best bet is
29 // probably to stick with the existing patterns.
30 //
31 #ifndef _H_SSTRANSIT
32 #define _H_SSTRANSIT
33
34 #include "ssclient.h"
35 #include <Security/mach++.h>
36 #include <Security/cssmwalkers.h>
37 #include <Security/AuthorizationWalkers.h>
38 #include "ucsp.h"
39
40 namespace Security
41 {
42
43 // stock leading argument profile used by all calls
44 #define UCSP_ARGS mGlobal().serverPort, mGlobal().thread().replyPort, &rcode
45
46 // IPC/IPCN wrap the actual Mach IPC call. IPC also activates the connection first
47 #define IPCN(statement) \
48 { CSSM_RETURN rcode; check(statement); if (rcode != CSSM_OK) CssmError::throwMe(rcode); }
49 #define IPC(statement) { activate(); IPCN(statement); }
50
51 // pass mandatory or optional CssmData arguments into an IPC call
52 #define DATA(arg) arg.data(), arg.length()
53 #define OPTIONALDATA(arg) (arg ? arg->data() : NULL), (arg ? arg->length() : 0)
54
55 // pass structured arguments in/out of IPC calls. See "data walkers" for details
56 #define COPY(copy) copy, copy.length(), copy
57 #define COPY_OUT(copy) &copy, &copy##Length, &copy##Base
58 #define COPY_OUT_DECL(type,name) type *name, *name##Base; mach_msg_type_number_t name##Length
59
60
61 //
62 // DataOutput manages an output CssmData argument.
63 //
64 class DataOutput {
65 public:
66 DataOutput(CssmData &arg, CssmAllocator &alloc)
67 : argument(arg), allocator(alloc) { mData = NULL; mLength = 0; }
68 ~DataOutput();
69
70 void **data() { return &mData; }
71 mach_msg_type_number_t *length() { return &mLength; }
72
73 CssmData &argument;
74 CssmAllocator &allocator;
75
76 private:
77 void *mData;
78 mach_msg_type_number_t mLength;
79 };
80
81
82 //
83 // Bundle up a Context for IPC transmission
84 //
85 class SendContext {
86 public:
87 SendContext(const Context &ctx);
88 ~SendContext() { CssmAllocator::standard().free(attributes); }
89
90 const Context &context;
91 CSSM_CONTEXT_ATTRIBUTE *attributes;
92 size_t attributeSize;
93 };
94
95 #define CONTEXT(ctx) ctx.context, ctx.attributes, ctx.attributes, ctx.attributeSize
96
97 } // end namespace Security
98
99 #endif //_H_SSTRANSIT