From: Ken Raeburn Date: Mon, 6 Oct 2008 21:18:36 +0000 (+0000) Subject: Substitute LDAP in makefiles with "yes" or "no" depending on configuration. X-Git-Tag: krb5-1.7-alpha1~341 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9ef6e783a0971cf31537951b34e00a8f47445b29;p=krb5.git Substitute LDAP in makefiles with "yes" or "no" depending on configuration. Split ASN.1 encode and decode tests so that they can be run independently and/or in parallel. Add ASN.1 tests for LDAP key-data sequence type, run only if LDAP enabled. Use krb5int_access to get at the encoder and decoder. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20832 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/configure.in b/src/configure.in index 40d818327..f1608d474 100644 --- a/src/configure.in +++ b/src/configure.in @@ -1074,8 +1074,12 @@ if test -n "$OPENLDAP_PLUGIN"; then K5_GEN_MAKEFILE(plugins/kdb/ldap/ldap_util) K5_GEN_MAKEFILE(plugins/kdb/ldap/libkdb_ldap) ldap_plugin_dir=plugins/kdb/ldap + LDAP=yes +else + LDAP=no fi AC_SUBST(ldap_plugin_dir) +AC_SUBST(LDAP) AC_CHECK_HEADERS(Python.h python2.3/Python.h) diff --git a/src/tests/asn.1/Makefile.in b/src/tests/asn.1/Makefile.in index 6fd8ddbbc..3caf68203 100644 --- a/src/tests/asn.1/Makefile.in +++ b/src/tests/asn.1/Makefile.in @@ -4,6 +4,7 @@ mydir=tests/asn.1 BUILDTOP=$(REL)..$(S).. PROG_LIBPATH=-L$(TOPLIBD) PROG_RPATH=$(KRB5_LIBDIR) +LDAP=@LDAP@ RUN_SETUP = @KRB5_RUN_ENV@ @@ -28,25 +29,43 @@ krb5_decode_test: $(DECOBJS) $(KRB5_BASE_DEPLIBS) t_trval: t_trval.o $(CC) -o t_trval $(ALL_CFLAGS) t_trval.o -check:: krb5_decode_test krb5_encode_test +check:: check-encode check-decode + +check-decode: krb5_decode_test KRB5_CONFIG=$(SRCTOP)/config-files/krb5.conf ; \ export KRB5_CONFIG ;\ $(RUN_SETUP) $(VALGRIND) ./krb5_decode_test + +expected_encode.out: reference_encode.out ldap_encode.out + if test "$(LDAP)" = yes; then \ + cat $(srcdir)/reference_encode.out $(srcdir)/ldap_encode.out > expected_encode.out; \ + else \ + cat $(srcdir)/reference_encode.out > expected_encode.out; \ + fi + +expected_trval.out: trval_reference.out ldap_trval.out + if test "$(LDAP)" = yes; then \ + cat $(srcdir)/trval_reference.out $(srcdir)/ldap_trval.out > expected_trval.out; \ + else \ + cat $(srcdir)/trval_reference.out > expected_trval.out; \ + fi + +check-encode: krb5_encode_test expected_encode.out expected_trval.out $(RM) test.out KRB5_CONFIG=$(SRCTOP)/config-files/krb5.conf ; \ export KRB5_CONFIG ;\ $(RUN_SETUP) $(VALGRIND) ./krb5_encode_test > test.out - cmp test.out $(srcdir)/reference_encode.out + cmp test.out expected_encode.out KRB5_CONFIG=$(SRCTOP)/config-files/krb5.conf ; \ export KRB5_CONFIG ;\ $(RUN_SETUP) $(VALGRIND) ./krb5_encode_test -t > test.out - cmp test.out $(srcdir)/trval_reference.out + cmp test.out expected_trval.out $(RM) test.out install:: clean:: - rm -f *~ *.o krb5_encode_test krb5_decode_test test.out trval t_trval + rm -f *~ *.o krb5_encode_test krb5_decode_test test.out trval t_trval expected_encode.out expected_trval.out ################ Dependencies ################ diff --git a/src/tests/asn.1/krb5_decode_test.c b/src/tests/asn.1/krb5_decode_test.c index a84ac5983..7111a7ece 100644 --- a/src/tests/asn.1/krb5_decode_test.c +++ b/src/tests/asn.1/krb5_decode_test.c @@ -27,24 +27,25 @@ int main(argc, argv) com_err(argv[0], retval, "while initializing krb5"); exit(1); } + init_access(argv[0]); #define setup(type,typestring,constructor) \ type ref, *var; \ retval = constructor(&ref); \ - if (retval) { \ + if (retval) { \ com_err("krb5_decode_test", retval, "while making sample %s", typestring); \ exit(1); \ } #define decode_run(typestring,description,encoding,decoder,comparator,cleanup) \ retval = krb5_data_hex_parse(&code,encoding); \ - if (retval) { \ + if (retval) { \ com_err("krb5_decode_test", retval, "while parsing %s", typestring); \ exit(1); \ } \ retval = decoder(&code,&var); \ - if (retval) { \ + if (retval) { \ com_err("krb5_decode_test", retval, "while decoding %s", typestring); \ error_count++; \ } \ @@ -874,6 +875,15 @@ int main(argc, argv) ktest_empty_sam_response(&ref); } +#ifdef ENABLE_LDAP + /* ldap sequence_of_keys */ + { + setup(ldap_seqof_key_data,"ldap_seqof_key_data", + ktest_make_sample_ldap_seqof_key_data); + decode_run("ldap_seqof_key_data","","30 81 87 A0 03 02 01 01 A1 03 02 01 01 A2 03 02 01 2A A3 03 02 01 0E A4 71 30 6F 30 23 A0 10 30 0E A0 03 02 01 00 A1 07 04 05 73 61 6C 74 30 A1 0F 30 0D A0 03 02 01 02 A1 06 04 04 6B 65 79 30 30 23 A0 10 30 0E A0 03 02 01 01 A1 07 04 05 73 61 6C 74 31 A1 0F 30 0D A0 03 02 01 02 A1 06 04 04 6B 65 79 31 30 23 A0 10 30 0E A0 03 02 01 02 A1 07 04 05 73 61 6C 74 32 A1 0F 30 0D A0 03 02 01 02 A1 06 04 04 6B 65 79 32",acc.asn1_ldap_decode_sequence_of_keys,ktest_equal_ldap_sequence_of_keys,ktest_empty_ldap_seqof_key_data); + } +#endif + krb5_free_context(test_context); exit(error_count); return(error_count); diff --git a/src/tests/asn.1/krb5_encode_test.c b/src/tests/asn.1/krb5_encode_test.c index 2795a6383..3f8e34492 100644 --- a/src/tests/asn.1/krb5_encode_test.c +++ b/src/tests/asn.1/krb5_encode_test.c @@ -101,6 +101,7 @@ main(argc, argv) com_err(argv[0], retval, "while initializing krb5"); exit(1); } + init_access(argv[0]); #define setup(value,type,typestring,constructor) \ retval = constructor(&(value)); \ @@ -672,10 +673,19 @@ main(argc, argv) encode_krb5_predicted_sam_response); } #endif +#ifdef ENABLE_LDAP + { + ldap_seqof_key_data skd; + + setup(skd, ldap_seqof_key_data, "ldap_seqof_key_data", + ktest_make_sample_ldap_seqof_key_data); + encode_run(skd, ldap_seqof_key_data, "ldap_seqof_key_data", "", + acc.asn1_ldap_encode_sequence_of_keys); + ktest_empty_ldap_seqof_key_data(test_context, &skd); + } +#endif krb5_free_context(test_context); exit(error_count); return(error_count); } - - diff --git a/src/tests/asn.1/ktest.c b/src/tests/asn.1/ktest.c index 179512cbe..9e8754dd6 100644 --- a/src/tests/asn.1/ktest.c +++ b/src/tests/asn.1/ktest.c @@ -779,8 +779,40 @@ krb5_error_code ktest_make_sample_sam_response(p) return 0; } +#ifdef ENABLE_LDAP +static krb5_error_code ktest_make_sample_key_data(krb5_key_data *p, int i) +{ + char buf[10]; + p->key_data_ver = 2; + p->key_data_kvno = 42; + sprintf(buf, "key%d", i); + p->key_data_type[0] = 2; + p->key_data_length[0] = strlen(buf); + p->key_data_contents[0] = strdup(buf); + sprintf(buf, "salt%d", i); + p->key_data_type[1] = i; + p->key_data_length[1] = strlen(buf); + p->key_data_contents[1] = strdup(buf); + if (p->key_data_contents[0] == NULL || p->key_data_contents[1] == NULL) + return ENOMEM; + return 0; +} - +krb5_error_code ktest_make_sample_ldap_seqof_key_data(p) + ldap_seqof_key_data *p; +{ + int i; + p->mkvno = 14; + p->n_key_data = 3; + p->key_data = calloc(3,sizeof(krb5_key_data)); + for (i = 0; i < 3; i++) { + krb5_error_code ret; + ret = ktest_make_sample_key_data(&p->key_data[i], i); + if (ret) return ret; + } + return 0; +} +#endif /****************************************************************/ @@ -1289,3 +1321,16 @@ void ktest_empty_sam_response(p) ktest_empty_data(&(p->sam_enc_key.ciphertext)); ktest_empty_data(&(p->sam_enc_nonce_or_ts.ciphertext)); } + +#ifdef ENABLE_LDAP +void ktest_empty_ldap_seqof_key_data(ctx, p) + krb5_context ctx; + ldap_seqof_key_data *p; +{ + int i; + for (i = 0; i < p->n_key_data; i++) { + free(p->key_data[i].key_data_contents[0]); + free(p->key_data[i].key_data_contents[1]); + } +} +#endif diff --git a/src/tests/asn.1/ktest.h b/src/tests/asn.1/ktest.h index 915f36a00..5173260bd 100644 --- a/src/tests/asn.1/ktest.h +++ b/src/tests/asn.1/ktest.h @@ -2,6 +2,7 @@ #define __KTEST_H__ #include "k5-int.h" +#include "kdb.h" #define SAMPLE_USEC 123456 #define SAMPLE_TIME 771228197 /* Fri Jun 10 6:03:17 GMT 1994 */ @@ -97,7 +98,9 @@ krb5_error_code ktest_make_sample_sam_challenge (krb5_sam_challenge * p); krb5_error_code ktest_make_sample_sam_response (krb5_sam_response * p); - +#ifdef ENABLE_LDAP +krb5_error_code ktest_make_sample_ldap_seqof_key_data(ldap_seqof_key_data * p); +#endif /*----------------------------------------------------------------------*/ void ktest_empty_authorization_data @@ -197,6 +200,9 @@ void ktest_empty_sam_challenge (krb5_sam_challenge * p); void ktest_empty_sam_response (krb5_sam_response * p); +#ifdef ENABLE_LDAP +void ktest_empty_ldap_seqof_key_data(krb5_context, ldap_seqof_key_data *p); +#endif extern krb5_context test_context; extern char *sample_principal_name; diff --git a/src/tests/asn.1/ktest_equal.c b/src/tests/asn.1/ktest_equal.c index bc8f4bc16..5ec0a01dc 100644 --- a/src/tests/asn.1/ktest_equal.c +++ b/src/tests/asn.1/ktest_equal.c @@ -542,6 +542,45 @@ int ktest_equal_sam_response(ref, var) return p; } +#ifdef ENABLE_LDAP +static int equal_key_data(ref, var) + krb5_key_data *ref; + krb5_key_data *var; +{ + int p=TRUE; + if (ref==var) return TRUE; + else if (ref == NULL || var == NULL) return FALSE; + p=p&&scalar_equal(key_data_ver); + p=p&&scalar_equal(key_data_kvno); + p=p&&scalar_equal(key_data_type[0]); + p=p&&scalar_equal(key_data_type[1]); + p=p&&len_equal(key_data_length[0],key_data_contents[0], + ktest_equal_array_of_octet); + p=p&&len_equal(key_data_length[1],key_data_contents[1], + ktest_equal_array_of_octet); + return p; +} +static int equal_key_data_array(int n, krb5_key_data *ref, krb5_key_data *val) +{ + int i, p=TRUE; + for (i = 0; i < n; i++) { + p=p&&equal_key_data(ref+i, val+i); + } + return p; +} +int ktest_equal_ldap_sequence_of_keys(ref, var) + ldap_seqof_key_data *ref; + ldap_seqof_key_data *var; +{ + int p=TRUE; + if (ref==var) return TRUE; + else if (ref == NULL || var == NULL) return FALSE; + p=p&&scalar_equal(mkvno); + p=p&&len_equal(n_key_data,key_data,equal_key_data_array); + return p; +} +#endif + /**** arrays ****************************************************************/ int ktest_equal_array_of_data(length, ref, var) diff --git a/src/tests/asn.1/ktest_equal.h b/src/tests/asn.1/ktest_equal.h index d45cf51a3..217272378 100644 --- a/src/tests/asn.1/ktest_equal.h +++ b/src/tests/asn.1/ktest_equal.h @@ -2,6 +2,7 @@ #define __KTEST_EQUAL_H__ #include "k5-int.h" +#include "kdb.h" /* int ktest_equal_structure(krb5_structure *ref, *var) */ /* effects Returns true (non-zero) if ref and var are @@ -90,4 +91,6 @@ int ktest_equal_krb5_etype_info_entry (krb5_etype_info_entry * ref, krb5_etype_info_entry * var); +int ktest_equal_ldap_sequence_of_keys(ldap_seqof_key_data *ref, + ldap_seqof_key_data *var); #endif diff --git a/src/tests/asn.1/ldap_encode.out b/src/tests/asn.1/ldap_encode.out new file mode 100644 index 000000000..41dbc1e61 --- /dev/null +++ b/src/tests/asn.1/ldap_encode.out @@ -0,0 +1 @@ +encode_krb5_ldap_seqof_key_data: 30 81 87 A0 03 02 01 01 A1 03 02 01 01 A2 03 02 01 2A A3 03 02 01 0E A4 71 30 6F 30 23 A0 10 30 0E A0 03 02 01 00 A1 07 04 05 73 61 6C 74 30 A1 0F 30 0D A0 03 02 01 02 A1 06 04 04 6B 65 79 30 30 23 A0 10 30 0E A0 03 02 01 01 A1 07 04 05 73 61 6C 74 31 A1 0F 30 0D A0 03 02 01 02 A1 06 04 04 6B 65 79 31 30 23 A0 10 30 0E A0 03 02 01 02 A1 07 04 05 73 61 6C 74 32 A1 0F 30 0D A0 03 02 01 02 A1 06 04 04 6B 65 79 32 diff --git a/src/tests/asn.1/ldap_trval.out b/src/tests/asn.1/ldap_trval.out new file mode 100644 index 000000000..02a37e306 --- /dev/null +++ b/src/tests/asn.1/ldap_trval.out @@ -0,0 +1,30 @@ +encode_krb5_ldap_seqof_key_data: + +[Sequence/Sequence Of] +. [0] [Integer] 1 +. [1] [Integer] 1 +. [2] [Integer] 42 +. [3] [Integer] 14 +. [4] [Sequence/Sequence Of] +. . [Sequence/Sequence Of] +. . . [0] [Sequence/Sequence Of] +. . . . [0] [Integer] 0 +. . . . [1] [Octet String] "salt0" +. . . [1] [Sequence/Sequence Of] +. . . . [0] [Integer] 2 +. . . . [1] [Octet String] "key0" +. . [Sequence/Sequence Of] +. . . [0] [Sequence/Sequence Of] +. . . . [0] [Integer] 1 +. . . . [1] [Octet String] "salt1" +. . . [1] [Sequence/Sequence Of] +. . . . [0] [Integer] 2 +. . . . [1] [Octet String] "key1" +. . [Sequence/Sequence Of] +. . . [0] [Sequence/Sequence Of] +. . . . [0] [Integer] 2 +. . . . [1] [Octet String] "salt2" +. . . [1] [Sequence/Sequence Of] +. . . . [0] [Integer] 2 +. . . . [1] [Octet String] "key2" + diff --git a/src/tests/asn.1/utility.c b/src/tests/asn.1/utility.c index c5715b0bb..f2a856af2 100644 --- a/src/tests/asn.1/utility.c +++ b/src/tests/asn.1/utility.c @@ -4,6 +4,8 @@ #include #include +krb5int_access acc; + char hexchar (const unsigned int digit); asn1_error_code asn1_krb5_data_unparse(code, s) @@ -123,3 +125,13 @@ void asn1buf_print(buf) free(s); } #endif + +void init_access(const char *progname) +{ + krb5_error_code ret; + ret = krb5int_accessor(&acc, KRB5INT_ACCESS_VERSION); + if (ret) { + com_err(progname, ret, "while initializing accessor"); + exit(1); + } +} diff --git a/src/tests/asn.1/utility.h b/src/tests/asn.1/utility.h index 4c761244f..12d7a996a 100644 --- a/src/tests/asn.1/utility.h +++ b/src/tests/asn.1/utility.h @@ -3,6 +3,7 @@ #include "krbasn1.h" #include "asn1buf.h" +#include "k5-int.h" asn1_error_code asn1_krb5_data_unparse (const krb5_data *code, char **s); @@ -28,4 +29,7 @@ krb5_error_code krb5_data_hex_parse void asn1buf_print (const asn1buf *buf); +extern krb5int_access acc; +extern void init_access(const char *progname); + #endif