2 Unix SMB/CIFS implementation.
6 Copyright (C) Amitay Isaacs 2011
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/>.
23 #include "dnsserver.h"
24 #include "rpc_server/common/common.h"
25 #include "dsdb/samdb/samdb.h"
26 #include "lib/socket/netif.h"
29 struct dnsserver_serverinfo
*dnsserver_init_serverinfo(TALLOC_CTX
*mem_ctx
,
30 struct loadparm_context
*lp_ctx
,
31 struct ldb_context
*samdb
)
33 struct dnsserver_serverinfo
*serverinfo
;
34 struct dcerpc_server_info
*dinfo
;
35 struct ldb_dn
*domain_dn
, *forest_dn
;
36 struct interface
*ifaces
;
37 int num_interfaces
, i
;
39 serverinfo
= talloc_zero(mem_ctx
, struct dnsserver_serverinfo
);
40 if (serverinfo
== NULL
) {
44 dinfo
= lpcfg_dcerpc_server_info(mem_ctx
, lp_ctx
);
46 serverinfo
->dwVersion
= (dinfo
->version_build
& 0x0000FFFF) << 16 |
47 (dinfo
->version_minor
& 0x000000FF) << 8 |
48 (dinfo
->version_major
& 0x000000FF);
51 serverinfo
->dwVersion
= 0x0ECE0205; /* build, os_minor, os_major */;
54 serverinfo
->fBootMethod
= DNS_BOOT_METHOD_DIRECTORY
;
55 serverinfo
->fAdminConfigured
= 0;
56 serverinfo
->fAllowUpdate
= 1;
57 serverinfo
->fDsAvailable
= 1;
59 serverinfo
->pszServerName
= talloc_asprintf(mem_ctx
, "%s.%s",
60 lpcfg_netbios_name(lp_ctx
),
61 lpcfg_dnsdomain(lp_ctx
));
63 domain_dn
= ldb_get_default_basedn(samdb
);
64 forest_dn
= ldb_get_root_basedn(samdb
);
66 serverinfo
->pszDsContainer
= talloc_asprintf(mem_ctx
,
67 "CN=MicrosoftDNS,DC=DomainDnsZones,%s",
68 ldb_dn_get_linearized(domain_dn
));
70 serverinfo
->dwDsForestVersion
= dsdb_forest_functional_level(samdb
);
71 serverinfo
->dwDsDomainVersion
= dsdb_functional_level(samdb
);
72 serverinfo
->dwDsDsaVersion
= 4; /* need to do ldb search here */
74 serverinfo
->pszDomainName
= samdb_dn_to_dns_domain(mem_ctx
, domain_dn
);
75 serverinfo
->pszForestName
= samdb_dn_to_dns_domain(mem_ctx
, forest_dn
);
77 serverinfo
->pszDomainDirectoryPartition
= talloc_asprintf(mem_ctx
,
78 "DC=DomainDnsZones,%s",
79 ldb_dn_get_linearized(domain_dn
));
80 serverinfo
->pszForestDirectoryPartition
= talloc_asprintf(mem_ctx
,
81 "DC=ForestDnsZones,%s",
82 ldb_dn_get_linearized(forest_dn
));
84 load_interface_list(mem_ctx
, lp_ctx
, &ifaces
);
85 num_interfaces
= iface_list_count(ifaces
);
87 serverinfo
->aipServerAddrs
= talloc_zero(mem_ctx
, struct IP4_ARRAY
);
89 if (serverinfo
->aipServerAddrs
) {
90 serverinfo
->aipServerAddrs
->AddrCount
= num_interfaces
;
91 if (num_interfaces
> 0) {
92 serverinfo
->aipServerAddrs
->AddrArray
= talloc_zero_array(mem_ctx
,
95 if (serverinfo
->aipServerAddrs
->AddrArray
) {
96 for (i
=0; i
<num_interfaces
; i
++) {
97 serverinfo
->aipServerAddrs
->AddrArray
[i
] = inet_addr(iface_list_n_ip(ifaces
, i
));
100 serverinfo
->aipServerAddrs
->AddrCount
= 0;
106 /* Assume listen addresses are same as server addresses */
107 serverinfo
->aipListenAddrs
= serverinfo
->aipServerAddrs
;
109 serverinfo
->aipForwarders
= NULL
;
111 serverinfo
->aipLogFilter
= NULL
;
112 serverinfo
->pwszLogFilePath
= NULL
;
114 serverinfo
->dwLogLevel
= 0;
115 serverinfo
->dwDebugLevel
= 0;
116 serverinfo
->dwEventLogLevel
= DNS_EVENT_LOG_INFORMATION_TYPE
;
117 serverinfo
->dwLogFileMaxSize
= 0;
119 serverinfo
->dwForwardTimeout
= 3; /* seconds (default) */
120 serverinfo
->dwRpcProtocol
= 5;
121 serverinfo
->dwNameCheckFlag
= DNS_ALLOW_MULTIBYTE_NAMES
;
122 serverinfo
->cAddressAnswerLimit
= 0;
123 serverinfo
->dwRecursionRetry
= 3 /* seconds (default) */;
124 serverinfo
->dwRecursionTimeout
= 8 /* seconds (default) */;
125 serverinfo
->dwMaxCacheTtl
= 0x00015180; /* 1 day (default) */;
126 serverinfo
->dwDsPollingInterval
= 0xB4; /* 3 minutes (default) */;
127 serverinfo
->dwLocalNetPriorityNetMask
= 0x000000FF;;
129 serverinfo
->dwScavengingInterval
= 0;
130 serverinfo
->dwDefaultRefreshInterval
= 0xA8; /* 7 days in hours */;
131 serverinfo
->dwDefaultNoRefreshInterval
= 0xA8; /* 7 days in hours */;;
132 serverinfo
->dwLastScavengeTime
= 0;
134 serverinfo
->fAutoReverseZones
= 0;
135 serverinfo
->fAutoCacheUpdate
= 0;
137 serverinfo
->fRecurseAfterForwarding
= 0;
138 serverinfo
->fForwardDelegations
= 1;
139 serverinfo
->fNoRecursion
= 0;
140 serverinfo
->fSecureResponses
= 0;
142 serverinfo
->fRoundRobin
= 1;
143 serverinfo
->fLocalNetPriority
= 0;
145 serverinfo
->fBindSecondaries
= 0;
146 serverinfo
->fWriteAuthorityNs
= 0;
148 serverinfo
->fStrictFileParsing
= 0;
149 serverinfo
->fLooseWildcarding
= 0 ;
150 serverinfo
->fDefaultAgingState
= 0;
156 struct dnsserver_zoneinfo
*dnsserver_init_zoneinfo(struct dnsserver_zone
*zone
,
157 struct dnsserver_serverinfo
*serverinfo
)
159 struct dnsserver_zoneinfo
*zoneinfo
;
161 const char *revzone
= "in-addr.arpa";
162 const char *revzone6
= "ip6.arpa";
165 zoneinfo
= talloc_zero(zone
, struct dnsserver_zoneinfo
);
166 if (zoneinfo
== NULL
) {
170 /* If the zone name ends with in-addr.arpa, it's reverse zone */
171 /* If the zone name ends with ip6.arpa, it's reverse zone (IPv6) */
173 len1
= strlen(zone
->name
);
174 len2
= strlen(revzone
);
175 if (len1
> len2
&& strcasecmp(&zone
->name
[len1
-len2
], revzone
) == 0) {
178 len2
= strlen(revzone6
);
179 if (len1
> len2
&& strcasecmp(&zone
->name
[len1
-len2
], revzone6
) == 0) {
184 zoneinfo
->Version
= 0x32;
185 zoneinfo
->Flags
= DNS_RPC_ZONE_DSINTEGRATED
;
187 if (strcmp(zone
->name
, ".") == 0) {
188 zoneinfo
->dwZoneType
= DNS_ZONE_TYPE_CACHE
;
189 zoneinfo
->fAllowUpdate
= DNS_ZONE_UPDATE_OFF
;
190 zoneinfo
->fSecureSecondaries
= DNS_ZONE_SECSECURE_NO_SECURITY
;
191 zoneinfo
->fNotifyLevel
= DNS_ZONE_NOTIFY_OFF
;
192 zoneinfo
->dwNoRefreshInterval
= 0;
193 zoneinfo
->dwRefreshInterval
= 0;
195 zoneinfo
->Flags
|= DNS_RPC_ZONE_UPDATE_SECURE
;
196 zoneinfo
->dwZoneType
= DNS_ZONE_TYPE_PRIMARY
;
197 zoneinfo
->fAllowUpdate
= DNS_ZONE_UPDATE_SECURE
;
198 zoneinfo
->fSecureSecondaries
= DNS_ZONE_SECSECURE_NO_XFER
;
199 zoneinfo
->fNotifyLevel
= DNS_ZONE_NOTIFY_LIST_ONLY
;
200 zoneinfo
->dwNoRefreshInterval
= serverinfo
->dwDefaultNoRefreshInterval
;
201 zoneinfo
->dwRefreshInterval
= serverinfo
->dwDefaultRefreshInterval
;
204 zoneinfo
->fReverse
= fReverse
;
205 zoneinfo
->fPaused
= 0;
206 zoneinfo
->fShutdown
= 0;
207 zoneinfo
->fAutoCreated
= 0;
208 zoneinfo
->fUseDatabase
= 1;
209 zoneinfo
->pszDataFile
= NULL
;
210 zoneinfo
->aipMasters
= NULL
;
211 zoneinfo
->aipSecondaries
= NULL
;
212 zoneinfo
->aipNotify
= NULL
;
213 zoneinfo
->fUseWins
= 0;
214 zoneinfo
->fUseNbstat
= 0;
215 zoneinfo
->fAging
= 0;
216 zoneinfo
->dwAvailForScavengeTime
= 0;
217 zoneinfo
->aipScavengeServers
= NULL
;
218 zoneinfo
->dwForwarderTimeout
= 0;
219 zoneinfo
->fForwarderSlave
= 0;
220 zoneinfo
->aipLocalMasters
= NULL
;
221 zoneinfo
->pwszZoneDn
= discard_const_p(char, ldb_dn_get_linearized(zone
->zone_dn
));
222 zoneinfo
->dwLastSuccessfulSoaCheck
= 0;
223 zoneinfo
->dwLastSuccessfulXfr
= 0;
224 zoneinfo
->fQueuedForBackgroundLoad
= 0;
225 zoneinfo
->fBackgroundLoadInProgress
= 0;
226 zoneinfo
->fReadOnlyZone
= 0;
227 zoneinfo
->dwLastXfrAttempt
= 0;
228 zoneinfo
->dwLastXfrResult
= 0;
233 struct dnsserver_partition
*dnsserver_find_partition(struct dnsserver_partition
*partitions
,
236 struct dnsserver_partition
*p
= NULL
;
238 for (p
= partitions
; p
; p
= p
->next
) {
239 if (strcasecmp(dp_fqdn
, p
->pszDpFqdn
) == 0) {
247 struct dnsserver_zone
*dnsserver_find_zone(struct dnsserver_zone
*zones
, const char *zone_name
)
249 struct dnsserver_zone
*z
= NULL
;
251 for (z
= zones
; z
; z
= z
->next
) {
252 if (strcasecmp(zone_name
, z
->name
) == 0) {
260 struct ldb_dn
*dnsserver_name_to_dn(TALLOC_CTX
*mem_ctx
, struct dnsserver_zone
*z
, const char *name
)
265 dn
= ldb_dn_copy(mem_ctx
, z
->zone_dn
);
269 if (strcasecmp(name
, z
->name
) == 0) {
270 ret
= ldb_dn_add_child_fmt(dn
, "DC=@");
272 ret
= ldb_dn_add_child_fmt(dn
, "DC=%s", name
);
282 uint32_t dnsserver_zone_to_request_filter(const char *zone_name
)
284 uint32_t request_filter
= 0;
286 if (strcmp(zone_name
, "..AllZones") == 0) {
287 request_filter
= DNS_ZONE_REQUEST_PRIMARY
288 | DNS_ZONE_REQUEST_SECONDARY
289 | DNS_ZONE_REQUEST_AUTO
290 | DNS_ZONE_REQUEST_FORWARD
291 | DNS_ZONE_REQUEST_REVERSE
292 | DNS_ZONE_REQUEST_FORWARDER
293 | DNS_ZONE_REQUEST_STUB
294 | DNS_ZONE_REQUEST_DS
295 | DNS_ZONE_REQUEST_NON_DS
296 | DNS_ZONE_REQUEST_DOMAIN_DP
297 | DNS_ZONE_REQUEST_FOREST_DP
298 | DNS_ZONE_REQUEST_CUSTOM_DP
299 | DNS_ZONE_REQUEST_LEGACY_DP
;
300 } else if (strcmp(zone_name
, "..AllZonesAndCache") == 0) {
301 request_filter
= DNS_ZONE_REQUEST_PRIMARY
302 | DNS_ZONE_REQUEST_SECONDARY
303 | DNS_ZONE_REQUEST_CACHE
304 | DNS_ZONE_REQUEST_AUTO
305 | DNS_ZONE_REQUEST_FORWARD
306 | DNS_ZONE_REQUEST_REVERSE
307 | DNS_ZONE_REQUEST_FORWARDER
308 | DNS_ZONE_REQUEST_STUB
309 | DNS_ZONE_REQUEST_DS
310 | DNS_ZONE_REQUEST_NON_DS
311 | DNS_ZONE_REQUEST_DOMAIN_DP
312 | DNS_ZONE_REQUEST_FOREST_DP
313 | DNS_ZONE_REQUEST_CUSTOM_DP
314 | DNS_ZONE_REQUEST_LEGACY_DP
;
315 } else if (strcmp(zone_name
, "..AllPrimaryZones") == 0) {
316 request_filter
= DNS_ZONE_REQUEST_PRIMARY
;
317 } else if (strcmp(zone_name
, "..AllSecondaryZones") == 0) {
318 request_filter
= DNS_ZONE_REQUEST_SECONDARY
;
319 } else if (strcmp(zone_name
, "..AllForwardZones") == 0) {
320 request_filter
= DNS_ZONE_REQUEST_FORWARD
;
321 } else if (strcmp(zone_name
, "..AllReverseZones") == 0) {
322 request_filter
= DNS_ZONE_REQUEST_REVERSE
;
323 } else if (strcmp(zone_name
, "..AllDsZones") == 0) {
324 request_filter
= DNS_ZONE_REQUEST_DS
;
325 } else if (strcmp(zone_name
, "..AllNonDsZones") == 0) {
326 request_filter
= DNS_ZONE_REQUEST_NON_DS
;
327 } else if (strcmp(zone_name
, "..AllPrimaryReverseZones") == 0) {
328 request_filter
= DNS_ZONE_REQUEST_PRIMARY
329 | DNS_ZONE_REQUEST_REVERSE
;
330 } else if (strcmp(zone_name
, "..AllPrimaryForwardZones") == 0) {
331 request_filter
= DNS_ZONE_REQUEST_PRIMARY
332 | DNS_ZONE_REQUEST_FORWARD
;
333 } else if (strcmp(zone_name
, "..AllSecondaryReverseZones") == 0) {
334 request_filter
= DNS_ZONE_REQUEST_SECONDARY
335 | DNS_ZONE_REQUEST_REVERSE
;
336 } else if (strcmp(zone_name
, "..AllSecondaryForwardZones") == 0) {
337 request_filter
= DNS_ZONE_REQUEST_SECONDARY
338 | DNS_ZONE_REQUEST_REVERSE
;
341 return request_filter
;