]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ntlm_wb: use pipe instead of socketpair when possible
authorDaniel Stenberg <daniel@haxx.se>
Wed, 18 Oct 2023 07:10:30 +0000 (09:10 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 19 Oct 2023 08:20:12 +0000 (10:20 +0200)
Closes #12149

lib/curl_ntlm_wb.c

index aa7bea75e377cf868ac4fd6f91102903197bf76a..0ff0887f63cd7b86050a1f1a1f7ba96d3b5b2e32 100644 (file)
@@ -68,7 +68,9 @@
 
 /* Portable 'sclose_nolog' used only in child process instead of 'sclose'
    to avoid fooling the socket leak detector */
-#if defined(HAVE_CLOSESOCKET)
+#ifdef HAVE_PIPE
+#  define sclose_nolog(x)  close((x))
+#eliif defined(HAVE_CLOSESOCKET)
 #  define sclose_nolog(x)  closesocket((x))
 #elif defined(HAVE_CLOSESOCKET_CAMEL)
 #  define sclose_nolog(x)  CloseSocket((x))
@@ -189,7 +191,7 @@ static CURLcode ntlm_wb_init(struct Curl_easy *data, struct ntlmdata *ntlm,
     goto done;
   }
 
-  if(Curl_socketpair(AF_UNIX, SOCK_STREAM, 0, sockfds)) {
+  if(wakeup_create(sockfds)) {
     failf(data, "Could not open socket pair. errno %d: %s",
           errno, Curl_strerror(errno, buffer, sizeof(buffer)));
     goto done;
@@ -197,8 +199,8 @@ static CURLcode ntlm_wb_init(struct Curl_easy *data, struct ntlmdata *ntlm,
 
   child_pid = fork();
   if(child_pid == -1) {
-    sclose(sockfds[0]);
-    sclose(sockfds[1]);
+    wakeup_close(sockfds[0]);
+    wakeup_close(sockfds[1]);
     failf(data, "Could not fork. errno %d: %s",
           errno, Curl_strerror(errno, buffer, sizeof(buffer)));
     goto done;
@@ -268,7 +270,7 @@ static CURLcode ntlm_wb_response(struct Curl_easy *data, struct ntlmdata *ntlm,
   Curl_dyn_init(&b, MAX_NTLM_WB_RESPONSE);
 
   while(len_in > 0) {
-    ssize_t written = swrite(ntlm->ntlm_auth_hlpr_socket, input, len_in);
+    ssize_t written = wakeup_write(ntlm->ntlm_auth_hlpr_socket, input, len_in);
     if(written == -1) {
       /* Interrupted by a signal, retry it */
       if(errno == EINTR)
@@ -282,7 +284,7 @@ static CURLcode ntlm_wb_response(struct Curl_easy *data, struct ntlmdata *ntlm,
   /* Read one line */
   while(1) {
     ssize_t size =
-      sread(ntlm->ntlm_auth_hlpr_socket, buf, data->set.buffer_size);
+      wakeup_read(ntlm->ntlm_auth_hlpr_socket, buf, data->set.buffer_size);
     if(size == -1) {
       if(errno == EINTR)
         continue;