* This module handles shared rooms, inter-Citadel mail, and outbound
* mailing list processing.
*
- * Copyright (c) 2000-2012 by the citadel.org team
+ * Copyright (c) 2000-2016 by the citadel.org team
*
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 3.
+ * This program is open source software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 3.
*
- * 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.
+ * 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.
*
*/
#include "sysdep.h"
#include <stdio.h>
+#include <sys/types.h>
+#include <dirent.h>
#ifdef HAVE_SYSCALL_H
# include <syscall.h>
TmpFD = open(tempfilename, O_CREAT|O_EXCL|O_RDWR, S_IRUSR|S_IWUSR);
Cfg = NewStrBuf();
if ((TmpFD < 0) || (errno != 0)) {
- syslog(LOG_CRIT, "ERROR: cannot open %s: %s\n",
+ syslog(LOG_CRIT, "ERROR: cannot open %s: %s",
filename, strerror(errno));
unlink(tempfilename);
FreeStrBuf(&Cfg);
else {
OutBuffer = NewStrBuf();
CfgIt = GetNewHashPos(CfgTypeHash, 1);
- fchown(TmpFD, config.c_ctdluid, 0);
+ fchown(TmpFD, ctdluid, 0);
for (eCfg = subpending; eCfg < maxRoomNetCfg; eCfg ++)
{
const CfgLineType *pCfg;
}
else {
syslog(LOG_EMERG,
- "unable to write %s; [%s]; not enough space on the disk?\n",
- tempfilename,
- strerror(errno));
+ "unable to write %s; [%s]; not enough space on the disk?",
+ tempfilename,
+ strerror(errno)
+ );
close(TmpFD);
unlink(tempfilename);
rc = 0;
if (OneRNCfg != NULL)
Put(RoomConfigs, LKEY(RoomNumber), OneRNCfg, vFreeRoomNetworkStruct);
- /* syslog(9, "[%s | %s]\n", ChrPtr(OneWebName), ChrPtr(FileName)); */
}
break;
default:
lens[0] = strlen(CCC->cs_addr);
strs[1] = "SRV_UNKNOWN";
- lens[1] = sizeof("SRV_UNKNOWN" - 1);
+ lens[1] = sizeof("SRV_UNKNOWN") - 1;
CtdlAideFPMessage(
err_buf,
lens[0] = strlen(CCC->cs_addr);
strs[1] = "SRV_PW";
- lens[1] = sizeof("SRV_PW" - 1);
+ lens[1] = sizeof("SRV_PW") - 1;
CtdlAideFPMessage(
err_buf,
}
nodelen = safestrncpy(CCC->net_node, node, sizeof CCC->net_node);
CtdlNetworkTalkingTo(CCC->net_node, nodelen, NTT_ADD);
- syslog(LOG_NOTICE, "Network node <%s> logged in from %s [%s]\n",
+ syslog(LOG_NOTICE, "Network node <%s> logged in from %s [%s]",
CCC->net_node, CCC->cs_host, CCC->cs_addr
);
cprintf("%d authenticated as network node '%s'\n", CIT_OK, CCC->net_node);
* First try the neighbor nodes
*/
if (GetCount(IgnetCfg) == 0) {
- syslog(LOG_INFO, "IgnetCfg is empty!\n");
+ syslog(LOG_INFO, "IgnetCfg is empty!");
if (nexthop != NULL) {
*nexthop = NULL;
}
/*
* If we get to this point, the supplied node name is bogus.
*/
- syslog(LOG_ERR, "Invalid node name <%s>\n", ChrPtr(node));
+ syslog(LOG_ERR, "Invalid node name <%s>", ChrPtr(node));
return(-1);
}
DeleteHash(&pCfgTypeHash);
}
+
+
+
+/*
+ * Create a config key for a room's netconfig entry
+ */
+void netcfg_keyname(char *keybuf, long roomnum)
+{
+ if (!keybuf) return;
+ sprintf(keybuf, "c_netconfig_%010ld", roomnum);
+}
+
+
+
+
+/*
+ * Convert any legacy configuration files in the "netconfigs" directory
+ */
+void convert_legacy_netcfg_files(void)
+{
+ DIR *dh = NULL;
+ struct dirent *dit = NULL;
+ char keyname[25];
+ char filename[PATH_MAX];
+ long roomnum;
+ FILE *fp;
+ long len;
+ char *v;
+
+ dh = opendir(ctdl_netcfg_dir);
+ if (!dh) return;
+
+ syslog(LOG_INFO, "Legacy netconfig files exist - converting them!");
+
+ while (dit = readdir(dh), dit != NULL) { // yes, we use the non-reentrant version; we're not in threaded mode yet
+ roomnum = atol(dit->d_name);
+ if (roomnum > 0) {
+ netcfg_keyname(keyname, roomnum);
+ snprintf(filename, sizeof filename, "%s/%ld", ctdl_netcfg_dir, roomnum);
+ fp = fopen(filename, "r");
+ if (fp) {
+ fseek(fp, 0L, SEEK_END);
+ len = ftell(fp);
+ v = malloc(len);
+ if (v) {
+ rewind(fp);
+ if (fread(v, len, 1, fp)) {
+ char *enc = malloc(len * 2);
+ int enc_len;
+ if (enc) {
+ enc_len = CtdlEncodeBase64(enc, v, len, 0);
+ if ((enc_len > 1) && (enc[enc_len-2] == 13)) enc[enc_len-2] = 0;
+ if ((enc_len > 0) && (enc[enc_len-1] == 10)) enc[enc_len-1] = 0;
+ enc[enc_len] = 0;
+ syslog(LOG_DEBUG, "Writing key '%s' (length=%d)", keyname, enc_len);
+ CtdlSetConfigStr(keyname, enc);
+ free(enc);
+ // unlink(filename); // FIXME uncomment this when ready
+ fclose(fp);
+ }
+ }
+ free(v);
+ }
+ }
+ }
+ }
+
+ closedir(dh);
+ // rmdir(ctdl_netcfg_dir); // FIXME uncomment this when ready
+}
+
+
+
/*
* Module entry point
*/
if (!threading)
{
CtdlRegisterCleanupHook(destroy_network_cfgs);
- LoadAllNetConfigs ();
+ convert_legacy_netcfg_files();
+ LoadAllNetConfigs();
CtdlRegisterProtoHook(cmd_gnet, "GNET", "Get network config");
CtdlRegisterProtoHook(cmd_snet, "SNET", "Set network config");
CtdlRegisterProtoHook(cmd_netp, "NETP", "Identify as network poller");