1 /*
2  * This is backwards compatibility for CCache API v2 clients to be able to run
3  * against the CCache API v3 library
4  */
5 
6 #ifndef __CREDENTIALSCACHE2__
7 #define __CREDENTIALSCACHE2__
8 
9 #include <CredentialsCache/CredentialsCache.h>
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif /* __cplusplus */
14 
15 #include <KerberosSupport/KerberosConditionalMacros.h>
16 
17 #if PRAGMA_IMPORT
18 #	pragma import on
19 #endif
20 
21 /* This stuff is to make sure that we always use the same compiler options for
22    this header file. Otherwise we get really exciting failure modes -- meeroh */
23 /* Sadly, the v2 APi didn't specify the alignment, so we use the default except on MacOS
24    (where our implementation defined it to be 2-byte aligned) */
25 #if TARGET_OS_MAC
26 	#if PRAGMA_STRUCT_ALIGN
27 		#pragma options align=mac68k
28 	#elif PRAGMA_STRUCT_PACKPUSH
29 		#pragma pack(push, 2)
30 	#elif PRAGMA_STRUCT_PACK
31 		#pragma pack(2)
32 	#endif
33 #endif
34 
35 #if PRAGMA_ENUM_ALWAYSINT
36 	#pragma enumsalwaysint on
37 #endif
38 
39 #if TARGET_CPU_68K
40 	#pragma fourbyteints on
41 #endif
42 
43 /* Some old types get directly mapped to new types */
44 
45 typedef cc_context_d apiCB;
46 typedef cc_ccache_d ccache_p;
47 typedef cc_credentials_iterator_d ccache_cit_creds;
48 typedef cc_ccache_iterator_d ccache_cit_ccache;
49 typedef cc_data cc_data_compat;
50 typedef cc_int32 cc_cred_vers;
51 typedef cc_int32 cc_result;
52 
53 /* This doesn't exist in API v3 */
54 typedef cc_uint32 cc_flags;
55 
56 /* Credentials types are visible to the caller so we have to keep binary compatibility */
57 
58 typedef struct cc_credentials_v5_compat {
59 	char*				client;
60 	char*				server;
61 	cc_data_compat		keyblock;
62 	cc_time_t			authtime;
63 	cc_time_t			starttime;
64 	cc_time_t			endtime;
65 	cc_time_t			renew_till;
66 	cc_uint32			is_skey;
67 	cc_uint32			ticket_flags;
68 	cc_data_compat**	addresses;
69     cc_data_compat		ticket;
70 	cc_data_compat		second_ticket;
71 	cc_data_compat**	authdata;
72 } cc_credentials_v5_compat;
73 
74 enum {
75 	MAX_V4_CRED_LEN = 1250
76 };
77 
78 enum {
79 	KRB_NAME_SZ = 40,
80 	KRB_INSTANCE_SZ = 40,
81 	KRB_REALM_SZ = 40
82 };
83 
84 typedef struct cc_credentials_v4_compat {
85 	unsigned char	kversion;
86 	char			principal[KRB_NAME_SZ+1];
87 	char			principal_instance[KRB_INSTANCE_SZ+1];
88 	char			service[KRB_NAME_SZ+1];
89 	char			service_instance[KRB_INSTANCE_SZ+1];
90 	char			realm[KRB_REALM_SZ+1];
91 	unsigned char	session_key[8];
92 	cc_int32		kvno;
93 	cc_int32		str_to_key;
94 	long			issue_date;
95 	cc_int32		lifetime;
96     cc_uint32		address;
97 	cc_int32		ticket_sz;
98 	unsigned char	ticket[MAX_V4_CRED_LEN];
99 	unsigned long	oops;
100 } cc_credentials_v4_compat;
101 
102 typedef union cred_ptr_union_compat {
103     cc_credentials_v4_compat*	pV4Cred;
104     cc_credentials_v5_compat*	pV5Cred;
105 } cred_ptr_union_compat;
106 
107 typedef struct cred_union {
108     cc_int32				cred_type;  // cc_cred_vers
109     cred_ptr_union_compat	cred;
110 } cred_union;
111 
112 /* NC info structure is gone in v3 */
113 
114 struct infoNC {
115 	char*		name;
116 	char*		principal;
117 	cc_int32	vers;
118 };
119 
120 typedef struct infoNC infoNC;
121 
122 /* Some old type names */
123 
124 typedef cc_credentials_v4_compat V4Cred_type;
125 typedef cc_credentials_v5_compat cc_creds;
126 struct ccache_cit;
127 typedef struct ccache_cit ccache_cit;
128 
129 enum {
130 	CC_API_VER_2 = ccapi_version_2
131 };
132 
133 enum {
134 	CC_NOERROR,
135 	CC_BADNAME,
136 	CC_NOTFOUND,
137 	CC_END,
138 	CC_IO,
139 	CC_WRITE,
140 	CC_NOMEM,
141 	CC_FORMAT,
142 	CC_LOCKED,
143 	CC_BAD_API_VERSION,
144 	CC_NO_EXIST,
145 	CC_NOT_SUPP,
146 	CC_BAD_PARM,
147 	CC_ERR_CACHE_ATTACH,
148 	CC_ERR_CACHE_RELEASE,
149 	CC_ERR_CACHE_FULL,
150 	CC_ERR_CRED_VERSION
151 };
152 
153 enum {
154 	CC_CRED_UNKNOWN,
155 	CC_CRED_V4,
156 	CC_CRED_V5,
157 	CC_CRED_MAX
158 };
159 
160 cc_int32 cc_shutdown (
161 	apiCB**				ioContext);
162 
163 cc_int32 cc_get_NC_info (
164 	apiCB*				inContext,
165 	infoNC***			outInfo);
166 
167 cc_int32 cc_get_change_time (
168 	apiCB*				inContext,
169 	cc_time_t*			outTime);
170 
171 cc_int32 cc_open (
172 	apiCB*				inContext,
173 	const char*			inName,
174 	cc_int32			inVersion,
175 	cc_uint32			inFlags,
176 	ccache_p**			outCCache);
177 
178 cc_int32 cc_create (
179 	apiCB*				inContext,
180 	const char*			inName,
181 	const char*			inPrincipal,
182 	cc_int32			inVersion,
183 	cc_uint32			inFlags,
184 	ccache_p**			outCCache);
185 
186 cc_int32 cc_close (
187 	apiCB*				inContext,
188 	ccache_p**			ioCCache);
189 
190 cc_int32 cc_destroy (
191 	apiCB*				inContext,
192 	ccache_p**			ioCCache);
193 
194 cc_int32 cc_seq_fetch_NCs_begin (
195 	apiCB*				inContext,
196 	ccache_cit**		outIterator);
197 
198 cc_int32 cc_seq_fetch_NCs_next (
199 	apiCB*				inContext,
200 	ccache_p**			outCCache,
201 	ccache_cit*			inIterator);
202 
203 cc_int32 cc_seq_fetch_NCs_end (
204 	apiCB*				inContext,
205 	ccache_cit**		ioIterator);
206 
207 cc_int32 cc_get_name (
208 	apiCB*				inContext,
209 	ccache_p*			inCCache,
210 	char**				outName);
211 
212 cc_int32 cc_get_cred_version (
213 	apiCB*				inContext,
214 	ccache_p*			inCCache,
215 	cc_int32*			outVersion);
216 
217 cc_int32 cc_set_principal (
218 	apiCB*				inContext,
219 	ccache_p*			inCCache,
220 	cc_int32			inVersion,
221 	char*				inPrincipal);
222 
223 cc_int32 cc_get_principal (
224 	apiCB*				inContext,
225 	ccache_p*			inCCache,
226 	char**				outPrincipal);
227 
228 cc_int32 cc_store (
229 	apiCB*				inContext,
230 	ccache_p*			inCCache,
231 	cred_union			inCredentials);
232 
233 cc_int32 cc_remove_cred (
234 	apiCB*				inContext,
235 	ccache_p*			inCCache,
236 	cred_union			inCredentials);
237 
238 cc_int32 cc_seq_fetch_creds_begin (
239 	apiCB*				inContext,
240 	const ccache_p*		inCCache,
241 	ccache_cit**		outIterator);
242 
243 cc_int32 cc_seq_fetch_creds_next (
244 	apiCB*				inContext,
245 	cred_union**		outCreds,
246 	ccache_cit*			inIterator);
247 
248 cc_int32 cc_seq_fetch_creds_end (
249 	apiCB*				inContext,
250 	ccache_cit**		ioIterator);
251 
252 cc_int32 cc_free_principal (
253 	apiCB*				inContext,
254 	char**				ioPrincipal);
255 
256 cc_int32 cc_free_name (
257 	apiCB*				inContext,
258 	char**				ioName);
259 
260 cc_int32 cc_free_creds (
261 	apiCB*				inContext,
262 	cred_union**		creds);
263 
264 cc_int32 cc_free_NC_info (
265 	apiCB*				inContext,
266 	infoNC***			ioInfo);
267 
268 #if TARGET_OS_MAC
269 	#if PRAGMA_STRUCT_ALIGN
270 		#pragma options align=reset
271 	#elif PRAGMA_STRUCT_PACKPUSH
272 		#pragma pack(pop)
273 	#elif PRAGMA_STRUCT_PACK
274 		#pragma pack()
275 	#endif
276 #endif
277 
278 #if PRAGMA_ENUM_ALWAYSINT
279 	#pragma enumsalwaysint reset
280 #endif
281 
282 #if TARGET_CPU_68K
283 	#pragma fourbyteints reset
284 #endif
285 
286 #if PRAGMA_IMPORT
287 #	pragma import reset
288 #endif
289 
290 #ifdef __cplusplus
291 }
292 #endif /* __cplusplus */
293 
294 #endif /* __CREDENTIALSCACHE2__ */