2 * This module handles shared rooms, inter-Citadel mail, and outbound
3 * mailing list processing.
5 * Copyright (c) 2000-2016 by the citadel.org team
7 * This program is open source software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 3.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
19 #include <sys/types.h>
25 # if HAVE_SYS_SYSCALL_H
26 # include <sys/syscall.h>
32 #include <libcitadel.h>
34 #include "include/ctdl_module.h"
35 #include "serv_extensions.h"
38 void vFreeRoomNetworkStruct(void *vOneRoomNetCfg);
39 void FreeRoomNetworkStructContent(OneRoomNetCfg *OneRNCfg);
41 HashList *CfgTypeHash = NULL;
43 /*-----------------------------------------------------------------------------*
44 * Per room network configs *
45 *-----------------------------------------------------------------------------*/
48 void RegisterRoomCfgType(const char* Name, long len, RoomNetCfg eCfg, CfgLineParser p, int uniq, int nSegments, CfgLineSerializer s, CfgLineDeAllocator d)
52 pCfg = (CfgLineType*) malloc(sizeof(CfgLineType));
55 pCfg->DeAllocator = d;
59 pCfg->IsSingleLine = uniq;
60 pCfg->nSegments = nSegments;
61 if (CfgTypeHash == NULL) {
62 CfgTypeHash = NewHash(1, NULL);
64 Put(CfgTypeHash, Name, len, pCfg, NULL);
68 const CfgLineType *GetCfgTypeByStr(const char *Key, long len)
72 if (GetHash(CfgTypeHash, Key, len, &pv) && (pv != NULL))
74 return (const CfgLineType *) pv;
82 const CfgLineType *GetCfgTypeByEnum(RoomNetCfg eCfg, HashPos *It)
89 RewindHashPos(CfgTypeHash, It, 1);
90 while (GetNextHashPos(CfgTypeHash, It, &len, &Key, &pv) && (pv != NULL))
92 pCfg = (CfgLineType*) pv;
99 void ParseGeneric(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *OneRNCfg)
101 RoomNetCfgLine *nptr;
104 nptr = (RoomNetCfgLine *)
105 malloc(sizeof(RoomNetCfgLine));
106 nptr->next = OneRNCfg->NetConfigs[ThisOne->C];
107 nptr->Value = malloc(sizeof(StrBuf*) * ThisOne->nSegments);
109 memset(nptr->Value, 0, sizeof(StrBuf*) * ThisOne->nSegments);
110 if (ThisOne->nSegments == 1)
112 nptr->Value[0] = NewStrBufPlain(LinePos, StrLength(Line) - ( LinePos - ChrPtr(Line)) );
115 else for (i = 0; i < ThisOne->nSegments; i++)
118 nptr->Value[i] = NewStrBufPlain(NULL, StrLength(Line) - ( LinePos - ChrPtr(Line)) );
119 StrBufExtract_NextToken(nptr->Value[i], Line, &LinePos, '|');
122 OneRNCfg->NetConfigs[ThisOne->C] = nptr;
125 void SerializeGeneric(const CfgLineType *ThisOne, StrBuf *OutputBuffer, OneRoomNetCfg *OneRNCfg, RoomNetCfgLine *data)
129 StrBufAppendBufPlain(OutputBuffer, CKEY(ThisOne->Str), 0);
130 StrBufAppendBufPlain(OutputBuffer, HKEY("|"), 0);
131 for (i = 0; i < ThisOne->nSegments; i++)
133 StrBufAppendBuf(OutputBuffer, data->Value[i], 0);
134 if (i + 1 < ThisOne->nSegments)
135 StrBufAppendBufPlain(OutputBuffer, HKEY("|"), 0);
137 StrBufAppendBufPlain(OutputBuffer, HKEY("\n"), 0);
140 void DeleteGenericCfgLine(const CfgLineType *ThisOne, RoomNetCfgLine **data)
147 for (i = 0; i < (*data)->nValues; i++)
149 FreeStrBuf(&(*data)->Value[i]);
151 free ((*data)->Value);
156 RoomNetCfgLine *DuplicateOneGenericCfgLine(const RoomNetCfgLine *data)
159 RoomNetCfgLine *NewData;
161 NewData = (RoomNetCfgLine*)malloc(sizeof(RoomNetCfgLine));
162 memset(NewData, 0, sizeof(RoomNetCfgLine));
163 NewData->Value = (StrBuf **)malloc(sizeof(StrBuf*) * data->nValues);
164 memset(NewData->Value, 0, sizeof(StrBuf*) * data->nValues);
166 for (i = 0; i < data->nValues; i++)
168 NewData->Value[i] = NewStrBufDup(data->Value[i]);
170 NewData->nValues = data->nValues;
176 * Create a config key for a room's netconfig entry
178 void netcfg_keyname(char *keybuf, long roomnum)
181 sprintf(keybuf, "c_netconfig_%010ld", roomnum);
187 * Given a room number and a textual netconfig, convert to base64 and write to the configdb
189 void write_netconfig_to_configdb(long roomnum, const char *raw_netconfig)
196 len = strlen(raw_netconfig);
197 netcfg_keyname(keyname, roomnum);
198 enc = malloc(len * 2);
201 enc_len = CtdlEncodeBase64(enc, raw_netconfig, len, 0);
202 if ((enc_len > 1) && (enc[enc_len-2] == 13)) enc[enc_len-2] = 0;
203 if ((enc_len > 0) && (enc[enc_len-1] == 10)) enc[enc_len-1] = 0;
205 syslog(LOG_DEBUG, "Writing key '%s' (length=%d)", keyname, enc_len);
206 CtdlSetConfigStr(keyname, enc);
214 * Given a room number, attempt to load the netconfig configdb entry for that room.
215 * If it returns NULL, there is no netconfig.
216 * Otherwise the caller owns the returned memory and is responsible for freeing it.
218 char *LoadRoomNetConfigFile(long roomnum)
221 char *encoded_netconfig = NULL;
222 char *decoded_netconfig = NULL;
224 netcfg_keyname(keyname, roomnum);
225 encoded_netconfig = CtdlGetConfigStr(keyname);
226 if (!encoded_netconfig) return NULL;
228 decoded_netconfig = malloc(strlen(encoded_netconfig)); // yeah, way bigger than it needs to be, but safe
229 CtdlDecodeBase64(decoded_netconfig, encoded_netconfig, strlen(encoded_netconfig));
230 return decoded_netconfig;
235 * Deserialize a netconfig , allocate and return structured data
237 OneRoomNetCfg *ParseRoomNetConfigFile(char *serialized_data)
239 const char *Pos = NULL;
240 const CfgLineType *pCfg = NULL;
242 StrBuf *InStr = NULL;
244 OneRoomNetCfg *OneRNCfg = NULL;
248 OneRNCfg = malloc(sizeof(OneRoomNetCfg));
249 memset(OneRNCfg, 0, sizeof(OneRoomNetCfg));
253 Cfg = NewStrBufPlain(serialized_data, -1);
254 num_lines = num_tokens(ChrPtr(Cfg), '\n');
256 for (i=0; i<num_lines; ++i) {
257 StrBufExtract_token(Line, Cfg, i, '\n');
258 if (StrLength(Line) > 0) {
260 StrBufExtract_NextToken(InStr, Line, &Pos, '|');
262 pCfg = GetCfgTypeByStr(SKEY(InStr));
265 pCfg->Parser(pCfg, Line, Pos, OneRNCfg);
269 if (OneRNCfg->misc == NULL)
271 OneRNCfg->misc = NewStrBufDup(Line);
275 if (StrLength(OneRNCfg->misc) > 0) {
276 StrBufAppendBufPlain(OneRNCfg->misc, HKEY("\n"), 0);
278 StrBufAppendBuf(OneRNCfg->misc, Line, 0);
290 void SaveRoomNetConfigFile(OneRoomNetCfg *OneRNCfg, long roomnum)
294 StrBuf *OutBuffer = NULL;
298 OutBuffer = NewStrBuf();
299 CfgIt = GetNewHashPos(CfgTypeHash, 1);
300 for (eCfg = subpending; eCfg < maxRoomNetCfg; eCfg ++)
302 const CfgLineType *pCfg;
303 pCfg = GetCfgTypeByEnum(eCfg, CfgIt);
304 if (pCfg->IsSingleLine)
306 pCfg->Serializer(pCfg, OutBuffer, OneRNCfg, NULL);
310 RoomNetCfgLine *pName = OneRNCfg->NetConfigs[pCfg->C];
311 while (pName != NULL)
313 pCfg->Serializer(pCfg, OutBuffer, OneRNCfg, pName);
321 DeleteHashPos(&CfgIt);
323 if (OneRNCfg->misc != NULL) {
324 StrBufAppendBuf(OutBuffer, OneRNCfg->misc, 0);
327 write_netconfig_to_configdb(roomnum, ChrPtr(OutBuffer));
329 FreeStrBuf(&OutBuffer);
335 void AddRoomCfgLine(OneRoomNetCfg *OneRNCfg, struct ctdlroom *qrbuf, RoomNetCfg LineType, RoomNetCfgLine *Line)
337 RoomNetCfgLine **pLine;
339 if (OneRNCfg == NULL)
341 OneRNCfg = (OneRoomNetCfg*) malloc(sizeof(OneRoomNetCfg));
342 memset(OneRNCfg, 0, sizeof(OneRoomNetCfg));
344 pLine = &OneRNCfg->NetConfigs[LineType];
346 while(*pLine != NULL) pLine = &((*pLine)->next);
351 void FreeRoomNetworkStructContent(OneRoomNetCfg *OneRNCfg)
356 CfgIt = GetNewHashPos(CfgTypeHash, 1);
357 for (eCfg = subpending; eCfg < maxRoomNetCfg; eCfg ++)
359 const CfgLineType *pCfg;
360 RoomNetCfgLine *pNext, *pName;
362 pCfg = GetCfgTypeByEnum(eCfg, CfgIt);
363 pName= OneRNCfg->NetConfigs[eCfg];
364 while (pName != NULL)
369 pCfg->DeAllocator(pCfg, &pName);
373 DeleteGenericCfgLine(NULL, &pName);
378 DeleteHashPos(&CfgIt);
380 FreeStrBuf(&OneRNCfg->Sender);
381 FreeStrBuf(&OneRNCfg->RoomInfo);
382 FreeStrBuf(&OneRNCfg->misc);
383 memset(OneRNCfg, 0, sizeof(OneRoomNetCfg));
387 void vFreeRoomNetworkStruct(void *vOneRoomNetCfg)
389 OneRoomNetCfg *OneRNCfg;
390 OneRNCfg = (OneRoomNetCfg*)vOneRoomNetCfg;
391 FreeRoomNetworkStructContent(OneRNCfg);
396 void FreeRoomNetworkStruct(OneRoomNetCfg **pOneRNCfg)
398 vFreeRoomNetworkStruct(*pOneRNCfg);
404 * Fetch the netconfig entry for a room, parse it, and return the data.
405 * Caller owns the returned memory and MUST free it using FreeRoomNetworkStruct()
407 OneRoomNetCfg *CtdlGetNetCfgForRoom(long roomnum)
409 OneRoomNetCfg *OneRNCfg = NULL;
410 char *serialized_config = NULL;
412 serialized_config = LoadRoomNetConfigFile(roomnum);
413 if (!serialized_config) return NULL;
415 OneRNCfg = ParseRoomNetConfigFile(serialized_config);
416 free(serialized_config);
421 /*-----------------------------------------------------------------------------*
422 * Per room network configs : exchange with client *
423 *-----------------------------------------------------------------------------*/
425 void cmd_gnet(char *argbuf)
427 if ( (CC->room.QRflags & QR_MAILBOX) && (CC->user.usernum == atol(CC->room.QRname)) ) {
428 /* users can edit the netconfigs for their own mailbox rooms */
430 else if (CtdlAccessCheck(ac_room_aide)) return;
432 cprintf("%d Network settings for room #%ld <%s>\n", LISTING_FOLLOWS, CC->room.QRnumber, CC->room.QRname);
434 char *c = LoadRoomNetConfigFile(CC->room.QRnumber);
443 void cmd_snet(char *argbuf)
445 struct CitContext *CCC = CC;
447 StrBuf *TheConfig = NULL;
452 TheConfig = NewStrBuf();
453 cprintf("%d send new netconfig now\n", SEND_LISTING);
455 while (rc = CtdlClientGetLine(Line), (rc >= 0))
457 if ((rc == 3) && (strcmp(ChrPtr(Line), "000") == 0))
460 StrBufAppendBuf(TheConfig, Line, 0);
461 StrBufAppendBufPlain(TheConfig, HKEY("\n"), 0);
465 write_netconfig_to_configdb(CCC->room.QRnumber, ChrPtr(TheConfig));
466 FreeStrBuf(&TheConfig);
470 /*-----------------------------------------------------------------------------*
471 * Per node network configs *
472 *-----------------------------------------------------------------------------*/
473 void DeleteCtdlNodeConf(void *vNode)
475 CtdlNodeConf *Node = (CtdlNodeConf*) vNode;
476 FreeStrBuf(&Node->NodeName);
477 FreeStrBuf(&Node->Secret);
478 FreeStrBuf(&Node->Host);
479 FreeStrBuf(&Node->Port);
483 CtdlNodeConf *NewNode(StrBuf *SerializedNode)
485 const char *Pos = NULL;
488 /* we need at least 4 pipes and some other text so its invalid. */
489 if (StrLength(SerializedNode) < 8)
491 Node = (CtdlNodeConf *) malloc(sizeof(CtdlNodeConf));
495 Node->NodeName=NewStrBuf();
496 StrBufExtract_NextToken(Node->NodeName, SerializedNode, &Pos, '|');
498 Node->Secret=NewStrBuf();
499 StrBufExtract_NextToken(Node->Secret, SerializedNode, &Pos, '|');
501 Node->Host=NewStrBuf();
502 StrBufExtract_NextToken(Node->Host, SerializedNode, &Pos, '|');
504 Node->Port=NewStrBuf();
505 StrBufExtract_NextToken(Node->Port, SerializedNode, &Pos, '|');
511 * Load or refresh the Citadel network (IGnet) configuration for this node.
513 HashList* CtdlLoadIgNetCfg(void)
522 Cfg = CtdlGetSysConfig(IGNETCFG);
523 if ((Cfg == NULL) || IsEmptyStr(Cfg)) {
529 Hash = NewHash(1, NULL);
530 Buf = NewStrBufPlain(Cfg, -1);
532 LineBuf = NewStrBufPlain(NULL, StrLength(Buf));
536 StrBufSipLine(LineBuf, Buf, &LinePos);
537 if (StrLength(LineBuf) != 0) {
538 Node = NewNode(LineBuf);
540 Put(Hash, SKEY(Node->NodeName), Node, DeleteCtdlNodeConf);
543 } while (LinePos != StrBufNOTNULL);
545 FreeStrBuf(&LineBuf);
550 int is_recipient(OneRoomNetCfg *RNCfg, const char *Name)
552 const RoomNetCfg RecipientCfgs[] = {
559 RoomNetCfgLine *nptr;
564 while (RecipientCfgs[i] != maxRoomNetCfg)
566 nptr = RNCfg->NetConfigs[RecipientCfgs[i]];
570 if ((StrLength(nptr->Value[0]) == len) &&
571 (!strcmp(Name, ChrPtr(nptr->Value[0]))))
584 int CtdlNetconfigCheckRoomaccess(
587 const char* RemoteIdentifier)
589 OneRoomNetCfg *RNCfg;
592 if (RemoteIdentifier == NULL)
594 snprintf(errmsgbuf, n, "Need sender to permit access.");
595 return (ERROR + USERNAME_REQUIRED);
598 begin_critical_section(S_NETCONFIGS);
599 RNCfg = CtdlGetNetCfgForRoom (CC->room.QRnumber);
602 end_critical_section(S_NETCONFIGS);
603 snprintf(errmsgbuf, n,
604 "This mailing list only accepts posts from subscribers.");
605 return (ERROR + NO_SUCH_USER);
607 found = is_recipient (RNCfg, RemoteIdentifier);
608 FreeRoomNetworkStruct(&RNCfg);
609 end_critical_section(S_NETCONFIGS);
615 snprintf(errmsgbuf, n,
616 "This mailing list only accepts posts from subscribers.");
617 return (ERROR + NO_SUCH_USER);
624 * cmd_netp() - authenticate to the server as another Citadel node polling
625 * for network traffic
627 void cmd_netp(char *cmdbuf)
629 struct CitContext *CCC = CC;
630 HashList *working_ignetcfg;
638 const StrBuf *secret = NULL;
639 const StrBuf *nexthop = NULL;
640 char err_buf[SIZ] = "";
643 node = CCC->curr_user;
644 nodelen = extract_token(CCC->curr_user, cmdbuf, 0, '|', sizeof CCC->curr_user);
645 NodeStr = NewStrBufPlain(node, nodelen);
646 /* load the IGnet Configuration to check node validity */
647 working_ignetcfg = CtdlLoadIgNetCfg();
648 v = CtdlIsValidNode(&nexthop, &secret, NodeStr, working_ignetcfg, NULL);
650 snprintf(err_buf, sizeof err_buf,
651 "An unknown Citadel server called \"%s\" attempted to connect from %s [%s].\n",
652 node, CCC->cs_host, CCC->cs_addr
654 syslog(LOG_WARNING, "%s", err_buf);
655 cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
657 strs[0] = CCC->cs_addr;
658 lens[0] = strlen(CCC->cs_addr);
660 strs[1] = "SRV_UNKNOWN";
661 lens[1] = sizeof("SRV_UNKNOWN") - 1;
666 2, strs, (long*) &lens,
670 DeleteHash(&working_ignetcfg);
671 FreeStrBuf(&NodeStr);
675 extract_token(CCC->user.password, cmdbuf, 1, '|', sizeof CCC->user.password);
676 if (strcasecmp(CCC->user.password, ChrPtr(secret))) {
677 snprintf(err_buf, sizeof err_buf,
678 "A Citadel server at %s [%s] failed to authenticate as network node \"%s\".\n",
679 CCC->cs_host, CCC->cs_addr, node
681 syslog(LOG_WARNING, "%s", err_buf);
682 cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
684 strs[0] = CCC->cs_addr;
685 lens[0] = strlen(CCC->cs_addr);
688 lens[1] = sizeof("SRV_PW") - 1;
698 DeleteHash(&working_ignetcfg);
699 FreeStrBuf(&NodeStr);
703 if (CtdlNetworkTalkingTo(node, nodelen, NTT_CHECK)) {
704 syslog(LOG_WARNING, "Duplicate session for network node <%s>", node);
705 cprintf("%d Already talking to %s right now\n", ERROR + RESOURCE_BUSY, node);
706 DeleteHash(&working_ignetcfg);
707 FreeStrBuf(&NodeStr);
710 nodelen = safestrncpy(CCC->net_node, node, sizeof CCC->net_node);
711 CtdlNetworkTalkingTo(CCC->net_node, nodelen, NTT_ADD);
712 syslog(LOG_NOTICE, "Network node <%s> logged in from %s [%s]",
713 CCC->net_node, CCC->cs_host, CCC->cs_addr
715 cprintf("%d authenticated as network node '%s'\n", CIT_OK, CCC->net_node);
716 DeleteHash(&working_ignetcfg);
717 FreeStrBuf(&NodeStr);
721 /*-----------------------------------------------------------------------------*
722 * Network maps: evaluate other nodes *
723 *-----------------------------------------------------------------------------*/
725 void DeleteNetMap(void *vNetMap)
727 CtdlNetMap *TheNetMap = (CtdlNetMap*) vNetMap;
728 FreeStrBuf(&TheNetMap->NodeName);
729 FreeStrBuf(&TheNetMap->NextHop);
733 CtdlNetMap *NewNetMap(StrBuf *SerializedNetMap)
735 const char *Pos = NULL;
738 /* we need at least 3 pipes and some other text so its invalid. */
739 if (StrLength(SerializedNetMap) < 6)
741 NM = (CtdlNetMap *) malloc(sizeof(CtdlNetMap));
743 NM->NodeName=NewStrBuf();
744 StrBufExtract_NextToken(NM->NodeName, SerializedNetMap, &Pos, '|');
746 NM->lastcontact = StrBufExtractNext_long(SerializedNetMap, &Pos, '|');
748 NM->NextHop=NewStrBuf();
749 StrBufExtract_NextToken(NM->NextHop, SerializedNetMap, &Pos, '|');
754 HashList* CtdlReadNetworkMap(void)
761 CtdlNetMap *TheNetMap;
763 Hash = NewHash(1, NULL);
764 Cfg = CtdlGetSysConfig(IGNETMAP);
765 if ((Cfg == NULL) || IsEmptyStr(Cfg)) {
771 Buf = NewStrBufPlain(Cfg, -1);
773 LineBuf = NewStrBufPlain(NULL, StrLength(Buf));
775 while (StrBufSipLine(Buf, LineBuf, &LinePos))
777 TheNetMap = NewNetMap(LineBuf);
778 if (TheNetMap != NULL) { /* TODO: is the NodeName Uniq? */
779 Put(Hash, SKEY(TheNetMap->NodeName), TheNetMap, DeleteNetMap);
783 FreeStrBuf(&LineBuf);
787 StrBuf *CtdlSerializeNetworkMap(HashList *Map)
792 StrBuf *Ret = NewStrBuf();
793 HashPos *Pos = GetNewHashPos(Map, 0);
795 while (GetNextHashPos(Map, Pos, &len, &key, &vMap))
797 CtdlNetMap *pMap = (CtdlNetMap*) vMap;
798 StrBufAppendBuf(Ret, pMap->NodeName, 0);
799 StrBufAppendBufPlain(Ret, HKEY("|"), 0);
801 StrBufAppendPrintf(Ret, "%ld", pMap->lastcontact, 0);
802 StrBufAppendBufPlain(Ret, HKEY("|"), 0);
804 StrBufAppendBuf(Ret, pMap->NextHop, 0);
805 StrBufAppendBufPlain(Ret, HKEY("\n"), 0);
813 * Learn topology from path fields
815 void NetworkLearnTopology(char *node, char *path, HashList *the_netmap, int *netmap_changed)
817 CtdlNetMap *pNM = NULL;
822 if (GetHash(the_netmap, node, strlen(node), &vptr) &&
823 (vptr != NULL))/* TODO: is the NodeName Uniq? */
825 pNM = (CtdlNetMap*)vptr;
826 extract_token(nexthop, path, 0, '!', sizeof nexthop);
827 if (!strcmp(nexthop, ChrPtr(pNM->NextHop))) {
828 pNM->lastcontact = time(NULL);
829 (*netmap_changed) ++;
834 /* If we got here then it's not in the map, so add it. */
835 nmptr = (CtdlNetMap *) malloc(sizeof (CtdlNetMap));
836 nmptr->NodeName = NewStrBufPlain(node, -1);
837 nmptr->lastcontact = time(NULL);
838 nmptr->NextHop = NewStrBuf ();
839 StrBufExtract_tokenFromStr(nmptr->NextHop, path, strlen(path), 0, '!');
840 /* TODO: is the NodeName Uniq? */
841 Put(the_netmap, SKEY(nmptr->NodeName), nmptr, DeleteNetMap);
842 (*netmap_changed) ++;
847 * Check the network map and determine whether the supplied node name is
848 * valid. If it is not a neighbor node, supply the name of a neighbor node
849 * which is the next hop. If it *is* a neighbor node, we also fill in the
852 int CtdlIsValidNode(const StrBuf **nexthop,
853 const StrBuf **secret,
856 HashList *the_netmap)
860 CtdlNodeConf *TheNode;
861 CtdlNetMap *TheNetMap;
863 if (StrLength(node) == 0) {
868 * First try the neighbor nodes
870 if (GetCount(IgnetCfg) == 0) {
871 syslog(LOG_INFO, "IgnetCfg is empty!");
872 if (nexthop != NULL) {
878 /* try to find a neigbour with the name 'node' */
879 if (GetHash(IgnetCfg, SKEY(node), &vNodeConf) &&
882 TheNode = (CtdlNodeConf*)vNodeConf;
884 *secret = TheNode->Secret;
885 return 0; /* yup, it's a direct neighbor */
889 * If we get to this point we have to see if we know the next hop
890 *//* TODO: is the NodeName Uniq? */
891 if ((GetCount(the_netmap) > 0) &&
892 (GetHash(the_netmap, SKEY(node), &vNetMap)))
894 TheNetMap = (CtdlNetMap*)vNetMap;
896 *nexthop = TheNetMap->NextHop;
901 * If we get to this point, the supplied node name is bogus.
903 syslog(LOG_ERR, "Invalid node name <%s>", ChrPtr(node));
909 * Convert any legacy configuration files in the "netconfigs" directory
911 void convert_legacy_netcfg_files(void)
914 struct dirent *dit = NULL;
915 char filename[PATH_MAX];
921 dh = opendir(ctdl_netcfg_dir);
924 syslog(LOG_INFO, "Legacy netconfig files exist - converting them!");
926 while (dit = readdir(dh), dit != NULL) { // yes, we use the non-reentrant version; we're not in threaded mode yet
927 roomnum = atol(dit->d_name);
929 snprintf(filename, sizeof filename, "%s/%ld", ctdl_netcfg_dir, roomnum);
930 fp = fopen(filename, "r");
932 fseek(fp, 0L, SEEK_END);
938 if (fread(v, len, 1, fp)) {
939 write_netconfig_to_configdb(roomnum, v);
946 unlink(filename); // zero length netconfig, just delete it
954 rmdir(ctdl_netcfg_dir);
962 CTDL_MODULE_INIT(netconfig)
966 convert_legacy_netcfg_files();
967 CtdlRegisterProtoHook(cmd_gnet, "GNET", "Get network config");
968 CtdlRegisterProtoHook(cmd_snet, "SNET", "Set network config");
969 CtdlRegisterProtoHook(cmd_netp, "NETP", "Identify as network poller");