xref: /netbsd-src/crypto/external/bsd/heimdal/dist/doc/doxyout/krb5/man/man3/krb5_ccache_intro.3 (revision afab4e300d3a9fb07dd8c80daf53d0feb3345706)
$NetBSD: krb5_ccache_intro.3,v 1.3 2023/06/19 21:41:40 christos Exp $

"krb5_ccache_intro" 3 "Tue Nov 15 2022" "Version 7.8.0" "Heimdal Kerberos 5 library" \" -*- nroff -*-
NAME
krb5_ccache_intro - The credential cache functions
"Kerberos credential caches"

krb5_ccache structure holds a Kerberos credential cache.

Heimdal support the follow types of credential caches:

"\(bu" 2
SCC Store the credential in a database
"\(bu" 2
FILE Store the credential in memory
"\(bu" 2
MEMORY Store the credential in memory
"\(bu" 2
API A credential cache server based solution for Mac OS X
"\(bu" 2
KCM A credential cache server based solution for all platforms

"Example"
This is a minimalistic version of klist:

#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(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;
}