]> granicus.if.org Git - curl/commitdiff
ldap: Fixed Unicode user and password in Win32 bind calls
authorSteve Holme <steve_holme@hotmail.com>
Sat, 3 Jan 2015 20:16:26 +0000 (20:16 +0000)
committerSteve Holme <steve_holme@hotmail.com>
Sun, 4 Jan 2015 01:57:09 +0000 (01:57 +0000)
lib/ldap.c

index b618cd17ce53b9bba0859c47402faf320d539744..e4ce503c50b7bfbf9b2acfc0240e356d789d3762 100644 (file)
@@ -188,8 +188,12 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
 #if defined(CURL_LDAP_WIN) && \
     (defined(USE_WIN32_IDN) || defined(USE_WINDOWS_SSPI))
   TCHAR *host = NULL;
+  TCHAR *user = NULL;
+  TCHAR *passwd = NULL;
 #else
   char *host = NULL;
+  char *user = NULL;
+  char *passwd = NULL;
 #endif
 
   *done = TRUE; /* unconditionally */
@@ -222,8 +226,23 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
 
     goto quit;
   }
+
+  if(conn->bits.user_passwd) {
+    user = Curl_convert_UTF8_to_tchar(conn->user);
+    passwd = Curl_convert_UTF8_to_tchar(conn->passwd);
+    if(!user || !passwd) {
+      result = CURLE_OUT_OF_MEMORY;
+
+      goto quit;
+    }
+  }
 #else
   host = conn->host.name;
+
+  if(conn->bits.user_passwd) {
+    user = conn->user;
+    passwd = conn->passwd;
+  }
 #endif
 
 #ifdef LDAP_OPT_NETWORK_TIMEOUT
@@ -370,15 +389,11 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
   ldap_set_option(server, LDAP_OPT_PROTOCOL_VERSION, &ldap_proto);
 #endif
 
-  rc = ldap_simple_bind_s(server,
-                          conn->bits.user_passwd ? conn->user : NULL,
-                          conn->bits.user_passwd ? conn->passwd : NULL);
+  rc = ldap_simple_bind_s(server, user, passwd);
   if(!ldap_ssl && rc != 0) {
     ldap_proto = LDAP_VERSION2;
     ldap_set_option(server, LDAP_OPT_PROTOCOL_VERSION, &ldap_proto);
-    rc = ldap_simple_bind_s(server,
-                            conn->bits.user_passwd ? conn->user : NULL,
-                            conn->bits.user_passwd ? conn->passwd : NULL);
+    rc = ldap_simple_bind_s(server, user, passwd);
   }
   if(rc != 0) {
     failf(data, "LDAP local: ldap_simple_bind_s %s", ldap_err2string(rc));
@@ -572,6 +587,8 @@ quit:
 
 #if defined(CURL_LDAP_WIN) && \
     (defined(USE_WIN32_IDN) || defined(USE_WINDOWS_SSPI))
+  Curl_unicodefree(passwd);
+  Curl_unicodefree(user);
   Curl_unicodefree(host);
 #endif