* load_siteconfig(): revalidate what the server gives us as siteconfig, and bail...
authorWilfried Göesgens <willi@citadel.org>
Wed, 11 Aug 2010 11:15:15 +0000 (11:15 +0000)
committerWilfried Göesgens <willi@citadel.org>
Wed, 11 Aug 2010 11:15:15 +0000 (11:15 +0000)
webcit/siteconfig.c

index 6a5eea83ba186cf3550e4b70b485c0c6527baa84..24f97212c3abf30c57f4bb40a99ef99690498295 100644 (file)
@@ -213,7 +213,6 @@ void load_siteconfig(void)
        wcsession *WCC = WC;
        StrBuf *Buf;
        HashList *Cfg;
-       char buf[SIZ];
        long len;
        int i;
        
@@ -221,14 +220,21 @@ void load_siteconfig(void)
                WCC->ServCfg = NewHash(1, NULL);
        Cfg = WCC->ServCfg;
 
+       Buf = NewStrBuf();
+
        serv_printf("CONF get");
-       serv_getln(buf, sizeof buf);
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) != 1) {
+               StrBufCutLeft(Buf, 4);
+               AppendImportantMessage(SKEY(Buf));
+               return;
+               
+       }
        i = 0;
-       Buf = NewStrBuf();
-       while ((sizeof(ServerConfig) / sizeof(CfgMapping)) &&
-              (len = StrBuf_ServGetln(Buf),
-               strcmp(ChrPtr(Buf), "000")) && 
-              (i <= sizeof(ServerConfig))) 
+       while (len = StrBuf_ServGetln(Buf),
+              (i <= (sizeof(ServerConfig) / sizeof(CfgMapping))) &&
+              ((len != 3) || (strcmp(ChrPtr(Buf), "000")!= 0))
+               )
        {
                Put(Cfg,
                    ServerConfig[i].Key, 
@@ -241,6 +247,14 @@ void load_siteconfig(void)
                else
                        Buf = NULL;                     
        }
+       if (strcmp(ChrPtr(Buf), "000")!=0)
+       {
+               /* WHOOOOPSI??? burn the lines we don't understand */
+               while ((len = StrBuf_ServGetln(Buf),
+                       strcmp(ChrPtr(Buf), "000"))) {}
+               AppendImportantMessage(_("WARNING: Failed to parse Server Config; do you run a to new citserver?"), -1);
+               return;
+       }
        FreeStrBuf(&Buf);
 
        LoadExpirePolicy(sitepolicy);