فهرست منبع

Fix for #157020: convert unicode password to little-endian byte order

David Boreham 20 سال پیش
والد
کامیت
2930910e65
1فایلهای تغییر یافته به همراه16 افزوده شده و 0 حذف شده
  1. 16 0
      ldap/servers/plugins/replication/windows_protocol_util.c

+ 16 - 0
ldap/servers/plugins/replication/windows_protocol_util.c

@@ -700,6 +700,19 @@ windows_release_replica(Private_Repl_Protocol *prp)
 
 }
 
+static void
+to_little_endian_double_bytes(UChar *unicode_password, int32_t unicode_password_length)
+{
+	int32_t i = 0;
+	for (i = 0 ; i < unicode_password_length; i++) 
+	{
+		UChar c = unicode_password[i];
+		char *byte_ptr = (char*)&(unicode_password[i]);
+		byte_ptr[0] = (char)(c & 0xff);
+		byte_ptr[1] = (char)(c >> 8);
+	}
+}
+
 /* this entry had a password, handle it seperately */
 /* http://support.microsoft.com/?kbid=269190 */
 static int
@@ -729,6 +742,9 @@ send_password_modify(Slapi_DN *sdn, char *password, Private_Repl_Protocol *prp)
 				error = U_ZERO_ERROR;
 				u_strFromUTF8(unicode_password, buffer_size, &unicode_password_length, quoted_password, strlen(quoted_password), &error);
 
+				/* As an extra special twist, we need to send the unicode in little-endian order for AD to be happy */
+				to_little_endian_double_bytes(unicode_password, unicode_password_length);
+
 				bv.bv_len = unicode_password_length * sizeof(UChar);
 				bv.bv_val = (char*)unicode_password;