realm_iter.c: New function which iterators over the realms in the
authorTheodore Tso <tytso@mit.edu>
Fri, 4 Dec 1998 08:17:26 +0000 (08:17 +0000)
committerTheodore Tso <tytso@mit.edu>
Fri, 4 Dec 1998 08:17:26 +0000 (08:17 +0000)
krb5.conf file.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11061 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/os/ChangeLog
src/lib/krb5/os/Makefile.in
src/lib/krb5/os/realm_iter.c [new file with mode: 0644]
src/lib/krb5/os/t_realm_iter.c [new file with mode: 0644]

index 13b401729c34ef9ffc4542f184e78cbe7bf7ca05..95f8bfd550aad2aa1c47009f8e2c3a947f99ecea 100644 (file)
@@ -1,3 +1,8 @@
+1998-12-04  Theodore Ts'o  <tytso@rsts-11.mit.edu>
+
+       * realm_iter.c: New function which iterators over the realms in
+               the krb5.conf file.
+
 1998-11-13  Theodore Ts'o  <tytso@rsts-11.mit.edu>
 
        * Makefile.in: Set the myfulldir and mydir variables (which are
index 9d03c5e49cf506f7d50ed6dc3359ad2d2fa4b801..c1b48d7b254b0ca4876150a81ddd5b6f86c08062 100644 (file)
@@ -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 (file)
index 0000000..0c3d127
--- /dev/null
@@ -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 <ctype.h>
+#include <stdio.h>
+
+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 (file)
index 0000000..c9281a8
--- /dev/null
@@ -0,0 +1,46 @@
+#include "krb5.h"
+
+#include <stdio.h>
+
+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;
+}