/*
- * This module handles shared rooms, inter-Citadel mail, and outbound
- * mailing list processing.
+ * This module handles loading, saving, and parsing of room network configurations.
*
- * Copyright (c) 2000-2016 by the citadel.org team
+ * Copyright (c) 2000-2017 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.
# endif
#endif
#include <dirent.h>
+#include <assert.h>
#include <libcitadel.h>
pCfg->Str.len = len;
pCfg->IsSingleLine = uniq;
pCfg->nSegments = nSegments;
- if (CfgTypeHash == NULL)
+ if (CfgTypeHash == NULL) {
CfgTypeHash = NewHash(1, NULL);
+ }
Put(CfgTypeHash, Name, len, pCfg, NULL);
}
}
}
+
const CfgLineType *GetCfgTypeByEnum(RoomNetCfg eCfg, HashPos *It)
{
const char *Key;
return NULL;
}
+
void ParseGeneric(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *OneRNCfg)
{
RoomNetCfgLine *nptr;
OneRNCfg->NetConfigs[ThisOne->C] = nptr;
}
+
void SerializeGeneric(const CfgLineType *ThisOne, StrBuf *OutputBuffer, OneRoomNetCfg *OneRNCfg, RoomNetCfgLine *data)
{
int i;
StrBufAppendBufPlain(OutputBuffer, HKEY("\n"), 0);
}
+
void DeleteGenericCfgLine(const CfgLineType *ThisOne, RoomNetCfgLine **data)
{
int i;
*data = NULL;
}
+
RoomNetCfgLine *DuplicateOneGenericCfgLine(const RoomNetCfgLine *data)
{
int i;
}
-
/*
* Given a room number and a textual netconfig, convert to base64 and write to the configdb
*/
int enc_len;
int len;
- syslog(LOG_DEBUG, "\033[32m--- START WRITE ---\033[0m\n\033[31m%s\033[0m\n\033[32m---- END WRITE ----\033[0m", raw_netconfig);
len = strlen(raw_netconfig);
netcfg_keyname(keyname, roomnum);
enc = malloc(len * 2);
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);
+ syslog(LOG_DEBUG, "netconfig: writing key '%s' (length=%d)", keyname, enc_len);
CtdlSetConfigStr(keyname, enc);
free(enc);
}
}
-
/*
* Given a room number, attempt to load the netconfig configdb entry for that room.
* If it returns NULL, there is no netconfig.
OneRoomNetCfg *ParseRoomNetConfigFile(char *serialized_data)
{
const char *Pos = NULL;
- const char *CPos = NULL;
const CfgLineType *pCfg = NULL;
StrBuf *Line = NULL;
StrBuf *InStr = NULL;
StrBuf *Cfg = NULL;
OneRoomNetCfg *OneRNCfg = NULL;
+ int num_lines = 0;
+ int i = 0;
OneRNCfg = malloc(sizeof(OneRoomNetCfg));
memset(OneRNCfg, 0, sizeof(OneRoomNetCfg));
Line = NewStrBuf();
InStr = NewStrBuf();
Cfg = NewStrBufPlain(serialized_data, -1);
+ num_lines = num_tokens(ChrPtr(Cfg), '\n');
- syslog(LOG_DEBUG, "\033[32m--- START READ ---\033[0m");
- while (StrBufSipLine(Line, Cfg, &CPos)) {
- syslog(LOG_DEBUG, "READ NET CONFIG LINE: '\033[31m%s\033[0m'", ChrPtr(Line));
-
+ for (i=0; i<num_lines; ++i) {
+ StrBufExtract_token(Line, Cfg, i, '\n');
if (StrLength(Line) > 0) {
Pos = NULL;
StrBufExtract_NextToken(InStr, Line, &Pos, '|');
}
}
}
- syslog(LOG_DEBUG, "\033[32m---- END READ ----\033[0m");
FreeStrBuf(&InStr);
FreeStrBuf(&Line);
FreeStrBuf(&Cfg);
{
const CfgLineType *pCfg;
pCfg = GetCfgTypeByEnum(eCfg, CfgIt);
- if (pCfg->IsSingleLine)
+ if (pCfg)
{
- pCfg->Serializer(pCfg, OutBuffer, OneRNCfg, NULL);
- }
- else
- {
- RoomNetCfgLine *pName = OneRNCfg->NetConfigs[pCfg->C];
- while (pName != NULL)
+ if (pCfg->IsSingleLine)
+ {
+ pCfg->Serializer(pCfg, OutBuffer, OneRNCfg, NULL);
+ }
+ else
{
- pCfg->Serializer(pCfg, OutBuffer, OneRNCfg, pName);
- pName = pName->next;
+ RoomNetCfgLine *pName = OneRNCfg->NetConfigs[pCfg->C];
+ while (pName != NULL)
+ {
+ pCfg->Serializer(pCfg, OutBuffer, OneRNCfg, pName);
+ pName = pName->next;
+ }
}
-
-
}
}
}
-
void AddRoomCfgLine(OneRoomNetCfg *OneRNCfg, struct ctdlroom *qrbuf, RoomNetCfg LineType, RoomNetCfgLine *Line)
{
RoomNetCfgLine **pLine;
char *c = LoadRoomNetConfigFile(CC->room.QRnumber);
if (c) {
- cprintf("%s\n", c);
+ int len = strlen(c);
+ client_write(c, len); // Can't use cprintf() here, it has a limit of 1024 bytes
+ if (c[len] != '\n') {
+ client_write(HKEY("\n"));
+ }
free(c);
}
cprintf("000\n");
free(Node);
}
+
CtdlNodeConf *NewNode(StrBuf *SerializedNode)
{
const char *Pos = NULL;
}
-
-int CtdlNetconfigCheckRoomaccess(
- char *errmsgbuf,
- size_t n,
- const char* RemoteIdentifier)
+int CtdlNetconfigCheckRoomaccess(char *errmsgbuf, size_t n, const char* RemoteIdentifier)
{
OneRoomNetCfg *RNCfg;
int found;
return (ERROR + NO_SUCH_USER);
}
found = is_recipient (RNCfg, RemoteIdentifier);
+ FreeRoomNetworkStruct(&RNCfg);
end_critical_section(S_NETCONFIGS);
if (found) {
}
-
/*
* cmd_netp() - authenticate to the server as another Citadel node polling
* for network traffic
StrBuf *NodeStr;
long nodelen;
int v;
- long lens[2];
- const char *strs[2];
const StrBuf *secret = NULL;
const StrBuf *nexthop = NULL;
"An unknown Citadel server called \"%s\" attempted to connect from %s [%s].\n",
node, CCC->cs_host, CCC->cs_addr
);
- syslog(LOG_WARNING, "%s", err_buf);
+ syslog(LOG_WARNING, "netconfig: %s", err_buf);
cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
-
- strs[0] = CCC->cs_addr;
- lens[0] = strlen(CCC->cs_addr);
-
- strs[1] = "SRV_UNKNOWN";
- lens[1] = sizeof("SRV_UNKNOWN") - 1;
-
- CtdlAideFPMessage(
- err_buf,
- "IGNet Networking.",
- 2, strs, (long*) &lens,
- CCC->cs_pid, 0,
- time(NULL));
-
+ CtdlAideMessage(err_buf, "IGNet Networking");
DeleteHash(&working_ignetcfg);
FreeStrBuf(&NodeStr);
return;
"A Citadel server at %s [%s] failed to authenticate as network node \"%s\".\n",
CCC->cs_host, CCC->cs_addr, node
);
- syslog(LOG_WARNING, "%s", err_buf);
+ syslog(LOG_WARNING, "netconfig: %s", err_buf);
cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
- strs[0] = CCC->cs_addr;
- lens[0] = strlen(CCC->cs_addr);
-
- strs[1] = "SRV_PW";
- lens[1] = sizeof("SRV_PW") - 1;
-
- CtdlAideFPMessage(
- err_buf,
- "IGNet Networking.",
- 2, strs,
- (long*) &lens,
- CCC->cs_pid, 0,
- time(NULL));
-
+ CtdlAideMessage(err_buf, "IGNet Networking");
DeleteHash(&working_ignetcfg);
FreeStrBuf(&NodeStr);
return;
}
if (CtdlNetworkTalkingTo(node, nodelen, NTT_CHECK)) {
- syslog(LOG_WARNING, "Duplicate session for network node <%s>", node);
+ syslog(LOG_WARNING, "netconfig: duplicate session for network node <%s>", node);
cprintf("%d Already talking to %s right now\n", ERROR + RESOURCE_BUSY, node);
DeleteHash(&working_ignetcfg);
FreeStrBuf(&NodeStr);
}
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]",
+ syslog(LOG_INFO, "netconfig: 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);
free(TheNetMap);
}
+
CtdlNetMap *NewNetMap(StrBuf *SerializedNetMap)
{
const char *Pos = NULL;
return NM;
}
+
HashList* CtdlReadNetworkMap(void)
{
const char *LinePos;
return Hash;
}
+
StrBuf *CtdlSerializeNetworkMap(HashList *Map)
{
void *vMap;
* First try the neighbor nodes
*/
if (GetCount(IgnetCfg) == 0) {
- syslog(LOG_INFO, "IgnetCfg is empty!");
+ syslog(LOG_INFO, "netconfig: 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>", ChrPtr(node));
+ syslog(LOG_ERR, "netconfig: invalid node name <%s>", ChrPtr(node));
return(-1);
}
dh = opendir(ctdl_netcfg_dir);
if (!dh) return;
- syslog(LOG_INFO, "Legacy netconfig files exist - converting them!");
+ syslog(LOG_INFO, "netconfig: 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 (fp) {
fseek(fp, 0L, SEEK_END);
len = ftell(fp);
- v = malloc(len);
- if (v) {
- rewind(fp);
- if (fread(v, len, 1, fp)) {
- write_netconfig_to_configdb(roomnum, v);
- unlink(filename);
+ if (len > 0) {
+ v = malloc(len);
+ if (v) {
+ rewind(fp);
+ if (fread(v, len, 1, fp)) {
+ write_netconfig_to_configdb(roomnum, v);
+ unlink(filename);
+ }
+ free(v);
}
- free(v);
+ }
+ else {
+ unlink(filename); // zero length netconfig, just delete it
}
fclose(fp);
}
}
-
/*
* Module entry point
*/