From 5a4881bf396e691524329bcd6aa1ae4a7f4084ec Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Dec 2005 20:52:36 +0000 Subject: r12522: Try and fix bug #2926 by removing setlocale(LC_ALL, "C") and replace calls to isupper/islower/toupper/tolower with ASCII equivalents (mapping into _w variants). Jeremy. (This used to be commit c2752347eb2deeb2798c580ec7fc751a847717e9) --- source3/lib/util_unistr.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'source3/lib/util_unistr.c') diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index b979745d36..880416a549 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -51,6 +51,7 @@ static uint8 doschar_table[8192]; /* 65536 characters / 8 bits/byte */ void load_case_tables(void) { static int initialised; + char *old_locale = NULL, *saved_locale = NULL; int i; if (initialised) { @@ -61,6 +62,17 @@ void load_case_tables(void) upcase_table = map_file(lib_path("upcase.dat"), 0x20000); lowcase_table = map_file(lib_path("lowcase.dat"), 0x20000); +#ifdef HAVE_SETLOCALE + /* Get the name of the current locale. */ + old_locale = setlocale(LC_ALL, NULL); + + /* Save it as it is in static storage. */ + saved_locale = SMB_STRDUP(old_locale); + + /* We set back the locale to C to get ASCII-compatible toupper/lower functions. */ + setlocale(LC_ALL, "C"); +#endif + /* we would like Samba to limp along even if these tables are not available */ if (!upcase_table) { @@ -92,6 +104,12 @@ void load_case_tables(void) lowcase_table[v] = UCS2_CHAR(isupper(i)?tolower(i):i); } } + +#ifdef HAVE_SETLOCALE + /* Restore the old locale. */ + setlocale (LC_ALL, saved_locale); + SAFE_FREE(saved_locale); +#endif } /* @@ -997,3 +1015,41 @@ UNISTR2* ucs2_to_unistr2(TALLOC_CTX *ctx, UNISTR2* dst, smb_ucs2_t* src) return dst; } + +/************************************************************* + ascii only toupper - saves the need for smbd to be in C locale. +*************************************************************/ + +int toupper_ascii(int c) +{ + smb_ucs2_t uc = toupper_w(UCS2_CHAR(c)); + return UCS2_TO_CHAR(uc); +} + +/************************************************************* + ascii only tolower - saves the need for smbd to be in C locale. +*************************************************************/ + +int tolower_ascii(int c) +{ + smb_ucs2_t uc = tolower_w(UCS2_CHAR(c)); + return UCS2_TO_CHAR(uc); +} + +/************************************************************* + ascii only isupper - saves the need for smbd to be in C locale. +*************************************************************/ + +int isupper_ascii(int c) +{ + return isupper_w(UCS2_CHAR(c)); +} + +/************************************************************* + ascii only islower - saves the need for smbd to be in C locale. +*************************************************************/ + +int islower_ascii(int c) +{ + return islower_w(UCS2_CHAR(c)); +} -- cgit