From: Stig Venaas Date: Thu, 9 Nov 2000 12:39:18 +0000 (+0000) Subject: Improved ucdata loading error handling X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~1652 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b44cc963c2b021821ccac582054e2ffa04f4f1e1;p=openldap Improved ucdata loading error handling --- diff --git a/libraries/liblunicode/ucdata/ucdata.c b/libraries/liblunicode/ucdata/ucdata.c index c25c591ca2..d730730ce5 100644 --- a/libraries/liblunicode/ucdata/ucdata.c +++ b/libraries/liblunicode/ucdata/ucdata.c @@ -110,7 +110,10 @@ static unsigned long _ucprop_size; static unsigned short *_ucprop_offsets; static unsigned long *_ucprop_ranges; -static void +/* + * Return -1 on error, 0 if okay + */ +static int _ucprop_load(char *paths, int reload) { FILE *in; @@ -122,7 +125,7 @@ _ucprop_load(char *paths, int reload) /* * The character properties have already been loaded. */ - return; + return 0; /* * Unload the current character property data in preparation for @@ -135,7 +138,7 @@ _ucprop_load(char *paths, int reload) } if ((in = _ucopenfile(paths, "ctype.dat", "rb")) == 0) - return; + return -1; /* * Load the header. @@ -149,7 +152,7 @@ _ucprop_load(char *paths, int reload) if ((_ucprop_size = hdr.cnt) == 0) { fclose(in); - return; + return -1; } /* @@ -198,6 +201,7 @@ _ucprop_load(char *paths, int reload) for (i = 0; i < _ucprop_offsets[_ucprop_size]; i++) _ucprop_ranges[i] = endian_long(_ucprop_ranges[i]); } + return 0; } static void @@ -284,7 +288,10 @@ static unsigned long _uccase_size; static unsigned short _uccase_len[2]; static unsigned long *_uccase_map; -static void +/* + * Return -1 on error, 0 if okay + */ +static int _uccase_load(char *paths, int reload) { FILE *in; @@ -296,14 +303,14 @@ _uccase_load(char *paths, int reload) /* * The case mappings have already been loaded. */ - return; + return 0; free((char *) _uccase_map); _uccase_size = 0; } if ((in = _ucopenfile(paths, "case.dat", "rb")) == 0) - return; + return -1; /* * Load the header. @@ -339,6 +346,7 @@ _uccase_load(char *paths, int reload) for (i = 0; i < _uccase_size; i++) _uccase_map[i] = endian_long(_uccase_map[i]); } + return 0; } static void @@ -471,7 +479,10 @@ static unsigned long _ucdcmp_size; static unsigned long *_ucdcmp_nodes; static unsigned long *_ucdcmp_decomp; -static void +/* + * Return -1 on error, 0 if okay + */ +static int _ucdcmp_load(char *paths, int reload) { FILE *in; @@ -483,14 +494,14 @@ _ucdcmp_load(char *paths, int reload) /* * The decompositions have already been loaded. */ - return; + return 0; free((char *) _ucdcmp_nodes); _ucdcmp_size = 0; } if ((in = _ucopenfile(paths, "decomp.dat", "rb")) == 0) - return; + return -1; /* * Load the header. @@ -518,7 +529,8 @@ _ucdcmp_load(char *paths, int reload) if (hdr.bom == 0xfffe) { for (i = 0; i < size; i++) _ucdcmp_nodes[i] = endian_long(_ucdcmp_nodes[i]); - } + } + return 0; } static void @@ -587,7 +599,10 @@ ucdecomp_hangul(unsigned long code, unsigned long *num, unsigned long decomp[]) static unsigned long _uccmcl_size; static unsigned long *_uccmcl_nodes; -static void +/* + * Return -1 on error, 0 if okay + */ +static int _uccmcl_load(char *paths, int reload) { FILE *in; @@ -599,14 +614,14 @@ _uccmcl_load(char *paths, int reload) /* * The combining classes have already been loaded. */ - return; + return 0; free((char *) _uccmcl_nodes); _uccmcl_size = 0; } if ((in = _ucopenfile(paths, "cmbcl.dat", "rb")) == 0) - return; + return -1; /* * Load the header. @@ -632,7 +647,8 @@ _uccmcl_load(char *paths, int reload) if (hdr.bom == 0xfffe) { for (i = 0; i < _uccmcl_size; i++) _uccmcl_nodes[i] = endian_long(_uccmcl_nodes[i]); - } + } + return 0; } static void @@ -676,7 +692,10 @@ static unsigned long *_ucnum_nodes; static unsigned long _ucnum_size; static short *_ucnum_vals; -void +/* + * Return -1 on error, 0 if okay + */ +static int _ucnumb_load(char *paths, int reload) { FILE *in; @@ -688,14 +707,14 @@ _ucnumb_load(char *paths, int reload) /* * The numbers have already been loaded. */ - return; + return 0; free((char *) _ucnum_nodes); _ucnum_size = 0; } if ((in = _ucopenfile(paths, "num.dat", "rb")) == 0) - return; + return -1; /* * Load the header. @@ -732,7 +751,8 @@ _ucnumb_load(char *paths, int reload) for (i = 0; i < size; i++) _ucnum_vals[i] = endian_short(_ucnum_vals[i]); - } + } + return 0; } static void @@ -845,19 +865,24 @@ ucgetdigit(unsigned long code) * **************************************************************************/ -void +/* + * Return 0 if okay, negative on error + */ +int ucdata_load(char *paths, int masks) { + int error = 0; if (masks & UCDATA_CTYPE) - _ucprop_load(paths, 0); + error |= _ucprop_load(paths, 0) < 0 ? UCDATA_CTYPE : 0; if (masks & UCDATA_CASE) - _uccase_load(paths, 0); + error |= _uccase_load(paths, 0) < 0 ? UCDATA_CASE : 0; if (masks & UCDATA_DECOMP) - _ucdcmp_load(paths, 0); + error |= _ucdcmp_load(paths, 0) < 0 ? UCDATA_DECOMP : 0; if (masks & UCDATA_CMBCL) - _uccmcl_load(paths, 0); + error |= _uccmcl_load(paths, 0) < 0 ? UCDATA_CMBCL : 0; if (masks & UCDATA_NUM) - _ucnumb_load(paths, 0); + error |= _ucnumb_load(paths, 0) < 0 ? UCDATA_NUM : 0; + return -error; } void @@ -875,19 +900,24 @@ ucdata_unload(int masks) _ucnumb_unload(); } -void +/* + * Return 0 if okay, negative on error + */ +int ucdata_reload(char *paths, int masks) { + int error = 0; if (masks & UCDATA_CTYPE) - _ucprop_load(paths, 1); + error |= _ucprop_load(paths, 1) < 0 ? UCDATA_CTYPE : 0; if (masks & UCDATA_CASE) - _uccase_load(paths, 1); + error |= _uccase_load(paths, 1) < 0 ? UCDATA_CASE : 0; if (masks & UCDATA_DECOMP) - _ucdcmp_load(paths, 1); + error |= _ucdcmp_load(paths, 1) < 0 ? UCDATA_DECOMP : 0; if (masks & UCDATA_CMBCL) - _uccmcl_load(paths, 1); + error |= _uccmcl_load(paths, 1) < 0 ? UCDATA_CMBCL : 0; if (masks & UCDATA_NUM) - _ucnumb_load(paths, 1); + error |= _ucnumb_load(paths, 1) < 0 ? UCDATA_NUM : 0; + return -error; } #ifdef TEST diff --git a/libraries/liblunicode/ucdata/ucdata.h b/libraries/liblunicode/ucdata/ucdata.h index 8e05933db0..ec79fe759a 100644 --- a/libraries/liblunicode/ucdata/ucdata.h +++ b/libraries/liblunicode/ucdata/ucdata.h @@ -286,9 +286,9 @@ extern int ucgetdigit __((unsigned long code)); /* * Functions to load, unload, and reload specific data files. */ -extern void ucdata_load __((char *paths, int mask)); +extern int ucdata_load __((char *paths, int mask)); extern void ucdata_unload __((int mask)); -extern void ucdata_reload __((char *paths, int mask)); +extern int ucdata_reload __((char *paths, int mask)); #ifdef UCDATA_DEPRECATED /* diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 4d82b2794d..b96596cf9f 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -208,7 +208,9 @@ read_config( const char *fname ) default_search_base = ch_strdup( cargv[1] ); default_search_nbase = ch_strdup( cargv[1] ); - load_ucdata( NULL ); + if ( load_ucdata( NULL ) < 0 ) { + return( 1 ); + } if( dn_normalize( default_search_nbase ) == NULL ) { Debug( LDAP_DEBUG_ANY, "%s: line %d: " "invalid default search base \"%s\"\n", @@ -351,6 +353,7 @@ read_config( const char *fname ) /* set UCDATA path */ } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) { + int err; if ( cargc < 2 ) { Debug( LDAP_DEBUG_ANY, "%s: line %d: missing path in \"ucdata-path \" line\n", @@ -358,11 +361,14 @@ read_config( const char *fname ) return( 1 ); } - if ( load_ucdata( cargv[1] ) == 0 ) { - Debug( LDAP_DEBUG_ANY, - "%s: line %d: ucdata already loaded, ucdata-path must be set earlier in the file and/or be specified only once!\n", - fname, lineno, 0 ); - return 1; + err = load_ucdata( cargv[1] ); + if ( err <= 0 ) { + if ( err == 0 ) { + Debug( LDAP_DEBUG_ANY, + "%s: line %d: ucdata already loaded, ucdata-path must be set earlier in the file and/or be specified only once!\n", + fname, lineno, 0 ); + } + return( 1 ); } /* set time limit */ @@ -420,7 +426,9 @@ read_config( const char *fname ) fname, lineno, tmp_be->be_suffix[0] ); } else { char *dn = ch_strdup( cargv[1] ); - load_ucdata( NULL ); + if ( load_ucdata( NULL ) < 0 ) { + return( 1 ); + } if( dn_validate( dn ) == NULL ) { Debug( LDAP_DEBUG_ANY, "%s: line %d: " "suffix DN invalid \"%s\"\n", @@ -479,7 +487,9 @@ read_config( const char *fname ) char *alias, *aliased_dn; alias = ch_strdup( cargv[1] ); - load_ucdata( NULL ); + if ( load_ucdata( NULL ) < 0 ) { + return( 1 ); + } (void) dn_normalize( alias ); aliased_dn = ch_strdup( cargv[2] ); @@ -531,7 +541,9 @@ read_config( const char *fname ) be->be_root_dn = ch_strdup( cargv[1] ); be->be_root_ndn = ch_strdup( cargv[1] ); - load_ucdata( NULL ); + if ( load_ucdata( NULL ) < 0 ) { + return( 1 ); + } if( dn_normalize( be->be_root_ndn ) == NULL ) { free( be->be_root_dn ); free( be->be_root_ndn ); @@ -932,7 +944,9 @@ read_config( const char *fname ) fname, lineno, 0 ); } else { be->be_update_ndn = ch_strdup( cargv[1] ); - load_ucdata( NULL ); + if ( load_ucdata( NULL ) < 0 ) { + return( 1 ); + } if( dn_normalize( be->be_update_ndn ) == NULL ) { Debug( LDAP_DEBUG_ANY, "%s: line %d: updatedn DN is invalid\n", @@ -1162,7 +1176,9 @@ read_config( const char *fname ) free( saveline ); } fclose( fp ); - load_ucdata( NULL ); + if ( load_ucdata( NULL ) < 0 ) { + return( 1 ); + } return( 0 ); } @@ -1295,17 +1311,23 @@ fp_getline_init( int *lineno ) buf[0] = '\0'; } -/* Loads ucdata, returns 1 if loading, 0 if already loaded */ +/* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */ static int load_ucdata( char *path ) { static int loaded = 0; - + int err; + if ( loaded ) { - return 0; + return( 0 ); + } + err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, + UCDATA_CASE|UCDATA_CTYPE|UCDATA_NUM ); + if ( err ) { + Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n", + err, 0, 0 ); + return( -1 ); } - ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, - UCDATA_CASE|UCDATA_CTYPE|UCDATA_NUM ); loaded = 1; - return 1; + return( 1 ); }