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>
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);
62 Put(CfgTypeHash, Name, len, pCfg, NULL);
66 const CfgLineType *GetCfgTypeByStr(const char *Key, long len)
70 if (GetHash(CfgTypeHash, Key, len, &pv) && (pv != NULL))
72 return (const CfgLineType *) pv;
80 const CfgLineType *GetCfgTypeByEnum(RoomNetCfg eCfg, HashPos *It)
87 RewindHashPos(CfgTypeHash, It, 1);
88 while (GetNextHashPos(CfgTypeHash, It, &len, &Key, &pv) && (pv != NULL))
90 pCfg = (CfgLineType*) pv;
97 void ParseGeneric(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *OneRNCfg)
102 nptr = (RoomNetCfgLine *)
103 malloc(sizeof(RoomNetCfgLine));
104 nptr->next = OneRNCfg->NetConfigs[ThisOne->C];
105 nptr->Value = malloc(sizeof(StrBuf*) * ThisOne->nSegments);
107 memset(nptr->Value, 0, sizeof(StrBuf*) * ThisOne->nSegments);
108 if (ThisOne->nSegments == 1)
110 nptr->Value[0] = NewStrBufPlain(LinePos, StrLength(Line) - ( LinePos - ChrPtr(Line)) );
113 else for (i = 0; i < ThisOne->nSegments; i++)
116 nptr->Value[i] = NewStrBufPlain(NULL, StrLength(Line) - ( LinePos - ChrPtr(Line)) );
117 StrBufExtract_NextToken(nptr->Value[i], Line, &LinePos, '|');
120 OneRNCfg->NetConfigs[ThisOne->C] = nptr;
123 void SerializeGeneric(const CfgLineType *ThisOne, StrBuf *OutputBuffer, OneRoomNetCfg *OneRNCfg, RoomNetCfgLine *data)
127 StrBufAppendBufPlain(OutputBuffer, CKEY(ThisOne->Str), 0);
128 StrBufAppendBufPlain(OutputBuffer, HKEY("|"), 0);
129 for (i = 0; i < ThisOne->nSegments; i++)
131 StrBufAppendBuf(OutputBuffer, data->Value[i], 0);
132 if (i + 1 < ThisOne->nSegments)
133 StrBufAppendBufPlain(OutputBuffer, HKEY("|"), 0);
135 StrBufAppendBufPlain(OutputBuffer, HKEY("\n"), 0);
138 void DeleteGenericCfgLine(const CfgLineType *ThisOne, RoomNetCfgLine **data)
145 for (i = 0; i < (*data)->nValues; i++)
147 FreeStrBuf(&(*data)->Value[i]);
149 free ((*data)->Value);
154 RoomNetCfgLine *DuplicateOneGenericCfgLine(const RoomNetCfgLine *data)
157 RoomNetCfgLine *NewData;
159 NewData = (RoomNetCfgLine*)malloc(sizeof(RoomNetCfgLine));
160 memset(NewData, 0, sizeof(RoomNetCfgLine));
161 NewData->Value = (StrBuf **)malloc(sizeof(StrBuf*) * data->nValues);
162 memset(NewData->Value, 0, sizeof(StrBuf*) * data->nValues);
164 for (i = 0; i < data->nValues; i++)
166 NewData->Value[i] = NewStrBufDup(data->Value[i]);
168 NewData->nValues = data->nValues;
174 * Create a config key for a room's netconfig entry
176 void netcfg_keyname(char *keybuf, long roomnum)
179 sprintf(keybuf, "c_netconfig_%010ld", roomnum);
185 * Given a room number and a textual netconfig, convert to base64 and write to the configdb
187 void write_netconfig_to_configdb(long roomnum, const char *raw_netconfig)
194 len = strlen(raw_netconfig);
195 netcfg_keyname(keyname, roomnum);
196 enc = malloc(len * 2);
199 enc_len = CtdlEncodeBase64(enc, raw_netconfig, len, 0);
200 if ((enc_len > 1) && (enc[enc_len-2] == 13)) enc[enc_len-2] = 0;
201 if ((enc_len > 0) && (enc[enc_len-1] == 10)) enc[enc_len-1] = 0;
203 syslog(LOG_DEBUG, "Writing key '%s' (length=%d)", keyname, enc_len);
204 CtdlSetConfigStr(keyname, enc);
212 * Given a room number, attempt to load the netconfig configdb entry for that room.
213 * If it returns NULL, there is no netconfig.
214 * Otherwise the caller owns the returned memory and is responsible for freeing it.
216 char *LoadRoomNetConfigFile(long roomnum)
219 char *encoded_netconfig = NULL;
220 char *decoded_netconfig = NULL;
222 netcfg_keyname(keyname, roomnum);
223 encoded_netconfig = CtdlGetConfigStr(keyname);
224 if (!encoded_netconfig) return NULL;
226 decoded_netconfig = malloc(strlen(encoded_netconfig)); // yeah, way bigger than it needs to be, but safe
227 CtdlDecodeBase64(decoded_netconfig, encoded_netconfig, strlen(encoded_netconfig));
228 return decoded_netconfig;
233 * Deserialize a netconfig , allocate and return structured data
235 OneRoomNetCfg *ParseRoomNetConfigFile(char *serialized_data)
237 const char *Pos = NULL;
238 const char *CPos = NULL;
239 const CfgLineType *pCfg = NULL;
241 StrBuf *InStr = NULL;
243 OneRoomNetCfg *OneRNCfg = NULL;
245 OneRNCfg = malloc(sizeof(OneRoomNetCfg));
246 memset(OneRNCfg, 0, sizeof(OneRoomNetCfg));
250 Cfg = NewStrBufPlain(serialized_data, -1);
252 while (StrBufSipLine(Line, Cfg, &CPos)) {
254 if (StrLength(Line) > 0) {
256 StrBufExtract_NextToken(InStr, Line, &Pos, '|');
258 pCfg = GetCfgTypeByStr(SKEY(InStr));
261 pCfg->Parser(pCfg, Line, Pos, OneRNCfg);
265 if (OneRNCfg->misc == NULL)
267 OneRNCfg->misc = NewStrBufDup(Line);
271 if (StrLength(OneRNCfg->misc) > 0) {
272 StrBufAppendBufPlain(OneRNCfg->misc, HKEY("\n"), 0);
274 StrBufAppendBuf(OneRNCfg->misc, Line, 0);
286 void SaveRoomNetConfigFile(OneRoomNetCfg *OneRNCfg, long roomnum)
290 StrBuf *OutBuffer = NULL;
294 OutBuffer = NewStrBuf();
295 CfgIt = GetNewHashPos(CfgTypeHash, 1);
296 for (eCfg = subpending; eCfg < maxRoomNetCfg; eCfg ++)
298 const CfgLineType *pCfg;
299 pCfg = GetCfgTypeByEnum(eCfg, CfgIt);
300 if (pCfg->IsSingleLine)
302 pCfg->Serializer(pCfg, OutBuffer, OneRNCfg, NULL);
306 RoomNetCfgLine *pName = OneRNCfg->NetConfigs[pCfg->C];
307 while (pName != NULL)
309 pCfg->Serializer(pCfg, OutBuffer, OneRNCfg, pName);
317 DeleteHashPos(&CfgIt);
319 if (OneRNCfg->misc != NULL) {
320 StrBufAppendBuf(OutBuffer, OneRNCfg->misc, 0);
323 write_netconfig_to_configdb(roomnum, ChrPtr(OutBuffer));
325 FreeStrBuf(&OutBuffer);
331 void AddRoomCfgLine(OneRoomNetCfg *OneRNCfg, struct ctdlroom *qrbuf, RoomNetCfg LineType, RoomNetCfgLine *Line)
333 RoomNetCfgLine **pLine;
335 if (OneRNCfg == NULL)
337 OneRNCfg = (OneRoomNetCfg*) malloc(sizeof(OneRoomNetCfg));
338 memset(OneRNCfg, 0, sizeof(OneRoomNetCfg));
340 pLine = &OneRNCfg->NetConfigs[LineType];
342 while(*pLine != NULL) pLine = &((*pLine)->next);
347 void FreeRoomNetworkStructContent(OneRoomNetCfg *OneRNCfg)
352 CfgIt = GetNewHashPos(CfgTypeHash, 1);
353 for (eCfg = subpending; eCfg < maxRoomNetCfg; eCfg ++)
355 const CfgLineType *pCfg;
356 RoomNetCfgLine *pNext, *pName;
358 pCfg = GetCfgTypeByEnum(eCfg, CfgIt);
359 pName= OneRNCfg->NetConfigs[eCfg];
360 while (pName != NULL)
365 pCfg->DeAllocator(pCfg, &pName);
369 DeleteGenericCfgLine(NULL, &pName);
374 DeleteHashPos(&CfgIt);
376 FreeStrBuf(&OneRNCfg->Sender);
377 FreeStrBuf(&OneRNCfg->RoomInfo);
378 FreeStrBuf(&OneRNCfg->misc);
379 memset(OneRNCfg, 0, sizeof(OneRoomNetCfg));
383 void vFreeRoomNetworkStruct(void *vOneRoomNetCfg)
385 OneRoomNetCfg *OneRNCfg;
386 OneRNCfg = (OneRoomNetCfg*)vOneRoomNetCfg;
387 FreeRoomNetworkStructContent(OneRNCfg);
392 void FreeRoomNetworkStruct(OneRoomNetCfg **pOneRNCfg)
394 vFreeRoomNetworkStruct(*pOneRNCfg);
400 * Fetch the netconfig entry for a room, parse it, and return the data.
401 * Caller owns the returned memory and MUST free it using FreeRoomNetworkStruct()
403 OneRoomNetCfg *CtdlGetNetCfgForRoom(long roomnum)
405 OneRoomNetCfg *OneRNCfg = NULL;
406 char *serialized_config = NULL;
408 serialized_config = LoadRoomNetConfigFile(roomnum);
409 if (!serialized_config) return NULL;
411 OneRNCfg = ParseRoomNetConfigFile(serialized_config);
412 free(serialized_config);
417 /*-----------------------------------------------------------------------------*
418 * Per room network configs : exchange with client *
419 *-----------------------------------------------------------------------------*/
421 void cmd_gnet(char *argbuf)
423 if ( (CC->room.QRflags & QR_MAILBOX) && (CC->user.usernum == atol(CC->room.QRname)) ) {
424 /* users can edit the netconfigs for their own mailbox rooms */
426 else if (CtdlAccessCheck(ac_room_aide)) return;
428 cprintf("%d Network settings for room #%ld <%s>\n", LISTING_FOLLOWS, CC->room.QRnumber, CC->room.QRname);
430 char *c = LoadRoomNetConfigFile(CC->room.QRnumber);
439 void cmd_snet(char *argbuf)
441 struct CitContext *CCC = CC;
443 StrBuf *TheConfig = NULL;
448 TheConfig = NewStrBuf();
449 cprintf("%d send new netconfig now\n", SEND_LISTING);
451 while (rc = CtdlClientGetLine(Line), (rc >= 0))
453 if ((rc == 3) && (strcmp(ChrPtr(Line), "000") == 0))
456 StrBufAppendBuf(TheConfig, Line, 0);
457 StrBufAppendBufPlain(TheConfig, HKEY("\n"), 0);
461 write_netconfig_to_configdb(CCC->room.QRnumber, ChrPtr(TheConfig));
462 FreeStrBuf(&TheConfig);
466 /*-----------------------------------------------------------------------------*
467 * Per node network configs *
468 *-----------------------------------------------------------------------------*/
469 void DeleteCtdlNodeConf(void *vNode)
471 CtdlNodeConf *Node = (CtdlNodeConf*) vNode;
472 FreeStrBuf(&Node->NodeName);
473 FreeStrBuf(&Node->Secret);
474 FreeStrBuf(&Node->Host);
475 FreeStrBuf(&Node->Port);
479 CtdlNodeConf *NewNode(StrBuf *SerializedNode)
481 const char *Pos = NULL;
484 /* we need at least 4 pipes and some other text so its invalid. */
485 if (StrLength(SerializedNode) < 8)
487 Node = (CtdlNodeConf *) malloc(sizeof(CtdlNodeConf));
491 Node->NodeName=NewStrBuf();
492 StrBufExtract_NextToken(Node->NodeName, SerializedNode, &Pos, '|');
494 Node->Secret=NewStrBuf();
495 StrBufExtract_NextToken(Node->Secret, SerializedNode, &Pos, '|');
497 Node->Host=NewStrBuf();
498 StrBufExtract_NextToken(Node->Host, SerializedNode, &Pos, '|');
500 Node->Port=NewStrBuf();
501 StrBufExtract_NextToken(Node->Port, SerializedNode, &Pos, '|');
507 * Load or refresh the Citadel network (IGnet) configuration for this node.
509 HashList* CtdlLoadIgNetCfg(void)
518 Cfg = CtdlGetSysConfig(IGNETCFG);
519 if ((Cfg == NULL) || IsEmptyStr(Cfg)) {
525 Hash = NewHash(1, NULL);
526 Buf = NewStrBufPlain(Cfg, -1);
528 LineBuf = NewStrBufPlain(NULL, StrLength(Buf));
532 StrBufSipLine(LineBuf, Buf, &LinePos);
533 if (StrLength(LineBuf) != 0) {
534 Node = NewNode(LineBuf);
536 Put(Hash, SKEY(Node->NodeName), Node, DeleteCtdlNodeConf);
539 } while (LinePos != StrBufNOTNULL);
541 FreeStrBuf(&LineBuf);
546 int is_recipient(OneRoomNetCfg *RNCfg, const char *Name)
548 const RoomNetCfg RecipientCfgs[] = {
555 RoomNetCfgLine *nptr;
560 while (RecipientCfgs[i] != maxRoomNetCfg)
562 nptr = RNCfg->NetConfigs[RecipientCfgs[i]];
566 if ((StrLength(nptr->Value[0]) == len) &&
567 (!strcmp(Name, ChrPtr(nptr->Value[0]))))
580 int CtdlNetconfigCheckRoomaccess(
583 const char* RemoteIdentifier)
585 OneRoomNetCfg *RNCfg;
588 if (RemoteIdentifier == NULL)
590 snprintf(errmsgbuf, n, "Need sender to permit access.");
591 return (ERROR + USERNAME_REQUIRED);
594 begin_critical_section(S_NETCONFIGS);
595 RNCfg = CtdlGetNetCfgForRoom (CC->room.QRnumber);
598 end_critical_section(S_NETCONFIGS);
599 snprintf(errmsgbuf, n,
600 "This mailing list only accepts posts from subscribers.");
601 return (ERROR + NO_SUCH_USER);
603 found = is_recipient (RNCfg, RemoteIdentifier);
604 FreeRoomNetworkStruct(&RNCfg);
605 end_critical_section(S_NETCONFIGS);
611 snprintf(errmsgbuf, n,
612 "This mailing list only accepts posts from subscribers.");
613 return (ERROR + NO_SUCH_USER);
620 * cmd_netp() - authenticate to the server as another Citadel node polling
621 * for network traffic
623 void cmd_netp(char *cmdbuf)
625 struct CitContext *CCC = CC;
626 HashList *working_ignetcfg;
634 const StrBuf *secret = NULL;
635 const StrBuf *nexthop = NULL;
636 char err_buf[SIZ] = "";
639 node = CCC->curr_user;
640 nodelen = extract_token(CCC->curr_user, cmdbuf, 0, '|', sizeof CCC->curr_user);
641 NodeStr = NewStrBufPlain(node, nodelen);
642 /* load the IGnet Configuration to check node validity */
643 working_ignetcfg = CtdlLoadIgNetCfg();
644 v = CtdlIsValidNode(&nexthop, &secret, NodeStr, working_ignetcfg, NULL);
646 snprintf(err_buf, sizeof err_buf,
647 "An unknown Citadel server called \"%s\" attempted to connect from %s [%s].\n",
648 node, CCC->cs_host, CCC->cs_addr
650 syslog(LOG_WARNING, "%s", err_buf);
651 cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
653 strs[0] = CCC->cs_addr;
654 lens[0] = strlen(CCC->cs_addr);
656 strs[1] = "SRV_UNKNOWN";
657 lens[1] = sizeof("SRV_UNKNOWN") - 1;
662 2, strs, (long*) &lens,
666 DeleteHash(&working_ignetcfg);
667 FreeStrBuf(&NodeStr);
671 extract_token(CCC->user.password, cmdbuf, 1, '|', sizeof CCC->user.password);
672 if (strcasecmp(CCC->user.password, ChrPtr(secret))) {
673 snprintf(err_buf, sizeof err_buf,
674 "A Citadel server at %s [%s] failed to authenticate as network node \"%s\".\n",
675 CCC->cs_host, CCC->cs_addr, node
677 syslog(LOG_WARNING, "%s", err_buf);
678 cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
680 strs[0] = CCC->cs_addr;
681 lens[0] = strlen(CCC->cs_addr);
684 lens[1] = sizeof("SRV_PW") - 1;
694 DeleteHash(&working_ignetcfg);
695 FreeStrBuf(&NodeStr);
699 if (CtdlNetworkTalkingTo(node, nodelen, NTT_CHECK)) {
700 syslog(LOG_WARNING, "Duplicate session for network node <%s>", node);
701 cprintf("%d Already talking to %s right now\n", ERROR + RESOURCE_BUSY, node);
702 DeleteHash(&working_ignetcfg);
703 FreeStrBuf(&NodeStr);
706 nodelen = safestrncpy(CCC->net_node, node, sizeof CCC->net_node);
707 CtdlNetworkTalkingTo(CCC->net_node, nodelen, NTT_ADD);
708 syslog(LOG_NOTICE, "Network node <%s> logged in from %s [%s]",
709 CCC->net_node, CCC->cs_host, CCC->cs_addr
711 cprintf("%d authenticated as network node '%s'\n", CIT_OK, CCC->net_node);
712 DeleteHash(&working_ignetcfg);
713 FreeStrBuf(&NodeStr);
717 /*-----------------------------------------------------------------------------*
718 * Network maps: evaluate other nodes *
719 *-----------------------------------------------------------------------------*/
721 void DeleteNetMap(void *vNetMap)
723 CtdlNetMap *TheNetMap = (CtdlNetMap*) vNetMap;
724 FreeStrBuf(&TheNetMap->NodeName);
725 FreeStrBuf(&TheNetMap->NextHop);
729 CtdlNetMap *NewNetMap(StrBuf *SerializedNetMap)
731 const char *Pos = NULL;
734 /* we need at least 3 pipes and some other text so its invalid. */
735 if (StrLength(SerializedNetMap) < 6)
737 NM = (CtdlNetMap *) malloc(sizeof(CtdlNetMap));
739 NM->NodeName=NewStrBuf();
740 StrBufExtract_NextToken(NM->NodeName, SerializedNetMap, &Pos, '|');
742 NM->lastcontact = StrBufExtractNext_long(SerializedNetMap, &Pos, '|');
744 NM->NextHop=NewStrBuf();
745 StrBufExtract_NextToken(NM->NextHop, SerializedNetMap, &Pos, '|');
750 HashList* CtdlReadNetworkMap(void)
757 CtdlNetMap *TheNetMap;
759 Hash = NewHash(1, NULL);
760 Cfg = CtdlGetSysConfig(IGNETMAP);
761 if ((Cfg == NULL) || IsEmptyStr(Cfg)) {
767 Buf = NewStrBufPlain(Cfg, -1);
769 LineBuf = NewStrBufPlain(NULL, StrLength(Buf));
771 while (StrBufSipLine(Buf, LineBuf, &LinePos))
773 TheNetMap = NewNetMap(LineBuf);
774 if (TheNetMap != NULL) { /* TODO: is the NodeName Uniq? */
775 Put(Hash, SKEY(TheNetMap->NodeName), TheNetMap, DeleteNetMap);
779 FreeStrBuf(&LineBuf);
783 StrBuf *CtdlSerializeNetworkMap(HashList *Map)
788 StrBuf *Ret = NewStrBuf();
789 HashPos *Pos = GetNewHashPos(Map, 0);
791 while (GetNextHashPos(Map, Pos, &len, &key, &vMap))
793 CtdlNetMap *pMap = (CtdlNetMap*) vMap;
794 StrBufAppendBuf(Ret, pMap->NodeName, 0);
795 StrBufAppendBufPlain(Ret, HKEY("|"), 0);
797 StrBufAppendPrintf(Ret, "%ld", pMap->lastcontact, 0);
798 StrBufAppendBufPlain(Ret, HKEY("|"), 0);
800 StrBufAppendBuf(Ret, pMap->NextHop, 0);
801 StrBufAppendBufPlain(Ret, HKEY("\n"), 0);
809 * Learn topology from path fields
811 void NetworkLearnTopology(char *node, char *path, HashList *the_netmap, int *netmap_changed)
813 CtdlNetMap *pNM = NULL;
818 if (GetHash(the_netmap, node, strlen(node), &vptr) &&
819 (vptr != NULL))/* TODO: is the NodeName Uniq? */
821 pNM = (CtdlNetMap*)vptr;
822 extract_token(nexthop, path, 0, '!', sizeof nexthop);
823 if (!strcmp(nexthop, ChrPtr(pNM->NextHop))) {
824 pNM->lastcontact = time(NULL);
825 (*netmap_changed) ++;
830 /* If we got here then it's not in the map, so add it. */
831 nmptr = (CtdlNetMap *) malloc(sizeof (CtdlNetMap));
832 nmptr->NodeName = NewStrBufPlain(node, -1);
833 nmptr->lastcontact = time(NULL);
834 nmptr->NextHop = NewStrBuf ();
835 StrBufExtract_tokenFromStr(nmptr->NextHop, path, strlen(path), 0, '!');
836 /* TODO: is the NodeName Uniq? */
837 Put(the_netmap, SKEY(nmptr->NodeName), nmptr, DeleteNetMap);
838 (*netmap_changed) ++;
843 * Check the network map and determine whether the supplied node name is
844 * valid. If it is not a neighbor node, supply the name of a neighbor node
845 * which is the next hop. If it *is* a neighbor node, we also fill in the
848 int CtdlIsValidNode(const StrBuf **nexthop,
849 const StrBuf **secret,
852 HashList *the_netmap)
856 CtdlNodeConf *TheNode;
857 CtdlNetMap *TheNetMap;
859 if (StrLength(node) == 0) {
864 * First try the neighbor nodes
866 if (GetCount(IgnetCfg) == 0) {
867 syslog(LOG_INFO, "IgnetCfg is empty!");
868 if (nexthop != NULL) {
874 /* try to find a neigbour with the name 'node' */
875 if (GetHash(IgnetCfg, SKEY(node), &vNodeConf) &&
878 TheNode = (CtdlNodeConf*)vNodeConf;
880 *secret = TheNode->Secret;
881 return 0; /* yup, it's a direct neighbor */
885 * If we get to this point we have to see if we know the next hop
886 *//* TODO: is the NodeName Uniq? */
887 if ((GetCount(the_netmap) > 0) &&
888 (GetHash(the_netmap, SKEY(node), &vNetMap)))
890 TheNetMap = (CtdlNetMap*)vNetMap;
892 *nexthop = TheNetMap->NextHop;
897 * If we get to this point, the supplied node name is bogus.
899 syslog(LOG_ERR, "Invalid node name <%s>", ChrPtr(node));
905 * Convert any legacy configuration files in the "netconfigs" directory
907 void convert_legacy_netcfg_files(void)
910 struct dirent *dit = NULL;
911 char filename[PATH_MAX];
917 dh = opendir(ctdl_netcfg_dir);
920 syslog(LOG_INFO, "Legacy netconfig files exist - converting them!");
922 while (dit = readdir(dh), dit != NULL) { // yes, we use the non-reentrant version; we're not in threaded mode yet
923 roomnum = atol(dit->d_name);
925 snprintf(filename, sizeof filename, "%s/%ld", ctdl_netcfg_dir, roomnum);
926 fp = fopen(filename, "r");
928 fseek(fp, 0L, SEEK_END);
934 if (fread(v, len, 1, fp)) {
935 write_netconfig_to_configdb(roomnum, v);
942 unlink(filename); // zero length netconfig, just delete it
950 rmdir(ctdl_netcfg_dir);
958 CTDL_MODULE_INIT(netconfig)
962 convert_legacy_netcfg_files();
963 CtdlRegisterProtoHook(cmd_gnet, "GNET", "Get network config");
964 CtdlRegisterProtoHook(cmd_snet, "SNET", "Set network config");
965 CtdlRegisterProtoHook(cmd_netp, "NETP", "Identify as network poller");