dns: Delete dnsNode objects when they are empty
[obnox/samba/samba-obnox.git] / source4 / dns_server / dns_utils.c
index b4f308c0279473c631e072cc148cc13db2442d10..72782cf450011bd211ad6e24955ff9eb9390dbb4 100644 (file)
@@ -30,6 +30,9 @@
 #include "dsdb/common/util.h"
 #include "dns_server/dns_server.h"
 
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_DNS
+
 uint8_t werr_to_dns_err(WERROR werr)
 {
        if (W_ERROR_EQUAL(WERR_OK, werr)) {
@@ -54,8 +57,10 @@ uint8_t werr_to_dns_err(WERROR werr)
                return DNS_RCODE_NOTAUTH;
        } else if (W_ERROR_EQUAL(DNS_ERR(NOTZONE), werr)) {
                return DNS_RCODE_NOTZONE;
+       } else if (W_ERROR_EQUAL(DNS_ERR(BADKEY), werr)) {
+               return DNS_RCODE_BADKEY;
        }
-       DEBUG(5, ("No mapping exists for %%s\n"));
+       DEBUG(5, ("No mapping exists for %s\n", win_errstr(werr)));
        return DNS_RCODE_SERVFAIL;
 }
 
@@ -199,11 +204,13 @@ WERROR dns_lookup_records(struct dns_server *dns,
        if (el == NULL) {
                *records = NULL;
                *rec_count = 0;
-               return WERR_OK;
+               return DNS_ERR(NAME_ERROR);
        }
 
        recs = talloc_zero_array(mem_ctx, struct dnsp_DnssrvRpcRecord, el->num_values);
-       W_ERROR_HAVE_NO_MEMORY(recs);
+       if (recs == NULL) {
+               return WERR_NOMEM;
+       }
        for (ri = 0; ri < el->num_values; ri++) {
                struct ldb_val *v = &el->values[ri];
                enum ndr_err_code ndr_err;
@@ -269,7 +276,13 @@ WERROR dns_replace_records(struct dns_server *dns,
                if (needs_add) {
                        return WERR_OK;
                }
-               /* TODO: Delete object? */
+               /* No entries left, delete the dnsNode object */
+               ret = ldb_delete(dns->samdb, msg->dn);
+               if (ret != LDB_SUCCESS) {
+                       DEBUG(0, ("Deleting record failed; %d\n", ret));
+                       return DNS_ERR(SERVER_FAILURE);
+               }
+               return WERR_OK;
        }
 
        if (needs_add) {
@@ -371,3 +384,24 @@ WERROR dns_name2dn(struct dns_server *dns,
        *_dn = dn;
        return WERR_OK;
 }
+
+WERROR dns_generate_options(struct dns_server *dns,
+                           TALLOC_CTX *mem_ctx,
+                           struct dns_res_rec **options)
+{
+       struct dns_res_rec *o;
+
+       o = talloc_zero(mem_ctx, struct dns_res_rec);
+       if (o == NULL) {
+               return WERR_NOMEM;
+       }
+       o->name = '\0';
+       o->rr_type = DNS_QTYPE_OPT;
+       /* This is ugly, but RFC2671 wants the payload size in this field */
+       o->rr_class = (enum dns_qclass) dns->max_payload;
+       o->ttl = 0;
+       o->length = 0;
+
+       *options = o;
+       return WERR_OK;
+}