From 72ab1ae4c613e78539ccf721f781b10c998dc759 Mon Sep 17 00:00:00 2001 From: Ezra Peisach Date: Fri, 22 Sep 2000 20:13:30 +0000 Subject: [PATCH] * Makefile.in (check-unix): Build and exectute t_cc * t_cc.c: Test harness for memory, stdio and file caches. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@12665 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/ccache/ChangeLog | 6 + src/lib/krb5/ccache/Makefile.in | 26 ++++- src/lib/krb5/ccache/t_cc.c | 191 ++++++++++++++++++++++++++++++++ 3 files changed, 220 insertions(+), 3 deletions(-) create mode 100644 src/lib/krb5/ccache/t_cc.c diff --git a/src/lib/krb5/ccache/ChangeLog b/src/lib/krb5/ccache/ChangeLog index dbff67adb..075a121ac 100644 --- a/src/lib/krb5/ccache/ChangeLog +++ b/src/lib/krb5/ccache/ChangeLog @@ -1,3 +1,9 @@ +2000-09-22 Ezra Peisach + + * Makefile.in (check-unix): Build and exectute t_cc. + + * t_cc.c: Test harness for memory, stdio and file caches. + 2000-07-20 Danilo Almeida * cc_file.c, cc_stdio.c: Remove unused krb5_[fs]cc_default_name() diff --git a/src/lib/krb5/ccache/Makefile.in b/src/lib/krb5/ccache/Makefile.in index c4e7d98d7..b3344f757 100644 --- a/src/lib/krb5/ccache/Makefile.in +++ b/src/lib/krb5/ccache/Makefile.in @@ -4,6 +4,10 @@ mydir=ccache BUILDTOP=$(REL)$(U)$(S)$(U)$(S)$(U) LOCAL_SUBDIRS = +RUN_SETUP = @KRB5_RUN_ENV@ +PROG_LIBPATH=-L$(TOPLIBD) +PROG_RPATH=$(KRB5_LIBDIR) + LOCALINCLUDES = -I$(srcdir)$(S)ccapi $(WIN_INCLUDES) ##DOS##WIN_INCLUDES = -I$(SRCTOP)\windows\lib @@ -49,9 +53,6 @@ SRCS= $(srcdir)/ccbase.c \ all-unix:: all-libobjs -t_stdio: t_stdio.o - $(CC) -o t_stdio $(OBJS) t_stdio.o - all-windows:: subdirs $(OBJFILE) ##DOS##subdirs:: ccapi\$(OUTPRE)file.lst @@ -78,3 +79,22 @@ clean-windows:: cd .. @echo Making clean in krb5\ccache $(RM) $(OBJFILE) + +T_FILE_OBJS=t_file.o + +t_file: $(T_FILE_OBJS) $(KRB5_BASE_DEPLIBS) + $(CC_LINK) -o t_file $(T_FILE_OBJS) $(KRB5_BASE_LIBS) + +T_CC_OBJS=t_cc.o + +t_cc: $(T_CC_OBJS) $(KRB5_BASE_DEPLIBS) + $(CC_LINK) -o t_cc $(T_CC_OBJS) $(KRB5_BASE_LIBS) + +check-unix:: t_cc + KRB5_CONFIG=$(srcdir)/t_krb5.conf ; export KRB5_CONFIG ;\ + $(RUN_SETUP) ./t_cc + +clean-unix:: + $(RM) t_cc t_cc.o + + diff --git a/src/lib/krb5/ccache/t_cc.c b/src/lib/krb5/ccache/t_cc.c new file mode 100644 index 000000000..fc8a7599f --- /dev/null +++ b/src/lib/krb5/ccache/t_cc.c @@ -0,0 +1,191 @@ +/* + * lib/krb5/ccache/scc_test.c + * + * Copyright 2000 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + * + */ + + +#include "krb5.h" +#include +#include +#include "com_err.h" + +#define KRB5_OK 0 + +krb5_creds test_creds; + +int debug=0; + +static void init_structs() +{ + static int add=0x12345; + + static krb5_address addr; + + static krb5_address *addrs[] = { + &addr, + 0, + }; + + addr.magic = KV5M_ADDRESS; + addr.addrtype = ADDRTYPE_INET; + addr.length = 4; + addr.contents = (krb5_octet *) &add; + + test_creds.magic = KV5M_CREDS; + test_creds.client = NULL; + test_creds.server = NULL; + + test_creds.keyblock.magic = KV5M_KEYBLOCK; + test_creds.keyblock.contents = 0; + test_creds.keyblock.enctype = 1; + test_creds.keyblock.length = 1; + test_creds.keyblock.contents = (unsigned char *) "1"; + test_creds.times.authtime = 1111; + test_creds.times.starttime = 2222; + test_creds.times.endtime = 3333; + test_creds.times.renew_till = 4444; + test_creds.is_skey = 1; + test_creds.ticket_flags = 5555; + test_creds.addresses = addrs; + +#define SET_TICKET(ent, str) {ent.magic = KV5M_DATA; ent.length = sizeof(str); ent.data = str;} + SET_TICKET(test_creds.ticket, "This is ticket 1"); + SET_TICKET(test_creds.second_ticket, "This is ticket 2"); + test_creds.authdata = NULL; +} + +static void init_test_cred(context) +krb5_context context; +{ +#define REALM "REALM" + krb5_build_principal(context, &test_creds.client, sizeof(REALM), REALM, + "client-comp1", "client-comp2", 0); + + krb5_build_principal(context, &test_creds.server, sizeof(REALM), REALM, + "server-comp1", "server-comp2", 0); +} + +#define CHECK(kret,msg) \ + if (kret != KRB5_OK) {\ + com_err(msg, kret, "");\ + exit(1);\ + } else if(debug) printf("%s went ok\n", msg); + +static void cc_test(context, name, flags) + krb5_context context; + const char *name; + int flags; +{ + krb5_ccache id; + krb5_creds creds; + krb5_error_code kret; + krb5_cc_cursor cursor; + + init_test_cred(context); + + kret = krb5_cc_resolve(context, name, &id); + CHECK(kret, "resolve"); + kret = krb5_cc_initialize(context, id, test_creds.client); + CHECK(kret, "initialize"); + kret = krb5_cc_store_cred(context, id, &test_creds); + CHECK(kret, "store"); + + kret = krb5_cc_set_flags (context, id, flags); + CHECK(kret, "set_flags"); + kret = krb5_cc_start_seq_get(context, id, &cursor); + CHECK(kret, "start_seq_get"); + kret = 0; + while (kret != KRB5_CC_END) { + if(debug) printf("Calling next_cred\n"); + kret = krb5_cc_next_cred(context, id, &cursor, &creds); + if(kret == KRB5_CC_END) { + if(debug) printf("next_cred: ok at end\n"); + } + else + CHECK(kret, "next_cred"); + } + kret = krb5_cc_end_seq_get(context, id, &cursor); + CHECK(kret, "end_seq_get"); + + kret = krb5_cc_close(context, id); + CHECK(kret, "close"); + + + kret = krb5_cc_resolve(context, name, &id); + CHECK(kret, "resolve"); + kret = krb5_cc_destroy(context, id); + CHECK(kret, "destroy"); +} + +static void do_test(context, name) +krb5_context context; +const char *name; +{ + printf("Starting test on %s\n", name); + cc_test (context, name, 0); + cc_test (context, name, !0); + printf("Test on %s passed\n", name); +} + +extern krb5_cc_ops krb5_scc_ops; +extern krb5_cc_ops krb5_mcc_ops; +extern krb5_cc_ops krb5_fcc_ops; + +int main () +{ + krb5_context context; + krb5_error_code kret; + + initialize_krb5_error_table (); + + if ((kret = krb5_init_context(&context))) { + printf("Couldn't initialize krb5 library: %s\n", + error_message(kret)); + exit(1); + } + + kret = krb5_cc_register(context, &krb5_scc_ops,0); + if(kret && kret != KRB5_CC_TYPE_EXISTS) { + CHECK(kret, "register_scc"); + } + + kret = krb5_cc_register(context, &krb5_mcc_ops,0); + if(kret && kret != KRB5_CC_TYPE_EXISTS) { + CHECK(kret, "register_mem"); + } + + kret = krb5_cc_register(context, &krb5_fcc_ops,0); + if(kret && kret != KRB5_CC_TYPE_EXISTS) { + CHECK(kret, "register_mem"); + } + + init_structs(); + + do_test(context, "STDIO:/tmp/tkt_test"); + do_test(context, "MEMORY:/tmp/tkt_test"); + do_test(context, "FILE:/tmp/tkt_test"); + return 0; +} -- 2.26.2