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

« back to all changes in this revision

Viewing changes to src/lib/krb5/ccache/ccapi/stdcc.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:
5
5
 * Written by Frank Dabek July 1998
6
6
 * Updated by Jeffrey Altman June 2006
7
7
 *
8
 
 * Copyright 1998, 1999, 2006 by the Massachusetts Institute of Technology.
 
8
 * Copyright 1998, 1999, 2006, 2008 by the Massachusetts Institute of Technology.
9
9
 * All Rights Reserved.
10
10
 *
11
11
 * Export of this software from the United States of America may
29
29
 * 
30
30
 */
31
31
 
 
32
#if defined(_WIN32) || defined(USE_CCAPI)
 
33
 
32
34
#include "k5-int.h"
33
35
#include "stdcc.h"
34
36
#include "stdcc_util.h"
88
90
      krb5_stdccv3_ptcursor_new,
89
91
      krb5_stdccv3_ptcursor_next,
90
92
      krb5_stdccv3_ptcursor_free,
91
 
      NULL,
92
 
      NULL,
93
 
      NULL,
 
93
      NULL, /* move */
 
94
      krb5_stdccv3_last_change_time, /* lastchange */
 
95
      NULL, /* wasdefault */
 
96
      krb5_stdccv3_lock,
 
97
      krb5_stdccv3_unlock,
94
98
#else
95
99
      krb5_stdcc_get_name,
96
100
      krb5_stdcc_resolve,
230
234
    krb5_error_code err = 0;
231
235
    
232
236
    if (gCCVersion >= ccapi_version_5) {
233
 
        krb5_os_context os_ctx = (krb5_os_context) in_context->os_context;
 
237
        krb5_os_context os_ctx = (krb5_os_context) &in_context->os_context;
234
238
        cc_time_t time_offset = 0;
235
239
    
236
240
        err = cc_ccache_get_kdc_time_offset (in_ccache, cc_credentials_v5,
257
261
    krb5_error_code err = 0;
258
262
    
259
263
    if (gCCVersion >= ccapi_version_5) {
260
 
        krb5_os_context os_ctx = (krb5_os_context) in_context->os_context;
 
264
        krb5_os_context os_ctx = (krb5_os_context) &in_context->os_context;
261
265
        
262
266
        if (!err && os_ctx->os_flags & KRB5_OS_TOFFSET_VALID) {
263
267
            err = cc_ccache_set_kdc_time_offset (in_ccache, 
343
347
    }
344
348
    
345
349
    if (!err) {
346
 
        name = (char *) malloc (sizeof (*name) * (strlen (ccstring->data) + 1));
 
350
        name = strdup (ccstring->data);
347
351
        if (!name) { err = KRB5_CC_NOMEM; }
348
352
    }
349
353
    
350
354
    if (!err) {
351
 
        strcpy (name, ccstring->data);
352
355
        ccapi_data->cache_name = name;
353
356
        name = NULL; /* take ownership */
354
357
        
403
406
    }
404
407
    
405
408
    if (!err) {
406
 
        name = malloc (strlen(residual) + 1);
 
409
        name = strdup (residual);
407
410
        if (!name) { err = KRB5_CC_NOMEM; }
408
411
    }
409
412
    
417
420
    }
418
421
 
419
422
    if (!err) {
420
 
        strcpy(name, residual);        
421
423
        ccapi_data->cache_name = name;
422
424
        name = NULL; /* take ownership */
423
425
 
846
848
    }
847
849
    if (err == ccIteratorEnd) { err = ccErrCredentialsNotFound; }    
848
850
 
 
851
    if (iterator) {
 
852
        err = cc_credentials_iterator_release(iterator);
 
853
    }
 
854
 
849
855
    if (!err) {
850
856
        cache_changed ();
851
857
    }
906
912
        cc_string_t ccstring = NULL;
907
913
        char *name = NULL;
908
914
        
909
 
        // TODO set proper errors, check context param
910
915
        if (!cursor || !cursor->data) {
911
916
                err = ccErrInvalidContext;
912
917
        }
933
938
        }
934
939
 
935
940
        if (!err) {
936
 
            name = (char *) malloc (sizeof (*name) * (strlen (ccstring->data) + 1));
 
941
            name = strdup (ccstring->data);
937
942
            if (!name) { err = KRB5_CC_NOMEM; }
938
943
        }
939
944
        
940
945
        if (!err) {
941
 
            strcpy (name, ccstring->data);
942
946
            ccapi_data->cache_name = name;
943
947
            name = NULL; /* take ownership */
944
948
    
982
986
    return 0;
983
987
}
984
988
 
 
989
krb5_error_code KRB5_CALLCONV krb5_stdccv3_last_change_time
 
990
                (krb5_context context, krb5_ccache id,
 
991
           krb5_timestamp *change_time)
 
992
{
 
993
    krb5_error_code err = 0;
 
994
    stdccCacheDataPtr ccapi_data = id->data;
 
995
    cc_time_t ccapi_change_time = 0;
 
996
 
 
997
    *change_time = 0;
 
998
    
 
999
    if (!err) {
 
1000
        err = stdccv3_setup(context, ccapi_data);
 
1001
    }
 
1002
    if (!err) {
 
1003
        err = cc_ccache_get_change_time (ccapi_data->NamedCache, &ccapi_change_time);
 
1004
    }
 
1005
    if (!err) {
 
1006
        *change_time = ccapi_change_time;
 
1007
    }
 
1008
    
 
1009
    return cc_err_xlate (err);
 
1010
}
 
1011
 
 
1012
krb5_error_code KRB5_CALLCONV krb5_stdccv3_lock
 
1013
(krb5_context context, krb5_ccache id)
 
1014
{
 
1015
    krb5_error_code err = 0;
 
1016
    stdccCacheDataPtr ccapi_data = id->data;
 
1017
    
 
1018
    if (!err) {
 
1019
        err = stdccv3_setup(context, ccapi_data);
 
1020
    }
 
1021
    if (!err) {
 
1022
        err = cc_ccache_lock(ccapi_data->NamedCache, cc_lock_write, cc_lock_block);
 
1023
    }
 
1024
    return cc_err_xlate(err);    
 
1025
}
 
1026
 
 
1027
krb5_error_code KRB5_CALLCONV krb5_stdccv3_unlock
 
1028
(krb5_context context, krb5_ccache id)
 
1029
{
 
1030
    krb5_error_code err = 0;
 
1031
    stdccCacheDataPtr ccapi_data = id->data;
 
1032
    
 
1033
    if (!err) {
 
1034
        err = stdccv3_setup(context, ccapi_data);
 
1035
    }
 
1036
    if (!err) {
 
1037
        err = cc_ccache_unlock(ccapi_data->NamedCache);
 
1038
    }
 
1039
    return cc_err_xlate(err);    
 
1040
}
 
1041
 
 
1042
krb5_error_code KRB5_CALLCONV krb5_stdccv3_context_lock
 
1043
(krb5_context context)
 
1044
{
 
1045
    krb5_error_code err = 0;
 
1046
 
 
1047
    if (!err && !gCntrlBlock) {
 
1048
        err = cc_initialize (&gCntrlBlock, ccapi_version_max, &gCCVersion, NULL);
 
1049
    }
 
1050
    if (!err) {
 
1051
        err = cc_context_lock(gCntrlBlock, cc_lock_write, cc_lock_block);
 
1052
    }
 
1053
    return cc_err_xlate(err);    
 
1054
}
 
1055
 
 
1056
krb5_error_code KRB5_CALLCONV krb5_stdccv3_context_unlock
 
1057
(krb5_context context)
 
1058
{
 
1059
    krb5_error_code err = 0;
 
1060
 
 
1061
    if (!err && !gCntrlBlock) {
 
1062
        err = cc_initialize (&gCntrlBlock, ccapi_version_max, &gCCVersion, NULL);
 
1063
    }
 
1064
    if (!err) {
 
1065
        err = cc_context_unlock(gCntrlBlock);
 
1066
    }
 
1067
    return cc_err_xlate(err);    
 
1068
}
 
1069
 
985
1070
#else /* !USE_CCAPI_V3 */
986
1071
 
987
1072
static krb5_error_code stdcc_setup(krb5_context context,
1060
1145
        
1061
1146
        /* create a unique name */
1062
1147
        cc_get_change_time(gCntrlBlock, &change_time);
1063
 
        sprintf(name, "gen_new_cache%d", change_time);
 
1148
        snprintf(name, 256, "gen_new_cache%d", change_time);
1064
1149
        
1065
1150
        /* create the new cache */
1066
1151
        err = cc_create(gCntrlBlock, name, name, CC_CRED_V5, 0L,
1114
1199
        if (!(ccapi_data = (stdccCacheDataPtr)malloc(sizeof(stdccCacheData))))
1115
1200
                goto errout;
1116
1201
 
1117
 
        if (!(cName = malloc(strlen(residual)+1)))
 
1202
        if (!(cName = strdup(residual)))
1118
1203
                goto errout;
1119
1204
        
1120
1205
        newCache->ops = &krb5_cc_stdcc_ops;
1121
1206
        newCache->data = ccapi_data;
1122
1207
        ccapi_data->cache_name = cName;
1123
1208
 
1124
 
        strcpy(cName, residual);
1125
 
        
1126
1209
        err = cc_open(gCntrlBlock, cName, CC_CRED_V5, 0L,
1127
1210
                      &ccapi_data->NamedCache);
1128
1211
        if (err != CC_NOERROR) {
1586
1669
        int err;
1587
1670
        stdccCacheDataPtr       ccapi_data = id->data;
1588
1671
        krb5_error_code         retval;
1589
 
        
 
1672
        
1590
1673
        if ((retval = stdcc_setup(context, ccapi_data))) {
1591
1674
                if (retval == KRB5_FCC_NOFILE)
1592
1675
                        return 0;
1611
1694
        return 0;
1612
1695
}
1613
1696
#endif /* !USE_CCAPI_V3 */
 
1697
 
 
1698
#endif /* defined(_WIN32) || defined(USE_CCAPI) */
 
1699