summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2015-07-31 14:40:06 +0200
committerSimon Rettberg2015-07-31 14:40:06 +0200
commit81ea84ca414361a0983a18256f44dcdc75675f4d (patch)
treeebdaf84cb6c43779a906ebf64986e8566d89c4d7
parent[server.c] Pay attention to failed sends, and return error in related functions (diff)
downloadldadp-81ea84ca414361a0983a18256f44dcdc75675f4d.tar.gz
ldadp-81ea84ca414361a0983a18256f44dcdc75675f4d.tar.xz
ldadp-81ea84ca414361a0983a18256f44dcdc75675f4d.zip
Error handling in server.c
-rw-r--r--server.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/server.c b/server.c
index c62afd3..d24af1a 100644
--- a/server.c
+++ b/server.c
@@ -170,6 +170,8 @@ server_t *server_getFromBase(struct string *in)
uint32_t server_searchRequest(server_t *server, struct SearchRequest *req)
{
epoll_server_t * const s = &server->con;
+ if (!server_ensureConnected(server)) return 0;
+ printf("fd: %d, Kill: %d, Bound: %d, idle: %d\n", s->fd, (int)s->kill, (int)s->bound, (int)(time(NULL) - s->lastActive));
if (s->fd != -1 && !s->kill) {
uint32_t msgId = server_searchRequestOnConnection(s, req);
if (msgId != 0) return msgId;
@@ -233,6 +235,7 @@ uint32_t server_tryUserBind(server_t *server, struct string *binddn, struct stri
fmt_ldapbindrequeststring(bufoff, 3, binddn, password);
fmt_ldapmessage(bufoff - headerLen, id, BindRequest, bodyLen);
if (!server_send(con, bufoff - headerLen, bodyLen + headerLen, FALSE)) {
+ printf("[Server] Could not send user bindrequest to server %s\n", server->addr);
server_free(con);
return 0;
}
@@ -270,6 +273,7 @@ void server_free(epoll_server_t *server)
{
proxy_removeServer(server);
server->bound = FALSE;
+ server->kill = FALSE;
if (server->ssl != NULL) {
SSL_free(server->ssl);
server->ssl = NULL;
@@ -299,7 +303,7 @@ static void server_callback(void *data, int haveIn, int haveOut, int doCleanup)
// SSL
if (!server->sslConnected) {
// Still SSL-Connecting
- if (!ssl_connectServer(server)) {
+ if (!ssl_connectServer(server) || doCleanup || server->kill) {
printf("[Proxy] SSL handshake for AD server %s failed.\n", server->serverData->addr);
server_free(server);
return;
@@ -379,6 +383,7 @@ static void server_haveIn(epoll_server_t *server)
BOOL server_send(epoll_server_t *server, const char *buffer, size_t len, const BOOL cork)
{
+ if (server->kill) return FALSE;
if (server->ssl == NULL && server->sbFill == 0 && !cork) {
// Nothing in send buffer, fire away
const int ret = write(server->fd, buffer, len);
@@ -457,9 +462,9 @@ static BOOL server_ensureConnected(server_t *server)
{
epoll_server_t * const con = &server->con;
if (con->fd != -1 && con->lastActive + 120 > time(NULL)) return TRUE;
- if (con->fd != -1) close(con->fd);
- con->bound = FALSE;
- con->sbPos = con->sbFill = 0;
+ if (con->fd != -1) {
+ server_free(con);
+ }
int sock = server_connectInternal(server);
if (sock == -1) {
printf("[Server] Creating socket for shared connection failed.\n");
@@ -492,9 +497,14 @@ static BOOL server_ensureConnected(server_t *server)
con->fd = -1;
return FALSE;
}
+ con->kill = FALSE;
fmt_ldapbindrequest(bufoff, 3, server->bind, server->password);
fmt_ldapmessage(bufoff - headerLen, MSGID_BIND, BindRequest, bodyLen);
- return server_send(con, bufoff - headerLen, bodyLen + headerLen, FALSE);
+ if (!server_send(con, bufoff - headerLen, bodyLen + headerLen, FALSE)) {
+ printf("[Server] Sending bindrequest for shared connection failed for server %s\n", server->addr);
+ return FALSE;
+ }
+ return TRUE;
}
static BOOL server_ensureSendBuffer(epoll_server_t * const s, const size_t len)