Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Jun 16, 2015
1 parent 29719a0 commit 45812a0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 47 deletions.
22 changes: 8 additions & 14 deletions src/modules/rlm_krb5/krb5.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ char const *rlm_krb5_error(krb5_context context, krb5_error_code code)
msg = krb5_get_error_message(context, code);
if (msg) {
strlcpy(buffer, msg, KRB5_STRERROR_BUFSIZE);
#ifdef HAVE_KRB5_FREE_ERROR_MESSAGE
# ifdef HAVE_KRB5_FREE_ERROR_MESSAGE
krb5_free_error_message(context, msg);
#elif defined(HAVE_KRB5_FREE_ERROR_STRING)
# elif defined(HAVE_KRB5_FREE_ERROR_STRING)
{
char *free;

memcpy(&free, &msg, sizeof(free));
krb5_free_error_string(context, free);
}
#else
# error "No way to free error strings, missing krb5_free_error_message() and krb5_free_error_string()"
#endif
# else
# error "No way to free error strings, missing krb5_free_error_message() and krb5_free_error_string()"
# endif
} else {
strlcpy(buffer, "Unknown error", KRB5_STRERROR_BUFSIZE);
}
Expand All @@ -99,14 +99,10 @@ char const *rlm_krb5_error(krb5_context context, krb5_error_code code)
static int _mod_conn_free(rlm_krb5_handle_t *conn) {
krb5_free_context(conn->context);

if (conn->keytab) {
krb5_kt_close(conn->context, conn->keytab);
}
if (conn->keytab) krb5_kt_close(conn->context, conn->keytab);

#ifdef HEIMDAL_KRB5
if (conn->ccache) {
krb5_cc_destroy(conn->context, conn->ccache);
}
if (conn->ccache) krb5_cc_destroy(conn->context, conn->ccache);
#endif

return 0;
Expand Down Expand Up @@ -158,9 +154,7 @@ void *mod_conn_create(TALLOC_CTX *ctx, void *instance)
krb5_verify_opt_set_keytab(&conn->options, conn->keytab);
krb5_verify_opt_set_secure(&conn->options, true);

if (inst->service) {
krb5_verify_opt_set_service(&conn->options, inst->service);
}
if (inst->service) krb5_verify_opt_set_service(&conn->options, inst->service);
#else
krb5_verify_init_creds_opt_set_ap_req_nofail(inst->vic_options, true);
#endif
Expand Down
51 changes: 18 additions & 33 deletions src/modules/rlm_krb5/rlm_krb5.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,14 @@ static int mod_detach(void *instance)
#ifndef HEIMDAL_KRB5
talloc_free(inst->vic_options);

if (inst->gic_options) {
krb5_get_init_creds_opt_free(inst->context, inst->gic_options);
}

if (inst->server) {
krb5_free_principal(inst->context, inst->server);
}
if (inst->gic_options) krb5_get_init_creds_opt_free(inst->context, inst->gic_options);
if (inst->server) krb5_free_principal(inst->context, inst->server);
#endif

/* Don't free hostname, it's just a pointer into service_princ */
talloc_free(inst->service);

if (inst->context) {
krb5_free_context(inst->context);
}
if (inst->context) krb5_free_context(inst->context);
#ifdef KRB5_IS_THREAD_SAFE
fr_connection_pool_free(inst->pool);
#endif
Expand Down Expand Up @@ -110,9 +103,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
}

inst->xlat_name = cf_section_name2(conf);
if (!inst->xlat_name) {
inst->xlat_name = cf_section_name1(conf);
}
if (!inst->xlat_name) inst->xlat_name = cf_section_name1(conf);

ret = krb5_init_context(&inst->context);
if (ret) {
Expand Down Expand Up @@ -145,10 +136,8 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
}

#ifdef HEIMDAL_KRB5
if (inst->hostname) {
DEBUG("rlm_krb5 (%s): Ignoring hostname component of service principal \"%s\", not "
"needed/supported by Heimdal", inst->xlat_name, inst->hostname);
}
if (inst->hostname) DEBUG("rlm_krb5 (%s): Ignoring hostname component of service principal \"%s\", not "
"needed/supported by Heimdal", inst->xlat_name, inst->hostname);
#else

/*
Expand Down Expand Up @@ -338,12 +327,12 @@ static rlm_rcode_t CC_HINT(nonnull) mod_authenticate(void *instance, REQUEST *re

krb5_principal client;

#ifdef KRB5_IS_THREAD_SAFE
# ifdef KRB5_IS_THREAD_SAFE
conn = fr_connection_get(inst->pool);
if (!conn) return RLM_MODULE_FAIL;
#else
# else
conn = inst->conn;
#endif
# endif

/*
* Zero out local storage
Expand Down Expand Up @@ -390,9 +379,9 @@ static rlm_rcode_t CC_HINT(nonnull) mod_authenticate(void *instance, REQUEST *re
krb5_free_principal(conn->context, client);
}

#ifdef KRB5_IS_THREAD_SAFE
# ifdef KRB5_IS_THREAD_SAFE
fr_connection_release(inst->pool, conn);
#endif
# endif
return rcode;
}

Expand All @@ -415,12 +404,12 @@ static rlm_rcode_t CC_HINT(nonnull) mod_authenticate(void *instance, REQUEST *re

rad_assert(inst->context);

#ifdef KRB5_IS_THREAD_SAFE
# ifdef KRB5_IS_THREAD_SAFE
conn = fr_connection_get(inst->pool);
if (!conn) return RLM_MODULE_FAIL;
#else
# else
conn = inst->conn;
#endif
# endif

/*
* Zero out local storage
Expand Down Expand Up @@ -449,19 +438,15 @@ static rlm_rcode_t CC_HINT(nonnull) mod_authenticate(void *instance, REQUEST *re

RDEBUG("Attempting to authenticate against service principal");
ret = krb5_verify_init_creds(conn->context, &init_creds, inst->server, conn->keytab, NULL, inst->vic_options);
if (ret) {
rcode = krb5_process_error(request, conn, ret);
}
if (ret) rcode = krb5_process_error(request, conn, ret);

cleanup:
if (client) {
krb5_free_principal(conn->context, client);
}
if (client) krb5_free_principal(conn->context, client);
krb5_free_cred_contents(conn->context, &init_creds);

#ifdef KRB5_IS_THREAD_SAFE
# ifdef KRB5_IS_THREAD_SAFE
fr_connection_release(inst->pool, conn);
#endif
# endif
return rcode;
}

Expand Down

0 comments on commit 45812a0

Please sign in to comment.