summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apache1x/mod_httpauth.c44
-rw-r--r--apache2x/mod_httpauth.c57
2 files changed, 52 insertions, 49 deletions
diff --git a/apache1x/mod_httpauth.c b/apache1x/mod_httpauth.c
index b7023b0..b2d9945 100644
--- a/apache1x/mod_httpauth.c
+++ b/apache1x/mod_httpauth.c
@@ -154,6 +154,19 @@ static const command_rec httpauth_cmds[] =
* Socket handling code
*/
+void disconnect_socket(httpauth_context_t* ctx, server_rec* s)
+{
+ if(ctx->socket != -1)
+ {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, s,
+ "httpauth: disconnecting from daemon");
+
+ ap_pclosesocket(ctx->child_pool, ctx->socket);
+ ctx->socket = -1;
+ errno = 0;
+ }
+}
+
void read_junk(httpauth_context_t* ctx, request_rec* r)
{
char buf[16];
@@ -245,8 +258,8 @@ int read_line(httpauth_context_t* ctx, request_rec* r, char** line)
/* If it's the end of file then return that */
else if(l == 0)
{
- ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
- "httpauth: unexpected end of data from daemon");
+ /* Disconnect from socket quietly so we can reconnect later */
+ disconnect_socket(ctx, r->server);
return -1;
}
@@ -424,19 +437,6 @@ int read_copy_headers(httpauth_context_t* ctx, int ccode, request_rec* r)
return 0;
}
-void disconnect_socket(httpauth_context_t* ctx, server_rec* s)
-{
- if(ctx->socket != -1)
- {
- ap_log_error(APLOG_MARK, APLOG_DEBUG, s,
- "httpauth: disconnecting from daemon");
-
- ap_pclosesocket(ctx->child_pool, ctx->socket);
- ctx->socket = -1;
- errno = 0;
- }
-}
-
int write_data(httpauth_context_t* ctx, server_rec* s, const char* data)
{
int r;
@@ -707,7 +707,8 @@ retry:
read_junk(ctx, r);
/* Send off a request */
- if(write_request(ctx, r) == -1)
+ if(write_request(ctx, r) == -1 ||
+ read_response(ctx, r, &code, &ccode, &details) == -1)
{
/*
* If our connection was closed by httpauthd then this
@@ -718,16 +719,17 @@ retry:
if(ctx->socket == -1 && !retried)
{
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
+ "httpauth: reconnecting to to httpauthd");
retried = 1;
goto retry;
}
- return SERVER_ERROR;
- }
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(errno), r,
+ "httpauth: couldn't send request to httpauthd");
- /* Read a response line */
- if(read_response(ctx, r, &code, &ccode, &details) == -1)
- return SERVER_ERROR;
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
if(code != 200)
{
diff --git a/apache2x/mod_httpauth.c b/apache2x/mod_httpauth.c
index c6d6e56..b225e5b 100644
--- a/apache2x/mod_httpauth.c
+++ b/apache2x/mod_httpauth.c
@@ -155,6 +155,26 @@ static const command_rec httpauth_cmds[] =
* Socket handling code
*/
+static apr_status_t cleanup_socket(void *fdv)
+{
+ close((int)(long)fdv);
+ return OK;
+}
+
+void disconnect_socket(httpauth_context_t* ctx, server_rec* s)
+{
+ if(ctx->socket != -1)
+ {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
+ "httpauth: disconnecting from daemon");
+
+ apr_pool_cleanup_kill(ctx->child_pool, (void*)(long)ctx->socket,
+ cleanup_socket);
+ close(ctx->socket);
+ ctx->socket = -1;
+ }
+}
+
void read_junk(httpauth_context_t* ctx, request_rec* r)
{
char buf[16];
@@ -245,8 +265,8 @@ int read_line(httpauth_context_t* ctx, request_rec* r, char** line)
/* If it's the end of file then return that */
else if(l == 0)
{
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "httpauth: unexpected end of data from daemon");
+ /* Disconnect from socket quietly so we can reconnect later */
+ disconnect_socket(ctx, r->server);
return -1;
}
@@ -423,27 +443,6 @@ int read_copy_headers(httpauth_context_t* ctx, int ccode, request_rec* r)
return 0;
}
-
-static apr_status_t cleanup_socket(void *fdv)
-{
- close((int)(long)fdv);
- return OK;
-}
-
-void disconnect_socket(httpauth_context_t* ctx, server_rec* s)
-{
- if(ctx->socket != -1)
- {
- ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
- "httpauth: disconnecting from daemon");
-
- apr_pool_cleanup_kill(ctx->child_pool, (void*)(long)ctx->socket,
- cleanup_socket);
- close(ctx->socket);
- ctx->socket = -1;
- }
-}
-
int write_data(httpauth_context_t* ctx, server_rec* s, const char* data)
{
int r;
@@ -716,7 +715,8 @@ retry:
read_junk(ctx, r);
/* Send off a request */
- if(write_request(ctx, r) == -1)
+ if(write_request(ctx, r) == -1 ||
+ read_response(ctx, r, &code, &ccode, &details) == -1)
{
/*
* If our connection was closed by httpauthd then this
@@ -727,16 +727,17 @@ retry:
if(ctx->socket == -1 && !retried)
{
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
+ "httpauth: reconnecting to to httpauthd");
retried = 1;
goto retry;
}
- return HTTP_INTERNAL_SERVER_ERROR;
- }
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(errno), r,
+ "httpauth: couldn't send request to httpauthd");
- /* Read a response line */
- if(read_response(ctx, r, &code, &ccode, &details) == -1)
return HTTP_INTERNAL_SERVER_ERROR;
+ }
if(code != 200)
{