]> www.average.org Git - pdns-pipe-nmc.git/commitdiff
support powerdns ABI v.4 (#1386)
authorEugene Crosser <crosser@average.org>
Tue, 3 Jun 2014 15:18:20 +0000 (19:18 +0400)
committerEugene Crosser <crosser@average.org>
Tue, 3 Jun 2014 15:18:20 +0000 (19:18 +0400)
PowerDns.hs
pdns-pipe-nmc.hs

index 9e1da83513130309234647b8246914a09d7d02ce..7036596fea1f324def3ae342fbbe63e967e01180 100644 (file)
@@ -58,7 +58,7 @@ data PdnsRequest = PdnsRequestQ
                    , localIpAddress     :: Maybe String
                    , ednsSubnetAddress  :: Maybe String
                    }
                    , localIpAddress     :: Maybe String
                    , ednsSubnetAddress  :: Maybe String
                    }
-                 | PdnsRequestAXFR Int
+                 | PdnsRequestAXFR Int (Maybe String)
                  | PdnsRequestPing
         deriving (Show)
 
                  | PdnsRequestPing
         deriving (Show)
 
@@ -82,7 +82,15 @@ pdnsParse ver s =
   in
     case words s of
       "PING":[]                 -> Right PdnsRequestPing
   in
     case words s of
       "PING":[]                 -> Right PdnsRequestPing
-      "AXFR":x:[]               -> Right (PdnsRequestAXFR (getInt x))
+      "AXFR":x:xs               ->
+        if ver < 4 then
+          case xs of
+            [] -> Right $ (PdnsRequestAXFR (getInt x)) Nothing
+            _  -> Left  $ "Extra arguments in AXFR (v 1-3): " ++ s
+        else
+          case xs of
+            [z] -> Right $ (PdnsRequestAXFR (getInt x)) (Just z)
+            _   -> Left  $ "Wrong arguments in AXFR (v 4+): " ++ s
       "Q":qn:"IN":qt:id:rip:xs  -> case rrType qt of
                                      RRTypeError e ->
                                        Left $ "Unrecognized RR type: " ++ e
       "Q":qn:"IN":qt:id:rip:xs  -> case rrType qt of
                                      RRTypeError e ->
                                        Left $ "Unrecognized RR type: " ++ e
@@ -146,9 +154,7 @@ formatRR ver id gen name dom rrtype =
               ++ "\t" ++ ttl ++ "\t" ++ (show id) ++ "\t" ++ x ++ "\n" ++ a)
         "" $ dataRR rrtype gen name dom
     where
               ++ "\t" ++ ttl ++ "\t" ++ (show id) ++ "\t" ++ x ++ "\n" ++ a)
         "" $ dataRR rrtype gen name dom
     where
-      v3ext = case ver of
-        3 -> "0\t1\t"
-        _ -> ""
+      v3ext = if ver >= 3 then "0\t1\t" else ""
       ttl = show 3600
 
 justl accessor _ _ dom = case accessor dom of
       ttl = show 3600
 
 justl accessor _ _ dom = case accessor dom of
index bbe89ab1ccea7025bcf06b7a5ab3cfb426dd2673..1f5a8918675d40f34ce66b49d59ae88c2e2df90c 100644 (file)
@@ -104,6 +104,7 @@ mainPdnsNmc = do
       ["HELO", "1"] -> return 1
       ["HELO", "2"] -> return 2
       ["HELO", "3"] -> return 3
       ["HELO", "1"] -> return 1
       ["HELO", "2"] -> return 2
       ["HELO", "3"] -> return 3
+      ["HELO", "4"] -> return 4
       ["HELO",  x ] -> loopErr $ "unsupported ABI version " ++ (show x)
       _             -> loopErr $ "bad HELO " ++ (show s)
 
       ["HELO",  x ] -> loopErr $ "unsupported ABI version " ++ (show x)
       _             -> loopErr $ "bad HELO " ++ (show s)
 
@@ -143,14 +144,26 @@ mainPdnsNmc = do
   -- end debug
   -}
               put $ stow qname (count, cache)
   -- end debug
   -}
               put $ stow qname (count, cache)
-            PdnsRequestAXFR xrq ->
-              case fetch xrq cache of
-                Nothing ->
-                  io $ putStr $
-                    pdnsReport ("AXFR for unknown id: " ++ (show xrq))
+            PdnsRequestAXFR xrq zid -> do
+  {-
+  -- debug
+              io $ putStrLn $ "LOG\tAXFR request id=" ++ (show xrq)
+                                ++ ", zone name: " ++ (show zid)
+  -- end debug
+  -}
+              let
+                czone = fetch xrq cache
+                zone = case zid of
+                  Nothing    -> czone
+                  Just qname -> Just qname
+                    -- if zid == czone then zid else Nothing -- paranoid
+              case zone of
                 Just qname ->
                   io $ queryDom (queryOpNmc cfg mgr xrq) qname
                 Just qname ->
                   io $ queryDom (queryOpNmc cfg mgr xrq) qname
-                    >>= putStr . (pdnsOutXfr ver count gen qname)
+                     >>= putStr . (pdnsOutXfr ver count gen qname)
+                Nothing ->
+                  io $ putStr $ pdnsReport $ "AXFR cannot determine zone: "
+                                          ++ (show xrq) ++ ", " ++ (show zid)
             PdnsRequestPing -> io $ putStrLn "END"
 
   runStateT mainloop (0, empty) >> return ()
             PdnsRequestPing -> io $ putStrLn "END"
 
   runStateT mainloop (0, empty) >> return ()