summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/charcnv.c11
-rw-r--r--source3/lib/replace.c2
-rw-r--r--source3/lib/username.c4
-rw-r--r--source3/lib/util_str.c16
-rw-r--r--source3/lib/util_unistr.c56
5 files changed, 68 insertions, 21 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index 0c806167f4..c4eeab135e 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -84,15 +84,6 @@ static const char *charset_name(charset_t ch)
}
ret = ln;
}
-#ifdef HAVE_SETLOCALE
- /* We set back the locale to C to get ASCII-compatible toupper/lower functions.
- For now we do not need any other POSIX localisations anyway. When we should
- really need localized string functions one day we need to write our own
- ascii_tolower etc.
- */
- setlocale(LC_ALL, "C");
- #endif
-
#endif
if (!ret || !*ret) ret = "ASCII";
@@ -747,7 +738,7 @@ char *strdup_upper(const char *s)
while (1) {
if (*p & 0x80)
break;
- *q++ = toupper(*p);
+ *q++ = toupper_ascii(*p);
if (!*p)
break;
p++;
diff --git a/source3/lib/replace.c b/source3/lib/replace.c
index 57ee6ea11e..120fd3a468 100644
--- a/source3/lib/replace.c
+++ b/source3/lib/replace.c
@@ -390,7 +390,7 @@ char *rep_inet_ntoa(struct in_addr ip)
if (isdigit(c))
c -= '0';
else if (isalpha(c))
- c -= isupper(c) ? 'A' - 10 : 'a' - 10;
+ c -= isupper_ascii(c) ? 'A' - 10 : 'a' - 10;
else
break;
if (c >= base)
diff --git a/source3/lib/username.c b/source3/lib/username.c
index ecfd5fef9e..7d66b320ad 100644
--- a/source3/lib/username.c
+++ b/source3/lib/username.c
@@ -716,9 +716,9 @@ static struct passwd *uname_string_combinations2(char *s,int offset,struct passw
for (i=offset;i<(len-(N-1));i++) {
char c = s[i];
- if (!islower((int)c))
+ if (!islower_ascii((int)c))
continue;
- s[i] = toupper(c);
+ s[i] = toupper_ascii(c);
ret = uname_string_combinations2(s,i+1,fn,N-1);
if(ret)
return(ret);
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index 80bb2ff2ad..0b02487f77 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -201,8 +201,8 @@ int StrCaseCmp(const char *s, const char *t)
/* not ascii anymore, do it the hard way from here on in */
break;
- us = toupper(*ps);
- ut = toupper(*pt);
+ us = toupper_ascii(*ps);
+ ut = toupper_ascii(*pt);
if (us == ut)
continue;
else if (us < ut)
@@ -309,7 +309,7 @@ int strwicmp(const char *psz1, const char *psz2)
psz1++;
while (isspace((int)*psz2))
psz2++;
- if (toupper(*psz1) != toupper(*psz2) || *psz1 == '\0'
+ if (toupper_ascii(*psz1) != toupper_ascii(*psz2) || *psz1 == '\0'
|| *psz2 == '\0')
break;
psz1++;
@@ -680,7 +680,7 @@ char *alpha_strcpy_fn(const char *fn, int line, char *dest, const char *src, con
for(i = 0; i < len; i++) {
int val = (src[i] & 0xff);
- if (isupper(val) || islower(val) || isdigit(val) || strchr_m(other_safe_chars, val))
+ if (isupper_ascii(val) || islower_ascii(val) || isdigit(val) || strchr_m(other_safe_chars, val))
dest[i] = src[i];
else
dest[i] = '_';
@@ -774,12 +774,12 @@ size_t strhex_to_str(char *p, size_t len, const char *strhex)
continue;
}
- if (!(p1 = strchr_m(hexchars, toupper(strhex[i]))))
+ if (!(p1 = strchr_m(hexchars, toupper_ascii(strhex[i]))))
break;
i++; /* next hex digit */
- if (!(p2 = strchr_m(hexchars, toupper(strhex[i]))))
+ if (!(p2 = strchr_m(hexchars, toupper_ascii(strhex[i]))))
break;
/* get the two nybbles */
@@ -1510,7 +1510,7 @@ void strlower_m(char *s)
(ie. they match for the first 128 chars) */
while (*s && !(((unsigned char)s[0]) & 0x80)) {
- *s = tolower((unsigned char)*s);
+ *s = tolower_ascii((unsigned char)*s);
s++;
}
@@ -1544,7 +1544,7 @@ void strupper_m(char *s)
(ie. they match for the first 128 chars) */
while (*s && !(((unsigned char)s[0]) & 0x80)) {
- *s = toupper((unsigned char)*s);
+ *s = toupper_ascii((unsigned char)*s);
s++;
}
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));
+}