/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* * This driver routine is used to test many of the standard Kerberos library * routines. */ #include "krb5.h" #include "autoconf.h" #include #include #include #include #include #include #include #include #include #include "com_err.h" void test_string_to_timestamp (krb5_context, char *); void test_425_conv_principal (krb5_context, char *, char*, char *); void test_524_conv_principal (krb5_context, char *); void test_parse_name (krb5_context, const char *); void test_set_realm (krb5_context, const char *, const char *); void usage (char *); void test_string_to_timestamp(krb5_context ctx, char *ktime) { krb5_timestamp timestamp; time_t t; krb5_error_code retval; retval = krb5_string_to_timestamp(ktime, ×tamp); if (retval) { com_err("krb5_string_to_timestamp", retval, 0); return; } t = (time_t) timestamp; printf("Parsed time was %s", ctime(&t)); } void test_425_conv_principal(krb5_context ctx, char *name, char *inst, char *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, &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_524_conv_principal(krb5_context ctx, char *name) { krb5_principal princ = 0; krb5_error_code retval; #define ANAME_SZ 40 #define INST_SZ 40 #define REALM_SZ 40 char aname[ANAME_SZ+1], inst[INST_SZ+1], realm[REALM_SZ+1]; aname[ANAME_SZ] = inst[INST_SZ] = realm[REALM_SZ] = 0; retval = krb5_parse_name(ctx, name, &princ); if (retval) { com_err("krb5_parse_name", retval, 0); goto fail; } retval = krb5_524_conv_principal(ctx, princ, aname, inst, realm); if (retval) { com_err("krb5_524_conv_principal", retval, 0); goto fail; } printf("524_converted_principal(%s): '%s' '%s' '%s'\n", name, aname, inst, realm); fail: if (princ) krb5_free_principal (ctx, princ); } void test_parse_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 test_set_realm(krb5_context ctx, const char *name, const char *realm) { krb5_error_code retval; krb5_principal princ = 0; char *outname = 0; retval = krb5_parse_name(ctx, name, &princ); if (retval) { com_err("krb5_parse_name", retval, 0); goto fail; } retval = krb5_set_principal_realm(ctx, princ, realm); if (retval) { com_err("krb5_set_principal_realm", retval, 0); goto fail; } retval = krb5_unparse_name(ctx, princ, &outname); if (retval) { com_err("krb5_unparse_name", retval, 0); goto fail; } printf("old principal: %s, modified principal: %s\n", name, outname); fail: if (outname) free(outname); if (princ) krb5_free_principal(ctx, princ); } void usage(char *progname) { fprintf(stderr, "%s: Usage: %s 425_conv_principal \n", progname); fprintf(stderr, "\t%s parse_name \n", progname); fprintf(stderr, "\t%s set_realm \n", progname); fprintf(stderr, "\t%s string_to_timestamp