]> granicus.if.org Git - curl/commitdiff
http_negotiate_sspi: Use a dynamic buffer for SPN generation
authorSteve Holme <steve_holme@hotmail.com>
Sat, 9 Aug 2014 16:56:51 +0000 (17:56 +0100)
committerSteve Holme <steve_holme@hotmail.com>
Sat, 9 Aug 2014 19:25:08 +0000 (20:25 +0100)
Updated to use a dynamic buffer for the SPN generation via the recently
introduced Curl_sasl_build_spn() function rather than a fixed buffer of
1024 characters, which should have been more than enough, but by using
the new function removes the need for another variable sname to do the
wide character conversion in Unicode builds.

lib/http_negotiate_sspi.c
lib/urldata.h

index a745e9dc2d7b01f3c751bdb4198ac4cb507a7ea8..a986b164be1289b5b036b8131985cbd625774525 100644 (file)
@@ -31,6 +31,7 @@
 #include "rawstr.h"
 #include "warnless.h"
 #include "curl_base64.h"
+#include "curl_sasl.h"
 #include "http_negotiate.h"
 #include "curl_memory.h"
 #include "curl_multibyte.h"
@@ -46,19 +47,16 @@ get_gss_name(struct connectdata *conn, bool proxy,
              struct negotiatedata *neg_ctx)
 {
   const char* service = "HTTP";
-  size_t length;
 
   if(proxy && !conn->proxy.name)
     /* proxy auth requested but no given proxy name, error out! */
     return -1;
 
-  length = strlen(service) + 1 + strlen(proxy ? conn->proxy.name :
-                                        conn->host.name) + 1;
-  if(length + 1 > sizeof(neg_ctx->server_name))
-    return EMSGSIZE;
-
-  snprintf(neg_ctx->server_name, sizeof(neg_ctx->server_name), "%s/%s",
-           service, proxy ? conn->proxy.name : conn->host.name);
+  neg_ctx->server_name = Curl_sasl_build_spn(service,
+                                             proxy ? conn->proxy.name :
+                                                     conn->host.name);
+  if(!neg_ctx->server_name)
+    return -1;
 
   return 0;
 }
@@ -75,7 +73,6 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy,
   SecBuffer         in_sec_buff;
   unsigned long     context_attributes;
   TimeStamp         lifetime;
-  TCHAR             *sname;
   int ret;
   size_t len = 0, input_token_len = 0;
   CURLcode error;
@@ -113,7 +110,7 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy,
     return -1;
   }
 
-  if(!strlen(neg_ctx->server_name)) {
+  if(!neg_ctx->server_name) {
     ret = get_gss_name(conn, proxy, neg_ctx);
     if(ret)
       return ret;
@@ -203,15 +200,11 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy,
     in_sec_buff.cbBuffer   = curlx_uztoul(input_token_len);
   }
 
-  sname = Curl_convert_UTF8_to_tchar(neg_ctx->server_name);
-  if(!sname)
-    return CURLE_OUT_OF_MEMORY;
-
   /* Generate our message */
   neg_ctx->status = s_pSecFn->InitializeSecurityContext(
     neg_ctx->credentials,
     input_token ? neg_ctx->context : NULL,
-    sname,
+    neg_ctx->server_name,
     ISC_REQ_CONFIDENTIALITY,
     0,
     SECURITY_NATIVE_DREP,
@@ -222,7 +215,6 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy,
     &context_attributes,
     &lifetime);
 
-  Curl_unicodefree(sname);
   Curl_safefree(input_token);
 
   if(GSS_ERROR(neg_ctx->status))
@@ -293,6 +285,8 @@ static void cleanup(struct negotiatedata *neg_ctx)
   neg_ctx->max_token_length = 0;
   Curl_safefree(neg_ctx->output_token);
 
+  Curl_safefree(neg_ctx->server_name);
+
   Curl_sspi_free_identity(neg_ctx->p_identity);
   neg_ctx->p_identity = NULL;
 }
index 69f2297ba2de55260a792a48ebe13fb4d39cd5d8..0fbcf74513ccdc5d9ebb66ce1b6a05295b61493b 100644 (file)
@@ -463,7 +463,7 @@ struct negotiatedata {
   CredHandle *credentials;
   SEC_WINNT_AUTH_IDENTITY identity;
   SEC_WINNT_AUTH_IDENTITY *p_identity;
-  char server_name[1024];
+  TCHAR *server_name;
   size_t max_token_length;
   BYTE *output_token;
   size_t output_token_length;