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);
306 if (pCfg->IsSingleLine)
308 pCfg->Serializer(pCfg, OutBuffer, OneRNCfg, NULL);
312 RoomNetCfgLine *pName = OneRNCfg->NetConfigs[pCfg->C];
313 while (pName != NULL)
315 pCfg->Serializer(pCfg, OutBuffer, OneRNCfg, pName);
322 DeleteHashPos(&CfgIt);
324 if (OneRNCfg->misc != NULL) {
325 StrBufAppendBuf(OutBuffer, OneRNCfg->misc, 0);
328 write_netconfig_to_configdb(roomnum, ChrPtr(OutBuffer));
330 FreeStrBuf(&OutBuffer);
336 void AddRoomCfgLine(OneRoomNetCfg *OneRNCfg, struct ctdlroom *qrbuf, RoomNetCfg LineType, RoomNetCfgLine *Line)
338 RoomNetCfgLine **pLine;
340 if (OneRNCfg == NULL)
342 OneRNCfg = (OneRoomNetCfg*) malloc(sizeof(OneRoomNetCfg));
343 memset(OneRNCfg, 0, sizeof(OneRoomNetCfg));
345 pLine = &OneRNCfg->NetConfigs[LineType];
347 while(*pLine != NULL) pLine = &((*pLine)->next);
352 void FreeRoomNetworkStructContent(OneRoomNetCfg *OneRNCfg)
357 CfgIt = GetNewHashPos(CfgTypeHash, 1);
358 for (eCfg = subpending; eCfg < maxRoomNetCfg; eCfg ++)
360 const CfgLineType *pCfg;
361 RoomNetCfgLine *pNext, *pName;
363 pCfg = GetCfgTypeByEnum(eCfg, CfgIt);
364 pName= OneRNCfg->NetConfigs[eCfg];
365 while (pName != NULL)
370 pCfg->DeAllocator(pCfg, &pName);
374 DeleteGenericCfgLine(NULL, &pName);
379 DeleteHashPos(&CfgIt);
381 FreeStrBuf(&OneRNCfg->Sender);
382 FreeStrBuf(&OneRNCfg->RoomInfo);
383 FreeStrBuf(&OneRNCfg->misc);
384 memset(OneRNCfg, 0, sizeof(OneRoomNetCfg));
388 void vFreeRoomNetworkStruct(void *vOneRoomNetCfg)
390 OneRoomNetCfg *OneRNCfg;
391 OneRNCfg = (OneRoomNetCfg*)vOneRoomNetCfg;
392 FreeRoomNetworkStructContent(OneRNCfg);
397 void FreeRoomNetworkStruct(OneRoomNetCfg **pOneRNCfg)
399 vFreeRoomNetworkStruct(*pOneRNCfg);
405 * Fetch the netconfig entry for a room, parse it, and return the data.
406 * Caller owns the returned memory and MUST free it using FreeRoomNetworkStruct()
408 OneRoomNetCfg *CtdlGetNetCfgForRoom(long roomnum)
410 OneRoomNetCfg *OneRNCfg = NULL;
411 char *serialized_config = NULL;
413 serialized_config = LoadRoomNetConfigFile(roomnum);
414 if (!serialized_config) return NULL;
416 OneRNCfg = ParseRoomNetConfigFile(serialized_config);
417 free(serialized_config);
422 /*-----------------------------------------------------------------------------*
423 * Per room network configs : exchange with client *
424 *-----------------------------------------------------------------------------*/
426 void cmd_gnet(char *argbuf)
428 if ( (CC->room.QRflags & QR_MAILBOX) && (CC->user.usernum == atol(CC->room.QRname)) ) {
429 /* users can edit the netconfigs for their own mailbox rooms */
431 else if (CtdlAccessCheck(ac_room_aide)) return;
433 cprintf("%d Network settings for room #%ld <%s>\n", LISTING_FOLLOWS, CC->room.QRnumber, CC->room.QRname);
435 char *c = LoadRoomNetConfigFile(CC->room.QRnumber);
444 void cmd_snet(char *argbuf)
446 struct CitContext *CCC = CC;
448 StrBuf *TheConfig = NULL;
453 TheConfig = NewStrBuf();
454 cprintf("%d send new netconfig now\n", SEND_LISTING);
456 while (rc = CtdlClientGetLine(Line), (rc >= 0))
458 if ((rc == 3) && (strcmp(ChrPtr(Line), "000") == 0))
461 StrBufAppendBuf(TheConfig, Line, 0);
462 StrBufAppendBufPlain(TheConfig, HKEY("\n"), 0);
466 write_netconfig_to_configdb(CCC->room.QRnumber, ChrPtr(TheConfig));
467 FreeStrBuf(&TheConfig);
471 /*-----------------------------------------------------------------------------*
472 * Per node network configs *
473 *-----------------------------------------------------------------------------*/
474 void DeleteCtdlNodeConf(void *vNode)
476 CtdlNodeConf *Node = (CtdlNodeConf*) vNode;
477 FreeStrBuf(&Node->NodeName);
478 FreeStrBuf(&Node->Secret);
479 FreeStrBuf(&Node->Host);
480 FreeStrBuf(&Node->Port);
484 CtdlNodeConf *NewNode(StrBuf *SerializedNode)
486 const char *Pos = NULL;
489 /* we need at least 4 pipes and some other text so its invalid. */
490 if (StrLength(SerializedNode) < 8)
492 Node = (CtdlNodeConf *) malloc(sizeof(CtdlNodeConf));
496 Node->NodeName=NewStrBuf();
497 StrBufExtract_NextToken(Node->NodeName, SerializedNode, &Pos, '|');
499 Node->Secret=NewStrBuf();
500 StrBufExtract_NextToken(Node->Secret, SerializedNode, &Pos, '|');
502 Node->Host=NewStrBuf();
503 StrBufExtract_NextToken(Node->Host, SerializedNode, &Pos, '|');
505 Node->Port=NewStrBuf();
506 StrBufExtract_NextToken(Node->Port, SerializedNode, &Pos, '|');
512 * Load or refresh the Citadel network (IGnet) configuration for this node.
514 HashList* CtdlLoadIgNetCfg(void)
523 Cfg = CtdlGetSysConfig(IGNETCFG);
524 if ((Cfg == NULL) || IsEmptyStr(Cfg)) {
530 Hash = NewHash(1, NULL);
531 Buf = NewStrBufPlain(Cfg, -1);
533 LineBuf = NewStrBufPlain(NULL, StrLength(Buf));
537 StrBufSipLine(LineBuf, Buf, &LinePos);
538 if (StrLength(LineBuf) != 0) {
539 Node = NewNode(LineBuf);
541 Put(Hash, SKEY(Node->NodeName), Node, DeleteCtdlNodeConf);
544 } while (LinePos != StrBufNOTNULL);
546 FreeStrBuf(&LineBuf);
551 int is_recipient(OneRoomNetCfg *RNCfg, const char *Name)
553 const RoomNetCfg RecipientCfgs[] = {
560 RoomNetCfgLine *nptr;
565 while (RecipientCfgs[i] != maxRoomNetCfg)
567 nptr = RNCfg->NetConfigs[RecipientCfgs[i]];
571 if ((StrLength(nptr->Value[0]) == len) &&
572 (!strcmp(Name, ChrPtr(nptr->Value[0]))))
585 int CtdlNetconfigCheckRoomaccess(
588 const char* RemoteIdentifier)
590 OneRoomNetCfg *RNCfg;
593 if (RemoteIdentifier == NULL)
595 snprintf(errmsgbuf, n, "Need sender to permit access.");
596 return (ERROR + USERNAME_REQUIRED);
599 begin_critical_section(S_NETCONFIGS);
600 RNCfg = CtdlGetNetCfgForRoom (CC->room.QRnumber);
603 end_critical_section(S_NETCONFIGS);
604 snprintf(errmsgbuf, n,
605 "This mailing list only accepts posts from subscribers.");
606 return (ERROR + NO_SUCH_USER);
608 found = is_recipient (RNCfg, RemoteIdentifier);
609 FreeRoomNetworkStruct(&RNCfg);
610 end_critical_section(S_NETCONFIGS);
616 snprintf(errmsgbuf, n,
617 "This mailing list only accepts posts from subscribers.");
618 return (ERROR + NO_SUCH_USER);
625 * cmd_netp() - authenticate to the server as another Citadel node polling
626 * for network traffic
628 void cmd_netp(char *cmdbuf)
630 struct CitContext *CCC = CC;
631 HashList *working_ignetcfg;
639 const StrBuf *secret = NULL;
640 const StrBuf *nexthop = NULL;
641 char err_buf[SIZ] = "";
644 node = CCC->curr_user;
645 nodelen = extract_token(CCC->curr_user, cmdbuf, 0, '|', sizeof CCC->curr_user);
646 NodeStr = NewStrBufPlain(node, nodelen);
647 /* load the IGnet Configuration to check node validity */
648 working_ignetcfg = CtdlLoadIgNetCfg();
649 v = CtdlIsValidNode(&nexthop, &secret, NodeStr, working_ignetcfg, NULL);
651 snprintf(err_buf, sizeof err_buf,
652 "An unknown Citadel server called \"%s\" attempted to connect from %s [%s].\n",
653 node, CCC->cs_host, CCC->cs_addr
655 syslog(LOG_WARNING, "%s", err_buf);
656 cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
658 strs[0] = CCC->cs_addr;
659 lens[0] = strlen(CCC->cs_addr);
661 strs[1] = "SRV_UNKNOWN";
662 lens[1] = sizeof("SRV_UNKNOWN") - 1;
667 2, strs, (long*) &lens,
671 DeleteHash(&working_ignetcfg);
672 FreeStrBuf(&NodeStr);
676 extract_token(CCC->user.password, cmdbuf, 1, '|', sizeof CCC->user.password);
677 if (strcasecmp(CCC->user.password, ChrPtr(secret))) {
678 snprintf(err_buf, sizeof err_buf,
679 "A Citadel server at %s [%s] failed to authenticate as network node \"%s\".\n",
680 CCC->cs_host, CCC->cs_addr, node
682 syslog(LOG_WARNING, "%s", err_buf);
683 cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
685 strs[0] = CCC->cs_addr;
686 lens[0] = strlen(CCC->cs_addr);
689 lens[1] = sizeof("SRV_PW") - 1;
699 DeleteHash(&working_ignetcfg);
700 FreeStrBuf(&NodeStr);
704 if (CtdlNetworkTalkingTo(node, nodelen, NTT_CHECK)) {
705 syslog(LOG_WARNING, "Duplicate session for network node <%s>", node);
706 cprintf("%d Already talking to %s right now\n", ERROR + RESOURCE_BUSY, node);
707 DeleteHash(&working_ignetcfg);
708 FreeStrBuf(&NodeStr);
711 nodelen = safestrncpy(CCC->net_node, node, sizeof CCC->net_node);
712 CtdlNetworkTalkingTo(CCC->net_node, nodelen, NTT_ADD);
713 syslog(LOG_NOTICE, "Network node <%s> logged in from %s [%s]",
714 CCC->net_node, CCC->cs_host, CCC->cs_addr
716 cprintf("%d authenticated as network node '%s'\n", CIT_OK, CCC->net_node);
717 DeleteHash(&working_ignetcfg);
718 FreeStrBuf(&NodeStr);
722 /*-----------------------------------------------------------------------------*
723 * Network maps: evaluate other nodes *
724 *-----------------------------------------------------------------------------*/
726 void DeleteNetMap(void *vNetMap)
728 CtdlNetMap *TheNetMap = (CtdlNetMap*) vNetMap;
729 FreeStrBuf(&TheNetMap->NodeName);
730 FreeStrBuf(&TheNetMap->NextHop);
734 CtdlNetMap *NewNetMap(StrBuf *SerializedNetMap)
736 const char *Pos = NULL;
739 /* we need at least 3 pipes and some other text so its invalid. */
740 if (StrLength(SerializedNetMap) < 6)
742 NM = (CtdlNetMap *) malloc(sizeof(CtdlNetMap));
744 NM->NodeName=NewStrBuf();
745 StrBufExtract_NextToken(NM->NodeName, SerializedNetMap, &Pos, '|');
747 NM->lastcontact = StrBufExtractNext_long(SerializedNetMap, &Pos, '|');
749 NM->NextHop=NewStrBuf();
750 StrBufExtract_NextToken(NM->NextHop, SerializedNetMap, &Pos, '|');
755 HashList* CtdlReadNetworkMap(void)
762 CtdlNetMap *TheNetMap;
764 Hash = NewHash(1, NULL);
765 Cfg = CtdlGetSysConfig(IGNETMAP);
766 if ((Cfg == NULL) || IsEmptyStr(Cfg)) {
772 Buf = NewStrBufPlain(Cfg, -1);
774 LineBuf = NewStrBufPlain(NULL, StrLength(Buf));
776 while (StrBufSipLine(Buf, LineBuf, &LinePos))
778 TheNetMap = NewNetMap(LineBuf);
779 if (TheNetMap != NULL) { /* TODO: is the NodeName Uniq? */
780 Put(Hash, SKEY(TheNetMap->NodeName), TheNetMap, DeleteNetMap);
784 FreeStrBuf(&LineBuf);
788 StrBuf *CtdlSerializeNetworkMap(HashList *Map)
793 StrBuf *Ret = NewStrBuf();
794 HashPos *Pos = GetNewHashPos(Map, 0);
796 while (GetNextHashPos(Map, Pos, &len, &key, &vMap))
798 CtdlNetMap *pMap = (CtdlNetMap*) vMap;
799 StrBufAppendBuf(Ret, pMap->NodeName, 0);
800 StrBufAppendBufPlain(Ret, HKEY("|"), 0);
802 StrBufAppendPrintf(Ret, "%ld", pMap->lastcontact, 0);
803 StrBufAppendBufPlain(Ret, HKEY("|"), 0);
805 StrBufAppendBuf(Ret, pMap->NextHop, 0);
806 StrBufAppendBufPlain(Ret, HKEY("\n"), 0);
814 * Learn topology from path fields
816 void NetworkLearnTopology(char *node, char *path, HashList *the_netmap, int *netmap_changed)
818 CtdlNetMap *pNM = NULL;
823 if (GetHash(the_netmap, node, strlen(node), &vptr) &&
824 (vptr != NULL))/* TODO: is the NodeName Uniq? */
826 pNM = (CtdlNetMap*)vptr;
827 extract_token(nexthop, path, 0, '!', sizeof nexthop);
828 if (!strcmp(nexthop, ChrPtr(pNM->NextHop))) {
829 pNM->lastcontact = time(NULL);
830 (*netmap_changed) ++;
835 /* If we got here then it's not in the map, so add it. */
836 nmptr = (CtdlNetMap *) malloc(sizeof (CtdlNetMap));
837 nmptr->NodeName = NewStrBufPlain(node, -1);
838 nmptr->lastcontact = time(NULL);
839 nmptr->NextHop = NewStrBuf ();
840 StrBufExtract_tokenFromStr(nmptr->NextHop, path, strlen(path), 0, '!');
841 /* TODO: is the NodeName Uniq? */
842 Put(the_netmap, SKEY(nmptr->NodeName), nmptr, DeleteNetMap);
843 (*netmap_changed) ++;
848 * Check the network map and determine whether the supplied node name is
849 * valid. If it is not a neighbor node, supply the name of a neighbor node
850 * which is the next hop. If it *is* a neighbor node, we also fill in the
853 int CtdlIsValidNode(const StrBuf **nexthop,
854 const StrBuf **secret,
857 HashList *the_netmap)
861 CtdlNodeConf *TheNode;
862 CtdlNetMap *TheNetMap;
864 if (StrLength(node) == 0) {
869 * First try the neighbor nodes
871 if (GetCount(IgnetCfg) == 0) {
872 syslog(LOG_INFO, "IgnetCfg is empty!");
873 if (nexthop != NULL) {
879 /* try to find a neigbour with the name 'node' */
880 if (GetHash(IgnetCfg, SKEY(node), &vNodeConf) &&
883 TheNode = (CtdlNodeConf*)vNodeConf;
885 *secret = TheNode->Secret;
886 return 0; /* yup, it's a direct neighbor */
890 * If we get to this point we have to see if we know the next hop
891 *//* TODO: is the NodeName Uniq? */
892 if ((GetCount(the_netmap) > 0) &&
893 (GetHash(the_netmap, SKEY(node), &vNetMap)))
895 TheNetMap = (CtdlNetMap*)vNetMap;
897 *nexthop = TheNetMap->NextHop;
902 * If we get to this point, the supplied node name is bogus.
904 syslog(LOG_ERR, "Invalid node name <%s>", ChrPtr(node));
910 * Convert any legacy configuration files in the "netconfigs" directory
912 void convert_legacy_netcfg_files(void)
915 struct dirent *dit = NULL;
916 char filename[PATH_MAX];
922 dh = opendir(ctdl_netcfg_dir);
925 syslog(LOG_INFO, "Legacy netconfig files exist - converting them!");
927 while (dit = readdir(dh), dit != NULL) { // yes, we use the non-reentrant version; we're not in threaded mode yet
928 roomnum = atol(dit->d_name);
930 snprintf(filename, sizeof filename, "%s/%ld", ctdl_netcfg_dir, roomnum);
931 fp = fopen(filename, "r");
933 fseek(fp, 0L, SEEK_END);
939 if (fread(v, len, 1, fp)) {
940 write_netconfig_to_configdb(roomnum, v);
947 unlink(filename); // zero length netconfig, just delete it
955 rmdir(ctdl_netcfg_dir);
963 CTDL_MODULE_INIT(netconfig)
967 convert_legacy_netcfg_files();
968 CtdlRegisterProtoHook(cmd_gnet, "GNET", "Get network config");
969 CtdlRegisterProtoHook(cmd_snet, "SNET", "Set network config");
970 CtdlRegisterProtoHook(cmd_netp, "NETP", "Identify as network poller");