get_in_tkt.c (make_preauth_list): Correctly null-terminate the
authorTheodore Tso <tytso@mit.edu>
Thu, 26 Sep 1996 22:54:45 +0000 (22:54 +0000)
committerTheodore Tso <tytso@mit.edu>
Thu, 26 Sep 1996 22:54:45 +0000 (22:54 +0000)
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

src/lib/krb5/krb/ChangeLog
src/lib/krb5/krb/Makefile.in
src/lib/krb5/krb/get_in_tkt.c
src/lib/krb5/krb/parse.c
src/lib/krb5/krb/t_kerb.c
src/lib/krb5/krb/t_ref_kerb.out
src/lib/krb5/krb/unparse.c

index 32612bb8c3a568e8988a47deca89631ba6e1bcc5..438876e42d156ddc5c3ad9dc4e751b752a89e4b4 100644 (file)
@@ -1,3 +1,19 @@
+Tue Sep 24 20:59:14 1996  Theodore Y. Ts'o  <tytso@mit.edu>
+
+       * 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  <tytso@mit.edu>
+
+       * 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  <tytso@mit.edu>
 
        * preauth.c (find_pa_system): Change type of first argument to be
index ebeedb0826d02086eb05123d6901f35517ddcd9b..ea8330040d57d95de9eb921221a0520c6f484763 100644 (file)
@@ -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
index 891bff8561a9309ded3b9585137cff3bcaa92261..048a56ca8c2a5d64df74d6b2d3d5bc70c013ba38 100644 (file)
@@ -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;
 }
index dbe9356fbeec56112b601d132d59397245bec463..0b41a201a2e4d43f5485a5011b974b949848f57e 100644 (file)
@@ -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);
 }
index ef0537ec207463e00bca4d3c7d568ab97ca769f3..3a960b844ee0cb8df3d0117519a6e227f2f1aad4 100644 (file)
@@ -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 <name> <inst> <realm]\n",
+       fprintf(stderr, "%s: Usage: %s 425_conv_principal <name> <inst> <realm\n",
                progname, progname);
+       fprintf(stderr, "\t%s parse_name <name>\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++;
      }
index b363c026c5fd1d828f62bfa22c47271d33843691..d3a79827b297826262eedc9b436c34ea6c49c56b 100644 (file)
@@ -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'
index fc9cc7a808b282197c38afa6aa4bb6ecad6c8822..7247d9a44af608cca20ea93afc171319a72e976e 100644 (file)
@@ -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';