s4 dns: Switch to WERROR
authorKai Blin <kai@samba.org>
Mon, 11 Oct 2010 21:39:44 +0000 (23:39 +0200)
committerKai Blin <kai@samba.org>
Sat, 23 Oct 2010 10:17:06 +0000 (10:17 +0000)
source4/dns_server/dns_query.c
source4/dns_server/dns_server.c
source4/dns_server/dns_server.h
source4/dns_server/dns_update.c
source4/dns_server/dns_utils.c

index f8c39ffe090706146bd06e6f727c5c02936ad36e..bf82ae2e92f4cb97f9d5ff084a289326e3fc2033 100644 (file)
@@ -20,7 +20,7 @@
 */
 
 #include "includes.h"
-#include "libcli/util/ntstatus.h"
+#include "libcli/util/werror.h"
 #include "librpc/ndr/libndr.h"
 #include "librpc/gen_ndr/ndr_dns.h"
 #include "librpc/gen_ndr/ndr_dnsp.h"
 #include "dsdb/common/util.h"
 #include "dns_server/dns_server.h"
 
-static NTSTATUS handle_question(struct dns_server *dns,
-                               TALLOC_CTX *mem_ctx,
-                               const struct dns_name_question *question,
-                               struct dns_res_rec **answers, uint16_t *ancount)
+static WERROR handle_question(struct dns_server *dns,
+                             TALLOC_CTX *mem_ctx,
+                             const struct dns_name_question *question,
+                             struct dns_res_rec **answers, uint16_t *ancount)
 {
        struct dns_res_rec *ans;
        struct ldb_dn *dn = NULL;
-       NTSTATUS status;
+       WERROR werror;
        static const char * const attrs[] = { "dnsRecord", NULL};
        int ret;
        uint16_t ai = *ancount;
@@ -45,18 +45,18 @@ static NTSTATUS handle_question(struct dns_server *dns,
        struct dnsp_DnssrvRpcRecord *recs;
        struct ldb_message_element *el;
 
-       status = dns_name2dn(dns, mem_ctx, question->name, &dn);
-       NT_STATUS_NOT_OK_RETURN(status);
+       werror = dns_name2dn(dns, mem_ctx, question->name, &dn);
+       W_ERROR_NOT_OK_RETURN(werror);
 
        ret = dsdb_search_one(dns->samdb, mem_ctx, &msg, dn,
                              LDB_SCOPE_BASE, attrs, 0, "%s", "(objectClass=dnsNode)");
        if (ret != LDB_SUCCESS) {
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+               return DNS_ERR(NAME_ERROR);
        }
 
        el = ldb_msg_find_element(msg, attrs[0]);
        if (el == NULL) {
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+               return DNS_ERR(NAME_ERROR);
        }
 
        recs = talloc_array(mem_ctx, struct dnsp_DnssrvRpcRecord, el->num_values);
@@ -68,13 +68,13 @@ static NTSTATUS handle_question(struct dns_server *dns,
                                (ndr_pull_flags_fn_t)ndr_pull_dnsp_DnssrvRpcRecord);
                if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
                        DEBUG(0, ("Failed to grab dnsp_DnssrvRpcRecord\n"));
-                       return NT_STATUS_INTERNAL_DB_CORRUPTION;
+                       return DNS_ERR(SERVER_FAILURE);
                }
        }
 
        ans = talloc_realloc(mem_ctx, *answers, struct dns_res_rec,
                             ai + el->num_values);
-       NT_STATUS_HAVE_NO_MEMORY(ans);
+       W_ERROR_HAVE_NO_MEMORY(ans);
 
        switch (question->question_type) {
        case DNS_QTYPE_CNAME:
@@ -185,38 +185,38 @@ static NTSTATUS handle_question(struct dns_server *dns,
                }
                break;
        default:
-               return NT_STATUS_NOT_IMPLEMENTED;
+               return DNS_ERR(NOT_IMPLEMENTED);
        }
 
        if (*ancount == ai) {
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+               return DNS_ERR(NAME_ERROR);
        }
 
        *ancount = ai;
        *answers = ans;
 
-       return NT_STATUS_OK;
+       return WERR_OK;
 
 }
 
-NTSTATUS dns_server_process_query(struct dns_server *dns,
-                                 TALLOC_CTX *mem_ctx,
-                                 struct dns_name_packet *in,
-                                 struct dns_res_rec **answers,    uint16_t *ancount,
-                                 struct dns_res_rec **nsrecs,     uint16_t *nscount,
-                                 struct dns_res_rec **additional, uint16_t *arcount)
+WERROR dns_server_process_query(struct dns_server *dns,
+                               TALLOC_CTX *mem_ctx,
+                               struct dns_name_packet *in,
+                               struct dns_res_rec **answers,    uint16_t *ancount,
+                               struct dns_res_rec **nsrecs,     uint16_t *nscount,
+                               struct dns_res_rec **additional, uint16_t *arcount)
 {
        uint16_t num_answers=0;
        struct dns_res_rec *ans=NULL;
        int i;
-       NTSTATUS status;
+       WERROR werror;
 
        ans = talloc_array(mem_ctx, struct dns_res_rec, 0);
-       if (answers == NULL) return NT_STATUS_NO_MEMORY;
+       W_ERROR_HAVE_NO_MEMORY(ans);
 
        for (i = 0; i < in->qdcount; ++i) {
-               status = handle_question(dns, mem_ctx, &in->questions[i], &ans, &num_answers);
-               NT_STATUS_NOT_OK_RETURN(status);
+               werror = handle_question(dns, mem_ctx, &in->questions[i], &ans, &num_answers);
+               W_ERROR_NOT_OK_RETURN(werror);
        }
 
        *answers = ans;
@@ -229,5 +229,5 @@ NTSTATUS dns_server_process_query(struct dns_server *dns,
        *additional = NULL;
        *arcount    = 0;
 
-       return NT_STATUS_OK;
+       return WERR_OK;
 }
index e17ec2d8870d18af37f59e778c7f0e6e82bc24b6..91469681277b234f467e07863f17efb6f6039513 100644 (file)
@@ -97,12 +97,11 @@ static NTSTATUS dns_process(struct dns_server *dns,
                            DATA_BLOB *out)
 {
        enum ndr_err_code ndr_err;
-       NTSTATUS ret;
+       WERROR ret;
        struct dns_name_packet *in_packet;
        struct dns_name_packet *out_packet;
        struct dns_res_rec *answers = NULL, *nsrecs = NULL, *additional = NULL;
        uint16_t num_answers = 0 , num_nsrecs = 0, num_additional = 0;
-       uint16_t reply_code;
 
        if (in->length < 12) {
                return NT_STATUS_INVALID_PARAMETER;
@@ -141,23 +140,20 @@ static NTSTATUS dns_process(struct dns_server *dns,
                                               &answers, &num_answers,
                                               &nsrecs,  &num_nsrecs,
                                               &additional, &num_additional);
-               reply_code = DNS_RCODE_NXDOMAIN;
 
                break;
        case DNS_OPCODE_REGISTER:
                ret = dns_server_process_update(dns, out_packet, in_packet,
-                                               &answers, &num_answers,
+                                               answers, num_answers,
                                                &nsrecs,  &num_nsrecs,
                                                &additional, &num_additional);
-               reply_code = ntstatus_to_dns_err(ret);
                break;
        default:
-               ret = NT_STATUS_NOT_IMPLEMENTED;
-               reply_code = DNS_RCODE_NOTIMP;
+               ret = WERR_DNS_ERROR_RCODE_NOT_IMPLEMENTED;
                break;
        }
 
-       if (NT_STATUS_IS_OK(ret)) {
+       if (W_ERROR_IS_OK(ret)) {
                out_packet->ancount = num_answers;
                out_packet->answers = answers;
 
@@ -167,7 +163,7 @@ static NTSTATUS dns_process(struct dns_server *dns,
                out_packet->arcount = num_additional;
                out_packet->additional = additional;
        } else {
-               out_packet->operation |= reply_code;
+               out_packet->operation |= werr_to_dns_err(ret);
        }
 
        NDR_PRINT_DEBUG(dns_name_packet, out_packet);
index ee3f88446059b62134e6099acafb4176d66017c4..28351e895571737f6f7bec015f971432e5d62319 100644 (file)
@@ -39,26 +39,26 @@ struct dns_server {
 };
 
 
-NTSTATUS dns_server_process_query(struct dns_server *dns,
-                                 TALLOC_CTX *mem_ctx,
-                                 struct dns_name_packet *in,
-                                 struct dns_res_rec **answers,    uint16_t *ancount,
-                                 struct dns_res_rec **nsrecs,     uint16_t *nscount,
-                                 struct dns_res_rec **additional, uint16_t *arcount);
+WERROR dns_server_process_query(struct dns_server *dns,
+                               TALLOC_CTX *mem_ctx,
+                               struct dns_name_packet *in,
+                               struct dns_res_rec **answers,    uint16_t *ancount,
+                               struct dns_res_rec **nsrecs,     uint16_t *nscount,
+                               struct dns_res_rec **additional, uint16_t *arcount);
 
-NTSTATUS dns_server_process_update(struct dns_server *dns,
-                                  TALLOC_CTX *mem_ctx,
-                                  struct dns_name_packet *in,
-                                  struct dns_res_rec **prereqs,    uint16_t *prereq_count,
-                                  struct dns_res_rec **updates,    uint16_t *update_count,
-                                  struct dns_res_rec **additional, uint16_t *arcount);
+WERROR dns_server_process_update(struct dns_server *dns,
+                                TALLOC_CTX *mem_ctx,
+                                struct dns_name_packet *in,
+                                const struct dns_res_rec *prereqs, uint16_t prereq_count,
+                                struct dns_res_rec **updates,      uint16_t *update_count,
+                                struct dns_res_rec **additional,   uint16_t *arcount);
 
-NTSTATUS dns_err_to_ntstatus(enum dns_rcode rcode);
-uint8_t ntstatus_to_dns_err(NTSTATUS status);
+uint8_t werr_to_dns_err(WERROR werror);
 bool dns_name_match(const char *zone, const char *name, size_t *host_part_len);
-NTSTATUS dns_name2dn(struct dns_server *dns,
-                    TALLOC_CTX *mem_ctx,
-                    const char *name,
-                    struct ldb_dn **_dn);
+WERROR dns_name2dn(struct dns_server *dns,
+                  TALLOC_CTX *mem_ctx,
+                  const char *name,
+                  struct ldb_dn **_dn);
 
+#define DNS_ERR(err_str) WERR_DNS_ERROR_RCODE_##err_str
 #endif /* __DNS_SERVER_H__ */
index d243736b5bb9761bc5586ade4a8849adf96638e6..4cd940ed10665ddd58c07ed591f384c874d82ea3 100644 (file)
 #include "dsdb/common/util.h"
 #include "dns_server/dns_server.h"
 
-NTSTATUS dns_server_process_update(struct dns_server *dns,
-                                  TALLOC_CTX *mem_ctx,
-                                  struct dns_name_packet *in,
-                                  struct dns_res_rec **prereqs,    uint16_t *prereq_count,
-                                  struct dns_res_rec **updates,    uint16_t *update_count,
-                                  struct dns_res_rec **additional, uint16_t *arcount)
+
+WERROR dns_server_process_update(struct dns_server *dns,
+                                TALLOC_CTX *mem_ctx,
+                                struct dns_name_packet *in,
+                                const struct dns_res_rec *prereqs, uint16_t prereq_count,
+                                struct dns_res_rec **updates,      uint16_t *update_count,
+                                struct dns_res_rec **additional,   uint16_t *arcount)
 {
        struct dns_name_question *zone;
-       NTSTATUS status;
        const struct dns_server_zone *z;
        size_t host_part_len = 0;
+       uint16_t i;
 
        if (in->qdcount != 1) {
-               return NT_STATUS_INVALID_PARAMETER;
+               return DNS_ERR(FORMAT_ERROR);
        }
 
        zone = in->questions;
 
        if (zone->question_type != DNS_QTYPE_SOA) {
-               return NT_STATUS_INVALID_PARAMETER;
+               return DNS_ERR(FORMAT_ERROR);
        }
 
        DEBUG(0, ("Got a dns update request.\n"));
@@ -63,12 +64,12 @@ NTSTATUS dns_server_process_update(struct dns_server *dns,
        }
 
        if (z == NULL) {
-               return NT_STATUS_FOOBAR;
+               return DNS_ERR(NOTAUTH);
        }
 
        if (host_part_len != 0) {
-               return NT_STATUS_NOT_IMPLEMENTED;
+               return DNS_ERR(NOT_IMPLEMENTED);
        }
 
-       return NT_STATUS_NOT_IMPLEMENTED;
+       return DNS_ERR(NOT_IMPLEMENTED);
 }
index 2c86f0d52e96b97fcf4001a73bab14f7e579b463..68c0c979da5c087c7135a4238252355d1e22b10a 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "includes.h"
 #include "libcli/util/ntstatus.h"
+#include "libcli/util/werror.h"
 #include "librpc/ndr/libndr.h"
 #include "librpc/gen_ndr/ndr_dns.h"
 #include "librpc/gen_ndr/ndr_dnsp.h"
 #include "dsdb/common/util.h"
 #include "dns_server/dns_server.h"
 
-NTSTATUS dns_err_to_ntstatus(enum dns_rcode rcode)
+uint8_t werr_to_dns_err(WERROR werr)
 {
-       switch (rcode) {
-       case DNS_RCODE_OK: return NT_STATUS_OK;
-       case DNS_RCODE_FORMERR: return NT_STATUS_INVALID_PARAMETER;
-       case DNS_RCODE_SERVFAIL: return NT_STATUS_INTERNAL_ERROR;
-       case DNS_RCODE_NXDOMAIN: return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-       case DNS_RCODE_NOTIMP: return NT_STATUS_NOT_IMPLEMENTED;
-       case DNS_RCODE_REFUSED: return NT_STATUS_ACCESS_DENIED;
-       case DNS_RCODE_NOTAUTH: return NT_STATUS_FOOBAR;
-       default: return NT_STATUS_NONE_MAPPED;
-       }
-}
-
-uint8_t ntstatus_to_dns_err(NTSTATUS status)
-{
-       if (NT_STATUS_EQUAL(NT_STATUS_OK, status)) {
+       if (W_ERROR_EQUAL(WERR_OK, werr)) {
                return DNS_RCODE_OK;
-       } else if (NT_STATUS_EQUAL(NT_STATUS_INVALID_PARAMETER, status)) {
+       } else if (W_ERROR_EQUAL(DNS_ERR(FORMAT_ERROR), werr)) {
                return DNS_RCODE_FORMERR;
-       } else if (NT_STATUS_EQUAL(NT_STATUS_INTERNAL_ERROR, status)) {
+       } else if (W_ERROR_EQUAL(DNS_ERR(SERVER_FAILURE), werr)) {
                return DNS_RCODE_SERVFAIL;
-       } else if (NT_STATUS_EQUAL(NT_STATUS_OBJECT_NAME_NOT_FOUND, status)) {
+       } else if (W_ERROR_EQUAL(DNS_ERR(NAME_ERROR), werr)) {
                return DNS_RCODE_NXDOMAIN;
-       } else if (NT_STATUS_EQUAL(NT_STATUS_NOT_IMPLEMENTED, status)) {
+       } else if (W_ERROR_EQUAL(DNS_ERR(NOT_IMPLEMENTED), werr)) {
                return DNS_RCODE_NOTIMP;
-       } else if (NT_STATUS_EQUAL(NT_STATUS_ACCESS_DENIED, status)) {
+       } else if (W_ERROR_EQUAL(DNS_ERR(REFUSED), werr)) {
                return DNS_RCODE_REFUSED;
-       } else if (NT_STATUS_EQUAL(NT_STATUS_FOOBAR, status)) {
+       } else if (W_ERROR_EQUAL(DNS_ERR(YXDOMAIN), werr)) {
+               return DNS_RCODE_YXDOMAIN;
+       } else if (W_ERROR_EQUAL(DNS_ERR(YXRRSET), werr)) {
+               return DNS_RCODE_YXRRSET;
+       } else if (W_ERROR_EQUAL(DNS_ERR(NXRRSET), werr)) {
+               return DNS_RCODE_NXRRSET;
+       } else if (W_ERROR_EQUAL(DNS_ERR(NOTAUTH), werr)) {
                return DNS_RCODE_NOTAUTH;
+       } else if (W_ERROR_EQUAL(DNS_ERR(NOTZONE), werr)) {
+               return DNS_RCODE_NOTZONE;
        }
-       DEBUG(0, ("No mapping exists for %s\n", nt_errstr(status)));
-       return DNS_RCODE_NOTIMP;
+       DEBUG(5, ("No mapping exists for %%s\n"));
+       return DNS_RCODE_SERVFAIL;
 }
 
 bool dns_name_match(const char *zone, const char *name, size_t *host_part_len)
@@ -105,10 +100,10 @@ bool dns_name_match(const char *zone, const char *name, size_t *host_part_len)
        return true;
 }
 
-NTSTATUS dns_name2dn(struct dns_server *dns,
-                    TALLOC_CTX *mem_ctx,
-                    const char *name,
-                    struct ldb_dn **_dn)
+WERROR dns_name2dn(struct dns_server *dns,
+                  TALLOC_CTX *mem_ctx,
+                  const char *name,
+                  struct ldb_dn **_dn)
 {
        struct ldb_dn *base;
        struct ldb_dn *dn;
@@ -116,7 +111,7 @@ NTSTATUS dns_name2dn(struct dns_server *dns,
        size_t host_part_len = 0;
 
        if (name == NULL) {
-               return NT_STATUS_INVALID_PARAMETER;
+               return DNS_ERR(FORMAT_ERROR);
        }
 
        /*TODO: Check if 'name' is a valid DNS name */
@@ -126,7 +121,7 @@ NTSTATUS dns_name2dn(struct dns_server *dns,
                dn = ldb_dn_copy(mem_ctx, base);
                ldb_dn_add_child_fmt(dn, "DC=@,DC=RootDNSServers,CN=MicrosoftDNS,CN=System");
                *_dn = dn;
-               return NT_STATUS_OK;
+               return WERR_OK;
        }
 
        for (z = dns->zones; z != NULL; z = z->next) {
@@ -139,18 +134,18 @@ NTSTATUS dns_name2dn(struct dns_server *dns,
        }
 
        if (z == NULL) {
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+               return DNS_ERR(NAME_ERROR);
        }
 
        if (host_part_len == 0) {
                dn = ldb_dn_copy(mem_ctx, z->dn);
                ldb_dn_add_child_fmt(dn, "DC=@");
                *_dn = dn;
-               return NT_STATUS_OK;
+               return WERR_OK;
        }
 
        dn = ldb_dn_copy(mem_ctx, z->dn);
        ldb_dn_add_child_fmt(dn, "DC=%*.*s", (int)host_part_len, (int)host_part_len, name);
        *_dn = dn;
-       return NT_STATUS_OK;
+       return WERR_OK;
 }