GVDN: new call. Get Valid Domain Names
authorWilfried Goesgens <dothebart@citadel.org>
Mon, 17 Dec 2012 23:13:43 +0000 (00:13 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Mon, 17 Dec 2012 23:13:43 +0000 (00:13 +0100)
outputs all configured valid domain names of the system
 0 - the ones which are realy ours.
 1 - domains which we may send through too.
 2 - relays also
 3 - system configs - probably not usefull.

citadel/control.c

index ea1591f9c448943d8ffbdf8a83fa581b9f30f3f1..c26aadbf0197cf5f99b0d64fb5c0777b410d93a8 100644 (file)
@@ -739,6 +739,88 @@ void cmd_conf(char *argbuf)
        }
 }
 
+typedef struct __ConfType {
+       ConstStr Name;
+       long Type;
+}ConfType;
+
+ConfType CfgNames[] = {
+       { {HKEY("localhost") },    0},
+       { {HKEY("directory") },    0},
+       { {HKEY("smarthost") },    2},
+       { {HKEY("fallbackhost") }, 2},
+       { {HKEY("rbl") },          3},
+       { {HKEY("spamassassin") }, 3},
+       { {HKEY("masqdomain") },   1},
+       { {HKEY("clamav") },       3},
+       { {HKEY("notify") },       3},
+       { {NULL, 0}, 0}
+};
+
+HashList *CfgNameHash = NULL;
+void cmd_gvdn(char *argbuf)
+{
+       const ConfType *pCfg;
+       char *confptr;
+       long min = atol(argbuf);
+       const char *Pos = NULL;
+       const char *PPos = NULL;
+       const char *HKey;
+       long HKLen;
+       StrBuf *Line;
+       StrBuf *Config;
+       StrBuf *Cfg;
+       StrBuf *CfgToken;
+       HashList *List;
+       HashPos *It;
+       void *vptr;
+       
+       List = NewHash(1, NULL);
+       Cfg = NewStrBufPlain(config.c_fqdn, -1);
+       Put(List, SKEY(Cfg), Cfg, HFreeStrBuf);
+       Cfg = NULL;
+
+       confptr = CtdlGetSysConfig(INTERNETCFG);
+       Config = NewStrBufPlain(confptr, -1);
+       free(confptr);
+
+       Line = NewStrBufPlain(NULL, StrLength(Config));
+       CfgToken = NewStrBufPlain(NULL, StrLength(Config));
+       while (StrBufSipLine(Line, Config, &Pos))
+       {
+               if (Cfg == NULL)
+                       Cfg = NewStrBufPlain(NULL, StrLength(Line));
+               PPos = NULL;
+               StrBufExtract_NextToken(Cfg, Line, &PPos, '|');
+               StrBufExtract_NextToken(CfgToken, Line, &PPos, '|');
+               if (GetHash(CfgNameHash, SKEY(CfgToken), &vptr) &&
+                   (vptr != NULL))
+               {
+                       pCfg = (ConfType *) vptr;
+                       if (pCfg->Type <= min)
+                       {
+                               Put(List, SKEY(Cfg), Cfg, HFreeStrBuf);
+                               Cfg = NULL;
+                       }
+               }
+       }
+
+       cprintf("%d Valid Domains\n", LISTING_FOLLOWS);
+       It = GetNewHashPos(List, 1);
+       while (GetNextHashPos(List, It, &HKLen, &HKey, &vptr))
+       {
+               cputbuf(vptr);
+               cprintf("\n");
+       }
+       cprintf("000\n");
+
+       DeleteHashPos(&It);
+       DeleteHash(&List);
+       FreeStrBuf(&Cfg);
+       FreeStrBuf(&Line);
+       FreeStrBuf(&CfgToken);
+       FreeStrBuf(&Config);
+}
 
 /*****************************************************************************/
 /*                      MODULE INITIALIZATION STUFF                          */
@@ -748,6 +830,13 @@ void cmd_conf(char *argbuf)
 CTDL_MODULE_INIT(control)
 {
        if (!threading) {
+               int i;
+
+               CfgNameHash = NewHash(1, NULL);
+               for (i = 0; CfgNames[i].Name.Key != NULL; i++)
+                       Put(CfgNameHash, CKEY(CfgNames[i].Name), &CfgNames[i], reference_free_handler);
+
+               CtdlRegisterProtoHook(cmd_gvdn, "GVDN", "get valid domain names");
                CtdlRegisterProtoHook(cmd_conf, "CONF", "get/set system configuration");
        }
        /* return our id for the Log */