Skip to content

Commit

Permalink
Properly scope per-request preauth data
Browse files Browse the repository at this point in the history
It should be possible to successfully use multiple initial credentials
contexts with the same library context.  Create a new internal type
krb5_preauth_req_context containing per-request preauth state,
including the clpreauth modreq handles and the list of preauth types
already tried.  Remove this state from clpreauth_handle and
krb5_preauth_context.

ticket: 7877
  • Loading branch information
greghudson committed Jan 26, 2017
1 parent 459a081 commit b061f41
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 81 deletions.
3 changes: 3 additions & 0 deletions src/include/k5-trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ void krb5int_trace(krb5_context context, const char *fmt, ...);
TRACE(c, "Preauth tryagain input types: {patypes}", padata)
#define TRACE_PREAUTH_TRYAGAIN_OUTPUT(c, padata) \
TRACE(c, "Followup preauth for next request: {patypes}", padata)
#define TRACE_PREAUTH_WRONG_CONTEXT(c) \
TRACE(c, "Wrong context passed to krb5_init_creds_free(); leaking " \
"modreq objects")

#define TRACE_PROFILE_ERR(c,subsection, section, retval) \
TRACE(c, "Bad value of {str} from [{str}] in conf file: {kerr}", \
Expand Down
12 changes: 6 additions & 6 deletions src/lib/krb5/krb/get_in_tkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ krb5_init_creds_free(krb5_context context,
k5_response_items_free(ctx->rctx.items);
free(ctx->in_tkt_service);
zapfree(ctx->gakpw.storage.data, ctx->gakpw.storage.length);
k5_preauth_request_context_fini(context);
k5_preauth_request_context_fini(context, ctx);
krb5_free_error(context, ctx->err_reply);
krb5_free_pa_data(context, ctx->err_padata);
krb5_free_cred_contents(context, &ctx->cred);
Expand Down Expand Up @@ -834,8 +834,8 @@ restart_init_creds_loop(krb5_context context, krb5_init_creds_context ctx,
if (fast_upgrade)
ctx->fast_state->fast_state_flags |= KRB5INT_FAST_DO_FAST;

k5_preauth_request_context_fini(context);
k5_preauth_request_context_init(context);
k5_preauth_request_context_fini(context, ctx);
k5_preauth_request_context_init(context, ctx);
krb5_free_data(context, ctx->outer_request_body);
ctx->outer_request_body = NULL;
if (ctx->opt->flags & KRB5_GET_INIT_CREDS_OPT_PREAUTH_LIST) {
Expand Down Expand Up @@ -1522,7 +1522,7 @@ init_creds_step_reply(krb5_context context,
} else if ((reply_code == KDC_ERR_MORE_PREAUTH_DATA_REQUIRED ||
reply_code == KDC_ERR_PREAUTH_REQUIRED) && retry) {
/* reset the list of preauth types to try */
k5_reset_preauth_types_tried(context);
k5_reset_preauth_types_tried(ctx);
krb5_free_pa_data(context, ctx->preauth_to_use);
ctx->preauth_to_use = ctx->err_padata;
ctx->err_padata = NULL;
Expand Down Expand Up @@ -1573,7 +1573,7 @@ init_creds_step_reply(krb5_context context,
goto cleanup;

/* process any preauth data in the as_reply */
k5_reset_preauth_types_tried(context);
k5_reset_preauth_types_tried(ctx);
code = krb5int_fast_process_response(context, ctx->fast_state,
ctx->reply, &strengthen_key);
if (code != 0)
Expand Down Expand Up @@ -1658,7 +1658,7 @@ init_creds_step_reply(krb5_context context,
k5_prependmsg(context, code, _("Failed to store credentials"));
}

k5_preauth_request_context_fini(context);
k5_preauth_request_context_fini(context, ctx);

/* success */
ctx->complete = TRUE;
Expand Down
3 changes: 3 additions & 0 deletions src/lib/krb5/krb/init_creds_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "k5-json.h"
#include "int-proto.h"

typedef struct krb5_preauth_req_context_st *krb5_preauth_req_context;

struct krb5_responder_context_st {
k5_response_items *items;
};
Expand Down Expand Up @@ -67,6 +69,7 @@ struct _krb5_init_creds_context {
krb5_timestamp pa_offset;
krb5_int32 pa_offset_usec;
enum { NO_OFFSET = 0, UNAUTH_OFFSET, AUTH_OFFSET } pa_offset_state;
krb5_preauth_req_context preauth_reqctx;
};

krb5_error_code
Expand Down
8 changes: 5 additions & 3 deletions src/lib/krb5/krb/int-proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,19 @@ void
k5_free_preauth_context(krb5_context context);

void
k5_reset_preauth_types_tried(krb5_context context);
k5_reset_preauth_types_tried(krb5_init_creds_context ctx);

void
k5_preauth_prepare_request(krb5_context context, krb5_get_init_creds_opt *opt,
krb5_kdc_req *request);

void
k5_preauth_request_context_init(krb5_context context);
k5_preauth_request_context_init(krb5_context context,
krb5_init_creds_context ctx);

void
k5_preauth_request_context_fini(krb5_context context);
k5_preauth_request_context_fini(krb5_context context,
krb5_init_creds_context ctx);

krb5_error_code
k5_response_items_new(k5_response_items **ri_out);
Expand Down
Loading

0 comments on commit b061f41

Please sign in to comment.