summaryrefslogtreecommitdiffstats
path: root/crypto/heimdal/lib/krb5/krb5_ccache.3
blob: 3fca5956e7dd5e403fadbed0f0ce9ddd5f09c813 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
.\" Copyright (c) 2003 - 2005 Kungliga Tekniska Högskolan
.\" (Royal Institute of Technology, Stockholm, Sweden).
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" 3. Neither the name of the Institute nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $Id: krb5_ccache.3 22071 2007-11-14 20:04:50Z lha $
.\"
.Dd October 19, 2005
.Dt KRB5_CCACHE 3
.Os HEIMDAL
.Sh NAME
.Nm krb5_ccache ,
.Nm krb5_cc_cursor ,
.Nm krb5_cc_ops ,
.Nm krb5_fcc_ops ,
.Nm krb5_mcc_ops ,
.Nm krb5_cc_clear_mcred ,
.Nm krb5_cc_close ,
.Nm krb5_cc_copy_cache ,
.Nm krb5_cc_default ,
.Nm krb5_cc_default_name ,
.Nm krb5_cc_destroy ,
.Nm krb5_cc_end_seq_get ,
.Nm krb5_cc_gen_new ,
.Nm krb5_cc_get_full_name ,
.Nm krb5_cc_get_name ,
.Nm krb5_cc_get_ops ,
.Nm krb5_cc_get_prefix_ops ,
.Nm krb5_cc_get_principal ,
.Nm krb5_cc_get_type ,
.Nm krb5_cc_get_version ,
.Nm krb5_cc_initialize ,
.Nm krb5_cc_next_cred ,
.Nm krb5_cc_next_cred_match ,
.Nm krb5_cc_new_unique ,
.Nm krb5_cc_register ,
.Nm krb5_cc_remove_cred ,
.Nm krb5_cc_resolve ,
.Nm krb5_cc_retrieve_cred ,
.Nm krb5_cc_set_default_name ,
.Nm krb5_cc_set_flags ,
.Nm krb5_cc_start_seq_get ,
.Nm krb5_cc_store_cred
.Nd mange credential cache
.Sh LIBRARY
Kerberos 5 Library (libkrb5, -lkrb5)
.Sh SYNOPSIS
.In krb5.h
.Pp
.Li "struct krb5_ccache;"
.Pp
.Li "struct krb5_cc_cursor;"
.Pp
.Li "struct krb5_cc_ops;"
.Pp
.Li "struct krb5_cc_ops *krb5_fcc_ops;"
.Pp
.Li "struct krb5_cc_ops *krb5_mcc_ops;"
.Pp
.Ft void
.Fo krb5_cc_clear_mcred
.Fa "krb5_creds *mcred"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_close
.Fa "krb5_context context"
.Fa "krb5_ccache id"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_copy_cache
.Fa "krb5_context context"
.Fa "const krb5_ccache from"
.Fa "krb5_ccache to"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_default
.Fa "krb5_context context"
.Fa "krb5_ccache *id"
.Fc
.Ft "const char *"
.Fo krb5_cc_default_name
.Fa "krb5_context context"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_destroy
.Fa "krb5_context context"
.Fa "krb5_ccache id"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_end_seq_get
.Fa "krb5_context context"
.Fa "const krb5_ccache id"
.Fa "krb5_cc_cursor *cursor"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_gen_new
.Fa "krb5_context context"
.Fa "const krb5_cc_ops *ops"
.Fa "krb5_ccache *id"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_get_full_name
.Fa "krb5_context context"
.Fa "krb5_ccache id"
.Fa "char **str"
.Fc
.Ft "const char *"
.Fo krb5_cc_get_name
.Fa "krb5_context context"
.Fa "krb5_ccache id"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_get_principal
.Fa "krb5_context context"
.Fa "krb5_ccache id"
.Fa "krb5_principal *principal"
.Fc
.Ft "const char *"
.Fo krb5_cc_get_type
.Fa "krb5_context context"
.Fa "krb5_ccache id"
.Fc
.Ft "const krb5_cc_ops *"
.Fo krb5_cc_get_ops
.Fa "krb5_context context"
.Fa "krb5_ccache id"
.Fc
.Ft "const krb5_cc_ops *"
.Fo krb5_cc_get_prefix_ops
.Fa "krb5_context context"
.Fa "const char *prefix"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_get_version
.Fa "krb5_context context"
.Fa "const krb5_ccache id"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_initialize
.Fa "krb5_context context"
.Fa "krb5_ccache id"
.Fa "krb5_principal primary_principal"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_register
.Fa "krb5_context context"
.Fa "const krb5_cc_ops *ops"
.Fa "krb5_boolean override"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_resolve
.Fa "krb5_context context"
.Fa "const char *name"
.Fa "krb5_ccache *id"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_retrieve_cred
.Fa "krb5_context context"
.Fa "krb5_ccache id"
.Fa "krb5_flags whichfields"
.Fa "const krb5_creds *mcreds"
.Fa "krb5_creds *creds"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_remove_cred
.Fa "krb5_context context"
.Fa "krb5_ccache id"
.Fa "krb5_flags which"
.Fa "krb5_creds *cred"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_set_default_name
.Fa "krb5_context context"
.Fa "const char *name"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_start_seq_get
.Fa "krb5_context context"
.Fa "const krb5_ccache id"
.Fa "krb5_cc_cursor *cursor"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_store_cred
.Fa "krb5_context context"
.Fa "krb5_ccache id"
.Fa "krb5_creds *creds"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_set_flags
.Fa "krb5_context context"
.Fa "krb5_cc_set_flags id"
.Fa "krb5_flags flags"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_next_cred
.Fa "krb5_context context"
.Fa "const krb5_ccache id"
.Fa "krb5_cc_cursor *cursor"
.Fa "krb5_creds *creds"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_next_cred_match
.Fa "krb5_context context"
.Fa "const krb5_ccache id"
.Fa "krb5_cc_cursor *cursor"
.Fa "krb5_creds *creds"
.Fa "krb5_flags whichfields"
.Fa "const krb5_creds *mcreds"
.Fc
.Ft krb5_error_code
.Fo krb5_cc_new_unique
.Fa "krb5_context context"
.Fa "const char *type"
.Fa "const char *hint"
.Fa "krb5_ccache *id"
.Fc
.Sh DESCRIPTION
The
.Li krb5_ccache
structure holds a Kerberos credential cache.
.Pp
The
.Li krb5_cc_cursor
structure holds current position in a credential cache when
iterating over the cache.
.Pp
The
.Li krb5_cc_ops
structure holds a set of operations that can me preformed on a
credential cache.
.Pp
There is no component inside
.Li krb5_ccache ,
.Li krb5_cc_cursor
nor
.Li krb5_fcc_ops
that is directly referable.
.Pp
The
.Li krb5_creds
holds a Kerberos credential, see manpage for
.Xr krb5_creds 3 .
.Pp
.Fn krb5_cc_default_name
and
.Fn krb5_cc_set_default_name
gets and sets the default name for the
.Fa context .
.Pp
.Fn krb5_cc_default
opens the default credential cache in
.Fa id .
Return 0 or an error code.
.Pp
.Fn krb5_cc_gen_new
generates a new credential cache of type
.Fa ops
in
.Fa id .
Return 0 or an error code.
The Heimdal version of this function also runs
.Fn krb5_cc_initialize
on the credential cache, but since the MIT version doesn't, portable
code must call krb5_cc_initialize.
.Pp
.Fn krb5_cc_new_unique
generates a new unique credential cache of
.Fa type
in
.Fa id .
If type is
.Dv NULL ,
the library chooses the default credential cache type.
The supplied
.Fa hint
(that can be
.Dv NULL )
is a string that the credential cache type can use to base the name of
the credential on, this is to make it easier for the user to
differentiate the credentials.
The returned credential cache
.Fa id
should be freed using
.Fn krb5_cc_close
or
.Fn krb5_cc_destroy .
Returns 0 or an error code.
.Pp
.Fn krb5_cc_resolve
finds and allocates a credential cache in
.Fa id
from the specification in
.Fa residual .
If the credential cache name doesn't contain any colon (:), interpret it as a
file name.
Return 0 or an error code.
.Pp
.Fn krb5_cc_initialize
creates a new credential cache in
.Fa id
for
.Fa primary_principal .
Return 0 or an error code.
.Pp
.Fn krb5_cc_close
stops using the credential cache
.Fa id
and frees the related resources.
Return 0 or an error code.
.Fn krb5_cc_destroy
removes the credential cache
and closes (by calling
.Fn krb5_cc_close )
.Fa id .
Return 0 or an error code.
.Pp
.Fn krb5_cc_copy_cache
copys the contents of
.Fa from
to
.Fa to .
.Pp
.Fn krb5_cc_get_full_name
returns the complete resolvable name of the credential cache
.Fa id
in
.Fa str .
.Fa str
should be freed with
.Xr free 3 .
Returns 0 or an error, on error
.Fa *str
is set to
.Dv NULL .
.Pp
.Fn krb5_cc_get_name
returns the name of the credential cache
.Fa id .
.Pp
.Fn krb5_cc_get_principal
returns the principal of
.Fa id
in
.Fa principal .
Return 0 or an error code.
.Pp
.Fn krb5_cc_get_type
returns the type of the credential cache
.Fa id .
.Pp
.Fn krb5_cc_get_ops
returns the ops of the credential cache
.Fa id .
.Pp
.Fn krb5_cc_get_version
returns the version of
.Fa id .
.Pp
.Fn krb5_cc_register
Adds a new credential cache type with operations
.Fa ops ,
overwriting any existing one if
.Fa override .
Return an error code or 0.
.Pp
.Fn krb5_cc_get_prefix_ops
Get the cc ops that is registered in
.Fa context
to handle the
.Fa prefix .
Returns
.Dv NULL
if ops not found.
.Pp
.Fn krb5_cc_remove_cred
removes the credential identified by
.Fa ( cred ,
.Fa which )
from
.Fa id .
.Pp
.Fn krb5_cc_store_cred
stores
.Fa creds
in the credential cache
.Fa id .
Return 0 or an error code.
.Pp
.Fn krb5_cc_set_flags
sets the flags of
.Fa id
to
.Fa flags .
.Pp
.Fn krb5_cc_clear_mcred
clears the
.Fa mcreds
argument so it is reset and can be used with
.Fa krb5_cc_retrieve_cred .
.Pp
.Fn krb5_cc_retrieve_cred ,
retrieves the credential identified by
.Fa mcreds
(and
.Fa whichfields )
from
.Fa id
in
.Fa creds .
.Fa creds
should be freed using
.Fn krb5_free_cred_contents .
Return 0 or an error code.
.Pp
.Fn krb5_cc_start_seq_get
initiates the
.Li krb5_cc_cursor
structure to be used for iteration over the credential cache.
.Pp
.Fn krb5_cc_next_cred
retrieves the next cred pointed to by
.Fa ( id ,
.Fa cursor )
in
.Fa creds ,
and advance
.Fa cursor .
Return 0 or an error code.
.Pp
.Fn krb5_cc_next_cred_match
is similar to
.Fn krb5_cc_next_cred
except that it will only return creds matching 
.Fa whichfields
and
.Fa mcreds
(as interpreted by 
.Xr krb5_compare_creds 3 . )
.Pp
.Fn krb5_cc_end_seq_get
Destroys the cursor
.Fa cursor .
.Sh EXAMPLE
This is a minimalistic version of
.Nm klist .
.Pp
.Bd -literal
#include <krb5.h>

int
main (int argc, char **argv)
{
    krb5_context context;
    krb5_cc_cursor cursor;
    krb5_error_code ret;
    krb5_ccache id;
    krb5_creds creds;

    if (krb5_init_context (&context) != 0)
	errx(1, "krb5_context");

    ret = krb5_cc_default (context, &id);
    if (ret)
	krb5_err(context, 1, ret, "krb5_cc_default");

    ret = krb5_cc_start_seq_get(context, id, &cursor);
    if (ret)
	krb5_err(context, 1, ret, "krb5_cc_start_seq_get");

    while((ret = krb5_cc_next_cred(context, id, &cursor, &creds)) == 0){
        char *principal;

	krb5_unparse_name_short(context, creds.server, &principal);
	printf("principal: %s\\n", principal);
	free(principal);
	krb5_free_cred_contents (context, &creds);
    }
    ret = krb5_cc_end_seq_get(context, id, &cursor);
    if (ret)
	krb5_err(context, 1, ret, "krb5_cc_end_seq_get");

    krb5_cc_close(context, id);

    krb5_free_context(context);
    return 0;
}
.Ed
.Sh SEE ALSO
.Xr krb5 3 ,
.Xr krb5.conf 5 ,
.Xr kerberos 8
OpenPOWER on IntegriCloud