X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fnetwork%2Fserv_network.c;h=c20712142f8a8529532ba24b0644a35128f01fbc;hb=7a4d3aeb0b3a8210edc8f627e0914e2aa4c93131;hp=b5c5e050fc6768d051529518a66d8e2eede1d7a3;hpb=5485de5a09add8f7253058a1ce62e92559351790;p=citadel.git diff --git a/citadel/modules/network/serv_network.c b/citadel/modules/network/serv_network.c index b5c5e050f..c20712142 100644 --- a/citadel/modules/network/serv_network.c +++ b/citadel/modules/network/serv_network.c @@ -4,8 +4,21 @@ * This module handles shared rooms, inter-Citadel mail, and outbound * mailing list processing. * - * Copyright (C) 2000-2009 by Art Cancro and others. - * This code is released under the terms of the GNU General Public License. + * Copyright (c) 2000-2009 by the citadel.org team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * ** NOTE ** A word on the S_NETCONFIGS semaphore: * This is a fairly high-level type of critical section. It ensures that no @@ -54,7 +67,6 @@ #include "citserver.h" #include "support.h" #include "config.h" -#include "room_ops.h" #include "user_ops.h" #include "policy.h" #include "database.h" @@ -70,6 +82,7 @@ #include "snprintf.h" #endif +#include "context.h" #include "ctdl_module.h" @@ -204,14 +217,14 @@ int network_usetable(struct CtdlMessage *msg) { cdbut = cdb_fetch(CDB_USETABLE, msgid, strlen(msgid)); if (cdbut != NULL) { cdb_free(cdbut); + CtdlLogPrintf(CTDL_DEBUG, "network_usetable() : we already have %s\n", msgid); return(1); } /* If we got to this point, it's unique: add it. */ strcpy(ut.ut_msgid, msgid); ut.ut_timestamp = time(NULL); - cdb_store(CDB_USETABLE, msgid, strlen(msgid), - &ut, sizeof(struct UseTable) ); + cdb_store(CDB_USETABLE, msgid, strlen(msgid), &ut, sizeof(struct UseTable) ); return(0); } @@ -1129,7 +1142,7 @@ void network_spoolout_room(char *room_to_spool) { * Normally this should never happen, but once in a while maybe a room gets * queued for networking and then deleted before it can happen. */ - if (getroom(&CC->room, room_to_spool) != 0) { + if (CtdlGetRoom(&CC->room, room_to_spool) != 0) { CtdlLogPrintf(CTDL_CRIT, "ERROR: cannot load <%s>\n", room_to_spool); return; } @@ -1471,6 +1484,8 @@ void network_process_buffer(char *buffer, long size) { unsigned char firstbyte; unsigned char lastbyte; + CtdlLogPrintf(CTDL_DEBUG, "network_process_buffer() processing %ld bytes\n", size); + /* Validate just a little bit. First byte should be FF and * last byte should be 00. */ firstbyte = buffer[0]; lastbyte = buffer[size-1]; @@ -1569,17 +1584,14 @@ void network_process_buffer(char *buffer, long size) { /* Learn network topology from the path */ if ((msg->cm_fields['N'] != NULL) && (msg->cm_fields['P'] != NULL)) { - network_learn_topology(msg->cm_fields['N'], - msg->cm_fields['P']); + network_learn_topology(msg->cm_fields['N'], msg->cm_fields['P']); } /* Is the sending node giving us a very persuasive suggestion about * which room this message should be saved in? If so, go with that. */ if (msg->cm_fields['C'] != NULL) { - safestrncpy(target_room, - msg->cm_fields['C'], - sizeof target_room); + safestrncpy(target_room, msg->cm_fields['C'], sizeof target_room); } /* Otherwise, does it have a recipient? If so, validate it... */ @@ -1591,6 +1603,7 @@ void network_process_buffer(char *buffer, long size) { "Please check the address and try sending the message again.\n"); msg = NULL; free_recipients(recp); + CtdlLogPrintf(CTDL_DEBUG, "Bouncing message due to invalid recipient address.\n"); return; } strcpy(target_room, ""); /* no target room if mail */ @@ -1600,9 +1613,7 @@ void network_process_buffer(char *buffer, long size) { * it has the O field (Originating room) set. */ else if (msg->cm_fields['O'] != NULL) { - safestrncpy(target_room, - msg->cm_fields['O'], - sizeof target_room); + safestrncpy(target_room, msg->cm_fields['O'], sizeof target_room); } /* Strip out fields that are only relevant during transit */ @@ -2015,22 +2026,24 @@ void network_poll_node(char *node, char *secret, char *host, char *port) { 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."); + 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); } - - /* 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); @@ -2162,7 +2175,7 @@ void *network_do_queue(void *args) { */ if (full_processing && !CtdlThreadCheckStop()) { CtdlLogPrintf(CTDL_DEBUG, "network: loading outbound queue\n"); - ForEachRoom(network_queue_room, NULL); + CtdlForEachRoom(network_queue_room, NULL); } if (rplist != NULL) { @@ -2248,19 +2261,24 @@ void cmd_netp(char *cmdbuf) v = is_valid_node(nexthop, secret, node); if (v != 0) { - snprintf (err_buf, sizeof(err_buf), "Unknown node <%s>\n", node); + snprintf(err_buf, sizeof err_buf, + "An unknown Citadel server called \"%s\" attempted to connect from %s [%s].\n", + node, CC->cs_host, CC->cs_addr + ); CtdlLogPrintf(CTDL_WARNING, err_buf); - cprintf("%d authentication failed\n", - ERROR + PASSWORD_REQUIRED); - aide_message(err_buf, "IGNet Networking."); + cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED); + CtdlAideMessage(err_buf, "IGNet Networking."); return; } if (strcasecmp(pass, secret)) { - snprintf (err_buf, sizeof(err_buf), "Bad password for network node <%s>", node); + snprintf(err_buf, sizeof err_buf, + "A Citadel server at %s [%s] failed to authenticate as network node \"%s\".\n", + CC->cs_host, CC->cs_addr, node + ); CtdlLogPrintf(CTDL_WARNING, err_buf); cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED); - aide_message(err_buf, "IGNet Networking."); + CtdlAideMessage(err_buf, "IGNet Networking."); return; } @@ -2272,17 +2290,20 @@ void cmd_netp(char *cmdbuf) safestrncpy(CC->net_node, node, sizeof CC->net_node); network_talking_to(node, NTT_ADD); - CtdlLogPrintf(CTDL_NOTICE, "Network node <%s> logged in\n", CC->net_node); - cprintf("%d authenticated as network node '%s'\n", CIT_OK, - CC->net_node); + CtdlLogPrintf(CTDL_NOTICE, "Network node <%s> logged in from %s [%s]\n", + CC->net_node, CC->cs_host, CC->cs_addr + ); + cprintf("%d authenticated as network node '%s'\n", CIT_OK, CC->net_node); } + int network_room_handler (struct ctdlroom *room) { network_queue_room(room, NULL); return 0; } + /* * Module entry point */