-
- if (found) {
- return (0);
- }
- else {
- snprintf(errmsgbuf, n,
- "This mailing list only accepts posts from subscribers.");
- return (ERROR + NO_SUCH_USER);
- }
-}
-
-
-
-/*
- * cmd_netp() - authenticate to the server as another Citadel node polling
- * for network traffic
- */
-void cmd_netp(char *cmdbuf)
-{
- struct CitContext *CCC = CC;
- HashList *working_ignetcfg;
- char *node;
- StrBuf *NodeStr;
- long nodelen;
- int v;
-
- const StrBuf *secret = NULL;
- const StrBuf *nexthop = NULL;
- char err_buf[SIZ] = "";
-
- /* Authenticate */
- node = CCC->curr_user;
- nodelen = extract_token(CCC->curr_user, cmdbuf, 0, '|', sizeof CCC->curr_user);
- NodeStr = NewStrBufPlain(node, nodelen);
- /* load the IGnet Configuration to check node validity */
- working_ignetcfg = CtdlLoadIgNetCfg();
- v = CtdlIsValidNode(&nexthop, &secret, NodeStr, working_ignetcfg, NULL);
- if (v != 0) {
- snprintf(err_buf, sizeof err_buf,
- "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);
- cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
- CtdlAideMessage(err_buf, "IGNet Networking");
- DeleteHash(&working_ignetcfg);
- FreeStrBuf(&NodeStr);
- return;
- }
-
- extract_token(CCC->user.password, cmdbuf, 1, '|', sizeof CCC->user.password);
- if (strcasecmp(CCC->user.password, ChrPtr(secret))) {
- snprintf(err_buf, sizeof err_buf,
- "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);
- cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
-
- 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);
- cprintf("%d Already talking to %s right now\n", ERROR + RESOURCE_BUSY, node);
- DeleteHash(&working_ignetcfg);
- FreeStrBuf(&NodeStr);
- return;
- }
- 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]",
- CCC->net_node, CCC->cs_host, CCC->cs_addr
- );
- cprintf("%d authenticated as network node '%s'\n", CIT_OK, CCC->net_node);
- DeleteHash(&working_ignetcfg);
- FreeStrBuf(&NodeStr);
-}
-
-
-/*-----------------------------------------------------------------------------*
- * Network maps: evaluate other nodes *
- *-----------------------------------------------------------------------------*/
-
-void DeleteNetMap(void *vNetMap)
-{
- CtdlNetMap *TheNetMap = (CtdlNetMap*) vNetMap;
- FreeStrBuf(&TheNetMap->NodeName);
- FreeStrBuf(&TheNetMap->NextHop);
- free(TheNetMap);
-}
-
-CtdlNetMap *NewNetMap(StrBuf *SerializedNetMap)
-{
- const char *Pos = NULL;
- CtdlNetMap *NM;
-
- /* we need at least 3 pipes and some other text so its invalid. */
- if (StrLength(SerializedNetMap) < 6)
- return NULL;
- NM = (CtdlNetMap *) malloc(sizeof(CtdlNetMap));
-
- NM->NodeName=NewStrBuf();
- StrBufExtract_NextToken(NM->NodeName, SerializedNetMap, &Pos, '|');
-
- NM->lastcontact = StrBufExtractNext_long(SerializedNetMap, &Pos, '|');
-
- NM->NextHop=NewStrBuf();
- StrBufExtract_NextToken(NM->NextHop, SerializedNetMap, &Pos, '|');
-
- return NM;
-}
-
-HashList* CtdlReadNetworkMap(void)
-{
- const char *LinePos;
- char *Cfg;
- StrBuf *Buf;
- StrBuf *LineBuf;
- HashList *Hash;
- CtdlNetMap *TheNetMap;
-
- Hash = NewHash(1, NULL);
- Cfg = CtdlGetSysConfig(IGNETMAP);
- if ((Cfg == NULL) || IsEmptyStr(Cfg)) {
- if (Cfg != NULL)
- free(Cfg);
- return Hash;
- }
-
- Buf = NewStrBufPlain(Cfg, -1);
- free(Cfg);
- LineBuf = NewStrBufPlain(NULL, StrLength(Buf));
- LinePos = NULL;
- while (StrBufSipLine(Buf, LineBuf, &LinePos))
- {
- TheNetMap = NewNetMap(LineBuf);
- if (TheNetMap != NULL) { /* TODO: is the NodeName Uniq? */
- Put(Hash, SKEY(TheNetMap->NodeName), TheNetMap, DeleteNetMap);
- }
- }
- FreeStrBuf(&Buf);
- FreeStrBuf(&LineBuf);
- return Hash;
-}
-
-StrBuf *CtdlSerializeNetworkMap(HashList *Map)
-{
- void *vMap;
- const char *key;
- long len;
- StrBuf *Ret = NewStrBuf();
- HashPos *Pos = GetNewHashPos(Map, 0);
-
- while (GetNextHashPos(Map, Pos, &len, &key, &vMap))
- {
- CtdlNetMap *pMap = (CtdlNetMap*) vMap;
- StrBufAppendBuf(Ret, pMap->NodeName, 0);
- StrBufAppendBufPlain(Ret, HKEY("|"), 0);
-
- StrBufAppendPrintf(Ret, "%ld", pMap->lastcontact, 0);
- StrBufAppendBufPlain(Ret, HKEY("|"), 0);
-
- StrBufAppendBuf(Ret, pMap->NextHop, 0);
- StrBufAppendBufPlain(Ret, HKEY("\n"), 0);
- }
- DeleteHashPos(&Pos);
- return Ret;
-}
-
-
-/*
- * Learn topology from path fields
- */
-void NetworkLearnTopology(char *node, char *path, HashList *the_netmap, int *netmap_changed)
-{
- CtdlNetMap *pNM = NULL;
- void *vptr;
- char nexthop[256];
- CtdlNetMap *nmptr;
-
- if (GetHash(the_netmap, node, strlen(node), &vptr) &&
- (vptr != NULL))/* TODO: is the NodeName Uniq? */
- {
- pNM = (CtdlNetMap*)vptr;
- extract_token(nexthop, path, 0, '!', sizeof nexthop);
- if (!strcmp(nexthop, ChrPtr(pNM->NextHop))) {
- pNM->lastcontact = time(NULL);
- (*netmap_changed) ++;
- return;
- }
- }
-
- /* If we got here then it's not in the map, so add it. */
- nmptr = (CtdlNetMap *) malloc(sizeof (CtdlNetMap));
- nmptr->NodeName = NewStrBufPlain(node, -1);
- nmptr->lastcontact = time(NULL);
- nmptr->NextHop = NewStrBuf ();
- StrBufExtract_tokenFromStr(nmptr->NextHop, path, strlen(path), 0, '!');
- /* TODO: is the NodeName Uniq? */
- Put(the_netmap, SKEY(nmptr->NodeName), nmptr, DeleteNetMap);
- (*netmap_changed) ++;
-}
-
-
-/*
- * Check the network map and determine whether the supplied node name is
- * valid. If it is not a neighbor node, supply the name of a neighbor node
- * which is the next hop. If it *is* a neighbor node, we also fill in the
- * shared secret.
- */
-int CtdlIsValidNode(const StrBuf **nexthop,
- const StrBuf **secret,
- StrBuf *node,
- HashList *IgnetCfg,
- HashList *the_netmap)
-{
- void *vNetMap;
- void *vNodeConf;
- CtdlNodeConf *TheNode;
- CtdlNetMap *TheNetMap;
-
- if (StrLength(node) == 0) {
- return(-1);
- }
-
- /*
- * First try the neighbor nodes
- */
- if (GetCount(IgnetCfg) == 0) {
- syslog(LOG_INFO, "IgnetCfg is empty!");
- if (nexthop != NULL) {
- *nexthop = NULL;
- }
- return(-1);
- }
-
- /* try to find a neigbour with the name 'node' */
- if (GetHash(IgnetCfg, SKEY(node), &vNodeConf) &&
- (vNodeConf != NULL))
- {
- TheNode = (CtdlNodeConf*)vNodeConf;
- if (secret != NULL)
- *secret = TheNode->Secret;
- return 0; /* yup, it's a direct neighbor */
- }
-
- /*
- * If we get to this point we have to see if we know the next hop
- *//* TODO: is the NodeName Uniq? */
- if ((GetCount(the_netmap) > 0) &&
- (GetHash(the_netmap, SKEY(node), &vNetMap)))
- {
- TheNetMap = (CtdlNetMap*)vNetMap;
- if (nexthop != NULL)
- *nexthop = TheNetMap->NextHop;
- return(0);
- }
-
- /*
- * If we get to this point, the supplied node name is bogus.
- */
- syslog(LOG_ERR, "Invalid node name <%s>", ChrPtr(node));
- return(-1);