From d6641a41a237a8fda05f1cce04d3eb085065f3de Mon Sep 17 00:00:00 2001 From: Ezra Peisach Date: Sun, 17 Aug 2008 23:34:41 +0000 Subject: [PATCH] Using gcov, it was noted that the tests were never including authdata in the test credential - and a segment of code was never tested. Add some fake authdata to the test creds. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20668 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/ccache/t_cc.c | 94 ++++++++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 8 deletions(-) diff --git a/src/lib/krb5/ccache/t_cc.c b/src/lib/krb5/ccache/t_cc.c index 15f5cfb59..f941bb60f 100644 --- a/src/lib/krb5/ccache/t_cc.c +++ b/src/lib/krb5/ccache/t_cc.c @@ -81,14 +81,87 @@ static void init_structs(void) test_creds.authdata = NULL; } -static void init_test_cred(krb5_context context) +static krb5_error_code init_test_cred(krb5_context context) { + krb5_error_code kret; + unsigned int i; + krb5_authdata *a; #define REALM "REALM" - krb5_build_principal(context, &test_creds.client, sizeof(REALM), REALM, - "client-comp1", "client-comp2", NULL); - - krb5_build_principal(context, &test_creds.server, sizeof(REALM), REALM, - "server-comp1", "server-comp2", NULL); + kret = krb5_build_principal(context, &test_creds.client, sizeof(REALM), REALM, + "client-comp1", "client-comp2", NULL); + if(kret) + return kret; + + kret = krb5_build_principal(context, &test_creds.server, sizeof(REALM), REALM, + "server-comp1", "server-comp2", NULL); + if(kret) { + krb5_free_principal(context, test_creds.client); + test_creds.client = 0; + goto cleanup; + } + + test_creds.authdata = malloc (3 * sizeof(krb5_authdata *)); + if (!test_creds.authdata) { + kret = ENOMEM; + goto cleanup; + } + + for (i = 0 ; i <= 2 ; i++) { + test_creds.authdata[i] = 0; + } + a = (krb5_authdata *) malloc(sizeof(krb5_authdata)); + if(!a) { + kret = ENOMEM; + goto cleanup; + } + a->magic = KV5M_AUTHDATA; + a->ad_type = KRB5_AUTHDATA_IF_RELEVANT; + a->contents = (krb5_octet * ) malloc(1); + if(!a->contents) { + free(a); + kret = ENOMEM; + goto cleanup; + } + a->contents[0]=5; + a->length = 1; + test_creds.authdata[0] = a; + + a = (krb5_authdata *) malloc(sizeof(krb5_authdata)); + if(!a) { + kret = ENOMEM; + goto cleanup; + } + a->magic = KV5M_AUTHDATA; + a->ad_type = KRB5_AUTHDATA_KDC_ISSUED; + a->contents = (krb5_octet * ) malloc(2); + if(!a->contents) { + free(a); + kret = ENOMEM; + goto cleanup; + } + a->contents[0]=4; + a->contents[1]=6; + a->length = 2; + test_creds.authdata[1] = a; + +cleanup: + if(kret) { + if (test_creds.client) { + krb5_free_principal(context, test_creds.client); + test_creds.client = 0; + } + if (test_creds.server) { + krb5_free_principal(context, test_creds.server); + test_creds.server = 0; + + } + if (test_creds.authdata) { + krb5_free_authdata(context, test_creds.authdata); + test_creds.authdata = 0; + } + } + + return kret; } static void free_test_cred(krb5_context context) @@ -96,7 +169,11 @@ static void free_test_cred(krb5_context context) krb5_free_principal(context, test_creds.client); krb5_free_principal(context, test_creds.server); - + + if(test_creds.authdata) { + krb5_free_authdata(context, test_creds.authdata); + test_creds.authdata = 0; + } } #define CHECK(kret,msg) \ @@ -125,7 +202,8 @@ static void cc_test(krb5_context context, const char *name, int flags) char newcache[300]; char *save_type; - init_test_cred(context); + kret = init_test_cred(context); + CHECK(kret, "init_creds"); kret = krb5_cc_resolve(context, name, &id); CHECK(kret, "resolve"); -- 2.26.2