diff --git a/lib/iniparser/src/strlib.c b/lib/iniparser/src/strlib.c index f0d85ae..1847cff 100644 --- a/lib/iniparser/src/strlib.c +++ b/lib/iniparser/src/strlib.c @@ -60,7 +60,9 @@ char * strlwc(const char * s) memset(l, 0, ASCIILINESZ+1); i=0 ; while (s[i] && i= 'A' && l[i] <= 'Z') + l[i] = l[i] + 32; i++ ; } l[ASCIILINESZ]=(char)0; @@ -91,7 +93,9 @@ char * strupc(char * s) memset(l, 0, ASCIILINESZ+1); i=0 ; while (s[i] && i= 'a' && l[i] <= 'z') + l[i] = l[i] - 32; i++ ; } l[ASCIILINESZ]=(char)0; diff --git a/lib/replace/replace.c b/lib/replace/replace.c index 12716ea..7f50ccf 100644 --- a/lib/replace/replace.c +++ b/lib/replace/replace.c @@ -461,12 +461,20 @@ ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset) #endif #ifndef HAVE_STRCASESTR +static char +ascii_toupper (char c) +{ + if (c >= 'a' && c <= 'z') + c = c - 32; + return c; +} + char *rep_strcasestr(const char *haystack, const char *needle) { const char *s; size_t nlen = strlen(needle); for (s=haystack;*s;s++) { - if (toupper(*needle) == toupper(*s) && + if (ascii_toupper(*needle) == ascii_toupper(*s) && strncasecmp(s, needle, nlen) == 0) { return (char *)((uintptr_t)s); } diff --git a/lib/util/charset/charcnv.c b/lib/util/charset/charcnv.c index e9f6ab0..4e46cfc 100644 --- a/lib/util/charset/charcnv.c +++ b/lib/util/charset/charcnv.c @@ -135,21 +135,6 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic, charset_t from, charset_t to) { const char *n1, *n2; - static bool initialised; - - if (initialised == false) { - initialised = true; - -#ifdef LC_ALL - /* 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 - } if (ic->conv_handles[from][to]) { return ic->conv_handles[from][to]; diff --git a/lib/util/charset/codepoints.c b/lib/util/charset/codepoints.c index 8be2051..fe7ea36 100644 --- a/lib/util/charset/codepoints.c +++ b/lib/util/charset/codepoints.c @@ -69,7 +69,9 @@ void load_case_tables(void) _PUBLIC_ codepoint_t toupper_m(codepoint_t val) { if (val < 128) { - return toupper(val); + if (val >= 'a' && val <= 'z') + val -= 32; + return val; } if (upcase_table == NULL) { load_case_tables(); @@ -89,7 +91,9 @@ _PUBLIC_ codepoint_t toupper_m(codepoint_t val) _PUBLIC_ codepoint_t tolower_m(codepoint_t val) { if (val < 128) { - return tolower(val); + if (val >= 'A' && val <= 'Z') + val += 32; + return val; } if (lowcase_table == NULL) { load_case_tables(); diff --git a/lib/util/charset/util_unistr.c b/lib/util/charset/util_unistr.c index 520ce05..5e5edb7 100644 --- a/lib/util/charset/util_unistr.c +++ b/lib/util/charset/util_unistr.c @@ -542,7 +542,8 @@ _PUBLIC_ void strlower_m(char *s) supported multi-byte character sets are ascii-compatible (ie. they match for the first 128 chars) */ while (*s && !(((uint8_t)*s) & 0x80)) { - *s = tolower((uint8_t)*s); + if (*s >= 'A' && *s <= 'Z') + *s = (*s) + 32; s++; } @@ -581,7 +582,8 @@ _PUBLIC_ void strupper_m(char *s) supported multi-byte character sets are ascii-compatible (ie. they match for the first 128 chars) */ while (*s && !(((uint8_t)*s) & 0x80)) { - *s = toupper((uint8_t)*s); + if (*s >= 'a' && *s <= 'z') + *s = (*s) - 32; s++; } diff --git a/lib/util/util.c b/lib/util/util.c index d645f7e..803e9e9 100644 --- a/lib/util/util.c +++ b/lib/util/util.c @@ -42,6 +42,14 @@ #define uwrap_enabled() 0 #endif +static char +ascii_toupper (char c) +{ + if (c >= 'a' && c <= 'z') + c = c - 32; + return c; +} + /** * @file * @brief Misc utility functions @@ -602,12 +610,12 @@ _PUBLIC_ size_t strhex_to_str(char *p, size_t p_len, const char *strhex, size_t } for (; i < strhex_len && strhex[i] != 0; i++) { - if (!(p1 = strchr(hexchars, toupper((unsigned char)strhex[i])))) + if (!(p1 = strchr(hexchars, ascii_toupper((unsigned char)strhex[i])))) break; i++; /* next hex digit */ - if (!(p2 = strchr(hexchars, toupper((unsigned char)strhex[i])))) + if (!(p2 = strchr(hexchars, ascii_toupper((unsigned char)strhex[i])))) break; /* get the two nybbles */ diff --git a/lib/util/util_str.c b/lib/util/util_str.c index 0ea71a8..ba896e7 100644 --- a/lib/util/util_str.c +++ b/lib/util/util_str.c @@ -26,6 +26,14 @@ #undef strncasecmp #undef strcasemp +static char +ascii_toupper (char c) +{ + if (c >= 'a' && c <= 'z') + c = c - 32; + return c; +} + /** * @file * @brief String utilities. @@ -289,7 +297,7 @@ _PUBLIC_ int strwicmp(const char *psz1, const char *psz2) psz1++; while (isspace((int)*psz2)) psz2++; - if (toupper((unsigned char)*psz1) != toupper((unsigned char)*psz2) + if (ascii_toupper((unsigned char)*psz1) != ascii_toupper((unsigned char)*psz2) || *psz1 == '\0' || *psz2 == '\0') break; diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c index 515d96d..f13c37f 100644 --- a/source4/dsdb/common/util.c +++ b/source4/dsdb/common/util.c @@ -2898,6 +2898,22 @@ failed: return NULL; } +static char +ascii_tolower (char c) +{ + if (c >= 'A' && c <= 'Z') + c = c + 32; + return c; +} + +static char +ascii_toupper (char c) +{ + if (c >= 'a' && c <= 'z') + c = c - 32; + return c; +} + /* * Function which generates a "lDAPDisplayName" attribute from a "CN" one. * Algorithm implemented according to MS-ADTS 3.1.1.2.3.4 @@ -2911,10 +2927,10 @@ const char *samdb_cn_to_lDAPDisplayName(TALLOC_CTX *mem_ctx, const char *cn) if (tokens == NULL) return NULL; - /* "tolower()" and "toupper()" should also work properly on 0x00 */ - tokens[0][0] = tolower(tokens[0][0]); + /* "ascii_tolower()" and "ascii_toupper()" should also work properly on 0x00 */ + tokens[0][0] = ascii_tolower(tokens[0][0]); for (i = 1; i < str_list_length((const char **)tokens); i++) - tokens[i][0] = toupper(tokens[i][0]); + tokens[i][0] = ascii_toupper(tokens[i][0]); ret = talloc_strdup(mem_ctx, tokens[0]); for (i = 1; i < str_list_length((const char **)tokens); i++) diff --git a/source4/heimdal/lib/asn1/hash.c b/source4/heimdal/lib/asn1/hash.c index 73b6cf9..35dd885 100644 --- a/source4/heimdal/lib/asn1/hash.c +++ b/source4/heimdal/lib/asn1/hash.c @@ -174,6 +174,14 @@ hashadd(const char *s) return i; } +static char +ascii_toupper (char c) +{ + if (c >= 'a' && c <= 'z') + c = c - 32; + return c; +} + unsigned hashcaseadd(const char *s) { /* Standard hash function */ @@ -182,7 +190,7 @@ hashcaseadd(const char *s) assert(s); for (i = 0; *s; ++s) - i += toupper((unsigned char)*s); + i += ascii_toupper((unsigned char)*s); return i; } diff --git a/source4/heimdal/lib/hcrypto/imath/imath.c b/source4/heimdal/lib/hcrypto/imath/imath.c index 4e47a76..9922b58 100644 --- a/source4/heimdal/lib/hcrypto/imath/imath.c +++ b/source4/heimdal/lib/hcrypto/imath/imath.c @@ -3214,6 +3214,13 @@ STATIC mp_size s_inlen(int len, mp_size r) /* {{{ s_ch2val(c, r) */ +STATIC char ascii_toupper (char c) +{ + if (c >= 'a' && c <= 'z') + c = c - 32; + return c; +} + STATIC int s_ch2val(char c, int r) { int out; @@ -3221,7 +3228,7 @@ STATIC int s_ch2val(char c, int r) if(isdigit((unsigned char) c)) out = c - '0'; else if(r > 10 && isalpha((unsigned char) c)) - out = toupper(c) - 'A' + 10; + out = ascii_toupper(c) - 'A' + 10; else return -1; @@ -3242,7 +3249,7 @@ STATIC char s_val2ch(int v, int caps) char out = (v - 10) + 'a'; if(caps) - return toupper(out); + return ascii_toupper(out); else return out; } diff --git a/source4/heimdal/lib/krb5/crypto.c b/source4/heimdal/lib/krb5/crypto.c index ed87655..20e419a 100644 --- a/source4/heimdal/lib/krb5/crypto.c +++ b/source4/heimdal/lib/krb5/crypto.c @@ -171,6 +171,14 @@ struct evp_schedule { static HEIMDAL_MUTEX crypto_mutex = HEIMDAL_MUTEX_INITIALIZER; +static char +ascii_tolower (char c) +{ + if (c >= 'A' && c <= 'Z') + c = c + 32; + return c; +} + #ifdef HEIM_WEAK_CRYPTO static void krb5_DES_random_key(krb5_context context, @@ -213,7 +221,7 @@ krb5_DES_AFS3_CMU_string_to_key (krb5_data pw, for(i = 0; i < 8; i++) { char c = ((i < pw.length) ? ((char*)pw.data)[i] : 0) ^ ((i < cell.length) ? - tolower(((unsigned char*)cell.data)[i]) : 0); + ascii_tolower(((unsigned char*)cell.data)[i]) : 0); password[i] = c ? c : 'X'; } password[8] = '\0'; @@ -249,7 +257,7 @@ krb5_DES_AFS3_Transarc_string_to_key (krb5_data pw, memcpy(password + pw.length, cell.data, len); for (i = pw.length; i < pw.length + len; ++i) - password[i] = tolower((unsigned char)password[i]); + password[i] = ascii_tolower((unsigned char)password[i]); } passlen = min(sizeof(password), pw.length + cell.length); memcpy(&ivec, "kerberos", 8); diff --git a/source4/heimdal/lib/krb5/keytab_keyfile.c b/source4/heimdal/lib/krb5/keytab_keyfile.c index 54666c7..fd79210 100644 --- a/source4/heimdal/lib/krb5/keytab_keyfile.c +++ b/source4/heimdal/lib/krb5/keytab_keyfile.c @@ -51,6 +51,14 @@ #define AFS_SERVERTHISCELL "/usr/afs/etc/ThisCell" #define AFS_SERVERMAGICKRBCONF "/usr/afs/etc/krb.conf" +static char +ascii_toupper (char c) +{ + if (c >= 'a' && c <= 'z') + c = c - 32; + return c; +} + struct akf_data { uint32_t num_entries; char *filename; @@ -111,7 +119,7 @@ get_cell_and_realm (krb5_context context, struct akf_data *d) } /* uppercase */ for (cp = buf; *cp != '\0'; cp++) - *cp = toupper((unsigned char)*cp); + *cp = ascii_toupper((unsigned char)*cp); d->realm = strdup (buf); if (d->realm == NULL) { diff --git a/source4/heimdal/lib/ntlm/ntlm.c b/source4/heimdal/lib/ntlm/ntlm.c index 71f96bf..e6fd5fe 100644 --- a/source4/heimdal/lib/ntlm/ntlm.c +++ b/source4/heimdal/lib/ntlm/ntlm.c @@ -100,6 +100,14 @@ struct sec_buffer { static const unsigned char ntlmsigature[8] = "NTLMSSP\x00"; +static char +ascii_toupper (char c) +{ + if (c >= 'a' && c <= 'z') + c = c - 32; + return c; +} + /* * */ @@ -150,7 +158,7 @@ ascii2ucs2le(const char *string, int up, struct ntlm_buf *buf) return EINVAL; } if (up) - t = toupper(t); + t = ascii_toupper(t); p[(i * 2) + 0] = t; p[(i * 2) + 1] = 0; } diff --git a/source4/heimdal/lib/roken/hex.c b/source4/heimdal/lib/roken/hex.c index 91590dd..f6e6ea0 100644 --- a/source4/heimdal/lib/roken/hex.c +++ b/source4/heimdal/lib/roken/hex.c @@ -39,11 +39,19 @@ const static char hexchar[] = "0123456789ABCDEF"; +static char +ascii_toupper (char c) +{ + if (c >= 'a' && c <= 'z') + c = c - 32; + return c; +} + static int pos(char c) { const char *p; - c = toupper((unsigned char)c); + c = ascii_toupper((unsigned char)c); for (p = hexchar; *p; p++) if (*p == c) return p - hexchar; diff --git a/source4/heimdal/lib/roken/strlwr.c b/source4/heimdal/lib/roken/strlwr.c index 68bd4ed..58ca720 100644 --- a/source4/heimdal/lib/roken/strlwr.c +++ b/source4/heimdal/lib/roken/strlwr.c @@ -43,8 +43,10 @@ strlwr(char *str) { char *s; - for(s = str; *s; s++) - *s = tolower((unsigned char)*s); + for(s = str; *s; s++) { + if (*s >= 'A' && *s <= 'Z') + *s = (*s) + 32; + } return str; } #endif diff --git a/source4/heimdal/lib/roken/strupr.c b/source4/heimdal/lib/roken/strupr.c index fdff7f4..f110b76 100644 --- a/source4/heimdal/lib/roken/strupr.c +++ b/source4/heimdal/lib/roken/strupr.c @@ -38,13 +38,21 @@ #include "roken.h" #ifndef HAVE_STRUPR +static char +ascii_toupper (char c) +{ + if (c >= 'a' && c <= 'z') + c = c - 32; + return c; +} + ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strupr(char *str) { char *s; for(s = str; *s; s++) - *s = toupper((unsigned char)*s); + *s = ascii_toupper((unsigned char)*s); return str; } #endif diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 2f4454c..6bd9c5d 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -190,6 +190,14 @@ static int ldb_comparison_Boolean(struct ldb_context *ldb, void *mem_ctx, return strncasecmp((char *)v1->data, (char *)v2->data, v1->length); } +static char +ascii_toupper (char c) +{ + if (c >= 'a' && c <= 'z') + c = c - 32; + return c; +} + /* compare two binary blobs @@ -227,7 +235,7 @@ int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, * never appear in multibyte sequences */ if (((unsigned char)s1[0]) & 0x80) goto utf8str; if (((unsigned char)s2[0]) & 0x80) goto utf8str; - if (toupper((unsigned char)*s1) != toupper((unsigned char)*s2)) + if (ascii_toupper((unsigned char)*s1) != ascii_toupper((unsigned char)*s2)) break; if (*s1 == ' ') { while (n1 && s1[0] == s1[1]) { s1++; n1--; } @@ -249,15 +257,15 @@ int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, while (n2 && *s2 == ' ') { s2++; n2--; } } if (n1 == 0 && n2 != 0) { - return -(int)toupper(*s2); + return -(int)ascii_toupper(*s2); } if (n2 == 0 && n1 != 0) { - return (int)toupper(*s1); + return (int)ascii_toupper(*s1); } if (n2 == 0 && n2 == 0) { return 0; } - return (int)toupper(*s1) - (int)toupper(*s2); + return (int)ascii_toupper(*s1) - (int)ascii_toupper(*s2); utf8str: /* no need to recheck from the start, just from the first utf8 char found */ @@ -273,9 +281,9 @@ utf8str: if (ret == 0) { if (n1 == n2) return 0; if (n1 > n2) { - return (int)toupper(s1[n2]); + return (int)ascii_toupper(s1[n2]); } else { - return -(int)toupper(s2[n1]); + return -(int)ascii_toupper(s2[n1]); } } return ret; diff --git a/source4/lib/ldb/common/ldb_utf8.c b/source4/lib/ldb/common/ldb_utf8.c index 73ae71b..3b1a06b 100644 --- a/source4/lib/ldb/common/ldb_utf8.c +++ b/source4/lib/ldb/common/ldb_utf8.c @@ -34,6 +34,13 @@ #include "ldb_private.h" #include "system/locale.h" +static char +ascii_toupper (char c) +{ + if (c >= 'a' && c <= 'z') + c = c - 32; + return c; +} /* this allow the user to pass in a caseless comparison @@ -62,7 +69,7 @@ char *ldb_casefold_default(void *context, void *mem_ctx, const char *s, size_t n return NULL; } for (i=0;ret[i];i++) { - ret[i] = toupper((unsigned char)ret[i]); + ret[i] = ascii_toupper((unsigned char)ret[i]); } return ret; } @@ -118,7 +125,7 @@ char *ldb_attr_casefold(void *mem_ctx, const char *s) return NULL; } for (i = 0; ret[i]; i++) { - ret[i] = toupper((unsigned char)ret[i]); + ret[i] = ascii_toupper((unsigned char)ret[i]); } return ret; } diff --git a/source4/lib/samba3/smbpasswd.c b/source4/lib/samba3/smbpasswd.c index 502f13f..1397ba2 100644 --- a/source4/lib/samba3/smbpasswd.c +++ b/source4/lib/samba3/smbpasswd.c @@ -56,6 +56,14 @@ #include "system/locale.h" #include "lib/samba3/samba3.h" +static char +ascii_toupper (char c) +{ + if (c >= 'a' && c <= 'z') + c = c - 32; + return c; +} + /*! Convert 32 hex characters into a 16 byte array. */ struct samr_Password *smbpasswd_gethexpwd(TALLOC_CTX *mem_ctx, const char *p) @@ -70,8 +78,8 @@ struct samr_Password *smbpasswd_gethexpwd(TALLOC_CTX *mem_ctx, const char *p) for (i = 0; i < (sizeof(pwd->hash) * 2); i += 2) { - hinybble = toupper(p[i]); - lonybble = toupper(p[i + 1]); + hinybble = ascii_toupper(p[i]); + lonybble = ascii_toupper(p[i + 1]); p1 = strchr_m(hexchars, hinybble); p2 = strchr_m(hexchars, lonybble); diff --git a/source4/ntvfs/posix/pvfs_shortname.c b/source4/ntvfs/posix/pvfs_shortname.c index fc1cad1..3d03b9b 100644 --- a/source4/ntvfs/posix/pvfs_shortname.c +++ b/source4/ntvfs/posix/pvfs_shortname.c @@ -406,6 +406,22 @@ static bool is_legal_name(struct pvfs_mangle_context *ctx, const char *name) return true; } +static char +ascii_tolower (char c) +{ + if (c >= 'A' && c <= 'Z') + c = c + 32; + return c; +} + +static char +ascii_toupper (char c) +{ + if (c >= 'a' && c <= 'z') + c = c - 32; + return c; +} + /* the main forward mapping function, which converts a long filename to a 8.3 name @@ -469,7 +485,7 @@ static char *name_map(struct pvfs_mangle_context *ctx, if (! FLAG_CHECK(lead_chars[i], FLAG_ASCII)) { lead_chars[i] = '_'; } - lead_chars[i] = toupper((unsigned char)lead_chars[i]); + lead_chars[i] = ascii_toupper((unsigned char)lead_chars[i]); } for (;imangle_prefix;i++) { lead_chars[i] = '_'; @@ -489,7 +505,7 @@ static char *name_map(struct pvfs_mangle_context *ctx, for (i=1; extension_length < 3 && dot_p[i]; i++) { unsigned char c = dot_p[i]; if (FLAG_CHECK(c, FLAG_ASCII)) { - extension[extension_length++] = toupper(c); + extension[extension_length++] = ascii_toupper(c); } } } @@ -533,7 +549,6 @@ static char *name_map(struct pvfs_mangle_context *ctx, return new_name; } - /* initialise the flags table we allow only a very restricted set of characters as 'ascii' in this @@ -587,10 +602,10 @@ static void init_tables(struct pvfs_mangle_context *ctx) ctx->char_flags[c2] |= FLAG_POSSIBLE2; ctx->char_flags[c3] |= FLAG_POSSIBLE3; ctx->char_flags[c4] |= FLAG_POSSIBLE4; - ctx->char_flags[tolower(c1)] |= FLAG_POSSIBLE1; - ctx->char_flags[tolower(c2)] |= FLAG_POSSIBLE2; - ctx->char_flags[tolower(c3)] |= FLAG_POSSIBLE3; - ctx->char_flags[tolower(c4)] |= FLAG_POSSIBLE4; + ctx->char_flags[ascii_tolower(c1)] |= FLAG_POSSIBLE1; + ctx->char_flags[ascii_tolower(c2)] |= FLAG_POSSIBLE2; + ctx->char_flags[ascii_tolower(c3)] |= FLAG_POSSIBLE3; + ctx->char_flags[ascii_tolower(c4)] |= FLAG_POSSIBLE4; ctx->char_flags[(unsigned char)'.'] |= FLAG_POSSIBLE4; }