diff options
Diffstat (limited to 'doc/doxy_examples')
| -rw-r--r-- | doc/doxy_examples/cc_set_config.c | 33 | ||||
| -rw-r--r-- | doc/doxy_examples/cc_unique.c | 23 | ||||
| -rwxr-xr-x | doc/doxy_examples/error_message.c | 20 | ||||
| -rw-r--r-- | doc/doxy_examples/tkt_creds.c | 55 | ||||
| -rw-r--r-- | doc/doxy_examples/verify_init_creds.c | 28 | 
5 files changed, 159 insertions, 0 deletions
diff --git a/doc/doxy_examples/cc_set_config.c b/doc/doxy_examples/cc_set_config.c new file mode 100644 index 0000000000000..838ff7e22cf0b --- /dev/null +++ b/doc/doxy_examples/cc_set_config.c @@ -0,0 +1,33 @@ +/** @example  cc_set_config.c + * + *  Usage examples for krb5_cc_set_config and krb5_cc_get_config functions + */ +#include <k5-int.h> + +krb5_error_code +func_set(krb5_context context, krb5_ccache id, +         krb5_const_principal principal, const char *key) +{ +   krb5_data config_data; + +   config_data.data = "yes"; +   config_data.length = strlen(config_data.data); +   return  krb5_cc_set_config(context, id, principal, key, &config_data); +} + +krb5_error_code +func_get(krb5_context context, krb5_ccache id, +         krb5_const_principal principal, const char *key) +{ +   krb5_data config_data; +   krb5_error_code ret; + +   config_data.data = NULL; +   ret = krb5_cc_get_config(context, id, principal, key, &config_data); +   if (ret){ +        return ret; +   } +   /* do something */ +   krb5_free_data_contents(context, &config_data); +   return ret; +} diff --git a/doc/doxy_examples/cc_unique.c b/doc/doxy_examples/cc_unique.c new file mode 100644 index 0000000000000..0a03edb5250e7 --- /dev/null +++ b/doc/doxy_examples/cc_unique.c @@ -0,0 +1,23 @@ +/** @example  cc_unique.c + * + *  Usage example for krb5_cc_new_unique function + */ +#include "k5-int.h" + +krb5_error_code +func(krb5_context context) +{ +    krb5_error_code ret; +    krb5_ccache ccache = NULL; + +    ret = krb5_cc_new_unique(context, "MEMORY", NULL, &ccache); +    if (ret){ +        ccache = NULL;  +        return ret; +    } +    /* do something */ +    if (ccache) +        (void)krb5_cc_destroy(context, ccache); +    return 0; +} + diff --git a/doc/doxy_examples/error_message.c b/doc/doxy_examples/error_message.c new file mode 100755 index 0000000000000..1e1569760fc49 --- /dev/null +++ b/doc/doxy_examples/error_message.c @@ -0,0 +1,20 @@ +/** @example  error_message.c + * + *  Demo for krb5_get/set/free_error_message function family + */ +#include <k5-int.h> + +krb5_error_code +func(krb5_context context) +{ +    krb5_error_code ret; + +    ret = krb5_func(context); +    if (ret) { +        const char *err_str = krb5_get_error_message(context, ret); +        krb5_set_error_message(context, ret, +                               "Failed krb5_func: %s", err_str); +        krb5_free_error_message(context, err_str); +    } +} +                 diff --git a/doc/doxy_examples/tkt_creds.c b/doc/doxy_examples/tkt_creds.c new file mode 100644 index 0000000000000..9ddf5cc8e282c --- /dev/null +++ b/doc/doxy_examples/tkt_creds.c @@ -0,0 +1,55 @@ +/** @example tkt_creds.c + * + *  Usage example for krb5_tkt_creds function family + */ +#include "krb5.h" + +krb5_error_code +func(krb5_context context, krb5_flags options, +     krb5_ccache ccache, krb5_creds *in_creds, +     krb5_creds **out_creds) +{ +    krb5_error_code code = KRB5_OK; +    krb5_creds *ncreds = NULL; +    krb5_tkt_creds_context ctx = NULL; + +    *out_creds = NULL; + +    /* Allocate a container. */ +    ncreds = k5alloc(sizeof(*ncreds), &code); +    if (ncreds == NULL) +        goto cleanup; + +    /* Make and execute a krb5_tkt_creds context to get the credential. */ +    code = krb5_tkt_creds_init(context, ccache, in_creds, options, &ctx); +    if (code != KRB5_OK) +        goto cleanup; +    code = krb5_tkt_creds_get(context, ctx); +    if (code != KRB5_OK) +        goto cleanup; +    code = krb5_tkt_creds_get_creds(context, ctx, ncreds); +    if (code != KRB5_OK) +        goto cleanup; + +    *out_creds = ncreds; +    ncreds = NULL; + +cleanup: +    krb5_free_creds(context, ncreds); +    krb5_tkt_creds_free(context, ctx); +    return code; +} + +/* Allocate zeroed memory; set *code to 0 on success or ENOMEM on failure. */ +static inline void * +k5alloc(size_t len, krb5_error_code *code) +{ +    void *ptr; + +    /* Allocate at least one byte since zero-byte allocs may return NULL. */ +    ptr = calloc((len > 0) ? len : 1, 1); +    *code = (ptr == NULL) ? ENOMEM : 0; +    return ptr; +} + + diff --git a/doc/doxy_examples/verify_init_creds.c b/doc/doxy_examples/verify_init_creds.c new file mode 100644 index 0000000000000..c22e2528424ee --- /dev/null +++ b/doc/doxy_examples/verify_init_creds.c @@ -0,0 +1,28 @@ +/** @example  verify_init_creds.c + * + *  Usage example for krb5_verify_init_creds function family + */ +#include "k5-int.h" + +krb5_error_code +func(krb5_context context,  krb5_creds *creds, krb5_principal server_principal) +{ +    krb5_error_code ret = KRB5_OK; +    krb5_verify_init_creds_opt options; + +    krb5_verify_init_creds_opt_init (&options); +    krb5_verify_init_creds_opt_set_ap_req_nofail (&options, 1); + +    ret = krb5_verify_init_creds(context, +                                 creds, +                                 server_principal, +                                 NULL /* use default keytab */, +                                 NULL /* don't store creds in ccache */, +                                 &options); +    if (ret) { +        /* error while verifying credentials for server */ +    } + +    return ret; +} +  | 
