2 * This module handles loading, saving, and parsing of room network configurations.
4 * Copyright (c) 2000-2017 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
18 #include <sys/types.h>
24 # if HAVE_SYS_SYSCALL_H
25 # include <sys/syscall.h>
31 #include <libcitadel.h>
33 #include "include/ctdl_module.h"
34 #include "serv_extensions.h"
37 void vFreeRoomNetworkStruct(void *vOneRoomNetCfg);
38 void FreeRoomNetworkStructContent(OneRoomNetCfg *OneRNCfg);
40 HashList *CfgTypeHash = NULL;
42 /*-----------------------------------------------------------------------------*
43 * Per room network configs *
44 *-----------------------------------------------------------------------------*/
47 void RegisterRoomCfgType(const char* Name, long len, RoomNetCfg eCfg, CfgLineParser p, int uniq, int nSegments, CfgLineSerializer s, CfgLineDeAllocator d)
51 pCfg = (CfgLineType*) malloc(sizeof(CfgLineType));
54 pCfg->DeAllocator = d;
58 pCfg->IsSingleLine = uniq;
59 pCfg->nSegments = nSegments;
60 if (CfgTypeHash == NULL) {
61 CfgTypeHash = NewHash(1, NULL);
63 Put(CfgTypeHash, Name, len, pCfg, NULL);
67 const CfgLineType *GetCfgTypeByStr(const char *Key, long len)
71 if (GetHash(CfgTypeHash, Key, len, &pv) && (pv != NULL))
73 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;
100 void ParseGeneric(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *OneRNCfg)
102 RoomNetCfgLine *nptr;
105 nptr = (RoomNetCfgLine *)
106 malloc(sizeof(RoomNetCfgLine));
107 nptr->next = OneRNCfg->NetConfigs[ThisOne->C];
108 nptr->Value = malloc(sizeof(StrBuf*) * ThisOne->nSegments);
110 memset(nptr->Value, 0, sizeof(StrBuf*) * ThisOne->nSegments);
111 if (ThisOne->nSegments == 1)
113 nptr->Value[0] = NewStrBufPlain(LinePos, StrLength(Line) - ( LinePos - ChrPtr(Line)) );
116 else for (i = 0; i < ThisOne->nSegments; i++)
119 nptr->Value[i] = NewStrBufPlain(NULL, StrLength(Line) - ( LinePos - ChrPtr(Line)) );
120 StrBufExtract_NextToken(nptr->Value[i], Line, &LinePos, '|');
123 OneRNCfg->NetConfigs[ThisOne->C] = nptr;
127 void SerializeGeneric(const CfgLineType *ThisOne, StrBuf *OutputBuffer, OneRoomNetCfg *OneRNCfg, RoomNetCfgLine *data)
131 StrBufAppendBufPlain(OutputBuffer, CKEY(ThisOne->Str), 0);
132 StrBufAppendBufPlain(OutputBuffer, HKEY("|"), 0);
133 for (i = 0; i < ThisOne->nSegments; i++)
135 StrBufAppendBuf(OutputBuffer, data->Value[i], 0);
136 if (i + 1 < ThisOne->nSegments)
137 StrBufAppendBufPlain(OutputBuffer, HKEY("|"), 0);
139 StrBufAppendBufPlain(OutputBuffer, HKEY("\n"), 0);
143 void DeleteGenericCfgLine(const CfgLineType *ThisOne, RoomNetCfgLine **data)
150 for (i = 0; i < (*data)->nValues; i++)
152 FreeStrBuf(&(*data)->Value[i]);
154 free ((*data)->Value);
160 RoomNetCfgLine *DuplicateOneGenericCfgLine(const RoomNetCfgLine *data)
163 RoomNetCfgLine *NewData;
165 NewData = (RoomNetCfgLine*)malloc(sizeof(RoomNetCfgLine));
166 memset(NewData, 0, sizeof(RoomNetCfgLine));
167 NewData->Value = (StrBuf **)malloc(sizeof(StrBuf*) * data->nValues);
168 memset(NewData->Value, 0, sizeof(StrBuf*) * data->nValues);
170 for (i = 0; i < data->nValues; i++)
172 NewData->Value[i] = NewStrBufDup(data->Value[i]);
174 NewData->nValues = data->nValues;
180 * Create a config key for a room's netconfig entry
182 void netcfg_keyname(char *keybuf, long roomnum)
185 sprintf(keybuf, "c_netconfig_%010ld", roomnum);
190 * Given a room number and a textual netconfig, convert to base64 and write to the configdb
192 void write_netconfig_to_configdb(long roomnum, const char *raw_netconfig)
199 len = strlen(raw_netconfig);
200 netcfg_keyname(keyname, roomnum);
201 enc = malloc(len * 2);
204 enc_len = CtdlEncodeBase64(enc, raw_netconfig, len, 0);
205 if ((enc_len > 1) && (enc[enc_len-2] == 13)) enc[enc_len-2] = 0;
206 if ((enc_len > 0) && (enc[enc_len-1] == 10)) enc[enc_len-1] = 0;
208 syslog(LOG_DEBUG, "netconfig: writing key '%s' (length=%d)", keyname, enc_len);
209 CtdlSetConfigStr(keyname, enc);
216 * Given a room number, attempt to load the netconfig configdb entry for that room.
217 * If it returns NULL, there is no netconfig.
218 * Otherwise the caller owns the returned memory and is responsible for freeing it.
220 char *LoadRoomNetConfigFile(long roomnum)
223 char *encoded_netconfig = NULL;
224 char *decoded_netconfig = NULL;
226 netcfg_keyname(keyname, roomnum);
227 encoded_netconfig = CtdlGetConfigStr(keyname);
228 if (!encoded_netconfig) return NULL;
230 decoded_netconfig = malloc(strlen(encoded_netconfig)); // yeah, way bigger than it needs to be, but safe
231 CtdlDecodeBase64(decoded_netconfig, encoded_netconfig, strlen(encoded_netconfig));
232 return decoded_netconfig;
237 * Deserialize a netconfig , allocate and return structured data
239 OneRoomNetCfg *ParseRoomNetConfigFile(char *serialized_data)
241 const char *Pos = NULL;
242 const CfgLineType *pCfg = NULL;
244 StrBuf *InStr = NULL;
246 OneRoomNetCfg *OneRNCfg = NULL;
250 OneRNCfg = malloc(sizeof(OneRoomNetCfg));
251 memset(OneRNCfg, 0, sizeof(OneRoomNetCfg));
255 Cfg = NewStrBufPlain(serialized_data, -1);
256 num_lines = num_tokens(ChrPtr(Cfg), '\n');
258 for (i=0; i<num_lines; ++i) {
259 StrBufExtract_token(Line, Cfg, i, '\n');
260 if (StrLength(Line) > 0) {
262 StrBufExtract_NextToken(InStr, Line, &Pos, '|');
264 pCfg = GetCfgTypeByStr(SKEY(InStr));
267 pCfg->Parser(pCfg, Line, Pos, OneRNCfg);
271 if (OneRNCfg->misc == NULL)
273 OneRNCfg->misc = NewStrBufDup(Line);
277 if (StrLength(OneRNCfg->misc) > 0) {
278 StrBufAppendBufPlain(OneRNCfg->misc, HKEY("\n"), 0);
280 StrBufAppendBuf(OneRNCfg->misc, Line, 0);
292 void SaveRoomNetConfigFile(OneRoomNetCfg *OneRNCfg, long roomnum)
296 StrBuf *OutBuffer = NULL;
300 OutBuffer = NewStrBuf();
301 CfgIt = GetNewHashPos(CfgTypeHash, 1);
302 for (eCfg = subpending; eCfg < maxRoomNetCfg; eCfg ++)
304 const CfgLineType *pCfg;
305 pCfg = GetCfgTypeByEnum(eCfg, CfgIt);
308 if (pCfg->IsSingleLine)
310 pCfg->Serializer(pCfg, OutBuffer, OneRNCfg, NULL);
314 RoomNetCfgLine *pName = OneRNCfg->NetConfigs[pCfg->C];
315 while (pName != NULL)
317 pCfg->Serializer(pCfg, OutBuffer, OneRNCfg, pName);
324 DeleteHashPos(&CfgIt);
326 if (OneRNCfg->misc != NULL) {
327 StrBufAppendBuf(OutBuffer, OneRNCfg->misc, 0);
330 write_netconfig_to_configdb(roomnum, ChrPtr(OutBuffer));
332 FreeStrBuf(&OutBuffer);
337 void AddRoomCfgLine(OneRoomNetCfg *OneRNCfg, struct ctdlroom *qrbuf, RoomNetCfg LineType, RoomNetCfgLine *Line)
339 RoomNetCfgLine **pLine;
341 if (OneRNCfg == NULL)
343 OneRNCfg = (OneRoomNetCfg*) malloc(sizeof(OneRoomNetCfg));
344 memset(OneRNCfg, 0, sizeof(OneRoomNetCfg));
346 pLine = &OneRNCfg->NetConfigs[LineType];
348 while(*pLine != NULL) pLine = &((*pLine)->next);
353 void FreeRoomNetworkStructContent(OneRoomNetCfg *OneRNCfg)
358 CfgIt = GetNewHashPos(CfgTypeHash, 1);
359 for (eCfg = subpending; eCfg < maxRoomNetCfg; eCfg ++)
361 const CfgLineType *pCfg;
362 RoomNetCfgLine *pNext, *pName;
364 pCfg = GetCfgTypeByEnum(eCfg, CfgIt);
365 pName= OneRNCfg->NetConfigs[eCfg];
366 while (pName != NULL)
371 pCfg->DeAllocator(pCfg, &pName);
375 DeleteGenericCfgLine(NULL, &pName);
380 DeleteHashPos(&CfgIt);
382 FreeStrBuf(&OneRNCfg->Sender);
383 FreeStrBuf(&OneRNCfg->RoomInfo);
384 FreeStrBuf(&OneRNCfg->misc);
385 memset(OneRNCfg, 0, sizeof(OneRoomNetCfg));
389 void vFreeRoomNetworkStruct(void *vOneRoomNetCfg)
391 OneRoomNetCfg *OneRNCfg;
392 OneRNCfg = (OneRoomNetCfg*)vOneRoomNetCfg;
393 FreeRoomNetworkStructContent(OneRNCfg);
398 void FreeRoomNetworkStruct(OneRoomNetCfg **pOneRNCfg)
400 vFreeRoomNetworkStruct(*pOneRNCfg);
406 * Fetch the netconfig entry for a room, parse it, and return the data.
407 * Caller owns the returned memory and MUST free it using FreeRoomNetworkStruct()
409 OneRoomNetCfg *CtdlGetNetCfgForRoom(long roomnum)
411 OneRoomNetCfg *OneRNCfg = NULL;
412 char *serialized_config = NULL;
414 serialized_config = LoadRoomNetConfigFile(roomnum);
415 if (!serialized_config) return NULL;
417 OneRNCfg = ParseRoomNetConfigFile(serialized_config);
418 free(serialized_config);
423 /*-----------------------------------------------------------------------------*
424 * Per room network configs : exchange with client *
425 *-----------------------------------------------------------------------------*/
427 void cmd_gnet(char *argbuf)
429 if ( (CC->room.QRflags & QR_MAILBOX) && (CC->user.usernum == atol(CC->room.QRname)) ) {
430 /* users can edit the netconfigs for their own mailbox rooms */
432 else if (CtdlAccessCheck(ac_room_aide)) return;
434 cprintf("%d Network settings for room #%ld <%s>\n", LISTING_FOLLOWS, CC->room.QRnumber, CC->room.QRname);
436 char *c = LoadRoomNetConfigFile(CC->room.QRnumber);
439 client_write(c, len); // Can't use cprintf() here, it has a limit of 1024 bytes
440 if (c[len] != '\n') {
441 client_write(HKEY("\n"));
449 void cmd_snet(char *argbuf)
451 struct CitContext *CCC = CC;
453 StrBuf *TheConfig = NULL;
458 TheConfig = NewStrBuf();
459 cprintf("%d send new netconfig now\n", SEND_LISTING);
461 while (rc = CtdlClientGetLine(Line), (rc >= 0))
463 if ((rc == 3) && (strcmp(ChrPtr(Line), "000") == 0))
466 StrBufAppendBuf(TheConfig, Line, 0);
467 StrBufAppendBufPlain(TheConfig, HKEY("\n"), 0);
471 write_netconfig_to_configdb(CCC->room.QRnumber, ChrPtr(TheConfig));
472 FreeStrBuf(&TheConfig);
476 /*-----------------------------------------------------------------------------*
477 * Per node network configs *
478 *-----------------------------------------------------------------------------*/
479 void DeleteCtdlNodeConf(void *vNode)
481 CtdlNodeConf *Node = (CtdlNodeConf*) vNode;
482 FreeStrBuf(&Node->NodeName);
483 FreeStrBuf(&Node->Secret);
484 FreeStrBuf(&Node->Host);
485 FreeStrBuf(&Node->Port);
490 CtdlNodeConf *NewNode(StrBuf *SerializedNode)
492 const char *Pos = NULL;
495 /* we need at least 4 pipes and some other text so its invalid. */
496 if (StrLength(SerializedNode) < 8)
498 Node = (CtdlNodeConf *) malloc(sizeof(CtdlNodeConf));
502 Node->NodeName=NewStrBuf();
503 StrBufExtract_NextToken(Node->NodeName, SerializedNode, &Pos, '|');
505 Node->Secret=NewStrBuf();
506 StrBufExtract_NextToken(Node->Secret, SerializedNode, &Pos, '|');
508 Node->Host=NewStrBuf();
509 StrBufExtract_NextToken(Node->Host, SerializedNode, &Pos, '|');
511 Node->Port=NewStrBuf();
512 StrBufExtract_NextToken(Node->Port, SerializedNode, &Pos, '|');
518 * Load or refresh the Citadel network (IGnet) configuration for this node.
520 HashList* CtdlLoadIgNetCfg(void)
529 Cfg = CtdlGetSysConfig(IGNETCFG);
530 if ((Cfg == NULL) || IsEmptyStr(Cfg)) {
536 Hash = NewHash(1, NULL);
537 Buf = NewStrBufPlain(Cfg, -1);
539 LineBuf = NewStrBufPlain(NULL, StrLength(Buf));
543 StrBufSipLine(LineBuf, Buf, &LinePos);
544 if (StrLength(LineBuf) != 0) {
545 Node = NewNode(LineBuf);
547 Put(Hash, SKEY(Node->NodeName), Node, DeleteCtdlNodeConf);
550 } while (LinePos != StrBufNOTNULL);
552 FreeStrBuf(&LineBuf);
557 int is_recipient(OneRoomNetCfg *RNCfg, const char *Name)
559 const RoomNetCfg RecipientCfgs[] = {
566 RoomNetCfgLine *nptr;
571 while (RecipientCfgs[i] != maxRoomNetCfg)
573 nptr = RNCfg->NetConfigs[RecipientCfgs[i]];
577 if ((StrLength(nptr->Value[0]) == len) &&
578 (!strcmp(Name, ChrPtr(nptr->Value[0]))))
590 int CtdlNetconfigCheckRoomaccess(char *errmsgbuf, size_t n, const char* RemoteIdentifier)
592 OneRoomNetCfg *RNCfg;
595 if (RemoteIdentifier == NULL)
597 snprintf(errmsgbuf, n, "Need sender to permit access.");
598 return (ERROR + USERNAME_REQUIRED);
601 begin_critical_section(S_NETCONFIGS);
602 RNCfg = CtdlGetNetCfgForRoom (CC->room.QRnumber);
605 end_critical_section(S_NETCONFIGS);
606 snprintf(errmsgbuf, n,
607 "This mailing list only accepts posts from subscribers.");
608 return (ERROR + NO_SUCH_USER);
610 found = is_recipient (RNCfg, RemoteIdentifier);
611 FreeRoomNetworkStruct(&RNCfg);
612 end_critical_section(S_NETCONFIGS);
618 snprintf(errmsgbuf, n,
619 "This mailing list only accepts posts from subscribers.");
620 return (ERROR + NO_SUCH_USER);
626 * cmd_netp() - authenticate to the server as another Citadel node polling
627 * for network traffic
629 void cmd_netp(char *cmdbuf)
631 struct CitContext *CCC = CC;
632 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, "netconfig: %s", err_buf);
655 cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
656 CtdlAideMessage(err_buf, "IGNet Networking");
657 DeleteHash(&working_ignetcfg);
658 FreeStrBuf(&NodeStr);
662 extract_token(CCC->user.password, cmdbuf, 1, '|', sizeof CCC->user.password);
663 if (strcasecmp(CCC->user.password, ChrPtr(secret))) {
664 snprintf(err_buf, sizeof err_buf,
665 "A Citadel server at %s [%s] failed to authenticate as network node \"%s\".\n",
666 CCC->cs_host, CCC->cs_addr, node
668 syslog(LOG_WARNING, "netconfig: %s", err_buf);
669 cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
671 CtdlAideMessage(err_buf, "IGNet Networking");
672 DeleteHash(&working_ignetcfg);
673 FreeStrBuf(&NodeStr);
677 if (CtdlNetworkTalkingTo(node, nodelen, NTT_CHECK)) {
678 syslog(LOG_WARNING, "netconfig: duplicate session for network node <%s>", node);
679 cprintf("%d Already talking to %s right now\n", ERROR + RESOURCE_BUSY, node);
680 DeleteHash(&working_ignetcfg);
681 FreeStrBuf(&NodeStr);
684 nodelen = safestrncpy(CCC->net_node, node, sizeof CCC->net_node);
685 CtdlNetworkTalkingTo(CCC->net_node, nodelen, NTT_ADD);
686 syslog(LOG_INFO, "netconfig: network node <%s> logged in from %s [%s]",
687 CCC->net_node, CCC->cs_host, CCC->cs_addr
689 cprintf("%d authenticated as network node '%s'\n", CIT_OK, CCC->net_node);
690 DeleteHash(&working_ignetcfg);
691 FreeStrBuf(&NodeStr);
695 /*-----------------------------------------------------------------------------*
696 * Network maps: evaluate other nodes *
697 *-----------------------------------------------------------------------------*/
699 void DeleteNetMap(void *vNetMap)
701 CtdlNetMap *TheNetMap = (CtdlNetMap*) vNetMap;
702 FreeStrBuf(&TheNetMap->NodeName);
703 FreeStrBuf(&TheNetMap->NextHop);
708 CtdlNetMap *NewNetMap(StrBuf *SerializedNetMap)
710 const char *Pos = NULL;
713 /* we need at least 3 pipes and some other text so its invalid. */
714 if (StrLength(SerializedNetMap) < 6)
716 NM = (CtdlNetMap *) malloc(sizeof(CtdlNetMap));
718 NM->NodeName=NewStrBuf();
719 StrBufExtract_NextToken(NM->NodeName, SerializedNetMap, &Pos, '|');
721 NM->lastcontact = StrBufExtractNext_long(SerializedNetMap, &Pos, '|');
723 NM->NextHop=NewStrBuf();
724 StrBufExtract_NextToken(NM->NextHop, SerializedNetMap, &Pos, '|');
730 HashList* CtdlReadNetworkMap(void)
737 CtdlNetMap *TheNetMap;
739 Hash = NewHash(1, NULL);
740 Cfg = CtdlGetSysConfig(IGNETMAP);
741 if ((Cfg == NULL) || IsEmptyStr(Cfg)) {
747 Buf = NewStrBufPlain(Cfg, -1);
749 LineBuf = NewStrBufPlain(NULL, StrLength(Buf));
751 while (StrBufSipLine(Buf, LineBuf, &LinePos))
753 TheNetMap = NewNetMap(LineBuf);
754 if (TheNetMap != NULL) { /* TODO: is the NodeName Uniq? */
755 Put(Hash, SKEY(TheNetMap->NodeName), TheNetMap, DeleteNetMap);
759 FreeStrBuf(&LineBuf);
764 StrBuf *CtdlSerializeNetworkMap(HashList *Map)
769 StrBuf *Ret = NewStrBuf();
770 HashPos *Pos = GetNewHashPos(Map, 0);
772 while (GetNextHashPos(Map, Pos, &len, &key, &vMap))
774 CtdlNetMap *pMap = (CtdlNetMap*) vMap;
775 StrBufAppendBuf(Ret, pMap->NodeName, 0);
776 StrBufAppendBufPlain(Ret, HKEY("|"), 0);
778 StrBufAppendPrintf(Ret, "%ld", pMap->lastcontact, 0);
779 StrBufAppendBufPlain(Ret, HKEY("|"), 0);
781 StrBufAppendBuf(Ret, pMap->NextHop, 0);
782 StrBufAppendBufPlain(Ret, HKEY("\n"), 0);
790 * Learn topology from path fields
792 void NetworkLearnTopology(char *node, char *path, HashList *the_netmap, int *netmap_changed)
794 CtdlNetMap *pNM = NULL;
799 if (GetHash(the_netmap, node, strlen(node), &vptr) &&
800 (vptr != NULL))/* TODO: is the NodeName Uniq? */
802 pNM = (CtdlNetMap*)vptr;
803 extract_token(nexthop, path, 0, '!', sizeof nexthop);
804 if (!strcmp(nexthop, ChrPtr(pNM->NextHop))) {
805 pNM->lastcontact = time(NULL);
806 (*netmap_changed) ++;
811 /* If we got here then it's not in the map, so add it. */
812 nmptr = (CtdlNetMap *) malloc(sizeof (CtdlNetMap));
813 nmptr->NodeName = NewStrBufPlain(node, -1);
814 nmptr->lastcontact = time(NULL);
815 nmptr->NextHop = NewStrBuf ();
816 StrBufExtract_tokenFromStr(nmptr->NextHop, path, strlen(path), 0, '!');
817 /* TODO: is the NodeName Uniq? */
818 Put(the_netmap, SKEY(nmptr->NodeName), nmptr, DeleteNetMap);
819 (*netmap_changed) ++;
824 * Check the network map and determine whether the supplied node name is
825 * valid. If it is not a neighbor node, supply the name of a neighbor node
826 * which is the next hop. If it *is* a neighbor node, we also fill in the
829 int CtdlIsValidNode(const StrBuf **nexthop,
830 const StrBuf **secret,
833 HashList *the_netmap)
837 CtdlNodeConf *TheNode;
838 CtdlNetMap *TheNetMap;
840 if (StrLength(node) == 0) {
845 * First try the neighbor nodes
847 if (GetCount(IgnetCfg) == 0) {
848 syslog(LOG_INFO, "netconfig: IgnetCfg is empty!");
849 if (nexthop != NULL) {
855 /* try to find a neigbour with the name 'node' */
856 if (GetHash(IgnetCfg, SKEY(node), &vNodeConf) &&
859 TheNode = (CtdlNodeConf*)vNodeConf;
861 *secret = TheNode->Secret;
862 return 0; /* yup, it's a direct neighbor */
866 * If we get to this point we have to see if we know the next hop
867 *//* TODO: is the NodeName Uniq? */
868 if ((GetCount(the_netmap) > 0) &&
869 (GetHash(the_netmap, SKEY(node), &vNetMap)))
871 TheNetMap = (CtdlNetMap*)vNetMap;
873 *nexthop = TheNetMap->NextHop;
878 * If we get to this point, the supplied node name is bogus.
880 syslog(LOG_ERR, "netconfig: invalid node name <%s>", ChrPtr(node));
886 * Convert any legacy configuration files in the "netconfigs" directory
888 void convert_legacy_netcfg_files(void)
891 struct dirent *dit = NULL;
892 char filename[PATH_MAX];
898 dh = opendir(ctdl_netcfg_dir);
901 syslog(LOG_INFO, "netconfig: legacy netconfig files exist - converting them!");
903 while (dit = readdir(dh), dit != NULL) { // yes, we use the non-reentrant version; we're not in threaded mode yet
904 roomnum = atol(dit->d_name);
906 snprintf(filename, sizeof filename, "%s/%ld", ctdl_netcfg_dir, roomnum);
907 fp = fopen(filename, "r");
909 fseek(fp, 0L, SEEK_END);
915 if (fread(v, len, 1, fp)) {
916 write_netconfig_to_configdb(roomnum, v);
923 unlink(filename); // zero length netconfig, just delete it
931 rmdir(ctdl_netcfg_dir);
938 CTDL_MODULE_INIT(netconfig)
942 convert_legacy_netcfg_files();
943 CtdlRegisterProtoHook(cmd_gnet, "GNET", "Get network config");
944 CtdlRegisterProtoHook(cmd_snet, "SNET", "Set network config");
945 CtdlRegisterProtoHook(cmd_netp, "NETP", "Identify as network poller");