]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/network/serv_network.c
Now we name all the private contexts.
[citadel.git] / citadel / modules / network / serv_network.c
index 1165762fcda19c59c25d85153fec3fb25f37e9a4..2e963c82574389572501db1d55e2123b91159bf1 100644 (file)
@@ -521,7 +521,7 @@ void network_deliver_digest(SpoolControl *sc) {
        /* Now submit the message */
        valid = validate_recipients(recps, NULL, 0);
        free(recps);
-       CtdlSubmitMsg(msg, valid, NULL);
+       CtdlSubmitMsg(msg, valid, NULL, 0);
        CtdlFreeMessage(msg);
        free_recipients(valid);
 }
@@ -568,7 +568,7 @@ void network_deliver_list(struct CtdlMessage *msg, SpoolControl *sc) {
        /* Now submit the message */
        valid = validate_recipients(recps, NULL, 0);
        free(recps);
-       CtdlSubmitMsg(msg, valid, NULL);
+       CtdlSubmitMsg(msg, valid, NULL, 0);
        free_recipients(valid);
        /* Do not call CtdlFreeMessage(msg) here; the caller will free it. */
 }
@@ -670,7 +670,7 @@ void network_spool_msg(long msgnum, void *userdata) {
                        CC->redirect_alloc = SIZ;
 
                        safestrncpy(CC->preferred_formats, "text/plain", sizeof CC->preferred_formats);
-                       CtdlOutputPreLoadedMsg(msg, MT_CITADEL, HEADERS_NONE, 0, 0);
+                       CtdlOutputPreLoadedMsg(msg, MT_CITADEL, HEADERS_NONE, 0, 0, 0);
 
                        striplt(CC->redirect_buffer);
                        fprintf(sc->digestfp, "\n%s\n", CC->redirect_buffer);
@@ -736,7 +736,7 @@ void network_spool_msg(long msgnum, void *userdata) {
                                        msg->cm_fields['R'] = strdup(nptr->name);
        
                                        valid = validate_recipients(nptr->name, NULL, 0);
-                                       CtdlSubmitMsg(msg, valid, "");
+                                       CtdlSubmitMsg(msg, valid, "", 0);
                                        free_recipients(valid);
                                }
                        
@@ -1407,7 +1407,7 @@ void network_bounce(struct CtdlMessage *msg, char *reason) {
        if ( (valid == NULL) && IsEmptyStr(force_room) ) {
                strcpy(force_room, config.c_aideroom);
        }
-       CtdlSubmitMsg(msg, valid, force_room);
+       CtdlSubmitMsg(msg, valid, force_room, 0);
 
        /* Clean up */
        if (valid != NULL) free_recipients(valid);
@@ -1583,7 +1583,7 @@ void network_process_buffer(char *buffer, long size) {
        /* save the message into a room */
        if (PerformNetprocHooks(msg, target_room) == 0) {
                msg->cm_flags = CM_SKIP_HOOKS;
-               CtdlSubmitMsg(msg, recp, target_room);
+               CtdlSubmitMsg(msg, recp, target_room, 0);
        }
        CtdlFreeMessage(msg);
        free_recipients(recp);
@@ -1955,6 +1955,8 @@ ABORTUPL:
 void network_poll_node(char *node, char *secret, char *host, char *port) {
        int sock;
        char buf[SIZ];
+       char err_buf[SIZ];
+       char connected_to[SIZ];
 
        if (network_talking_to(node, NTT_CHECK)) return;
        network_talking_to(node, NTT_ADD);
@@ -1973,6 +1975,14 @@ void network_poll_node(char *node, char *secret, char *host, char *port) {
        if (sock_getln(sock, buf, sizeof buf) < 0) goto bail;
        CtdlLogPrintf(CTDL_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);
+               aide_message(err_buf, "IGNet Networking error.");
+       }
+
        /* Identify ourselves */
        snprintf(buf, sizeof buf, "NETP %s|%s", config.c_nodename, secret);
        CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf);
@@ -2075,10 +2085,8 @@ void *network_do_queue(void *args) {
        struct CitContext networkerCC;
 
        /* Give the networker its own private CitContext */
-       memset(&networkerCC, 0, sizeof(struct CitContext));
-       networkerCC.internal_pgm = 1;
-       networkerCC.cs_pid = 0;
-       pthread_setspecific(MyConKey, (void *)&networkerCC );
+       CtdlFillPrivateContext(&networkerCC, "network");
+       citthread_setspecific(MyConKey, (void *)&networkerCC );
 
        /*
         * Run the full set of processing tasks no more frequently
@@ -2188,6 +2196,7 @@ void cmd_netp(char *cmdbuf)
 
        char secret[256];
        char nexthop[256];
+       char err_buf[SIZ];
 
        /* Authenticate */
        extract_token(node, cmdbuf, 0, '|', sizeof node);
@@ -2205,15 +2214,19 @@ void cmd_netp(char *cmdbuf)
        v = is_valid_node(nexthop, secret, node);
 
        if (v != 0) {
-               CtdlLogPrintf(CTDL_WARNING, "Unknown node <%s>\n", node);
+               snprintf (err_buf, sizeof(err_buf), "Unknown node <%s>\n", node);
+               CtdlLogPrintf(CTDL_WARNING, err_buf);
                cprintf("%d authentication failed\n",
                        ERROR + PASSWORD_REQUIRED);
+               aide_message(err_buf, "IGNet Networking.");
                return;
        }
 
        if (strcasecmp(pass, secret)) {
-               CtdlLogPrintf(CTDL_WARNING, "Bad password for network node <%s>", node);
+               snprintf (err_buf, sizeof(err_buf), "Bad password for network node <%s>", node);
+               CtdlLogPrintf(CTDL_WARNING, err_buf);
                cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
+               aide_message(err_buf, "IGNet Networking.");
                return;
        }