From: Theodore Tso Date: Fri, 4 Dec 1998 08:17:26 +0000 (+0000) Subject: realm_iter.c: New function which iterators over the realms in the X-Git-Tag: krb5-1.1-beta1~460 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=33bf778b7c5efa1cf6f08cad6e307511ba6a88c7;p=krb5.git realm_iter.c: New function which iterators over the realms in the krb5.conf file. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11061 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 13b401729..95f8bfd55 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,8 @@ +1998-12-04 Theodore Ts'o + + * realm_iter.c: New function which iterators over the realms in + the krb5.conf file. + 1998-11-13 Theodore Ts'o * Makefile.in: Set the myfulldir and mydir variables (which are diff --git a/src/lib/krb5/os/Makefile.in b/src/lib/krb5/os/Makefile.in index 9d03c5e49..c1b48d7b2 100644 --- a/src/lib/krb5/os/Makefile.in +++ b/src/lib/krb5/os/Makefile.in @@ -47,6 +47,7 @@ STLIBOBJS= \ read_msg.o \ read_pwd.o \ realm_dom.o \ + realm_iter.o \ sendto_kdc.o \ sn2princ.o \ timeofday.o \ @@ -90,6 +91,7 @@ OBJS= \ read_msg.$(OBJEXT) \ read_pwd.$(OBJEXT) \ realm_dom.$(OBJEXT) \ + realm_iter.$(OBJEXT) \ sendto_kdc.$(OBJEXT) \ sn2princ.$(OBJEXT) \ timeofday.$(OBJEXT) \ @@ -132,6 +134,7 @@ SRCS= \ $(srcdir)/read_msg.c \ $(srcdir)/read_pwd.c \ $(srcdir)/realm_dom.c \ + $(srcdir)/realm_iter.c \ $(srcdir)/port2ip.c \ $(srcdir)/sendto_kdc.c \ $(srcdir)/sn2princ.c \ @@ -156,12 +159,17 @@ T_STD_CONF_OBJS= t_std_conf.o def_realm.o get_krbhst.o realm_dom.o \ T_AN_TO_LN_OBJS = t_an_to_ln.o an_to_ln.o +T_REALM_ITER_OBJS = t_realm_iter.o realm_iter.o + t_std_conf: $(T_STD_CONF_OBJS) $(KRB5_BASE_DEPLIBS) $(CC_LINK) -o t_std_conf $(T_STD_CONF_OBJS) $(KRB5_BASE_LIBS) t_an_to_ln: $(T_AN_TO_LN_OBJS) $(KRB5_BASE_DEPLIBS) $(CC_LINK) -o t_an_to_ln $(T_AN_TO_LN_OBJS) $(KRB5_BASE_LIBS) +t_realm_iter: $(T_REALM_ITER_OBJS) $(KRB5_BASE_DEPLIBS) + $(CC_LINK) -o t_realm_iter $(T_REALM_ITER_OBJS) $(KRB5_BASE_LIBS) + check-unix:: $(TEST_PROGS) KRB5_CONFIG=$(srcdir)/td_krb5.conf ; export KRB5_CONFIG ;\ $(KRB5_RUN_ENV) ./t_std_conf -d -s NEW.DEFAULT.REALM -d \ diff --git a/src/lib/krb5/os/realm_iter.c b/src/lib/krb5/os/realm_iter.c new file mode 100644 index 000000000..0c3d12773 --- /dev/null +++ b/src/lib/krb5/os/realm_iter.c @@ -0,0 +1,66 @@ +/* + * lib/krb5/os/realm_init.c + * + * Copyright 1998 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. 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_realm_iterate() + */ + +#include "k5-int.h" +#include +#include + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_realm_iterator_create(context, iter_p) + krb5_context context; + void **iter_p; +{ + static const char *names[] = { "realms", 0 }; + + return profile_iterator_create(context->profile, names, + PROFILE_ITER_LIST_SECTION | + PROFILE_ITER_SECTIONS_ONLY, + iter_p); +} + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_realm_iterator(context, iter_p, ret_realm) + krb5_context context; + void **iter_p; + char **ret_realm; +{ + return profile_iterator(iter_p, ret_realm, 0); +} + +KRB5_DLLIMP void KRB5_CALLCONV +krb5_realm_iterator_free(context, iter_p) + krb5_context context; + void **iter_p; +{ + profile_iterator_free(iter_p); +} + +KRB5_DLLIMP void KRB5_CALLCONV +krb5_free_realm_string(context, str) + krb5_context context; + char *str; +{ + profile_release_string(str); +} diff --git a/src/lib/krb5/os/t_realm_iter.c b/src/lib/krb5/os/t_realm_iter.c new file mode 100644 index 000000000..c9281a89c --- /dev/null +++ b/src/lib/krb5/os/t_realm_iter.c @@ -0,0 +1,46 @@ +#include "krb5.h" + +#include + +void test_realm_iterator(ctx) +{ + krb5_error_code retval; + char *realm; + void *iter; + + if ((retval = krb5_realm_iterator_create(ctx, &iter))) { + com_err("krb5_realm_iterator_create", retval, 0); + return; + } + while (iter) { + if ((retval = krb5_realm_iterator(ctx, &iter, &realm))) { + com_err("krb5_realm_iterator", retval, 0); + krb5_realm_iterator_free(ctx, &iter); + return; + } + if (realm) { + printf("Realm: '%s'\n", realm); + krb5_free_realm_string(ctx, realm); + } + } +} + +int main(argc, argv) + int argc; + char **argv; +{ + krb5_context ctx; + krb5_error_code retval; + + retval = krb5_init_context(&ctx); + if (retval) { + fprintf(stderr, "krb5_init_context returned error %ld\n", + retval); + exit(1); + } + + test_realm_iterator(ctx); + + krb5_free_context(ctx); + return 0; +}