1*7f2fe78bSCy Schubert /* ccapi/lib/ccapi_v2.c */
2*7f2fe78bSCy Schubert /*
3*7f2fe78bSCy Schubert * Copyright 2006 Massachusetts Institute of Technology.
4*7f2fe78bSCy Schubert * All Rights Reserved.
5*7f2fe78bSCy Schubert *
6*7f2fe78bSCy Schubert * Export of this software from the United States of America may
7*7f2fe78bSCy Schubert * require a specific license from the United States Government.
8*7f2fe78bSCy Schubert * It is the responsibility of any person or organization contemplating
9*7f2fe78bSCy Schubert * export to obtain such a license before exporting.
10*7f2fe78bSCy Schubert *
11*7f2fe78bSCy Schubert * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12*7f2fe78bSCy Schubert * distribute this software and its documentation for any purpose and
13*7f2fe78bSCy Schubert * without fee is hereby granted, provided that the above copyright
14*7f2fe78bSCy Schubert * notice appear in all copies and that both that copyright notice and
15*7f2fe78bSCy Schubert * this permission notice appear in supporting documentation, and that
16*7f2fe78bSCy Schubert * the name of M.I.T. not be used in advertising or publicity pertaining
17*7f2fe78bSCy Schubert * to distribution of the software without specific, written prior
18*7f2fe78bSCy Schubert * permission. Furthermore if you modify this software you must label
19*7f2fe78bSCy Schubert * your software as modified software and not distribute it in such a
20*7f2fe78bSCy Schubert * fashion that it might be confused with the original M.I.T. software.
21*7f2fe78bSCy Schubert * M.I.T. makes no representations about the suitability of
22*7f2fe78bSCy Schubert * this software for any purpose. It is provided "as is" without express
23*7f2fe78bSCy Schubert * or implied warranty.
24*7f2fe78bSCy Schubert */
25*7f2fe78bSCy Schubert
26*7f2fe78bSCy Schubert #include "cci_common.h"
27*7f2fe78bSCy Schubert #include "ccapi_string.h"
28*7f2fe78bSCy Schubert #include "ccapi_context.h"
29*7f2fe78bSCy Schubert #include "ccapi_ccache.h"
30*7f2fe78bSCy Schubert #include "ccapi_ccache_iterator.h"
31*7f2fe78bSCy Schubert #include "ccapi_credentials.h"
32*7f2fe78bSCy Schubert #include "ccapi_credentials_iterator.h"
33*7f2fe78bSCy Schubert #include <CredentialsCache2.h>
34*7f2fe78bSCy Schubert
35*7f2fe78bSCy Schubert infoNC infoNC_initializer = { NULL, NULL, CC_CRED_UNKNOWN };
36*7f2fe78bSCy Schubert
37*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
38*7f2fe78bSCy Schubert
cci_remap_version(cc_int32 in_v2_version,cc_uint32 * out_v3_version)39*7f2fe78bSCy Schubert static cc_int32 cci_remap_version (cc_int32 in_v2_version,
40*7f2fe78bSCy Schubert cc_uint32 *out_v3_version)
41*7f2fe78bSCy Schubert {
42*7f2fe78bSCy Schubert cc_result err = ccNoError;
43*7f2fe78bSCy Schubert
44*7f2fe78bSCy Schubert if (!out_v3_version) { err = cci_check_error (ccErrBadParam); }
45*7f2fe78bSCy Schubert
46*7f2fe78bSCy Schubert if (!err) {
47*7f2fe78bSCy Schubert if (in_v2_version == CC_CRED_V5) {
48*7f2fe78bSCy Schubert *out_v3_version = cc_credentials_v5;
49*7f2fe78bSCy Schubert
50*7f2fe78bSCy Schubert } else {
51*7f2fe78bSCy Schubert err = ccErrBadCredentialsVersion;
52*7f2fe78bSCy Schubert }
53*7f2fe78bSCy Schubert }
54*7f2fe78bSCy Schubert
55*7f2fe78bSCy Schubert return cci_check_error (err);
56*7f2fe78bSCy Schubert }
57*7f2fe78bSCy Schubert
58*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
59*7f2fe78bSCy Schubert
_cci_remap_error(cc_result in_error,const char * in_function,const char * in_file,int in_line)60*7f2fe78bSCy Schubert static cc_result _cci_remap_error (cc_result in_error,
61*7f2fe78bSCy Schubert const char *in_function,
62*7f2fe78bSCy Schubert const char *in_file,
63*7f2fe78bSCy Schubert int in_line)
64*7f2fe78bSCy Schubert {
65*7f2fe78bSCy Schubert _cci_check_error (in_error, in_function, in_file, in_line);
66*7f2fe78bSCy Schubert
67*7f2fe78bSCy Schubert if (in_error >= CC_NOERROR && in_error <= CC_ERR_CRED_VERSION) {
68*7f2fe78bSCy Schubert return in_error;
69*7f2fe78bSCy Schubert }
70*7f2fe78bSCy Schubert
71*7f2fe78bSCy Schubert switch (in_error) {
72*7f2fe78bSCy Schubert case ccNoError:
73*7f2fe78bSCy Schubert return CC_NOERROR;
74*7f2fe78bSCy Schubert
75*7f2fe78bSCy Schubert case ccIteratorEnd:
76*7f2fe78bSCy Schubert return CC_END;
77*7f2fe78bSCy Schubert
78*7f2fe78bSCy Schubert case ccErrBadParam:
79*7f2fe78bSCy Schubert case ccErrContextNotFound:
80*7f2fe78bSCy Schubert case ccErrInvalidContext:
81*7f2fe78bSCy Schubert case ccErrInvalidCredentials:
82*7f2fe78bSCy Schubert case ccErrInvalidCCacheIterator:
83*7f2fe78bSCy Schubert case ccErrInvalidCredentialsIterator:
84*7f2fe78bSCy Schubert case ccErrInvalidLock:
85*7f2fe78bSCy Schubert case ccErrBadLockType:
86*7f2fe78bSCy Schubert return CC_BAD_PARM;
87*7f2fe78bSCy Schubert
88*7f2fe78bSCy Schubert case ccErrNoMem:
89*7f2fe78bSCy Schubert return CC_NOMEM;
90*7f2fe78bSCy Schubert
91*7f2fe78bSCy Schubert case ccErrInvalidCCache:
92*7f2fe78bSCy Schubert case ccErrCCacheNotFound:
93*7f2fe78bSCy Schubert return CC_NO_EXIST;
94*7f2fe78bSCy Schubert
95*7f2fe78bSCy Schubert case ccErrCredentialsNotFound:
96*7f2fe78bSCy Schubert return CC_NOTFOUND;
97*7f2fe78bSCy Schubert
98*7f2fe78bSCy Schubert case ccErrBadName:
99*7f2fe78bSCy Schubert return CC_BADNAME;
100*7f2fe78bSCy Schubert
101*7f2fe78bSCy Schubert case ccErrBadCredentialsVersion:
102*7f2fe78bSCy Schubert return CC_ERR_CRED_VERSION;
103*7f2fe78bSCy Schubert
104*7f2fe78bSCy Schubert case ccErrBadAPIVersion:
105*7f2fe78bSCy Schubert return CC_BAD_API_VERSION;
106*7f2fe78bSCy Schubert
107*7f2fe78bSCy Schubert case ccErrContextLocked:
108*7f2fe78bSCy Schubert case ccErrContextUnlocked:
109*7f2fe78bSCy Schubert case ccErrCCacheLocked:
110*7f2fe78bSCy Schubert case ccErrCCacheUnlocked:
111*7f2fe78bSCy Schubert return CC_LOCKED;
112*7f2fe78bSCy Schubert
113*7f2fe78bSCy Schubert case ccErrServerUnavailable:
114*7f2fe78bSCy Schubert case ccErrServerInsecure:
115*7f2fe78bSCy Schubert case ccErrServerCantBecomeUID:
116*7f2fe78bSCy Schubert case ccErrBadInternalMessage:
117*7f2fe78bSCy Schubert case ccErrClientNotFound:
118*7f2fe78bSCy Schubert return CC_IO;
119*7f2fe78bSCy Schubert
120*7f2fe78bSCy Schubert case ccErrNotImplemented:
121*7f2fe78bSCy Schubert return CC_NOT_SUPP;
122*7f2fe78bSCy Schubert
123*7f2fe78bSCy Schubert default:
124*7f2fe78bSCy Schubert cci_debug_printf ("%s(): Unhandled error", __FUNCTION__);
125*7f2fe78bSCy Schubert return CC_BAD_PARM;
126*7f2fe78bSCy Schubert }
127*7f2fe78bSCy Schubert }
128*7f2fe78bSCy Schubert #define cci_remap_error(err) _cci_remap_error(err, __FUNCTION__, __FILE__, __LINE__)
129*7f2fe78bSCy Schubert
130*7f2fe78bSCy Schubert
131*7f2fe78bSCy Schubert #if TARGET_OS_MAC
132*7f2fe78bSCy Schubert #pragma mark -
133*7f2fe78bSCy Schubert #endif
134*7f2fe78bSCy Schubert
135*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
136*7f2fe78bSCy Schubert
cc_shutdown(apiCB ** io_context)137*7f2fe78bSCy Schubert cc_result cc_shutdown (apiCB **io_context)
138*7f2fe78bSCy Schubert {
139*7f2fe78bSCy Schubert cc_result err = ccNoError;
140*7f2fe78bSCy Schubert
141*7f2fe78bSCy Schubert if (!io_context) { err = cci_check_error (ccErrBadParam); }
142*7f2fe78bSCy Schubert
143*7f2fe78bSCy Schubert if (!err) {
144*7f2fe78bSCy Schubert err = ccapi_context_release (*io_context);
145*7f2fe78bSCy Schubert }
146*7f2fe78bSCy Schubert
147*7f2fe78bSCy Schubert if (!err) {
148*7f2fe78bSCy Schubert *io_context = NULL;
149*7f2fe78bSCy Schubert }
150*7f2fe78bSCy Schubert
151*7f2fe78bSCy Schubert return cci_remap_error (err);
152*7f2fe78bSCy Schubert }
153*7f2fe78bSCy Schubert
154*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
155*7f2fe78bSCy Schubert
cc_get_change_time(apiCB * in_context,cc_time_t * out_change_time)156*7f2fe78bSCy Schubert cc_result cc_get_change_time (apiCB *in_context,
157*7f2fe78bSCy Schubert cc_time_t *out_change_time)
158*7f2fe78bSCy Schubert {
159*7f2fe78bSCy Schubert cc_result err = ccNoError;
160*7f2fe78bSCy Schubert
161*7f2fe78bSCy Schubert if (!in_context ) { err = cci_check_error (ccErrBadParam); }
162*7f2fe78bSCy Schubert if (!out_change_time) { err = cci_check_error (ccErrBadParam); }
163*7f2fe78bSCy Schubert
164*7f2fe78bSCy Schubert if (!err) {
165*7f2fe78bSCy Schubert err = ccapi_context_get_change_time (in_context, out_change_time);
166*7f2fe78bSCy Schubert }
167*7f2fe78bSCy Schubert
168*7f2fe78bSCy Schubert return cci_remap_error (err);
169*7f2fe78bSCy Schubert }
170*7f2fe78bSCy Schubert
171*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
172*7f2fe78bSCy Schubert
cc_get_NC_info(apiCB * in_context,infoNC *** out_info)173*7f2fe78bSCy Schubert cc_result cc_get_NC_info (apiCB *in_context,
174*7f2fe78bSCy Schubert infoNC ***out_info)
175*7f2fe78bSCy Schubert {
176*7f2fe78bSCy Schubert cc_result err = CC_NOERROR;
177*7f2fe78bSCy Schubert infoNC **info = NULL;
178*7f2fe78bSCy Schubert cc_uint64 count = 0; /* Preflight the size */
179*7f2fe78bSCy Schubert cc_uint64 i;
180*7f2fe78bSCy Schubert
181*7f2fe78bSCy Schubert if (!in_context) { err = cci_check_error (ccErrBadParam); }
182*7f2fe78bSCy Schubert if (!out_info ) { err = cci_check_error (ccErrBadParam); }
183*7f2fe78bSCy Schubert
184*7f2fe78bSCy Schubert if (!err) {
185*7f2fe78bSCy Schubert ccache_cit *iterator = NULL;
186*7f2fe78bSCy Schubert
187*7f2fe78bSCy Schubert err = cc_seq_fetch_NCs_begin (in_context, &iterator);
188*7f2fe78bSCy Schubert
189*7f2fe78bSCy Schubert while (!err) {
190*7f2fe78bSCy Schubert ccache_p *ccache = NULL;
191*7f2fe78bSCy Schubert
192*7f2fe78bSCy Schubert err = cc_seq_fetch_NCs_next (in_context, &ccache, iterator);
193*7f2fe78bSCy Schubert
194*7f2fe78bSCy Schubert if (!err) { count++; }
195*7f2fe78bSCy Schubert
196*7f2fe78bSCy Schubert if (ccache) { cc_close (in_context, &ccache); }
197*7f2fe78bSCy Schubert }
198*7f2fe78bSCy Schubert if (err == CC_END) { err = CC_NOERROR; }
199*7f2fe78bSCy Schubert
200*7f2fe78bSCy Schubert if (!err) {
201*7f2fe78bSCy Schubert err = cc_seq_fetch_NCs_end (in_context, &iterator);
202*7f2fe78bSCy Schubert }
203*7f2fe78bSCy Schubert }
204*7f2fe78bSCy Schubert
205*7f2fe78bSCy Schubert if (!err) {
206*7f2fe78bSCy Schubert info = malloc (sizeof (*info) * (count + 1));
207*7f2fe78bSCy Schubert if (info) {
208*7f2fe78bSCy Schubert for (i = 0; i < count + 1; i++) { info[i] = NULL; }
209*7f2fe78bSCy Schubert } else {
210*7f2fe78bSCy Schubert err = cci_check_error (CC_NOMEM);
211*7f2fe78bSCy Schubert }
212*7f2fe78bSCy Schubert }
213*7f2fe78bSCy Schubert
214*7f2fe78bSCy Schubert if (!err) {
215*7f2fe78bSCy Schubert ccache_cit *iterator = NULL;
216*7f2fe78bSCy Schubert
217*7f2fe78bSCy Schubert err = cc_seq_fetch_NCs_begin (in_context, &iterator);
218*7f2fe78bSCy Schubert
219*7f2fe78bSCy Schubert for (i = 0; !err && i < count; i++) {
220*7f2fe78bSCy Schubert ccache_p *ccache = NULL;
221*7f2fe78bSCy Schubert
222*7f2fe78bSCy Schubert err = cc_seq_fetch_NCs_next (in_context, &ccache, iterator);
223*7f2fe78bSCy Schubert
224*7f2fe78bSCy Schubert if (!err) {
225*7f2fe78bSCy Schubert info[i] = malloc (sizeof (*info[i]));
226*7f2fe78bSCy Schubert if (info[i]) {
227*7f2fe78bSCy Schubert *info[i] = infoNC_initializer;
228*7f2fe78bSCy Schubert } else {
229*7f2fe78bSCy Schubert err = cci_check_error (CC_NOMEM);
230*7f2fe78bSCy Schubert }
231*7f2fe78bSCy Schubert }
232*7f2fe78bSCy Schubert
233*7f2fe78bSCy Schubert if (!err) {
234*7f2fe78bSCy Schubert err = cc_get_name (in_context, ccache, &info[i]->name);
235*7f2fe78bSCy Schubert }
236*7f2fe78bSCy Schubert
237*7f2fe78bSCy Schubert if (!err) {
238*7f2fe78bSCy Schubert err = cc_get_principal (in_context, ccache, &info[i]->principal);
239*7f2fe78bSCy Schubert }
240*7f2fe78bSCy Schubert
241*7f2fe78bSCy Schubert if (!err) {
242*7f2fe78bSCy Schubert err = cc_get_cred_version (in_context, ccache, &info[i]->vers);
243*7f2fe78bSCy Schubert }
244*7f2fe78bSCy Schubert
245*7f2fe78bSCy Schubert if (ccache) { cc_close (in_context, &ccache); }
246*7f2fe78bSCy Schubert }
247*7f2fe78bSCy Schubert
248*7f2fe78bSCy Schubert if (!err) {
249*7f2fe78bSCy Schubert err = cc_seq_fetch_NCs_end (in_context, &iterator);
250*7f2fe78bSCy Schubert }
251*7f2fe78bSCy Schubert }
252*7f2fe78bSCy Schubert
253*7f2fe78bSCy Schubert if (!err) {
254*7f2fe78bSCy Schubert *out_info = info;
255*7f2fe78bSCy Schubert info = NULL;
256*7f2fe78bSCy Schubert }
257*7f2fe78bSCy Schubert
258*7f2fe78bSCy Schubert if (info) { cc_free_NC_info (in_context, &info); }
259*7f2fe78bSCy Schubert
260*7f2fe78bSCy Schubert return cci_check_error (err);
261*7f2fe78bSCy Schubert }
262*7f2fe78bSCy Schubert
263*7f2fe78bSCy Schubert #if TARGET_OS_MAC
264*7f2fe78bSCy Schubert #pragma mark -
265*7f2fe78bSCy Schubert #endif
266*7f2fe78bSCy Schubert
267*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
268*7f2fe78bSCy Schubert
cc_open(apiCB * in_context,const char * in_name,cc_int32 in_version,cc_uint32 in_flags,ccache_p ** out_ccache)269*7f2fe78bSCy Schubert cc_int32 cc_open (apiCB *in_context,
270*7f2fe78bSCy Schubert const char *in_name,
271*7f2fe78bSCy Schubert cc_int32 in_version,
272*7f2fe78bSCy Schubert cc_uint32 in_flags,
273*7f2fe78bSCy Schubert ccache_p **out_ccache)
274*7f2fe78bSCy Schubert {
275*7f2fe78bSCy Schubert cc_result err = ccNoError;
276*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
277*7f2fe78bSCy Schubert cc_uint32 compat_version;
278*7f2fe78bSCy Schubert cc_uint32 real_version;
279*7f2fe78bSCy Schubert
280*7f2fe78bSCy Schubert if (!in_context) { err = cci_check_error (ccErrBadParam); }
281*7f2fe78bSCy Schubert if (!in_name ) { err = cci_check_error (ccErrBadParam); }
282*7f2fe78bSCy Schubert if (!out_ccache) { err = cci_check_error (ccErrBadParam); }
283*7f2fe78bSCy Schubert
284*7f2fe78bSCy Schubert if (!err) {
285*7f2fe78bSCy Schubert err = cci_remap_version (in_version, &compat_version);
286*7f2fe78bSCy Schubert }
287*7f2fe78bSCy Schubert
288*7f2fe78bSCy Schubert if (!err) {
289*7f2fe78bSCy Schubert err = ccapi_context_open_ccache (in_context, in_name, &ccache);
290*7f2fe78bSCy Schubert }
291*7f2fe78bSCy Schubert
292*7f2fe78bSCy Schubert /* We must not allow a CCAPI v2 caller to open a v5-only ccache
293*7f2fe78bSCy Schubert as a v4 ccache and vice versa. Allowing that would break
294*7f2fe78bSCy Schubert (valid) assumptions made by CCAPI v2 callers. */
295*7f2fe78bSCy Schubert
296*7f2fe78bSCy Schubert if (!err) {
297*7f2fe78bSCy Schubert err = ccapi_ccache_get_credentials_version (ccache, &real_version);
298*7f2fe78bSCy Schubert }
299*7f2fe78bSCy Schubert
300*7f2fe78bSCy Schubert if (!err) {
301*7f2fe78bSCy Schubert /* check the version and set up the ccache to use it */
302*7f2fe78bSCy Schubert if (compat_version & real_version) {
303*7f2fe78bSCy Schubert err = cci_ccache_set_compat_version (ccache, compat_version);
304*7f2fe78bSCy Schubert } else {
305*7f2fe78bSCy Schubert err = ccErrBadCredentialsVersion;
306*7f2fe78bSCy Schubert }
307*7f2fe78bSCy Schubert }
308*7f2fe78bSCy Schubert
309*7f2fe78bSCy Schubert if (!err) {
310*7f2fe78bSCy Schubert *out_ccache = ccache;
311*7f2fe78bSCy Schubert ccache = NULL;
312*7f2fe78bSCy Schubert }
313*7f2fe78bSCy Schubert
314*7f2fe78bSCy Schubert if (ccache) { ccapi_ccache_release (ccache); }
315*7f2fe78bSCy Schubert
316*7f2fe78bSCy Schubert return cci_remap_error (err);
317*7f2fe78bSCy Schubert }
318*7f2fe78bSCy Schubert
319*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
320*7f2fe78bSCy Schubert
cc_create(apiCB * in_context,const char * in_name,const char * in_principal,cc_int32 in_version,cc_uint32 in_flags,ccache_p ** out_ccache)321*7f2fe78bSCy Schubert cc_result cc_create (apiCB *in_context,
322*7f2fe78bSCy Schubert const char *in_name,
323*7f2fe78bSCy Schubert const char *in_principal,
324*7f2fe78bSCy Schubert cc_int32 in_version,
325*7f2fe78bSCy Schubert cc_uint32 in_flags,
326*7f2fe78bSCy Schubert ccache_p **out_ccache)
327*7f2fe78bSCy Schubert {
328*7f2fe78bSCy Schubert cc_result err = ccNoError;
329*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
330*7f2fe78bSCy Schubert cc_uint32 compat_version;
331*7f2fe78bSCy Schubert
332*7f2fe78bSCy Schubert if (!in_context) { err = cci_check_error (ccErrBadParam); }
333*7f2fe78bSCy Schubert if (!in_name ) { err = cci_check_error (ccErrBadParam); }
334*7f2fe78bSCy Schubert if (!out_ccache) { err = cci_check_error (ccErrBadParam); }
335*7f2fe78bSCy Schubert
336*7f2fe78bSCy Schubert if (!err) {
337*7f2fe78bSCy Schubert err = cci_remap_version (in_version, &compat_version);
338*7f2fe78bSCy Schubert }
339*7f2fe78bSCy Schubert
340*7f2fe78bSCy Schubert if (!err) {
341*7f2fe78bSCy Schubert err = ccapi_context_create_ccache (in_context, in_name, compat_version,
342*7f2fe78bSCy Schubert in_principal, &ccache);
343*7f2fe78bSCy Schubert }
344*7f2fe78bSCy Schubert
345*7f2fe78bSCy Schubert if (!err) {
346*7f2fe78bSCy Schubert err = cci_ccache_set_compat_version (ccache, compat_version);
347*7f2fe78bSCy Schubert }
348*7f2fe78bSCy Schubert
349*7f2fe78bSCy Schubert if (!err) {
350*7f2fe78bSCy Schubert *out_ccache = ccache;
351*7f2fe78bSCy Schubert ccache = NULL;
352*7f2fe78bSCy Schubert }
353*7f2fe78bSCy Schubert
354*7f2fe78bSCy Schubert if (ccache) { ccapi_ccache_release (ccache); }
355*7f2fe78bSCy Schubert
356*7f2fe78bSCy Schubert return cci_remap_error (err);
357*7f2fe78bSCy Schubert }
358*7f2fe78bSCy Schubert
359*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
360*7f2fe78bSCy Schubert
cc_close(apiCB * in_context,ccache_p ** io_ccache)361*7f2fe78bSCy Schubert cc_result cc_close (apiCB *in_context,
362*7f2fe78bSCy Schubert ccache_p **io_ccache)
363*7f2fe78bSCy Schubert {
364*7f2fe78bSCy Schubert cc_result err = ccNoError;
365*7f2fe78bSCy Schubert
366*7f2fe78bSCy Schubert if (!in_context) { err = cci_check_error (ccErrBadParam); }
367*7f2fe78bSCy Schubert if (!io_ccache ) { err = cci_check_error (ccErrBadParam); }
368*7f2fe78bSCy Schubert
369*7f2fe78bSCy Schubert if (!err) {
370*7f2fe78bSCy Schubert err = ccapi_ccache_release (*io_ccache);
371*7f2fe78bSCy Schubert }
372*7f2fe78bSCy Schubert
373*7f2fe78bSCy Schubert if (!err) {
374*7f2fe78bSCy Schubert *io_ccache = NULL;
375*7f2fe78bSCy Schubert }
376*7f2fe78bSCy Schubert
377*7f2fe78bSCy Schubert return cci_remap_error (err);
378*7f2fe78bSCy Schubert }
379*7f2fe78bSCy Schubert
380*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
381*7f2fe78bSCy Schubert
cc_destroy(apiCB * in_context,ccache_p ** io_ccache)382*7f2fe78bSCy Schubert cc_result cc_destroy (apiCB *in_context,
383*7f2fe78bSCy Schubert ccache_p **io_ccache)
384*7f2fe78bSCy Schubert {
385*7f2fe78bSCy Schubert cc_result err = ccNoError;
386*7f2fe78bSCy Schubert
387*7f2fe78bSCy Schubert if (!in_context) { err = cci_check_error (ccErrBadParam); }
388*7f2fe78bSCy Schubert if (!io_ccache ) { err = cci_check_error (ccErrBadParam); }
389*7f2fe78bSCy Schubert
390*7f2fe78bSCy Schubert if (!err) {
391*7f2fe78bSCy Schubert err = ccapi_ccache_destroy (*io_ccache);
392*7f2fe78bSCy Schubert }
393*7f2fe78bSCy Schubert
394*7f2fe78bSCy Schubert if (!err) {
395*7f2fe78bSCy Schubert *io_ccache = NULL;
396*7f2fe78bSCy Schubert }
397*7f2fe78bSCy Schubert
398*7f2fe78bSCy Schubert return cci_remap_error (err);
399*7f2fe78bSCy Schubert }
400*7f2fe78bSCy Schubert
401*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
402*7f2fe78bSCy Schubert
cc_get_name(apiCB * in_context,ccache_p * in_ccache,char ** out_name)403*7f2fe78bSCy Schubert cc_result cc_get_name (apiCB *in_context,
404*7f2fe78bSCy Schubert ccache_p *in_ccache,
405*7f2fe78bSCy Schubert char **out_name)
406*7f2fe78bSCy Schubert {
407*7f2fe78bSCy Schubert cc_result err = ccNoError;
408*7f2fe78bSCy Schubert cc_string_t name = NULL;
409*7f2fe78bSCy Schubert
410*7f2fe78bSCy Schubert if (!in_context) { err = cci_check_error (ccErrBadParam); }
411*7f2fe78bSCy Schubert if (!in_ccache ) { err = cci_check_error (ccErrBadParam); }
412*7f2fe78bSCy Schubert if (!out_name ) { err = cci_check_error (ccErrBadParam); }
413*7f2fe78bSCy Schubert
414*7f2fe78bSCy Schubert if (!err) {
415*7f2fe78bSCy Schubert err = ccapi_ccache_get_name (in_ccache, &name);
416*7f2fe78bSCy Schubert }
417*7f2fe78bSCy Schubert
418*7f2fe78bSCy Schubert if (!err) {
419*7f2fe78bSCy Schubert char *string = strdup (name->data);
420*7f2fe78bSCy Schubert if (string) {
421*7f2fe78bSCy Schubert *out_name = string;
422*7f2fe78bSCy Schubert } else {
423*7f2fe78bSCy Schubert err = cci_check_error (ccErrNoMem);
424*7f2fe78bSCy Schubert }
425*7f2fe78bSCy Schubert }
426*7f2fe78bSCy Schubert
427*7f2fe78bSCy Schubert if (name) { ccapi_string_release (name); }
428*7f2fe78bSCy Schubert
429*7f2fe78bSCy Schubert return cci_remap_error (err);
430*7f2fe78bSCy Schubert }
431*7f2fe78bSCy Schubert
432*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
433*7f2fe78bSCy Schubert
cc_get_cred_version(apiCB * in_context,ccache_p * in_ccache,cc_int32 * out_version)434*7f2fe78bSCy Schubert cc_result cc_get_cred_version (apiCB *in_context,
435*7f2fe78bSCy Schubert ccache_p *in_ccache,
436*7f2fe78bSCy Schubert cc_int32 *out_version)
437*7f2fe78bSCy Schubert {
438*7f2fe78bSCy Schubert cc_result err = ccNoError;
439*7f2fe78bSCy Schubert cc_uint32 compat_version;
440*7f2fe78bSCy Schubert
441*7f2fe78bSCy Schubert if (!in_context ) { err = cci_check_error (ccErrBadParam); }
442*7f2fe78bSCy Schubert if (!in_ccache ) { err = cci_check_error (ccErrBadParam); }
443*7f2fe78bSCy Schubert if (!out_version) { err = cci_check_error (ccErrBadParam); }
444*7f2fe78bSCy Schubert
445*7f2fe78bSCy Schubert if (!err) {
446*7f2fe78bSCy Schubert err = cci_ccache_get_compat_version (in_ccache, &compat_version);
447*7f2fe78bSCy Schubert }
448*7f2fe78bSCy Schubert
449*7f2fe78bSCy Schubert if (!err) {
450*7f2fe78bSCy Schubert if (compat_version == cc_credentials_v5) {
451*7f2fe78bSCy Schubert *out_version = CC_CRED_V5;
452*7f2fe78bSCy Schubert
453*7f2fe78bSCy Schubert } else {
454*7f2fe78bSCy Schubert err = ccErrBadCredentialsVersion;
455*7f2fe78bSCy Schubert }
456*7f2fe78bSCy Schubert }
457*7f2fe78bSCy Schubert
458*7f2fe78bSCy Schubert return cci_remap_error (err);
459*7f2fe78bSCy Schubert }
460*7f2fe78bSCy Schubert
461*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
462*7f2fe78bSCy Schubert
cc_set_principal(apiCB * in_context,ccache_p * io_ccache,cc_int32 in_version,char * in_principal)463*7f2fe78bSCy Schubert cc_result cc_set_principal (apiCB *in_context,
464*7f2fe78bSCy Schubert ccache_p *io_ccache,
465*7f2fe78bSCy Schubert cc_int32 in_version,
466*7f2fe78bSCy Schubert char *in_principal)
467*7f2fe78bSCy Schubert {
468*7f2fe78bSCy Schubert cc_result err = ccNoError;
469*7f2fe78bSCy Schubert cc_uint32 version;
470*7f2fe78bSCy Schubert cc_uint32 compat_version;
471*7f2fe78bSCy Schubert
472*7f2fe78bSCy Schubert if (!in_context ) { err = cci_check_error (ccErrBadParam); }
473*7f2fe78bSCy Schubert if (!io_ccache ) { err = cci_check_error (ccErrBadParam); }
474*7f2fe78bSCy Schubert if (!in_principal) { err = cci_check_error (ccErrBadParam); }
475*7f2fe78bSCy Schubert
476*7f2fe78bSCy Schubert if (!err) {
477*7f2fe78bSCy Schubert err = cci_remap_version (in_version, &version);
478*7f2fe78bSCy Schubert }
479*7f2fe78bSCy Schubert
480*7f2fe78bSCy Schubert if (!err) {
481*7f2fe78bSCy Schubert err = cci_ccache_get_compat_version (io_ccache, &compat_version);
482*7f2fe78bSCy Schubert }
483*7f2fe78bSCy Schubert
484*7f2fe78bSCy Schubert if (!err && version != compat_version) {
485*7f2fe78bSCy Schubert err = cci_check_error (ccErrBadCredentialsVersion);
486*7f2fe78bSCy Schubert }
487*7f2fe78bSCy Schubert
488*7f2fe78bSCy Schubert if (!err) {
489*7f2fe78bSCy Schubert err = ccapi_ccache_set_principal (io_ccache, version, in_principal);
490*7f2fe78bSCy Schubert }
491*7f2fe78bSCy Schubert
492*7f2fe78bSCy Schubert return cci_remap_error (err);
493*7f2fe78bSCy Schubert }
494*7f2fe78bSCy Schubert
495*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
496*7f2fe78bSCy Schubert
cc_get_principal(apiCB * in_context,ccache_p * in_ccache,char ** out_principal)497*7f2fe78bSCy Schubert cc_result cc_get_principal (apiCB *in_context,
498*7f2fe78bSCy Schubert ccache_p *in_ccache,
499*7f2fe78bSCy Schubert char **out_principal)
500*7f2fe78bSCy Schubert {
501*7f2fe78bSCy Schubert cc_result err = ccNoError;
502*7f2fe78bSCy Schubert cc_uint32 compat_version;
503*7f2fe78bSCy Schubert cc_string_t principal = NULL;
504*7f2fe78bSCy Schubert
505*7f2fe78bSCy Schubert if (!in_context ) { err = cci_check_error (ccErrBadParam); }
506*7f2fe78bSCy Schubert if (!in_ccache ) { err = cci_check_error (ccErrBadParam); }
507*7f2fe78bSCy Schubert if (!out_principal) { err = cci_check_error (ccErrBadParam); }
508*7f2fe78bSCy Schubert
509*7f2fe78bSCy Schubert if (!err) {
510*7f2fe78bSCy Schubert err = cci_ccache_get_compat_version (in_ccache, &compat_version);
511*7f2fe78bSCy Schubert }
512*7f2fe78bSCy Schubert
513*7f2fe78bSCy Schubert if (!err) {
514*7f2fe78bSCy Schubert err = ccapi_ccache_get_principal (in_ccache, compat_version, &principal);
515*7f2fe78bSCy Schubert }
516*7f2fe78bSCy Schubert
517*7f2fe78bSCy Schubert if (!err) {
518*7f2fe78bSCy Schubert char *string = strdup (principal->data);
519*7f2fe78bSCy Schubert if (string) {
520*7f2fe78bSCy Schubert *out_principal = string;
521*7f2fe78bSCy Schubert } else {
522*7f2fe78bSCy Schubert err = cci_check_error (ccErrNoMem);
523*7f2fe78bSCy Schubert }
524*7f2fe78bSCy Schubert }
525*7f2fe78bSCy Schubert
526*7f2fe78bSCy Schubert if (principal) { ccapi_string_release (principal); }
527*7f2fe78bSCy Schubert
528*7f2fe78bSCy Schubert return cci_remap_error (err);
529*7f2fe78bSCy Schubert }
530*7f2fe78bSCy Schubert
531*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
532*7f2fe78bSCy Schubert
cc_store(apiCB * in_context,ccache_p * io_ccache,cred_union in_credentials)533*7f2fe78bSCy Schubert cc_result cc_store (apiCB *in_context,
534*7f2fe78bSCy Schubert ccache_p *io_ccache,
535*7f2fe78bSCy Schubert cred_union in_credentials)
536*7f2fe78bSCy Schubert {
537*7f2fe78bSCy Schubert cc_result err = ccNoError;
538*7f2fe78bSCy Schubert cc_credentials_union *creds_union = NULL;
539*7f2fe78bSCy Schubert
540*7f2fe78bSCy Schubert if (!in_context) { err = cci_check_error (ccErrBadParam); }
541*7f2fe78bSCy Schubert if (!io_ccache ) { err = cci_check_error (ccErrBadParam); }
542*7f2fe78bSCy Schubert
543*7f2fe78bSCy Schubert if (!err) {
544*7f2fe78bSCy Schubert err = cci_cred_union_to_credentials_union (&in_credentials,
545*7f2fe78bSCy Schubert &creds_union);
546*7f2fe78bSCy Schubert }
547*7f2fe78bSCy Schubert
548*7f2fe78bSCy Schubert if (!err) {
549*7f2fe78bSCy Schubert err = ccapi_ccache_store_credentials (io_ccache, creds_union);
550*7f2fe78bSCy Schubert }
551*7f2fe78bSCy Schubert
552*7f2fe78bSCy Schubert if (creds_union) { cci_credentials_union_release (creds_union); }
553*7f2fe78bSCy Schubert return cci_remap_error (err);
554*7f2fe78bSCy Schubert }
555*7f2fe78bSCy Schubert
556*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
557*7f2fe78bSCy Schubert
cc_remove_cred(apiCB * in_context,ccache_p * in_ccache,cred_union in_credentials)558*7f2fe78bSCy Schubert cc_result cc_remove_cred (apiCB *in_context,
559*7f2fe78bSCy Schubert ccache_p *in_ccache,
560*7f2fe78bSCy Schubert cred_union in_credentials)
561*7f2fe78bSCy Schubert {
562*7f2fe78bSCy Schubert cc_result err = ccNoError;
563*7f2fe78bSCy Schubert cc_credentials_iterator_t iterator = NULL;
564*7f2fe78bSCy Schubert cc_uint32 found = 0;
565*7f2fe78bSCy Schubert
566*7f2fe78bSCy Schubert if (!in_context) { err = cci_check_error (ccErrBadParam); }
567*7f2fe78bSCy Schubert if (!in_ccache ) { err = cci_check_error (ccErrBadParam); }
568*7f2fe78bSCy Schubert
569*7f2fe78bSCy Schubert if (!err) {
570*7f2fe78bSCy Schubert err = ccapi_ccache_new_credentials_iterator (in_ccache, &iterator);
571*7f2fe78bSCy Schubert }
572*7f2fe78bSCy Schubert
573*7f2fe78bSCy Schubert while (!err && !found) {
574*7f2fe78bSCy Schubert cc_credentials_t creds = NULL;
575*7f2fe78bSCy Schubert
576*7f2fe78bSCy Schubert err = ccapi_credentials_iterator_next (iterator, &creds);
577*7f2fe78bSCy Schubert
578*7f2fe78bSCy Schubert if (!err) {
579*7f2fe78bSCy Schubert err = cci_cred_union_compare_to_credentials_union (&in_credentials,
580*7f2fe78bSCy Schubert creds->data,
581*7f2fe78bSCy Schubert &found);
582*7f2fe78bSCy Schubert }
583*7f2fe78bSCy Schubert
584*7f2fe78bSCy Schubert if (!err && found) {
585*7f2fe78bSCy Schubert err = ccapi_ccache_remove_credentials (in_ccache, creds);
586*7f2fe78bSCy Schubert }
587*7f2fe78bSCy Schubert
588*7f2fe78bSCy Schubert ccapi_credentials_release (creds);
589*7f2fe78bSCy Schubert }
590*7f2fe78bSCy Schubert if (err == ccIteratorEnd) { err = cci_check_error (ccErrCredentialsNotFound); }
591*7f2fe78bSCy Schubert
592*7f2fe78bSCy Schubert return cci_remap_error (err);
593*7f2fe78bSCy Schubert }
594*7f2fe78bSCy Schubert
595*7f2fe78bSCy Schubert #if TARGET_OS_MAC
596*7f2fe78bSCy Schubert #pragma mark -
597*7f2fe78bSCy Schubert #endif
598*7f2fe78bSCy Schubert
599*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
600*7f2fe78bSCy Schubert
cc_seq_fetch_NCs_begin(apiCB * in_context,ccache_cit ** out_iterator)601*7f2fe78bSCy Schubert cc_result cc_seq_fetch_NCs_begin (apiCB *in_context,
602*7f2fe78bSCy Schubert ccache_cit **out_iterator)
603*7f2fe78bSCy Schubert {
604*7f2fe78bSCy Schubert cc_result err = ccNoError;
605*7f2fe78bSCy Schubert cc_ccache_iterator_t iterator = NULL;
606*7f2fe78bSCy Schubert
607*7f2fe78bSCy Schubert if (!in_context ) { err = cci_check_error (ccErrBadParam); }
608*7f2fe78bSCy Schubert if (!out_iterator) { err = cci_check_error (ccErrBadParam); }
609*7f2fe78bSCy Schubert
610*7f2fe78bSCy Schubert if (!err) {
611*7f2fe78bSCy Schubert err = ccapi_context_new_ccache_iterator (in_context, &iterator);
612*7f2fe78bSCy Schubert }
613*7f2fe78bSCy Schubert
614*7f2fe78bSCy Schubert if (!err) {
615*7f2fe78bSCy Schubert *out_iterator = (ccache_cit *) iterator;
616*7f2fe78bSCy Schubert iterator = NULL; /* take ownership */
617*7f2fe78bSCy Schubert }
618*7f2fe78bSCy Schubert
619*7f2fe78bSCy Schubert if (iterator) { ccapi_ccache_iterator_release (iterator); }
620*7f2fe78bSCy Schubert
621*7f2fe78bSCy Schubert return cci_remap_error (err);
622*7f2fe78bSCy Schubert }
623*7f2fe78bSCy Schubert
624*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
625*7f2fe78bSCy Schubert
cc_seq_fetch_NCs_next(apiCB * in_context,ccache_p ** out_ccache,ccache_cit * in_iterator)626*7f2fe78bSCy Schubert cc_result cc_seq_fetch_NCs_next (apiCB *in_context,
627*7f2fe78bSCy Schubert ccache_p **out_ccache,
628*7f2fe78bSCy Schubert ccache_cit *in_iterator)
629*7f2fe78bSCy Schubert {
630*7f2fe78bSCy Schubert cc_result err = ccNoError;
631*7f2fe78bSCy Schubert cc_ccache_iterator_t iterator = (cc_ccache_iterator_t) in_iterator;
632*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
633*7f2fe78bSCy Schubert const char *saved_ccache_name;
634*7f2fe78bSCy Schubert
635*7f2fe78bSCy Schubert if (!in_context ) { err = cci_check_error (ccErrBadParam); }
636*7f2fe78bSCy Schubert if (!out_ccache ) { err = cci_check_error (ccErrBadParam); }
637*7f2fe78bSCy Schubert if (!in_iterator) { err = cci_check_error (ccErrBadParam); }
638*7f2fe78bSCy Schubert
639*7f2fe78bSCy Schubert if (!err) {
640*7f2fe78bSCy Schubert err = cci_ccache_iterator_get_saved_ccache_name (iterator,
641*7f2fe78bSCy Schubert &saved_ccache_name);
642*7f2fe78bSCy Schubert }
643*7f2fe78bSCy Schubert
644*7f2fe78bSCy Schubert if (!err) {
645*7f2fe78bSCy Schubert if (saved_ccache_name) {
646*7f2fe78bSCy Schubert err = ccapi_context_open_ccache (in_context, saved_ccache_name,
647*7f2fe78bSCy Schubert &ccache);
648*7f2fe78bSCy Schubert
649*7f2fe78bSCy Schubert if (!err) {
650*7f2fe78bSCy Schubert err = cci_ccache_set_compat_version (ccache, cc_credentials_v5);
651*7f2fe78bSCy Schubert }
652*7f2fe78bSCy Schubert
653*7f2fe78bSCy Schubert if (!err) {
654*7f2fe78bSCy Schubert err = cci_ccache_iterator_set_saved_ccache_name (iterator, NULL);
655*7f2fe78bSCy Schubert }
656*7f2fe78bSCy Schubert
657*7f2fe78bSCy Schubert } else {
658*7f2fe78bSCy Schubert cc_uint32 version = 0;
659*7f2fe78bSCy Schubert
660*7f2fe78bSCy Schubert err = ccapi_ccache_iterator_next (iterator, &ccache);
661*7f2fe78bSCy Schubert
662*7f2fe78bSCy Schubert if (!err) {
663*7f2fe78bSCy Schubert err = ccapi_ccache_get_credentials_version (ccache, &version);
664*7f2fe78bSCy Schubert }
665*7f2fe78bSCy Schubert
666*7f2fe78bSCy Schubert if (!err) {
667*7f2fe78bSCy Schubert err = cci_ccache_set_compat_version (ccache, version);
668*7f2fe78bSCy Schubert }
669*7f2fe78bSCy Schubert }
670*7f2fe78bSCy Schubert }
671*7f2fe78bSCy Schubert
672*7f2fe78bSCy Schubert if (!err) {
673*7f2fe78bSCy Schubert *out_ccache = ccache;
674*7f2fe78bSCy Schubert ccache = NULL; /* take ownership */
675*7f2fe78bSCy Schubert }
676*7f2fe78bSCy Schubert
677*7f2fe78bSCy Schubert if (ccache) { ccapi_ccache_release (ccache); }
678*7f2fe78bSCy Schubert
679*7f2fe78bSCy Schubert return cci_remap_error (err);
680*7f2fe78bSCy Schubert }
681*7f2fe78bSCy Schubert
682*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
683*7f2fe78bSCy Schubert
cc_seq_fetch_NCs_end(apiCB * in_context,ccache_cit ** io_iterator)684*7f2fe78bSCy Schubert cc_result cc_seq_fetch_NCs_end (apiCB *in_context,
685*7f2fe78bSCy Schubert ccache_cit **io_iterator)
686*7f2fe78bSCy Schubert {
687*7f2fe78bSCy Schubert cc_result err = ccNoError;
688*7f2fe78bSCy Schubert cc_ccache_iterator_t iterator = (cc_ccache_iterator_t) *io_iterator;
689*7f2fe78bSCy Schubert
690*7f2fe78bSCy Schubert if (!in_context ) { err = cci_check_error (ccErrBadParam); }
691*7f2fe78bSCy Schubert if (!io_iterator) { err = cci_check_error (ccErrBadParam); }
692*7f2fe78bSCy Schubert
693*7f2fe78bSCy Schubert if (!err) {
694*7f2fe78bSCy Schubert err = ccapi_ccache_iterator_release (iterator);
695*7f2fe78bSCy Schubert }
696*7f2fe78bSCy Schubert
697*7f2fe78bSCy Schubert if (!err) {
698*7f2fe78bSCy Schubert *io_iterator = NULL;
699*7f2fe78bSCy Schubert }
700*7f2fe78bSCy Schubert
701*7f2fe78bSCy Schubert return cci_remap_error (err);
702*7f2fe78bSCy Schubert }
703*7f2fe78bSCy Schubert
704*7f2fe78bSCy Schubert #if TARGET_OS_MAC
705*7f2fe78bSCy Schubert #pragma mark -
706*7f2fe78bSCy Schubert #endif
707*7f2fe78bSCy Schubert
708*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
709*7f2fe78bSCy Schubert
cc_seq_fetch_creds_begin(apiCB * in_context,const ccache_p * in_ccache,ccache_cit ** out_iterator)710*7f2fe78bSCy Schubert cc_result cc_seq_fetch_creds_begin (apiCB *in_context,
711*7f2fe78bSCy Schubert const ccache_p *in_ccache,
712*7f2fe78bSCy Schubert ccache_cit **out_iterator)
713*7f2fe78bSCy Schubert {
714*7f2fe78bSCy Schubert cc_result err = ccNoError;
715*7f2fe78bSCy Schubert cc_credentials_iterator_t iterator = NULL;
716*7f2fe78bSCy Schubert cc_uint32 compat_version;
717*7f2fe78bSCy Schubert
718*7f2fe78bSCy Schubert if (!in_context ) { err = cci_check_error (ccErrBadParam); }
719*7f2fe78bSCy Schubert if (!in_ccache ) { err = cci_check_error (ccErrBadParam); }
720*7f2fe78bSCy Schubert if (!out_iterator) { err = cci_check_error (ccErrBadParam); }
721*7f2fe78bSCy Schubert
722*7f2fe78bSCy Schubert if (!err) {
723*7f2fe78bSCy Schubert err = cci_ccache_get_compat_version ((cc_ccache_t) in_ccache,
724*7f2fe78bSCy Schubert &compat_version);
725*7f2fe78bSCy Schubert }
726*7f2fe78bSCy Schubert
727*7f2fe78bSCy Schubert if (!err) {
728*7f2fe78bSCy Schubert err = ccapi_ccache_new_credentials_iterator ((cc_ccache_t) in_ccache,
729*7f2fe78bSCy Schubert &iterator);
730*7f2fe78bSCy Schubert }
731*7f2fe78bSCy Schubert
732*7f2fe78bSCy Schubert if (!err) {
733*7f2fe78bSCy Schubert err = cci_credentials_iterator_set_compat_version (iterator,
734*7f2fe78bSCy Schubert compat_version);
735*7f2fe78bSCy Schubert }
736*7f2fe78bSCy Schubert
737*7f2fe78bSCy Schubert if (!err) {
738*7f2fe78bSCy Schubert *out_iterator = (ccache_cit *) iterator;
739*7f2fe78bSCy Schubert iterator = NULL; /* take ownership */
740*7f2fe78bSCy Schubert }
741*7f2fe78bSCy Schubert
742*7f2fe78bSCy Schubert if (iterator) { ccapi_credentials_iterator_release (iterator); }
743*7f2fe78bSCy Schubert
744*7f2fe78bSCy Schubert return cci_remap_error (err);
745*7f2fe78bSCy Schubert }
746*7f2fe78bSCy Schubert
747*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
748*7f2fe78bSCy Schubert
cc_seq_fetch_creds_next(apiCB * in_context,cred_union ** out_creds,ccache_cit * in_iterator)749*7f2fe78bSCy Schubert cc_result cc_seq_fetch_creds_next (apiCB *in_context,
750*7f2fe78bSCy Schubert cred_union **out_creds,
751*7f2fe78bSCy Schubert ccache_cit *in_iterator)
752*7f2fe78bSCy Schubert {
753*7f2fe78bSCy Schubert cc_result err = ccNoError;
754*7f2fe78bSCy Schubert cc_credentials_iterator_t iterator = (cc_credentials_iterator_t) in_iterator;
755*7f2fe78bSCy Schubert cc_uint32 compat_version;
756*7f2fe78bSCy Schubert
757*7f2fe78bSCy Schubert if (!in_context ) { err = cci_check_error (ccErrBadParam); }
758*7f2fe78bSCy Schubert if (!out_creds ) { err = cci_check_error (ccErrBadParam); }
759*7f2fe78bSCy Schubert if (!in_iterator) { err = cci_check_error (ccErrBadParam); }
760*7f2fe78bSCy Schubert
761*7f2fe78bSCy Schubert if (!err) {
762*7f2fe78bSCy Schubert err = cci_credentials_iterator_get_compat_version (iterator,
763*7f2fe78bSCy Schubert &compat_version);
764*7f2fe78bSCy Schubert }
765*7f2fe78bSCy Schubert
766*7f2fe78bSCy Schubert while (!err) {
767*7f2fe78bSCy Schubert cc_credentials_t credentials = NULL;
768*7f2fe78bSCy Schubert
769*7f2fe78bSCy Schubert err = ccapi_credentials_iterator_next (iterator, &credentials);
770*7f2fe78bSCy Schubert
771*7f2fe78bSCy Schubert if (!err && (credentials->data->version & compat_version)) {
772*7f2fe78bSCy Schubert /* got the next credentials for the correct version */
773*7f2fe78bSCy Schubert err = cci_credentials_union_to_cred_union (credentials->data,
774*7f2fe78bSCy Schubert out_creds);
775*7f2fe78bSCy Schubert break;
776*7f2fe78bSCy Schubert }
777*7f2fe78bSCy Schubert
778*7f2fe78bSCy Schubert if (credentials) { ccapi_credentials_release (credentials); }
779*7f2fe78bSCy Schubert }
780*7f2fe78bSCy Schubert
781*7f2fe78bSCy Schubert return cci_remap_error (err);
782*7f2fe78bSCy Schubert }
783*7f2fe78bSCy Schubert
784*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
785*7f2fe78bSCy Schubert
cc_seq_fetch_creds_end(apiCB * in_context,ccache_cit ** io_iterator)786*7f2fe78bSCy Schubert cc_result cc_seq_fetch_creds_end (apiCB *in_context,
787*7f2fe78bSCy Schubert ccache_cit **io_iterator)
788*7f2fe78bSCy Schubert {
789*7f2fe78bSCy Schubert cc_result err = ccNoError;
790*7f2fe78bSCy Schubert cc_credentials_iterator_t iterator = (cc_credentials_iterator_t) *io_iterator;
791*7f2fe78bSCy Schubert
792*7f2fe78bSCy Schubert if (!in_context ) { err = cci_check_error (ccErrBadParam); }
793*7f2fe78bSCy Schubert if (!io_iterator) { err = cci_check_error (ccErrBadParam); }
794*7f2fe78bSCy Schubert
795*7f2fe78bSCy Schubert if (!err) {
796*7f2fe78bSCy Schubert err = ccapi_credentials_iterator_release (iterator);
797*7f2fe78bSCy Schubert }
798*7f2fe78bSCy Schubert
799*7f2fe78bSCy Schubert if (!err) {
800*7f2fe78bSCy Schubert *io_iterator = NULL;
801*7f2fe78bSCy Schubert }
802*7f2fe78bSCy Schubert
803*7f2fe78bSCy Schubert return cci_remap_error (err);
804*7f2fe78bSCy Schubert }
805*7f2fe78bSCy Schubert
806*7f2fe78bSCy Schubert #if TARGET_OS_MAC
807*7f2fe78bSCy Schubert #pragma mark -
808*7f2fe78bSCy Schubert #endif
809*7f2fe78bSCy Schubert
810*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
811*7f2fe78bSCy Schubert
cc_free_principal(apiCB * in_context,char ** io_principal)812*7f2fe78bSCy Schubert cc_result cc_free_principal (apiCB *in_context,
813*7f2fe78bSCy Schubert char **io_principal)
814*7f2fe78bSCy Schubert {
815*7f2fe78bSCy Schubert cc_result err = ccNoError;
816*7f2fe78bSCy Schubert
817*7f2fe78bSCy Schubert if (!in_context ) { err = cci_check_error (ccErrBadParam); }
818*7f2fe78bSCy Schubert if (!io_principal) { err = cci_check_error (ccErrBadParam); }
819*7f2fe78bSCy Schubert
820*7f2fe78bSCy Schubert if (!err) {
821*7f2fe78bSCy Schubert free (*io_principal);
822*7f2fe78bSCy Schubert *io_principal = NULL;
823*7f2fe78bSCy Schubert }
824*7f2fe78bSCy Schubert
825*7f2fe78bSCy Schubert return cci_remap_error (err);
826*7f2fe78bSCy Schubert }
827*7f2fe78bSCy Schubert
828*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
829*7f2fe78bSCy Schubert
cc_free_name(apiCB * in_context,char ** io_name)830*7f2fe78bSCy Schubert cc_result cc_free_name (apiCB *in_context,
831*7f2fe78bSCy Schubert char **io_name)
832*7f2fe78bSCy Schubert {
833*7f2fe78bSCy Schubert cc_result err = ccNoError;
834*7f2fe78bSCy Schubert
835*7f2fe78bSCy Schubert if (!in_context) { err = cci_check_error (ccErrBadParam); }
836*7f2fe78bSCy Schubert if (!io_name ) { err = cci_check_error (ccErrBadParam); }
837*7f2fe78bSCy Schubert
838*7f2fe78bSCy Schubert if (!err) {
839*7f2fe78bSCy Schubert free (*io_name);
840*7f2fe78bSCy Schubert *io_name = NULL;
841*7f2fe78bSCy Schubert }
842*7f2fe78bSCy Schubert
843*7f2fe78bSCy Schubert return cci_remap_error (err);
844*7f2fe78bSCy Schubert }
845*7f2fe78bSCy Schubert
846*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
847*7f2fe78bSCy Schubert
cc_free_creds(apiCB * in_context,cred_union ** io_credentials)848*7f2fe78bSCy Schubert cc_result cc_free_creds (apiCB *in_context,
849*7f2fe78bSCy Schubert cred_union **io_credentials)
850*7f2fe78bSCy Schubert {
851*7f2fe78bSCy Schubert cc_result err = ccNoError;
852*7f2fe78bSCy Schubert
853*7f2fe78bSCy Schubert if (!in_context ) { err = cci_check_error (ccErrBadParam); }
854*7f2fe78bSCy Schubert if (!io_credentials) { err = cci_check_error (ccErrBadParam); }
855*7f2fe78bSCy Schubert
856*7f2fe78bSCy Schubert if (!err) {
857*7f2fe78bSCy Schubert err = cci_cred_union_release (*io_credentials);
858*7f2fe78bSCy Schubert if (!err) { *io_credentials = NULL; }
859*7f2fe78bSCy Schubert }
860*7f2fe78bSCy Schubert
861*7f2fe78bSCy Schubert return cci_remap_error (err);
862*7f2fe78bSCy Schubert }
863*7f2fe78bSCy Schubert
864*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
865*7f2fe78bSCy Schubert
cc_free_NC_info(apiCB * in_context,infoNC *** io_info)866*7f2fe78bSCy Schubert cc_result cc_free_NC_info (apiCB *in_context,
867*7f2fe78bSCy Schubert infoNC ***io_info)
868*7f2fe78bSCy Schubert {
869*7f2fe78bSCy Schubert cc_result err = ccNoError;
870*7f2fe78bSCy Schubert
871*7f2fe78bSCy Schubert if (!in_context) { err = cci_check_error (ccErrBadParam); }
872*7f2fe78bSCy Schubert if (!io_info ) { err = cci_check_error (ccErrBadParam); }
873*7f2fe78bSCy Schubert
874*7f2fe78bSCy Schubert if (!err && *io_info) {
875*7f2fe78bSCy Schubert infoNC **data = *io_info;
876*7f2fe78bSCy Schubert int i;
877*7f2fe78bSCy Schubert
878*7f2fe78bSCy Schubert for (i = 0; data[i] != NULL; i++) {
879*7f2fe78bSCy Schubert cc_free_principal (in_context, &data[i]->principal);
880*7f2fe78bSCy Schubert cc_free_name (in_context, &data[i]->name);
881*7f2fe78bSCy Schubert free (data[i]);
882*7f2fe78bSCy Schubert }
883*7f2fe78bSCy Schubert free (data);
884*7f2fe78bSCy Schubert
885*7f2fe78bSCy Schubert *io_info = NULL;
886*7f2fe78bSCy Schubert }
887*7f2fe78bSCy Schubert
888*7f2fe78bSCy Schubert return cci_remap_error (err);
889*7f2fe78bSCy Schubert }
890