2000-05-15 Jeffrey Altman <jaltman@columbia.edu>
authorJeffrey Altman <jaltman@secure-endpoints.com>
Tue, 16 May 2000 03:20:20 +0000 (03:20 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Tue, 16 May 2000 03:20:20 +0000 (03:20 +0000)
        * Added new source file appdefault.c
          Implements new public functions

               krb5_appdefault_string
               krb5_appdefault_boolean

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

src/lib/krb5/krb/ChangeLog
src/lib/krb5/krb/Makefile.in
src/lib/krb5/krb/appdefault.c [new file with mode: 0644]

index 7241e65cb76ebd3b40f814abf35622cd92c5c945..3c4bb65b5a3efc23e824f07318a44f785036e266 100644 (file)
@@ -1,3 +1,11 @@
+2000-05-15      Jeffrey Altman          <jaltman@columbia.edu>
+
+        * Added new source file appdefault.c
+          Implements new public functions
+
+               krb5_appdefault_string
+               krb5_appdefault_boolean
+
 2000-04-28     Alexandra Ellwood       <lxs@mit.edu>
 
        * gic_pwd.c (krb5_init_creds_password) added code to return to login library if 
index ba7666247c7a73458d43e12aeb747b1b16432a2c..8aeb398d0694fa577a8a9561917a8ca25da0f06d 100644 (file)
@@ -15,6 +15,7 @@ STLIBOBJS= \
        addr_comp.o     \
        addr_order.o    \
        addr_srch.o     \
+       appdefault.o    \
        auth_con.o      \
        bld_pr_ext.o    \
        bld_princ.o     \
@@ -99,6 +100,7 @@ STLIBOBJS= \
 OBJS=  $(OUTPRE)addr_comp.$(OBJEXT)    \
        $(OUTPRE)addr_order.$(OBJEXT)   \
        $(OUTPRE)addr_srch.$(OBJEXT)    \
+       $(OUTPRE)appdefault.$(OBJEXT)   \
        $(OUTPRE)auth_con.$(OBJEXT)     \
        $(OUTPRE)bld_pr_ext.$(OBJEXT)   \
        $(OUTPRE)bld_princ.$(OBJEXT)    \
@@ -183,6 +185,7 @@ OBJS=       $(OUTPRE)addr_comp.$(OBJEXT)    \
 SRCS=  $(srcdir)/addr_comp.c   \
        $(srcdir)/addr_order.c  \
        $(srcdir)/addr_srch.c   \
+       $(srcdir)/appdefault.c  \
        $(srcdir)/auth_con.c    \
        $(srcdir)/bld_pr_ext.c  \
        $(srcdir)/bld_princ.c   \
diff --git a/src/lib/krb5/krb/appdefault.c b/src/lib/krb5/krb/appdefault.c
new file mode 100644 (file)
index 0000000..17183d8
--- /dev/null
@@ -0,0 +1,183 @@
+/*
+ * appdefault - routines designed to be called from applications to
+ *              handle the [appdefaults] profile section
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <k5-int.h>
+
+
+
+ /*xxx Duplicating this is annoying; try to work on a better way.*/
+static char *conf_yes[] = {
+       "y", "yes", "true", "t", "1", "on",
+       0,
+};
+
+static char *conf_no[] = {
+       "n", "no", "false", "nil", "0", "off",
+       0,
+};
+
+static int conf_boolean(s)
+       char *s;
+{
+       char **p;
+       for(p=conf_yes; *p; p++) {
+               if (!strcasecmp(*p,s))
+                       return 1;
+       }
+       for(p=conf_no; *p; p++) {
+               if (!strcasecmp(*p,s))
+               return 0;
+       }
+       /* Default to "no" */
+       return 0;
+}
+
+static krb5_error_code appdefault_get(context, appname, realm, option,
+                               ret_value)
+        krb5_context context;
+       const char *appname, *option;
+        const krb5_data *realm;
+       char **ret_value;
+{
+        profile_t profile;
+        const char *names[5];
+       char **nameval = NULL;
+       krb5_error_code retval;
+       const char * realmstr =  realm?realm->data:NULL;
+
+           if (!context || (context->magic != KV5M_CONTEXT)) 
+           return KV5M_CONTEXT;
+
+           profile = context->profile;
+           
+       /*
+        * Try number one:
+        *
+        * [appdefaults]
+        *      app = {
+        *              SOME.REALM = {
+        *                      option = <boolean>
+        *              }
+        *      }
+        */
+
+       names[0] = "appdefaults";
+       names[1] = appname;
+
+       if (realmstr) {
+               names[2] = realmstr;
+               names[3] = option;
+               names[4] = 0;
+               retval = profile_get_values(profile, names, &nameval);
+               if (retval == 0 && nameval && nameval[0]) {
+                       *ret_value = strdup(nameval[0]);
+                       goto goodbye;
+               }
+       }
+
+       /*
+        * Try number two:
+        *
+        * [appdefaults]
+        *      app = {
+        *              option = <boolean>
+        *      }
+        */
+
+       names[2] = option;
+       names[3] = 0;
+       retval = profile_get_values(profile, names, &nameval);
+       if (retval == 0 && nameval && nameval[0]) {
+               *ret_value = strdup(nameval[0]);
+               goto goodbye;
+       }
+
+       /*
+        * Try number three:
+        *
+        * [appdefaults]
+        *      realm = {
+        *              option = <boolean>
+        */
+       
+       if (realmstr) {
+               names[1] = realmstr;
+               names[2] = option;
+               names[3] = 0;
+               retval = profile_get_values(profile, names, &nameval);
+               if (retval == 0 && nameval && nameval[0]) {
+                       *ret_value = strdup(nameval[0]);
+                       goto goodbye;
+               }
+       }
+
+       /*
+        * Try number four:
+        *
+        * [appdefaults]
+        *      option = <boolean>
+        */
+
+       names[1] = option;
+       names[2] = 0;
+       retval = profile_get_values(profile, names, &nameval);
+       if (retval == 0 && nameval && nameval[0]) {
+               *ret_value = strdup(nameval[0]);
+       } else {
+               return retval;
+       }
+
+goodbye:
+       if (nameval) {
+               char **cpp;
+               for (cpp = nameval; *cpp; cpp++)
+                       free(*cpp);
+               free(nameval);
+       }
+       return 0;
+}
+
+KRB5_DLLIMP void KRB5_CALLCONV 
+krb5_appdefault_boolean(context, appname, realm, option,
+                       default_value, ret_value)
+        krb5_context context;
+       const char *appname,  *option;
+        const krb5_data *realm;
+       int default_value;
+       int *ret_value;
+{
+       char *string = NULL;
+       krb5_error_code retval;
+
+       retval = appdefault_get(context, appname, realm, option, &string);
+
+       if (! retval && string) {
+               *ret_value = conf_boolean(string);
+               free(string);
+       } else
+               *ret_value = default_value;
+}
+
+KRB5_DLLIMP void KRB5_CALLCONV 
+krb5_appdefault_string(context, appname, realm, option, default_value,
+                      ret_value)
+     krb5_context context;
+       const char *appname, *option, *default_value;
+       char **ret_value;
+     const krb5_data *realm;
+       {
+       krb5_error_code retval;
+       char *string;
+
+       retval = appdefault_get(context, appname, realm, option, &string);
+
+       if (! retval && string) {
+               *ret_value = string;
+       } else {
+               *ret_value = strdup(default_value);
+       }
+}