818dc60b626e23772e46794e5d2a659b40c413a4
[tridge/samba.git] / source4 / rpc_server / dnsserver / dnsserver.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    DNS Server
5
6    Copyright (C) Amitay Isaacs 2011
7
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.
12
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.
17
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/>.
20 */
21
22 #ifndef __DNSSERVER_H__
23 #define __DNSSERVER_H__
24
25 #include "librpc/gen_ndr/dnsp.h"
26 #include "librpc/gen_ndr/dnsserver.h"
27 #include "param/param.h"
28 #include "ldb.h"
29
30 struct dnsserver_serverinfo {
31         uint32_t        dwVersion;
32         uint8_t         fBootMethod;
33         uint8_t         fAdminConfigured;
34         uint8_t         fAllowUpdate;
35         uint8_t         fDsAvailable;
36
37         char *          pszServerName;
38         char *          pszDsContainer;
39
40         uint32_t        dwDsForestVersion;
41         uint32_t        dwDsDomainVersion;
42         uint32_t        dwDsDsaVersion;
43         uint32_t        fReadOnlyDC;
44         char *          pszDomainName;
45         char *          pszForestName;
46         char *          pszDomainDirectoryPartition;
47         char *          pszForestDirectoryPartition;
48
49         struct IP4_ARRAY * aipServerAddrs;
50         struct IP4_ARRAY * aipListenAddrs;
51         struct IP4_ARRAY * aipForwarders;
52
53         struct IP4_ARRAY * aipLogFilter;
54         char *          pwszLogFilePath;
55
56         uint32_t        dwLogLevel;
57         uint32_t        dwDebugLevel;
58         uint32_t        dwEventLogLevel;
59         uint32_t        dwLogFileMaxSize;
60
61         uint32_t        dwForwardTimeout;
62         uint32_t        dwRpcProtocol;
63         uint32_t        dwNameCheckFlag;
64         uint32_t        cAddressAnswerLimit;
65         uint32_t        dwRecursionRetry;
66         uint32_t        dwRecursionTimeout;
67         uint32_t        dwMaxCacheTtl;
68         uint32_t        dwDsPollingInterval;
69         uint32_t        dwLocalNetPriorityNetMask;
70
71         uint32_t        dwScavengingInterval;
72         uint32_t        dwDefaultRefreshInterval;
73         uint32_t        dwDefaultNoRefreshInterval;
74         uint32_t        dwLastScavengeTime;
75
76         uint8_t         fAutoReverseZones;
77         uint8_t         fAutoCacheUpdate;
78
79         uint8_t         fRecurseAfterForwarding;
80         uint8_t         fForwardDelegations;
81         uint8_t         fNoRecursion;
82         uint8_t         fSecureResponses;
83
84         uint8_t         fRoundRobin;
85         uint8_t         fLocalNetPriority;
86
87         uint8_t         fBindSecondaries;
88         uint8_t         fWriteAuthorityNs;
89
90         uint8_t         fStrictFileParsing;
91         uint8_t         fLooseWildcarding;
92         uint8_t         fDefaultAgingState;
93 };
94
95 struct dnsserver_zoneinfo {
96         uint8_t         Version;
97         uint32_t        Flags;
98         uint8_t         dwZoneType;
99         uint8_t         fReverse;
100         uint8_t         fAllowUpdate;
101         uint8_t         fPaused;
102         uint8_t         fShutdown;
103         uint8_t         fAutoCreated;
104
105         uint8_t         fUseDatabase;
106         char *          pszDataFile;
107
108         struct IP4_ARRAY * aipMasters;
109
110         uint32_t        fSecureSecondaries;
111         uint32_t        fNotifyLevel;
112         struct IP4_ARRAY * aipSecondaries;
113         struct IP4_ARRAY * aipNotify;
114
115         uint32_t        fUseWins;
116         uint32_t        fUseNbstat;
117
118         uint32_t        fAging;
119         uint32_t        dwNoRefreshInterval;
120         uint32_t        dwRefreshInterval;
121         uint32_t        dwAvailForScavengeTime;
122         struct IP4_ARRAY * aipScavengeServers;
123
124         uint32_t        dwForwarderTimeout;
125         uint32_t        fForwarderSlave;
126
127         struct IP4_ARRAY * aipLocalMasters;
128
129         uint32_t        dwDpFlags;
130         char *          pszDpFqdn;
131         char *          pwszZoneDn;
132
133         uint32_t        dwLastSuccessfulSoaCheck;
134         uint32_t        dwLastSuccessfulXfr;
135
136         uint32_t        fQueuedForBackgroundLoad;
137         uint32_t        fBackgroundLoadInProgress;
138         uint8_t         fReadOnlyZone;
139
140         uint32_t        dwLastXfrAttempt;
141         uint32_t        dwLastXfrResult;
142 };
143
144
145 struct dnsserver_zone {
146         struct dnsserver_zone *prev, *next;
147         const char *name;
148         struct ldb_dn *partition_dn;
149         struct ldb_dn *zone_dn;
150         struct dnsserver_zoneinfo *zoneinfo;
151 };
152
153
154 struct dns_tree {
155         const char *name;
156         int level;
157         unsigned int num_children;
158         struct dns_tree **children;
159         void *data;
160 };
161
162 /* Data structure manipulation functions from dnsdata.c */
163
164 struct IP4_ARRAY *ip4_array_copy(TALLOC_CTX *mem_ctx, struct IP4_ARRAY *ip4);
165 struct DNS_ADDR_ARRAY *ip4_array_to_dns_addr_array(TALLOC_CTX *mem_ctx, struct IP4_ARRAY *ip4);
166 struct DNS_ADDR_ARRAY *dns_addr_array_copy(TALLOC_CTX *mem_ctx, struct DNS_ADDR_ARRAY *addr);
167
168 int dns_split_name_components(TALLOC_CTX *mem_ctx, const char *name, char ***components);
169 char *dns_split_node_name(TALLOC_CTX *mem_ctx, const char *node_name, const char *zone_name);
170
171 int dns_name_compare(const struct ldb_message **m1, const struct ldb_message **m2,
172                         char *search_name);
173 bool dns_name_equal(const char *name1, const char *name2);
174 bool dns_record_match(struct dnsp_DnssrvRpcRecord *rec1, struct dnsp_DnssrvRpcRecord *rec2);
175
176 void dnsp_to_dns_copy(TALLOC_CTX *mem_ctx, struct dnsp_DnssrvRpcRecord *dnsp,
177                         struct DNS_RPC_RECORD *dns);
178 struct dnsp_DnssrvRpcRecord *dns_to_dnsp_copy(TALLOC_CTX *mem_ctx, struct DNS_RPC_RECORD *dns);
179
180 struct dns_tree *dns_build_tree(TALLOC_CTX *mem_ctx, const char *name, struct ldb_result *res);
181 WERROR dns_fill_records_array(TALLOC_CTX *mem_ctx, struct dnsserver_zone *z,
182                         enum dns_record_type record_type,
183                         unsigned int select_flag, const char *zone_name,
184                         struct ldb_message *msg, int num_children,
185                         struct DNS_RPC_RECORDS_ARRAY *recs,
186                         char ***add_names, int *add_count);
187
188
189 /* Utility functions from dnsutils.c */
190
191 struct dnsserver_serverinfo *dnsserver_init_serverinfo(TALLOC_CTX *mem_ctx,
192                                         struct loadparm_context *lp_ctx,
193                                         struct ldb_context *samdb);
194 struct dnsserver_zoneinfo *dnsserver_init_zoneinfo(struct dnsserver_zone *zone,
195                                         struct dnsserver_serverinfo *serverinfo,
196                                         bool is_forest);
197 struct dnsserver_zone *dnsserver_find_zone(struct dnsserver_zone *zones,
198                                         const char *zone_name);
199 struct ldb_dn *dnsserver_name_to_dn(TALLOC_CTX *mem_ctx, struct dnsserver_zone *z,
200                                         const char *name);
201 uint32_t dnsserver_zone_to_request_filter(const char *zone);
202
203
204 /* Database functions from dnsdb.c */
205
206 struct dnsserver_zone *dnsserver_db_enumerate_zones(TALLOC_CTX *mem_ctx,
207                                         struct ldb_context *samdb,
208                                         bool is_forest);
209 WERROR dnsserver_db_add_empty_node(TALLOC_CTX *mem_ctx,
210                                         struct ldb_context *samdb,
211                                         struct dnsserver_zone *z,
212                                         const char *node_name);
213 WERROR dnsserver_db_add_record(TALLOC_CTX *mem_ctx,
214                                         struct ldb_context *samdb,
215                                         struct dnsserver_zone *z,
216                                         const char *node_name,
217                                         struct DNS_RPC_RECORD *add_record);
218 WERROR dnsserver_db_update_record(TALLOC_CTX *mem_ctx,
219                                         struct ldb_context *samdb,
220                                         struct dnsserver_zone *z,
221                                         const char *node_name,
222                                         struct DNS_RPC_RECORD *add_record,
223                                         struct DNS_RPC_RECORD *del_record);
224 WERROR dnsserver_db_delete_record(TALLOC_CTX *mem_ctx,
225                                         struct ldb_context *samdb,
226                                         struct dnsserver_zone *z,
227                                         const char *node_name,
228                                         struct DNS_RPC_RECORD *del_record);
229
230 #endif /* __DNSSERVER_H__ */