Browse Source

[1790] Address review comments (see full log)

* The filetype parameter is optional, which means it might be missing
  from the dict. Therefore indexing it with zone["filetype"] without
  further check is unsafe. We check for this key now.

* The handling of origin and dots is needlessly complicated. We now
  create Name objects of both and compare them. We also use RRClass
  objects for the zone class. This makes sure the comparison is correct
  one.
Mukund Sivaraman 13 years ago
parent
commit
ab86972df5
2 changed files with 24 additions and 15 deletions
  1. 21 15
      src/bin/xfrin/xfrin.py.in
  2. 3 0
      src/bin/xfrin/xfrin_messages.mes

+ 21 - 15
src/bin/xfrin/xfrin.py.in

@@ -1549,24 +1549,30 @@ class Xfrin:
         if is_default:
             return
         for d in datasources:
-            if "class" in d:
-                dclass = d["class"]
-            else:
-                dclass = "IN"
-            if d["type"].lower() == "memory" and dclass.lower() == zone_class.to_text().lower():
+            try:
+                if "class" in d:
+                    dclass = RRClass(d["class"])
+                else:
+                    dclass = RRClass("IN")
+            except InvalidRRType as err:
+                logger.info(XFRIN_AUTH_CONFIG_ERROR, str(err))
+                continue
+
+            if d["type"].lower() == "memory" and dclass == zone_class:
                 for zone in d["zones"]:
-                    # Remove trailing periods
-                    n1 = zone["origin"]
-                    if n1[-1] == '.':
-                        n1 = n1[:-1]
-                    n2 = zone_name.to_text()
-                    if n2[-1] == '.':
-                        n2 = n2[:-1]
-
-                    if zone["filetype"].lower() == "sqlite3" and n1.lower() == n2.lower():
-                        param = {"origin": n1,
+                    if "filetype" not in zone:
+                        continue
+                    try:
+                        name = Name(zone["origin"])
+                    except (EmptyLabel, TooLongLabel, BadLabelType, BadEscape, TooLongName, IncompleteName):
+                        logger.info(XFRIN_AUTH_CONFIG_ERROR, str(err))
+                        continue
+
+                    if zone["filetype"].lower() == "sqlite3" and name == zone_name:
+                        param = {"origin": zone_name.to_text(),
                                  "class": zone_class.to_text(),
                                  "datasrc": d["type"]}
+
                         logger.debug(DBG_XFRIN_TRACE, XFRIN_AUTH_LOADZONE,
                                      param["origin"], param["class"], param["datasrc"])
 

+ 3 - 0
src/bin/xfrin/xfrin_messages.mes

@@ -121,6 +121,9 @@ likely means that the msgq daemon has quit or was killed.
 There was a problem sending a message to b10-auth. This most likely
 means that the msgq daemon has quit or was killed.
 
+% XFRIN_AUTH_CONFIG_ERROR Error parsing Auth configuration: %1
+There was an error when parsing Auth configuration.
+
 % XFRIN_AUTH_LOADZONE sending Auth loadzone for origin=%1, class=%2, datasrc=%3
 There was a successful zone transfer, and the zone is served by b10-auth
 in the in-memory data source using sqlite3 as a backend. We send the