for (i = offset; i < (len - (N - 1)); i++) {
char c = s[i];
- if (!islower(c))
+ if (!islower_ascii(c))
continue;
- s[i] = toupper(c);
+ s[i] = toupper_ascii(c);
if (!NT_STATUS_EQUAL(nt_status = string_combinations2(s, i + 1, fn, N - 1),NT_STATUS_WRONG_PASSWORD)) {
return (nt_status);
}
{
char *s1_0=s1;
- while(*s1 && *s2 && (*s1 == *s2 || tolower(*s1) == tolower(*s2) ||
+ while(*s1 && *s2 && (*s1 == *s2 || tolower_ascii(*s1) == tolower_ascii(*s2) ||
(*s1 == '\\' && *s2=='/') || (*s1 == '/' && *s2=='\\'))) {
s1++; s2++;
}
/* turn a 7 bit character into a ucs2 character */
#define UCS2_CHAR(c) ((c) << UCS2_SHIFT)
+/* return an ascii version of a ucs2 character */
+#define UCS2_TO_CHAR(c) ((c) & 0xff)
+
/* Copy into a smb_ucs2_t from a possibly unaligned buffer. Return the copied smb_ucs2_t */
#define COPY_UCS2_CHAR(dest,src) (((unsigned char *)(dest))[0] = ((unsigned char *)(src))[0],\
((unsigned char *)(dest))[1] = ((unsigned char *)(src))[1], (dest))
}
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";
while (1) {
if (*p & 0x80)
break;
- *q++ = toupper(*p);
+ *q++ = toupper_ascii(*p);
if (!*p)
break;
p++;
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)
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);
/* 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)
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++;
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] = '_';
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 */
(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++;
}
(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++;
}
void load_case_tables(void)
{
static int initialised;
+ char *old_locale = NULL, *saved_locale = NULL;
int i;
if (initialised) {
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) {
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
}
/*
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));
+}
return (False);
for (i = 0; i < 32; i += 2) {
- hinybble = toupper(p[i]);
- lonybble = toupper(p[i + 1]);
+ hinybble = toupper_ascii(p[i]);
+ lonybble = toupper_ascii(p[i + 1]);
p1 = strchr(hexchars, hinybble);
p2 = strchr(hexchars, lonybble);
}
for (i = 0; i < 42; i += 2) {
- hinybble = toupper(p[i]);
- lonybble = toupper(p[i + 1]);
+ hinybble = toupper_ascii(p[i]);
+ lonybble = toupper_ascii(p[i + 1]);
p1 = strchr(hexchars, hinybble);
p2 = strchr(hexchars, lonybble);
lowercasename = smb_xstrdup(sname);
l = strlen(lowercasename);
for(i = 0; i < l; i++) {
- lowercasename[i] = tolower(lowercasename[i]);
+ lowercasename[i] = tolower_ascii(lowercasename[i]);
}
result = pgsqlsam_select_by_field( methods, user, SQL_SEARCH_USER_NAME, lowercasename ) ;
magic = strchr_m( s, magic_char );
while( magic && magic[1] && magic[2] ) { /* 3 chars, 1st is magic. */
if( ('.' == magic[3] || '/' == magic[3] || !(magic[3])) /* Ends with '.' or nul or '/' ? */
- && isbasechar( toupper(magic[1]) ) /* is 2nd char basechar? */
- && isbasechar( toupper(magic[2]) ) ) /* is 3rd char basechar? */
+ && isbasechar( toupper_ascii(magic[1]) ) /* is 2nd char basechar? */
+ && isbasechar( toupper_ascii(magic[2]) ) ) /* is 3rd char basechar? */
return( True ); /* If all above, then true, */
magic = strchr_m( magic+1, magic_char ); /* else seek next magic. */
}
s1 = strrchr( mangled_name_key, '.' );
if( s1 && (s2 = strrchr( raw_name, '.' )) ) {
size_t i = 1;
- while( s1[i] && (tolower( s1[i] ) == s2[i]) )
+ while( s1[i] && (tolower_ascii( s1[i] ) == s2[i]) )
i++;
if( !s1[i] && !s2[i] ) {
/* Truncate at the '.' */
if (! FLAG_CHECK(lead_chars[i], FLAG_ASCII)) {
lead_chars[i] = '_';
}
- lead_chars[i] = toupper(lead_chars[i]);
+ lead_chars[i] = toupper_ascii(lead_chars[i]);
}
for (;i<mangle_prefix;i++) {
lead_chars[i] = '_';
for (i=1; extension_length < 3 && dot_p[i]; i++) {
char c = dot_p[i];
if (FLAG_CHECK(c, FLAG_ASCII)) {
- extension[extension_length++] = toupper(c);
+ extension[extension_length++] = toupper_ascii(c);
}
}
}
char_flags[c2] |= FLAG_POSSIBLE2;
char_flags[c3] |= FLAG_POSSIBLE3;
char_flags[c4] |= FLAG_POSSIBLE4;
- char_flags[tolower(c1)] |= FLAG_POSSIBLE1;
- char_flags[tolower(c2)] |= FLAG_POSSIBLE2;
- char_flags[tolower(c3)] |= FLAG_POSSIBLE3;
- char_flags[tolower(c4)] |= FLAG_POSSIBLE4;
+ char_flags[tolower_ascii(c1)] |= FLAG_POSSIBLE1;
+ char_flags[tolower_ascii(c2)] |= FLAG_POSSIBLE2;
+ char_flags[tolower_ascii(c3)] |= FLAG_POSSIBLE3;
+ char_flags[tolower_ascii(c4)] |= FLAG_POSSIBLE4;
char_flags[(unsigned char)'.'] |= FLAG_POSSIBLE4;
}
char *p = newstring;
while (*str) {
- if (*str != ' ') *p++ = toupper(*str);
+ if (*str != ' ') *p++ = toupper_ascii(*str);
++str;
}
*p = '\0';