4 * This module handles shared rooms, inter-Citadel mail, and outbound
5 * mailing list processing.
7 * Copyright (C) 2000-2002 by Art Cancro and others.
8 * This code is released under the terms of the GNU General Public License.
10 * ** NOTE ** A word on the S_NETCONFIGS semaphore:
11 * This is a fairly high-level type of critical section. It ensures that no
12 * two threads work on the netconfigs files at the same time. Since we do
13 * so many things inside these, here are the rules:
14 * 1. begin_critical_section(S_NETCONFIGS) *before* begin_ any others.
15 * 2. Do *not* perform any I/O with the client during these sections.
20 * Duration of time (in seconds) after which pending list subscribe/unsubscribe
21 * requests that have not been confirmed will be deleted.
23 #define EXP 259200 /* three days */
34 #include <sys/types.h>
36 #if TIME_WITH_SYS_TIME
37 # include <sys/time.h>
41 # include <sys/time.h>
52 #include "sysdep_decls.h"
53 #include "citserver.h"
56 #include "serv_extensions.h"
63 #include "internet_addressing.h"
64 #include "serv_network.h"
65 #include "clientsocket.h"
72 /* Nonzero while we are doing outbound network processing */
73 static int doing_queue = 0;
76 * When we do network processing, it's accomplished in two passes; one to
77 * gather a list of rooms and one to actually do them. It's ok that rplist
78 * is global; this process *only* runs as part of the housekeeping loop and
79 * therefore only one will run at a time.
81 struct RoomProcList *rplist = NULL;
84 * We build a map of network nodes during processing.
86 struct NetMap *the_netmap = NULL;
87 char *working_ignetcfg = NULL;
90 * Load or refresh the Citadel network (IGnet) configuration for this node.
92 void load_working_ignetcfg(void) {
96 cfg = CtdlGetSysConfig(IGNETCFG);
101 oldcfg = working_ignetcfg;
102 working_ignetcfg = cfg;
103 if (oldcfg != NULL) {
113 * Keep track of what messages to reject
115 struct FilterList *load_filter_list(void) {
116 char *serialized_list = NULL;
119 struct FilterList *newlist = NULL;
120 struct FilterList *nptr;
122 serialized_list = CtdlGetSysConfig(FILTERLIST);
123 if (serialized_list == NULL) return(NULL); /* if null, no entries */
125 /* Use the string tokenizer to grab one line at a time */
126 for (i=0; i<num_tokens(serialized_list, '\n'); ++i) {
127 extract_token(buf, serialized_list, i, '\n');
128 nptr = (struct FilterList *) malloc(sizeof(struct FilterList));
129 extract(nptr->fl_user, buf, 0);
130 striplt(nptr->fl_user);
131 extract(nptr->fl_room, buf, 1);
132 striplt(nptr->fl_room);
133 extract(nptr->fl_node, buf, 2);
134 striplt(nptr->fl_node);
136 /* Cowardly refuse to add an any/any/any entry that would
137 * end up filtering every single message.
139 if (strlen(nptr->fl_user) + strlen(nptr->fl_room)
140 + strlen(nptr->fl_node) == 0) {
144 nptr->next = newlist;
149 free(serialized_list);
154 void free_filter_list(struct FilterList *fl) {
155 if (fl == NULL) return;
156 free_filter_list(fl->next);
163 * Check the use table. This is a list of messages which have recently
164 * arrived on the system. It is maintained and queried to prevent the same
165 * message from being entered into the database multiple times if it happens
166 * to arrive multiple times by accident.
168 int network_usetable(struct CtdlMessage *msg) {
171 struct cdbdata *cdbut;
174 /* Bail out if we can't generate a message ID */
178 if (msg->cm_fields['I'] == NULL) {
181 if (strlen(msg->cm_fields['I']) == 0) {
185 /* Generate the message ID */
186 strcpy(msgid, msg->cm_fields['I']);
187 if (haschar(msgid, '@') == 0) {
189 if (msg->cm_fields['N'] != NULL) {
190 strcat(msgid, msg->cm_fields['N']);
197 cdbut = cdb_fetch(CDB_USETABLE, msgid, strlen(msgid));
203 /* If we got to this point, it's unique: add it. */
204 strcpy(ut.ut_msgid, msgid);
205 ut.ut_timestamp = time(NULL);
206 cdb_store(CDB_USETABLE, msgid, strlen(msgid),
207 &ut, sizeof(struct UseTable) );
213 * Read the network map from its configuration file into memory.
215 void read_network_map(void) {
216 char *serialized_map = NULL;
219 struct NetMap *nmptr;
221 serialized_map = CtdlGetSysConfig(IGNETMAP);
222 if (serialized_map == NULL) return; /* if null, no entries */
224 /* Use the string tokenizer to grab one line at a time */
225 for (i=0; i<num_tokens(serialized_map, '\n'); ++i) {
226 extract_token(buf, serialized_map, i, '\n');
227 nmptr = (struct NetMap *) malloc(sizeof(struct NetMap));
228 extract(nmptr->nodename, buf, 0);
229 nmptr->lastcontact = extract_long(buf, 1);
230 extract(nmptr->nexthop, buf, 2);
231 nmptr->next = the_netmap;
235 free(serialized_map);
240 * Write the network map from memory back to the configuration file.
242 void write_network_map(void) {
243 char *serialized_map = NULL;
244 struct NetMap *nmptr;
246 serialized_map = strdup("");
248 if (the_netmap != NULL) {
249 for (nmptr = the_netmap; nmptr != NULL; nmptr = nmptr->next) {
250 serialized_map = realloc(serialized_map,
251 (strlen(serialized_map)+SIZ) );
252 if (strlen(nmptr->nodename) > 0) {
253 snprintf(&serialized_map[strlen(serialized_map)],
257 (long)nmptr->lastcontact,
263 CtdlPutSysConfig(IGNETMAP, serialized_map);
264 free(serialized_map);
266 /* Now free the list */
267 while (the_netmap != NULL) {
268 nmptr = the_netmap->next;
277 * Check the network map and determine whether the supplied node name is
278 * valid. If it is not a neighbor node, supply the name of a neighbor node
279 * which is the next hop. If it *is* a neighbor node, we also fill in the
282 int is_valid_node(char *nexthop, char *secret, char *node) {
287 struct NetMap *nmptr;
294 * First try the neighbor nodes
296 if (working_ignetcfg == NULL) {
297 lprintf(CTDL_ERR, "working_ignetcfg is NULL!\n");
298 if (nexthop != NULL) {
305 if (nexthop != NULL) {
309 /* Use the string tokenizer to grab one line at a time */
310 for (i=0; i<num_tokens(working_ignetcfg, '\n'); ++i) {
311 extract_token(linebuf, working_ignetcfg, i, '\n');
312 extract(buf, linebuf, 0);
313 if (!strcasecmp(buf, node)) {
314 if (nexthop != NULL) {
317 if (secret != NULL) {
318 extract(secret, linebuf, 1);
325 return(retval); /* yup, it's a direct neighbor */
329 * If we get to this point we have to see if we know the next hop
331 if (the_netmap != NULL) {
332 for (nmptr = the_netmap; nmptr != NULL; nmptr = nmptr->next) {
333 if (!strcasecmp(nmptr->nodename, node)) {
334 if (nexthop != NULL) {
335 strcpy(nexthop, nmptr->nexthop);
343 * If we get to this point, the supplied node name is bogus.
345 lprintf(CTDL_ERR, "Invalid node name <%s>\n", node);
353 void cmd_gnet(char *argbuf) {
358 if (CtdlAccessCheck(ac_room_aide)) return;
359 assoc_file_name(filename, sizeof filename, &CC->room, "netconfigs");
360 cprintf("%d Network settings for room #%ld <%s>\n",
362 CC->room.QRnumber, CC->room.QRname);
364 fp = fopen(filename, "r");
366 while (fgets(buf, sizeof buf, fp) != NULL) {
367 buf[strlen(buf)-1] = 0;
368 cprintf("%s\n", buf);
377 void cmd_snet(char *argbuf) {
378 char tempfilename[SIZ];
385 if (CtdlAccessCheck(ac_room_aide)) return;
386 safestrncpy(tempfilename, tmpnam(NULL), sizeof tempfilename);
387 assoc_file_name(filename, sizeof filename, &CC->room, "netconfigs");
389 fp = fopen(tempfilename, "w");
391 cprintf("%d Cannot open %s: %s\n",
392 ERROR + INTERNAL_ERROR,
397 cprintf("%d %s\n", SEND_LISTING, tempfilename);
398 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
399 fprintf(fp, "%s\n", buf);
403 /* Now copy the temp file to its permanent location
404 * (We use /bin/mv instead of link() because they may be on
405 * different filesystems)
408 snprintf(buf, sizeof buf, "/bin/mv %s %s", tempfilename, filename);
409 begin_critical_section(S_NETCONFIGS);
411 end_critical_section(S_NETCONFIGS);
416 * Spools out one message from the list.
418 void network_spool_msg(long msgnum, void *userdata) {
419 struct SpoolControl *sc;
422 char *newpath = NULL;
424 size_t instr_len = SIZ;
425 struct CtdlMessage *msg = NULL;
426 struct CtdlMessage *imsg;
427 struct namelist *nptr;
428 struct maplist *mptr;
429 struct ser_ret sermsg;
435 int delete_after_send = 0; /* Set to 1 to delete after spooling */
436 long list_msgnum = 0L;
437 int ok_to_participate = 0;
439 sc = (struct SpoolControl *)userdata;
442 * Process mailing list recipients
445 if (sc->listrecps != NULL) {
447 /* First, copy it to the spoolout room */
448 err = CtdlSaveMsgPointerInRoom(SMTP_SPOOLOUT_ROOM, msgnum, 0);
449 if (err != 0) return;
452 * Figure out how big a buffer we need to allocate
454 for (nptr = sc->listrecps; nptr != NULL; nptr = nptr->next) {
455 instr_len = instr_len + strlen(nptr->name);
461 lprintf(CTDL_DEBUG, "Generating delivery instructions\n");
462 instr = malloc(instr_len);
465 "Cannot allocate %ld bytes for instr...\n",
469 snprintf(instr, instr_len,
470 "Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n"
471 "bounceto|postmaster@%s\n" ,
472 SPOOLMIME, msgnum, (long)time(NULL), config.c_fqdn );
474 /* Generate delivery instructions for each recipient */
475 for (nptr = sc->listrecps; nptr != NULL; nptr = nptr->next) {
476 size_t tmp = strlen(instr);
477 snprintf(&instr[tmp], instr_len - tmp,
478 "remote|%s|0||\n", nptr->name);
482 * Generate a message from the instructions
484 imsg = malloc(sizeof(struct CtdlMessage));
485 memset(imsg, 0, sizeof(struct CtdlMessage));
486 imsg->cm_magic = CTDLMESSAGE_MAGIC;
487 imsg->cm_anon_type = MES_NORMAL;
488 imsg->cm_format_type = FMT_RFC822;
489 imsg->cm_fields['A'] = strdup("Citadel");
490 imsg->cm_fields['M'] = instr;
492 /* Save delivery instructions in spoolout room */
493 CtdlSubmitMsg(imsg, NULL, SMTP_SPOOLOUT_ROOM);
494 CtdlFreeMessage(imsg);
498 * Process digest recipients
500 if ((sc->digestrecps != NULL) && (sc->digestfp != NULL)) {
501 fprintf(sc->digestfp, " -----------------------------------"
502 "------------------------------------"
504 CtdlRedirectOutput(sc->digestfp);
505 CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 0);
506 CtdlRedirectOutput(NULL);
507 sc->num_msgs_spooled += 1;
511 * Process client-side list participations for this room
514 if (sc->participates != NULL) {
515 msg = CtdlFetchMessage(msgnum, 1);
518 /* Only send messages which originated on our own Citadel
519 * network, otherwise we'll end up sending the remote
520 * mailing list's messages back to it, which is rude...
522 ok_to_participate = 0;
523 if (msg->cm_fields['N'] != NULL) {
524 if (!strcasecmp(msg->cm_fields['N'], config.c_nodename)) {
525 ok_to_participate = 1;
527 if (is_valid_node(NULL, NULL, msg->cm_fields['N']) == 0) {
528 ok_to_participate = 1;
531 if (ok_to_participate) {
532 if (msg->cm_fields['F'] != NULL) {
533 free(msg->cm_fields['F']);
535 msg->cm_fields['F'] = malloc(SIZ);
536 /* Replace the Internet email address of the actual
537 * author with the email address of the room itself,
538 * so the remote listserv doesn't reject us.
539 * FIXME ... I want to be able to pick any address
541 snprintf(msg->cm_fields['F'], SIZ,
542 "room_%s@%s", CC->room.QRname,
544 for (i=0; i<strlen(msg->cm_fields['F']); ++i) {
545 if (isspace(msg->cm_fields['F'][i])) {
546 msg->cm_fields['F'][i] = '_';
550 /* Now save it and generate delivery instructions */
551 list_msgnum = CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM);
554 * Figure out how big a buffer we need to allocate
556 for (nptr = sc->participates; nptr != NULL; nptr = nptr->next) {
557 instr_len = instr_len + strlen(nptr->name);
563 instr = malloc(instr_len);
566 "Cannot allocate %ld bytes for instr...\n",
570 snprintf(instr, instr_len,
571 "Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n"
572 "bounceto|postmaster@%s\n" ,
573 SPOOLMIME, list_msgnum, (long)time(NULL), config.c_fqdn );
575 /* Generate delivery instructions for each recipient */
576 for (nptr = sc->participates; nptr != NULL; nptr = nptr->next) {
577 size_t tmp = strlen(instr);
578 snprintf(&instr[tmp], instr_len - tmp,
579 "remote|%s|0||\n", nptr->name);
583 * Generate a message from the instructions
585 imsg = malloc(sizeof(struct CtdlMessage));
586 memset(imsg, 0, sizeof(struct CtdlMessage));
587 imsg->cm_magic = CTDLMESSAGE_MAGIC;
588 imsg->cm_anon_type = MES_NORMAL;
589 imsg->cm_format_type = FMT_RFC822;
590 imsg->cm_fields['A'] = strdup("Citadel");
591 imsg->cm_fields['M'] = instr;
593 /* Save delivery instructions in spoolout room */
594 CtdlSubmitMsg(imsg, NULL, SMTP_SPOOLOUT_ROOM);
595 CtdlFreeMessage(imsg);
597 CtdlFreeMessage(msg);
602 * Process IGnet push shares
604 if (sc->ignet_push_shares != NULL) {
606 msg = CtdlFetchMessage(msgnum, 1);
610 /* Prepend our node name to the Path field whenever
611 * sending a message to another IGnet node
613 if (msg->cm_fields['P'] == NULL) {
614 msg->cm_fields['P'] = strdup("username");
616 newpath_len = strlen(msg->cm_fields['P']) +
617 strlen(config.c_nodename) + 2;
618 newpath = malloc(newpath_len);
619 snprintf(newpath, newpath_len, "%s!%s",
620 config.c_nodename, msg->cm_fields['P']);
621 free(msg->cm_fields['P']);
622 msg->cm_fields['P'] = newpath;
625 * Determine if this message is set to be deleted
626 * after sending out on the network
628 if (msg->cm_fields['S'] != NULL) {
629 if (!strcasecmp(msg->cm_fields['S'],
631 delete_after_send = 1;
635 /* Now send it to every node */
636 for (mptr = sc->ignet_push_shares; mptr != NULL;
641 /* Check for valid node name */
642 if (is_valid_node(NULL, NULL, mptr->remote_nodename) != 0) {
643 lprintf(CTDL_ERR, "Invalid node <%s>\n",
644 mptr->remote_nodename);
648 /* Check for split horizon */
649 lprintf(CTDL_DEBUG, "Path is %s\n", msg->cm_fields['P']);
650 bang = num_tokens(msg->cm_fields['P'], '!');
651 if (bang > 1) for (i=0; i<(bang-1); ++i) {
652 extract_token(buf, msg->cm_fields['P'],
654 if (!strcasecmp(buf, mptr->remote_nodename)) {
659 /* Send the message */
663 * Force the message to appear in the correct room
664 * on the far end by setting the C field correctly
666 if (msg->cm_fields['C'] != NULL) {
667 free(msg->cm_fields['C']);
669 if (strlen(mptr->remote_roomname) > 0) {
670 msg->cm_fields['C'] = strdup(mptr->remote_roomname);
673 msg->cm_fields['C'] = strdup(CC->room.QRname);
676 /* serialize it for transmission */
677 serialize_message(&sermsg, msg);
679 /* write it to the spool file */
680 snprintf(filename, sizeof filename,
681 "./network/spoolout/%s",
682 mptr->remote_nodename);
683 fp = fopen(filename, "ab");
690 /* free the serialized version */
694 CtdlFreeMessage(msg);
698 /* update lastsent */
699 sc->lastsent = msgnum;
701 /* Delete this message if delete-after-send is set */
702 if (delete_after_send) {
703 CtdlDeleteMessages(CC->room.QRname, msgnum, "");
710 * Deliver digest messages
712 void network_deliver_digest(struct SpoolControl *sc) {
715 struct CtdlMessage *msg;
719 size_t instr_len = SIZ;
720 struct CtdlMessage *imsg;
721 struct namelist *nptr;
723 if (sc->num_msgs_spooled < 1) {
724 fclose(sc->digestfp);
729 msg = malloc(sizeof(struct CtdlMessage));
730 memset(msg, 0, sizeof(struct CtdlMessage));
731 msg->cm_magic = CTDLMESSAGE_MAGIC;
732 msg->cm_format_type = FMT_RFC822;
733 msg->cm_anon_type = MES_NORMAL;
735 sprintf(buf, "%ld", time(NULL));
736 msg->cm_fields['T'] = strdup(buf);
737 msg->cm_fields['A'] = strdup(CC->room.QRname);
738 msg->cm_fields['U'] = strdup(CC->room.QRname);
739 sprintf(buf, "room_%s@%s", CC->room.QRname, config.c_fqdn);
740 for (i=0; i<strlen(buf); ++i) {
741 if (isspace(buf[i])) buf[i]='_';
742 buf[i] = tolower(buf[i]);
744 msg->cm_fields['F'] = strdup(buf);
746 fseek(sc->digestfp, 0L, SEEK_END);
747 msglen = ftell(sc->digestfp);
749 msg->cm_fields['M'] = malloc(msglen + 1);
750 fseek(sc->digestfp, 0L, SEEK_SET);
751 fread(msg->cm_fields['M'], (size_t)msglen, 1, sc->digestfp);
752 msg->cm_fields['M'][msglen] = 0;
754 fclose(sc->digestfp);
757 msgnum = CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM);
758 CtdlFreeMessage(msg);
760 /* Now generate the delivery instructions */
763 * Figure out how big a buffer we need to allocate
765 for (nptr = sc->digestrecps; nptr != NULL; nptr = nptr->next) {
766 instr_len = instr_len + strlen(nptr->name);
772 lprintf(CTDL_DEBUG, "Generating delivery instructions\n");
773 instr = malloc(instr_len);
775 lprintf(CTDL_EMERG, "Cannot allocate %ld bytes for instr...\n",
779 snprintf(instr, instr_len,
780 "Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n"
781 "bounceto|postmaster@%s\n" ,
782 SPOOLMIME, msgnum, (long)time(NULL), config.c_fqdn );
784 /* Generate delivery instructions for each recipient */
785 for (nptr = sc->digestrecps; nptr != NULL; nptr = nptr->next) {
786 size_t tmp = strlen(instr);
787 snprintf(&instr[tmp], instr_len - tmp,
788 "remote|%s|0||\n", nptr->name);
792 * Generate a message from the instructions
794 imsg = malloc(sizeof(struct CtdlMessage));
795 memset(imsg, 0, sizeof(struct CtdlMessage));
796 imsg->cm_magic = CTDLMESSAGE_MAGIC;
797 imsg->cm_anon_type = MES_NORMAL;
798 imsg->cm_format_type = FMT_RFC822;
799 imsg->cm_fields['A'] = strdup("Citadel");
800 imsg->cm_fields['M'] = instr;
802 /* Save delivery instructions in spoolout room */
803 CtdlSubmitMsg(imsg, NULL, SMTP_SPOOLOUT_ROOM);
804 CtdlFreeMessage(imsg);
809 * Batch up and send all outbound traffic from the current room
811 void network_spoolout_room(char *room_to_spool) {
819 struct SpoolControl sc;
820 struct namelist *nptr = NULL;
821 struct maplist *mptr = NULL;
824 int skipthisline = 0;
827 if (getroom(&CC->room, room_to_spool) != 0) {
828 lprintf(CTDL_CRIT, "ERROR: cannot load <%s>\n", room_to_spool);
832 memset(&sc, 0, sizeof(struct SpoolControl));
833 assoc_file_name(filename, sizeof filename, &CC->room, "netconfigs");
835 begin_critical_section(S_NETCONFIGS);
837 fp = fopen(filename, "r");
839 end_critical_section(S_NETCONFIGS);
843 lprintf(CTDL_INFO, "Networking started for <%s>\n", CC->room.QRname);
845 while (fgets(buf, sizeof buf, fp) != NULL) {
846 buf[strlen(buf)-1] = 0;
848 extract(instr, buf, 0);
849 if (!strcasecmp(instr, "lastsent")) {
850 sc.lastsent = extract_long(buf, 1);
852 else if (!strcasecmp(instr, "listrecp")) {
853 nptr = (struct namelist *)
854 malloc(sizeof(struct namelist));
855 nptr->next = sc.listrecps;
856 extract(nptr->name, buf, 1);
859 else if (!strcasecmp(instr, "participate")) {
860 nptr = (struct namelist *)
861 malloc(sizeof(struct namelist));
862 nptr->next = sc.participates;
863 extract(nptr->name, buf, 1);
864 sc.participates = nptr;
866 else if (!strcasecmp(instr, "digestrecp")) {
867 nptr = (struct namelist *)
868 malloc(sizeof(struct namelist));
869 nptr->next = sc.digestrecps;
870 extract(nptr->name, buf, 1);
871 sc.digestrecps = nptr;
873 else if (!strcasecmp(instr, "ignet_push_share")) {
874 /* by checking each node's validity, we automatically
875 * purge nodes which do not exist from room network
876 * configurations at this time.
878 extract(nodename, buf, 1);
879 extract(roomname, buf, 2);
880 strcpy(nexthop, "xxx");
881 if (is_valid_node(nexthop, NULL, nodename) == 0) {
882 if (strlen(nexthop) == 0) {
883 mptr = (struct maplist *)
884 malloc(sizeof(struct maplist));
885 mptr->next = sc.ignet_push_shares;
886 strcpy(mptr->remote_nodename, nodename);
887 strcpy(mptr->remote_roomname, roomname);
888 sc.ignet_push_shares = mptr;
893 /* Preserve 'other' lines ... *unless* they happen to
894 * be subscribe/unsubscribe pendings with expired
898 if (!strncasecmp(buf, "subpending|", 11)) {
899 if (time(NULL) - extract_long(buf, 4) > EXP) {
903 if (!strncasecmp(buf, "unsubpending|", 13)) {
904 if (time(NULL) - extract_long(buf, 3) > EXP) {
909 if (skipthisline == 0) {
910 linesize = strlen(buf);
911 sc.misc = realloc(sc.misc,
912 (miscsize + linesize + 2) );
913 sprintf(&sc.misc[miscsize], "%s\n", buf);
914 miscsize = miscsize + linesize + 1;
922 /* If there are digest recipients, we have to build a digest */
923 if (sc.digestrecps != NULL) {
924 sc.digestfp = tmpfile();
925 fprintf(sc.digestfp, "Content-type: text/plain\n\n");
928 /* Do something useful */
929 CtdlForEachMessage(MSGS_GT, sc.lastsent, NULL, NULL,
930 network_spool_msg, &sc);
932 /* If we wrote a digest, deliver it and then close it */
933 snprintf(buf, sizeof buf, "room_%s@%s",
934 CC->room.QRname, config.c_fqdn);
935 for (i=0; i<strlen(buf); ++i) {
936 buf[i] = tolower(buf[i]);
937 if (isspace(buf[i])) buf[i] = '_';
939 if (sc.digestfp != NULL) {
940 fprintf(sc.digestfp, " -----------------------------------"
941 "------------------------------------"
943 "You are subscribed to the '%s' "
945 "To post to the list: %s\n",
948 network_deliver_digest(&sc); /* deliver and close */
951 /* Now rewrite the config file */
952 fp = fopen(filename, "w");
954 lprintf(CTDL_CRIT, "ERROR: cannot open %s: %s\n",
955 filename, strerror(errno));
958 fprintf(fp, "lastsent|%ld\n", sc.lastsent);
960 /* Write out the listrecps while freeing from memory at the
961 * same time. Am I clever or what? :)
963 while (sc.listrecps != NULL) {
964 fprintf(fp, "listrecp|%s\n", sc.listrecps->name);
965 nptr = sc.listrecps->next;
969 /* Do the same for digestrecps */
970 while (sc.digestrecps != NULL) {
971 fprintf(fp, "digestrecp|%s\n", sc.digestrecps->name);
972 nptr = sc.digestrecps->next;
973 free(sc.digestrecps);
974 sc.digestrecps = nptr;
976 /* Do the same for participates */
977 while (sc.participates != NULL) {
978 fprintf(fp, "participate|%s\n", sc.participates->name);
979 nptr = sc.participates->next;
980 free(sc.participates);
981 sc.participates = nptr;
983 while (sc.ignet_push_shares != NULL) {
984 /* by checking each node's validity, we automatically
985 * purge nodes which do not exist from room network
986 * configurations at this time.
988 if (is_valid_node(NULL, NULL, sc.ignet_push_shares->remote_nodename) == 0) {
990 fprintf(fp, "ignet_push_share|%s",
991 sc.ignet_push_shares->remote_nodename);
992 if (strlen(sc.ignet_push_shares->remote_roomname) > 0) {
993 fprintf(fp, "|%s", sc.ignet_push_shares->remote_roomname);
996 mptr = sc.ignet_push_shares->next;
997 free(sc.ignet_push_shares);
998 sc.ignet_push_shares = mptr;
1000 if (sc.misc != NULL) {
1001 fwrite(sc.misc, strlen(sc.misc), 1, fp);
1007 end_critical_section(S_NETCONFIGS);
1013 * Send the *entire* contents of the current room to one specific network node,
1014 * ignoring anything we know about which messages have already undergone
1015 * network processing. This can be used to bring a new node into sync.
1017 int network_sync_to(char *target_node) {
1018 struct SpoolControl sc;
1019 int num_spooled = 0;
1028 /* Grab the configuration line we're looking for */
1029 assoc_file_name(filename, sizeof filename, &CC->room, "netconfigs");
1030 begin_critical_section(S_NETCONFIGS);
1031 fp = fopen(filename, "r");
1033 end_critical_section(S_NETCONFIGS);
1036 while (fgets(buf, sizeof buf, fp) != NULL) {
1037 buf[strlen(buf)-1] = 0;
1038 extract(sc_type, buf, 0);
1039 extract(sc_node, buf, 1);
1040 extract(sc_room, buf, 2);
1041 if ( (!strcasecmp(sc_type, "ignet_push_share"))
1042 && (!strcasecmp(sc_node, target_node)) ) {
1045 /* Concise syntax because we don't need a full linked-list */
1046 memset(&sc, 0, sizeof(struct SpoolControl));
1047 sc.ignet_push_shares = (struct maplist *)
1048 malloc(sizeof(struct maplist));
1049 sc.ignet_push_shares->next = NULL;
1050 safestrncpy(sc.ignet_push_shares->remote_nodename,
1052 sizeof sc.ignet_push_shares->remote_nodename);
1053 safestrncpy(sc.ignet_push_shares->remote_roomname,
1055 sizeof sc.ignet_push_shares->remote_roomname);
1059 end_critical_section(S_NETCONFIGS);
1061 if (!found_node) return(-1);
1063 /* Send ALL messages */
1064 num_spooled = CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL,
1065 network_spool_msg, &sc);
1067 /* Concise cleanup because we know there's only one node in the sc */
1068 free(sc.ignet_push_shares);
1070 lprintf(CTDL_NOTICE, "Synchronized %d messages to <%s>\n",
1071 num_spooled, target_node);
1072 return(num_spooled);
1077 * Implements the NSYN command
1079 void cmd_nsyn(char *argbuf) {
1081 char target_node[SIZ];
1083 if (CtdlAccessCheck(ac_aide)) return;
1085 extract(target_node, argbuf, 0);
1086 num_spooled = network_sync_to(target_node);
1087 if (num_spooled >= 0) {
1088 cprintf("%d Spooled %d messages.\n", CIT_OK, num_spooled);
1091 cprintf("%d No such room/node share exists.\n",
1092 ERROR + ROOM_NOT_FOUND);
1099 * Batch up and send all outbound traffic from the current room
1101 void network_queue_room(struct ctdlroom *qrbuf, void *data) {
1102 struct RoomProcList *ptr;
1104 ptr = (struct RoomProcList *) malloc(sizeof (struct RoomProcList));
1105 if (ptr == NULL) return;
1107 safestrncpy(ptr->name, qrbuf->QRname, sizeof ptr->name);
1114 * Learn topology from path fields
1116 void network_learn_topology(char *node, char *path) {
1118 struct NetMap *nmptr;
1120 strcpy(nexthop, "");
1122 if (num_tokens(path, '!') < 3) return;
1123 for (nmptr = the_netmap; nmptr != NULL; nmptr = nmptr->next) {
1124 if (!strcasecmp(nmptr->nodename, node)) {
1125 extract_token(nmptr->nexthop, path, 0, '!');
1126 nmptr->lastcontact = time(NULL);
1131 /* If we got here then it's not in the map, so add it. */
1132 nmptr = (struct NetMap *) malloc(sizeof (struct NetMap));
1133 strcpy(nmptr->nodename, node);
1134 nmptr->lastcontact = time(NULL);
1135 extract_token(nmptr->nexthop, path, 0, '!');
1136 nmptr->next = the_netmap;
1144 * Bounce a message back to the sender
1146 void network_bounce(struct CtdlMessage *msg, char *reason) {
1147 char *oldpath = NULL;
1149 char bouncesource[SIZ];
1150 char recipient[SIZ];
1151 struct recptypes *valid = NULL;
1152 char force_room[ROOMNAMELEN];
1153 static int serialnum = 0;
1156 lprintf(CTDL_DEBUG, "entering network_bounce()\n");
1158 if (msg == NULL) return;
1160 snprintf(bouncesource, sizeof bouncesource, "%s@%s", BOUNCESOURCE, config.c_nodename);
1163 * Give it a fresh message ID
1165 if (msg->cm_fields['I'] != NULL) {
1166 free(msg->cm_fields['I']);
1168 snprintf(buf, sizeof buf, "%ld.%04lx.%04x@%s",
1169 (long)time(NULL), (long)getpid(), ++serialnum, config.c_fqdn);
1170 msg->cm_fields['I'] = strdup(buf);
1173 * FIXME ... right now we're just sending a bounce; we really want to
1174 * include the text of the bounced message.
1176 if (msg->cm_fields['M'] != NULL) {
1177 free(msg->cm_fields['M']);
1179 msg->cm_fields['M'] = strdup(reason);
1180 msg->cm_format_type = 0;
1183 * Turn the message around
1185 if (msg->cm_fields['R'] == NULL) {
1186 free(msg->cm_fields['R']);
1189 if (msg->cm_fields['D'] == NULL) {
1190 free(msg->cm_fields['D']);
1193 snprintf(recipient, sizeof recipient, "%s@%s",
1194 msg->cm_fields['A'], msg->cm_fields['N']);
1196 if (msg->cm_fields['A'] == NULL) {
1197 free(msg->cm_fields['A']);
1200 if (msg->cm_fields['N'] == NULL) {
1201 free(msg->cm_fields['N']);
1204 msg->cm_fields['A'] = strdup(BOUNCESOURCE);
1205 msg->cm_fields['N'] = strdup(config.c_nodename);
1208 /* prepend our node to the path */
1209 if (msg->cm_fields['P'] != NULL) {
1210 oldpath = msg->cm_fields['P'];
1211 msg->cm_fields['P'] = NULL;
1214 oldpath = strdup("unknown_user");
1216 size = strlen(oldpath) + SIZ;
1217 msg->cm_fields['P'] = malloc(size);
1218 snprintf(msg->cm_fields['P'], size, "%s!%s", config.c_nodename, oldpath);
1221 /* Now submit the message */
1222 valid = validate_recipients(recipient);
1223 if (valid != NULL) if (valid->num_error > 0) {
1227 if ( (valid == NULL) || (!strcasecmp(recipient, bouncesource)) ) {
1228 strcpy(force_room, config.c_aideroom);
1231 strcpy(force_room, "");
1233 if ( (valid == NULL) && (strlen(force_room) == 0) ) {
1234 strcpy(force_room, config.c_aideroom);
1236 CtdlSubmitMsg(msg, valid, force_room);
1239 if (valid != NULL) free(valid);
1240 CtdlFreeMessage(msg);
1241 lprintf(CTDL_DEBUG, "leaving network_bounce()\n");
1248 * Process a buffer containing a single message from a single file
1249 * from the inbound queue
1251 void network_process_buffer(char *buffer, long size) {
1252 struct CtdlMessage *msg;
1255 struct recptypes *recp = NULL;
1256 char target_room[ROOMNAMELEN];
1257 struct ser_ret sermsg;
1258 char *oldpath = NULL;
1262 unsigned char firstbyte;
1263 unsigned char lastbyte;
1265 /* Validate just a little bit. First byte should be FF and
1266 * last byte should be 00.
1268 memcpy(&firstbyte, &buffer[0], 1);
1269 memcpy(&lastbyte, &buffer[size-1], 1);
1270 if ( (firstbyte != 255) || (lastbyte != 0) ) {
1271 lprintf(CTDL_ERR, "Corrupt message! Ignoring.\n");
1275 /* Set default target room to trash */
1276 strcpy(target_room, TWITROOM);
1278 /* Load the message into memory */
1279 msg = (struct CtdlMessage *) malloc(sizeof(struct CtdlMessage));
1280 memset(msg, 0, sizeof(struct CtdlMessage));
1281 msg->cm_magic = CTDLMESSAGE_MAGIC;
1282 msg->cm_anon_type = buffer[1];
1283 msg->cm_format_type = buffer[2];
1285 for (pos = 3; pos < size; ++pos) {
1286 field = buffer[pos];
1287 msg->cm_fields[field] = strdup(&buffer[pos+1]);
1288 pos = pos + strlen(&buffer[(int)pos]);
1291 /* Check for message routing */
1292 if (msg->cm_fields['D'] != NULL) {
1293 if (strcasecmp(msg->cm_fields['D'], config.c_nodename)) {
1295 /* route the message */
1296 strcpy(nexthop, "");
1297 if (is_valid_node(nexthop, NULL,
1298 msg->cm_fields['D']) == 0) {
1300 /* prepend our node to the path */
1301 if (msg->cm_fields['P'] != NULL) {
1302 oldpath = msg->cm_fields['P'];
1303 msg->cm_fields['P'] = NULL;
1306 oldpath = strdup("unknown_user");
1308 size = strlen(oldpath) + SIZ;
1309 msg->cm_fields['P'] = malloc(size);
1310 snprintf(msg->cm_fields['P'], size, "%s!%s",
1311 config.c_nodename, oldpath);
1314 /* serialize the message */
1315 serialize_message(&sermsg, msg);
1318 if (strlen(nexthop) == 0) {
1319 strcpy(nexthop, msg->cm_fields['D']);
1321 snprintf(filename, sizeof filename,
1322 "./network/spoolout/%s", nexthop);
1323 fp = fopen(filename, "ab");
1330 CtdlFreeMessage(msg);
1334 else { /* invalid destination node name */
1337 "A message you sent could not be delivered due to an invalid destination node"
1338 " name. Please check the address and try sending the message again.\n");
1347 * Check to see if we already have a copy of this message, and
1348 * abort its processing if so. (We used to post a warning to Aide>
1349 * every time this happened, but the network is now so densely
1350 * connected that it's inevitable.)
1352 if (network_usetable(msg) != 0) {
1356 /* Learn network topology from the path */
1357 if ((msg->cm_fields['N'] != NULL) && (msg->cm_fields['P'] != NULL)) {
1358 network_learn_topology(msg->cm_fields['N'],
1359 msg->cm_fields['P']);
1362 /* Is the sending node giving us a very persuasive suggestion about
1363 * which room this message should be saved in? If so, go with that.
1365 if (msg->cm_fields['C'] != NULL) {
1366 safestrncpy(target_room,
1367 msg->cm_fields['C'],
1368 sizeof target_room);
1371 /* Otherwise, does it have a recipient? If so, validate it... */
1372 else if (msg->cm_fields['R'] != NULL) {
1373 recp = validate_recipients(msg->cm_fields['R']);
1374 if (recp != NULL) if (recp->num_error > 0) {
1376 "A message you sent could not be delivered due to an invalid address.\n"
1377 "Please check the address and try sending the message again.\n");
1382 strcpy(target_room, ""); /* no target room if mail */
1385 /* Our last shot at finding a home for this message is to see if
1386 * it has the O field (Originating room) set.
1388 else if (msg->cm_fields['O'] != NULL) {
1389 safestrncpy(target_room,
1390 msg->cm_fields['O'],
1391 sizeof target_room);
1394 /* Strip out fields that are only relevant during transit */
1395 if (msg->cm_fields['D'] != NULL) {
1396 free(msg->cm_fields['D']);
1397 msg->cm_fields['D'] = NULL;
1399 if (msg->cm_fields['C'] != NULL) {
1400 free(msg->cm_fields['C']);
1401 msg->cm_fields['C'] = NULL;
1404 /* save the message into a room */
1405 if (PerformNetprocHooks(msg, target_room) == 0) {
1406 msg->cm_flags = CM_SKIP_HOOKS;
1407 CtdlSubmitMsg(msg, recp, target_room);
1409 CtdlFreeMessage(msg);
1415 * Process a single message from a single file from the inbound queue
1417 void network_process_message(FILE *fp, long msgstart, long msgend) {
1422 hold_pos = ftell(fp);
1423 size = msgend - msgstart + 1;
1424 buffer = malloc(size);
1425 if (buffer != NULL) {
1426 fseek(fp, msgstart, SEEK_SET);
1427 fread(buffer, size, 1, fp);
1428 network_process_buffer(buffer, size);
1432 fseek(fp, hold_pos, SEEK_SET);
1437 * Process a single file from the inbound queue
1439 void network_process_file(char *filename) {
1441 long msgstart = (-1L);
1442 long msgend = (-1L);
1447 fp = fopen(filename, "rb");
1449 lprintf(CTDL_CRIT, "Error opening %s: %s\n",
1450 filename, strerror(errno));
1454 lprintf(CTDL_INFO, "network: processing <%s>\n", filename);
1456 /* Look for messages in the data stream and break them out */
1457 while (ch = getc(fp), ch >= 0) {
1460 if (msgstart >= 0L) {
1461 msgend = msgcur - 1;
1462 network_process_message(fp, msgstart, msgend);
1470 msgend = msgcur - 1;
1471 if (msgstart >= 0L) {
1472 network_process_message(fp, msgstart, msgend);
1481 * Process anything in the inbound queue
1483 void network_do_spoolin(void) {
1488 dp = opendir("./network/spoolin");
1489 if (dp == NULL) return;
1491 while (d = readdir(dp), d != NULL) {
1492 snprintf(filename, sizeof filename,
1493 "./network/spoolin/%s", d->d_name);
1494 network_process_file(filename);
1503 * Delete any files in the outbound queue that were intended
1504 * to be sent to nodes which no longer exist.
1506 void network_purge_spoolout(void) {
1513 dp = opendir("./network/spoolout");
1514 if (dp == NULL) return;
1516 while (d = readdir(dp), d != NULL) {
1517 if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
1519 snprintf(filename, sizeof filename,
1520 "./network/spoolout/%s", d->d_name);
1522 strcpy(nexthop, "");
1523 i = is_valid_node(nexthop, NULL, d->d_name);
1525 if ( (i != 0) || (strlen(nexthop) > 0) ) {
1537 * receive network spool from the remote system
1539 void receive_spool(int sock, char *remote_nodename) {
1541 long bytes_received;
1543 static char pbuf[IGNET_PACKET_SIZE];
1544 char tempfilename[PATH_MAX];
1548 strcpy(tempfilename, tmpnam(NULL));
1549 if (sock_puts(sock, "NDOP") < 0) return;
1550 if (sock_gets(sock, buf) < 0) return;
1551 lprintf(CTDL_DEBUG, "<%s\n", buf);
1552 if (buf[0] != '2') {
1555 download_len = extract_long(&buf[4], 0);
1557 bytes_received = 0L;
1558 fp = fopen(tempfilename, "w");
1560 lprintf(CTDL_CRIT, "cannot open download file locally: %s\n",
1565 while (bytes_received < download_len) {
1566 snprintf(buf, sizeof buf, "READ %ld|%ld",
1568 ((download_len - bytes_received > IGNET_PACKET_SIZE)
1569 ? IGNET_PACKET_SIZE : (download_len - bytes_received)));
1570 if (sock_puts(sock, buf) < 0) {
1572 unlink(tempfilename);
1575 if (sock_gets(sock, buf) < 0) {
1577 unlink(tempfilename);
1580 if (buf[0] == '6') {
1581 plen = extract_long(&buf[4], 0);
1582 if (sock_read(sock, pbuf, plen) < 0) {
1584 unlink(tempfilename);
1587 fwrite((char *) pbuf, plen, 1, fp);
1588 bytes_received = bytes_received + plen;
1593 if (sock_puts(sock, "CLOS") < 0) {
1594 unlink(tempfilename);
1597 if (sock_gets(sock, buf) < 0) {
1598 unlink(tempfilename);
1601 if (download_len > 0)
1602 lprintf(CTDL_NOTICE, "Received %ld octets from <%s>",
1603 download_len, remote_nodename);
1604 lprintf(CTDL_DEBUG, "%s", buf);
1605 snprintf(buf, sizeof buf, "mv %s ./network/spoolin/%s.%ld",
1606 tempfilename, remote_nodename, (long) getpid());
1613 * transmit network spool to the remote system
1615 void transmit_spool(int sock, char *remote_nodename)
1620 long bytes_to_write, thisblock, bytes_written;
1624 if (sock_puts(sock, "NUOP") < 0) return;
1625 if (sock_gets(sock, buf) < 0) return;
1626 lprintf(CTDL_DEBUG, "<%s\n", buf);
1627 if (buf[0] != '2') {
1631 snprintf(sfname, sizeof sfname, "./network/spoolout/%s", remote_nodename);
1632 fd = open(sfname, O_RDONLY);
1634 if (errno != ENOENT) {
1635 lprintf(CTDL_CRIT, "cannot open upload file locally: %s\n",
1641 while (plen = (long) read(fd, pbuf, IGNET_PACKET_SIZE), plen > 0L) {
1642 bytes_to_write = plen;
1643 while (bytes_to_write > 0L) {
1644 snprintf(buf, sizeof buf, "WRIT %ld", bytes_to_write);
1645 if (sock_puts(sock, buf) < 0) {
1649 if (sock_gets(sock, buf) < 0) {
1653 thisblock = atol(&buf[4]);
1654 if (buf[0] == '7') {
1655 if (sock_write(sock, pbuf,
1656 (int) thisblock) < 0) {
1660 bytes_to_write -= thisblock;
1661 bytes_written += thisblock;
1670 if (sock_puts(sock, "UCLS 1") < 0) return;
1671 if (sock_gets(sock, buf) < 0) return;
1672 lprintf(CTDL_NOTICE, "Sent %ld octets to <%s>",
1673 bytes_written, remote_nodename);
1674 lprintf(CTDL_DEBUG, "<%s\n", buf);
1675 if (buf[0] == '2') {
1683 * Poll one Citadel node (called by network_poll_other_citadel_nodes() below)
1685 void network_poll_node(char *node, char *secret, char *host, char *port) {
1689 if (network_talking_to(node, NTT_CHECK)) return;
1690 network_talking_to(node, NTT_ADD);
1691 lprintf(CTDL_NOTICE, "Connecting to <%s> at %s:%s\n", node, host, port);
1693 sock = sock_connect(host, port, "tcp");
1695 lprintf(CTDL_ERR, "Could not connect: %s\n", strerror(errno));
1696 network_talking_to(node, NTT_REMOVE);
1700 lprintf(CTDL_DEBUG, "Connected!\n");
1702 /* Read the server greeting */
1703 if (sock_gets(sock, buf) < 0) goto bail;
1704 lprintf(CTDL_DEBUG, ">%s\n", buf);
1706 /* Identify ourselves */
1707 snprintf(buf, sizeof buf, "NETP %s|%s", config.c_nodename, secret);
1708 lprintf(CTDL_DEBUG, "<%s\n", buf);
1709 if (sock_puts(sock, buf) <0) goto bail;
1710 if (sock_gets(sock, buf) < 0) goto bail;
1711 lprintf(CTDL_DEBUG, ">%s\n", buf);
1712 if (buf[0] != '2') goto bail;
1714 /* At this point we are authenticated. */
1715 receive_spool(sock, node);
1716 transmit_spool(sock, node);
1718 sock_puts(sock, "QUIT");
1719 bail: sock_close(sock);
1720 network_talking_to(node, NTT_REMOVE);
1726 * Poll other Citadel nodes and transfer inbound/outbound network data.
1727 * Set "full" to nonzero to force a poll of every node, or to zero to poll
1728 * only nodes to which we have data to send.
1730 void network_poll_other_citadel_nodes(int full_poll) {
1738 char spoolfile[SIZ];
1740 if (working_ignetcfg == NULL) {
1741 lprintf(CTDL_DEBUG, "No nodes defined - not polling\n");
1745 /* Use the string tokenizer to grab one line at a time */
1746 for (i=0; i<num_tokens(working_ignetcfg, '\n'); ++i) {
1747 extract_token(linebuf, working_ignetcfg, i, '\n');
1748 extract(node, linebuf, 0);
1749 extract(secret, linebuf, 1);
1750 extract(host, linebuf, 2);
1751 extract(port, linebuf, 3);
1752 if ( (strlen(node) > 0) && (strlen(secret) > 0)
1753 && (strlen(host) > 0) && strlen(port) > 0) {
1756 sprintf(spoolfile, "./network/spoolout/%s",
1758 if (access(spoolfile, R_OK) == 0) {
1763 network_poll_node(node, secret, host, port);
1777 * network_do_queue()
1779 * Run through the rooms doing various types of network stuff.
1781 void network_do_queue(void) {
1782 static time_t last_run = 0L;
1783 struct RoomProcList *ptr;
1784 int full_processing = 1;
1787 * Run the full set of processing tasks no more frequently
1788 * than once every n seconds
1790 if ( (time(NULL) - last_run) < config.c_net_freq ) {
1791 full_processing = 0;
1795 * This is a simple concurrency check to make sure only one queue run
1796 * is done at a time. We could do this with a mutex, but since we
1797 * don't really require extremely fine granularity here, we'll do it
1798 * with a static variable instead.
1800 if (doing_queue) return;
1803 /* Load the IGnet Configuration into memory */
1804 load_working_ignetcfg();
1807 * Poll other Citadel nodes. Maybe. If "full_processing" is set
1808 * then we poll everyone. Otherwise we only poll nodes we have stuff
1811 network_poll_other_citadel_nodes(full_processing);
1814 * Load the network map and filter list into memory.
1817 filterlist = load_filter_list();
1820 * Go ahead and run the queue
1822 if (full_processing) {
1823 lprintf(CTDL_DEBUG, "network: loading outbound queue\n");
1824 ForEachRoom(network_queue_room, NULL);
1826 lprintf(CTDL_DEBUG, "network: running outbound queue\n");
1827 while (rplist != NULL) {
1828 network_spoolout_room(rplist->name);
1830 rplist = rplist->next;
1835 lprintf(CTDL_DEBUG, "network: processing inbound queue\n");
1836 network_do_spoolin();
1838 /* Save the network map back to disk */
1839 write_network_map();
1841 /* Free the filter list in memory */
1842 free_filter_list(filterlist);
1845 network_purge_spoolout();
1847 lprintf(CTDL_DEBUG, "network: queue run completed\n");
1849 if (full_processing) {
1850 last_run = time(NULL);
1858 * cmd_netp() - authenticate to the server as another Citadel node polling
1859 * for network traffic
1861 void cmd_netp(char *cmdbuf)
1871 extract(node, cmdbuf, 0);
1872 extract(pass, cmdbuf, 1);
1875 lprintf(CTDL_WARNING, "Network node <%s> refused - spooling", node);
1876 cprintf("%d spooling - try again in a few minutes\n",
1877 ERROR + RESOURCE_BUSY);
1881 /* load the IGnet Configuration to check node validity */
1882 load_working_ignetcfg();
1883 v = is_valid_node(nexthop, secret, node);
1886 lprintf(CTDL_WARNING, "Unknown node <%s>", node);
1887 cprintf("%d authentication failed\n",
1888 ERROR + PASSWORD_REQUIRED);
1892 if (strcasecmp(pass, secret)) {
1893 lprintf(CTDL_WARNING, "Bad password for network node <%s>", node);
1894 cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
1898 if (network_talking_to(node, NTT_CHECK)) {
1899 lprintf(CTDL_WARNING, "Duplicate session for network node <%s>", node);
1900 cprintf("%d Already talking to %s right now\n", ERROR + RESOURCE_BUSY, node);
1904 safestrncpy(CC->net_node, node, sizeof CC->net_node);
1905 network_talking_to(node, NTT_ADD);
1906 lprintf(CTDL_NOTICE, "Network node <%s> logged in\n", CC->net_node);
1907 cprintf("%d authenticated as network node '%s'\n", CIT_OK,
1914 * Module entry point
1916 char *serv_network_init(void)
1918 CtdlRegisterProtoHook(cmd_gnet, "GNET", "Get network config");
1919 CtdlRegisterProtoHook(cmd_snet, "SNET", "Set network config");
1920 CtdlRegisterProtoHook(cmd_netp, "NETP", "Identify as network poller");
1921 CtdlRegisterProtoHook(cmd_nsyn, "NSYN", "Synchronize room to node");
1922 CtdlRegisterSessionHook(network_do_queue, EVT_TIMER);