From: Theodore Tso Date: Thu, 26 Sep 1996 22:54:45 +0000 (+0000) Subject: get_in_tkt.c (make_preauth_list): Correctly null-terminate the X-Git-Tag: krb5-1.0-freeze1~296 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=777053b025b8e13d8b102ae7c8894111bf094671;p=krb5.git get_in_tkt.c (make_preauth_list): Correctly null-terminate the preauth list generated by make_preauth_list. unparse.c (krb5_unparse_name_ext): Make unparse correctly handle all cases where a principal contains a nulls, backspace, newlines, or tabs. t_kerb.c (test_parse_principal): Add test for checking krb5_parse_principal() parse.c (krb5_parse_name): Set all of the magic field values. Makefile.in, t_ref_kerb.out: Added new tests to test krb5_parse() and krb5_unparse(). git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@9126 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/krb/ChangeLog b/src/lib/krb5/krb/ChangeLog index 32612bb8c..438876e42 100644 --- a/src/lib/krb5/krb/ChangeLog +++ b/src/lib/krb5/krb/ChangeLog @@ -1,3 +1,19 @@ +Tue Sep 24 20:59:14 1996 Theodore Y. Ts'o + + * get_in_tkt.c (make_preauth_list): Correctly null-terminate the + preauth list generated by make_preauth_list. + +Thu Sep 19 12:29:59 1996 Theodore Y. Ts'o + + * unparse.c (krb5_unparse_name_ext): Make unparse correctly handle + a all cases where a principal contains a nulls, backspace, + newlines, or tabs. + + * t_kerb.c (test_parse_principal): Add test for checking + krb5_parse_principal() + + * parse.c (krb5_parse_name): Set all of the magic field values. + Wed Jul 24 17:09:39 1996 Theodore Y. Ts'o * preauth.c (find_pa_system): Change type of first argument to be diff --git a/src/lib/krb5/krb/Makefile.in b/src/lib/krb5/krb/Makefile.in index ebeedb082..ea8330040 100644 --- a/src/lib/krb5/krb/Makefile.in +++ b/src/lib/krb5/krb/Makefile.in @@ -184,13 +184,23 @@ TEST_PROGS= t_walk_rtree t_kerb t_ser check-unix:: $(TEST_PROGS) KRB5_CONFIG=$(srcdir)/t_krb5.conf ; export KRB5_CONFIG ;\ - $(RUN_SETUP) ./t_kerb 425_conv_principal rcmd e40-po ATHENA.MIT.EDU \ - 425_conv_principal rcmd mit ATHENA.MIT.EDU \ - 425_conv_principal rcmd lithium ATHENA.MIT.EDU \ - 425_conv_principal rcmd tweedledumb CYGNUS.COM \ - 425_conv_principal rcmd uunet UU.NET \ - 425_conv_principal zephyr zephyr ATHENA.MIT.EDU \ - 425_conv_principal kadmin ATHENA.MIT.EDU ATHENA.MIT.EDU \ + $(RUN_SETUP) ./t_kerb \ + parse_name tytso \ + parse_name tytso@SHAZAAM \ + parse_name tytso/root@VEGGIE.COM \ + parse_name tytso/tuber/carrot@VEGGIE.COM \ + parse_name tytso/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t \ + parse_name tytso/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t@FOO \ + parse_name tytso\\\\0/\\0@B\\n\\t\\\\GAG \ + parse_name tytso/\\n/\\b\\t@B\\0hacky-test \ + parse_name \\/slash/\\@atsign/octa\\/thorpe@\\/slash\\@at\\/sign \ + 425_conv_principal rcmd e40-po ATHENA.MIT.EDU \ + 425_conv_principal rcmd mit ATHENA.MIT.EDU \ + 425_conv_principal rcmd lithium ATHENA.MIT.EDU \ + 425_conv_principal rcmd tweedledumb CYGNUS.COM \ + 425_conv_principal rcmd uunet UU.NET \ + 425_conv_principal zephyr zephyr ATHENA.MIT.EDU \ + 425_conv_principal kadmin ATHENA.MIT.EDU ATHENA.MIT.EDU \ > test.out cmp test.out $(srcdir)/t_ref_kerb.out $(RM) test.out diff --git a/src/lib/krb5/krb/get_in_tkt.c b/src/lib/krb5/krb/get_in_tkt.c index 891bff856..048a56ca8 100644 --- a/src/lib/krb5/krb/get_in_tkt.c +++ b/src/lib/krb5/krb/get_in_tkt.c @@ -354,6 +354,7 @@ make_preauth_list(context, ptypes, ret_list) (*preauthp)->length = 0; (*preauthp)->contents = 0; } + *preauthp = NULL; *ret_list = preauth_to_use; return 0; } diff --git a/src/lib/krb5/krb/parse.c b/src/lib/krb5/krb/parse.c index dbe9356fb..0b41a201a 100644 --- a/src/lib/krb5/krb/parse.c +++ b/src/lib/krb5/krb/parse.c @@ -154,7 +154,6 @@ krb5_parse_name(context, name, nprincipal) } default_realm_size = strlen(default_realm); } - krb5_princ_realm(context, principal)->length = default_realm_size; realmsize = default_realm_size; } /* @@ -202,7 +201,6 @@ krb5_parse_name(context, name, nprincipal) */ for (i=0; i < components; i++) krb5_princ_component(context, principal, i)->length = fcompsize[i]; - krb5_princ_realm(context, principal)->length = realmsize; } /* * Now, we need to allocate the space for the strings themselves..... @@ -213,6 +211,7 @@ krb5_parse_name(context, name, nprincipal) krb5_xfree(principal); return ENOMEM; } + krb5_princ_set_realm_length(context, principal, realmsize); krb5_princ_set_realm_data(context, principal, tmpdata); for (i=0; i < components; i++) { char *tmpdata = @@ -226,6 +225,7 @@ krb5_parse_name(context, name, nprincipal) return(ENOMEM); } krb5_princ_component(context, principal, i)->data = tmpdata; + krb5_princ_component(context, principal, i)->magic = KV5M_DATA; } /* @@ -272,6 +272,7 @@ krb5_parse_name(context, name, nprincipal) */ krb5_princ_type(context, principal) = KRB5_NT_PRINCIPAL; principal->magic = KV5M_PRINCIPAL; + principal->realm.magic = KV5M_DATA; *nprincipal = principal; return(0); } diff --git a/src/lib/krb5/krb/t_kerb.c b/src/lib/krb5/krb/t_kerb.c index ef0537ec2..3a960b844 100644 --- a/src/lib/krb5/krb/t_kerb.c +++ b/src/lib/krb5/krb/t_kerb.c @@ -21,23 +21,67 @@ void test_425_conv_principal(ctx, name, inst, realm) { krb5_error_code retval; krb5_principal princ; + char *out_name; retval = krb5_425_conv_principal(ctx, name, inst, realm, &princ); if (retval) { com_err("krb5_425_conv_principal", retval, 0); return; } - retval = krb5_unparse_name(ctx, princ, &name); - printf("425_converted principal: '%s'\n", name); - free(name); + retval = krb5_unparse_name(ctx, princ, &out_name); + if (retval) { + com_err("krb5_unparse_name", retval, 0); + return; + } + printf("425_converted principal(%s, %s, %s): '%s'\n", + name, inst, realm, out_name); + free(out_name); krb5_free_principal(ctx, princ); } +void test_parse_name(ctx, name) + krb5_context ctx; + const char *name; +{ + krb5_error_code retval; + krb5_principal princ = 0, princ2 = 0; + char *outname = 0; + + retval = krb5_parse_name(ctx, name, &princ); + if (retval) { + com_err("krb5_parse_name", retval, 0); + goto fail; + } + retval = krb5_copy_principal(ctx, princ, &princ2); + if (retval) { + com_err("krb5_copy_principal", retval, 0); + goto fail; + } + retval = krb5_unparse_name(ctx, princ2, &outname); + if (retval) { + com_err("krb5_unparse_name", retval, 0); + goto fail; + } + printf("parsed (and unparsed) principal(%s): ", name); + if (strcmp(name, outname) == 0) + printf("MATCH\n"); + else + printf("'%s'\n", outname); +fail: + if (outname) + free(outname); + if (princ) + krb5_free_principal(ctx, princ); + if (princ2) + krb5_free_principal(ctx, princ2); +} + void usage(progname) char *progname; { - fprintf(stderr, "%s: Usage: %s [425_conv_principal \n", progname); exit(1); } @@ -74,7 +118,13 @@ main(argc, argv) if (!argc) usage(progname); realm = *argv; test_425_conv_principal(ctx, name, inst, realm); - } else + } else if (strcmp(*argv, "parse_name") == 0) { + argc--; argv++; + if (!argc) usage(progname); + name = *argv; + test_parse_name(ctx, name); + } + else usage(progname); argc--; argv++; } diff --git a/src/lib/krb5/krb/t_ref_kerb.out b/src/lib/krb5/krb/t_ref_kerb.out index b363c026c..d3a79827b 100644 --- a/src/lib/krb5/krb/t_ref_kerb.out +++ b/src/lib/krb5/krb/t_ref_kerb.out @@ -1,7 +1,16 @@ -425_converted principal: 'host/e40-po.mit.edu@ATHENA.MIT.EDU' -425_converted principal: 'host/mit.edu@ATHENA.MIT.EDU' -425_converted principal: 'host/lithium.lcs.mit.edu@ATHENA.MIT.EDU' -425_converted principal: 'host/tweedledumb.cygnus.com@CYGNUS.COM' -425_converted principal: 'host/uunet.uu.net@UU.NET' -425_converted principal: 'zephyr/zephyr@ATHENA.MIT.EDU' -425_converted principal: 'kadmin/ATHENA.MIT.EDU@ATHENA.MIT.EDU' +parsed (and unparsed) principal(tytso): 'tytso@ATHENA.MIT.EDU' +parsed (and unparsed) principal(tytso@SHAZAAM): MATCH +parsed (and unparsed) principal(tytso/root@VEGGIE.COM): MATCH +parsed (and unparsed) principal(tytso/tuber/carrot@VEGGIE.COM): MATCH +parsed (and unparsed) principal(tytso/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t): 'tytso/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t@ATHENA.MIT.EDU' +parsed (and unparsed) principal(tytso/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t@FOO): MATCH +parsed (and unparsed) principal(tytso\\0/\0@B\n\t\\GAG): MATCH +parsed (and unparsed) principal(tytso/\n/\b\t@B\0hacky-test): MATCH +parsed (and unparsed) principal(\/slash/\@atsign/octa\/thorpe@\/slash\@at\/sign): MATCH +425_converted principal(rcmd, e40-po, ATHENA.MIT.EDU): 'host/e40-po.mit.edu@ATHENA.MIT.EDU' +425_converted principal(rcmd, mit, ATHENA.MIT.EDU): 'host/mit.edu@ATHENA.MIT.EDU' +425_converted principal(rcmd, lithium, ATHENA.MIT.EDU): 'host/lithium.lcs.mit.edu@ATHENA.MIT.EDU' +425_converted principal(rcmd, tweedledumb, CYGNUS.COM): 'host/tweedledumb.cygnus.com@CYGNUS.COM' +425_converted principal(rcmd, uunet, UU.NET): 'host/uunet.uu.net@UU.NET' +425_converted principal(zephyr, zephyr, ATHENA.MIT.EDU): 'zephyr/zephyr@ATHENA.MIT.EDU' +425_converted principal(kadmin, ATHENA.MIT.EDU, ATHENA.MIT.EDU): 'kadmin/ATHENA.MIT.EDU@ATHENA.MIT.EDU' diff --git a/src/lib/krb5/krb/unparse.c b/src/lib/krb5/krb/unparse.c index fc9cc7a80..7247d9a44 100644 --- a/src/lib/krb5/krb/unparse.c +++ b/src/lib/krb5/krb/unparse.c @@ -120,13 +120,9 @@ krb5_unparse_name_ext(context, principal, name, size) switch (*cp) { case COMPONENT_SEP: case REALM_SEP: - case '\0': - *q++ = '\\'; - *q++ = *cp; - break; case '\\': *q++ = '\\'; - *q++ = '\\'; + *q++ = *cp; break; case '\t': *q++ = '\\'; @@ -140,6 +136,10 @@ krb5_unparse_name_ext(context, principal, name, size) *q++ = '\\'; *q++ = 'b'; break; + case '\0': + *q++ = '\\'; + *q++ = '0'; + break; default: *q++ = *cp; } @@ -156,11 +156,22 @@ krb5_unparse_name_ext(context, principal, name, size) switch (*cp) { case COMPONENT_SEP: case REALM_SEP: - case '\t': case '\\': *q++ = '\\'; *q++ = *cp; break; + case '\t': + *q++ = '\\'; + *q++ = 't'; + break; + case '\n': + *q++ = '\\'; + *q++ = 'n'; + break; + case '\b': + *q++ = '\\'; + *q++ = 'b'; + break; case '\0': *q++ = '\\'; *q++ = '0';