ctdb-common: Map ENOENT for a missing event script to ENOEXEC
[samba4-gss.git] / source4 / dns_server / dns_utils.c
blobd0661f35f6f69c0f7961bc94f67873996d868a01
1 /*
2 Unix SMB/CIFS implementation.
4 DNS server utils
6 Copyright (C) 2010 Kai Blin <kai@samba.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "libcli/util/ntstatus.h"
24 #include "libcli/util/werror.h"
25 #include "librpc/ndr/libndr.h"
26 #include "librpc/gen_ndr/ndr_dns.h"
27 #include "librpc/gen_ndr/ndr_dnsp.h"
28 #include <ldb.h>
29 #include "dsdb/samdb/samdb.h"
30 #include "dsdb/common/util.h"
31 #include "dns_server/dns_server.h"
33 #undef DBGC_CLASS
34 #define DBGC_CLASS DBGC_DNS
38 * Lookup a DNS record, performing an exact match.
39 * i.e. DNS wild card records are not considered.
41 WERROR dns_lookup_records(struct dns_server *dns,
42 TALLOC_CTX *mem_ctx,
43 struct ldb_dn *dn,
44 struct dnsp_DnssrvRpcRecord **records,
45 uint16_t *rec_count)
47 return dns_common_lookup(dns->samdb, mem_ctx, dn,
48 records, rec_count, NULL);
52 * Lookup a DNS record, will match DNS wild card records if an exact match
53 * is not found.
55 WERROR dns_lookup_records_wildcard(struct dns_server *dns,
56 TALLOC_CTX *mem_ctx,
57 struct ldb_dn *dn,
58 struct dnsp_DnssrvRpcRecord **records,
59 uint16_t *rec_count)
61 return dns_common_wildcard_lookup(dns->samdb, mem_ctx, dn,
62 records, rec_count);
65 WERROR dns_replace_records(struct dns_server *dns,
66 TALLOC_CTX *mem_ctx,
67 struct ldb_dn *dn,
68 bool needs_add,
69 struct dnsp_DnssrvRpcRecord *records,
70 uint16_t rec_count)
72 /* TODO: Autogenerate this somehow */
73 uint32_t dwSerial = 110;
74 return dns_common_replace(dns->samdb, mem_ctx, dn,
75 needs_add, dwSerial, records, rec_count);
78 bool dns_authoritative_for_zone(struct dns_server *dns,
79 const char *name)
81 const struct dns_server_zone *z;
82 size_t host_part_len = 0;
84 if (name == NULL) {
85 return false;
88 if (strcmp(name, "") == 0) {
89 return true;
91 for (z = dns->zones; z != NULL; z = z->next) {
92 bool match;
94 match = dns_name_match(z->name, name, &host_part_len);
95 if (match) {
96 break;
99 if (z == NULL) {
100 return false;
103 return true;
106 const char *dns_get_authoritative_zone(struct dns_server *dns,
107 const char *name)
109 const struct dns_server_zone *z;
110 size_t host_part_len = 0;
112 for (z = dns->zones; z != NULL; z = z->next) {
113 bool match;
114 match = dns_name_match(z->name, name, &host_part_len);
115 if (match) {
116 return z->name;
119 return NULL;
122 WERROR dns_name2dn(struct dns_server *dns,
123 TALLOC_CTX *mem_ctx,
124 const char *name,
125 struct ldb_dn **dn)
127 return dns_common_name2dn(dns->samdb, dns->zones,
128 mem_ctx, name, dn);