diff options
author | Kai Blin <kai@samba.org> | 2010-10-11 23:39:44 +0200 |
---|---|---|
committer | Kai Blin <kai@samba.org> | 2010-10-23 10:17:06 +0000 |
commit | cfa47965fe2aacf861a107c0db4daa5d43180471 (patch) | |
tree | c9af64af9e47efe426493dd30b6bdc2900e5f304 /source4 | |
parent | 682a2e93daddbd95e617dde9dcdc7dee7a739929 (diff) | |
download | samba-cfa47965fe2aacf861a107c0db4daa5d43180471.tar.gz samba-cfa47965fe2aacf861a107c0db4daa5d43180471.tar.bz2 samba-cfa47965fe2aacf861a107c0db4daa5d43180471.zip |
s4 dns: Switch to WERROR
Diffstat (limited to 'source4')
-rw-r--r-- | source4/dns_server/dns_query.c | 52 | ||||
-rw-r--r-- | source4/dns_server/dns_server.c | 14 | ||||
-rw-r--r-- | source4/dns_server/dns_server.h | 36 | ||||
-rw-r--r-- | source4/dns_server/dns_update.c | 25 | ||||
-rw-r--r-- | source4/dns_server/dns_utils.c | 61 |
5 files changed, 90 insertions, 98 deletions
diff --git a/source4/dns_server/dns_query.c b/source4/dns_server/dns_query.c index f8c39ffe09..bf82ae2e92 100644 --- a/source4/dns_server/dns_query.c +++ b/source4/dns_server/dns_query.c @@ -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" @@ -29,14 +29,14 @@ #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; } diff --git a/source4/dns_server/dns_server.c b/source4/dns_server/dns_server.c index e17ec2d887..9146968127 100644 --- a/source4/dns_server/dns_server.c +++ b/source4/dns_server/dns_server.c @@ -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); diff --git a/source4/dns_server/dns_server.h b/source4/dns_server/dns_server.h index ee3f884460..28351e8955 100644 --- a/source4/dns_server/dns_server.h +++ b/source4/dns_server/dns_server.h @@ -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__ */ diff --git a/source4/dns_server/dns_update.c b/source4/dns_server/dns_update.c index d243736b5b..4cd940ed10 100644 --- a/source4/dns_server/dns_update.c +++ b/source4/dns_server/dns_update.c @@ -29,26 +29,27 @@ #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); } diff --git a/source4/dns_server/dns_utils.c b/source4/dns_server/dns_utils.c index 2c86f0d52e..68c0c979da 100644 --- a/source4/dns_server/dns_utils.c +++ b/source4/dns_server/dns_utils.c @@ -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" @@ -29,39 +30,33 @@ #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; } |