From: mike Date: Tue, 14 Feb 2006 19:27:42 +0000 (+0000) Subject: Fix undetected disconnect in cupsGetFd() and related HTTP functions. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=926aa697c78dcffe920d462addc5b5e080c3bf76;p=thirdparty%2Fcups.git Fix undetected disconnect in cupsGetFd() and related HTTP functions. 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 --- diff --git a/cups/getputfile.c b/cups/getputfile.c index 8eddf3f618..12cbb29a3d 100644 --- a/cups/getputfile.c +++ b/cups/getputfile.c @@ -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... diff --git a/cups/http-addrlist.c b/cups/http-addrlist.c index 400b8f9697..ee4e62a730 100644 --- a/cups/http-addrlist.c +++ b/cups/http-addrlist.c @@ -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; } diff --git a/cups/http.c b/cups/http.c index 2fbc735d14..c4f2dde444 100644 --- a/cups/http.c +++ b/cups/http.c @@ -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... */ diff --git a/scheduler/conf.c b/scheduler/conf.c index da157b2acb..dc83a7aaa9 100644 --- a/scheduler/conf.c +++ b/scheduler/conf.c @@ -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);