From: Kurt Zeilenga Date: Sun, 3 Sep 2000 23:48:35 +0000 (+0000) Subject: Bring UCdata infrastructure. X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~2113 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=cee040a3218637b541aa6c17fb074dc840752fab;p=openldap Bring UCdata infrastructure. --- diff --git a/include/ldap_defaults.h b/include/ldap_defaults.h index c02734465d..811865f1d1 100644 --- a/include/ldap_defaults.h +++ b/include/ldap_defaults.h @@ -200,6 +200,7 @@ Please try again later.\r\n" */ /* location of the default slapd config file */ #define SLAPD_DEFAULT_CONFIGFILE LDAP_SYSCONFDIR LDAP_DIRSEP "slapd.conf" +#define SLAPD_DEFAULT_UCDATA LDAP_DATADIR LDAP_DIRSEP "ucdata" /* default max deref depth for aliases */ #define SLAPD_DEFAULT_MAXDEREFDEPTH 15 /* default sizelimit on number of entries from a search */ diff --git a/include/ldap_pvt.h b/include/ldap_pvt.h index 042cdd18d9..2596e29f02 100644 --- a/include/ldap_pvt.h +++ b/include/ldap_pvt.h @@ -177,8 +177,19 @@ LDAP_F (int) ldap_pvt_tls_set_option LDAP_P(( struct ldapoptions *lo, int option */ typedef ber_int_t ldap_ucs4_t; +#define LDAP_UCS4_INVALID (0x80000000U) + typedef short ldap_ucs2_t; -typedef ldap_ucs2_t ldap_unicode_t; + +/* UCDATA uses UCS-2 passed in an unsigned long */ +typedef unsigned long ldap_unicode_t; + +/* conversion routines */ +LDAP_F( ldap_ucs4_t ) ldap_utf8_to_ucs4( const char * p ); +LDAP_F( int ) ldap_ucs4_to_utf8( ldap_ucs4_t c, char *buf ); + +#define ldap_utf8_to_unicode( p ) ldap_utf8_to_ucs4((p)) +#define ldap_unicode_to_utf8( c, buf ) ldap_ucs4_to_ucs4((c),(buf)) /* returns the number of bytes in the UTF-8 string */ LDAP_F (ber_len_t) ldap_utf8_bytes( const char * ); diff --git a/libraries/libldap/utf-8.c b/libraries/libldap/utf-8.c index 07243b786d..1523b7b4a4 100644 --- a/libraries/libldap/utf-8.c +++ b/libraries/libldap/utf-8.c @@ -30,8 +30,6 @@ #undef ISASCII #define ISASCII(uc) ((uc) < 0x100) -#undef UCS4_INVALID -#define UCS4_INVALID 0x80000000U /* * Basic UTF-8 routines @@ -119,13 +117,13 @@ ldap_ucs4_t ldap_utf8_to_ucs4( const char * p ) len = LDAP_UTF8_CHARLEN(p); - if( len == 0 ) return UCS4_INVALID; + if( len == 0 ) return LDAP_UCS4_INVALID; ch = c[0] & mask[len]; for(i=1; i < len; i++) { if ((c[i] & 0xc0) != 0x80) { - return UCS4_INVALID; + return LDAP_UCS4_INVALID; } ch <<= 6; diff --git a/libraries/liblunicode/Makefile.in b/libraries/liblunicode/Makefile.in index 4f8b891b28..815a16eeaa 100644 --- a/libraries/liblunicode/Makefile.in +++ b/libraries/liblunicode/Makefile.in @@ -8,6 +8,7 @@ LIBRARY = liblunicode.a XXDIR = $(srcdir)/*/ XXHEADERS = ucdata.h ure.h + XXSRCS = ucdata.c ucgendat.c ure.c urestubs.c SRCS = OBJS = ucdata.o ure.o urestubs.o @@ -20,6 +21,13 @@ LDAP_LIBDIR= ../../libraries ucgendat: $(LIBRARY) ucgendat.o $(LTLINK) $(LDFLAGS) -o $@ ucgendat.o $(LIBS) + ./ucgendat $(srcdir)/UnicodeData.txt + +install-local: $(PROGRAMS) FORCE + -$(MKDIR) $(DESTDIR)$(datadir)/ucdata + @for i $(DATFILES); do \ + $(INSTALL) $(INSTALLFLAGS) -m 644 $$i $(DESTDIR)$(datadir)/ucdata \ + done .links : @for i in $(XXSRCS) $(XXHEADERS); do \ @@ -31,6 +39,6 @@ ucgendat: $(LIBRARY) ucgendat.o $(XXSRCS) : .links clean-local: FORCE - @$(RM) .links + @$(RM) *.dat .links depend-common: .links diff --git a/servers/slapd/Makefile.in b/servers/slapd/Makefile.in index 1c3b14747d..eb54e1542e 100644 --- a/servers/slapd/Makefile.in +++ b/servers/slapd/Makefile.in @@ -41,7 +41,7 @@ XDEFS = $(MODULES_CPPFLAGS) XLDFLAGS = $(MODULES_LDFLAGS) $(SLAPD_MODULES) # $(LTHREAD_LIBS) must be last -XLIBS = libbackends.a -lavl -lldbm -lldif -llutil -lldap_r -llber +XLIBS = libbackends.a -lavl -lldbm -lldif -llutil -llunicode -lldap_r -llber XXLIBS = $(LDBM_LIBS) $(SLAPD_LIBS) \ $(SECURITY_LIBS) \ $(LDIF_LIBS) $(LUTIL_LIBS) diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 69cd36c6f3..903932def8 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -34,6 +34,7 @@ int global_lastmod = ON; int global_idletimeout = 0; char *global_host = NULL; char *global_realm = NULL; +char *global_ucdata_path = NULL; char *ldap_srvtab = ""; char *default_passwd_hash; @@ -283,6 +284,25 @@ read_config( const char *fname ) return 1; } + /* set UCDATA path */ + } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) { + if ( cargc < 2 ) { + Debug( LDAP_DEBUG_ANY, + "%s: line %d: missing path in \"ucdata-path \" line\n", + fname, lineno, 0 ); + return( 1 ); + } + + if ( global_ucdata_path != NULL ) { + Debug( LDAP_DEBUG_ANY, + "%s: line %d: already set ucdata-path!\n", + fname, lineno, 0 ); + return 1; + + } else { + global_ucdata_path = ch_strdup( cargv[1] ); + } + /* set time limit */ } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) { if ( cargc < 2 ) { diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 5789dc7925..c324adf296 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -769,6 +769,7 @@ LDAP_SLAPD_F (int) global_idletimeout; LDAP_SLAPD_F (int) global_schemacheck; LDAP_SLAPD_F (char) *global_host; LDAP_SLAPD_F (char) *global_realm; +LDAP_SLAPD_F (char) *global_ucdata_path; LDAP_SLAPD_F (char) *default_passwd_hash; LDAP_SLAPD_F (int) lber_debug; LDAP_SLAPD_F (int) ldap_syslog; diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index 1a8071ff65..cac0f0b0a3 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -343,6 +343,62 @@ booleanMatch( return LDAP_SUCCESS; } +#if 0 +static int +UTF8casecmp( + struct berval *right, + struct berval *left ) +{ + ber_len_t r, l; + int rlen, llen; + ldap_unicode_t ru, lu; + ldap_unicode_t ruu, luu; + + for( r=0, l=0; + r < right->bv_len && l < left->bv_len; + r+=rlen, l+=llen ) + { + /* + * XXYYZ: we convert to ucs4 even though -llunicode + * expects ucs2 in an unsigned long + */ + ru = ldap_utf8_to_ucs4( &right->bv_val[r] ); + if( ru == LDAP_UCS4_INVALID ) { + return 1; + } + + lu = ldap_utf8_to_ucs4( &left->bv_val[l] ); + if( lu == LDAP_UCS4_INVALID ) { + return -1; + } + + ruu = uctoupper( ru ); + luu = uctoupper( lu ); + + if( ruu > luu ) { + return 1; + } else if( luu > ruu ) { + return -1; + } + + rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] ); + llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] ); + } + + if( r < right->bv_len ) { + /* less left */ + return -1; + } + + if( l < left->bv_len ) { + /* less right */ + return 1; + } + + return 0; +} +#endif + static int UTF8StringValidate( Syntax *syntax, @@ -1019,6 +1075,9 @@ caseIgnoreMatch( struct berval *value, void *assertedValue ) { +#if 0 + *matchp = UTF8casecmp( value, (struct berval *) assertedValue ); +#else int match = value->bv_len - ((struct berval *) assertedValue)->bv_len; if( match == 0 ) { @@ -1028,6 +1087,7 @@ caseIgnoreMatch( } *matchp = match; +#endif return LDAP_SUCCESS; } diff --git a/servers/slapd/schema_prep.c b/servers/slapd/schema_prep.c index 0574dcde18..12b0af963f 100644 --- a/servers/slapd/schema_prep.c +++ b/servers/slapd/schema_prep.c @@ -15,6 +15,7 @@ #include "slap.h" #include "ldap_pvt.h" +#include "../libraries/liblunicode/ucdata.h" int schema_init_done = 0; @@ -218,6 +219,9 @@ schema_prep( void ) /* we should only be called once after schema_init() was called */ assert( schema_init_done == 1 ); + ucdata_load( global_ucdata_path ? global_ucdata_path : + SLAPD_DEFAULT_UCDATA, UCDATA_CASE|UCDATA_CTYPE|UCDATA_NUM ); + for( i=0; oc_map[i].ssom_name; i++ ) { ObjectClass ** ocp = (ObjectClass **) &(((char *) &slap_schema)[oc_map[i].ssom_offset]); diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 6d196c4511..76bf82d2ff 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -256,7 +256,7 @@ typedef struct slap_syntax { #define slap_syntax_is_ber(s) slap_syntax_is_flag((s),SLAP_SYNTAX_BER) #define slap_syntax_is_hidden(s) slap_syntax_is_flag((s),SLAP_SYNTAX_HIDE) -/* XXX -> UCS-2 Converter */ +/* X -> Y Converter */ typedef int slap_mr_convert_func LDAP_P(( struct berval * in, struct berval ** out )); diff --git a/servers/slapd/tools/Makefile.in b/servers/slapd/tools/Makefile.in index 227ffd0bea..777e666a93 100644 --- a/servers/slapd/tools/Makefile.in +++ b/servers/slapd/tools/Makefile.in @@ -25,7 +25,7 @@ SLAPD_MODULES = @SLAPD_MODULES_LIST@ XDEFS = $(MODULES_CPPFLAGS) XLDFLAGS = $(MODULES_LDFLAGS) $(SLAPD_MODULES) -XLIBS = -lavl -lldif -lldbm -llutil -lldap_r -llber +XLIBS = -lavl -lldif -lldbm -llutil -llunicode -lldap_r -llber XXLIBS = $(SLAPD_LIBS) \ $(LDBM_LIBS) $(SECURITY_LIBS) \ $(LDIF_LIBS) $(LUTIL_LIBS) diff --git a/tests/Makefile.in b/tests/Makefile.in index 5d250a2d5a..ff5467d677 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -13,6 +13,7 @@ ldbm: test-ldbm test-ldbm: FORCE @-$(LN_S) $(srcdir)/data . @-$(LN_S) $(top_srcdir)/servers/slapd/schema . + @-$(LN_S) ../libraries/liblunicode/ucdata . @if test "$(BUILD_LDBM)" = "yes" ; then \ echo "Initiating LDAP tests for LDBM..." ; \ $(MKDIR) test-db test-repl || true; \ @@ -25,6 +26,7 @@ passwd: test-passwd test-passwd: FORCE @-$(LN_S) $(srcdir)/data . @-$(LN_S) $(top_srcdir)/servers/slapd/schema . + @-$(LN_S) ../libraries/liblunicode/ucdata . @echo "Initiating LDAP tests..." @-$(MKDIR) test-db test-repl || true @$(srcdir)/scripts/passwd-search $(srcdir) passwd @@ -33,6 +35,7 @@ test-nis-schema: test-nis-schema-ldbm test-nis-schema-ldbm: @-$(LN_S) $(srcdir)/data . @-$(LN_S) $(top_srcdir)/servers/slapd/schema . + @-$(LN_S) ../libraries/liblunicode/ucdata . @echo "Initiating LDAP server with NIS schema & ldbm backend..."; \ $(MKDIR) test-db test-repl ; \ $(srcdir)/scripts/startup_nis_ldap_server.sh $(srcdir) ldbm @@ -41,6 +44,6 @@ clean-local: FORCE -$(RM) -r test-db/[!C]* test-repl/[!C]* *leak *gmon *core veryclean-local: FORCE - @-$(RM) data schema + @-$(RM) data schema ucdata -$(RM) -r test-db test-repl diff --git a/tests/data/slapd-acl.conf b/tests/data/slapd-acl.conf index 58992bfb71..bf0bbd659f 100644 --- a/tests/data/slapd-acl.conf +++ b/tests/data/slapd-acl.conf @@ -2,6 +2,7 @@ # # master slapd config -- for testing # +ucdata-path ./ucdata #include ./data/slapd.at.conf #include ./data/slapd.oc.conf include ./schema/core.schema diff --git a/tests/data/slapd-dnssrv.conf b/tests/data/slapd-dnssrv.conf index bdd60db810..e66e58e3b7 100644 --- a/tests/data/slapd-dnssrv.conf +++ b/tests/data/slapd-dnssrv.conf @@ -2,6 +2,7 @@ # # DNS SRV slapd config -- for testing # +ucdata-path ./ucdata #include ./data/slapd.at.conf #include ./data/slapd.oc.conf include ./schema/core.schema diff --git a/tests/data/slapd-master.conf b/tests/data/slapd-master.conf index f3d7e044b1..7c0cc687dc 100644 --- a/tests/data/slapd-master.conf +++ b/tests/data/slapd-master.conf @@ -2,6 +2,7 @@ # # master slapd config -- for testing # +ucdata-path ./ucdata #include ./data/slapd.at.conf #include ./data/slapd.oc.conf include ./schema/core.schema diff --git a/tests/data/slapd-nis-master.conf b/tests/data/slapd-nis-master.conf index 0aebb564d0..db1e2c2bb3 100644 --- a/tests/data/slapd-nis-master.conf +++ b/tests/data/slapd-nis-master.conf @@ -2,6 +2,7 @@ # # master slapd config -- for testing # +ucdata-path ./ucdata include ../servers/slapd/schema/others_nis.at.conf include ../servers/slapd/schema/others_nis.oc.conf include ../servers/slapd/schema/nis.at.conf diff --git a/tests/data/slapd-passwd.conf b/tests/data/slapd-passwd.conf index 78279e4f5d..a231233f38 100644 --- a/tests/data/slapd-passwd.conf +++ b/tests/data/slapd-passwd.conf @@ -2,6 +2,7 @@ # # master slapd config -- for testing # +ucdata-path ./ucdata #include ./data/slapd.at.conf #include ./data/slapd.oc.conf include ./schema/core.schema diff --git a/tests/data/slapd-pw.conf b/tests/data/slapd-pw.conf index 2b1681c989..1fd26b5992 100644 --- a/tests/data/slapd-pw.conf +++ b/tests/data/slapd-pw.conf @@ -2,6 +2,7 @@ # # master slapd config -- for testing # +ucdata-path ./ucdata #include ./data/slapd.at.conf #include ./data/slapd.oc.conf include ./schema/core.schema diff --git a/tests/data/slapd-ref-slave.conf b/tests/data/slapd-ref-slave.conf index 714e4e097e..f804e4d2e0 100644 --- a/tests/data/slapd-ref-slave.conf +++ b/tests/data/slapd-ref-slave.conf @@ -2,6 +2,7 @@ # # slave slapd config -- for default referral testing # +ucdata-path ./ucdata #include ./data/slapd.at.conf #include ./data/slapd.oc.conf include ./schema/core.schema diff --git a/tests/data/slapd-repl-master.conf b/tests/data/slapd-repl-master.conf index 57098f3786..6df433a502 100644 --- a/tests/data/slapd-repl-master.conf +++ b/tests/data/slapd-repl-master.conf @@ -2,6 +2,7 @@ # # master slapd config -- for testing of replication # +ucdata-path ./ucdata #include ./data/slapd.at.conf #include ./data/slapd.oc.conf include ./schema/core.schema diff --git a/tests/data/slapd-repl-slave.conf b/tests/data/slapd-repl-slave.conf index ee7fea837b..84919f7b87 100644 --- a/tests/data/slapd-repl-slave.conf +++ b/tests/data/slapd-repl-slave.conf @@ -2,6 +2,7 @@ # # master slapd config -- for testing of replication # +ucdata-path ./ucdata #include ./data/slapd.at.conf #include ./data/slapd.oc.conf include ./schema/core.schema diff --git a/tests/data/slapd.conf b/tests/data/slapd.conf index 413b16ec67..a15e2b7cb0 100644 --- a/tests/data/slapd.conf +++ b/tests/data/slapd.conf @@ -3,6 +3,7 @@ # stand-alone slapd config -- for testing # with indexing # +ucdata-path ./ucdata #include ./data/slapd.at.conf #include ./data/slapd.oc.conf include ./schema/core.schema