Browse Source

- fixed a bug where $ORIGIN '.' caused names to be rendered as "name.."
- added exception handling around the zone loading so that a zone would
not be committed to the database after being only partially loaded


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1217 e5f2f494-b856-4b98-b285-d166d9295462

Evan Hunt 15 years ago
parent
commit
c5a54508e7

+ 1 - 1
src/bin/loadzone/b10-loadzone.py.in

@@ -40,7 +40,7 @@ def main():
         exit(2)
 
     dbfile = '/tmp/zone.sqlite3'
-    initial_origin = '.'
+    initial_origin = ''
     for o, a in opts:
         if o in ("-d", "--dbfile"):
             dbfile = a

+ 9 - 3
src/lib/python/isc/auth/master.py

@@ -194,7 +194,9 @@ def directive(s):
             raise MasterFileError('Invalid $ORIGIN')
         if more:
             raise MasterFileError('Invalid $ORIGIN')
-        if second[-1] == '.':
+        if second == '.':
+            origin = ''
+        elif second[-1] == '.':
             origin = second
         else:
             origin = second + '.' + origin
@@ -341,11 +343,13 @@ def reset():
 #########################################################################
 # openzone: open a zone master file, set initial origin, return descriptor
 #########################################################################
-def openzone(filename, initial_origin = '.'):
+def openzone(filename, initial_origin = ''):
     try:
         zf = open(filename, 'r')
     except:
         raise MasterFileError("Could not open " + filename)
+    if initial_origin == '.':
+        initial_origin = ''
     origin = initial_origin
     return zf
 
@@ -421,9 +425,11 @@ def zonedata(zone):
 # zonename: scans zone data for an SOA record, returns its name, restores
 # the zone file to its prior state
 #########################################################################
-def zonename(zone, initial_origin = '.'):
+def zonename(zone, initial_origin = ''):
     global origin
     old_origin = origin
+    if initial_origin == '.':
+        initial_origin = ''
     origin = initial_origin
     old_location = zone.tell()
     zone.seek(0)

+ 28 - 23
src/lib/python/isc/auth/sqlite3_ds.py

@@ -129,29 +129,34 @@ def load(dbfile, zone, reader, file):
     cur.execute("INSERT INTO zones (name, rdclass) VALUES (?, 'IN')", [temp])
     new_zone_id = cur.lastrowid
 
-    for name, ttl, rdclass, rdtype, rdata in reader(file):
-        sigtype = ''
-        if rdtype.lower() == 'rrsig':
-            sigtype = rdata.split()[0]
-
-        if rdtype.lower() == 'nsec3' or sigtype.lower() == 'nsec3':
-            hash = name.split('.')[0]
-            cur.execute("""INSERT INTO nsec3
-                           (zone_id, hash, owner, ttl, rdtype, rdata)
-                           VALUES (?, ?, ?, ?, ?, ?)""",
-                        [new_zone_id, hash, name, ttl, rdtype, rdata])
-        elif rdtype.lower() == 'rrsig':
-            cur.execute("""INSERT INTO records
-                           (zone_id, name, rname, ttl, rdtype, sigtype, rdata)
-                           VALUES (?, ?, ?, ?, ?, ?, ?)""",
-                        [new_zone_id, name, reverse_name(name), ttl,
-                        rdtype, sigtype, rdata])
-        else:
-            cur.execute("""INSERT INTO records
-                           (zone_id, name, rname, ttl, rdtype, rdata)
-                           VALUES (?, ?, ?, ?, ?, ?)""",
-                        [new_zone_id, name, reverse_name(name), ttl,
-                        rdtype, rdata])
+    try:
+        for name, ttl, rdclass, rdtype, rdata in reader(file):
+            sigtype = ''
+            if rdtype.lower() == 'rrsig':
+                sigtype = rdata.split()[0]
+
+            if rdtype.lower() == 'nsec3' or sigtype.lower() == 'nsec3':
+                hash = name.split('.')[0]
+                cur.execute("""INSERT INTO nsec3
+                               (zone_id, hash, owner, ttl, rdtype, rdata)
+                               VALUES (?, ?, ?, ?, ?, ?)""",
+                            [new_zone_id, hash, name, ttl, rdtype, rdata])
+            elif rdtype.lower() == 'rrsig':
+                cur.execute("""INSERT INTO records
+                               (zone_id, name, rname, ttl,
+                                rdtype, sigtype, rdata)
+                               VALUES (?, ?, ?, ?, ?, ?, ?)""",
+                            [new_zone_id, name, reverse_name(name), ttl,
+                            rdtype, sigtype, rdata])
+            else:
+                cur.execute("""INSERT INTO records
+                               (zone_id, name, rname, ttl, rdtype, rdata)
+                               VALUES (?, ?, ?, ?, ?, ?)""",
+                            [new_zone_id, name, reverse_name(name), ttl,
+                            rdtype, rdata])
+    except Exception as e:
+        fail = "Error while loading " + zone + ": " + e.args[0]
+        raise Sqlite3DSError(fail)
 
     if old_zone_id:
         cur.execute("DELETE FROM zones WHERE id=?", [old_zone_id])