|
|
749169 |
From 86fd6a4e1a768eff55aa3df6bc5794dfa63b801f Mon Sep 17 00:00:00 2001
|
|
|
665228 |
From: Greg Hudson <ghudson@mit.edu>
|
|
|
665228 |
Date: Mon, 9 Jan 2017 11:44:29 -0500
|
|
|
665228 |
Subject: [PATCH] Document and check init_creds context requirement
|
|
|
665228 |
|
|
|
665228 |
To ensure that the same clpreauth plugin modules and moddata pointers
|
|
|
665228 |
are used for each step of an initial creds operation, the caller must
|
|
|
665228 |
use the same library context for krb5_init_creds_init(),
|
|
|
665228 |
krb5_init_creds_step(), and krb5_init_creds_free(). Document and
|
|
|
665228 |
enforce this requirement.
|
|
|
665228 |
|
|
|
665228 |
ticket: 7877
|
|
|
665228 |
(cherry picked from commit c4beb35c9ac0711ef650abc4f1e44a4c82d5f3d0)
|
|
|
665228 |
---
|
|
|
665228 |
src/include/krb5/krb5.hin | 13 +++++++++++++
|
|
|
665228 |
src/lib/krb5/krb/get_in_tkt.c | 6 +++++-
|
|
|
665228 |
src/lib/krb5/krb/int-proto.h | 3 +++
|
|
|
665228 |
src/lib/krb5/krb/preauth2.c | 13 +++++++++++++
|
|
|
665228 |
4 files changed, 34 insertions(+), 1 deletion(-)
|
|
|
665228 |
|
|
|
665228 |
diff --git a/src/include/krb5/krb5.hin b/src/include/krb5/krb5.hin
|
|
|
665228 |
index 53ad85384..28557659e 100644
|
|
|
665228 |
--- a/src/include/krb5/krb5.hin
|
|
|
665228 |
+++ b/src/include/krb5/krb5.hin
|
|
|
665228 |
@@ -7321,6 +7321,9 @@ typedef struct _krb5_init_creds_context *krb5_init_creds_context;
|
|
|
665228 |
*
|
|
|
665228 |
* @param [in] context Library context
|
|
|
665228 |
* @param [in] ctx Initial credentials context
|
|
|
665228 |
+ *
|
|
|
665228 |
+ * @a context must be the same as the one passed to krb5_init_creds_init() for
|
|
|
665228 |
+ * this initial credentials context.
|
|
|
665228 |
*/
|
|
|
665228 |
void KRB5_CALLCONV
|
|
|
665228 |
krb5_init_creds_free(krb5_context context, krb5_init_creds_context ctx);
|
|
|
665228 |
@@ -7335,6 +7338,9 @@ krb5_init_creds_free(krb5_context context, krb5_init_creds_context ctx);
|
|
|
665228 |
* krb5_init_creds_init(). On successful return, the credentials can be
|
|
|
665228 |
* retrieved with krb5_init_creds_get_creds().
|
|
|
665228 |
*
|
|
|
665228 |
+ * @a context must be the same as the one passed to krb5_init_creds_init() for
|
|
|
665228 |
+ * this initial credentials context.
|
|
|
665228 |
+ *
|
|
|
665228 |
* @retval 0 Success; otherwise - Kerberos error codes
|
|
|
665228 |
*/
|
|
|
665228 |
krb5_error_code KRB5_CALLCONV
|
|
|
665228 |
@@ -7385,6 +7391,10 @@ krb5_init_creds_get_error(krb5_context context, krb5_init_creds_context ctx,
|
|
|
665228 |
* This function creates a new context for acquiring initial credentials. Use
|
|
|
665228 |
* krb5_init_creds_free() to free @a ctx when it is no longer needed.
|
|
|
665228 |
*
|
|
|
665228 |
+ * Any subsequent calls to krb5_init_creds_step(), krb5_init_creds_get(), or
|
|
|
665228 |
+ * krb5_init_creds_free() for this initial credentials context must use the
|
|
|
665228 |
+ * same @a context argument as the one passed to this function.
|
|
|
665228 |
+ *
|
|
|
665228 |
* @retval 0 Success; otherwise - Kerberos error codes
|
|
|
665228 |
*/
|
|
|
665228 |
krb5_error_code KRB5_CALLCONV
|
|
|
665228 |
@@ -7434,6 +7444,9 @@ krb5_init_creds_set_keytab(krb5_context context, krb5_init_creds_context ctx,
|
|
|
665228 |
* transmit the next request using TCP rather than UDP. If this function
|
|
|
665228 |
* returns any other error, the initial credential exchange has failed.
|
|
|
665228 |
*
|
|
|
665228 |
+ * @a context must be the same as the one passed to krb5_init_creds_init() for
|
|
|
665228 |
+ * this initial credentials context.
|
|
|
665228 |
+ *
|
|
|
665228 |
* @retval 0 Success; otherwise - Kerberos error codes
|
|
|
665228 |
*/
|
|
|
665228 |
krb5_error_code KRB5_CALLCONV
|
|
|
665228 |
diff --git a/src/lib/krb5/krb/get_in_tkt.c b/src/lib/krb5/krb/get_in_tkt.c
|
|
|
665228 |
index 80f5e1870..52e07bb67 100644
|
|
|
665228 |
--- a/src/lib/krb5/krb/get_in_tkt.c
|
|
|
665228 |
+++ b/src/lib/krb5/krb/get_in_tkt.c
|
|
|
665228 |
@@ -1667,7 +1667,7 @@ krb5_init_creds_step(krb5_context context,
|
|
|
665228 |
krb5_data *realm,
|
|
|
665228 |
unsigned int *flags)
|
|
|
665228 |
{
|
|
|
665228 |
- krb5_error_code code = 0, code2;
|
|
|
665228 |
+ krb5_error_code code, code2;
|
|
|
665228 |
|
|
|
665228 |
*flags = 0;
|
|
|
665228 |
|
|
|
665228 |
@@ -1680,6 +1680,10 @@ krb5_init_creds_step(krb5_context context,
|
|
|
665228 |
if (ctx->complete)
|
|
|
665228 |
return EINVAL;
|
|
|
665228 |
|
|
|
665228 |
+ code = k5_preauth_check_context(context, ctx);
|
|
|
665228 |
+ if (code)
|
|
|
665228 |
+ return code;
|
|
|
665228 |
+
|
|
|
665228 |
if (in->length != 0) {
|
|
|
665228 |
code = init_creds_step_reply(context, ctx, in);
|
|
|
665228 |
if (code == KRB5KRB_ERR_RESPONSE_TOO_BIG) {
|
|
|
665228 |
diff --git a/src/lib/krb5/krb/int-proto.h b/src/lib/krb5/krb/int-proto.h
|
|
|
665228 |
index f1667c238..628f0baa8 100644
|
|
|
665228 |
--- a/src/lib/krb5/krb/int-proto.h
|
|
|
665228 |
+++ b/src/lib/krb5/krb/int-proto.h
|
|
|
665228 |
@@ -208,6 +208,9 @@ void
|
|
|
665228 |
k5_preauth_request_context_fini(krb5_context context,
|
|
|
665228 |
krb5_init_creds_context ctx);
|
|
|
665228 |
|
|
|
665228 |
+krb5_error_code
|
|
|
665228 |
+k5_preauth_check_context(krb5_context context, krb5_init_creds_context ctx);
|
|
|
665228 |
+
|
|
|
665228 |
krb5_error_code
|
|
|
665228 |
k5_response_items_new(k5_response_items **ri_out);
|
|
|
665228 |
|
|
|
665228 |
diff --git a/src/lib/krb5/krb/preauth2.c b/src/lib/krb5/krb/preauth2.c
|
|
|
665228 |
index 9a178f4e3..9c5d6eaa9 100644
|
|
|
665228 |
--- a/src/lib/krb5/krb/preauth2.c
|
|
|
665228 |
+++ b/src/lib/krb5/krb/preauth2.c
|
|
|
665228 |
@@ -296,6 +296,19 @@ k5_preauth_request_context_fini(krb5_context context,
|
|
|
665228 |
ctx->preauth_reqctx = NULL;
|
|
|
665228 |
}
|
|
|
665228 |
|
|
|
665228 |
+krb5_error_code
|
|
|
665228 |
+k5_preauth_check_context(krb5_context context, krb5_init_creds_context ctx)
|
|
|
665228 |
+{
|
|
|
665228 |
+ krb5_preauth_req_context reqctx = ctx->preauth_reqctx;
|
|
|
665228 |
+
|
|
|
665228 |
+ if (reqctx != NULL && reqctx->orig_context != context) {
|
|
|
665228 |
+ k5_setmsg(context, EINVAL,
|
|
|
665228 |
+ _("krb5_init_creds calls must use same library context"));
|
|
|
665228 |
+ return EINVAL;
|
|
|
665228 |
+ }
|
|
|
665228 |
+ return 0;
|
|
|
665228 |
+}
|
|
|
665228 |
+
|
|
|
665228 |
/* Return 1 if pa_type is a real preauthentication mechanism according to the
|
|
|
665228 |
* module h. Return 0 if it is not. */
|
|
|
665228 |
static int
|