[patch] alpha_strcpy for HEAD

Ihar Viarheichyk i.viarheichyk at sam-solutions.net
Tue Jan 15 10:16:28 GMT 2002


Hello.

This is a patch for HEAD to make alpha_strcpy work correcly with
non-latin characters in usernames. It is based one patch I sent some time
ago for 2.2.


-- 
Igor Vergeichik
ICQ 47298730

-------------- next part --------------
diff -urNk.origg samba.HEAD/source/lib/util_str.c.origg samba.HEAD/source/lib/util_str.c
--- samba.HEAD/source/lib/util_str.c.origg	Tue Jan 15 19:38:09 2002
+++ samba.HEAD/source/lib/util_str.c	Tue Jan 15 19:38:57 2002
@@ -436,6 +436,7 @@
 char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength)
 {
 	size_t len, i;
+	smb_ucs2_t *str_ucs, *other_ucs; 
 
 	if (!dest) {
 		DEBUG(0,("ERROR: NULL dest in alpha_strcpy\n"));
@@ -445,24 +446,32 @@
 	if (!src) {
 		*dest = 0;
 		return dest;
-	}  
-
-	len = strlen(src);
-	if (len >= maxlength)
-		len = maxlength - 1;
+	}
+	if(!(str_ucs = acnv_uxu2(src))) {
+		*dest = 0;	
+		return dest;
+	}
+	len = strlen_w(str_ucs);
 
 	if (!other_safe_chars)
 		other_safe_chars = "";
 
+	if(!(other_ucs = acnv_uxu2(other_safe_chars))) {
+		SAFE_FREE(str_ucs);
+		*dest=0;
+		return dest;
+	}	
+
 	for(i = 0; i < len; i++) {
-		int val = (src[i] & 0xff);
-		if(isupper(val) || islower(val) || isdigit(val) || strchr_m(other_safe_chars, val))
-			dest[i] = src[i];
+		if(isupper_w(str_ucs[i]) || islower_w(str_ucs[i]) || isdigit(str_ucs[i]) || strchr_w(other_ucs, str_ucs[i]))
+				;
 		else
-			dest[i] = '_';
+			str_ucs[i] = (smb_ucs2_t)'_';
 	}
+	convert_string(CH_UCS2, CH_UNIX, str_ucs, len*2+2, dest, maxlength);
 
-	dest[i] = '\0';
+	SAFE_FREE(other_ucs);
+	SAFE_FREE(str_ucs);
 
 	return dest;
 }


More information about the samba-technical mailing list