From: Kern Sibbald Date: Tue, 16 Sep 2003 08:51:39 +0000 (+0000) Subject: Add debug code bnet_server, bnet, authenticated X-Git-Tag: Release-1.32~15 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=688cfb4bb159b43b44c5bcc041c390a5185d00d3;p=bacula%2Fbacula Add debug code bnet_server, bnet, authenticated git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@704 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/lib/bnet.c b/bacula/src/lib/bnet.c index 70e8e3919b..0e04ffa224 100644 --- a/bacula/src/lib/bnet.c +++ b/bacula/src/lib/bnet.c @@ -147,6 +147,7 @@ int32_t bnet_recv(BSOCK *bsock) int32_t nbytes; int32_t pktsiz; + ASSERT(bsock != NULL); mp_chr(bsock->msg)[0] = 0; if (bsock->errors || bsock->terminated) { return BNET_HARDEOF; diff --git a/bacula/src/lib/bnet_server.c b/bacula/src/lib/bnet_server.c index cc6e9a3b50..308ef2c87e 100644 --- a/bacula/src/lib/bnet_server.c +++ b/bacula/src/lib/bnet_server.c @@ -128,19 +128,20 @@ bnet_thread_server(char *bind_addr, int port, int max_clients, workq_t *client_w * Wait for a connection from a client process. */ ready = sockset; - if ((stat = select(sockfd+1, &ready, NULL, NULL, NULL)) < 0) { - if (errno == EINTR || errno == EAGAIN) { - errno = 0; - continue; - } + do { + errno = 0; + stat = select(sockfd+1, &ready, NULL, NULL, NULL); + } while(stat == -1 && (errno == EINTR || errno == EAGAIN)); + if (stat < 0) { close(sockfd); Emsg1(M_FATAL, 0, _("Error in select: %s\n"), strerror(errno)); break; } do { clilen = sizeof(cli_addr); + errno = 0; newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen); - } while (newsockfd < 0 && errno == EINTR); + } while (newsockfd < 0 && (errno == EINTR || errno == EAGAIN)); if (newsockfd < 0) { continue; } @@ -173,9 +174,13 @@ bnet_thread_server(char *bind_addr, int port, int max_clients, workq_t *client_w caller = "unknown client"; } + BSOCK *bs = init_bsock(NULL, newsockfd, "client", caller, port); + if (bs == NULL) { + Jmsg0(NULL, M_ABORT, 0, _("Could not create client BSOCK.\n")); + } + /* Queue client to be served */ - if ((stat = workq_add(client_wq, - (void *)init_bsock(NULL, newsockfd, "client", caller, port), NULL, 0)) != 0) { + if ((stat = workq_add(client_wq, (void *)bs, NULL, 0)) != 0) { V(mutex); Jmsg1(NULL, M_ABORT, 0, _("Could not add job to client queue: ERR=%s\n"), strerror(stat)); } diff --git a/bacula/src/lib/cram-md5.c b/bacula/src/lib/cram-md5.c index 27a2d41a1a..948892dc24 100644 --- a/bacula/src/lib/cram-md5.c +++ b/bacula/src/lib/cram-md5.c @@ -57,7 +57,7 @@ int cram_md5_auth(BSOCK *bs, char *password, int ssl_need) return 0; } - Dmsg1(99, "%s", bs->msg); + Dmsg1(99, "sent challenge: %s", bs->msg); if (bnet_wait_data(bs, 180) <= 0 || bnet_recv(bs) <= 0) { bmicrosleep(5, 0); return 0; @@ -70,6 +70,7 @@ int cram_md5_auth(BSOCK *bs, char *password, int ssl_need) if (ok) { bnet_fsend(bs, "1000 OK auth\n"); } else { + Dmsg1(100, "PW: %s\n", password); bnet_fsend(bs, "1999 Authorization failed.\n"); bmicrosleep(5, 0); } @@ -95,6 +96,7 @@ int cram_md5_get_auth(BSOCK *bs, char *password, int ssl_need) if (sscanf(mp_chr(bs->msg), "auth cram-md5 %s ssl=%d\n", chal, &ssl_has) != 2) { ssl_has = BNET_SSL_NONE; if (sscanf(mp_chr(bs->msg), "auth cram-md5 %s\n", chal) != 1) { + Dmsg1(100, "Cannot scan challenge: %s\n", bs->msg); bmicrosleep(5, 0); return 0; } @@ -106,6 +108,7 @@ int cram_md5_get_auth(BSOCK *bs, char *password, int ssl_need) hmac_md5((uint8_t *)chal, strlen(chal), (uint8_t *)password, strlen(password), hmac); bs->msglen = bin_to_base64(mp_chr(bs->msg), (char *)hmac, 16) + 1; if (!bnet_send(bs)) { + Dmsg0(100, "Send response failed.\n"); return 0; } Dmsg1(99, "sending resp to challenge: %s\n", bs->msg); @@ -116,6 +119,7 @@ int cram_md5_get_auth(BSOCK *bs, char *password, int ssl_need) if (strcmp(mp_chr(bs->msg), "1000 OK auth\n") == 0) { return 1; } + Dmsg1(100, "PW: %s\n", password); bmicrosleep(5, 0); return 0; }