From bbense@shred.stanford.edu Tue Apr 16 15:57:46 2002 Received: from fort-point-station.mit.edu (FORT-POINT-STATION.MIT.EDU [18.7.7.76]) by rt-11.mit.edu (8.9.3/8.9.3) with ESMTP id PAA06097 for ; Tue, 16 Apr 2002 15:57:45 -0400 (EDT) Received: from shred.stanford.edu (shred.Stanford.EDU [171.64.13.91]) by fort-point-station.mit.edu (8.9.2/8.9.2) with ESMTP id PAA17656 for ; Tue, 16 Apr 2002 15:57:44 -0400 (EDT) Received: (from bbense@localhost) by shred.stanford.edu (8.11.6.Beta0/8.10.0.PreAlpha1) id g3GJvi728053; Tue, 16 Apr 2002 12:57:44 -0700 (PDT) Message-Id: <200204161957.g3GJvi728053@shred.stanford.edu> Date: Tue, 16 Apr 2002 12:57:44 -0700 (PDT) From: bbense@stanford.edu Reply-To: bbense@stanford.edu To: krb5-bugs@mit.edu Subject: patch for new krb5 appdefault functions X-Send-Pr-Version: 3.99 >Number: 1088 >Category: pending >Synopsis: patch for new krb5 appdefault functions >Confidential: yes >Severity: serious >Priority: medium >Responsible: gnats-admin >State: open >Class: sw-bug >Submitter-Id: unknown >Arrival-Date: Tue Apr 16 15:58:00 EDT 2002 >Last-Modified: >Originator: >Organization: >Release: >Environment: >Description: >How-To-Repeat: >Fix: >Audit-Trail: >Unformatted: Submitter-Id: net Originator: Booker C. Bense Organization: Stanford University Confidential: no Synopsis: new api function for getting appdefaults Severity: non-critical Priority: low Category: krb5-libs Class: change-request 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: A more general API for getting appdefaults in a systematic way. You set up an array of structs defining the appdefaults you want and this function gets them in one fell swoop. How-To-Repeat: Fix: Here are the patches required to implement this. =================================================================== 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@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 */