~ubuntu-branches/ubuntu/maverick/krb5/maverick

« back to all changes in this revision

Viewing changes to src/lib/gssapi/krb5/export_name.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman
  • Date: 2009-05-07 16:16:34 UTC
  • mfrom: (13.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20090507161634-xqyk0s9na0le4flj
Tags: 1.7dfsg~beta1-4
When  decrypting the TGS response fails with the subkey, try with the
session key to work around Heimdal bug, Closes: #527353 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c; indent-tabs-mode: nil -*- */
1
2
/*
2
3
 * lib/gssapi/krb5/export_name.c
3
4
 *
4
 
 * Copyright 1997 by the Massachusetts Institute of Technology.
 
5
 * Copyright 1997, 2007 by the Massachusetts Institute of Technology.
5
6
 * All Rights Reserved.
6
7
 *
7
8
 * Export of this software from the United States of America may
28
29
#include "gssapiP_krb5.h"
29
30
 
30
31
OM_uint32 krb5_gss_export_name(OM_uint32  *minor_status,
31
 
                               const gss_name_t input_name,
32
 
                               gss_buffer_t exported_name)
 
32
                               const gss_name_t input_name,
 
33
                               gss_buffer_t exported_name)
33
34
{
34
 
        krb5_context context;
35
 
        krb5_error_code code;
36
 
        size_t length;
37
 
        char *str, *cp;
38
 
 
39
 
        if (minor_status)
40
 
                *minor_status = 0;
41
 
 
42
 
        code = krb5_gss_init_context(&context);
43
 
        if (code) {
44
 
            if (minor_status)
45
 
                *minor_status = code;
46
 
            return GSS_S_FAILURE;
47
 
        }
48
 
 
49
 
        exported_name->length = 0;
50
 
        exported_name->value = NULL;
51
 
        
52
 
        if (! kg_validate_name(input_name)) {
53
 
                if (minor_status)
54
 
                        *minor_status = (OM_uint32) G_VALIDATE_FAILED;
55
 
                krb5_free_context(context);
56
 
                return(GSS_S_CALL_BAD_STRUCTURE|GSS_S_BAD_NAME);
57
 
        }
58
 
 
59
 
        if ((code = krb5_unparse_name(context, (krb5_principal) input_name, 
60
 
                                      &str))) {
61
 
                if (minor_status)
62
 
                        *minor_status = code;
63
 
                krb5_free_context(context);
64
 
                return(GSS_S_FAILURE);
65
 
        }
66
 
 
67
 
        krb5_free_context(context);
68
 
        length = strlen(str);
69
 
        exported_name->length = 10 + length + gss_mech_krb5->length;
70
 
        exported_name->value = malloc(exported_name->length);
71
 
        if (!exported_name->value) {
72
 
                free(str);
73
 
                if (minor_status)
74
 
                        *minor_status = ENOMEM;
75
 
                return(GSS_S_FAILURE);
76
 
        }
77
 
        cp = exported_name->value;
78
 
 
79
 
        /* Note: we assume the OID will be less than 128 bytes... */
80
 
        *cp++ = 0x04; *cp++ = 0x01;
81
 
        *cp++ = (gss_mech_krb5->length+2) >> 8;
82
 
        *cp++ = (gss_mech_krb5->length+2) & 0xFF;
83
 
        *cp++ = 0x06;
84
 
        *cp++ = (gss_mech_krb5->length) & 0xFF;
85
 
        memcpy(cp, gss_mech_krb5->elements, gss_mech_krb5->length);
86
 
        cp += gss_mech_krb5->length;
87
 
        *cp++ = length >> 24;
88
 
        *cp++ = length >> 16;
89
 
        *cp++ = length >> 8;
90
 
        *cp++ = length & 0xFF;
91
 
        memcpy(cp, str, length);
92
 
 
93
 
        free(str);
94
 
 
95
 
        return(GSS_S_COMPLETE);
 
35
    krb5_context context;
 
36
    krb5_error_code code;
 
37
    size_t length;
 
38
    char *str;
 
39
    unsigned char *cp;
 
40
 
 
41
    if (minor_status)
 
42
        *minor_status = 0;
 
43
 
 
44
    code = krb5_gss_init_context(&context);
 
45
    if (code) {
 
46
        if (minor_status)
 
47
            *minor_status = code;
 
48
        return GSS_S_FAILURE;
 
49
    }
 
50
 
 
51
    exported_name->length = 0;
 
52
    exported_name->value = NULL;
 
53
 
 
54
    if (! kg_validate_name(input_name)) {
 
55
        if (minor_status)
 
56
            *minor_status = (OM_uint32) G_VALIDATE_FAILED;
 
57
        krb5_free_context(context);
 
58
        return(GSS_S_CALL_BAD_STRUCTURE|GSS_S_BAD_NAME);
 
59
    }
 
60
 
 
61
    if ((code = krb5_unparse_name(context, (krb5_principal) input_name,
 
62
                                  &str))) {
 
63
        if (minor_status)
 
64
            *minor_status = code;
 
65
        save_error_info((OM_uint32)code, context);
 
66
        krb5_free_context(context);
 
67
        return(GSS_S_FAILURE);
 
68
    }
 
69
 
 
70
    krb5_free_context(context);
 
71
    length = strlen(str);
 
72
    exported_name->length = 10 + length + gss_mech_krb5->length;
 
73
    exported_name->value = malloc(exported_name->length);
 
74
    if (!exported_name->value) {
 
75
        free(str);
 
76
        if (minor_status)
 
77
            *minor_status = ENOMEM;
 
78
        return(GSS_S_FAILURE);
 
79
    }
 
80
    cp = exported_name->value;
 
81
 
 
82
    /* Note: we assume the OID will be less than 128 bytes... */
 
83
    *cp++ = 0x04; *cp++ = 0x01;
 
84
    store_16_be(gss_mech_krb5->length+2, cp);
 
85
    cp += 2;
 
86
    *cp++ = 0x06;
 
87
    *cp++ = (gss_mech_krb5->length) & 0xFF;
 
88
    memcpy(cp, gss_mech_krb5->elements, gss_mech_krb5->length);
 
89
    cp += gss_mech_krb5->length;
 
90
    store_32_be(length, cp);
 
91
    cp += 4;
 
92
    memcpy(cp, str, length);
 
93
 
 
94
    free(str);
 
95
 
 
96
    return(GSS_S_COMPLETE);
96
97
}