Example #1
0
 def getZone(self, con, name, current):
     cur = self._dbh.execute(con, 'SELECT id FROM domains WHERE name=%s',
                             name)
     result = cur.fetchall()
     if len(result) != 1:
         raise ICore.NotFoundError("Could not locate zone in the database")
     return utils.proxy(I.ZonePrx, current, "DNS-Zone", str(result[0][0]))
Example #2
0
 def __call__(self, code, where, message):
     if code in _ALREADYEXISTS_ERRORS:
         raise C.AlreadyExistsError(message, where)
     if code in _AUTH_ERRORS:
         raise C.PermissionError(message, where, self.princ)
     if code in _NOTFOUND_ERRORS:
         raise C.NotFoundError(message, where)
     raise I.KadminError(message, where, code)
Example #3
0
 def deleteZone(self, con, name, current):
     cur = self._dbh.execute(con, "SELECT id FROM domains WHERE name=%s",
                             name)
     res = cur.fetchall()
     if len(res) != 1:
         raise ICore.NotFoundError("No such zone.")
     key = res[0][0]
     self._dropZone(con, key)
Example #4
0
 def addUserToGroups(self, con, uid, groups, current):
     gen = ( (uid - self._uo, gid - self._go) for gid in groups )
     try:
         self._dbh.execute_many(con,
                 "INSERT INTO real_group_entries (uid, gid) "
                 "VALUES (%s, %s)", gen)
     except self._dbh.IntegrityError:
         raise C.NotFoundError("Group not found",
                               "adding user to multiple groups")
     con.commit()
Example #5
0
 def dropRecord(self, con, record, current):
     if record.name.endswith('.'):
         record.name = record.name[:-1]
     cur = self._dbh.execute(
         con, "DELETE FROM records "
         "WHERE domain_id=%s AND name=%s AND type=%s AND content=%s",
         utils.name(current), record.name, str(record.type), record.data)
     if cur.rowcount == 0:
         self._check_existance(con, current)
         #no exception raised - zone exists, but no such record
         raise ICore.NotFoundError("No such record.")
     con.commit()
Example #6
0
 def replaceRecord(self, con, oldr, newr, current):
     domain = self._get_name(con, current)
     if oldr.name.endswith('.'):
         oldr.name = oldr.name[:-1]
     args = self._unpack_record(newr, None, domain)[1:]
     args += (utils.name(current), oldr.name, str(oldr.type), oldr.data)
     cur = self._dbh.execute(
         con, "UPDATE records SET "
         "name=%s, type=%s, content=%s, ttl=%s, prio=%s "
         "WHERE domain_id=%s AND name=%s AND type=%s AND content=%s", *args)
     if cur.rowcount != 1:
         # domain already exists, so there is no such record
         raise ICore.NotFoundError("Failed to replace record",
                                   "Record not found")
     con.commit()
Example #7
0
 def _dropZone(self, con, key):
     cur = self._dbh.execute(con, "DELETE FROM domains WHERE id=%s", key)
     if cur.rowcount != 1:
         raise ICore.NotFoundError("Zone not found in database.")
     self._dbh.execute(con, "DELETE FROM records WHERE domain_id=%s", key)
     con.commit()