From: Ezra Peisach Date: Wed, 24 Sep 1997 16:01:03 +0000 (+0000) Subject: * kdc_util.c (add_to_transited): Fix up memory leaks, clean out X-Git-Tag: krb5-1.1-beta1~1024 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ce33c8103370305cc7c67b49928338f9b5106fd6;p=krb5.git * kdc_util.c (add_to_transited): Fix up memory leaks, clean out new memory allocated, allocate buffers to max size needed. [based on krb5-kdc/461 by Ken Hornstein]. * rtest.c: Rewrite code to use context and current krb5_principal structure. * configure.in: Add KRB5_RUN_FLAGS * Makefile.in (rtest): Compile rtest and run during make check. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@10201 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/kdc/ChangeLog b/src/kdc/ChangeLog index 72b2001db..da5180203 100644 --- a/src/kdc/ChangeLog +++ b/src/kdc/ChangeLog @@ -1,3 +1,17 @@ +Wed Sep 24 11:56:50 1997 Ezra Peisach + + * kdc_util.c (add_to_transited): Fix up memory leaks, clean out + new memory allocated, allocate buffers to max size + needed. [based on krb5-kdc/461 by Ken Hornstein]. + + * rtest.c: Rewrite code to use context and current krb5_principal + structure. + + * configure.in: Add KRB5_RUN_FLAGS + + * Makefile.in (rtest): Compile rtest and run during make check. + + Tue Sep 23 13:25:35 1997 Ezra Peisach * kerberos_v4.c (check_princ): Add checks for V5 kdc flags diff --git a/src/kdc/Makefile.in b/src/kdc/Makefile.in index 630eba013..b21d7b631 100644 --- a/src/kdc/Makefile.in +++ b/src/kdc/Makefile.in @@ -1,8 +1,9 @@ CFLAGS = $(CCOPTS) $(DEFS) $(LOCALINCLUDE) +RUN_SETUP = @KRB5_RUN_ENV@ PROG_LIBPATH=-L$(TOPLIBD) $(KRB4_LIBPATH) PROG_RPATH=$(KRB5_LIBDIR) -all:: krb5kdc +all:: krb5kdc rtest DEFINES = -DBACKWARD_COMPAT $(KRB4DEF) @@ -37,6 +38,11 @@ OBJS= \ replay.o \ kerberos_v4.o +RT_OBJS= rtest.o \ + kdc_util.o \ + policy.o \ + extern.o + depend:: kdc5_err.c logger.c: $(SRCTOP)/lib/kadm5/logger.c @@ -54,10 +60,19 @@ kdc5_err.o: kdc5_err.h krb5kdc: $(OBJS) $(KADMSRV_DEPLIBS) $(KRB4COMPAT_DEPLIBS) $(CC_LINK) -o krb5kdc $(OBJS) $(KADMSRV_LIBS) $(KRB4COMPAT_LIBS) +rtest: $(RT_OBJS) $(KADM_COMM_DEPLIBS) $(KRB5_BASE_DEPLIBS) + $(CC_LINK) -o rtest $(RT_OBJS) $(KADM_COMM_LIBS) $(KRB5_BASE_LIBS) + +check-unix:: rtest + KRB5_CONFIG=$(SRCTOP)/config-files/krb5.conf ; export KRB5_CONFIG ;\ + $(RUN_SETUP) $(srcdir)/rtscript > test.out + cmp test.out $(srcdir)/rtest.good + $(RM) test.out + install:: $(INSTALL_PROGRAM) krb5kdc ${DESTDIR}$(SERVER_BINDIR)/krb5kdc $(INSTALL_DATA) $(srcdir)/krb5kdc.M ${DESTDIR}$(SERVER_MANDIR)/krb5kdc.8 clean:: - $(RM) kdc5_err.h kdc5_err.c krb5kdc logger.c + $(RM) kdc5_err.h kdc5_err.c krb5kdc logger.c rtest.o rtest diff --git a/src/kdc/configure.in b/src/kdc/configure.in index d749707bd..c9b5ba3e2 100644 --- a/src/kdc/configure.in +++ b/src/kdc/configure.in @@ -32,6 +32,7 @@ if test "$withval" = yes; then AC_DEFINE(KRBCONF_KDC_MODIFIES_KDB) fi dnl - +dnl +KRB5_RUN_FLAGS KRB5_BUILD_PROGRAM V5_AC_OUTPUT_MAKEFILE diff --git a/src/kdc/kdc_util.c b/src/kdc/kdc_util.c index 06af6bece..2fd9245c9 100644 --- a/src/kdc/kdc_util.c +++ b/src/kdc/kdc_util.c @@ -537,7 +537,7 @@ add_to_transited(tgt_trans, new_trans, tgs, client, server) { char *realm; char *trans; - char *otrans; + char *otrans, *otrans_ptr; /* The following are for stepping through the transited field */ @@ -558,17 +558,28 @@ add_to_transited(tgt_trans, new_trans, tgs, client, server) realm[krb5_princ_realm(kdc_context, tgs)->length] = '\0'; if (!(otrans = (char *) malloc(tgt_trans->length+1))) { + free(realm); return(ENOMEM); } memcpy(otrans, tgt_trans->data, tgt_trans->length); otrans[tgt_trans->length] = '\0'; - - if (!(trans = (char *) malloc(strlen(realm) + strlen(otrans) + 1))) { + /* Keep track of start so we can free */ + otrans_ptr = otrans; + + /* +1 for null, + +1 for extra comma which may be added between + +1 for potential space when leading slash in realm */ + if (!(trans = (char *) malloc(strlen(realm) + strlen(otrans) + 3))) { + free(realm); + free(otrans_ptr); return(ENOMEM); } if (new_trans->data) free(new_trans->data); new_trans->data = trans; + new_trans->length = 0; + + trans[0] = '\0'; /* For the purpose of appending, the realm preceding the first */ /* realm in the transited field is considered the null realm */ @@ -706,6 +717,8 @@ add_to_transited(tgt_trans, new_trans, tgs, client, server) new_trans->length = strlen(trans) + 1; } + free(realm); + free(otrans_ptr); return(0); } diff --git a/src/kdc/rtest.c b/src/kdc/rtest.c index 68835bd6b..b422fa273 100644 --- a/src/kdc/rtest.c +++ b/src/kdc/rtest.c @@ -26,6 +26,34 @@ #include "k5-int.h" #include #include "kdc_util.h" +#include "extern.h" + +krb5_principal +make_princ(ctx, str, prog) + krb5_context ctx; + const char *str; + const char *prog; +{ + krb5_principal ret; + char *dat; + + if(!(ret = (krb5_principal) malloc(sizeof(krb5_principal_data)))) { + com_err(prog, ENOMEM, "while allocating principal data"); + exit(3); + } + memset(ret, 0, sizeof(krb5_principal_data)); + + /* We do not include the null... */ + if(!(dat = (char *) malloc(strlen(str)))) { + com_err(prog, ENOMEM, "while allocating principal realm data"); + exit(3); + } + memcpy(dat, str, strlen(str)); + krb5_princ_set_realm_data(ctx, ret, dat); + krb5_princ_set_realm_length(ctx, ret, strlen(str)); + + return ret; +} void main(argc,argv) @@ -34,47 +62,50 @@ main(argc,argv) { krb5_data otrans; krb5_data ntrans; - - krb5_data *tgnames[10]; - krb5_principal tgs = tgnames; - krb5_data tgsrlm; - - krb5_data *cnames[10]; - krb5_principal cl = cnames; - krb5_data crlm; - - krb5_data *snames[10]; - krb5_principal sv = snames; - krb5_data srlm; + krb5_principal tgs, cl, sv; + krb5_error_code kret; + kdc_realm_t kdc_realm; if (argc < 4) { fprintf(stderr, "not enough args\n"); exit(1); } + + + /* Get a context */ + kret = krb5_init_context(&kdc_realm.realm_context); + if (kret) { + com_err(argv[0], kret, "while getting krb5 context"); + exit(2); + } + /* Needed so kdc_context will work */ + kdc_active_realm = &kdc_realm; + ntrans.length = 0; - otrans.length = strlen(argv[1]) + 1; + ntrans.data = 0; + + otrans.length = strlen(argv[1]); otrans.data = (char *) malloc(otrans.length); - strcpy(otrans.data,argv[1]); - - tgsrlm.length = strlen(argv[2]) + 1; - tgsrlm.data = (char *) malloc(tgsrlm.length); - strcpy(tgsrlm.data,argv[2]); - tgs[0] = &tgsrlm; - - crlm.length = strlen(argv[3]) + 1; - crlm.data = (char *) malloc(crlm.length); - strcpy(crlm.data,argv[3]); - cl[0] = &crlm; - - srlm.length = strlen(argv[4]) + 1; - srlm.data = (char *) malloc(srlm.length); - strcpy(srlm.data,argv[4]); - sv[0] = &srlm; + memcpy(otrans.data,argv[1], otrans.length); + + tgs = make_princ(kdc_context, argv[2], argv[0]); + cl = make_princ(kdc_context, argv[3], argv[0]); + sv = make_princ(kdc_context, argv[4], argv[0]); add_to_transited(&otrans,&ntrans,tgs,cl,sv); printf("%s\n",ntrans.data); + /* Free up all memory so we can profile for leaks */ + free(otrans.data); + free(ntrans.data); + + krb5_free_principal(kdc_realm.realm_context, tgs); + krb5_free_principal(kdc_realm.realm_context, cl); + krb5_free_principal(kdc_realm.realm_context, sv); + krb5_free_context(kdc_realm.realm_context); + + exit(0); } -krb5_encrypt_block master_encblock; +void krb5_klog_syslog() {}