* 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-2010 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
#include "citserver.h"
#include "support.h"
#include "config.h"
-#include "room_ops.h"
#include "user_ops.h"
#include "policy.h"
#include "database.h"
#include "snprintf.h"
#endif
+#include "context.h"
#include "ctdl_module.h"
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);
}
long msglen;
char *recps = NULL;
size_t recps_len = SIZ;
+ size_t siz;
struct recptypes *valid;
namelist *nptr;
char bounce_to[256];
msg->cm_fields['M'] = malloc(msglen + 1);
fseek(sc->digestfp, 0L, SEEK_SET);
- fread(msg->cm_fields['M'], (size_t)msglen, 1, sc->digestfp);
- msg->cm_fields['M'][msglen] = 0;
+ siz = fread(msg->cm_fields['M'], (size_t)msglen, 1, sc->digestfp);
+ msg->cm_fields['M'][msglen] = '\0';
fclose(sc->digestfp);
sc->digestfp = NULL;
* 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;
}
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];
/* 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... */
"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 */
* 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 */
buffer = malloc(size);
if (buffer != NULL) {
fseek(fp, msgstart, SEEK_SET);
- fread(buffer, size, 1, fp);
- network_process_buffer(buffer, size);
+ if (fread(buffer, size, 1, fp) > 0) {
+ network_process_buffer(buffer, size);
+ }
free(buffer);
}
/*
* receive network spool from the remote system
*/
-void receive_spool(int sock, char *remote_nodename) {
+void receive_spool(int *sock, char *remote_nodename) {
+ size_t siz;
long download_len = 0L;
long bytes_received = 0L;
long bytes_copied = 0L;
FILE *fp, *newfp;
CtdlMakeTempFileName(tempfilename, sizeof tempfilename);
- if (sock_puts(sock, "NDOP") < 0) return;
+ if (sock_puts(*sock, "NDOP") < 0) return;
if (sock_getln(sock, buf, sizeof buf) < 0) return;
CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf);
if (buf[0] != '2') {
bytes_received,
((download_len - bytes_received > IGNET_PACKET_SIZE)
? IGNET_PACKET_SIZE : (download_len - bytes_received)));
- if (sock_puts(sock, buf) < 0) {
+ if (sock_puts(*sock, buf) < 0) {
fclose(fp);
unlink(tempfilename);
return;
unlink(tempfilename);
return;
}
- if (sock_puts(sock, "CLOS") < 0) {
+ if (sock_puts(*sock, "CLOS") < 0) {
unlink(tempfilename);
return;
}
if (plen > sizeof buf) {
plen = sizeof buf;
}
- fread(buf, plen, 1, fp);
+ siz = fread(buf, plen, 1, fp);
fwrite(buf, plen, 1, newfp);
bytes_copied += plen;
}
/*
* transmit network spool to the remote system
*/
-void transmit_spool(int sock, char *remote_nodename)
+void transmit_spool(int *sock, char *remote_nodename)
{
char buf[SIZ];
char pbuf[4096];
int fd;
char sfname[128];
- if (sock_puts(sock, "NUOP") < 0) return;
+ if (sock_puts(*sock, "NUOP") < 0) return;
if (sock_getln(sock, buf, sizeof buf) < 0) return;
CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf);
if (buf[0] != '2') {
}
snprintf(buf, sizeof buf, "WRIT %ld", bytes_to_write);
- if (sock_puts(sock, buf) < 0) {
+ if (sock_puts(*sock, buf) < 0) {
close(fd);
return;
}
}
thisblock = atol(&buf[4]);
if (buf[0] == '7') {
- if (sock_write(sock, pbuf,
+ if (sock_write(*sock, pbuf,
(int) thisblock) < 0) {
close(fd);
return;
if(CtdlThreadCheckStop())
return;
- if (sock_puts(sock, "UCLS 1") < 0) return;
+ if (sock_puts(*sock, "UCLS 1") < 0) return;
/**
* From here on we must complete or messages will get lost
*/
CtdlLogPrintf(CTDL_DEBUG, "Connected!\n");
/* Read the server greeting */
- if (sock_getln(sock, buf, sizeof buf) < 0) goto bail;
+ 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 */
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);
* It's ok if these directories already exist. Just fail silently.
*/
void create_spool_dirs(void) {
- mkdir(ctdl_spool_dir, 0700);
- chown(ctdl_spool_dir, CTDLUID, (-1));
- mkdir(ctdl_netin_dir, 0700);
- chown(ctdl_netin_dir, CTDLUID, (-1));
- mkdir(ctdl_netout_dir, 0700);
- chown(ctdl_netout_dir, CTDLUID, (-1));
+ if ((mkdir(ctdl_spool_dir, 0700) != 0) && (errno != EEXIST))
+ CtdlLogPrintf(CTDL_EMERG, "unable to create directory [%s]: %s", ctdl_spool_dir, strerror(errno));
+ if (chown(ctdl_spool_dir, CTDLUID, (-1)) != 0)
+ CtdlLogPrintf(CTDL_EMERG, "unable to set the access rights for [%s]: %s", ctdl_spool_dir, strerror(errno));
+ if ((mkdir(ctdl_netin_dir, 0700) != 0) && (errno != EEXIST))
+ CtdlLogPrintf(CTDL_EMERG, "unable to create directory [%s]: %s", ctdl_netin_dir, strerror(errno));
+ if (chown(ctdl_netin_dir, CTDLUID, (-1)) != 0)
+ CtdlLogPrintf(CTDL_EMERG, "unable to set the access rights for [%s]: %s", ctdl_netin_dir, strerror(errno));
+ if ((mkdir(ctdl_netout_dir, 0700) != 0) && (errno != EEXIST))
+ CtdlLogPrintf(CTDL_EMERG, "unable to create directory [%s]: %s", ctdl_netout_dir, strerror(errno));
+ if (chown(ctdl_netout_dir, CTDLUID, (-1)) != 0)
+ CtdlLogPrintf(CTDL_EMERG, "unable to set the access rights for [%s]: %s", ctdl_netout_dir, strerror(errno));
}
*/
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) {
);
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;
}
);
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;
}