1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/gssapi/krb5/import_sec_context.c - Internalize the security context */
3 /*
4 * Copyright 1995,2004,2007,2008 by the Massachusetts Institute of Technology.
5 * All Rights Reserved.
6 *
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
11 *
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. Furthermore if you modify this software you must label
20 * your software as modified software and not distribute it in such a
21 * fashion that it might be confused with the original M.I.T. software.
22 * M.I.T. makes no representations about the suitability of
23 * this software for any purpose. It is provided "as is" without express
24 * or implied warranty.
25 */
26
27 #include "gssapiP_krb5.h"
28 /* for serialization initialization functions */
29 #include "k5-int.h"
30
31 /*
32 * Fix up the OID of the mechanism so that uses the static version of
33 * the OID if possible.
34 */
krb5_gss_convert_static_mech_oid(gss_OID oid)35 gss_OID krb5_gss_convert_static_mech_oid(gss_OID oid)
36 {
37 const gss_OID_desc *p;
38 OM_uint32 minor_status;
39
40 for (p = krb5_gss_oid_array; p->length; p++) {
41 if ((oid->length == p->length) &&
42 (memcmp(oid->elements, p->elements, p->length) == 0)) {
43 generic_gss_release_oid(&minor_status, &oid);
44 return (gss_OID) p;
45 }
46 }
47 return oid;
48 }
49
50 OM_uint32 KRB5_CALLCONV
krb5_gss_import_sec_context(OM_uint32 * minor_status,gss_buffer_t interprocess_token,gss_ctx_id_t * context_handle)51 krb5_gss_import_sec_context(OM_uint32 *minor_status,
52 gss_buffer_t interprocess_token,
53 gss_ctx_id_t *context_handle)
54 {
55 krb5_context context;
56 krb5_error_code kret = 0;
57 size_t blen;
58 krb5_gss_ctx_id_t ctx;
59 krb5_octet *ibp;
60
61 /* This is a bit screwy. We create a krb5 context because we need
62 one when calling the serialization code. However, one of the
63 objects we're unpacking is a krb5 context, so when we finish,
64 we can throw this one away. */
65 kret = krb5_gss_init_context(&context);
66 if (kret) {
67 *minor_status = kret;
68 return GSS_S_FAILURE;
69 }
70
71 /* Assume a tragic failure */
72 ctx = (krb5_gss_ctx_id_t) NULL;
73 *minor_status = 0;
74
75 /* Internalize the context */
76 ibp = (krb5_octet *) interprocess_token->value;
77 blen = (size_t) interprocess_token->length;
78 kret = kg_ctx_internalize(context, &ctx, &ibp, &blen);
79 if (kret) {
80 *minor_status = (OM_uint32) kret;
81 save_error_info(*minor_status, context);
82 krb5_free_context(context);
83 return(GSS_S_FAILURE);
84 }
85 krb5_free_context(context);
86
87 ctx->mech_used = krb5_gss_convert_static_mech_oid(ctx->mech_used);
88
89 *context_handle = (gss_ctx_id_t) ctx;
90
91 *minor_status = 0;
92 return (GSS_S_COMPLETE);
93 }
94