[PATCH] alpha_strcpy
Ihar Viarheichyk
i.viarheichyk at sam-solutions.net
Thu Nov 8 02:03:03 GMT 2001
Hello.
alpha_strcpy function currently does not work with non-ascii characters.
Here is a patch for samba-2.2 which handles non-ascii characters in user
and domain names.
It also fixes small bug in multibyte_to_unicode function.
--
Igor Vergeichik
ICQ 47298730
-------------- next part --------------
--- samba-2.2.orig/source/lib/util_str.c Fri Oct 26 11:18:49 2001
+++ samba-2.2/source/lib/util_str.c Thu Nov 8 11:43:29 2001
@@ -924,6 +924,8 @@
char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength)
{
size_t len, i;
+ size_t buflen;
+ smb_ucs2_t *str_ucs, *other_ucs;
if (!dest) {
DEBUG(0,("ERROR: NULL dest in alpha_strcpy\n"));
@@ -934,23 +936,37 @@
*dest = 0;
return dest;
}
-
- len = strlen(src);
- if (len >= maxlength)
- len = maxlength - 1;
+ /* Get UCS2 version of src string*/
+ buflen=2*strlen(src)+2; /*Must be enough for any charset*/
+ str_ucs = (smb_ucs2_t*)malloc(buflen);
+ if(!str_ucs) {
+ *dest=0;
+ return dest;
+ }
+ unix_to_unicode(str_ucs, src, buflen);
if (!other_safe_chars)
other_safe_chars = "";
+ len = strlen_w(str_ucs);
+ /* Get UCS2 version of other_safe_chars string*/
+ buflen=2*strlen(other_safe_chars)+2;
+ other_ucs = (smb_ucs2_t*)malloc(buflen);
+ if(!other_ucs) {
+ *dest=0;
+ return dest;
+ }
+ unix_to_unicode(other_ucs, other_safe_chars, buflen);
+
+
for(i = 0; i < len; i++) {
- int val = (src[i] & 0xff);
- if(isupper(val) || islower(val) || isdigit(val) || strchr(other_safe_chars, val))
- dest[i] = src[i];
- else
- dest[i] = '_';
+ if(isupper_w(str_ucs[i]) || islower_w(str_ucs[i]) || isdigit_w(str_ucs[i]) || strchr_w(other_ucs, str_ucs[i]));
+ else str_ucs[i] = (smb_ucs2_t)'_'; /*This will work*/
}
+ unicode_to_unix(dest, str_ucs, maxlength);
- dest[i] = '\0';
+ free(other_ucs);
+ free(str_ucs);
return dest;
}
--- samba-2.2.orig/source/lib/util_unistr.c Fri Oct 26 11:18:49 2001
+++ samba-2.2/source/lib/util_unistr.c Thu Nov 8 11:36:10 2001
@@ -735,7 +735,7 @@
dst_len /= sizeof(smb_ucs2_t); /* Convert to smb_ucs2_t units. */
- for(i = 0; (i < (dst_len - 1)) && src[i];) {
+ for(i = 0; (i < (dst_len - 1)) && *src;) {
size_t skip = skip_multibyte_char(*src);
smb_ucs2_t val = (*src & 0xff);
More information about the samba-technical
mailing list