krb5-libs/1090: resend of appdefault patches

bbense@stanford.edu bbense at stanford.edu
Tue Apr 16 16:22:40 EDT 2002


>Number:         1090
>Category:       krb5-libs
>Synopsis:       Patches to implement new appdefault api
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    krb5-unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   unknown
>Arrival-Date:   Tue Apr 16 16:23:00 EDT 2002
>Last-Modified:
>Originator:     Booker C. Bense
>Organization:
	Stanford University
>Release:        krb5-1.2.2
>Environment:
	UNIX
System: SunOS shred.Stanford.EDU 5.7 Generic_106541-15 sun4u sparc SUNW,Ultra-5_10
Architecture: sun4

>Description:
	This patch implements a new function that allows for a generic 
	interface to appdefault reading. You set up an array of structs
	to define the defaults and call this function to get all the defaults
	set in one stroke. 
>How-To-Repeat:
	
>Fix:
	
===================================================================
RCS file: /afs/ir/dev/cvs/kerberos/krb5/lib/krb5/krb/appdefault.c,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- /usr/users/bbense/work/kerberos/krb5/lib/krb5/krb/appdefault.c	5 Jul 2000 22:47:02 -0000	1.1.1.1
+++ /usr/users/bbense/work/kerberos/krb5/lib/krb5/krb/appdefault.c	18 Sep 2000 17:32:56 -0000	1.3
@@ -141,6 +141,9 @@
 	return 0;
 }
 
+/* public routines */ 
+
+/* I think this one is a bad idea, bbense at stanford.edu */ 
 KRB5_DLLIMP void KRB5_CALLCONV 
 krb5_appdefault_boolean(context, appname, realm, option,
 			default_value, ret_value)
@@ -162,18 +165,28 @@
 		*ret_value = default_value;
 }
 
+/* At the base level I'd rather see just these two */ 
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV 
+krb5_string_to_boolean (string,value)
+     const char *string;
+     int *value;
+{ 
+  *value = conf_boolean(string) ; 
+  return 0 ; 
+}
+
 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 char *appname, *option, *default_value;
+     char **ret_value;
      const krb5_data *realm;
-	{
-	krb5_error_code retval;
-	char *string;
+{
+     krb5_error_code retval;
+     char *string;
 
-	retval = appdefault_get(context, appname, realm, option, &string);
+     retval = appdefault_get(context, appname, realm, option, &string);
 
 	if (! retval && string) {
 		*ret_value = string;
@@ -181,3 +194,69 @@
 		*ret_value = strdup(default_value);
 	}
 }
+
+/* A helper routine for appdefault read */ 
+
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV 
+krb5_string_to_string (string,value)
+     const char *string;
+     char **value;
+{ 
+  *value = strdup(string);  
+  return 0 ; 
+}
+
+KRB5_DLLIMP void KRB5_CALLCONV 
+krb5_free_string(context,string)
+     krb5_context context; 
+     char *string ; 
+{ 
+  if ( string != NULL ) {
+    krb5_xfree(string); 
+  }
+} 
+
+/* Read in all the defaults at once. */ 
+
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV 
+krb5_appdefault_read(context,appname,realm,default_list, count) 
+     krb5_context context;
+     const char *appname; 
+     const krb5_data *realm; 
+     krb5_appdefault_list_item *default_list; 
+     int count ; 
+{ 
+  int i,rcode; 
+  char *ret_val; 
+  /* First check args for sanity */ 
+  if ( default_list == NULL || count < 0 ) { 
+    return EINVAL ; 
+  }
+
+  for ( i = 0 ; i < count ; i++ ) 
+    { 
+      if ( default_list[i].option != NULL && 
+	   default_list[i].store != NULL && 
+	   default_list[i].default_value != NULL ) 
+	{ 
+	  krb5_appdefault_string(context,appname,realm,default_list[i].option,
+				default_list[i].default_value,&ret_val) ;
+	  if ( ret_val != NULL ) 
+	    { 
+	      rcode = (*default_list[i].parse_function)(ret_val,default_list[i].store); 
+	      /* too bad libraries can't com_err, it would be very useful
+		 to tell the programmer what went wrong here. */ 
+	      free( ret_val );
+	      if ( rcode ) return rcode ;
+	    } else { /* This should never happen */  
+	      return ENOMEM ; 
+	    } 
+	}
+    } 
+  return 0 ; 
+}
+
+
+
+
+

===================================================================
RCS file: /afs/ir/dev/cvs/kerberos/krb5/include/krb5.hin,v
retrieving revision 1.1.1.3
retrieving revision 1.2
diff -u -r1.1.1.3 -r1.2
--- /usr/users/bbense/work/kerberos/krb5/include/krb5.hin	5 Jul 2000 22:46:14 -0000	1.1.1.3
+++ /usr/users/bbense/work/kerberos/krb5/include/krb5.hin	18 Sep 2000 17:43:56 -0000	1.2
@@ -2416,6 +2416,42 @@
 		int default_value,
 		int *ret_value));
 
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV 
+krb5_string_to_boolean
+KRB5_PROTOTYPE((const char FAR *, int FAR *));
+
+  /* helper routine for krb5_appdefault_read */ 
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV 
+krb5_string_to_string
+KRB5_PROTOTYPE((const char FAR *, char FAR * FAR *));
+
+  /* free the string returned above */ 
+KRB5_DLLIMP void KRB5_CALLCONV 
+krb5_free_string 
+KRB5_PROTOTYPE((krb5_context context,char FAR * ));
+
+  /* This is for use with krb5_appdefault_read. */ 
+typedef struct _krb5_appdefault_list_item { 
+  char FAR *option ; /* The default name */ 
+  char FAR *default_value; /* The default value if not found in krb.conf */ 
+  krb5_error_code (*parse_function)(); /* This function should take a string,
+					  parse it and store the resulting 
+					  value in the second arg. 
+					  krb5_string_to_deltat is a good 
+					  example*/ 
+  void *store; /* This is an address for the second arg to parse function */ 
+
+} krb5_appdefault_list_item; 
+
+KRB5_DLLIMP krb5_error_code KRB5_CALLCONV
+krb5_appdefault_read
+KRB5_PROTOTYPE((krb5_context context,
+		const char *appname,  
+	        const krb5_data *realm,
+		krb5_appdefault_list_item *default_list,
+		const int count));
+
+
 /*
  * The realm iterator functions
  */
>Audit-Trail:
>Unformatted:



More information about the krb5-bugs mailing list