- if (sock_getln(sock, buf, sizeof buf) < 0) goto bail;
- CtdlLogPrintf(CTDL_DEBUG, ">%s\n", buf);
-
- /* Identify ourselves */
- snprintf(buf, sizeof buf, "NETP %s|%s", config.c_nodename, secret);
- CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf);
- if (sock_puts(sock, buf) <0) goto bail;
- if (sock_getln(sock, buf, sizeof buf) < 0) goto bail;
- CtdlLogPrintf(CTDL_DEBUG, ">%s\n", buf);
- if (buf[0] != '2') goto bail;
-
- /* At this point we are authenticated. */
- if (!CtdlThreadCheckStop())
- receive_spool(sock, node);
- if (!CtdlThreadCheckStop())
- transmit_spool(sock, node);
-
- sock_puts(sock, "QUIT");
-bail: sock_close(sock);
+ if (sock_getln(&sock, buf, sizeof buf) < 0) goto bail;
+ syslog(LOG_DEBUG, ">%s\n", buf);
+
+ /* Check that the remote is who we think it is and warn the Aide if not */
+ extract_token (connected_to, buf, 1, ' ', sizeof connected_to);
+ if (strcmp(connected_to, node))
+ {
+ snprintf(err_buf, sizeof(err_buf),
+ "Connected to node \"%s\" but I was expecting to connect to node \"%s\".",
+ connected_to, node
+ );
+ syslog(LOG_ERR, "%s\n", err_buf);
+ CtdlAideMessage(err_buf, "Network error");
+ }
+ else {
+ /* We're talking to the correct node. Now identify ourselves. */
+ snprintf(buf, sizeof buf, "NETP %s|%s", config.c_nodename, secret);
+ syslog(LOG_DEBUG, "<%s\n", buf);
+ if (sock_puts(&sock, buf) <0) goto bail;
+ if (sock_getln(&sock, buf, sizeof buf) < 0) goto bail;
+ syslog(LOG_DEBUG, ">%s\n", buf);
+ if (buf[0] != '2') {
+ goto bail;
+ }
+
+ /* At this point we are authenticated. */
+ if (!server_shutting_down)
+ receive_spool(&sock, node);
+ if (!server_shutting_down)
+ transmit_spool(&sock, node);
+ }
+
+ sock_puts(&sock, "QUIT");
+bail:
+ FreeStrBuf(&CCC->SBuf.Buf);
+ FreeStrBuf(&CCC->sMigrateBuf);
+ if (sock != -1)
+ sock_close(sock);