xref: /freebsd/crypto/krb5/src/ccapi/lib/ccapi_ccache.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert /* ccapi/lib/ccapi_ccache.c */
2*7f2fe78bSCy Schubert /*
3*7f2fe78bSCy Schubert  * Copyright 2006, 2007 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 "ccapi_ccache.h"
27*7f2fe78bSCy Schubert 
28*7f2fe78bSCy Schubert #include "ccapi_string.h"
29*7f2fe78bSCy Schubert #include "ccapi_credentials.h"
30*7f2fe78bSCy Schubert #include "ccapi_credentials_iterator.h"
31*7f2fe78bSCy Schubert #include "ccapi_ipc.h"
32*7f2fe78bSCy Schubert 
33*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
34*7f2fe78bSCy Schubert 
35*7f2fe78bSCy Schubert typedef struct cci_ccache_d {
36*7f2fe78bSCy Schubert     cc_ccache_f *functions;
37*7f2fe78bSCy Schubert #if TARGET_OS_MAC
38*7f2fe78bSCy Schubert     cc_ccache_f *vector_functions;
39*7f2fe78bSCy Schubert #endif
40*7f2fe78bSCy Schubert     cci_identifier_t identifier;
41*7f2fe78bSCy Schubert     cc_time_t last_wait_for_change_time;
42*7f2fe78bSCy Schubert     cc_uint32 compat_version;
43*7f2fe78bSCy Schubert } *cci_ccache_t;
44*7f2fe78bSCy Schubert 
45*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
46*7f2fe78bSCy Schubert 
47*7f2fe78bSCy Schubert struct cci_ccache_d cci_ccache_initializer = {
48*7f2fe78bSCy Schubert     NULL
49*7f2fe78bSCy Schubert     VECTOR_FUNCTIONS_INITIALIZER,
50*7f2fe78bSCy Schubert     NULL,
51*7f2fe78bSCy Schubert     0
52*7f2fe78bSCy Schubert };
53*7f2fe78bSCy Schubert 
54*7f2fe78bSCy Schubert cc_ccache_f cci_ccache_f_initializer = {
55*7f2fe78bSCy Schubert     ccapi_ccache_release,
56*7f2fe78bSCy Schubert     ccapi_ccache_destroy,
57*7f2fe78bSCy Schubert     ccapi_ccache_set_default,
58*7f2fe78bSCy Schubert     ccapi_ccache_get_credentials_version,
59*7f2fe78bSCy Schubert     ccapi_ccache_get_name,
60*7f2fe78bSCy Schubert     ccapi_ccache_get_principal,
61*7f2fe78bSCy Schubert     ccapi_ccache_set_principal,
62*7f2fe78bSCy Schubert     ccapi_ccache_store_credentials,
63*7f2fe78bSCy Schubert     ccapi_ccache_remove_credentials,
64*7f2fe78bSCy Schubert     ccapi_ccache_new_credentials_iterator,
65*7f2fe78bSCy Schubert     ccapi_ccache_move,
66*7f2fe78bSCy Schubert     ccapi_ccache_lock,
67*7f2fe78bSCy Schubert     ccapi_ccache_unlock,
68*7f2fe78bSCy Schubert     ccapi_ccache_get_last_default_time,
69*7f2fe78bSCy Schubert     ccapi_ccache_get_change_time,
70*7f2fe78bSCy Schubert     ccapi_ccache_compare,
71*7f2fe78bSCy Schubert     ccapi_ccache_get_kdc_time_offset,
72*7f2fe78bSCy Schubert     ccapi_ccache_set_kdc_time_offset,
73*7f2fe78bSCy Schubert     ccapi_ccache_clear_kdc_time_offset,
74*7f2fe78bSCy Schubert     ccapi_ccache_wait_for_change
75*7f2fe78bSCy Schubert };
76*7f2fe78bSCy Schubert 
77*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
78*7f2fe78bSCy Schubert 
cci_ccache_new(cc_ccache_t * out_ccache,cci_identifier_t in_identifier)79*7f2fe78bSCy Schubert cc_int32 cci_ccache_new (cc_ccache_t      *out_ccache,
80*7f2fe78bSCy Schubert                          cci_identifier_t  in_identifier)
81*7f2fe78bSCy Schubert {
82*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
83*7f2fe78bSCy Schubert     cci_ccache_t ccache = NULL;
84*7f2fe78bSCy Schubert 
85*7f2fe78bSCy Schubert     if (!out_ccache   ) { err = cci_check_error (ccErrBadParam); }
86*7f2fe78bSCy Schubert     if (!in_identifier) { err = cci_check_error (ccErrBadParam); }
87*7f2fe78bSCy Schubert 
88*7f2fe78bSCy Schubert     if (!err) {
89*7f2fe78bSCy Schubert         ccache = malloc (sizeof (*ccache));
90*7f2fe78bSCy Schubert         if (ccache) {
91*7f2fe78bSCy Schubert             *ccache = cci_ccache_initializer;
92*7f2fe78bSCy Schubert         } else {
93*7f2fe78bSCy Schubert             err = cci_check_error (ccErrNoMem);
94*7f2fe78bSCy Schubert         }
95*7f2fe78bSCy Schubert     }
96*7f2fe78bSCy Schubert 
97*7f2fe78bSCy Schubert     if (!err) {
98*7f2fe78bSCy Schubert         ccache->functions = malloc (sizeof (*ccache->functions));
99*7f2fe78bSCy Schubert         if (ccache->functions) {
100*7f2fe78bSCy Schubert             *ccache->functions = cci_ccache_f_initializer;
101*7f2fe78bSCy Schubert         } else {
102*7f2fe78bSCy Schubert             err = cci_check_error (ccErrNoMem);
103*7f2fe78bSCy Schubert         }
104*7f2fe78bSCy Schubert     }
105*7f2fe78bSCy Schubert 
106*7f2fe78bSCy Schubert     if (!err) {
107*7f2fe78bSCy Schubert         err = cci_identifier_copy (&ccache->identifier, in_identifier);
108*7f2fe78bSCy Schubert     }
109*7f2fe78bSCy Schubert 
110*7f2fe78bSCy Schubert     if (!err) {
111*7f2fe78bSCy Schubert         *out_ccache = (cc_ccache_t) ccache;
112*7f2fe78bSCy Schubert         ccache = NULL; /* take ownership */
113*7f2fe78bSCy Schubert     }
114*7f2fe78bSCy Schubert 
115*7f2fe78bSCy Schubert     ccapi_ccache_release ((cc_ccache_t) ccache);
116*7f2fe78bSCy Schubert 
117*7f2fe78bSCy Schubert     return cci_check_error (err);
118*7f2fe78bSCy Schubert }
119*7f2fe78bSCy Schubert 
120*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
121*7f2fe78bSCy Schubert 
cci_ccache_write(cc_ccache_t in_ccache,k5_ipc_stream in_stream)122*7f2fe78bSCy Schubert cc_int32 cci_ccache_write (cc_ccache_t  in_ccache,
123*7f2fe78bSCy Schubert                            k5_ipc_stream in_stream)
124*7f2fe78bSCy Schubert {
125*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
126*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) in_ccache;
127*7f2fe78bSCy Schubert 
128*7f2fe78bSCy Schubert     if (!in_ccache) { err = cci_check_error (ccErrBadParam); }
129*7f2fe78bSCy Schubert     if (!in_stream) { err = cci_check_error (ccErrBadParam); }
130*7f2fe78bSCy Schubert 
131*7f2fe78bSCy Schubert     if (!err) {
132*7f2fe78bSCy Schubert         err = cci_identifier_write (ccache->identifier, in_stream);
133*7f2fe78bSCy Schubert     }
134*7f2fe78bSCy Schubert 
135*7f2fe78bSCy Schubert     return cci_check_error (err);
136*7f2fe78bSCy Schubert }
137*7f2fe78bSCy Schubert 
138*7f2fe78bSCy Schubert #ifdef TARGET_OS_MAC
139*7f2fe78bSCy Schubert #pragma mark -
140*7f2fe78bSCy Schubert #endif
141*7f2fe78bSCy Schubert 
142*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
143*7f2fe78bSCy Schubert 
ccapi_ccache_release(cc_ccache_t io_ccache)144*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_release (cc_ccache_t io_ccache)
145*7f2fe78bSCy Schubert {
146*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
147*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) io_ccache;
148*7f2fe78bSCy Schubert 
149*7f2fe78bSCy Schubert     if (!io_ccache) { err = ccErrBadParam; }
150*7f2fe78bSCy Schubert 
151*7f2fe78bSCy Schubert     if (!err) {
152*7f2fe78bSCy Schubert         cci_identifier_release (ccache->identifier);
153*7f2fe78bSCy Schubert 
154*7f2fe78bSCy Schubert         free ((char *) ccache->functions);
155*7f2fe78bSCy Schubert         free (ccache);
156*7f2fe78bSCy Schubert     }
157*7f2fe78bSCy Schubert 
158*7f2fe78bSCy Schubert     return err;
159*7f2fe78bSCy Schubert }
160*7f2fe78bSCy Schubert 
161*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
162*7f2fe78bSCy Schubert 
ccapi_ccache_destroy(cc_ccache_t io_ccache)163*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_destroy (cc_ccache_t io_ccache)
164*7f2fe78bSCy Schubert {
165*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
166*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) io_ccache;
167*7f2fe78bSCy Schubert 
168*7f2fe78bSCy Schubert     if (!io_ccache) { err = cci_check_error (ccErrBadParam); }
169*7f2fe78bSCy Schubert 
170*7f2fe78bSCy Schubert     if (!err) {
171*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_destroy_msg_id,
172*7f2fe78bSCy Schubert                              ccache->identifier,
173*7f2fe78bSCy Schubert                              NULL,
174*7f2fe78bSCy Schubert                              NULL);
175*7f2fe78bSCy Schubert     }
176*7f2fe78bSCy Schubert 
177*7f2fe78bSCy Schubert     if (!err) {
178*7f2fe78bSCy Schubert         err = ccapi_ccache_release (io_ccache);
179*7f2fe78bSCy Schubert     }
180*7f2fe78bSCy Schubert 
181*7f2fe78bSCy Schubert     return cci_check_error (err);
182*7f2fe78bSCy Schubert }
183*7f2fe78bSCy Schubert 
184*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
185*7f2fe78bSCy Schubert 
ccapi_ccache_set_default(cc_ccache_t io_ccache)186*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_set_default (cc_ccache_t io_ccache)
187*7f2fe78bSCy Schubert {
188*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
189*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) io_ccache;
190*7f2fe78bSCy Schubert 
191*7f2fe78bSCy Schubert     if (!io_ccache) { err = cci_check_error (ccErrBadParam); }
192*7f2fe78bSCy Schubert 
193*7f2fe78bSCy Schubert     if (!err) {
194*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_set_default_msg_id,
195*7f2fe78bSCy Schubert                              ccache->identifier,
196*7f2fe78bSCy Schubert                              NULL,
197*7f2fe78bSCy Schubert                              NULL);
198*7f2fe78bSCy Schubert     }
199*7f2fe78bSCy Schubert 
200*7f2fe78bSCy Schubert     return cci_check_error (err);
201*7f2fe78bSCy Schubert }
202*7f2fe78bSCy Schubert 
203*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
204*7f2fe78bSCy Schubert 
ccapi_ccache_get_credentials_version(cc_ccache_t in_ccache,cc_uint32 * out_credentials_version)205*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_get_credentials_version (cc_ccache_t  in_ccache,
206*7f2fe78bSCy Schubert                                                cc_uint32   *out_credentials_version)
207*7f2fe78bSCy Schubert {
208*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
209*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) in_ccache;
210*7f2fe78bSCy Schubert     k5_ipc_stream reply = NULL;
211*7f2fe78bSCy Schubert 
212*7f2fe78bSCy Schubert     if (!in_ccache              ) { err = cci_check_error (ccErrBadParam); }
213*7f2fe78bSCy Schubert     if (!out_credentials_version) { err = cci_check_error (ccErrBadParam); }
214*7f2fe78bSCy Schubert 
215*7f2fe78bSCy Schubert     if (!err) {
216*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_get_credentials_version_msg_id,
217*7f2fe78bSCy Schubert                              ccache->identifier,
218*7f2fe78bSCy Schubert                              NULL,
219*7f2fe78bSCy Schubert                              &reply);
220*7f2fe78bSCy Schubert     }
221*7f2fe78bSCy Schubert 
222*7f2fe78bSCy Schubert     if (!err) {
223*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_read_uint32 (reply, out_credentials_version);
224*7f2fe78bSCy Schubert     }
225*7f2fe78bSCy Schubert 
226*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (reply);
227*7f2fe78bSCy Schubert 
228*7f2fe78bSCy Schubert     return cci_check_error (err);
229*7f2fe78bSCy Schubert }
230*7f2fe78bSCy Schubert 
231*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
232*7f2fe78bSCy Schubert 
ccapi_ccache_get_name(cc_ccache_t in_ccache,cc_string_t * out_name)233*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_get_name (cc_ccache_t  in_ccache,
234*7f2fe78bSCy Schubert                                 cc_string_t *out_name)
235*7f2fe78bSCy Schubert {
236*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
237*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) in_ccache;
238*7f2fe78bSCy Schubert     k5_ipc_stream reply = NULL;
239*7f2fe78bSCy Schubert     char *name = NULL;
240*7f2fe78bSCy Schubert 
241*7f2fe78bSCy Schubert     if (!in_ccache) { err = cci_check_error (ccErrBadParam); }
242*7f2fe78bSCy Schubert     if (!out_name ) { err = cci_check_error (ccErrBadParam); }
243*7f2fe78bSCy Schubert 
244*7f2fe78bSCy Schubert     if (!err) {
245*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_get_name_msg_id,
246*7f2fe78bSCy Schubert                              ccache->identifier,
247*7f2fe78bSCy Schubert                              NULL,
248*7f2fe78bSCy Schubert                              &reply);
249*7f2fe78bSCy Schubert     }
250*7f2fe78bSCy Schubert 
251*7f2fe78bSCy Schubert     if (!err) {
252*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_read_string (reply, &name);
253*7f2fe78bSCy Schubert     }
254*7f2fe78bSCy Schubert 
255*7f2fe78bSCy Schubert     if (!err) {
256*7f2fe78bSCy Schubert         err = cci_string_new (out_name, name);
257*7f2fe78bSCy Schubert     }
258*7f2fe78bSCy Schubert 
259*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (reply);
260*7f2fe78bSCy Schubert     krb5int_ipc_stream_free_string (name);
261*7f2fe78bSCy Schubert 
262*7f2fe78bSCy Schubert     return cci_check_error (err);
263*7f2fe78bSCy Schubert }
264*7f2fe78bSCy Schubert 
265*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
266*7f2fe78bSCy Schubert 
ccapi_ccache_get_principal(cc_ccache_t in_ccache,cc_uint32 in_credentials_version,cc_string_t * out_principal)267*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_get_principal (cc_ccache_t  in_ccache,
268*7f2fe78bSCy Schubert                                      cc_uint32    in_credentials_version,
269*7f2fe78bSCy Schubert                                      cc_string_t *out_principal)
270*7f2fe78bSCy Schubert {
271*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
272*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) in_ccache;
273*7f2fe78bSCy Schubert     k5_ipc_stream request = NULL;
274*7f2fe78bSCy Schubert     k5_ipc_stream reply = NULL;
275*7f2fe78bSCy Schubert     char *principal = NULL;
276*7f2fe78bSCy Schubert 
277*7f2fe78bSCy Schubert     if (!in_ccache    ) { err = cci_check_error (ccErrBadParam); }
278*7f2fe78bSCy Schubert     if (!out_principal) { err = cci_check_error (ccErrBadParam); }
279*7f2fe78bSCy Schubert 
280*7f2fe78bSCy Schubert     if (!err) {
281*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_new (&request);
282*7f2fe78bSCy Schubert     }
283*7f2fe78bSCy Schubert 
284*7f2fe78bSCy Schubert     if (!err) {
285*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_write_uint32 (request, in_credentials_version);
286*7f2fe78bSCy Schubert     }
287*7f2fe78bSCy Schubert 
288*7f2fe78bSCy Schubert     if (!err) {
289*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_get_principal_msg_id,
290*7f2fe78bSCy Schubert                              ccache->identifier,
291*7f2fe78bSCy Schubert                              request,
292*7f2fe78bSCy Schubert                              &reply);
293*7f2fe78bSCy Schubert     }
294*7f2fe78bSCy Schubert 
295*7f2fe78bSCy Schubert     if (!err) {
296*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_read_string (reply, &principal);
297*7f2fe78bSCy Schubert     }
298*7f2fe78bSCy Schubert 
299*7f2fe78bSCy Schubert     if (!err) {
300*7f2fe78bSCy Schubert         err = cci_string_new (out_principal, principal);
301*7f2fe78bSCy Schubert     }
302*7f2fe78bSCy Schubert 
303*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (request);
304*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (reply);
305*7f2fe78bSCy Schubert     krb5int_ipc_stream_free_string (principal);
306*7f2fe78bSCy Schubert 
307*7f2fe78bSCy Schubert     return cci_check_error (err);
308*7f2fe78bSCy Schubert }
309*7f2fe78bSCy Schubert 
310*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
311*7f2fe78bSCy Schubert 
ccapi_ccache_set_principal(cc_ccache_t io_ccache,cc_uint32 in_credentials_version,const char * in_principal)312*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_set_principal (cc_ccache_t  io_ccache,
313*7f2fe78bSCy Schubert                                      cc_uint32    in_credentials_version,
314*7f2fe78bSCy Schubert                                      const char  *in_principal)
315*7f2fe78bSCy Schubert {
316*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
317*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) io_ccache;
318*7f2fe78bSCy Schubert     k5_ipc_stream request = NULL;
319*7f2fe78bSCy Schubert 
320*7f2fe78bSCy Schubert     if (!io_ccache   ) { err = cci_check_error (ccErrBadParam); }
321*7f2fe78bSCy Schubert     if (!in_principal) { err = cci_check_error (ccErrBadParam); }
322*7f2fe78bSCy Schubert 
323*7f2fe78bSCy Schubert     if (!err) {
324*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_new (&request);
325*7f2fe78bSCy Schubert     }
326*7f2fe78bSCy Schubert 
327*7f2fe78bSCy Schubert     if (!err) {
328*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_write_uint32 (request, in_credentials_version);
329*7f2fe78bSCy Schubert     }
330*7f2fe78bSCy Schubert 
331*7f2fe78bSCy Schubert     if (!err) {
332*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_write_string (request, in_principal);
333*7f2fe78bSCy Schubert     }
334*7f2fe78bSCy Schubert 
335*7f2fe78bSCy Schubert     if (!err) {
336*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_set_principal_msg_id,
337*7f2fe78bSCy Schubert                              ccache->identifier,
338*7f2fe78bSCy Schubert                              request,
339*7f2fe78bSCy Schubert                              NULL);
340*7f2fe78bSCy Schubert     }
341*7f2fe78bSCy Schubert 
342*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (request);
343*7f2fe78bSCy Schubert 
344*7f2fe78bSCy Schubert     return cci_check_error (err);
345*7f2fe78bSCy Schubert }
346*7f2fe78bSCy Schubert 
347*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
348*7f2fe78bSCy Schubert 
ccapi_ccache_store_credentials(cc_ccache_t io_ccache,const cc_credentials_union * in_credentials_union)349*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_store_credentials (cc_ccache_t                 io_ccache,
350*7f2fe78bSCy Schubert                                          const cc_credentials_union *in_credentials_union)
351*7f2fe78bSCy Schubert {
352*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
353*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) io_ccache;
354*7f2fe78bSCy Schubert     k5_ipc_stream request = NULL;
355*7f2fe78bSCy Schubert 
356*7f2fe78bSCy Schubert     if (!io_ccache           ) { err = cci_check_error (ccErrBadParam); }
357*7f2fe78bSCy Schubert     if (!in_credentials_union) { err = cci_check_error (ccErrBadParam); }
358*7f2fe78bSCy Schubert 
359*7f2fe78bSCy Schubert     if (!err) {
360*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_new (&request);
361*7f2fe78bSCy Schubert     }
362*7f2fe78bSCy Schubert 
363*7f2fe78bSCy Schubert     if (!err) {
364*7f2fe78bSCy Schubert         err = cci_credentials_union_write (in_credentials_union, request);
365*7f2fe78bSCy Schubert     }
366*7f2fe78bSCy Schubert 
367*7f2fe78bSCy Schubert     if (!err) {
368*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_store_credentials_msg_id,
369*7f2fe78bSCy Schubert                              ccache->identifier,
370*7f2fe78bSCy Schubert                              request,
371*7f2fe78bSCy Schubert                              NULL);
372*7f2fe78bSCy Schubert     }
373*7f2fe78bSCy Schubert 
374*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (request);
375*7f2fe78bSCy Schubert 
376*7f2fe78bSCy Schubert     return cci_check_error (err);
377*7f2fe78bSCy Schubert }
378*7f2fe78bSCy Schubert 
379*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
380*7f2fe78bSCy Schubert 
ccapi_ccache_remove_credentials(cc_ccache_t io_ccache,cc_credentials_t in_credentials)381*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_remove_credentials (cc_ccache_t      io_ccache,
382*7f2fe78bSCy Schubert                                           cc_credentials_t in_credentials)
383*7f2fe78bSCy Schubert {
384*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
385*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) io_ccache;
386*7f2fe78bSCy Schubert     k5_ipc_stream request = NULL;
387*7f2fe78bSCy Schubert 
388*7f2fe78bSCy Schubert     if (!io_ccache     ) { err = cci_check_error (ccErrBadParam); }
389*7f2fe78bSCy Schubert     if (!in_credentials) { err = cci_check_error (ccErrBadParam); }
390*7f2fe78bSCy Schubert 
391*7f2fe78bSCy Schubert     if (!err) {
392*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_new (&request);
393*7f2fe78bSCy Schubert     }
394*7f2fe78bSCy Schubert 
395*7f2fe78bSCy Schubert     if (!err) {
396*7f2fe78bSCy Schubert         err = cci_credentials_write (in_credentials, request);
397*7f2fe78bSCy Schubert     }
398*7f2fe78bSCy Schubert 
399*7f2fe78bSCy Schubert     if (!err) {
400*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_remove_credentials_msg_id,
401*7f2fe78bSCy Schubert                              ccache->identifier,
402*7f2fe78bSCy Schubert                              request,
403*7f2fe78bSCy Schubert                              NULL);
404*7f2fe78bSCy Schubert     }
405*7f2fe78bSCy Schubert 
406*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (request);
407*7f2fe78bSCy Schubert 
408*7f2fe78bSCy Schubert     return cci_check_error (err);
409*7f2fe78bSCy Schubert }
410*7f2fe78bSCy Schubert 
411*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
412*7f2fe78bSCy Schubert 
ccapi_ccache_new_credentials_iterator(cc_ccache_t in_ccache,cc_credentials_iterator_t * out_credentials_iterator)413*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_new_credentials_iterator (cc_ccache_t                in_ccache,
414*7f2fe78bSCy Schubert                                                 cc_credentials_iterator_t *out_credentials_iterator)
415*7f2fe78bSCy Schubert {
416*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
417*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) in_ccache;
418*7f2fe78bSCy Schubert     k5_ipc_stream reply = NULL;
419*7f2fe78bSCy Schubert     cci_identifier_t identifier = NULL;
420*7f2fe78bSCy Schubert 
421*7f2fe78bSCy Schubert     if (!in_ccache               ) { err = cci_check_error (ccErrBadParam); }
422*7f2fe78bSCy Schubert     if (!out_credentials_iterator) { err = cci_check_error (ccErrBadParam); }
423*7f2fe78bSCy Schubert 
424*7f2fe78bSCy Schubert     if (!err) {
425*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_new_credentials_iterator_msg_id,
426*7f2fe78bSCy Schubert                              ccache->identifier,
427*7f2fe78bSCy Schubert                              NULL,
428*7f2fe78bSCy Schubert                              &reply);
429*7f2fe78bSCy Schubert     }
430*7f2fe78bSCy Schubert 
431*7f2fe78bSCy Schubert     if (!err) {
432*7f2fe78bSCy Schubert         err =  cci_identifier_read (&identifier, reply);
433*7f2fe78bSCy Schubert     }
434*7f2fe78bSCy Schubert 
435*7f2fe78bSCy Schubert     if (!err) {
436*7f2fe78bSCy Schubert         err = cci_credentials_iterator_new (out_credentials_iterator, identifier);
437*7f2fe78bSCy Schubert     }
438*7f2fe78bSCy Schubert 
439*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (reply);
440*7f2fe78bSCy Schubert     cci_identifier_release (identifier);
441*7f2fe78bSCy Schubert 
442*7f2fe78bSCy Schubert     return cci_check_error (err);
443*7f2fe78bSCy Schubert }
444*7f2fe78bSCy Schubert 
445*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
446*7f2fe78bSCy Schubert /* Note: message is sent as the destination to avoid extra work on the      */
447*7f2fe78bSCy Schubert /* server when deleting it the source ccache.                               */
448*7f2fe78bSCy Schubert 
ccapi_ccache_move(cc_ccache_t io_source_ccache,cc_ccache_t io_destination_ccache)449*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_move (cc_ccache_t io_source_ccache,
450*7f2fe78bSCy Schubert                             cc_ccache_t io_destination_ccache)
451*7f2fe78bSCy Schubert {
452*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
453*7f2fe78bSCy Schubert     cci_ccache_t source_ccache = (cci_ccache_t) io_source_ccache;
454*7f2fe78bSCy Schubert     cci_ccache_t destination_ccache = (cci_ccache_t) io_destination_ccache;
455*7f2fe78bSCy Schubert     k5_ipc_stream request = NULL;
456*7f2fe78bSCy Schubert 
457*7f2fe78bSCy Schubert     if (!io_source_ccache     ) { err = cci_check_error (ccErrBadParam); }
458*7f2fe78bSCy Schubert     if (!io_destination_ccache) { err = cci_check_error (ccErrBadParam); }
459*7f2fe78bSCy Schubert 
460*7f2fe78bSCy Schubert     if (!err) {
461*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_new (&request);
462*7f2fe78bSCy Schubert     }
463*7f2fe78bSCy Schubert 
464*7f2fe78bSCy Schubert     if (!err) {
465*7f2fe78bSCy Schubert         err = cci_identifier_write (source_ccache->identifier, request);
466*7f2fe78bSCy Schubert     }
467*7f2fe78bSCy Schubert 
468*7f2fe78bSCy Schubert     if (!err) {
469*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_move_msg_id,
470*7f2fe78bSCy Schubert                              destination_ccache->identifier,
471*7f2fe78bSCy Schubert                              request,
472*7f2fe78bSCy Schubert                              NULL);
473*7f2fe78bSCy Schubert     }
474*7f2fe78bSCy Schubert 
475*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (request);
476*7f2fe78bSCy Schubert 
477*7f2fe78bSCy Schubert     return cci_check_error (err);
478*7f2fe78bSCy Schubert }
479*7f2fe78bSCy Schubert 
480*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
481*7f2fe78bSCy Schubert 
ccapi_ccache_lock(cc_ccache_t io_ccache,cc_uint32 in_lock_type,cc_uint32 in_block)482*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_lock (cc_ccache_t io_ccache,
483*7f2fe78bSCy Schubert                             cc_uint32   in_lock_type,
484*7f2fe78bSCy Schubert                             cc_uint32   in_block)
485*7f2fe78bSCy Schubert {
486*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
487*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) io_ccache;
488*7f2fe78bSCy Schubert     k5_ipc_stream request = NULL;
489*7f2fe78bSCy Schubert 
490*7f2fe78bSCy Schubert     if (!io_ccache) { err = cci_check_error (ccErrBadParam); }
491*7f2fe78bSCy Schubert 
492*7f2fe78bSCy Schubert     if (!err) {
493*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_new (&request);
494*7f2fe78bSCy Schubert     }
495*7f2fe78bSCy Schubert 
496*7f2fe78bSCy Schubert     if (!err) {
497*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_write_uint32 (request, in_lock_type);
498*7f2fe78bSCy Schubert     }
499*7f2fe78bSCy Schubert 
500*7f2fe78bSCy Schubert     if (!err) {
501*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_write_uint32 (request, in_block);
502*7f2fe78bSCy Schubert     }
503*7f2fe78bSCy Schubert 
504*7f2fe78bSCy Schubert     if (!err) {
505*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_lock_msg_id,
506*7f2fe78bSCy Schubert                              ccache->identifier,
507*7f2fe78bSCy Schubert                              request,
508*7f2fe78bSCy Schubert                              NULL);
509*7f2fe78bSCy Schubert     }
510*7f2fe78bSCy Schubert 
511*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (request);
512*7f2fe78bSCy Schubert 
513*7f2fe78bSCy Schubert     return cci_check_error (err);
514*7f2fe78bSCy Schubert }
515*7f2fe78bSCy Schubert 
516*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
517*7f2fe78bSCy Schubert 
ccapi_ccache_unlock(cc_ccache_t io_ccache)518*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_unlock (cc_ccache_t io_ccache)
519*7f2fe78bSCy Schubert {
520*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
521*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) io_ccache;
522*7f2fe78bSCy Schubert 
523*7f2fe78bSCy Schubert     if (!io_ccache) { err = cci_check_error (ccErrBadParam); }
524*7f2fe78bSCy Schubert 
525*7f2fe78bSCy Schubert     if (!err) {
526*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_unlock_msg_id,
527*7f2fe78bSCy Schubert                              ccache->identifier,
528*7f2fe78bSCy Schubert                              NULL,
529*7f2fe78bSCy Schubert                              NULL);
530*7f2fe78bSCy Schubert     }
531*7f2fe78bSCy Schubert 
532*7f2fe78bSCy Schubert     return cci_check_error (err);
533*7f2fe78bSCy Schubert }
534*7f2fe78bSCy Schubert 
535*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
536*7f2fe78bSCy Schubert 
ccapi_ccache_get_last_default_time(cc_ccache_t in_ccache,cc_time_t * out_last_default_time)537*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_get_last_default_time (cc_ccache_t  in_ccache,
538*7f2fe78bSCy Schubert                                              cc_time_t   *out_last_default_time)
539*7f2fe78bSCy Schubert {
540*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
541*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) in_ccache;
542*7f2fe78bSCy Schubert     k5_ipc_stream reply = NULL;
543*7f2fe78bSCy Schubert 
544*7f2fe78bSCy Schubert     if (!in_ccache            ) { err = cci_check_error (ccErrBadParam); }
545*7f2fe78bSCy Schubert     if (!out_last_default_time) { err = cci_check_error (ccErrBadParam); }
546*7f2fe78bSCy Schubert 
547*7f2fe78bSCy Schubert     if (!err) {
548*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_get_last_default_time_msg_id,
549*7f2fe78bSCy Schubert                              ccache->identifier,
550*7f2fe78bSCy Schubert                              NULL,
551*7f2fe78bSCy Schubert                              &reply);
552*7f2fe78bSCy Schubert     }
553*7f2fe78bSCy Schubert 
554*7f2fe78bSCy Schubert     if (!err) {
555*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_read_time (reply, out_last_default_time);
556*7f2fe78bSCy Schubert     }
557*7f2fe78bSCy Schubert 
558*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (reply);
559*7f2fe78bSCy Schubert 
560*7f2fe78bSCy Schubert     return cci_check_error (err);
561*7f2fe78bSCy Schubert }
562*7f2fe78bSCy Schubert 
563*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
564*7f2fe78bSCy Schubert 
ccapi_ccache_get_change_time(cc_ccache_t in_ccache,cc_time_t * out_change_time)565*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_get_change_time (cc_ccache_t  in_ccache,
566*7f2fe78bSCy Schubert                                        cc_time_t   *out_change_time)
567*7f2fe78bSCy Schubert {
568*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
569*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) in_ccache;
570*7f2fe78bSCy Schubert     k5_ipc_stream reply = NULL;
571*7f2fe78bSCy Schubert 
572*7f2fe78bSCy Schubert     if (!in_ccache      ) { err = cci_check_error (ccErrBadParam); }
573*7f2fe78bSCy Schubert     if (!out_change_time) { err = cci_check_error (ccErrBadParam); }
574*7f2fe78bSCy Schubert 
575*7f2fe78bSCy Schubert     if (!err) {
576*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_get_change_time_msg_id,
577*7f2fe78bSCy Schubert                              ccache->identifier,
578*7f2fe78bSCy Schubert                              NULL,
579*7f2fe78bSCy Schubert                              &reply);
580*7f2fe78bSCy Schubert     }
581*7f2fe78bSCy Schubert 
582*7f2fe78bSCy Schubert     if (!err) {
583*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_read_time (reply, out_change_time);
584*7f2fe78bSCy Schubert     }
585*7f2fe78bSCy Schubert 
586*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (reply);
587*7f2fe78bSCy Schubert 
588*7f2fe78bSCy Schubert     return cci_check_error (err);
589*7f2fe78bSCy Schubert }
590*7f2fe78bSCy Schubert 
591*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
592*7f2fe78bSCy Schubert 
ccapi_ccache_wait_for_change(cc_ccache_t in_ccache)593*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_wait_for_change (cc_ccache_t  in_ccache)
594*7f2fe78bSCy Schubert {
595*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
596*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) in_ccache;
597*7f2fe78bSCy Schubert     k5_ipc_stream request = NULL;
598*7f2fe78bSCy Schubert     k5_ipc_stream reply = NULL;
599*7f2fe78bSCy Schubert 
600*7f2fe78bSCy Schubert     if (!in_ccache) { err = cci_check_error (ccErrBadParam); }
601*7f2fe78bSCy Schubert 
602*7f2fe78bSCy Schubert     if (!err) {
603*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_new (&request);
604*7f2fe78bSCy Schubert     }
605*7f2fe78bSCy Schubert 
606*7f2fe78bSCy Schubert     if (!err) {
607*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_write_time (request, ccache->last_wait_for_change_time);
608*7f2fe78bSCy Schubert     }
609*7f2fe78bSCy Schubert 
610*7f2fe78bSCy Schubert     if (!err) {
611*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_wait_for_change_msg_id,
612*7f2fe78bSCy Schubert                              ccache->identifier,
613*7f2fe78bSCy Schubert                              request,
614*7f2fe78bSCy Schubert 			     &reply);
615*7f2fe78bSCy Schubert     }
616*7f2fe78bSCy Schubert 
617*7f2fe78bSCy Schubert     if (!err) {
618*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_read_time (reply, &ccache->last_wait_for_change_time);
619*7f2fe78bSCy Schubert     }
620*7f2fe78bSCy Schubert 
621*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (request);
622*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (reply);
623*7f2fe78bSCy Schubert 
624*7f2fe78bSCy Schubert     return cci_check_error (err);
625*7f2fe78bSCy Schubert }
626*7f2fe78bSCy Schubert 
627*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
628*7f2fe78bSCy Schubert 
ccapi_ccache_compare(cc_ccache_t in_ccache,cc_ccache_t in_compare_to_ccache,cc_uint32 * out_equal)629*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_compare (cc_ccache_t  in_ccache,
630*7f2fe78bSCy Schubert                                cc_ccache_t  in_compare_to_ccache,
631*7f2fe78bSCy Schubert                                cc_uint32   *out_equal)
632*7f2fe78bSCy Schubert {
633*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
634*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) in_ccache;
635*7f2fe78bSCy Schubert     cci_ccache_t compare_to_ccache = (cci_ccache_t) in_compare_to_ccache;
636*7f2fe78bSCy Schubert 
637*7f2fe78bSCy Schubert     if (!in_ccache           ) { err = cci_check_error (ccErrBadParam); }
638*7f2fe78bSCy Schubert     if (!in_compare_to_ccache) { err = cci_check_error (ccErrBadParam); }
639*7f2fe78bSCy Schubert     if (!out_equal           ) { err = cci_check_error (ccErrBadParam); }
640*7f2fe78bSCy Schubert 
641*7f2fe78bSCy Schubert     if (!err) {
642*7f2fe78bSCy Schubert         err = cci_identifier_compare (ccache->identifier,
643*7f2fe78bSCy Schubert                                       compare_to_ccache->identifier,
644*7f2fe78bSCy Schubert                                       out_equal);
645*7f2fe78bSCy Schubert     }
646*7f2fe78bSCy Schubert 
647*7f2fe78bSCy Schubert     return cci_check_error (err);
648*7f2fe78bSCy Schubert }
649*7f2fe78bSCy Schubert 
650*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
651*7f2fe78bSCy Schubert 
ccapi_ccache_get_kdc_time_offset(cc_ccache_t in_ccache,cc_uint32 in_credentials_version,cc_time_t * out_time_offset)652*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_get_kdc_time_offset (cc_ccache_t  in_ccache,
653*7f2fe78bSCy Schubert                                            cc_uint32    in_credentials_version,
654*7f2fe78bSCy Schubert                                            cc_time_t   *out_time_offset)
655*7f2fe78bSCy Schubert {
656*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
657*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) in_ccache;
658*7f2fe78bSCy Schubert     k5_ipc_stream request = NULL;
659*7f2fe78bSCy Schubert     k5_ipc_stream reply = NULL;
660*7f2fe78bSCy Schubert 
661*7f2fe78bSCy Schubert     if (!in_ccache      ) { err = cci_check_error (ccErrBadParam); }
662*7f2fe78bSCy Schubert     if (!out_time_offset) { err = cci_check_error (ccErrBadParam); }
663*7f2fe78bSCy Schubert 
664*7f2fe78bSCy Schubert     if (!err) {
665*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_new (&request);
666*7f2fe78bSCy Schubert     }
667*7f2fe78bSCy Schubert 
668*7f2fe78bSCy Schubert     if (!err) {
669*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_write_uint32 (request, in_credentials_version);
670*7f2fe78bSCy Schubert     }
671*7f2fe78bSCy Schubert 
672*7f2fe78bSCy Schubert     if (!err) {
673*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_get_kdc_time_offset_msg_id,
674*7f2fe78bSCy Schubert                              ccache->identifier,
675*7f2fe78bSCy Schubert                              request,
676*7f2fe78bSCy Schubert                              &reply);
677*7f2fe78bSCy Schubert     }
678*7f2fe78bSCy Schubert 
679*7f2fe78bSCy Schubert     if (!err) {
680*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_read_time (reply, out_time_offset);
681*7f2fe78bSCy Schubert     }
682*7f2fe78bSCy Schubert 
683*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (request);
684*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (reply);
685*7f2fe78bSCy Schubert 
686*7f2fe78bSCy Schubert     return cci_check_error (err);
687*7f2fe78bSCy Schubert }
688*7f2fe78bSCy Schubert 
689*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
690*7f2fe78bSCy Schubert 
ccapi_ccache_set_kdc_time_offset(cc_ccache_t io_ccache,cc_uint32 in_credentials_version,cc_time_t in_time_offset)691*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_set_kdc_time_offset (cc_ccache_t io_ccache,
692*7f2fe78bSCy Schubert                                            cc_uint32   in_credentials_version,
693*7f2fe78bSCy Schubert                                            cc_time_t   in_time_offset)
694*7f2fe78bSCy Schubert {
695*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
696*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) io_ccache;
697*7f2fe78bSCy Schubert     k5_ipc_stream request = NULL;
698*7f2fe78bSCy Schubert 
699*7f2fe78bSCy Schubert     if (!io_ccache) { err = cci_check_error (ccErrBadParam); }
700*7f2fe78bSCy Schubert 
701*7f2fe78bSCy Schubert     if (!err) {
702*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_new (&request);
703*7f2fe78bSCy Schubert     }
704*7f2fe78bSCy Schubert 
705*7f2fe78bSCy Schubert     if (!err) {
706*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_write_uint32 (request, in_credentials_version);
707*7f2fe78bSCy Schubert     }
708*7f2fe78bSCy Schubert 
709*7f2fe78bSCy Schubert     if (!err) {
710*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_write_time (request, in_time_offset);
711*7f2fe78bSCy Schubert     }
712*7f2fe78bSCy Schubert 
713*7f2fe78bSCy Schubert     if (!err) {
714*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_set_kdc_time_offset_msg_id,
715*7f2fe78bSCy Schubert                              ccache->identifier,
716*7f2fe78bSCy Schubert                              request,
717*7f2fe78bSCy Schubert                              NULL);
718*7f2fe78bSCy Schubert     }
719*7f2fe78bSCy Schubert 
720*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (request);
721*7f2fe78bSCy Schubert 
722*7f2fe78bSCy Schubert     return cci_check_error (err);
723*7f2fe78bSCy Schubert }
724*7f2fe78bSCy Schubert 
725*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
726*7f2fe78bSCy Schubert 
ccapi_ccache_clear_kdc_time_offset(cc_ccache_t io_ccache,cc_uint32 in_credentials_version)727*7f2fe78bSCy Schubert cc_int32 ccapi_ccache_clear_kdc_time_offset (cc_ccache_t io_ccache,
728*7f2fe78bSCy Schubert                                              cc_uint32   in_credentials_version)
729*7f2fe78bSCy Schubert {
730*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
731*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) io_ccache;
732*7f2fe78bSCy Schubert     k5_ipc_stream request = NULL;
733*7f2fe78bSCy Schubert 
734*7f2fe78bSCy Schubert     if (!io_ccache) { err = cci_check_error (ccErrBadParam); }
735*7f2fe78bSCy Schubert 
736*7f2fe78bSCy Schubert     if (!err) {
737*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_new (&request);
738*7f2fe78bSCy Schubert     }
739*7f2fe78bSCy Schubert 
740*7f2fe78bSCy Schubert     if (!err) {
741*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_write_uint32 (request, in_credentials_version);
742*7f2fe78bSCy Schubert     }
743*7f2fe78bSCy Schubert 
744*7f2fe78bSCy Schubert     if (!err) {
745*7f2fe78bSCy Schubert         err =  cci_ipc_send (cci_ccache_clear_kdc_time_offset_msg_id,
746*7f2fe78bSCy Schubert                              ccache->identifier,
747*7f2fe78bSCy Schubert                              request,
748*7f2fe78bSCy Schubert                              NULL);
749*7f2fe78bSCy Schubert     }
750*7f2fe78bSCy Schubert 
751*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (request);
752*7f2fe78bSCy Schubert 
753*7f2fe78bSCy Schubert     return cci_check_error (err);
754*7f2fe78bSCy Schubert }
755*7f2fe78bSCy Schubert 
756*7f2fe78bSCy Schubert #ifdef TARGET_OS_MAC
757*7f2fe78bSCy Schubert #pragma mark -
758*7f2fe78bSCy Schubert #endif
759*7f2fe78bSCy Schubert 
760*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
761*7f2fe78bSCy Schubert 
cci_ccache_get_compat_version(cc_ccache_t in_ccache,cc_uint32 * out_compat_version)762*7f2fe78bSCy Schubert cc_int32 cci_ccache_get_compat_version (cc_ccache_t  in_ccache,
763*7f2fe78bSCy Schubert                                         cc_uint32   *out_compat_version)
764*7f2fe78bSCy Schubert {
765*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
766*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) in_ccache;
767*7f2fe78bSCy Schubert 
768*7f2fe78bSCy Schubert     if (!in_ccache         ) { err = cci_check_error (ccErrBadParam); }
769*7f2fe78bSCy Schubert     if (!out_compat_version) { err = cci_check_error (ccErrBadParam); }
770*7f2fe78bSCy Schubert 
771*7f2fe78bSCy Schubert     if (!err) {
772*7f2fe78bSCy Schubert         *out_compat_version = ccache->compat_version;
773*7f2fe78bSCy Schubert     }
774*7f2fe78bSCy Schubert 
775*7f2fe78bSCy Schubert     return cci_check_error (err);
776*7f2fe78bSCy Schubert }
777*7f2fe78bSCy Schubert 
778*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
779*7f2fe78bSCy Schubert 
cci_ccache_set_compat_version(cc_ccache_t io_ccache,cc_uint32 in_compat_version)780*7f2fe78bSCy Schubert cc_int32 cci_ccache_set_compat_version (cc_ccache_t io_ccache,
781*7f2fe78bSCy Schubert                                         cc_uint32   in_compat_version)
782*7f2fe78bSCy Schubert {
783*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
784*7f2fe78bSCy Schubert     cci_ccache_t ccache = (cci_ccache_t) io_ccache;
785*7f2fe78bSCy Schubert 
786*7f2fe78bSCy Schubert     if (!io_ccache) { err = cci_check_error (ccErrBadParam); }
787*7f2fe78bSCy Schubert 
788*7f2fe78bSCy Schubert     if (!err) {
789*7f2fe78bSCy Schubert         ccache->compat_version = in_compat_version;
790*7f2fe78bSCy Schubert     }
791*7f2fe78bSCy Schubert 
792*7f2fe78bSCy Schubert     return cci_check_error (err);
793*7f2fe78bSCy Schubert }
794