---
name: "krb5_ccache"
section: "3"
platform: "linux"
package: "heimdal-dev"
version: "1.2.dfsg.1-2.1+lenny1"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/krb5_cc_remove_cred"
---

# krb5\_ccache(3)

mange credential cache

Part of [krb5\_cc\_remove\_cred(3)](/krb5_cc_remove_cred/3.md).

## NAME

**krb5\_ccache**, **krb5\_cc\_cursor**, **krb5\_cc\_ops**, **krb5\_fcc\_ops**, **krb5\_mcc\_ops**, **krb5\_cc\_clear\_mcred**, **krb5\_cc\_close**, **krb5\_cc\_copy\_cache**, **krb5\_cc\_default**, **krb5\_cc\_default\_name**, **krb5\_cc\_destroy**, **krb5\_cc\_end\_seq\_get**, **krb5\_cc\_gen\_new**, **krb5\_cc\_get\_full\_name**, **krb5\_cc\_get\_name**, **krb5\_cc\_get\_ops**, **krb5\_cc\_get\_prefix\_ops**, **krb5\_cc\_get\_principal**, **krb5\_cc\_get\_type**, **krb5\_cc\_get\_version**, **krb5\_cc\_initialize**, **krb5\_cc\_next\_cred**, **krb5\_cc\_next\_cred\_match**, **krb5\_cc\_new\_unique**, **krb5\_cc\_register**, **krb5\_cc\_remove\_cred**, **krb5\_cc\_resolve**, **krb5\_cc\_retrieve\_cred**, **krb5\_cc\_set\_default\_name**, **krb5\_cc\_set\_flags**, **krb5\_cc\_start\_seq\_get**, **krb5\_cc\_store\_cred** – mange credential cache

## LIBRARY

Kerberos 5 Library (libkrb5, -lkrb5)

## SYNOPSIS

**#include \<krb5.h\>**

struct krb5\_ccache;

struct krb5\_cc\_cursor;

struct krb5\_cc\_ops;

struct krb5\_cc\_ops \*krb5\_fcc\_ops;

struct krb5\_cc\_ops \*krb5\_mcc\_ops;

*void*\

**krb5\_cc\_clear\_mcred**(*krb5\_creds \*mcred*);

*krb5\_error\_code*\

**krb5\_cc\_close**(*krb5\_context context*, *krb5\_ccache id*);

*krb5\_error\_code*\

**krb5\_cc\_copy\_cache**(*krb5\_context context*, *const krb5\_ccache from*, *krb5\_ccache to*);

*krb5\_error\_code*\

**krb5\_cc\_default**(*krb5\_context context*, *krb5\_ccache \*id*);

*const char \**\

**krb5\_cc\_default\_name**(*krb5\_context context*);

*krb5\_error\_code*\

**krb5\_cc\_destroy**(*krb5\_context context*, *krb5\_ccache id*);

*krb5\_error\_code*\

**krb5\_cc\_end\_seq\_get**(*krb5\_context context*, *const krb5\_ccache id*, *krb5\_cc\_cursor \*cursor*);

*krb5\_error\_code*\

**krb5\_cc\_gen\_new**(*krb5\_context context*, *const krb5\_cc\_ops \*ops*, *krb5\_ccache \*id*);

*krb5\_error\_code*\

**krb5\_cc\_get\_full\_name**(*krb5\_context context*, *krb5\_ccache id*, *char \*\*str*);

*const char \**\

**krb5\_cc\_get\_name**(*krb5\_context context*, *krb5\_ccache id*);

*krb5\_error\_code*\

**krb5\_cc\_get\_principal**(*krb5\_context context*, *krb5\_ccache id*, *krb5\_principal \*principal*);

*const char \**\

**krb5\_cc\_get\_type**(*krb5\_context context*, *krb5\_ccache id*);

*const krb5\_cc\_ops \**\

**krb5\_cc\_get\_ops**(*krb5\_context context*, *krb5\_ccache id*);

*const krb5\_cc\_ops \**\

**krb5\_cc\_get\_prefix\_ops**(*krb5\_context context*, *const char \*prefix*);

*krb5\_error\_code*\

**krb5\_cc\_get\_version**(*krb5\_context context*, *const krb5\_ccache id*);

*krb5\_error\_code*\

**krb5\_cc\_initialize**(*krb5\_context context*, *krb5\_ccache id*, *krb5\_principal primary\_principal*);

*krb5\_error\_code*\

**krb5\_cc\_register**(*krb5\_context context*, *const krb5\_cc\_ops \*ops*, *krb5\_boolean override*);

*krb5\_error\_code*\

**krb5\_cc\_resolve**(*krb5\_context context*, *const char \*name*, *krb5\_ccache \*id*);

*krb5\_error\_code*\

**krb5\_cc\_retrieve\_cred**(*krb5\_context context*, *krb5\_ccache id*, *krb5\_flags whichfields*, *const krb5\_creds \*mcreds*, *krb5\_creds \*creds*);

*krb5\_error\_code*\

**krb5\_cc\_remove\_cred**(*krb5\_context context*, *krb5\_ccache id*, *krb5\_flags which*, *krb5\_creds \*cred*);

*krb5\_error\_code*\

**krb5\_cc\_set\_default\_name**(*krb5\_context context*, *const char \*name*);

*krb5\_error\_code*\

**krb5\_cc\_start\_seq\_get**(*krb5\_context context*, *const krb5\_ccache id*, *krb5\_cc\_cursor \*cursor*);

*krb5\_error\_code*\

**krb5\_cc\_store\_cred**(*krb5\_context context*, *krb5\_ccache id*, *krb5\_creds \*creds*);

*krb5\_error\_code*\

**krb5\_cc\_set\_flags**(*krb5\_context context*, *krb5\_cc\_set\_flags id*, *krb5\_flags flags*);

*krb5\_error\_code*\

**krb5\_cc\_next\_cred**(*krb5\_context context*, *const krb5\_ccache id*, *krb5\_cc\_cursor \*cursor*, *krb5\_creds \*creds*);

*krb5\_error\_code*\

**krb5\_cc\_next\_cred\_match**(*krb5\_context context*, *const krb5\_ccache id*, *krb5\_cc\_cursor \*cursor*, *krb5\_creds \*creds*, *krb5\_flags whichfields*, *const krb5\_creds \*mcreds*);

*krb5\_error\_code*\

**krb5\_cc\_new\_unique**(*krb5\_context context*, *const char \*type*, *const char \*hint*, *krb5\_ccache \*id*);

## DESCRIPTION

The krb5\_ccache structure holds a Kerberos credential cache.

The krb5\_cc\_cursor structure holds current position in a credential cache when iterating over the cache.

The krb5\_cc\_ops structure holds a set of operations that can me preformed on a credential cache.

There is no component inside krb5\_ccache, krb5\_cc\_cursor nor krb5\_fcc\_ops that is directly referable.

The krb5\_creds holds a Kerberos credential, see manpage for [krb5\_creds(3)](/krb5_creds/3.md).

**krb5\_cc\_default\_name**() and **krb5\_cc\_set\_default\_name**() gets and sets the default name for the *context*.

**krb5\_cc\_default**() opens the default credential cache in *id*. Return 0 or an error code.

**krb5\_cc\_gen\_new**() generates a new credential cache of type *ops* in *id*. Return 0 or an error code. The Heimdal version of this function also runs **krb5\_cc\_initialize**() on the credential cache, but since the MIT version doesn't, portable code must call krb5\_cc\_initialize.

**krb5\_cc\_new\_unique**() generates a new unique credential cache of *type* in *id*. If type is NULL, the library chooses the default credential cache type. The supplied *hint* (that can be 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 *id* should be freed using **krb5\_cc\_close**() or **krb5\_cc\_destroy**(). Returns 0 or an error code.

**krb5\_cc\_resolve**() finds and allocates a credential cache in *id* from the specification in *residual*. If the credential cache name doesn't contain any colon (:), interpret it as a file name. Return 0 or an error code.

**krb5\_cc\_initialize**() creates a new credential cache in *id* for *primary\_principal*. Return 0 or an error code.

**krb5\_cc\_close**() stops using the credential cache *id* and frees the related resources. Return 0 or an error code. **krb5\_cc\_destroy**() removes the credential cache and closes (by calling **krb5\_cc\_close**()) *id*. Return 0 or an error code.

**krb5\_cc\_copy\_cache**() copys the contents of *from* to *to*.

**krb5\_cc\_get\_full\_name**() returns the complete resolvable name of the credential cache *id* in *str*. *str* should be freed with [free(3)](/free/3.md). Returns 0 or an error, on error *\*str* is set to NULL.

**krb5\_cc\_get\_name**() returns the name of the credential cache *id*.

**krb5\_cc\_get\_principal**() returns the principal of *id* in *principal*. Return 0 or an error code.

**krb5\_cc\_get\_type**() returns the type of the credential cache *id*.

**krb5\_cc\_get\_ops**() returns the ops of the credential cache *id*.

**krb5\_cc\_get\_version**() returns the version of *id*.

**krb5\_cc\_register**() Adds a new credential cache type with operations *ops*, overwriting any existing one if *override*. Return an error code or 0.

**krb5\_cc\_get\_prefix\_ops**() Get the cc ops that is registered in *context* to handle the *prefix*. Returns NULL if ops not found.

**krb5\_cc\_remove\_cred**() removes the credential identified by *(*, *cred*, *which*) from *id*.

**krb5\_cc\_store\_cred**() stores *creds* in the credential cache *id*. Return 0 or an error code.

**krb5\_cc\_set\_flags**() sets the flags of *id* to *flags*.

**krb5\_cc\_clear\_mcred**() clears the *mcreds* argument so it is reset and can be used with *krb5\_cc\_retrieve\_cred*.

**krb5\_cc\_retrieve\_cred**(), retrieves the credential identified by *mcreds* (and *whichfields*) from *id* in *creds*. *creds* should be freed using **krb5\_free\_cred\_contents**(). Return 0 or an error code.

**krb5\_cc\_start\_seq\_get**() initiates the krb5\_cc\_cursor structure to be used for iteration over the credential cache.

**krb5\_cc\_next\_cred**() retrieves the next cred pointed to by *(*, *id*, *cursor*) in *creds*, and advance *cursor*. Return 0 or an error code.

**krb5\_cc\_next\_cred\_match**() is similar to **krb5\_cc\_next\_cred**() except that it will only return creds matching  *whichfields* and *mcreds* (as interpreted by  [krb5\_compare\_creds(3)](/krb5_compare_creds/3.md).)

**krb5\_cc\_end\_seq\_get**() Destroys the cursor *cursor*.

## 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_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;
}
```

## SEE ALSO

[krb5(3)](/krb5/3.md), [krb5.conf(5)](/krb5.conf/5.md), [kerberos(8)](/kerberos/8.md)
