[svn] commit: r1217 - in /trunk/src: bin/loadzone/b10-loadzone.py.in lib/python/isc/auth/master.py lib/python/isc/auth/sqlite3_ds.py

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Mar 8 21:42:13 UTC 2010


Author: each
Date: Mon Mar  8 21:42:12 2010
New Revision: 1217

Log:
- 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

Modified:
    trunk/src/bin/loadzone/b10-loadzone.py.in
    trunk/src/lib/python/isc/auth/master.py
    trunk/src/lib/python/isc/auth/sqlite3_ds.py

Modified: trunk/src/bin/loadzone/b10-loadzone.py.in
==============================================================================
--- trunk/src/bin/loadzone/b10-loadzone.py.in (original)
+++ trunk/src/bin/loadzone/b10-loadzone.py.in Mon Mar  8 21:42:12 2010
@@ -40,7 +40,7 @@
         exit(2)
 
     dbfile = '/tmp/zone.sqlite3'
-    initial_origin = '.'
+    initial_origin = ''
     for o, a in opts:
         if o in ("-d", "--dbfile"):
             dbfile = a

Modified: trunk/src/lib/python/isc/auth/master.py
==============================================================================
--- trunk/src/lib/python/isc/auth/master.py (original)
+++ trunk/src/lib/python/isc/auth/master.py Mon Mar  8 21:42:12 2010
@@ -194,7 +194,9 @@
             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 @@
 #########################################################################
 # 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 @@
 # 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)

Modified: trunk/src/lib/python/isc/auth/sqlite3_ds.py
==============================================================================
--- trunk/src/lib/python/isc/auth/sqlite3_ds.py (original)
+++ trunk/src/lib/python/isc/auth/sqlite3_ds.py Mon Mar  8 21:42:12 2010
@@ -129,29 +129,34 @@
     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]
+    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])
+            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])




More information about the bind10-changes mailing list