]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/network/serv_network.c
Implemented RFC2919, the 'List-ID' field for mailing
[citadel.git] / citadel / modules / network / serv_network.c
index deb9f8cbb9bc488f09184ae48c032df2d9ea2fa4..b71d95a5f8d81f40454c1f0dd4ceb1556f00d9e8 100644 (file)
@@ -363,7 +363,7 @@ int is_valid_node(char *nexthop, char *secret, char *node) {
 
 
 void cmd_gnet(char *argbuf) {
-       char filename[SIZ];
+       char filename[PATH_MAX];
        char buf[SIZ];
        FILE *fp;
 
@@ -391,8 +391,8 @@ void cmd_gnet(char *argbuf) {
 
 
 void cmd_snet(char *argbuf) {
-       char tempfilename[SIZ];
-       char filename[SIZ];
+       char tempfilename[PATH_MAX];
+       char filename[PATH_MAX];
        char buf[SIZ];
        FILE *fp, *newfp;
 
@@ -415,7 +415,7 @@ void cmd_snet(char *argbuf) {
        }
 
        cprintf("%d %s\n", SEND_LISTING, tempfilename);
-       while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
+       while (client_getln(buf, sizeof buf) >= 0 && strcmp(buf, "000")) {
                fprintf(fp, "%s\n", buf);
        }
        fclose(fp);
@@ -478,6 +478,15 @@ void network_deliver_digest(SpoolControl *sc) {
        msg->cm_fields['F'] = strdup(buf);
        msg->cm_fields['R'] = strdup(buf);
 
+       /* Set the 'List-ID' header */
+       msg->cm_fields['L'] = malloc(1024);
+       snprintf(msg->cm_fields['L'], 1024,
+               "%s <%ld.list-id.%s>",
+               CC->room.QRname,
+               CC->room.QRnumber,
+               config.c_fqdn
+       );
+
        /*
         * Go fetch the contents of the digest
         */
@@ -521,7 +530,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 +577,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. */
 }
@@ -589,7 +598,7 @@ void network_spool_msg(long msgnum, void *userdata) {
        maplist *mptr;
        struct ser_ret sermsg;
        FILE *fp;
-       char filename[SIZ];
+       char filename[PATH_MAX];
        char buf[SIZ];
        int bang = 0;
        int send = 1;
@@ -610,6 +619,18 @@ void network_spool_msg(long msgnum, void *userdata) {
                msg = CtdlFetchMessage(msgnum, 1);
                if (msg != NULL) {
 
+                       /* Set the 'List-ID' header */
+                       if (msg->cm_fields['L'] != NULL) {
+                               free(msg->cm_fields['L']);
+                       }
+                       msg->cm_fields['L'] = malloc(1024);
+                       snprintf(msg->cm_fields['L'], 1024,
+                               "%s <%ld.list-id.%s>",
+                               CC->room.QRname,
+                               CC->room.QRnumber,
+                               config.c_fqdn
+                       );
+
                        /* Prepend "[List name]" to the subject */
                        if (msg->cm_fields['U'] == NULL) {
                                msg->cm_fields['U'] = strdup("(no subject)");
@@ -670,7 +691,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 +757,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);
                                }
                        
@@ -793,10 +814,16 @@ void network_spool_msg(long msgnum, void *userdata) {
                        CtdlLogPrintf(CTDL_DEBUG, "Path is %s\n", msg->cm_fields['P']);
                        bang = num_tokens(msg->cm_fields['P'], '!');
                        if (bang > 1) for (i=0; i<(bang-1); ++i) {
-                               extract_token(buf, msg->cm_fields['P'],
-                                       i, '!', sizeof buf);
+                               extract_token(buf, msg->cm_fields['P'], i, '!', sizeof buf);
+                               CtdlLogPrintf(CTDL_DEBUG, "Compare <%s> to <%s>\n",
+                                       buf, mptr->remote_nodename) ;
                                if (!strcasecmp(buf, mptr->remote_nodename)) {
                                        send = 0;
+                                       CtdlLogPrintf(CTDL_DEBUG, "Not sending to %s\n",
+                                               mptr->remote_nodename);
+                               }
+                               else {
+                                       CtdlLogPrintf(CTDL_DEBUG, "Sending to %s\n", mptr->remote_nodename);
                                }
                        }
 
@@ -1077,7 +1104,7 @@ int is_recipient(SpoolControl *sc, const char *Name)
  */
 void network_spoolout_room(char *room_to_spool) {
        char buf[SIZ];
-       char filename[SIZ];
+       char filename[PATH_MAX];
        SpoolControl *sc;
        int i;
 
@@ -1092,17 +1119,15 @@ void network_spoolout_room(char *room_to_spool) {
        }
 
        assoc_file_name(filename, sizeof filename, &CC->room, ctdl_netcfg_dir);
-
-       CtdlLogPrintf(CTDL_INFO, "Networking started for <%s>\n", CC->room.QRname);
        begin_critical_section(S_NETCONFIGS);
 
        /* Only do net processing for rooms that have netconfigs */
-
        if (!read_spoolcontrol_file(&sc, filename))
        {
                end_critical_section(S_NETCONFIGS);
                return;
        }
+       CtdlLogPrintf(CTDL_INFO, "Networking started for <%s>\n", CC->room.QRname);
 
        /* If there are digest recipients, we have to build a digest */
        if (sc->digestrecps != NULL) {
@@ -1153,7 +1178,7 @@ int network_sync_to(char *target_node) {
        char sc_type[256];
        char sc_node[256];
        char sc_room[256];
-       char filename[256];
+       char filename[PATH_MAX];
        FILE *fp;
 
        /* Grab the configuration line we're looking for */
@@ -1401,7 +1426,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);
@@ -1424,7 +1449,7 @@ void network_process_buffer(char *buffer, long size) {
        char target_room[ROOMNAMELEN];
        struct ser_ret sermsg;
        char *oldpath = NULL;
-       char filename[SIZ];
+       char filename[PATH_MAX];
        FILE *fp;
        char nexthop[SIZ];
        unsigned char firstbyte;
@@ -1577,7 +1602,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);
@@ -1658,7 +1683,7 @@ void network_do_spoolin(void) {
        DIR *dp;
        struct dirent *d;
        struct stat statbuf;
-       char filename[256];
+       char filename[PATH_MAX];
        static time_t last_spoolin_mtime = 0L;
 
        /*
@@ -1700,7 +1725,7 @@ void network_do_spoolin(void) {
 void network_purge_spoolout(void) {
        DIR *dp;
        struct dirent *d;
-       char filename[256];
+       char filename[PATH_MAX];
        char nexthop[256];
        int i;
 
@@ -1949,6 +1974,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);
@@ -1967,6 +1994,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);
@@ -2069,10 +2104,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 );
+       CtdlFillSystemContext(&networkerCC, "network");
+       citthread_setspecific(MyConKey, (void *)&networkerCC );
 
        /*
         * Run the full set of processing tasks no more frequently
@@ -2182,6 +2215,7 @@ void cmd_netp(char *cmdbuf)
 
        char secret[256];
        char nexthop[256];
+       char err_buf[SIZ];
 
        /* Authenticate */
        extract_token(node, cmdbuf, 0, '|', sizeof node);
@@ -2199,15 +2233,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;
        }