]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix undetected disconnect in cupsGetFd() and related HTTP functions.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Tue, 14 Feb 2006 19:27:42 +0000 (19:27 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Tue, 14 Feb 2006 19:27:42 +0000 (19:27 +0000)
Fix check_permissions function to validate all of the permission bits
for directories.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@5103 7a7537e8-13f0-0310-91df-b6672ffda945

cups/getputfile.c
cups/http-addrlist.c
cups/http.c
scheduler/conf.c

index 8eddf3f61820aef4705aa994972ce929e3c699a8..12cbb29a3d85a52ca4b4137f5d463208e691ef94 100644 (file)
@@ -260,7 +260,8 @@ cupsPutFd(http_t     *http,         /* I - HTTP connection to server */
           const char *resource,                /* I - Resource name */
          int        fd)                /* I - File descriptor */
 {
-  int          bytes;                  /* Number of bytes read */
+  int          bytes,                  /* Number of bytes read */
+               retries;                /* Number of retries */
   char         buffer[8192];           /* Buffer for file */
   http_status_t        status;                 /* HTTP status from server */
 
@@ -284,6 +285,8 @@ cupsPutFd(http_t     *http,         /* I - HTTP connection to server */
   * Then send PUT requests to the HTTP server...
   */
 
+  retries = 0;
+
   do
   {
     DEBUG_printf(("cupsPutFd: starting attempt, authstring=\"%s\"...\n",
@@ -331,6 +334,26 @@ cupsPutFd(http_t     *http,                /* I - HTTP connection to server */
       while ((status = httpUpdate(http)) == HTTP_CONTINUE);
     }
 
+    if (status == HTTP_ERROR && !retries)
+    {
+      DEBUG_printf(("cupsPutFd: retry on status %d\n", status));
+
+      retries ++;
+
+      /* Flush any error message... */
+      httpFlush(http);
+
+      /* Reconnect... */
+      if (httpReconnect(http))
+      {
+        status = HTTP_ERROR;
+        break;
+      }
+
+      /* Try again... */
+      continue;
+    }
+
     DEBUG_printf(("cupsPutFd: status=%d\n", status));
 
     if (status == HTTP_UNAUTHORIZED)
@@ -377,7 +400,8 @@ cupsPutFd(http_t     *http,         /* I - HTTP connection to server */
     }
 #endif /* HAVE_SSL */
   }
-  while (status == HTTP_UNAUTHORIZED || status == HTTP_UPGRADE_REQUIRED);
+  while (status == HTTP_UNAUTHORIZED || status == HTTP_UPGRADE_REQUIRED ||
+         (status == HTTP_ERROR && retries < 2));
 
  /*
   * See if we actually put the file or an error...
index 400b8f9697129eba29dbb605344fced7e9c07b62..ee4e62a73003fd6ba123fd6257744f4d767dde41 100644 (file)
@@ -128,7 +128,11 @@ httpAddrConnect(
     * Close this socket and move to the next address...
     */
 
+#ifdef WIN32
     closesocket(*sock);
+#else
+    close(*sock);
+#endif /* WIN32 */
 
     addrlist = addrlist->next;
   }
index 2fbc735d147cd831fcdc6a3da8ab0528a7679672..c4f2dde444a19908a8708f2edff5add4e8ee9a01 100644 (file)
@@ -1311,12 +1311,16 @@ httpReconnect(http_t *http)             /* I - HTTP data */
   */
 
   if (http->fd >= 0)
+  {
 #ifdef WIN32
     closesocket(http->fd);
 #else
     close(http->fd);
 #endif /* WIN32 */
 
+    http->fd = -1;
+  }
+
  /*
   * Connect to the server...
   */
index da157b2acb6e8d43edf5bda8d552985e4966656f..dc83a7aaa92e330c831474b848992e9e2be18050 100644 (file)
@@ -1102,7 +1102,7 @@ check_permissions(const char *filename,   /* I - File/directory name */
     }
   }
 
-  if (dir_created || (fileinfo.st_mode & 0777) != mode)
+  if (dir_created || (fileinfo.st_mode & 07777) != mode)
   {
     cupsdLogMessage(CUPSD_LOG_WARN, "Repairing access permissions of \"%s\"", filename);