From 0032360557cdac7a52615a19c0533d59dd289d33 Mon Sep 17 00:00:00 2001 From: Zhanna Tsitkov Date: Mon, 4 Jan 2010 06:22:41 +0000 Subject: [PATCH] For the better code modularity keep some "free" routines closer to the resource allocators. Also, reindent cleanup in the touched files git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23576 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/krb/Makefile.in | 5 +- src/lib/krb5/krb/etype_list.c | 1 - src/lib/krb5/krb/free_rtree.c | 44 ---------- src/lib/krb5/krb/walk_rtree.c | 153 +++++++++++++++++----------------- src/lib/krb5/os/Makefile.in | 3 - src/lib/krb5/os/free_hstrl.c | 43 ---------- src/lib/krb5/os/hst_realm.c | 28 +++++-- 7 files changed, 100 insertions(+), 177 deletions(-) delete mode 100644 src/lib/krb5/krb/free_rtree.c delete mode 100644 src/lib/krb5/os/free_hstrl.c diff --git a/src/lib/krb5/krb/Makefile.in b/src/lib/krb5/krb/Makefile.in index 43d754cdc..d7a4a2da4 100644 --- a/src/lib/krb5/krb/Makefile.in +++ b/src/lib/krb5/krb/Makefile.in @@ -42,7 +42,6 @@ STLIBOBJS= \ encrypt_tk.o \ etype_list.o \ fast.o \ - free_rtree.o \ fwd_tgt.o \ gc_frm_kdc.o \ gc_via_tkt.o \ @@ -137,7 +136,6 @@ OBJS= $(OUTPRE)addr_comp.$(OBJEXT) \ $(OUTPRE)encrypt_tk.$(OBJEXT) \ $(OUTPRE)etype_list.$(OBJEXT) \ $(OUTPRE)fast.$(OBJEXT) \ - $(OUTPRE)free_rtree.$(OBJEXT) \ $(OUTPRE)fwd_tgt.$(OBJEXT) \ $(OUTPRE)gc_frm_kdc.$(OBJEXT) \ $(OUTPRE)gc_via_tkt.$(OBJEXT) \ @@ -233,7 +231,6 @@ SRCS= $(srcdir)/addr_comp.c \ $(srcdir)/encrypt_tk.c \ $(srcdir)/etype_list.c \ $(srcdir)/fast.c \ - $(srcdir)/free_rtree.c \ $(srcdir)/fwd_tgt.c \ $(srcdir)/gc_frm_kdc.c \ $(srcdir)/gc_via_tkt.c \ @@ -323,7 +320,7 @@ clean-unix:: clean-libobjs COMERRLIB=$(TOPLIBD)/libcom_err.a T_WALK_RTREE_OBJS= t_walk_rtree.o walk_rtree.o tgtname.o unparse.o \ - free_rtree.o bld_pr_ext.o copy_data.o + bld_pr_ext.o copy_data.o T_KERB_OBJS= t_kerb.o conv_princ.o unparse.o set_realm.o str_conv.o diff --git a/src/lib/krb5/krb/etype_list.c b/src/lib/krb5/krb/etype_list.c index 98ebc8033..a7fe0d514 100644 --- a/src/lib/krb5/krb/etype_list.c +++ b/src/lib/krb5/krb/etype_list.c @@ -56,4 +56,3 @@ krb5int_copy_etypes(const krb5_enctype *old_list, krb5_enctype **new_list) *new_list = list; return 0; } - diff --git a/src/lib/krb5/krb/free_rtree.c b/src/lib/krb5/krb/free_rtree.c deleted file mode 100644 index 951d55dd3..000000000 --- a/src/lib/krb5/krb/free_rtree.c +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ -/* - * lib/krb5/krb/free_rtree.c - * - * Copyright 1990 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. - * - * - * krb5_free_realm_tree() - */ - -#include "k5-int.h" - -void -krb5_free_realm_tree(krb5_context context, krb5_principal *realms) -{ - register krb5_principal *nrealms = realms; - if (realms == NULL) - return; - while (*nrealms) { - krb5_free_principal(context, *nrealms); - nrealms++; - } - free(realms); -} diff --git a/src/lib/krb5/krb/walk_rtree.c b/src/lib/krb5/krb/walk_rtree.c index d1be2270f..3c5a94524 100644 --- a/src/lib/krb5/krb/walk_rtree.c +++ b/src/lib/krb5/krb/walk_rtree.c @@ -25,6 +25,7 @@ * or implied warranty. * * krb5_walk_realm_tree() + * krb5_free_realm_tree() * * internal function, used by krb5_get_cred_from_kdc() */ @@ -44,51 +45,45 @@ struct hstate { }; static krb5_error_code -rtree_capath_tree( - krb5_context context, - const krb5_data *client, - const krb5_data *server, - char **vals, - krb5_principal **tree); +rtree_capath_tree(krb5_context context, + const krb5_data *client, + const krb5_data *server, + char **vals, + krb5_principal **tree); static krb5_error_code -rtree_capath_vals( - krb5_context context, - const krb5_data *client, - const krb5_data *server, - char ***vals); +rtree_capath_vals(krb5_context context, + const krb5_data *client, + const krb5_data *server, + char ***vals); static krb5_error_code -rtree_hier_tree( - krb5_context context, - const krb5_data *client, - const krb5_data *server, - krb5_principal **rettree, - int sep); +rtree_hier_tree(krb5_context context, + const krb5_data *client, + const krb5_data *server, + krb5_principal **rettree, + int sep); static krb5_error_code -rtree_hier_realms( - krb5_context context, - const krb5_data *client, - const krb5_data *server, - krb5_data **realms, - size_t *nrealms, - int sep); +rtree_hier_realms(krb5_context context, + const krb5_data *client, + const krb5_data *server, + krb5_data **realms, + size_t *nrealms, + int sep); static void -free_realmlist( - krb5_context context, - krb5_data *realms, - size_t nrealms); +free_realmlist(krb5_context context, + krb5_data *realms, + size_t nrealms); static krb5_error_code -rtree_hier_tweens( - krb5_context context, - struct hstate *realm, - krb5_data **tweens, - size_t *ntweens, - int dotail, - int sep); +rtree_hier_tweens(krb5_context context, + struct hstate *realm, + krb5_data **tweens, + size_t *ntweens, + int dotail, + int sep); static void adjtail(struct hstate *c, struct hstate *s, int sep); @@ -97,12 +92,11 @@ static void comtail(struct hstate *c, struct hstate *s, int sep); krb5_error_code -krb5_walk_realm_tree( - krb5_context context, - const krb5_data *client, - const krb5_data *server, - krb5_principal **tree, - int realm_sep) +krb5_walk_realm_tree( krb5_context context, + const krb5_data *client, + const krb5_data *server, + krb5_principal **tree, + int realm_sep) { krb5_error_code retval = 0; char **capvals; @@ -188,12 +182,11 @@ krb5_walk_realm_tree( * walk_rtree_capath_vals(). */ static krb5_error_code -rtree_capath_tree( - krb5_context context, - const krb5_data *client, - const krb5_data *server, - char **vals, - krb5_principal **rettree) +rtree_capath_tree(krb5_context context, + const krb5_data *client, + const krb5_data *server, + char **vals, + krb5_principal **rettree) { krb5_error_code retval = 0; unsigned int nvals, nlinks, nprincs, i; @@ -253,11 +246,10 @@ error: * by not finding anything. */ static krb5_error_code -rtree_capath_vals( - krb5_context context, - const krb5_data *client, - const krb5_data *server, - char ***vals) +rtree_capath_vals(krb5_context context, + const krb5_data *client, + const krb5_data *server, + char ***vals) { krb5_error_code retval = 0; /* null-terminated realm names */ @@ -306,12 +298,11 @@ error: * Build tree by hierarchical traversal. */ static krb5_error_code -rtree_hier_tree( - krb5_context context, - const krb5_data *client, - const krb5_data *server, - krb5_principal **rettree, - int sep) +rtree_hier_tree(krb5_context context, + const krb5_data *client, + const krb5_data *server, + krb5_principal **rettree, + int sep) { krb5_error_code retval; krb5_data *realms; @@ -356,13 +347,12 @@ error: * Construct list of realms between client and server. */ static krb5_error_code -rtree_hier_realms( - krb5_context context, - const krb5_data *client, - const krb5_data *server, - krb5_data **realms, - size_t *nrealms, - int sep) +rtree_hier_realms(krb5_context context, + const krb5_data *client, + const krb5_data *server, + krb5_data **realms, + size_t *nrealms, + int sep) { krb5_error_code retval; struct hstate c, s; @@ -418,10 +408,9 @@ error: } static void -free_realmlist( - krb5_context context, - krb5_data *realms, - size_t nrealms) +free_realmlist(krb5_context context, + krb5_data *realms, + size_t nrealms) { size_t i; @@ -439,13 +428,12 @@ free_realmlist( * make copies as needed and not call krb5_free_data_contents, etc. */ static krb5_error_code -rtree_hier_tweens( - krb5_context context, - struct hstate *realm, - krb5_data **tweens, - size_t *ntweens, - int dotail, - int sep) +rtree_hier_tweens(krb5_context context, + struct hstate *realm, + krb5_data **tweens, + size_t *ntweens, + int dotail, + int sep) { char *p, *r, *rtail, *lp; size_t rlen, n; @@ -579,3 +567,16 @@ comtail(struct hstate *c, struct hstate *s, int sep) c->dot = cdot; s->dot = sdot; } + +void +krb5_free_realm_tree(krb5_context context, krb5_principal *realms) +{ + register krb5_principal *nrealms = realms; + if (realms == NULL) + return; + while (*nrealms) { + krb5_free_principal(context, *nrealms); + nrealms++; + } + free(realms); +} diff --git a/src/lib/krb5/os/Makefile.in b/src/lib/krb5/os/Makefile.in index 5a8130237..6a1ffd13f 100644 --- a/src/lib/krb5/os/Makefile.in +++ b/src/lib/krb5/os/Makefile.in @@ -21,7 +21,6 @@ STLIBOBJS= \ dnsglue.o \ dnssrv.o \ free_krbhs.o \ - free_hstrl.o \ full_ipadr.o \ get_krbhst.o \ gen_port.o \ @@ -65,7 +64,6 @@ OBJS= \ $(OUTPRE)dnsglue.$(OBJEXT) \ $(OUTPRE)dnssrv.$(OBJEXT) \ $(OUTPRE)free_krbhs.$(OBJEXT) \ - $(OUTPRE)free_hstrl.$(OBJEXT) \ $(OUTPRE)full_ipadr.$(OBJEXT) \ $(OUTPRE)get_krbhst.$(OBJEXT) \ $(OUTPRE)gen_port.$(OBJEXT) \ @@ -109,7 +107,6 @@ SRCS= \ $(srcdir)/dnsglue.c \ $(srcdir)/dnssrv.c \ $(srcdir)/free_krbhs.c \ - $(srcdir)/free_hstrl.c \ $(srcdir)/full_ipadr.c \ $(srcdir)/get_krbhst.c \ $(srcdir)/gen_port.c \ diff --git a/src/lib/krb5/os/free_hstrl.c b/src/lib/krb5/os/free_hstrl.c deleted file mode 100644 index 58222a6df..000000000 --- a/src/lib/krb5/os/free_hstrl.c +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ -/* - * lib/krb5/os/free_hstrl.c - * - * Copyright 1990 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. - * - * - * krb5_free_host_realm() - */ - -#include "k5-int.h" -#include - -/* - Frees the storage taken by a realm list returned by krb5_get_host_realm. -*/ - -krb5_error_code KRB5_CALLCONV -krb5_free_host_realm(krb5_context context, char *const *realmlist) -{ - /* same format, so why duplicate code? */ - return krb5_free_krbhst(context, realmlist); -} diff --git a/src/lib/krb5/os/hst_realm.c b/src/lib/krb5/os/hst_realm.c index 23c7893b6..96a022f4d 100644 --- a/src/lib/krb5/os/hst_realm.c +++ b/src/lib/krb5/os/hst_realm.c @@ -2,7 +2,7 @@ /* * lib/krb5/os/hst_realm.c * - * Copyright 1990,1991,2002,2008 by the Massachusetts Institute of Technology. + * Copyright 1990,1991,2002,2008,2009 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -26,6 +26,9 @@ * * * krb5_get_host_realm() + * krb5_get_fallback_host_realm() + * krb5int_clean_hostname() + * krb5_free_host_realm() */ @@ -94,7 +97,7 @@ domain_heuristic(krb5_context context, const char *domain, krb5_error_code krb5int_translate_gai_error (int); static krb5_error_code -krb5int_get_fq_hostname (char *buf, size_t bufsize, const char *name) +get_fq_hostname(char *buf, size_t bufsize, const char *name) { struct addrinfo *ai, hints; int err; @@ -116,13 +119,13 @@ krb5int_get_fq_hostname (char *buf, size_t bufsize, const char *name) Always return a null-terminated string. Might return an error if gethostname fails. */ krb5_error_code -krb5int_get_fq_local_hostname (char *buf, size_t bufsiz) +krb5int_get_fq_local_hostname(char *buf, size_t bufsiz) { buf[0] = 0; if (gethostname (buf, bufsiz) == -1) return SOCKET_ERRNO; buf[bufsiz - 1] = 0; - return krb5int_get_fq_hostname (buf, bufsiz, buf); + return get_fq_hostname (buf, bufsiz, buf); } krb5_error_code KRB5_CALLCONV @@ -266,7 +269,8 @@ krb5int_translate_gai_error (int num) */ krb5_error_code KRB5_CALLCONV -krb5_get_fallback_host_realm(krb5_context context, krb5_data *hdata, char ***realmsp) +krb5_get_fallback_host_realm(krb5_context context, + krb5_data *hdata, char ***realmsp) { char **retrealms; char *realm, *cp; @@ -368,7 +372,8 @@ krb5_get_fallback_host_realm(krb5_context context, krb5_data *hdata, char ***rea * to do basic sanity checks on supplied hostname. */ krb5_error_code KRB5_CALLCONV -krb5int_clean_hostname(krb5_context context, const char *host, char *local_host, size_t lhsize) +krb5int_clean_hostname(krb5_context context, + const char *host, char *local_host, size_t lhsize) { char *cp; krb5_error_code retval; @@ -492,3 +497,14 @@ cleanup: free(fqdn); return retval; } + +/* + * Frees the storage taken by a realm list returned by krb5_get_host_realm. + */ + +krb5_error_code KRB5_CALLCONV +krb5_free_host_realm(krb5_context context, char *const *realmlist) +{ + /* same format, so why duplicate code? */ + return krb5_free_krbhst(context, realmlist); +} -- 2.26.2