- /* Identify ourselves */
- snprintf(buf, sizeof buf, "NETP %s|%s", config.c_nodename, secret);
- lprintf(CTDL_DEBUG, "<%s\n", buf);
- if (sock_puts(sock, buf) <0) goto bail;
- if (sock_getln(sock, buf, sizeof buf) < 0) goto bail;
- lprintf(CTDL_DEBUG, ">%s\n", buf);
- if (buf[0] != '2') goto bail;
-
- /* At this point we are authenticated. */
- receive_spool(sock, node);
- transmit_spool(sock, node);
+ /* 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);
+ CtdlLogPrintf(CTDL_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);
+ 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);
+ }