LCOV - code coverage report
Current view: top level - source4/rpc_server/dnsserver - dcerpc_dnsserver.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 577 1582 36.5 %
Date: 2024-02-28 12:06:22 Functions: 18 23 78.3 %

          Line data    Source code
       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             : #include "includes.h"
      23             : #include "talloc.h"
      24             : #include "rpc_server/dcerpc_server.h"
      25             : #include "rpc_server/common/common.h"
      26             : #include "dsdb/samdb/samdb.h"
      27             : #include "lib/util/dlinklist.h"
      28             : #include "librpc/gen_ndr/ndr_dnsserver.h"
      29             : #include "dns_server/dnsserver_common.h"
      30             : #include "dnsserver.h"
      31             : 
      32             : #undef strcasecmp
      33             : 
      34             : #define DCESRV_INTERFACE_DNSSERVER_BIND(context, iface) \
      35             :         dcesrv_interface_dnsserver_bind(context, iface)
      36        1609 : static NTSTATUS dcesrv_interface_dnsserver_bind(struct dcesrv_connection_context *context,
      37             :                                                 const struct dcesrv_interface *iface)
      38             : {
      39        1609 :         return dcesrv_interface_bind_require_integrity(context, iface);
      40             : }
      41             : 
      42             : #define DNSSERVER_STATE_MAGIC 0xc9657ab4
      43             : struct dnsserver_state {
      44             :         struct loadparm_context *lp_ctx;
      45             :         struct ldb_context *samdb;
      46             :         struct dnsserver_partition *partitions;
      47             :         struct dnsserver_zone *zones;
      48             :         int zones_count;
      49             :         struct dnsserver_serverinfo *serverinfo;
      50             : };
      51             : 
      52             : 
      53             : /* Utility functions */
      54             : 
      55         806 : static void dnsserver_reload_zones(struct dnsserver_state *dsstate)
      56             : {
      57           0 :         struct dnsserver_partition *p;
      58           0 :         struct dnsserver_zone *zones, *z, *znext, *zmatch;
      59           0 :         struct dnsserver_zone *old_list, *new_list;
      60             : 
      61         806 :         old_list = dsstate->zones;
      62         806 :         new_list = NULL;
      63             : 
      64        2418 :         for (p = dsstate->partitions; p; p = p->next) {
      65        1612 :                 zones = dnsserver_db_enumerate_zones(dsstate, dsstate->samdb, p);
      66        1612 :                 if (zones == NULL) {
      67           0 :                         continue;
      68             :                 }
      69        4455 :                 for (z = zones; z; ) {
      70        2843 :                         znext = z->next;
      71        2843 :                         zmatch = dnsserver_find_zone(old_list, z->name);
      72        2843 :                         if (zmatch == NULL) {
      73             :                                 /* Missing zone */
      74         403 :                                 z->zoneinfo = dnsserver_init_zoneinfo(z, dsstate->serverinfo);
      75         403 :                                 if (z->zoneinfo == NULL) {
      76           0 :                                         continue;
      77             :                                 }
      78         403 :                                 DLIST_ADD_END(new_list, z);
      79         403 :                                 p->zones_count++;
      80         403 :                                 dsstate->zones_count++;
      81             :                         } else {
      82             :                                 /* Existing zone */
      83        2440 :                                 talloc_free(z);
      84        2440 :                                 DLIST_REMOVE(old_list, zmatch);
      85        2440 :                                 DLIST_ADD_END(new_list, zmatch);
      86             :                         }
      87        2843 :                         z = znext;
      88             :                 }
      89             :         }
      90             : 
      91         806 :         if (new_list == NULL) {
      92           0 :                 return;
      93             :         }
      94             : 
      95             :         /* Deleted zones */
      96        1209 :         for (z = old_list; z; ) {
      97         403 :                 znext = z->next;
      98         403 :                 z->partition->zones_count--;
      99         403 :                 dsstate->zones_count--;
     100         403 :                 talloc_free(z);
     101         403 :                 z = znext;
     102             :         }
     103             : 
     104         806 :         dsstate->zones = new_list;
     105             : }
     106             : 
     107             : 
     108        6961 : static struct dnsserver_state *dnsserver_connect(struct dcesrv_call_state *dce_call)
     109             : {
     110           0 :         struct dnsserver_state *dsstate;
     111           0 :         struct dnsserver_zone *zones, *z, *znext;
     112           0 :         struct dnsserver_partition *partitions, *p;
     113           0 :         NTSTATUS status;
     114             : 
     115        6961 :         dsstate = dcesrv_iface_state_find_conn(dce_call,
     116             :                                                DNSSERVER_STATE_MAGIC,
     117             :                                                struct dnsserver_state);
     118        6961 :         if (dsstate != NULL) {
     119        5430 :                 return dsstate;
     120             :         }
     121             : 
     122        1531 :         dsstate = talloc_zero(dce_call, struct dnsserver_state);
     123        1531 :         if (dsstate == NULL) {
     124           0 :                 return NULL;
     125             :         }
     126             : 
     127        1531 :         dsstate->lp_ctx = dce_call->conn->dce_ctx->lp_ctx;
     128             : 
     129        1531 :         dsstate->samdb = dcesrv_samdb_connect_as_user(dsstate, dce_call);
     130        1531 :         if (dsstate->samdb == NULL) {
     131           0 :                 DEBUG(0,("dnsserver: Failed to open samdb\n"));
     132           0 :                 goto failed;
     133             :         }
     134             : 
     135             :         /* Initialize server info */
     136        1531 :         dsstate->serverinfo = dnsserver_init_serverinfo(dsstate,
     137             :                                                         dsstate->lp_ctx,
     138             :                                                         dsstate->samdb);
     139        1531 :         if (dsstate->serverinfo == NULL) {
     140           0 :                 goto failed;
     141             :         }
     142             : 
     143             :         /* Search for DNS partitions */
     144        1531 :         partitions = dnsserver_db_enumerate_partitions(dsstate, dsstate->serverinfo, dsstate->samdb);
     145        1531 :         if (partitions == NULL) {
     146           0 :                 goto failed;
     147             :         }
     148        1531 :         dsstate->partitions = partitions;
     149             : 
     150             :         /* Search for DNS zones */
     151        4593 :         for (p = partitions; p; p = p->next) {
     152        3062 :                 zones = dnsserver_db_enumerate_zones(dsstate, dsstate->samdb, p);
     153        3062 :                 if (zones == NULL) {
     154           0 :                         goto failed;
     155             :                 }
     156        8475 :                 for (z = zones; z; ) {
     157        5413 :                         znext = z->next;
     158        5413 :                         if (dnsserver_find_zone(dsstate->zones, z->name) == NULL) {
     159        5413 :                                 z->zoneinfo = dnsserver_init_zoneinfo(z, dsstate->serverinfo);
     160        5413 :                                 if (z->zoneinfo == NULL) {
     161           0 :                                         goto failed;
     162             :                                 }
     163        5413 :                                 DLIST_ADD_END(dsstate->zones, z);
     164        5413 :                                 p->zones_count++;
     165        5413 :                                 dsstate->zones_count++;
     166             :                         } else {
     167             :                                 /* Ignore duplicate zone */
     168           0 :                                 DEBUG(3,("dnsserver: Ignoring duplicate zone '%s' from '%s'\n",
     169             :                                          z->name, ldb_dn_get_linearized(z->zone_dn)));
     170             :                         }
     171        5413 :                         z = znext;
     172             :                 }
     173             :         }
     174             : 
     175        1531 :         status = dcesrv_iface_state_store_conn(dce_call,
     176             :                                                DNSSERVER_STATE_MAGIC,
     177             :                                                dsstate);
     178        1531 :         if (!NT_STATUS_IS_OK(status)) {
     179           0 :                 goto failed;
     180             :         }
     181             : 
     182        1531 :         return dsstate;
     183             : 
     184           0 : failed:
     185           0 :         talloc_free(dsstate);
     186           0 :         dsstate = NULL;
     187           0 :         return NULL;
     188             : }
     189             : 
     190             : 
     191             : /* dnsserver query functions */
     192             : 
     193             : /* [MS-DNSP].pdf Section 3.1.1.1 DNS Server Configuration Information */
     194          12 : static WERROR dnsserver_query_server(struct dnsserver_state *dsstate,
     195             :                                         TALLOC_CTX *mem_ctx,
     196             :                                         const char *operation,
     197             :                                         const unsigned int client_version,
     198             :                                         enum DNS_RPC_TYPEID *typeid,
     199             :                                         union DNSSRV_RPC_UNION *r)
     200             : {
     201           0 :         uint8_t is_integer, is_addresses, is_string, is_wstring, is_stringlist;
     202           0 :         uint32_t answer_integer;
     203          12 :         struct IP4_ARRAY *answer_iparray = NULL;
     204          12 :         struct DNS_ADDR_ARRAY *answer_addrarray = NULL;
     205          12 :         char *answer_string = NULL;
     206          12 :         struct DNS_RPC_UTF8_STRING_LIST *answer_stringlist = NULL;
     207           0 :         struct dnsserver_serverinfo *serverinfo;
     208             : 
     209          12 :         serverinfo = dsstate->serverinfo;
     210             : 
     211          12 :         if (strcasecmp(operation, "ServerInfo") == 0) {
     212          12 :                 if (client_version == DNS_CLIENT_VERSION_W2K) {
     213           4 :                         *typeid = DNSSRV_TYPEID_SERVER_INFO_W2K;
     214           4 :                         r->ServerInfoW2K = talloc_zero(mem_ctx, struct DNS_RPC_SERVER_INFO_W2K);
     215             : 
     216           4 :                         r->ServerInfoW2K->dwVersion = serverinfo->dwVersion;
     217           4 :                         r->ServerInfoW2K->fBootMethod = serverinfo->fBootMethod;
     218           4 :                         r->ServerInfoW2K->fAdminConfigured = serverinfo->fAdminConfigured;
     219           4 :                         r->ServerInfoW2K->fAllowUpdate = serverinfo->fAllowUpdate;
     220           4 :                         r->ServerInfoW2K->fDsAvailable = serverinfo->fDsAvailable;
     221           4 :                         r->ServerInfoW2K->pszServerName = talloc_strdup(mem_ctx, serverinfo->pszServerName);
     222           4 :                         r->ServerInfoW2K->pszDsContainer = talloc_strdup(mem_ctx, serverinfo->pszDsContainer);
     223           4 :                         r->ServerInfoW2K->aipServerAddrs = dns_addr_array_to_ip4_array(mem_ctx,
     224             :                                                                                        serverinfo->aipServerAddrs);
     225           4 :                         r->ServerInfoW2K->aipListenAddrs = dns_addr_array_to_ip4_array(mem_ctx,
     226             :                                                                                        serverinfo->aipListenAddrs);
     227           4 :                         r->ServerInfoW2K->aipForwarders = ip4_array_copy(mem_ctx, serverinfo->aipForwarders);
     228           4 :                         r->ServerInfoW2K->dwLogLevel = serverinfo->dwLogLevel;
     229           4 :                         r->ServerInfoW2K->dwDebugLevel = serverinfo->dwDebugLevel;
     230           4 :                         r->ServerInfoW2K->dwForwardTimeout = serverinfo->dwForwardTimeout;
     231           4 :                         r->ServerInfoW2K->dwRpcProtocol = serverinfo->dwRpcProtocol;
     232           4 :                         r->ServerInfoW2K->dwNameCheckFlag = serverinfo->dwNameCheckFlag;
     233           4 :                         r->ServerInfoW2K->cAddressAnswerLimit = serverinfo->cAddressAnswerLimit;
     234           4 :                         r->ServerInfoW2K->dwRecursionRetry = serverinfo->dwRecursionRetry;
     235           4 :                         r->ServerInfoW2K->dwRecursionTimeout = serverinfo->dwRecursionTimeout;
     236           4 :                         r->ServerInfoW2K->dwMaxCacheTtl = serverinfo->dwMaxCacheTtl;
     237           4 :                         r->ServerInfoW2K->dwDsPollingInterval = serverinfo->dwDsPollingInterval;
     238           4 :                         r->ServerInfoW2K->dwScavengingInterval = serverinfo->dwScavengingInterval;
     239           4 :                         r->ServerInfoW2K->dwDefaultRefreshInterval = serverinfo->dwDefaultRefreshInterval;
     240           4 :                         r->ServerInfoW2K->dwDefaultNoRefreshInterval = serverinfo->dwDefaultNoRefreshInterval;
     241           4 :                         r->ServerInfoW2K->fAutoReverseZones = serverinfo->fAutoReverseZones;
     242           4 :                         r->ServerInfoW2K->fAutoCacheUpdate = serverinfo->fAutoCacheUpdate;
     243           4 :                         r->ServerInfoW2K->fRecurseAfterForwarding = serverinfo->fRecurseAfterForwarding;
     244           4 :                         r->ServerInfoW2K->fForwardDelegations = serverinfo->fForwardDelegations;
     245           4 :                         r->ServerInfoW2K->fNoRecursion = serverinfo->fNoRecursion;
     246           4 :                         r->ServerInfoW2K->fSecureResponses = serverinfo->fSecureResponses;
     247           4 :                         r->ServerInfoW2K->fRoundRobin = serverinfo->fRoundRobin;
     248           4 :                         r->ServerInfoW2K->fLocalNetPriority = serverinfo->fLocalNetPriority;
     249           4 :                         r->ServerInfoW2K->fBindSecondaries = serverinfo->fBindSecondaries;
     250           4 :                         r->ServerInfoW2K->fWriteAuthorityNs = serverinfo->fWriteAuthorityNs;
     251           4 :                         r->ServerInfoW2K->fStrictFileParsing = serverinfo->fStrictFileParsing;
     252           4 :                         r->ServerInfoW2K->fLooseWildcarding = serverinfo->fLooseWildcarding;
     253           4 :                         r->ServerInfoW2K->fDefaultAgingState = serverinfo->fDefaultAgingState;
     254             : 
     255           8 :                 } else if (client_version == DNS_CLIENT_VERSION_DOTNET) {
     256           4 :                         *typeid = DNSSRV_TYPEID_SERVER_INFO_DOTNET;
     257           4 :                         r->ServerInfoDotNet = talloc_zero(mem_ctx, struct DNS_RPC_SERVER_INFO_DOTNET);
     258             : 
     259           4 :                         r->ServerInfoDotNet->dwRpcStructureVersion = 0x01;
     260           4 :                         r->ServerInfoDotNet->dwVersion = serverinfo->dwVersion;
     261           4 :                         r->ServerInfoDotNet->fBootMethod = serverinfo->fBootMethod;
     262           4 :                         r->ServerInfoDotNet->fAdminConfigured = serverinfo->fAdminConfigured;
     263           4 :                         r->ServerInfoDotNet->fAllowUpdate = serverinfo->fAllowUpdate;
     264           4 :                         r->ServerInfoDotNet->fDsAvailable = serverinfo->fDsAvailable;
     265           4 :                         r->ServerInfoDotNet->pszServerName = talloc_strdup(mem_ctx, serverinfo->pszServerName);
     266           4 :                         r->ServerInfoDotNet->pszDsContainer = talloc_strdup(mem_ctx, serverinfo->pszDsContainer);
     267           4 :                         r->ServerInfoDotNet->aipServerAddrs = dns_addr_array_to_ip4_array(mem_ctx,
     268             :                                                                                           serverinfo->aipServerAddrs);
     269           4 :                         r->ServerInfoDotNet->aipListenAddrs = dns_addr_array_to_ip4_array(mem_ctx,
     270             :                                                                                           serverinfo->aipListenAddrs);
     271           4 :                         r->ServerInfoDotNet->aipForwarders = ip4_array_copy(mem_ctx, serverinfo->aipForwarders);
     272           4 :                         r->ServerInfoDotNet->aipLogFilter = ip4_array_copy(mem_ctx, serverinfo->aipLogFilter);
     273           4 :                         r->ServerInfoDotNet->pwszLogFilePath = talloc_strdup(mem_ctx, serverinfo->pwszLogFilePath);
     274           4 :                         r->ServerInfoDotNet->pszDomainName = talloc_strdup(mem_ctx, serverinfo->pszDomainName);
     275           4 :                         r->ServerInfoDotNet->pszForestName = talloc_strdup(mem_ctx, serverinfo->pszForestName);
     276           4 :                         r->ServerInfoDotNet->pszDomainDirectoryPartition = talloc_strdup(mem_ctx, serverinfo->pszDomainDirectoryPartition);
     277           4 :                         r->ServerInfoDotNet->pszForestDirectoryPartition = talloc_strdup(mem_ctx, serverinfo->pszForestDirectoryPartition);
     278           4 :                         r->ServerInfoDotNet->dwLogLevel = serverinfo->dwLogLevel;
     279           4 :                         r->ServerInfoDotNet->dwDebugLevel = serverinfo->dwDebugLevel;
     280           4 :                         r->ServerInfoDotNet->dwForwardTimeout = serverinfo->dwForwardTimeout;
     281           4 :                         r->ServerInfoDotNet->dwRpcProtocol = serverinfo->dwRpcProtocol;
     282           4 :                         r->ServerInfoDotNet->dwNameCheckFlag = serverinfo->dwNameCheckFlag;
     283           4 :                         r->ServerInfoDotNet->cAddressAnswerLimit = serverinfo->cAddressAnswerLimit;
     284           4 :                         r->ServerInfoDotNet->dwRecursionRetry = serverinfo->dwRecursionRetry;
     285           4 :                         r->ServerInfoDotNet->dwRecursionTimeout = serverinfo->dwRecursionTimeout;
     286           4 :                         r->ServerInfoDotNet->dwMaxCacheTtl = serverinfo->dwMaxCacheTtl;
     287           4 :                         r->ServerInfoDotNet->dwDsPollingInterval = serverinfo->dwDsPollingInterval;
     288           4 :                         r->ServerInfoDotNet->dwLocalNetPriorityNetMask = serverinfo->dwLocalNetPriorityNetMask;
     289           4 :                         r->ServerInfoDotNet->dwScavengingInterval = serverinfo->dwScavengingInterval;
     290           4 :                         r->ServerInfoDotNet->dwDefaultRefreshInterval = serverinfo->dwDefaultRefreshInterval;
     291           4 :                         r->ServerInfoDotNet->dwDefaultNoRefreshInterval = serverinfo->dwDefaultNoRefreshInterval;
     292           4 :                         r->ServerInfoDotNet->dwLastScavengeTime = serverinfo->dwLastScavengeTime;
     293           4 :                         r->ServerInfoDotNet->dwEventLogLevel = serverinfo->dwEventLogLevel;
     294           4 :                         r->ServerInfoDotNet->dwLogFileMaxSize = serverinfo->dwLogFileMaxSize;
     295           4 :                         r->ServerInfoDotNet->dwDsForestVersion = serverinfo->dwDsForestVersion;
     296           4 :                         r->ServerInfoDotNet->dwDsDomainVersion = serverinfo->dwDsDomainVersion;
     297           4 :                         r->ServerInfoDotNet->dwDsDsaVersion = serverinfo->dwDsDsaVersion;
     298           4 :                         r->ServerInfoDotNet->fAutoReverseZones = serverinfo->fAutoReverseZones;
     299           4 :                         r->ServerInfoDotNet->fAutoCacheUpdate = serverinfo->fAutoCacheUpdate;
     300           4 :                         r->ServerInfoDotNet->fRecurseAfterForwarding = serverinfo->fRecurseAfterForwarding;
     301           4 :                         r->ServerInfoDotNet->fForwardDelegations = serverinfo->fForwardDelegations;
     302           4 :                         r->ServerInfoDotNet->fNoRecursion = serverinfo->fNoRecursion;
     303           4 :                         r->ServerInfoDotNet->fSecureResponses = serverinfo->fSecureResponses;
     304           4 :                         r->ServerInfoDotNet->fRoundRobin = serverinfo->fRoundRobin;
     305           4 :                         r->ServerInfoDotNet->fLocalNetPriority = serverinfo->fLocalNetPriority;
     306           4 :                         r->ServerInfoDotNet->fBindSecondaries = serverinfo->fBindSecondaries;
     307           4 :                         r->ServerInfoDotNet->fWriteAuthorityNs = serverinfo->fWriteAuthorityNs;
     308           4 :                         r->ServerInfoDotNet->fStrictFileParsing = serverinfo->fStrictFileParsing;
     309           4 :                         r->ServerInfoDotNet->fLooseWildcarding = serverinfo->fLooseWildcarding;
     310           4 :                         r->ServerInfoDotNet->fDefaultAgingState = serverinfo->fDefaultAgingState;
     311             : 
     312           4 :                 } else if (client_version == DNS_CLIENT_VERSION_LONGHORN) {
     313           4 :                         *typeid = DNSSRV_TYPEID_SERVER_INFO;
     314           4 :                         r->ServerInfo = talloc_zero(mem_ctx, struct DNS_RPC_SERVER_INFO_LONGHORN);
     315             : 
     316           4 :                         r->ServerInfo->dwRpcStructureVersion = 0x02;
     317           4 :                         r->ServerInfo->dwVersion = serverinfo->dwVersion;
     318           4 :                         r->ServerInfo->fBootMethod = serverinfo->fBootMethod;
     319           4 :                         r->ServerInfo->fAdminConfigured = serverinfo->fAdminConfigured;
     320           4 :                         r->ServerInfo->fAllowUpdate = serverinfo->fAllowUpdate;
     321           4 :                         r->ServerInfo->fDsAvailable = serverinfo->fDsAvailable;
     322           4 :                         r->ServerInfo->pszServerName = talloc_strdup(mem_ctx, serverinfo->pszServerName);
     323           4 :                         r->ServerInfo->pszDsContainer = talloc_strdup(mem_ctx, serverinfo->pszDsContainer);
     324           4 :                         r->ServerInfo->aipServerAddrs = serverinfo->aipServerAddrs;
     325           4 :                         r->ServerInfo->aipListenAddrs = serverinfo->aipListenAddrs;
     326           4 :                         r->ServerInfo->aipForwarders = ip4_array_to_dns_addr_array(mem_ctx, serverinfo->aipForwarders);
     327           4 :                         r->ServerInfo->aipLogFilter = ip4_array_to_dns_addr_array(mem_ctx, serverinfo->aipLogFilter);
     328           4 :                         r->ServerInfo->pwszLogFilePath = talloc_strdup(mem_ctx, serverinfo->pwszLogFilePath);
     329           4 :                         r->ServerInfo->pszDomainName = talloc_strdup(mem_ctx, serverinfo->pszDomainName);
     330           4 :                         r->ServerInfo->pszForestName = talloc_strdup(mem_ctx, serverinfo->pszForestName);
     331           4 :                         r->ServerInfo->pszDomainDirectoryPartition = talloc_strdup(mem_ctx, serverinfo->pszDomainDirectoryPartition);
     332           4 :                         r->ServerInfo->pszForestDirectoryPartition = talloc_strdup(mem_ctx, serverinfo->pszForestDirectoryPartition);
     333           4 :                         r->ServerInfo->dwLogLevel = serverinfo->dwLogLevel;
     334           4 :                         r->ServerInfo->dwDebugLevel = serverinfo->dwDebugLevel;
     335           4 :                         r->ServerInfo->dwForwardTimeout = serverinfo->dwForwardTimeout;
     336           4 :                         r->ServerInfo->dwRpcProtocol = serverinfo->dwRpcProtocol;
     337           4 :                         r->ServerInfo->dwNameCheckFlag = serverinfo->dwNameCheckFlag;
     338           4 :                         r->ServerInfo->cAddressAnswerLimit = serverinfo->cAddressAnswerLimit;
     339           4 :                         r->ServerInfo->dwRecursionRetry = serverinfo->dwRecursionRetry;
     340           4 :                         r->ServerInfo->dwRecursionTimeout = serverinfo->dwRecursionTimeout;
     341           4 :                         r->ServerInfo->dwMaxCacheTtl = serverinfo->dwMaxCacheTtl;
     342           4 :                         r->ServerInfo->dwDsPollingInterval = serverinfo->dwDsPollingInterval;
     343           4 :                         r->ServerInfo->dwLocalNetPriorityNetMask = serverinfo->dwLocalNetPriorityNetMask;
     344           4 :                         r->ServerInfo->dwScavengingInterval = serverinfo->dwScavengingInterval;
     345           4 :                         r->ServerInfo->dwDefaultRefreshInterval = serverinfo->dwDefaultRefreshInterval;
     346           4 :                         r->ServerInfo->dwDefaultNoRefreshInterval = serverinfo->dwDefaultNoRefreshInterval;
     347           4 :                         r->ServerInfo->dwLastScavengeTime = serverinfo->dwLastScavengeTime;
     348           4 :                         r->ServerInfo->dwEventLogLevel = serverinfo->dwEventLogLevel;
     349           4 :                         r->ServerInfo->dwLogFileMaxSize = serverinfo->dwLogFileMaxSize;
     350           4 :                         r->ServerInfo->dwDsForestVersion = serverinfo->dwDsForestVersion;
     351           4 :                         r->ServerInfo->dwDsDomainVersion = serverinfo->dwDsDomainVersion;
     352           4 :                         r->ServerInfo->dwDsDsaVersion = serverinfo->dwDsDsaVersion;
     353           4 :                         r->ServerInfo->fReadOnlyDC = serverinfo->fReadOnlyDC;
     354           4 :                         r->ServerInfo->fAutoReverseZones = serverinfo->fAutoReverseZones;
     355           4 :                         r->ServerInfo->fAutoCacheUpdate = serverinfo->fAutoCacheUpdate;
     356           4 :                         r->ServerInfo->fRecurseAfterForwarding = serverinfo->fRecurseAfterForwarding;
     357           4 :                         r->ServerInfo->fForwardDelegations = serverinfo->fForwardDelegations;
     358           4 :                         r->ServerInfo->fNoRecursion = serverinfo->fNoRecursion;
     359           4 :                         r->ServerInfo->fSecureResponses = serverinfo->fSecureResponses;
     360           4 :                         r->ServerInfo->fRoundRobin = serverinfo->fRoundRobin;
     361           4 :                         r->ServerInfo->fLocalNetPriority = serverinfo->fLocalNetPriority;
     362           4 :                         r->ServerInfo->fBindSecondaries = serverinfo->fBindSecondaries;
     363           4 :                         r->ServerInfo->fWriteAuthorityNs = serverinfo->fWriteAuthorityNs;
     364           4 :                         r->ServerInfo->fStrictFileParsing = serverinfo->fStrictFileParsing;
     365           4 :                         r->ServerInfo->fLooseWildcarding = serverinfo->fLooseWildcarding;
     366           4 :                         r->ServerInfo->fDefaultAgingState = serverinfo->fDefaultAgingState;
     367             :                 }
     368          12 :                 return WERR_OK;
     369             :         }
     370             : 
     371           0 :         is_integer = 0;
     372           0 :         answer_integer = 0;
     373             : 
     374           0 :         if (strcasecmp(operation, "AddressAnswerLimit") == 0) {
     375           0 :                 answer_integer = serverinfo->cAddressAnswerLimit;
     376           0 :                 is_integer = 1;
     377           0 :         } else if (strcasecmp(operation, "AdminConfigured") == 0) {
     378           0 :                 answer_integer = serverinfo->fAdminConfigured;
     379           0 :                 is_integer = 1;
     380           0 :         } else if (strcasecmp(operation, "AllowCNAMEAtNS") == 0) {
     381           0 :                 answer_integer = 0;
     382           0 :                 is_integer = 1;
     383           0 :         } else if (strcasecmp(operation, "AllowUpdate") == 0) {
     384           0 :                 answer_integer = serverinfo->fAllowUpdate;
     385           0 :                 is_integer = 1;
     386           0 :         } else if (strcasecmp(operation, "AutoCacheUpdate") == 0) {
     387           0 :                 answer_integer = serverinfo->fAutoCacheUpdate;
     388           0 :                 is_integer = 1;
     389           0 :         } else if (strcasecmp(operation, "AutoConfigFileZones") == 0) {
     390           0 :                 answer_integer = 1;
     391           0 :                 is_integer = 1;
     392           0 :         } else if (strcasecmp(operation, "BindSecondaries") == 0) {
     393           0 :                 answer_integer = serverinfo->fBindSecondaries;
     394           0 :                 is_integer = 1;
     395           0 :         } else if (strcasecmp(operation, "BootMethod") == 0) {
     396           0 :                 answer_integer = serverinfo->fBootMethod;
     397           0 :                 is_integer = 1;
     398           0 :         } else if (strcasecmp(operation, "DebugLevel") == 0) {
     399           0 :                 answer_integer = serverinfo->dwDebugLevel;
     400           0 :                 is_integer = 1;
     401           0 :         } else if (strcasecmp(operation, "DefaultAgingState") == 0) {
     402           0 :                 answer_integer = serverinfo->fDefaultAgingState;
     403           0 :                 is_integer = 1;
     404           0 :         } else if (strcasecmp(operation, "DefaultNoRefreshInterval") == 0) {
     405           0 :                 answer_integer = serverinfo->dwDefaultNoRefreshInterval;
     406           0 :                 is_integer = 1;
     407           0 :         } else if (strcasecmp(operation, "DefaultRefreshInterval") == 0) {
     408           0 :                 answer_integer = serverinfo->dwDefaultRefreshInterval;
     409           0 :                 is_integer = 1;
     410           0 :         } else if (strcasecmp(operation, "DeleteOutsideGlue") == 0) {
     411           0 :                 answer_integer = 0;
     412           0 :                 is_integer = 1;
     413           0 :         } else if (strcasecmp(operation, "DisjointNets") == 0) {
     414           0 :                 answer_integer = 0;
     415           0 :                 is_integer = 1;
     416           0 :         } else if (strcasecmp(operation, "DsLazyUpdateInterval") == 0) {
     417           0 :                 answer_integer = 3; /* seconds */
     418           0 :                 is_integer = 1;
     419           0 :         } else if (strcasecmp(operation, "DsPollingInterval") == 0) {
     420           0 :                 answer_integer = serverinfo->dwDsPollingInterval;
     421           0 :                 is_integer = 1;
     422           0 :         } else if (strcasecmp(operation, "DsTombstoneInterval") == 0) {
     423           0 :                 answer_integer = 0x00127500; /* 14 days */
     424           0 :                 is_integer = 1;
     425           0 :         } else if (strcasecmp(operation, "EnableRegistryBoot") == 0) {
     426           0 :                 answer_integer = 0;
     427           0 :                 is_integer = 1;
     428           0 :         } else if (strcasecmp(operation, "EventLogLevel") == 0) {
     429           0 :                 answer_integer = serverinfo->dwEventLogLevel;
     430           0 :                 is_integer = 1;
     431           0 :         } else if (strcasecmp(operation, "ForceSoaSerial") == 0) {
     432           0 :                 answer_integer = 0;
     433           0 :                 is_integer = 1;
     434           0 :         } else if (strcasecmp(operation, "ForceSaoRetry") == 0) {
     435           0 :                 answer_integer = 0;
     436           0 :                 is_integer = 1;
     437           0 :         } else if (strcasecmp(operation, "ForceSoaRefresh") == 0) {
     438           0 :                 answer_integer = 0;
     439           0 :                 is_integer = 1;
     440           0 :         } else if (strcasecmp(operation, "ForceSoaMinimumTtl") == 0) {
     441           0 :                 answer_integer = 0;
     442           0 :                 is_integer = 1;
     443           0 :         } else if (strcasecmp(operation, "ForwardDelegations") == 0) {
     444           0 :                 answer_integer = 1;
     445           0 :                 is_integer = 1;
     446           0 :         } else if (strcasecmp(operation, "ForwardingTimeout") == 0) {
     447           0 :                 answer_integer = serverinfo->dwForwardTimeout;
     448           0 :                 is_integer = 1;
     449           0 :         } else if (strcasecmp(operation, "IsSlave") == 0) {
     450           0 :                 answer_integer = 0;
     451           0 :                 is_integer = 1;
     452           0 :         } else if (strcasecmp(operation, "LocalNetPriority") == 0) {
     453           0 :                 answer_integer = serverinfo->fLocalNetPriority;
     454           0 :                 is_integer = 1;
     455           0 :         } else if (strcasecmp(operation, "LogFileMaxSize") == 0) {
     456           0 :                 answer_integer = serverinfo->dwLogFileMaxSize;
     457           0 :                 is_integer = 1;
     458           0 :         } else if (strcasecmp(operation, "LogLevel") == 0) {
     459           0 :                 answer_integer = serverinfo->dwLogLevel;
     460           0 :                 is_integer = 1;
     461           0 :         } else if (strcasecmp(operation, "LooseWildcarding") == 0) {
     462           0 :                 answer_integer = serverinfo->fLooseWildcarding;
     463           0 :                 is_integer = 1;
     464           0 :         } else if (strcasecmp(operation, "MaxCacheTtl") == 0) {
     465           0 :                 answer_integer = serverinfo->dwMaxCacheTtl;
     466           0 :                 is_integer = 1;
     467           0 :         } else if (strcasecmp(operation, "MaxNegativeCacheTtl") == 0) {
     468           0 :                 answer_integer = 0x00000384; /* 15 minutes */
     469           0 :                 is_integer = 1;
     470           0 :         } else if (strcasecmp(operation, "NameCheckFlag") == 0) {
     471           0 :                 answer_integer = serverinfo->dwNameCheckFlag;
     472           0 :                 is_integer = 1;
     473           0 :         } else if (strcasecmp(operation, "NoRecursion") == 0) {
     474           0 :                 answer_integer = serverinfo->fNoRecursion;
     475           0 :                 is_integer = 1;
     476           0 :         } else if (strcasecmp(operation, "NoUpdateDelegations") == 0) {
     477           0 :                 answer_integer = 1;
     478           0 :                 is_integer = 1;
     479           0 :         } else if (strcasecmp(operation, "PublishAutonet") == 0) {
     480           0 :                 answer_integer = 0;
     481           0 :                 is_integer = 1;
     482           0 :         } else if (strcasecmp(operation, "QuietRecvFaultInterval") == 0) {
     483           0 :                 answer_integer = 0;
     484           0 :                 is_integer = 1;
     485           0 :         } else if (strcasecmp(operation, "QuietRecvLogInterval") == 0) {
     486           0 :                 answer_integer = 0;
     487           0 :                 is_integer = 1;
     488           0 :         } else if (strcasecmp(operation, "RecursionRetry") == 0) {
     489           0 :                 answer_integer = serverinfo->dwRecursionRetry;
     490           0 :                 is_integer = 1;
     491           0 :         } else if (strcasecmp(operation, "RecursionTimeout") == 0) {
     492           0 :                 answer_integer = serverinfo->dwRecursionTimeout;
     493           0 :                 is_integer = 1;
     494           0 :         } else if (strcasecmp(operation, "ReloadException") == 0) {
     495           0 :                 answer_integer = 0;
     496           0 :                 is_integer = 1;
     497           0 :         } else if (strcasecmp(operation, "RoundRobin") == 0) {
     498           0 :                 answer_integer = serverinfo->fRoundRobin;
     499           0 :                 is_integer = 1;
     500           0 :         } else if (strcasecmp(operation, "RpcProtocol") == 0) {
     501           0 :                 answer_integer = serverinfo->dwRpcProtocol;
     502           0 :                 is_integer = 1;
     503           0 :         } else if (strcasecmp(operation, "SecureResponses") == 0) {
     504           0 :                 answer_integer = serverinfo->fSecureResponses;
     505           0 :                 is_integer = 1;
     506           0 :         } else if (strcasecmp(operation, "SendPort") == 0) {
     507           0 :                 answer_integer = 0;
     508           0 :                 is_integer = 1;
     509           0 :         } else if (strcasecmp(operation, "ScavengingInterval") == 0) {
     510           0 :                 answer_integer = serverinfo->dwScavengingInterval;
     511           0 :                 is_integer = 1;
     512           0 :         } else if (strcasecmp(operation, "SocketPoolSize") == 0) {
     513           0 :                 answer_integer = 0x000009C4;
     514           0 :                 is_integer = 1;
     515           0 :         } else if (strcasecmp(operation, "StrictFileParsing") == 0) {
     516           0 :                 answer_integer = serverinfo->fStrictFileParsing;
     517           0 :                 is_integer = 1;
     518           0 :         } else if (strcasecmp(operation, "SyncDnsZoneSerial") == 0) {
     519           0 :                 answer_integer = 2; /* ZONE_SERIAL_SYNC_XFER */
     520           0 :                 is_integer = 1;
     521           0 :         } else if (strcasecmp(operation, "UpdateOptions") == 0) {
     522           0 :                 answer_integer = 0x0000030F; /* DNS_DEFAULT_UPDATE_OPTIONS */
     523           0 :                 is_integer = 1;
     524           0 :         } else if (strcasecmp(operation, "UseSystemEvengLog") == 0) {
     525           0 :                 answer_integer = 0;
     526           0 :                 is_integer = 1;
     527           0 :         } else if (strcasecmp(operation, "Version") == 0) {
     528           0 :                 answer_integer = serverinfo->dwVersion;
     529           0 :                 is_integer = 1;
     530           0 :         } else if (strcasecmp(operation, "XfrConnectTimeout") == 0) {
     531           0 :                 answer_integer = 0x0000001E;
     532           0 :                 is_integer = 1;
     533           0 :         } else if (strcasecmp(operation, "WriteAuthorityNs") == 0) {
     534           0 :                 answer_integer = serverinfo->fWriteAuthorityNs;
     535           0 :                 is_integer = 1;
     536           0 :         } else if (strcasecmp(operation, "AdditionalRecursionTimeout") == 0) {
     537           0 :                 answer_integer = 0x00000004;
     538           0 :                 is_integer = 1;
     539           0 :         } else if (strcasecmp(operation, "AppendMsZoneTransferFlag") == 0) {
     540           0 :                 answer_integer = 0;
     541           0 :                 is_integer = 1;
     542           0 :         } else if (strcasecmp(operation, "AutoCreateDelegations") == 0) {
     543           0 :                 answer_integer = 0; /* DNS_ACD_DONT_CREATE */
     544           0 :                 is_integer = 1;
     545           0 :         } else if (strcasecmp(operation, "BreakOnAscFailure") == 0) {
     546           0 :                 answer_integer = 0;
     547           0 :                 is_integer = 1;
     548           0 :         } else if (strcasecmp(operation, "CacheEmptyAuthResponses") == 0) {
     549           0 :                 answer_integer = 0;
     550           0 :                 is_integer = 1;
     551           0 :         } else if (strcasecmp(operation, "DirectoryPartitionAutoEnlistInterval") == 0) {
     552           0 :                 answer_integer = 0x00015180; /* 1 day */
     553           0 :                 is_integer = 1;
     554           0 :         } else if (strcasecmp(operation, "DisableAutoReverseZones") == 0) {
     555           0 :                 answer_integer = ~serverinfo->fAutoReverseZones;
     556           0 :                 is_integer = 1;
     557           0 :         } else if (strcasecmp(operation, "EDnsCacheTimeout") == 0) {
     558           0 :                 answer_integer = 0x00000384; /* 15 minutes */
     559           0 :                 is_integer = 1;
     560           0 :         } else if (strcasecmp(operation, "EnableDirectoryPartitions") == 0) {
     561           0 :                 answer_integer = serverinfo->fDsAvailable;
     562           0 :                 is_integer = 1;
     563           0 :         } else if (strcasecmp(operation, "EnableDnsSec") == 0) {
     564           0 :                 answer_integer = 0;
     565           0 :                 is_integer = 1;
     566           0 :         } else if (strcasecmp(operation, "EnableEDnsProbes") == 0) {
     567           0 :                 answer_integer = 0;
     568           0 :                 is_integer = 1;
     569           0 :         } else if (strcasecmp(operation, "EnableEDnsReception") == 0) {
     570           0 :                 answer_integer = 0;
     571           0 :                 is_integer = 1;
     572           0 :         } else if (strcasecmp(operation, "EnableIPv6") == 0) {
     573           0 :                 answer_integer = 0;
     574           0 :                 is_integer = 1;
     575           0 :         } else if (strcasecmp(operation, "EnableIQueryResponseGeneration") == 0) {
     576           0 :                 answer_integer = 0;
     577           0 :                 is_integer = 1;
     578           0 :         } else if (strcasecmp(operation, "EnableSendErrorSuppression") == 0) {
     579           0 :                 answer_integer = 0;
     580           0 :                 is_integer = 1;
     581           0 :         } else if (strcasecmp(operation, "EnableUpdateForwarding") == 0) {
     582           0 :                 answer_integer = 0;
     583           0 :                 is_integer = 1;
     584           0 :         } else if (strcasecmp(operation, "EnableWinsR") == 0) {
     585           0 :                 answer_integer = 0;
     586           0 :                 is_integer = 1;
     587           0 :         } else if (strcasecmp(operation, "ForceDsaBehaviorVersion") == 0) {
     588           0 :                 answer_integer = serverinfo->dwDsDsaVersion;
     589           0 :                 is_integer = 1;
     590           0 :         } else if (strcasecmp(operation, "ForceDomainBehaviorVersion") == 0) {
     591           0 :                 answer_integer = serverinfo->dwDsDsaVersion;
     592           0 :                 is_integer = 1;
     593           0 :         } else if (strcasecmp(operation, "ForceForestBehaviorVersion") == 0) {
     594           0 :                 answer_integer = serverinfo->dwDsDsaVersion;
     595           0 :                 is_integer = 1;
     596           0 :         } else if (strcasecmp(operation, "HeapDebug") == 0) {
     597           0 :                 answer_integer = 0;
     598           0 :                 is_integer = 1;
     599           0 :         } else if (strcasecmp(operation, "LameDelegationTtl") == 0) {
     600           0 :                 answer_integer = 0; /* seconds */
     601           0 :                 is_integer = 1;
     602           0 :         } else if (strcasecmp(operation, "LocalNetPriorityNetMask") == 0) {
     603           0 :                 answer_integer = serverinfo->dwLocalNetPriorityNetMask;
     604           0 :                 is_integer = 1;
     605           0 :         } else if (strcasecmp(operation, "MaxCacheSize") == 0) {
     606           0 :                 answer_integer = 0;
     607           0 :                 is_integer = 1;
     608           0 :         } else if (strcasecmp(operation, "MaxResourceRecordsInNonSecureUpdate") == 0) {
     609           0 :                 answer_integer = 0x0000001E;
     610           0 :                 is_integer = 1;
     611           0 :         } else if (strcasecmp(operation, "OperationsLogLevel") == 0) {
     612           0 :                 answer_integer = 0;
     613           0 :                 is_integer = 1;
     614           0 :         } else if (strcasecmp(operation, "OperationsLogLevel2") == 0) {
     615           0 :                 answer_integer = 0;
     616           0 :                 is_integer = 1;
     617           0 :         } else if (strcasecmp(operation, "MaximumUdpPacketSize") == 0) {
     618           0 :                 answer_integer = 0x00004000; /* maximum possible */
     619           0 :                 is_integer = 1;
     620           0 :         } else if (strcasecmp(operation, "RecurseToInternetRootMask") == 0) {
     621           0 :                 answer_integer = 0;
     622           0 :                 is_integer = 1;
     623           0 :         } else if (strcasecmp(operation, "SelfTest") == 0) {
     624           0 :                 answer_integer = 0;
     625           0 :                 is_integer = 1;
     626           0 :         } else if (strcasecmp(operation, "SilentlyIgnoreCNameUpdateConflicts") == 0) {
     627           0 :                 answer_integer = 1;
     628           0 :                 is_integer = 1;
     629           0 :         } else if (strcasecmp(operation, "TcpReceivePacketSize") == 0) {
     630           0 :                 answer_integer = 0x00010000;
     631           0 :                 is_integer = 1;
     632           0 :         } else if (strcasecmp(operation, "XfrThrottleMultiplier") == 0) {
     633           0 :                 answer_integer = 0x0000000A;
     634           0 :                 is_integer = 1;
     635           0 :         } else if (strcasecmp(operation, "AllowMsdcsLookupRetry") == 0) {
     636           0 :                 answer_integer = 1;
     637           0 :                 is_integer = 1;
     638           0 :         } else if (strcasecmp(operation, "AllowReadOnlyZoneTransfer") == 0) {
     639           0 :                 answer_integer = 0;
     640           0 :                 is_integer = 1;
     641           0 :         } else if (strcasecmp(operation, "DsBackGroundLoadPaused") == 0) {
     642           0 :                 answer_integer = 0;
     643           0 :                 is_integer = 1;
     644           0 :         } else if (strcasecmp(operation, "DsMinimumBackgroundLoadThreads") == 0) {
     645           0 :                 answer_integer = 0;
     646           0 :                 is_integer = 1;
     647           0 :         } else if (strcasecmp(operation, "DsRemoteReplicationDelay") == 0) {
     648           0 :                 answer_integer = 0x0000001E; /* 30 seconds */
     649           0 :                 is_integer = 1;
     650           0 :         } else if (strcasecmp(operation, "EnableDuplicateQuerySuppresion") == 0) {
     651           0 :                 answer_integer = 0;
     652           0 :                 is_integer = 1;
     653           0 :         } else if (strcasecmp(operation, "EnableGlobalNamesSupport") == 0) {
     654           0 :                 answer_integer = 0;
     655           0 :                 is_integer = 1;
     656           0 :         } else if (strcasecmp(operation, "EnableVersionQuery") == 0) {
     657           0 :                 answer_integer = 1; /* DNS_VERSION_QUERY_FULL */
     658           0 :                 is_integer = 1;
     659           0 :         } else if (strcasecmp(operation, "EnableRsoForRodc") == 0) {
     660           0 :                 answer_integer = 0;
     661           0 :                 is_integer = 1;
     662           0 :         } else if (strcasecmp(operation, "ForceRODCMode") == 0) {
     663           0 :                 answer_integer = 0;
     664           0 :                 is_integer = 1;
     665           0 :         } else if (strcasecmp(operation, "GlobalNamesAlwaysQuerySrv") == 0) {
     666           0 :                 answer_integer = 1;
     667           0 :                 is_integer = 1;
     668           0 :         } else if (strcasecmp(operation, "GlobalNamesBlockUpdates") == 0) {
     669           0 :                 answer_integer = 0;
     670           0 :                 is_integer = 1;
     671           0 :         } else if (strcasecmp(operation, "GlobalNamesEnableEDnsProbes") == 0) {
     672           0 :                 answer_integer = 0;
     673           0 :                 is_integer = 1;
     674           0 :         } else if (strcasecmp(operation, "GlobalNamesPreferAAAA") == 0) {
     675           0 :                 answer_integer = 0;
     676           0 :                 is_integer = 1;
     677           0 :         } else if (strcasecmp(operation, "GlobalNamesQueryOrder") == 0) {
     678           0 :                 answer_integer = 1;
     679           0 :                 is_integer = 1;
     680           0 :         } else if (strcasecmp(operation, "GlobalNamesSendTimeout") == 0) {
     681           0 :                 answer_integer = 3; /* seconds */
     682           0 :                 is_integer = 1;
     683           0 :         } else if (strcasecmp(operation, "GlobalNamesServerQueryInterval") == 0) {
     684           0 :                 answer_integer = 0x00005460; /* 6 hours */
     685           0 :                 is_integer = 1;
     686           0 :         } else if (strcasecmp(operation, "RemoteIPv4RankBoost") == 0) {
     687           0 :                 answer_integer = 0;
     688           0 :                 is_integer = 1;
     689           0 :         } else if (strcasecmp(operation, "RemoteIPv6RankBoost") == 0) {
     690           0 :                 answer_integer = 0;
     691           0 :                 is_integer = 1;
     692           0 :         } else if (strcasecmp(operation, "MaximumRodcRsoAttemptsPerCycle") == 0) {
     693           0 :                 answer_integer = 0x00000064;
     694           0 :                 is_integer = 1;
     695           0 :         } else if (strcasecmp(operation, "MaximumRodcRsoQueueLength") == 0) {
     696           0 :                 answer_integer = 0x0000012C;
     697           0 :                 is_integer = 1;
     698           0 :         } else if (strcasecmp(operation, "EnableGlobalQueryBlockList") == 0) {
     699           0 :                 answer_integer = 0;
     700           0 :                 is_integer = 1;
     701           0 :         } else if (strcasecmp(operation, "OpenACLOnProxyUpdates") == 0) {
     702           0 :                 answer_integer = 0;
     703           0 :                 is_integer = 1;
     704           0 :         } else if (strcasecmp(operation, "CacheLockingPercent") == 0) {
     705           0 :                 answer_integer = 0x00000064;
     706           0 :                 is_integer = 1;
     707             :         }
     708             : 
     709           0 :         if (is_integer == 1) {
     710           0 :                 *typeid = DNSSRV_TYPEID_DWORD;
     711           0 :                 r->Dword = answer_integer;
     712           0 :                 return WERR_OK;
     713             :         }
     714             : 
     715           0 :         is_addresses = 0;
     716             : 
     717           0 :         if (strcasecmp(operation, "Forwarders") == 0) {
     718           0 :                 if (client_version == DNS_CLIENT_VERSION_LONGHORN) {
     719           0 :                         answer_addrarray = ip4_array_to_dns_addr_array(mem_ctx, serverinfo->aipForwarders);
     720             :                 } else {
     721           0 :                         answer_iparray = ip4_array_copy(mem_ctx, serverinfo->aipForwarders);
     722             :                 }
     723           0 :                 is_addresses = 1;
     724           0 :         } else if (strcasecmp(operation, "ListenAddresses") == 0) {
     725           0 :                 if (client_version == DNS_CLIENT_VERSION_LONGHORN) {
     726           0 :                         answer_addrarray = serverinfo->aipListenAddrs;
     727             :                 } else {
     728           0 :                         answer_iparray = dns_addr_array_to_ip4_array(mem_ctx, serverinfo->aipListenAddrs);
     729             :                 }
     730           0 :                 is_addresses = 1;
     731           0 :         } else if (strcasecmp(operation, "BreakOnReceiveFrom") == 0) {
     732           0 :                 is_addresses = 1;
     733           0 :         } else if (strcasecmp(operation, "BreakOnUpdateFrom") == 0) {
     734           0 :                 is_addresses = 1;
     735           0 :         } else if (strcasecmp(operation, "LogIPFilterList") == 0) {
     736           0 :                 if (client_version == DNS_CLIENT_VERSION_LONGHORN) {
     737           0 :                         answer_addrarray = ip4_array_to_dns_addr_array(mem_ctx, serverinfo->aipLogFilter);
     738             :                 } else {
     739           0 :                         answer_iparray = ip4_array_copy(mem_ctx, serverinfo->aipLogFilter);
     740             :                 }
     741           0 :                 is_addresses = 1;
     742             :         }
     743             : 
     744           0 :         if (is_addresses == 1) {
     745           0 :                 if (client_version == DNS_CLIENT_VERSION_LONGHORN) {
     746           0 :                         *typeid = DNSSRV_TYPEID_ADDRARRAY;
     747           0 :                         r->AddrArray = answer_addrarray;
     748             :                 } else {
     749           0 :                         *typeid = DNSSRV_TYPEID_IPARRAY;
     750           0 :                         r->IpArray = answer_iparray;
     751             :                 }
     752           0 :                 return WERR_OK;
     753             :         }
     754             : 
     755           0 :         is_string = is_wstring = 0;
     756             : 
     757           0 :         if (strcasecmp(operation, "DomainDirectoryPartitionBaseName") == 0) {
     758           0 :                 answer_string = talloc_strdup(mem_ctx, "DomainDnsZones");
     759           0 :                 if (! answer_string) {
     760           0 :                         return WERR_OUTOFMEMORY;
     761             :                 }
     762           0 :                 is_string = 1;
     763           0 :         } else if (strcasecmp(operation, "ForestDirectoryPartitionBaseName") == 0) {
     764           0 :                 answer_string = talloc_strdup(mem_ctx, "ForestDnsZones");
     765           0 :                 if (! answer_string) {
     766           0 :                         return WERR_OUTOFMEMORY;
     767             :                 }
     768           0 :                 is_string = 1;
     769           0 :         } else if (strcasecmp(operation, "LogFilePath") == 0) {
     770           0 :                 answer_string = talloc_strdup(mem_ctx, serverinfo->pwszLogFilePath);
     771           0 :                 is_wstring = 1;
     772           0 :         } else if (strcasecmp(operation, "ServerLevelPluginDll") == 0) {
     773           0 :                 is_wstring = 1;
     774           0 :         } else if (strcasecmp(operation, "DsBackgroundPauseName") == 0) {
     775           0 :                 is_string = 1;
     776           0 :         } else if (strcasecmp(operation, "DsNotRoundRobinTypes") == 0) {
     777           0 :                 is_string = 1;
     778             :         }
     779             : 
     780           0 :         if (is_string == 1) {
     781           0 :                 *typeid = DNSSRV_TYPEID_LPSTR;
     782           0 :                 r->String = answer_string;
     783           0 :                 return WERR_OK;
     784           0 :         } else if (is_wstring == 1) {
     785           0 :                 *typeid = DNSSRV_TYPEID_LPWSTR;
     786           0 :                 r->WideString = answer_string;
     787           0 :                 return WERR_OK;
     788             :         }
     789             : 
     790           0 :         is_stringlist = 0;
     791             : 
     792           0 :         if (strcasecmp(operation, "GlobalQueryBlockList") == 0) {
     793           0 :                 is_stringlist = 1;
     794           0 :         } else if (strcasecmp(operation, "SocketPoolExcludedPortRanges") == 0) {
     795           0 :                 is_stringlist = 1;
     796             :         }
     797             : 
     798           0 :         if (is_stringlist == 1) {
     799           0 :                 *typeid = DNSSRV_TYPEID_UTF8_STRING_LIST;
     800           0 :                 r->Utf8StringList = answer_stringlist;
     801           0 :                 return WERR_OK;
     802             :         }
     803             : 
     804           0 :         DEBUG(0,("dnsserver: Invalid server operation %s\n", operation));
     805           0 :         return WERR_DNS_ERROR_INVALID_PROPERTY;
     806             : }
     807             : 
     808             : /* [MS-DNSP].pdf Section 3.1.1.2 Zone Configuration Information */
     809          17 : static WERROR dnsserver_query_zone(struct dnsserver_state *dsstate,
     810             :                                         TALLOC_CTX *mem_ctx,
     811             :                                         struct dnsserver_zone *z,
     812             :                                         const char *operation,
     813             :                                         const unsigned int client_version,
     814             :                                         enum DNS_RPC_TYPEID *typeid,
     815             :                                         union DNSSRV_RPC_UNION *r)
     816             : {
     817           0 :         uint8_t is_integer, is_addresses, is_string;
     818          17 :         uint32_t answer_integer = 0;
     819          17 :         struct IP4_ARRAY *answer_iparray = NULL;
     820          17 :         struct DNS_ADDR_ARRAY *answer_addrarray = NULL;
     821          17 :         char *answer_string = NULL;
     822           0 :         struct dnsserver_zoneinfo *zoneinfo;
     823             : 
     824          17 :         zoneinfo = z->zoneinfo;
     825             : 
     826          17 :         if (strcasecmp(operation, "Zone") == 0) {
     827           0 :                 if (client_version == DNS_CLIENT_VERSION_W2K) {
     828           0 :                         *typeid = DNSSRV_TYPEID_ZONE_W2K;
     829           0 :                         r->ZoneW2K = talloc_zero(mem_ctx, struct DNS_RPC_ZONE_W2K);
     830             : 
     831           0 :                         r->ZoneW2K->pszZoneName = talloc_strdup(mem_ctx, z->name);
     832           0 :                         r->ZoneW2K->Flags = zoneinfo->Flags;
     833           0 :                         r->ZoneW2K->ZoneType = zoneinfo->dwZoneType;
     834           0 :                         r->ZoneW2K->Version = zoneinfo->Version;
     835             :                 } else {
     836           0 :                         *typeid = DNSSRV_TYPEID_ZONE;
     837           0 :                         r->Zone = talloc_zero(mem_ctx, struct DNS_RPC_ZONE_DOTNET);
     838             : 
     839           0 :                         r->Zone->dwRpcStructureVersion = 0x01;
     840           0 :                         r->Zone->pszZoneName = talloc_strdup(mem_ctx, z->name);
     841           0 :                         r->Zone->Flags = zoneinfo->Flags;
     842           0 :                         r->Zone->ZoneType = zoneinfo->dwZoneType;
     843           0 :                         r->Zone->Version = zoneinfo->Version;
     844           0 :                         r->Zone->dwDpFlags = z->partition->dwDpFlags;
     845           0 :                         r->Zone->pszDpFqdn = talloc_strdup(mem_ctx, z->partition->pszDpFqdn);
     846             :                 }
     847           0 :                 return WERR_OK;
     848             :         }
     849             : 
     850          17 :         if (strcasecmp(operation, "ZoneInfo") == 0) {
     851          17 :                 if (client_version == DNS_CLIENT_VERSION_W2K) {
     852           0 :                         *typeid = DNSSRV_TYPEID_ZONE_INFO_W2K;
     853           0 :                         r->ZoneInfoW2K = talloc_zero(mem_ctx, struct DNS_RPC_ZONE_INFO_W2K);
     854             : 
     855           0 :                         r->ZoneInfoW2K->pszZoneName = talloc_strdup(mem_ctx, z->name);
     856           0 :                         r->ZoneInfoW2K->dwZoneType = zoneinfo->dwZoneType;
     857           0 :                         r->ZoneInfoW2K->fReverse = zoneinfo->fReverse;
     858           0 :                         r->ZoneInfoW2K->fAllowUpdate = zoneinfo->fAllowUpdate;
     859           0 :                         r->ZoneInfoW2K->fPaused = zoneinfo->fPaused;
     860           0 :                         r->ZoneInfoW2K->fShutdown = zoneinfo->fShutdown;
     861           0 :                         r->ZoneInfoW2K->fAutoCreated = zoneinfo->fAutoCreated;
     862           0 :                         r->ZoneInfoW2K->fUseDatabase = zoneinfo->fUseDatabase;
     863           0 :                         r->ZoneInfoW2K->pszDataFile = talloc_strdup(mem_ctx, zoneinfo->pszDataFile);
     864           0 :                         r->ZoneInfoW2K->aipMasters = ip4_array_copy(mem_ctx, zoneinfo->aipMasters);
     865           0 :                         r->ZoneInfoW2K->fSecureSecondaries = zoneinfo->fSecureSecondaries;
     866           0 :                         r->ZoneInfoW2K->fNotifyLevel = zoneinfo->fNotifyLevel;
     867           0 :                         r->ZoneInfoW2K->aipSecondaries = ip4_array_copy(mem_ctx, zoneinfo->aipSecondaries);
     868           0 :                         r->ZoneInfoW2K->aipNotify = ip4_array_copy(mem_ctx, zoneinfo->aipNotify);
     869           0 :                         r->ZoneInfoW2K->fUseWins = zoneinfo->fUseWins;
     870           0 :                         r->ZoneInfoW2K->fUseNbstat = zoneinfo->fUseNbstat;
     871           0 :                         r->ZoneInfoW2K->fAging = zoneinfo->fAging;
     872           0 :                         r->ZoneInfoW2K->dwNoRefreshInterval = zoneinfo->dwNoRefreshInterval;
     873           0 :                         r->ZoneInfoW2K->dwRefreshInterval = zoneinfo->dwRefreshInterval;
     874           0 :                         r->ZoneInfoW2K->dwAvailForScavengeTime = zoneinfo->dwAvailForScavengeTime;
     875           0 :                         r->ZoneInfoW2K->aipScavengeServers = ip4_array_copy(mem_ctx, zoneinfo->aipScavengeServers);
     876             : 
     877          17 :                 } else if (client_version == DNS_CLIENT_VERSION_DOTNET) {
     878           0 :                         *typeid = DNSSRV_TYPEID_ZONE_INFO_DOTNET;
     879           0 :                         r->ZoneInfoDotNet = talloc_zero(mem_ctx, struct DNS_RPC_ZONE_INFO_DOTNET);
     880             : 
     881           0 :                         r->ZoneInfoDotNet->dwRpcStructureVersion = 0x01;
     882           0 :                         r->ZoneInfoDotNet->pszZoneName = talloc_strdup(mem_ctx, z->name);
     883           0 :                         r->ZoneInfoDotNet->dwZoneType = zoneinfo->dwZoneType;
     884           0 :                         r->ZoneInfoDotNet->fReverse = zoneinfo->fReverse;
     885           0 :                         r->ZoneInfoDotNet->fAllowUpdate = zoneinfo->fAllowUpdate;
     886           0 :                         r->ZoneInfoDotNet->fPaused = zoneinfo->fPaused;
     887           0 :                         r->ZoneInfoDotNet->fShutdown = zoneinfo->fShutdown;
     888           0 :                         r->ZoneInfoDotNet->fAutoCreated = zoneinfo->fAutoCreated;
     889           0 :                         r->ZoneInfoDotNet->fUseDatabase = zoneinfo->fUseDatabase;
     890           0 :                         r->ZoneInfoDotNet->pszDataFile = talloc_strdup(mem_ctx, zoneinfo->pszDataFile);
     891           0 :                         r->ZoneInfoDotNet->aipMasters = ip4_array_copy(mem_ctx, zoneinfo->aipMasters);
     892           0 :                         r->ZoneInfoDotNet->fSecureSecondaries = zoneinfo->fSecureSecondaries;
     893           0 :                         r->ZoneInfoDotNet->fNotifyLevel = zoneinfo->fNotifyLevel;
     894           0 :                         r->ZoneInfoDotNet->aipSecondaries = ip4_array_copy(mem_ctx, zoneinfo->aipSecondaries);
     895           0 :                         r->ZoneInfoDotNet->aipNotify = ip4_array_copy(mem_ctx, zoneinfo->aipNotify);
     896           0 :                         r->ZoneInfoDotNet->fUseWins = zoneinfo->fUseWins;
     897           0 :                         r->ZoneInfoDotNet->fUseNbstat = zoneinfo->fUseNbstat;
     898           0 :                         r->ZoneInfoDotNet->fAging = zoneinfo->fAging;
     899           0 :                         r->ZoneInfoDotNet->dwNoRefreshInterval = zoneinfo->dwNoRefreshInterval;
     900           0 :                         r->ZoneInfoDotNet->dwRefreshInterval = zoneinfo->dwRefreshInterval;
     901           0 :                         r->ZoneInfoDotNet->dwAvailForScavengeTime = zoneinfo->dwAvailForScavengeTime;
     902           0 :                         r->ZoneInfoDotNet->aipScavengeServers = ip4_array_copy(mem_ctx, zoneinfo->aipScavengeServers);
     903           0 :                         r->ZoneInfoDotNet->dwForwarderTimeout = zoneinfo->dwForwarderTimeout;
     904           0 :                         r->ZoneInfoDotNet->fForwarderSlave = zoneinfo->fForwarderSlave;
     905           0 :                         r->ZoneInfoDotNet->aipLocalMasters = ip4_array_copy(mem_ctx, zoneinfo->aipLocalMasters);
     906           0 :                         r->ZoneInfoDotNet->dwDpFlags = z->partition->dwDpFlags;
     907           0 :                         r->ZoneInfoDotNet->pszDpFqdn = talloc_strdup(mem_ctx, z->partition->pszDpFqdn);
     908           0 :                         r->ZoneInfoDotNet->pwszZoneDn = talloc_strdup(mem_ctx, zoneinfo->pwszZoneDn);
     909           0 :                         r->ZoneInfoDotNet->dwLastSuccessfulSoaCheck = zoneinfo->dwLastSuccessfulSoaCheck;
     910           0 :                         r->ZoneInfoDotNet->dwLastSuccessfulXfr = zoneinfo->dwLastSuccessfulXfr;
     911             : 
     912             :                 } else {
     913          17 :                         *typeid = DNSSRV_TYPEID_ZONE_INFO;
     914          17 :                         r->ZoneInfo = talloc_zero(mem_ctx, struct DNS_RPC_ZONE_INFO_LONGHORN);
     915             : 
     916          17 :                         r->ZoneInfo->dwRpcStructureVersion = 0x02;
     917          17 :                         r->ZoneInfo->pszZoneName = talloc_strdup(mem_ctx, z->name);
     918          17 :                         r->ZoneInfo->dwZoneType = zoneinfo->dwZoneType;
     919          17 :                         r->ZoneInfo->fReverse = zoneinfo->fReverse;
     920          17 :                         r->ZoneInfo->fAllowUpdate = zoneinfo->fAllowUpdate;
     921          17 :                         r->ZoneInfo->fPaused = zoneinfo->fPaused;
     922          17 :                         r->ZoneInfo->fShutdown = zoneinfo->fShutdown;
     923          17 :                         r->ZoneInfo->fAutoCreated = zoneinfo->fAutoCreated;
     924          17 :                         r->ZoneInfo->fUseDatabase = zoneinfo->fUseDatabase;
     925          17 :                         r->ZoneInfo->pszDataFile = talloc_strdup(mem_ctx, zoneinfo->pszDataFile);
     926          17 :                         r->ZoneInfo->aipMasters = ip4_array_to_dns_addr_array(mem_ctx, zoneinfo->aipMasters);
     927          17 :                         r->ZoneInfo->fSecureSecondaries = zoneinfo->fSecureSecondaries;
     928          17 :                         r->ZoneInfo->fNotifyLevel = zoneinfo->fNotifyLevel;
     929          17 :                         r->ZoneInfo->aipSecondaries = ip4_array_to_dns_addr_array(mem_ctx, zoneinfo->aipSecondaries);
     930          17 :                         r->ZoneInfo->aipNotify = ip4_array_to_dns_addr_array(mem_ctx, zoneinfo->aipNotify);
     931          17 :                         r->ZoneInfo->fUseWins = zoneinfo->fUseWins;
     932          17 :                         r->ZoneInfo->fUseNbstat = zoneinfo->fUseNbstat;
     933          17 :                         r->ZoneInfo->fAging = zoneinfo->fAging;
     934          17 :                         r->ZoneInfo->dwNoRefreshInterval = zoneinfo->dwNoRefreshInterval;
     935          17 :                         r->ZoneInfo->dwRefreshInterval = zoneinfo->dwRefreshInterval;
     936          17 :                         r->ZoneInfo->dwAvailForScavengeTime = zoneinfo->dwAvailForScavengeTime;
     937          17 :                         r->ZoneInfo->aipScavengeServers = ip4_array_to_dns_addr_array(mem_ctx, zoneinfo->aipScavengeServers);
     938          17 :                         r->ZoneInfo->dwForwarderTimeout = zoneinfo->dwForwarderTimeout;
     939          17 :                         r->ZoneInfo->fForwarderSlave = zoneinfo->fForwarderSlave;
     940          17 :                         r->ZoneInfo->aipLocalMasters = ip4_array_to_dns_addr_array(mem_ctx, zoneinfo->aipLocalMasters);
     941          17 :                         r->ZoneInfo->dwDpFlags = z->partition->dwDpFlags;
     942          17 :                         r->ZoneInfo->pszDpFqdn = talloc_strdup(mem_ctx, z->partition->pszDpFqdn);
     943          17 :                         r->ZoneInfo->pwszZoneDn = talloc_strdup(mem_ctx, zoneinfo->pwszZoneDn);
     944          17 :                         r->ZoneInfo->dwLastSuccessfulSoaCheck = zoneinfo->dwLastSuccessfulSoaCheck;
     945          17 :                         r->ZoneInfo->dwLastSuccessfulXfr = zoneinfo->dwLastSuccessfulXfr;
     946             : 
     947          17 :                         r->ZoneInfo->fQueuedForBackgroundLoad = zoneinfo->fQueuedForBackgroundLoad;
     948          17 :                         r->ZoneInfo->fBackgroundLoadInProgress = zoneinfo->fBackgroundLoadInProgress;
     949          17 :                         r->ZoneInfo->fReadOnlyZone = zoneinfo->fReadOnlyZone;
     950          17 :                         r->ZoneInfo->dwLastXfrAttempt = zoneinfo->dwLastXfrAttempt;
     951          17 :                         r->ZoneInfo->dwLastXfrResult = zoneinfo->dwLastXfrResult;
     952             :                 }
     953             : 
     954          17 :                 return WERR_OK;
     955             :         }
     956             : 
     957           0 :         is_integer = 0;
     958             : 
     959           0 :         if (strcasecmp(operation, "AllowUpdate") == 0) {
     960           0 :                 answer_integer = zoneinfo->fAllowUpdate;
     961           0 :                 is_integer = 1;
     962           0 :         } else if (strcasecmp(operation, "Secured") == 0) {
     963           0 :                 answer_integer = 0;
     964           0 :                 is_integer = 1;
     965           0 :         } else if (strcasecmp(operation, "DsIntegrated") == 0) {
     966           0 :                 answer_integer = zoneinfo->fUseDatabase;
     967           0 :                 is_integer = 1;
     968           0 :         } else if (strcasecmp(operation, "LogUpdates") == 0) {
     969           0 :                 answer_integer = 0;
     970           0 :                 is_integer = 1;
     971           0 :         } else if (strcasecmp(operation, "NoRefreshInterval") == 0) {
     972           0 :                 answer_integer = zoneinfo->dwNoRefreshInterval;
     973           0 :                 is_integer = 1;
     974           0 :         } else if (strcasecmp(operation, "NotifyLevel") == 0) {
     975           0 :                 answer_integer = zoneinfo->fNotifyLevel;
     976           0 :                 is_integer = 1;
     977           0 :         } else if (strcasecmp(operation, "RefreshInterval") == 0) {
     978           0 :                 answer_integer = zoneinfo->dwRefreshInterval;
     979           0 :                 is_integer = 1;
     980           0 :         } else if (strcasecmp(operation, "SecureSecondaries") == 0) {
     981           0 :                 answer_integer = zoneinfo->fSecureSecondaries;
     982           0 :                 is_integer = 1;
     983           0 :         } else if (strcasecmp(operation, "Type") == 0) {
     984           0 :                 answer_integer = zoneinfo->dwZoneType;
     985           0 :                 is_integer = 1;
     986           0 :         } else if (strcasecmp(operation, "Aging") == 0) {
     987           0 :                 answer_integer = zoneinfo->fAging;
     988           0 :                 is_integer = 1;
     989           0 :         } else if (strcasecmp(operation, "ForwarderSlave") == 0) {
     990           0 :                 answer_integer = zoneinfo->fForwarderSlave;
     991           0 :                 is_integer = 1;
     992           0 :         } else if (strcasecmp(operation, "ForwarderTimeout") == 0) {
     993           0 :                 answer_integer = zoneinfo->dwForwarderTimeout;
     994           0 :                 is_integer = 1;
     995           0 :         } else if (strcasecmp(operation, "Unicode") == 0) {
     996           0 :                 answer_integer = 0;
     997           0 :                 is_integer = 1;
     998             :         }
     999             : 
    1000           0 :         if (is_integer == 1) {
    1001           0 :                 *typeid = DNSSRV_TYPEID_DWORD;
    1002           0 :                 r->Dword = answer_integer;
    1003           0 :                 return WERR_OK;
    1004             :         }
    1005             : 
    1006           0 :         is_addresses = 0;
    1007             : 
    1008           0 :         if (strcasecmp(operation, "AllowNSRecordsAutoCreation") == 0) {
    1009           0 :                 is_addresses = 1;
    1010           0 :         } else if (strcasecmp(operation, "ScavengeServers") == 0) {
    1011           0 :                 if (client_version == DNS_CLIENT_VERSION_LONGHORN) {
    1012           0 :                         answer_addrarray = ip4_array_to_dns_addr_array(mem_ctx, zoneinfo->aipScavengeServers);
    1013             :                 } else {
    1014           0 :                         answer_iparray = ip4_array_copy(mem_ctx, zoneinfo->aipScavengeServers);
    1015             :                 }
    1016           0 :                 is_addresses = 1;
    1017           0 :         } else if (strcasecmp(operation, "MasterServers") == 0) {
    1018           0 :                 if (client_version == DNS_CLIENT_VERSION_LONGHORN) {
    1019           0 :                         answer_addrarray = ip4_array_to_dns_addr_array(mem_ctx, zoneinfo->aipMasters);
    1020             :                 } else {
    1021           0 :                         answer_iparray = ip4_array_copy(mem_ctx, zoneinfo->aipMasters);
    1022             :                 }
    1023           0 :                 is_addresses = 1;
    1024           0 :         } else if (strcasecmp(operation, "LocalMasterServers") == 0) {
    1025           0 :                 if (client_version == DNS_CLIENT_VERSION_LONGHORN) {
    1026           0 :                         answer_addrarray = ip4_array_to_dns_addr_array(mem_ctx, zoneinfo->aipLocalMasters);
    1027             :                 } else {
    1028           0 :                         answer_iparray = ip4_array_copy(mem_ctx, zoneinfo->aipLocalMasters);
    1029             :                 }
    1030           0 :                 is_addresses = 1;
    1031           0 :         } else if (strcasecmp(operation, "NotifyServers") == 0) {
    1032           0 :                 if (client_version == DNS_CLIENT_VERSION_LONGHORN) {
    1033           0 :                         answer_addrarray = ip4_array_to_dns_addr_array(mem_ctx, zoneinfo->aipNotify);
    1034             :                 } else {
    1035           0 :                         answer_iparray = ip4_array_copy(mem_ctx, zoneinfo->aipNotify);
    1036             :                 }
    1037           0 :                 is_addresses = 1;
    1038           0 :         } else if (strcasecmp(operation, "SecondaryServers") == 0) {
    1039           0 :                 if (client_version == DNS_CLIENT_VERSION_LONGHORN) {
    1040           0 :                         answer_addrarray = ip4_array_to_dns_addr_array(mem_ctx, zoneinfo->aipSecondaries);
    1041             :                 } else {
    1042           0 :                         answer_iparray = ip4_array_copy(mem_ctx, zoneinfo->aipSecondaries);
    1043             :                 }
    1044           0 :                 is_addresses = 1;
    1045             :         }
    1046             : 
    1047           0 :         if (is_addresses == 1) {
    1048           0 :                 if (client_version == DNS_CLIENT_VERSION_LONGHORN) {
    1049           0 :                         *typeid = DNSSRV_TYPEID_ADDRARRAY;
    1050           0 :                         r->AddrArray = answer_addrarray;
    1051             :                 } else {
    1052           0 :                         *typeid = DNSSRV_TYPEID_IPARRAY;
    1053           0 :                         r->IpArray = answer_iparray;
    1054             :                 }
    1055           0 :                 return WERR_OK;
    1056             :         }
    1057             : 
    1058           0 :         is_string = 0;
    1059             : 
    1060           0 :         if (strcasecmp(operation, "DatabaseFile") == 0) {
    1061           0 :                 answer_string = talloc_strdup(mem_ctx, zoneinfo->pszDataFile);
    1062           0 :                 is_string = 1;
    1063           0 :         } else if (strcasecmp(operation, "ApplicationDirectoryPartition") == 0) {
    1064           0 :                 answer_string = talloc_strdup(mem_ctx, z->partition->pszDpFqdn);
    1065           0 :                 is_string = 1;
    1066           0 :         } else if (strcasecmp(operation, "BreakOnNameUpdate") == 0) {
    1067           0 :                 is_string = 1;
    1068             :         }
    1069             : 
    1070           0 :         if (is_string == 1) {
    1071           0 :                 *typeid = DNSSRV_TYPEID_LPSTR;
    1072           0 :                 r->String = answer_string;
    1073           0 :                 return WERR_OK;
    1074             :         }
    1075             : 
    1076           0 :         DEBUG(0,("dnsserver: Invalid zone operation %s\n", operation));
    1077           0 :         return WERR_DNS_ERROR_INVALID_PROPERTY;
    1078             : 
    1079             : }
    1080             : 
    1081             : /* dnsserver operation functions */
    1082             : 
    1083             : /* [MS-DNSP].pdf Section 3.1.1.1 DNS Server Configuration Information */
    1084         429 : static WERROR dnsserver_operate_server(struct dnsserver_state *dsstate,
    1085             :                                         TALLOC_CTX *mem_ctx,
    1086             :                                         const char *operation,
    1087             :                                         const unsigned int client_version,
    1088             :                                         enum DNS_RPC_TYPEID typeid,
    1089             :                                         union DNSSRV_RPC_UNION *r)
    1090             : {
    1091         429 :         bool valid_operation = false;
    1092             : 
    1093         429 :         if (strcasecmp(operation, "ResetDwordProperty") == 0) {
    1094           0 :                 valid_operation = true;
    1095         429 :         } else if (strcasecmp(operation, "Restart") == 0) {
    1096           0 :                 valid_operation = true;
    1097         429 :         } else if (strcasecmp(operation, "ClearDebugLog") == 0) {
    1098           0 :                 valid_operation = true;
    1099         429 :         } else if (strcasecmp(operation, "ClearCache") == 0) {
    1100           0 :                 valid_operation = true;
    1101         429 :         } else if (strcasecmp(operation, "WriteDirtyZones") == 0) {
    1102           0 :                 valid_operation = true;
    1103         429 :         } else if (strcasecmp(operation, "ZoneCreate") == 0) {
    1104           0 :                 struct dnsserver_zone *z, *z2;
    1105           0 :                 WERROR status;
    1106           0 :                 size_t len;
    1107           0 :                 const char *name;
    1108         427 :                 z = talloc_zero(mem_ctx, struct dnsserver_zone);
    1109         427 :                 W_ERROR_HAVE_NO_MEMORY(z);
    1110         427 :                 z->partition = talloc_zero(z, struct dnsserver_partition);
    1111         427 :                 W_ERROR_HAVE_NO_MEMORY_AND_FREE(z->partition, z);
    1112         427 :                 z->zoneinfo = talloc_zero(z, struct dnsserver_zoneinfo);
    1113         427 :                 W_ERROR_HAVE_NO_MEMORY_AND_FREE(z->zoneinfo, z);
    1114             : 
    1115         427 :                 if (typeid == DNSSRV_TYPEID_ZONE_CREATE_W2K) {
    1116           0 :                         name = r->ZoneCreateW2K->pszZoneName;
    1117           0 :                         z->zoneinfo->dwZoneType = r->ZoneCreateW2K->dwZoneType;
    1118           0 :                         z->zoneinfo->fAllowUpdate = r->ZoneCreateW2K->fAllowUpdate;
    1119           0 :                         z->zoneinfo->fAging = r->ZoneCreateW2K->fAging;
    1120           0 :                         z->zoneinfo->Flags = r->ZoneCreateW2K->dwFlags;
    1121         427 :                 } else if (typeid == DNSSRV_TYPEID_ZONE_CREATE_DOTNET) {
    1122           0 :                         name = r->ZoneCreateDotNet->pszZoneName;
    1123           0 :                         z->zoneinfo->dwZoneType = r->ZoneCreateDotNet->dwZoneType;
    1124           0 :                         z->zoneinfo->fAllowUpdate = r->ZoneCreateDotNet->fAllowUpdate;
    1125           0 :                         z->zoneinfo->fAging = r->ZoneCreateDotNet->fAging;
    1126           0 :                         z->zoneinfo->Flags = r->ZoneCreateDotNet->dwFlags;
    1127           0 :                         z->partition->dwDpFlags = r->ZoneCreateDotNet->dwDpFlags;
    1128         427 :                 } else if (typeid == DNSSRV_TYPEID_ZONE_CREATE) {
    1129         427 :                         name = r->ZoneCreate->pszZoneName;
    1130         427 :                         z->zoneinfo->dwZoneType = r->ZoneCreate->dwZoneType;
    1131         427 :                         z->zoneinfo->fAllowUpdate = r->ZoneCreate->fAllowUpdate;
    1132         427 :                         z->zoneinfo->fAging = r->ZoneCreate->fAging;
    1133         427 :                         z->zoneinfo->Flags = r->ZoneCreate->dwFlags;
    1134         427 :                         z->partition->dwDpFlags = r->ZoneCreate->dwDpFlags;
    1135             :                 } else {
    1136           0 :                         talloc_free(z);
    1137           0 :                         return WERR_DNS_ERROR_INVALID_PROPERTY;
    1138             :                 }
    1139             : 
    1140         427 :                 len = strlen(name);
    1141         427 :                 if (name[len-1] == '.') {
    1142           6 :                         len -= 1;
    1143             :                 }
    1144         427 :                 z->name = talloc_strndup(z, name, len);
    1145         427 :                 if (z->name == NULL) {
    1146           0 :                         talloc_free(z);
    1147           0 :                         return WERR_NOT_ENOUGH_MEMORY;
    1148             :                 }
    1149             : 
    1150         427 :                 z2 = dnsserver_find_zone(dsstate->zones, z->name);
    1151         427 :                 if (z2 != NULL) {
    1152           6 :                         talloc_free(z);
    1153           6 :                         return WERR_DNS_ERROR_ZONE_ALREADY_EXISTS;
    1154             :                 }
    1155             : 
    1156         421 :                 status = dnsserver_db_create_zone(dsstate->samdb, dsstate->partitions, z,
    1157             :                                                   dsstate->lp_ctx);
    1158         421 :                 talloc_free(z);
    1159             : 
    1160         421 :                 if (W_ERROR_IS_OK(status)) {
    1161         403 :                         dnsserver_reload_zones(dsstate);
    1162             :                 }
    1163         421 :                 return status;
    1164           2 :         } else if (strcasecmp(operation, "ClearStatistics") == 0) {
    1165           0 :                 valid_operation = true;
    1166           2 :         } else if (strcasecmp(operation, "EnlistDirectoryPartition") == 0) {
    1167           0 :                 valid_operation = true;
    1168           2 :         } else if (strcasecmp(operation, "StartScavenging") == 0) {
    1169           2 :                 valid_operation = true;
    1170           0 :         } else if (strcasecmp(operation, "AbortScavenging") == 0) {
    1171           0 :                 valid_operation = true;
    1172           0 :         } else if (strcasecmp(operation, "AutoConfigure") == 0) {
    1173           0 :                 valid_operation = true;
    1174           0 :         } else if (strcasecmp(operation, "ExportSettings") == 0) {
    1175           0 :                 valid_operation = true;
    1176           0 :         } else if (strcasecmp(operation, "PrepareForDemotion") == 0) {
    1177           0 :                 valid_operation = true;
    1178           0 :         } else if (strcasecmp(operation, "PrepareForUninstall") == 0) {
    1179           0 :                 valid_operation = true;
    1180           0 :         } else if (strcasecmp(operation, "DeleteNode") == 0) {
    1181           0 :                 valid_operation = true;
    1182           0 :         } else if (strcasecmp(operation, "DeleteRecord") == 0) {
    1183           0 :                 valid_operation = true;
    1184           0 :         } else if (strcasecmp(operation, "WriteBackFile") == 0) {
    1185           0 :                 valid_operation = true;
    1186           0 :         } else if (strcasecmp(operation, "ListenAddresses") == 0) {
    1187           0 :                 valid_operation = true;
    1188           0 :         } else if (strcasecmp(operation, "Forwarders") == 0) {
    1189           0 :                 valid_operation = true;
    1190           0 :         } else if (strcasecmp(operation, "LogFilePath") == 0) {
    1191           0 :                 valid_operation = true;
    1192           0 :         } else if (strcasecmp(operation, "LogIpFilterList") == 0) {
    1193           0 :                 valid_operation = true;
    1194           0 :         } else if (strcasecmp(operation, "ForestDirectoryPartitionBaseName") == 0) {
    1195           0 :                 valid_operation = true;
    1196           0 :         } else if (strcasecmp(operation, "DomainDirectoryPartitionBaseName") == 0) {
    1197           0 :                 valid_operation = true;
    1198           0 :         } else if (strcasecmp(operation, "GlobalQueryBlockList") == 0) {
    1199           0 :                 valid_operation = true;
    1200           0 :         } else if (strcasecmp(operation, "BreakOnReceiveFrom") == 0) {
    1201           0 :                 valid_operation = true;
    1202           0 :         } else if (strcasecmp(operation, "BreakOnUpdateFrom") == 0) {
    1203           0 :                 valid_operation = true;
    1204           0 :         } else if (strcasecmp(operation, "ServerLevelPluginDll") == 0) {
    1205           0 :                 valid_operation = true;
    1206             :         }
    1207             : 
    1208           2 :         if (valid_operation) {
    1209           2 :                 DEBUG(0, ("dnsserver: server operation '%s' not implemented\n", operation));
    1210           2 :                 return WERR_CALL_NOT_IMPLEMENTED;
    1211             :         }
    1212             : 
    1213           0 :         DEBUG(0, ("dnsserver: invalid server operation '%s'\n", operation));
    1214           0 :         return WERR_DNS_ERROR_INVALID_PROPERTY;
    1215             : }
    1216             : 
    1217          20 : static WERROR dnsserver_complex_operate_server(struct dnsserver_state *dsstate,
    1218             :                                         TALLOC_CTX *mem_ctx,
    1219             :                                         const char *operation,
    1220             :                                         const unsigned int client_version,
    1221             :                                         enum DNS_RPC_TYPEID typeid_in,
    1222             :                                         union DNSSRV_RPC_UNION *rin,
    1223             :                                         enum DNS_RPC_TYPEID *typeid_out,
    1224             :                                         union DNSSRV_RPC_UNION *rout)
    1225             : {
    1226          20 :         int valid_operation = 0;
    1227           0 :         struct dnsserver_zone *z, **zlist;
    1228           0 :         size_t zcount;
    1229           0 :         bool found1, found2, found3, found4;
    1230           0 :         size_t i;
    1231             : 
    1232          20 :         if (strcasecmp(operation, "QueryDwordProperty") == 0) {
    1233           0 :                 if (typeid_in == DNSSRV_TYPEID_LPSTR) {
    1234           0 :                         return dnsserver_query_server(dsstate, mem_ctx,
    1235             :                                                         rin->String,
    1236             :                                                         client_version,
    1237             :                                                         typeid_out,
    1238             :                                                         rout);
    1239             :                 }
    1240          20 :         } else if (strcasecmp(operation, "EnumZones") == 0) {
    1241          20 :                 if (typeid_in != DNSSRV_TYPEID_DWORD) {
    1242           0 :                         return WERR_DNS_ERROR_INVALID_PROPERTY;
    1243             :                 }
    1244             : 
    1245          20 :                 zcount = 0;
    1246          20 :                 zlist = talloc_zero_array(mem_ctx, struct dnsserver_zone *, 0);
    1247         106 :                 for (z = dsstate->zones; z; z = z->next) {
    1248             : 
    1249             :                         /* Match the flags in groups
    1250             :                          *
    1251             :                          * Group1 : PRIMARY, SECONDARY, CACHE, AUTO
    1252             :                          * Group2 : FORWARD, REVERSE, FORWARDER, STUB
    1253             :                          * Group3 : DS, NON_DS, DOMAIN_DP, FOREST_DP
    1254             :                          * Group4 : CUSTOM_DP, LEGACY_DP
    1255             :                          */
    1256             :                         
    1257             :                         /* Group 1 */
    1258          86 :                         found1 = false;
    1259          86 :                         if (rin->Dword & 0x0000000f) {
    1260          86 :                                 if (rin->Dword & DNS_ZONE_REQUEST_PRIMARY) {
    1261          86 :                                         if (z->zoneinfo->dwZoneType == DNS_ZONE_TYPE_PRIMARY) {
    1262          66 :                                         found1 = true;
    1263             :                                         }
    1264             :                                 }
    1265          86 :                                 if (rin->Dword & DNS_ZONE_REQUEST_SECONDARY) {
    1266           0 :                                         if (z->zoneinfo->dwZoneType == DNS_ZONE_TYPE_SECONDARY) {
    1267           0 :                                                 found1 = true;
    1268             :                                         }
    1269             :                                 }
    1270          86 :                                 if (rin->Dword & DNS_ZONE_REQUEST_CACHE) {
    1271           0 :                                         if (z->zoneinfo->dwZoneType == DNS_ZONE_TYPE_CACHE) {
    1272           0 :                                                 found1 = true;
    1273             :                                         }
    1274             :                                 }
    1275          86 :                                 if (rin->Dword & DNS_ZONE_REQUEST_AUTO) {
    1276           0 :                                         if (z->zoneinfo->fAutoCreated 
    1277           0 :                                                 || z->partition->dwDpFlags & DNS_DP_AUTOCREATED) {
    1278           0 :                                                 found1 = true;
    1279             :                                         }
    1280             :                                 }
    1281             :                         } else {
    1282           0 :                                 found1 = true;
    1283             :                         }
    1284             : 
    1285             :                         /* Group 2 */
    1286          86 :                         found2 = false;
    1287          86 :                         if (rin->Dword & 0x000000f0) {
    1288          51 :                                 if (rin->Dword & DNS_ZONE_REQUEST_FORWARD) {
    1289          12 :                                         if (!(z->zoneinfo->fReverse)) {
    1290          12 :                                                 found2 = true;
    1291             :                                         }
    1292             :                                 }
    1293          51 :                                 if (rin->Dword & DNS_ZONE_REQUEST_REVERSE) {
    1294          39 :                                         if (z->zoneinfo->fReverse) {
    1295           3 :                                                 found2 = true;
    1296             :                                         }
    1297             :                                 }
    1298          51 :                                 if (rin->Dword & DNS_ZONE_REQUEST_FORWARDER) {
    1299           0 :                                         if (z->zoneinfo->dwZoneType == DNS_ZONE_TYPE_FORWARDER) {
    1300           0 :                                                 found2 = true;
    1301             :                                         }
    1302             :                                 }
    1303          51 :                                 if (rin->Dword & DNS_ZONE_REQUEST_STUB) {
    1304           0 :                                         if (z->zoneinfo->dwZoneType == DNS_ZONE_TYPE_STUB) {
    1305           0 :                                                 found2 = true;
    1306             :                                         }
    1307             :                                 }
    1308             :                         } else {
    1309          35 :                                 found2 = true;
    1310             :                         }
    1311             : 
    1312             :                         /* Group 3 */
    1313          86 :                         found3 = false;
    1314          86 :                         if (rin->Dword & 0x00000f00) {
    1315           0 :                                 if (rin->Dword & DNS_ZONE_REQUEST_DS) {
    1316           0 :                                         if (z->zoneinfo->Flags & DNS_RPC_ZONE_DSINTEGRATED) {
    1317           0 :                                                 found3 = true;
    1318             :                                         }
    1319             :                                 }
    1320           0 :                                 if (rin->Dword & DNS_ZONE_REQUEST_NON_DS) {
    1321           0 :                                         if (!(z->zoneinfo->Flags & DNS_RPC_ZONE_DSINTEGRATED)) {
    1322           0 :                                                 found3 = true;
    1323             :                                         }
    1324             :                                 }
    1325           0 :                                 if (rin->Dword & DNS_ZONE_REQUEST_DOMAIN_DP) {
    1326           0 :                                         if (!(z->partition->dwDpFlags & DNS_DP_DOMAIN_DEFAULT)) {
    1327           0 :                                                 found3 = true;
    1328             :                                         }
    1329             :                                 }
    1330           0 :                                 if (rin->Dword & DNS_ZONE_REQUEST_FOREST_DP) {
    1331           0 :                                         if (!(z->partition->dwDpFlags & DNS_DP_FOREST_DEFAULT)) {
    1332           0 :                                                 found3 = true;
    1333             :                                         }
    1334             :                                 }
    1335             :                         } else {
    1336          86 :                                 found3 = true;
    1337             :                         }
    1338             :         
    1339             :                         /* Group 4 */
    1340          86 :                         if (rin->Dword & 0x0000f000) {
    1341           0 :                                 found4 = false;
    1342             :                         } else {
    1343          86 :                                 found4 = true;
    1344             :                         }
    1345             : 
    1346          86 :                         if (found1 && found2 && found3 && found4) {
    1347          39 :                                 zlist = talloc_realloc(mem_ctx, zlist, struct dnsserver_zone *, zcount+1);
    1348          39 :                                 zlist[zcount] = z;
    1349          39 :                                 zcount++;
    1350             :                         }
    1351             :                 }
    1352             : 
    1353          20 :                 if (client_version == DNS_CLIENT_VERSION_W2K) {
    1354           0 :                         *typeid_out = DNSSRV_TYPEID_ZONE_LIST_W2K;
    1355           0 :                         rout->ZoneListW2K = talloc_zero(mem_ctx, struct DNS_RPC_ZONE_LIST_W2K);
    1356             : 
    1357           0 :                         if (zcount == 0) {
    1358           0 :                                 rout->ZoneListW2K->dwZoneCount = 0;
    1359           0 :                                 rout->ZoneListW2K->ZoneArray = NULL;
    1360             : 
    1361           0 :                                 return WERR_OK;
    1362             :                         }
    1363             : 
    1364           0 :                         rout->ZoneListW2K->ZoneArray = talloc_zero_array(mem_ctx, struct DNS_RPC_ZONE_W2K *, zcount);
    1365           0 :                         W_ERROR_HAVE_NO_MEMORY_AND_FREE(rout->ZoneListW2K->ZoneArray, zlist);
    1366             : 
    1367           0 :                         for (i=0; i<zcount; i++) {
    1368           0 :                                 rout->ZoneListW2K->ZoneArray[i] = talloc_zero(mem_ctx, struct DNS_RPC_ZONE_W2K);
    1369             : 
    1370           0 :                                 rout->ZoneListW2K->ZoneArray[i]->pszZoneName = talloc_strdup(mem_ctx, zlist[i]->name);
    1371           0 :                                 rout->ZoneListW2K->ZoneArray[i]->Flags = zlist[i]->zoneinfo->Flags;
    1372           0 :                                 rout->ZoneListW2K->ZoneArray[i]->ZoneType = zlist[i]->zoneinfo->dwZoneType;
    1373           0 :                                 rout->ZoneListW2K->ZoneArray[i]->Version = zlist[i]->zoneinfo->Version;
    1374             :                         }
    1375           0 :                         rout->ZoneListW2K->dwZoneCount = zcount;
    1376             : 
    1377             :                 } else {
    1378          20 :                         *typeid_out = DNSSRV_TYPEID_ZONE_LIST;
    1379          20 :                         rout->ZoneList = talloc_zero(mem_ctx, struct DNS_RPC_ZONE_LIST_DOTNET);
    1380             : 
    1381          20 :                         if (zcount == 0) {
    1382           6 :                                 rout->ZoneList->dwRpcStructureVersion = 1;
    1383           6 :                                 rout->ZoneList->dwZoneCount = 0;
    1384           6 :                                 rout->ZoneList->ZoneArray = NULL;
    1385             : 
    1386           6 :                                 return WERR_OK;
    1387             :                         }
    1388             : 
    1389          14 :                         rout->ZoneList->ZoneArray = talloc_zero_array(mem_ctx, struct DNS_RPC_ZONE_DOTNET *, zcount);
    1390          14 :                         W_ERROR_HAVE_NO_MEMORY_AND_FREE(rout->ZoneList->ZoneArray, zlist);
    1391             : 
    1392          53 :                         for (i=0; i<zcount; i++) {
    1393          39 :                                 rout->ZoneList->ZoneArray[i] = talloc_zero(mem_ctx, struct DNS_RPC_ZONE_DOTNET);
    1394             : 
    1395          39 :                                 rout->ZoneList->ZoneArray[i]->dwRpcStructureVersion = 1;
    1396          39 :                                 rout->ZoneList->ZoneArray[i]->pszZoneName = talloc_strdup(mem_ctx, zlist[i]->name);
    1397          39 :                                 rout->ZoneList->ZoneArray[i]->Flags = zlist[i]->zoneinfo->Flags;
    1398          39 :                                 rout->ZoneList->ZoneArray[i]->ZoneType = zlist[i]->zoneinfo->dwZoneType;
    1399          39 :                                 rout->ZoneList->ZoneArray[i]->Version = zlist[i]->zoneinfo->Version;
    1400          39 :                                 rout->ZoneList->ZoneArray[i]->dwDpFlags = zlist[i]->partition->dwDpFlags;
    1401          39 :                                 rout->ZoneList->ZoneArray[i]->pszDpFqdn = talloc_strdup(mem_ctx, zlist[i]->partition->pszDpFqdn);
    1402             :                         }
    1403          14 :                         rout->ZoneList->dwRpcStructureVersion = 1;
    1404          14 :                         rout->ZoneList->dwZoneCount = zcount;
    1405             :                 }
    1406          14 :                 talloc_free(zlist);
    1407          14 :                 return WERR_OK;
    1408           0 :         } else if (strcasecmp(operation, "EnumZones2") == 0) {
    1409           0 :                 valid_operation = true;
    1410           0 :         } else if (strcasecmp(operation, "EnumDirectoryPartitions") == 0) {
    1411           0 :                 if (typeid_in != DNSSRV_TYPEID_DWORD) {
    1412           0 :                         return WERR_DNS_ERROR_INVALID_PROPERTY;
    1413             :                 }
    1414             : 
    1415           0 :                 *typeid_out = DNSSRV_TYPEID_DP_LIST;
    1416           0 :                 rout->DirectoryPartitionList = talloc_zero(mem_ctx, struct DNS_RPC_DP_LIST);
    1417             : 
    1418           0 :                 if (rin->Dword != 0) {
    1419           0 :                         rout->DirectoryPartitionList->dwDpCount = 0;
    1420           0 :                         rout->DirectoryPartitionList->DpArray = NULL;
    1421             :                 } else {
    1422           0 :                         struct DNS_RPC_DP_ENUM **dplist;
    1423           0 :                         struct dnsserver_partition *p;
    1424           0 :                         int pcount = 2;
    1425             : 
    1426           0 :                         dplist = talloc_zero_array(mem_ctx, struct DNS_RPC_DP_ENUM *, pcount);
    1427           0 :                         W_ERROR_HAVE_NO_MEMORY(dplist);
    1428             : 
    1429           0 :                         p = dsstate->partitions;
    1430           0 :                         for (i=0; i<pcount; i++) {
    1431           0 :                                 dplist[i] = talloc_zero(dplist, struct DNS_RPC_DP_ENUM);
    1432             : 
    1433           0 :                                 dplist[i]->pszDpFqdn = talloc_strdup(mem_ctx, p->pszDpFqdn);
    1434           0 :                                 dplist[i]->dwFlags = p->dwDpFlags;
    1435           0 :                                 dplist[i]->dwZoneCount = p->zones_count;
    1436           0 :                                 p = p->next;
    1437             :                         }
    1438             : 
    1439           0 :                         rout->DirectoryPartitionList->dwDpCount = pcount;
    1440           0 :                         rout->DirectoryPartitionList->DpArray = dplist;
    1441             :                 }
    1442           0 :                 return WERR_OK;
    1443           0 :         } else if (strcasecmp(operation, "DirectoryPartitionInfo") == 0) {
    1444           0 :                 struct dnsserver_partition *p;
    1445           0 :                 struct dnsserver_partition_info *partinfo;
    1446           0 :                 struct DNS_RPC_DP_INFO *dpinfo = NULL;
    1447             : 
    1448           0 :                 if (typeid_in != DNSSRV_TYPEID_LPSTR) {
    1449           0 :                         return WERR_DNS_ERROR_INVALID_PROPERTY;
    1450             :                 }
    1451             : 
    1452           0 :                 *typeid_out = DNSSRV_TYPEID_DP_INFO;
    1453             : 
    1454           0 :                 for (p = dsstate->partitions; p; p = p->next) {
    1455           0 :                         if (strcasecmp(p->pszDpFqdn, rin->String) == 0) {
    1456           0 :                                 dpinfo = talloc_zero(mem_ctx, struct DNS_RPC_DP_INFO);
    1457           0 :                                 W_ERROR_HAVE_NO_MEMORY(dpinfo);
    1458             : 
    1459           0 :                                 partinfo = dnsserver_db_partition_info(mem_ctx, dsstate->samdb, p);
    1460           0 :                                 W_ERROR_HAVE_NO_MEMORY(partinfo);
    1461             : 
    1462           0 :                                 dpinfo->pszDpFqdn = talloc_strdup(dpinfo, p->pszDpFqdn);
    1463           0 :                                 dpinfo->pszDpDn = talloc_strdup(dpinfo, ldb_dn_get_linearized(p->partition_dn));
    1464           0 :                                 dpinfo->pszCrDn = talloc_steal(dpinfo, partinfo->pszCrDn);
    1465           0 :                                 dpinfo->dwFlags = p->dwDpFlags;
    1466           0 :                                 dpinfo->dwZoneCount = p->zones_count;
    1467           0 :                                 dpinfo->dwState = partinfo->dwState;
    1468           0 :                                 dpinfo->dwReplicaCount = partinfo->dwReplicaCount;
    1469           0 :                                 if (partinfo->dwReplicaCount > 0) {
    1470           0 :                                         dpinfo->ReplicaArray = talloc_steal(dpinfo,
    1471             :                                                                             partinfo->ReplicaArray);
    1472             :                                 } else {
    1473           0 :                                         dpinfo->ReplicaArray = NULL;
    1474             :                                 }
    1475           0 :                                 break;
    1476             :                         }
    1477             :                 }
    1478             : 
    1479           0 :                 if (dpinfo == NULL) {
    1480           0 :                         return WERR_DNS_ERROR_DP_DOES_NOT_EXIST;
    1481             :                 }
    1482             : 
    1483           0 :                 rout->DirectoryPartition = dpinfo;
    1484           0 :                 return WERR_OK;
    1485           0 :         } else if (strcasecmp(operation, "Statistics") == 0) {
    1486           0 :                 valid_operation = true;
    1487           0 :         } else if (strcasecmp(operation, "IpValidate") == 0) {
    1488           0 :                 valid_operation = true;
    1489             :         }
    1490             : 
    1491           0 :         if (valid_operation) {
    1492           0 :                 DEBUG(0, ("dnsserver: server complex operation '%s' not implemented\n", operation));
    1493           0 :                 return WERR_CALL_NOT_IMPLEMENTED;
    1494             :         }
    1495             : 
    1496           0 :         DEBUG(0, ("dnsserver: invalid server complex operation '%s'\n", operation));
    1497           0 :         return WERR_DNS_ERROR_INVALID_PROPERTY;
    1498             : }
    1499             : 
    1500             : /* [MS-DNSP].pdf Section 3.1.1.2 Zone Configuration Information */
    1501        1196 : static WERROR dnsserver_operate_zone(struct dnsserver_state *dsstate,
    1502             :                                         TALLOC_CTX *mem_ctx,
    1503             :                                         struct dnsserver_zone *z,
    1504             :                                         unsigned int request_filter,
    1505             :                                         const char *operation,
    1506             :                                         const unsigned int client_version,
    1507             :                                         enum DNS_RPC_TYPEID typeid,
    1508             :                                         union DNSSRV_RPC_UNION *r)
    1509             : {
    1510        1196 :         bool valid_operation = false;
    1511             : 
    1512        1196 :         if (strcasecmp(operation, "ResetDwordProperty") == 0) {
    1513             : 
    1514         793 :                 if (typeid != DNSSRV_TYPEID_NAME_AND_PARAM) {
    1515           0 :                         return WERR_DNS_ERROR_INVALID_PROPERTY;
    1516             :                 }
    1517             : 
    1518         793 :                 return dnsserver_db_do_reset_dword(dsstate->samdb, z,
    1519             :                                                    r->NameAndParam);
    1520             : 
    1521         403 :         } else if (strcasecmp(operation, "ZoneTypeReset") == 0) {
    1522           0 :                 valid_operation = true;
    1523         403 :         } else if (strcasecmp(operation, "PauseZone") == 0) {
    1524           0 :                 valid_operation = true;
    1525         403 :         } else if (strcasecmp(operation, "ResumeZone") == 0) {
    1526           0 :                 valid_operation = true;
    1527         403 :         } else if (strcasecmp(operation, "DeleteZone") == 0) {
    1528           0 :                 valid_operation = true;
    1529         403 :         } else if (strcasecmp(operation, "ReloadZone") == 0) {
    1530           0 :                 valid_operation = true;
    1531         403 :         } else if (strcasecmp(operation, "RefreshZone") == 0) {
    1532           0 :                 valid_operation = true;
    1533         403 :         } else if (strcasecmp(operation, "ExpireZone") == 0) {
    1534           0 :                 valid_operation = true;
    1535         403 :         } else if (strcasecmp(operation, "IncrementVersion") == 0) {
    1536           0 :                 valid_operation = true;
    1537         403 :         } else if (strcasecmp(operation, "WriteBackFile") == 0) {
    1538           0 :                 valid_operation = true;
    1539         403 :         } else if (strcasecmp(operation, "DeleteZoneFromDs") == 0) {
    1540           0 :                 WERROR status;
    1541         403 :                 if (z == NULL) {
    1542           0 :                         return WERR_DNS_ERROR_ZONE_DOES_NOT_EXIST;
    1543             :                 }
    1544         403 :                 status =  dnsserver_db_delete_zone(dsstate->samdb, z);
    1545         403 :                 if (W_ERROR_IS_OK(status)) {
    1546         403 :                         dnsserver_reload_zones(dsstate);
    1547             :                 }
    1548         403 :                 return status;
    1549           0 :         } else if (strcasecmp(operation, "UpdateZoneFromDs") == 0) {
    1550           0 :                 valid_operation = true;
    1551           0 :         } else if (strcasecmp(operation, "ZoneExport") == 0) {
    1552           0 :                 valid_operation = true;
    1553           0 :         } else if (strcasecmp(operation, "ZoneChangeDirectoryPartition") == 0) {
    1554           0 :                 valid_operation = true;
    1555           0 :         } else if (strcasecmp(operation, "DeleteNode") == 0) {
    1556           0 :                 valid_operation = true;
    1557           0 :         } else if (strcasecmp(operation, "DeleteRecordSet") == 0) {
    1558           0 :                 valid_operation = true;
    1559           0 :         } else if (strcasecmp(operation, "ForceAgingOnNode") == 0) {
    1560           0 :                 valid_operation = true;
    1561           0 :         } else if (strcasecmp(operation, "DatabaseFile") == 0) {
    1562           0 :                 valid_operation = true;
    1563           0 :         } else if (strcasecmp(operation, "MasterServers") == 0) {
    1564           0 :                 valid_operation = true;
    1565           0 :         } else if (strcasecmp(operation, "LocalMasterServers") == 0) {
    1566           0 :                 valid_operation = true;
    1567           0 :         } else if (strcasecmp(operation, "NotifyServers") == 0) {
    1568           0 :                 valid_operation = true;
    1569           0 :         } else if (strcasecmp(operation, "SecondaryServers") == 0) {
    1570           0 :                 valid_operation = true;
    1571           0 :         } else if (strcasecmp(operation, "ScavengingServers") == 0) {
    1572           0 :                 valid_operation = true;
    1573           0 :         } else if (strcasecmp(operation, "AllowNSRecordsAutoCreation") == 0) {
    1574           0 :                 valid_operation = true;
    1575           0 :         } else if (strcasecmp(operation, "BreakOnNameUpdate") == 0) {
    1576           0 :                 valid_operation = true;
    1577           0 :         } else if (strcasecmp(operation, "ApplicationDirectoryPartition") == 0) {
    1578           0 :                 valid_operation = true;
    1579             :         }
    1580             : 
    1581           0 :         if (valid_operation) {
    1582           0 :                 DEBUG(0, ("dnsserver: zone operation '%s' not implemented\n", operation));
    1583           0 :                 return WERR_CALL_NOT_IMPLEMENTED;
    1584             :         }
    1585             : 
    1586           0 :         DEBUG(0, ("dnsserver: invalid zone operation '%s'\n", operation));
    1587           0 :         return WERR_DNS_ERROR_INVALID_PROPERTY;
    1588             : }
    1589             : 
    1590           0 : static WERROR dnsserver_complex_operate_zone(struct dnsserver_state *dsstate,
    1591             :                                         TALLOC_CTX *mem_ctx,
    1592             :                                         struct dnsserver_zone *z,
    1593             :                                         const char *operation,
    1594             :                                         const unsigned int client_version,
    1595             :                                         enum DNS_RPC_TYPEID typeid_in,
    1596             :                                         union DNSSRV_RPC_UNION *rin,
    1597             :                                         enum DNS_RPC_TYPEID *typeid_out,
    1598             :                                         union DNSSRV_RPC_UNION *rout)
    1599             : {
    1600           0 :         if (strcasecmp(operation, "QueryDwordProperty") == 0) {
    1601           0 :                 if (typeid_in == DNSSRV_TYPEID_LPSTR) {
    1602           0 :                         return dnsserver_query_zone(dsstate, mem_ctx, z,
    1603             :                                                 rin->String,
    1604             :                                                 client_version,
    1605             :                                                 typeid_out,
    1606             :                                                 rout);
    1607             : 
    1608             :                 }
    1609             :         }
    1610             : 
    1611           0 :         DEBUG(0,("dnsserver: Invalid zone operation %s\n", operation));
    1612           0 :         return WERR_DNS_ERROR_INVALID_PROPERTY;
    1613             : }
    1614             : 
    1615             : /* dnsserver enumerate function */
    1616             : 
    1617           3 : static WERROR dnsserver_enumerate_root_records(struct dnsserver_state *dsstate,
    1618             :                                         TALLOC_CTX *mem_ctx,
    1619             :                                         unsigned int client_version,
    1620             :                                         const char *node_name,
    1621             :                                         enum dns_record_type record_type,
    1622             :                                         unsigned int select_flag,
    1623             :                                         unsigned int *buffer_length,
    1624             :                                         struct DNS_RPC_RECORDS_ARRAY **buffer)
    1625             : {
    1626           0 :         TALLOC_CTX *tmp_ctx;
    1627           0 :         struct dnsserver_zone *z;
    1628           3 :         const char * const attrs[] = { "name", "dnsRecord", NULL };
    1629           0 :         struct ldb_result *res;
    1630           0 :         struct DNS_RPC_RECORDS_ARRAY *recs;
    1631           0 :         char **add_names;
    1632           0 :         char *rname;
    1633           0 :         int add_count;
    1634           0 :         int i, ret, len;
    1635           0 :         WERROR status;
    1636             : 
    1637           3 :         tmp_ctx = talloc_new(mem_ctx);
    1638           3 :         W_ERROR_HAVE_NO_MEMORY(tmp_ctx);
    1639             : 
    1640           3 :         z = dnsserver_find_zone(dsstate->zones, ".");
    1641           3 :         if (z == NULL) {
    1642           0 :                 return WERR_DNS_ERROR_NAME_DOES_NOT_EXIST;
    1643             :         }
    1644             : 
    1645           3 :         ret = ldb_search(dsstate->samdb, tmp_ctx, &res, z->zone_dn,
    1646             :                          LDB_SCOPE_ONELEVEL, attrs,
    1647             :                          "(&(objectClass=dnsNode)(name=@)(!(dNSTombstoned=TRUE)))");
    1648           3 :         if (ret != LDB_SUCCESS) {
    1649           0 :                 talloc_free(tmp_ctx);
    1650           0 :                 return WERR_INTERNAL_DB_ERROR;
    1651             :         }
    1652           3 :         if (res->count == 0) {
    1653           0 :                 talloc_free(tmp_ctx);
    1654           0 :                 return WERR_DNS_ERROR_NAME_DOES_NOT_EXIST;
    1655             :         }
    1656             : 
    1657           3 :         recs = talloc_zero(mem_ctx, struct DNS_RPC_RECORDS_ARRAY);
    1658           3 :         W_ERROR_HAVE_NO_MEMORY_AND_FREE(recs, tmp_ctx);
    1659             : 
    1660           3 :         add_names = NULL;
    1661           3 :         add_count = 0;
    1662             : 
    1663           6 :         for (i=0; i<res->count; i++) {
    1664           3 :                 status = dns_fill_records_array(tmp_ctx, NULL, record_type,
    1665             :                                                 select_flag, NULL,
    1666           3 :                                                 res->msgs[i], 0, recs,
    1667             :                                                 &add_names, &add_count);
    1668           3 :                 if (!W_ERROR_IS_OK(status)) {
    1669           0 :                         talloc_free(tmp_ctx);
    1670           0 :                         return status;
    1671             :                 }
    1672             :         }
    1673           3 :         talloc_free(res);
    1674             : 
    1675             :         /* Add any additional records */
    1676           3 :         if (select_flag & DNS_RPC_VIEW_ADDITIONAL_DATA) {
    1677          42 :                 for (i=0; i<add_count; i++) {
    1678           0 :                         char *encoded_name
    1679          39 :                                 = ldb_binary_encode_string(tmp_ctx,
    1680          39 :                                                            add_names[i]);
    1681          39 :                         ret = ldb_search(dsstate->samdb, tmp_ctx, &res, z->zone_dn,
    1682             :                                          LDB_SCOPE_ONELEVEL, attrs,
    1683             :                                          "(&(objectClass=dnsNode)(name=%s)(!(dNSTombstoned=TRUE)))",
    1684             :                                          encoded_name);
    1685          39 :                         if (ret != LDB_SUCCESS || res->count == 0) {
    1686           0 :                                 talloc_free(res);
    1687           0 :                                 continue;
    1688             :                         }
    1689             : 
    1690          39 :                         len = strlen(add_names[i]);
    1691          39 :                         if (add_names[i][len-1] == '.') {
    1692           0 :                                 rname = talloc_strdup(tmp_ctx, add_names[i]);
    1693             :                         } else {
    1694          39 :                                 rname = talloc_asprintf(tmp_ctx, "%s.", add_names[i]);
    1695             :                         }
    1696          39 :                         status = dns_fill_records_array(tmp_ctx, NULL, DNS_TYPE_A,
    1697             :                                                         select_flag, rname,
    1698          39 :                                                         res->msgs[0], 0, recs,
    1699             :                                                         NULL, NULL);
    1700          39 :                         talloc_free(rname);
    1701          39 :                         talloc_free(res);
    1702          39 :                         if (!W_ERROR_IS_OK(status)) {
    1703           0 :                                 talloc_free(tmp_ctx);
    1704           0 :                                 return status;
    1705             :                         }
    1706             :                 }
    1707             :         }
    1708             : 
    1709           3 :         talloc_free(tmp_ctx);
    1710             : 
    1711           3 :         *buffer_length = ndr_size_DNS_RPC_RECORDS_ARRAY(recs, 0);
    1712           3 :         *buffer = recs;
    1713             : 
    1714           3 :         return WERR_OK;
    1715             : }
    1716             : 
    1717             : 
    1718        1259 : static WERROR dnsserver_enumerate_records(struct dnsserver_state *dsstate,
    1719             :                                         TALLOC_CTX *mem_ctx,
    1720             :                                         struct dnsserver_zone *z,
    1721             :                                         unsigned int client_version,
    1722             :                                         const char *node_name,
    1723             :                                         const char *start_child,
    1724             :                                         enum dns_record_type record_type,
    1725             :                                         unsigned int select_flag,
    1726             :                                         const char *filter_start,
    1727             :                                         const char *filter_stop,
    1728             :                                         unsigned int *buffer_length,
    1729             :                                         struct DNS_RPC_RECORDS_ARRAY **buffer)
    1730             : {
    1731           0 :         TALLOC_CTX *tmp_ctx;
    1732           0 :         char *name;
    1733        1259 :         const char * const attrs[] = { "name", "dnsRecord", NULL };
    1734        1259 :         struct ldb_result *res = NULL;
    1735        1259 :         struct DNS_RPC_RECORDS_ARRAY *recs = NULL;
    1736        1259 :         char **add_names = NULL;
    1737        1259 :         char *rname = NULL;
    1738        1259 :         const char *preference_name = NULL;
    1739        1259 :         int add_count = 0;
    1740           0 :         int i, ret, len;
    1741           0 :         WERROR status;
    1742        1259 :         struct dns_tree *tree = NULL;
    1743        1259 :         struct dns_tree *base = NULL;
    1744        1259 :         struct dns_tree *node = NULL;
    1745             : 
    1746        1259 :         tmp_ctx = talloc_new(mem_ctx);
    1747        1259 :         W_ERROR_HAVE_NO_MEMORY(tmp_ctx);
    1748             : 
    1749        1259 :         name = dns_split_node_name(tmp_ctx, node_name, z->name);
    1750        1259 :         W_ERROR_HAVE_NO_MEMORY_AND_FREE(name, tmp_ctx);
    1751             : 
    1752             :         /* search all records under parent tree */
    1753        1259 :         if (strcasecmp(name, z->name) == 0) {
    1754           6 :                 ret = ldb_search(dsstate->samdb, tmp_ctx, &res, z->zone_dn,
    1755             :                                  LDB_SCOPE_ONELEVEL, attrs,
    1756             :                                  "(&(objectClass=dnsNode)(!(dNSTombstoned=TRUE)))");
    1757           6 :                 preference_name = "@";
    1758             :         } else {
    1759           0 :                 char *encoded_name
    1760        1253 :                         = ldb_binary_encode_string(tmp_ctx, name);
    1761        1253 :                 ret = ldb_search(dsstate->samdb, tmp_ctx, &res, z->zone_dn,
    1762             :                                  LDB_SCOPE_ONELEVEL, attrs,
    1763             :                                  "(&(objectClass=dnsNode)(|(name=%s)(name=*.%s))(!(dNSTombstoned=TRUE)))",
    1764             :                                  encoded_name, encoded_name);
    1765        1253 :                 preference_name = name;
    1766             :         }
    1767        1259 :         if (ret != LDB_SUCCESS) {
    1768           0 :                 talloc_free(tmp_ctx);
    1769           0 :                 return WERR_INTERNAL_DB_ERROR;
    1770             :         }
    1771        1259 :         if (res->count == 0) {
    1772         182 :                 talloc_free(tmp_ctx);
    1773         182 :                 return WERR_DNS_ERROR_NAME_DOES_NOT_EXIST;
    1774             :         }
    1775             : 
    1776        1077 :         recs = talloc_zero(mem_ctx, struct DNS_RPC_RECORDS_ARRAY);
    1777        1077 :         W_ERROR_HAVE_NO_MEMORY_AND_FREE(recs, tmp_ctx);
    1778             : 
    1779             :         /*
    1780             :          * Sort the names, so that the records are in order by the child
    1781             :          * component below "name".
    1782             :          *
    1783             :          * A full tree sort is not required, so we pass in "name" so
    1784             :          * we know which level to sort, as only direct children are
    1785             :          * eventually returned
    1786             :          */
    1787        1077 :         LDB_TYPESAFE_QSORT(res->msgs, res->count, name, dns_name_compare);
    1788             : 
    1789             :         /* Build a tree of name components from dns name */
    1790        1077 :         tree = dns_build_tree(tmp_ctx, preference_name, res);
    1791        1077 :         W_ERROR_HAVE_NO_MEMORY_AND_FREE(tree, tmp_ctx);
    1792             : 
    1793             :         /* Find the parent record in the tree */
    1794        1077 :         base = tree;
    1795        1084 :         while (base->level != -1) {
    1796           7 :                 base = base->children[0];
    1797             :         }
    1798             : 
    1799             :         /* Add the parent record with blank name */
    1800        1077 :         if (!(select_flag & DNS_RPC_VIEW_ONLY_CHILDREN)) {
    1801        1077 :                 status = dns_fill_records_array(tmp_ctx, z, record_type,
    1802             :                                                 select_flag, NULL,
    1803        1077 :                                                 base->data, 0,
    1804             :                                                 recs, &add_names, &add_count);
    1805        1077 :                 if (!W_ERROR_IS_OK(status)) {
    1806           0 :                         talloc_free(tmp_ctx);
    1807           0 :                         return status;
    1808             :                 }
    1809             :         }
    1810             : 
    1811             :         /* Add all the children records */
    1812        1077 :         if (!(select_flag & DNS_RPC_VIEW_NO_CHILDREN)) {
    1813         330 :                 for (i=0; i<base->num_children; i++) {
    1814          63 :                         node = base->children[i];
    1815             : 
    1816          63 :                         status = dns_fill_records_array(tmp_ctx, z, record_type,
    1817             :                                                         select_flag, node->name,
    1818          63 :                                                         node->data, node->num_children,
    1819             :                                                         recs, &add_names, &add_count);
    1820          63 :                         if (!W_ERROR_IS_OK(status)) {
    1821           0 :                                 talloc_free(tmp_ctx);
    1822           0 :                                 return status;
    1823             :                         }
    1824             :                 }
    1825             :         }
    1826             : 
    1827        1077 :         TALLOC_FREE(res);
    1828        1077 :         TALLOC_FREE(tree);
    1829        1077 :         TALLOC_FREE(name);
    1830             : 
    1831             :         /* Add any additional records */
    1832        1077 :         if (select_flag & DNS_RPC_VIEW_ADDITIONAL_DATA) {
    1833           0 :                 for (i=0; i<add_count; i++) {
    1834           0 :                         struct dnsserver_zone *z2 = NULL;
    1835           0 :                         struct ldb_message *msg = NULL;
    1836             :                         /* Search all the available zones for additional name */
    1837           0 :                         for (z2 = dsstate->zones; z2; z2 = z2->next) {
    1838           0 :                                 char *encoded_name;
    1839           0 :                                 name = dns_split_node_name(tmp_ctx, add_names[i], z2->name);
    1840           0 :                                 encoded_name
    1841           0 :                                         = ldb_binary_encode_string(tmp_ctx,
    1842             :                                                                    name);
    1843           0 :                                 ret = ldb_search(dsstate->samdb, tmp_ctx, &res, z2->zone_dn,
    1844             :                                                 LDB_SCOPE_ONELEVEL, attrs,
    1845             :                                                 "(&(objectClass=dnsNode)(name=%s)(!(dNSTombstoned=TRUE)))",
    1846             :                                                 encoded_name);
    1847           0 :                                 TALLOC_FREE(name);
    1848           0 :                                 if (ret != LDB_SUCCESS) {
    1849           0 :                                         continue;
    1850             :                                 }
    1851           0 :                                 if (res->count == 1) {
    1852           0 :                                         msg = res->msgs[0];
    1853           0 :                                         break;
    1854             :                                 } else {
    1855           0 :                                         TALLOC_FREE(res);
    1856           0 :                                         continue;
    1857             :                                 }
    1858             :                         }
    1859             : 
    1860           0 :                         len = strlen(add_names[i]);
    1861           0 :                         if (add_names[i][len-1] == '.') {
    1862           0 :                                 rname = talloc_strdup(tmp_ctx, add_names[i]);
    1863             :                         } else {
    1864           0 :                                 rname = talloc_asprintf(tmp_ctx, "%s.", add_names[i]);
    1865             :                         }
    1866           0 :                         status = dns_fill_records_array(tmp_ctx, NULL, DNS_TYPE_A,
    1867             :                                                         select_flag, rname,
    1868             :                                                         msg, 0, recs,
    1869             :                                                         NULL, NULL);
    1870           0 :                         TALLOC_FREE(rname);
    1871           0 :                         TALLOC_FREE(res);
    1872           0 :                         if (!W_ERROR_IS_OK(status)) {
    1873           0 :                                 talloc_free(tmp_ctx);
    1874           0 :                                 return status;
    1875             :                         }
    1876             :                 }
    1877             :         }
    1878             : 
    1879        1077 :         *buffer_length = ndr_size_DNS_RPC_RECORDS_ARRAY(recs, 0);
    1880        1077 :         *buffer = recs;
    1881             : 
    1882        1077 :         return WERR_OK;
    1883             : }
    1884             : 
    1885             : /*
    1886             :  * Check str1 + '.' + str2 = name, for example:
    1887             :  * ("dc0", "example.com", "dc0.example.com") = true
    1888             :  */
    1889         257 : static bool cname_self_reference(const char* node_name,
    1890             :                                  const char* zone_name,
    1891             :                                  struct DNS_RPC_NAME name) {
    1892           0 :         size_t node_len, zone_len;
    1893             : 
    1894         257 :         if (node_name == NULL || zone_name == NULL) {
    1895           0 :                 return false;
    1896             :         }
    1897             : 
    1898         257 :         node_len = strlen(node_name);
    1899         257 :         zone_len = strlen(zone_name);
    1900             : 
    1901         257 :         if (node_len == 0 ||
    1902         257 :             zone_len == 0 ||
    1903         257 :             (name.len != node_len + zone_len + 1)) {
    1904         254 :                 return false;
    1905             :         }
    1906             : 
    1907           3 :         if (strncmp(node_name, name.str, node_len) == 0 &&
    1908           3 :             name.str[node_len] == '.' &&
    1909           3 :             strncmp(zone_name, name.str + node_len + 1, zone_len) == 0) {
    1910           3 :                 return true;
    1911             :         }
    1912             : 
    1913           0 :         return false;
    1914             : }
    1915             : 
    1916             : /* dnsserver update function */
    1917             : 
    1918        3995 : static WERROR dnsserver_update_record(struct dnsserver_state *dsstate,
    1919             :                                         TALLOC_CTX *mem_ctx,
    1920             :                                         struct dnsserver_zone *z,
    1921             :                                         unsigned int client_version,
    1922             :                                         const char *node_name,
    1923             :                                         struct DNS_RPC_RECORD_BUF *add_buf,
    1924             :                                         struct DNS_RPC_RECORD_BUF *del_buf)
    1925             : {
    1926           0 :         TALLOC_CTX *tmp_ctx;
    1927           0 :         char *name;
    1928           0 :         WERROR status;
    1929             : 
    1930        3995 :         tmp_ctx = talloc_new(mem_ctx);
    1931        3995 :         W_ERROR_HAVE_NO_MEMORY(tmp_ctx);
    1932             : 
    1933             :         /* If node_name is @ or zone name, dns record is @ */
    1934        3995 :         if (strcmp(node_name, "@") == 0 ||
    1935        3980 :             strcmp(node_name, ".") == 0 ||
    1936        3980 :             strcasecmp(node_name, z->name) == 0) {
    1937          18 :                 name = talloc_strdup(tmp_ctx, "@");
    1938             :         } else {
    1939        3977 :                 name = dns_split_node_name(tmp_ctx, node_name, z->name);
    1940             :         }
    1941        3995 :         W_ERROR_HAVE_NO_MEMORY_AND_FREE(name, tmp_ctx);
    1942             : 
    1943             :         /* CNAMEs can't point to themselves */
    1944        3995 :         if (add_buf != NULL && add_buf->rec.wType == DNS_TYPE_CNAME) {
    1945         257 :                 if (cname_self_reference(node_name, z->name, add_buf->rec.data.name)) {
    1946           3 :                         return WERR_DNS_ERROR_CNAME_LOOP;
    1947             :                 }
    1948             :         }
    1949             : 
    1950        3992 :         if (add_buf != NULL) {
    1951        2371 :                 if (del_buf == NULL) {
    1952             :                         /* Add record */
    1953        2230 :                         status = dnsserver_db_add_record(tmp_ctx, dsstate->samdb,
    1954             :                                                                 z, name,
    1955             :                                                                 &add_buf->rec);
    1956             :                 } else {
    1957             :                         /* Update record */
    1958         141 :                         status = dnsserver_db_update_record(tmp_ctx, dsstate->samdb,
    1959             :                                                                 z, name,
    1960             :                                                                 &add_buf->rec,
    1961             :                                                                 &del_buf->rec);
    1962             :                 }
    1963             :         } else {
    1964        1621 :                 if (del_buf == NULL) {
    1965             :                         /* Add empty node */
    1966           0 :                         status = dnsserver_db_add_empty_node(tmp_ctx, dsstate->samdb,
    1967             :                                                                 z, name);
    1968             :                 } else {
    1969             :                         /* Delete record */
    1970        1621 :                         status = dnsserver_db_delete_record(tmp_ctx, dsstate->samdb,
    1971             :                                                                 z, name,
    1972             :                                                                 &del_buf->rec);
    1973             :                 }
    1974             :         }
    1975             : 
    1976        3992 :         talloc_free(tmp_ctx);
    1977        3992 :         return status;
    1978             : }
    1979             : 
    1980             : 
    1981             : /* dnsserver interface functions */
    1982             : 
    1983           3 : static WERROR dcesrv_DnssrvOperation(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct DnssrvOperation *r)
    1984             : {
    1985           0 :         struct dnsserver_state *dsstate;
    1986           3 :         struct dnsserver_zone *z = NULL;
    1987           3 :         uint32_t request_filter = 0;
    1988           0 :         WERROR ret;
    1989             : 
    1990           3 :         if ((dsstate = dnsserver_connect(dce_call)) == NULL) {
    1991           0 :                 return WERR_DNS_ERROR_DS_UNAVAILABLE;
    1992             :         }
    1993             : 
    1994           3 :         if (r->in.dwContext == 0) {
    1995           0 :                 if (r->in.pszZone != NULL) {
    1996           0 :                         request_filter = dnsserver_zone_to_request_filter(r->in.pszZone);
    1997             :                 }
    1998             :         } else {
    1999           3 :                 request_filter = r->in.dwContext;
    2000             :         }
    2001             : 
    2002           3 :         if (r->in.pszZone == NULL) {
    2003           0 :                 ret = dnsserver_operate_server(dsstate, mem_ctx,
    2004             :                                                 r->in.pszOperation,
    2005             :                                                 DNS_CLIENT_VERSION_W2K,
    2006             :                                                 r->in.dwTypeId,
    2007             :                                                 &r->in.pData);
    2008             :         } else {
    2009           3 :                 z = dnsserver_find_zone(dsstate->zones, r->in.pszZone);
    2010             :                 /*
    2011             :                  * In the case that request_filter is not 0 and z is NULL,
    2012             :                  * the request is for a multizone operation, which we do not
    2013             :                  * yet support, so just error on NULL zone name.
    2014             :                  */
    2015           3 :                 if (z == NULL) {
    2016           3 :                         return WERR_DNS_ERROR_ZONE_DOES_NOT_EXIST;
    2017             :                 }
    2018             : 
    2019           0 :                 ret = dnsserver_operate_zone(dsstate, mem_ctx, z,
    2020             :                                                 request_filter,
    2021             :                                                 r->in.pszOperation,
    2022             :                                                 DNS_CLIENT_VERSION_W2K,
    2023             :                                                 r->in.dwTypeId,
    2024             :                                                 &r->in.pData);
    2025             :         }
    2026             : 
    2027           0 :         if (W_ERROR_EQUAL(ret, WERR_CALL_NOT_IMPLEMENTED)) {
    2028           0 :                 NDR_PRINT_FUNCTION_DEBUG(DnssrvOperation, NDR_IN, r);
    2029             :         }
    2030           0 :         return ret;
    2031             : }
    2032             : 
    2033           0 : static WERROR dcesrv_DnssrvQuery(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct DnssrvQuery *r)
    2034             : {
    2035           0 :         struct dnsserver_state *dsstate;
    2036           0 :         struct dnsserver_zone *z;
    2037           0 :         WERROR ret;
    2038             : 
    2039           0 :         ZERO_STRUCTP(r->out.pdwTypeId);
    2040           0 :         ZERO_STRUCTP(r->out.ppData);
    2041             : 
    2042           0 :         if ((dsstate = dnsserver_connect(dce_call)) == NULL) {
    2043           0 :                 return WERR_DNS_ERROR_DS_UNAVAILABLE;
    2044             :         }
    2045             : 
    2046           0 :         if (r->in.pszZone == NULL) {
    2047             :                 /* FIXME: DNS Server Configuration Access Control List */
    2048           0 :                 ret = dnsserver_query_server(dsstate, mem_ctx,
    2049             :                                                 r->in.pszOperation,
    2050             :                                                 DNS_CLIENT_VERSION_W2K,
    2051             :                                                 r->out.pdwTypeId,
    2052             :                                                 r->out.ppData);
    2053             :         } else {
    2054           0 :                 z = dnsserver_find_zone(dsstate->zones, r->in.pszZone);
    2055           0 :                 if (z == NULL) {
    2056           0 :                         return WERR_DNS_ERROR_ZONE_DOES_NOT_EXIST;
    2057             :                 }
    2058             : 
    2059           0 :                 ret = dnsserver_query_zone(dsstate, mem_ctx, z,
    2060             :                                                 r->in.pszOperation,
    2061             :                                                 DNS_CLIENT_VERSION_W2K,
    2062             :                                                 r->out.pdwTypeId,
    2063             :                                                 r->out.ppData);
    2064             :         }
    2065             : 
    2066           0 :         if (W_ERROR_EQUAL(ret, WERR_CALL_NOT_IMPLEMENTED)) {
    2067           0 :                 NDR_PRINT_FUNCTION_DEBUG(DnssrvQuery, NDR_IN, r);
    2068             :         }
    2069           0 :         return ret;
    2070             : }
    2071             : 
    2072           0 : static WERROR dcesrv_DnssrvComplexOperation(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct DnssrvComplexOperation *r)
    2073             : {
    2074           0 :         struct dnsserver_state *dsstate;
    2075           0 :         struct dnsserver_zone *z;
    2076           0 :         WERROR ret;
    2077             : 
    2078           0 :         ZERO_STRUCTP(r->out.pdwTypeOut);
    2079           0 :         ZERO_STRUCTP(r->out.ppDataOut);
    2080             : 
    2081           0 :         if ((dsstate = dnsserver_connect(dce_call)) == NULL) {
    2082           0 :                 return WERR_DNS_ERROR_DS_UNAVAILABLE;
    2083             :         }
    2084             : 
    2085           0 :         if (r->in.pszZone == NULL) {
    2086             :                 /* Server operation */
    2087           0 :                 ret = dnsserver_complex_operate_server(dsstate, mem_ctx,
    2088             :                                                         r->in.pszOperation,
    2089             :                                                         DNS_CLIENT_VERSION_W2K,
    2090             :                                                         r->in.dwTypeIn,
    2091             :                                                         &r->in.pDataIn,
    2092             :                                                         r->out.pdwTypeOut,
    2093             :                                                         r->out.ppDataOut);
    2094             :         } else {
    2095           0 :                 z = dnsserver_find_zone(dsstate->zones, r->in.pszZone);
    2096           0 :                 if (z == NULL) {
    2097           0 :                         return WERR_DNS_ERROR_ZONE_DOES_NOT_EXIST;
    2098             :                 }
    2099             : 
    2100           0 :                 ret = dnsserver_complex_operate_zone(dsstate, mem_ctx, z,
    2101             :                                                         r->in.pszOperation,
    2102             :                                                         DNS_CLIENT_VERSION_W2K,
    2103             :                                                         r->in.dwTypeIn,
    2104             :                                                         &r->in.pDataIn,
    2105             :                                                         r->out.pdwTypeOut,
    2106             :                                                         r->out.ppDataOut);
    2107             :         }
    2108             : 
    2109           0 :         if (W_ERROR_EQUAL(ret, WERR_CALL_NOT_IMPLEMENTED)) {
    2110           0 :                 NDR_PRINT_FUNCTION_DEBUG(DnssrvComplexOperation, NDR_IN, r);
    2111             :         }
    2112           0 :         return ret;
    2113             : }
    2114             : 
    2115           0 : static WERROR dcesrv_DnssrvEnumRecords(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct DnssrvEnumRecords *r)
    2116             : {
    2117           0 :         struct dnsserver_state *dsstate;
    2118           0 :         struct dnsserver_zone *z;
    2119           0 :         WERROR ret;
    2120             : 
    2121           0 :         ZERO_STRUCTP(r->out.pdwBufferLength);
    2122           0 :         ZERO_STRUCTP(r->out.pBuffer);
    2123             : 
    2124           0 :         if ((dsstate = dnsserver_connect(dce_call)) == NULL) {
    2125           0 :                 return WERR_DNS_ERROR_DS_UNAVAILABLE;
    2126             :         }
    2127             : 
    2128           0 :         if (r->in.pszZone == NULL) {
    2129           0 :                 return WERR_DNS_ERROR_NAME_DOES_NOT_EXIST;
    2130             :         }
    2131             : 
    2132           0 :         if (strcasecmp(r->in.pszZone, "..RootHints") == 0) {
    2133           0 :                 ret = dnsserver_enumerate_root_records(dsstate, mem_ctx,
    2134             :                                         DNS_CLIENT_VERSION_W2K,
    2135             :                                         r->in.pszNodeName,
    2136             :                                         r->in.wRecordType,
    2137             :                                         r->in.fSelectFlag,
    2138           0 :                                         r->out.pdwBufferLength,
    2139             :                                         r->out.pBuffer);
    2140             :         } else {
    2141           0 :                 z = dnsserver_find_zone(dsstate->zones, r->in.pszZone);
    2142           0 :                 if (z == NULL) {
    2143           0 :                         return WERR_DNS_ERROR_NAME_DOES_NOT_EXIST;
    2144             :                 }
    2145             : 
    2146           0 :                 ret = dnsserver_enumerate_records(dsstate, mem_ctx, z,
    2147             :                                         DNS_CLIENT_VERSION_W2K,
    2148             :                                         r->in.pszNodeName,
    2149             :                                         r->in.pszStartChild,
    2150             :                                         r->in.wRecordType,
    2151             :                                         r->in.fSelectFlag,
    2152             :                                         r->in.pszFilterStart,
    2153             :                                         r->in.pszFilterStop,
    2154           0 :                                         r->out.pdwBufferLength,
    2155             :                                         r->out.pBuffer);
    2156             :         }
    2157             : 
    2158           0 :         if (W_ERROR_EQUAL(ret, WERR_CALL_NOT_IMPLEMENTED)) {
    2159           0 :                 NDR_PRINT_FUNCTION_DEBUG(DnssrvEnumRecords, NDR_IN, r);
    2160             :         }
    2161           0 :         return ret;
    2162             : }
    2163             : 
    2164           0 : static WERROR dcesrv_DnssrvUpdateRecord(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct DnssrvUpdateRecord *r)
    2165             : {
    2166           0 :         struct dnsserver_state *dsstate;
    2167           0 :         struct dnsserver_zone *z;
    2168           0 :         WERROR ret;
    2169             : 
    2170           0 :         if ((dsstate = dnsserver_connect(dce_call)) == NULL) {
    2171           0 :                 return WERR_DNS_ERROR_DS_UNAVAILABLE;
    2172             :         }
    2173             : 
    2174           0 :         if (r->in.pszZone == NULL) {
    2175           0 :                 return WERR_DNS_ERROR_NAME_DOES_NOT_EXIST;
    2176             :         }
    2177             : 
    2178           0 :         z = dnsserver_find_zone(dsstate->zones, r->in.pszZone);
    2179           0 :         if (z == NULL) {
    2180           0 :                 return WERR_DNS_ERROR_NAME_DOES_NOT_EXIST;
    2181             :         }
    2182             : 
    2183           0 :         ret = dnsserver_update_record(dsstate, mem_ctx, z,
    2184             :                                         DNS_CLIENT_VERSION_W2K,
    2185             :                                         r->in.pszNodeName,
    2186             :                                         r->in.pAddRecord,
    2187             :                                         r->in.pDeleteRecord);
    2188             : 
    2189           0 :         if (W_ERROR_EQUAL(ret, WERR_CALL_NOT_IMPLEMENTED)) {
    2190           0 :                 NDR_PRINT_FUNCTION_DEBUG(DnssrvUpdateRecord, NDR_IN, r);
    2191             :         }
    2192           0 :         return ret;
    2193             : }
    2194             : 
    2195        1652 : static WERROR dcesrv_DnssrvOperation2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct DnssrvOperation2 *r)
    2196             : {
    2197           0 :         struct dnsserver_state *dsstate;
    2198        1652 :         struct dnsserver_zone *z = NULL;
    2199        1652 :         uint32_t request_filter = 0;
    2200           0 :         WERROR ret;
    2201             : 
    2202        1652 :         if ((dsstate = dnsserver_connect(dce_call)) == NULL) {
    2203           0 :                 return WERR_DNS_ERROR_DS_UNAVAILABLE;
    2204             :         }
    2205             : 
    2206        1652 :         if (r->in.dwContext == 0) {
    2207        1649 :                 if (r->in.pszZone != NULL) {
    2208        1220 :                         request_filter = dnsserver_zone_to_request_filter(r->in.pszZone);
    2209             :                 }
    2210             :         } else {
    2211           3 :                 request_filter = r->in.dwContext;
    2212             :         }
    2213             : 
    2214        1652 :         if (r->in.pszZone == NULL) {
    2215         429 :                 ret = dnsserver_operate_server(dsstate, mem_ctx,
    2216             :                                                 r->in.pszOperation,
    2217         429 :                                                 r->in.dwClientVersion,
    2218             :                                                 r->in.dwTypeId,
    2219             :                                                 &r->in.pData);
    2220             :         } else {
    2221        1223 :                 z = dnsserver_find_zone(dsstate->zones, r->in.pszZone);
    2222             :                 /*
    2223             :                  * In the case that request_filter is not 0 and z is NULL,
    2224             :                  * the request is for a multizone operation, which we do not
    2225             :                  * yet support, so just error on NULL zone name.
    2226             :                  */
    2227        1223 :                 if (z == NULL) {
    2228          27 :                         return WERR_DNS_ERROR_ZONE_DOES_NOT_EXIST;
    2229             :                 }
    2230             : 
    2231        1196 :                 ret = dnsserver_operate_zone(dsstate, mem_ctx, z,
    2232             :                                                 request_filter,
    2233             :                                                 r->in.pszOperation,
    2234        1196 :                                                 r->in.dwClientVersion,
    2235             :                                                 r->in.dwTypeId,
    2236             :                                                 &r->in.pData);
    2237             :         }
    2238             : 
    2239        1625 :         if (W_ERROR_EQUAL(ret, WERR_CALL_NOT_IMPLEMENTED)) {
    2240           2 :                 NDR_PRINT_FUNCTION_DEBUG(DnssrvOperation2, NDR_IN, r);
    2241             :         }
    2242        1625 :         return ret;
    2243             : }
    2244             : 
    2245          29 : static WERROR dcesrv_DnssrvQuery2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct DnssrvQuery2 *r)
    2246             : {
    2247           0 :         struct dnsserver_state *dsstate;
    2248           0 :         struct dnsserver_zone *z;
    2249           0 :         WERROR ret;
    2250             : 
    2251          29 :         ZERO_STRUCTP(r->out.pdwTypeId);
    2252          29 :         ZERO_STRUCTP(r->out.ppData);
    2253             : 
    2254          29 :         if ((dsstate = dnsserver_connect(dce_call)) == NULL) {
    2255           0 :                 return WERR_DNS_ERROR_DS_UNAVAILABLE;
    2256             :         }
    2257             : 
    2258          29 :         if (r->in.pszZone == NULL) {
    2259             :                 /* FIXME: DNS Server Configuration Access Control List */
    2260          12 :                 ret = dnsserver_query_server(dsstate, mem_ctx,
    2261             :                                                 r->in.pszOperation,
    2262          12 :                                                 r->in.dwClientVersion,
    2263             :                                                 r->out.pdwTypeId,
    2264             :                                                 r->out.ppData);
    2265             :         } else {
    2266          17 :                 z = dnsserver_find_zone(dsstate->zones, r->in.pszZone);
    2267          17 :                 if (z == NULL) {
    2268           0 :                         return WERR_DNS_ERROR_ZONE_DOES_NOT_EXIST;
    2269             :                 }
    2270             : 
    2271          17 :                 ret = dnsserver_query_zone(dsstate, mem_ctx, z,
    2272             :                                         r->in.pszOperation,
    2273          17 :                                         r->in.dwClientVersion,
    2274             :                                         r->out.pdwTypeId,
    2275             :                                         r->out.ppData);
    2276             :         }
    2277             : 
    2278          29 :         if (W_ERROR_EQUAL(ret, WERR_CALL_NOT_IMPLEMENTED)) {
    2279           0 :                 NDR_PRINT_FUNCTION_DEBUG(DnssrvQuery2, NDR_IN, r);
    2280             :         }
    2281          29 :         return ret;
    2282             : }
    2283             : 
    2284          20 : static WERROR dcesrv_DnssrvComplexOperation2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct DnssrvComplexOperation2 *r)
    2285             : {
    2286           0 :         struct dnsserver_state *dsstate;
    2287           0 :         struct dnsserver_zone *z;
    2288           0 :         WERROR ret;
    2289             : 
    2290          20 :         ZERO_STRUCTP(r->out.pdwTypeOut);
    2291          20 :         ZERO_STRUCTP(r->out.ppDataOut);
    2292             : 
    2293          20 :         if ((dsstate = dnsserver_connect(dce_call)) == NULL) {
    2294           0 :                 return WERR_DNS_ERROR_DS_UNAVAILABLE;
    2295             :         }
    2296             : 
    2297          20 :         if (r->in.pszZone == NULL) {
    2298             :                 /* Server operation */
    2299          20 :                 ret =  dnsserver_complex_operate_server(dsstate, mem_ctx,
    2300             :                                                         r->in.pszOperation,
    2301          20 :                                                         r->in.dwClientVersion,
    2302             :                                                         r->in.dwTypeIn,
    2303             :                                                         &r->in.pDataIn,
    2304             :                                                         r->out.pdwTypeOut,
    2305             :                                                         r->out.ppDataOut);
    2306             :         } else {
    2307             : 
    2308           0 :                 z = dnsserver_find_zone(dsstate->zones, r->in.pszZone);
    2309           0 :                 if (z == NULL) {
    2310           0 :                         return WERR_DNS_ERROR_ZONE_DOES_NOT_EXIST;
    2311             :                 }
    2312             : 
    2313           0 :                 ret = dnsserver_complex_operate_zone(dsstate, mem_ctx, z,
    2314             :                                                         r->in.pszOperation,
    2315           0 :                                                         r->in.dwClientVersion,
    2316             :                                                         r->in.dwTypeIn,
    2317             :                                                         &r->in.pDataIn,
    2318             :                                                         r->out.pdwTypeOut,
    2319             :                                                         r->out.ppDataOut);
    2320             :         }
    2321             : 
    2322          20 :         if (W_ERROR_EQUAL(ret, WERR_CALL_NOT_IMPLEMENTED)) {
    2323           0 :                 NDR_PRINT_FUNCTION_DEBUG(DnssrvComplexOperation2, NDR_IN, r);
    2324             :         }
    2325          20 :         return ret;
    2326             : }
    2327             : 
    2328        1262 : static WERROR dcesrv_DnssrvEnumRecords2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct DnssrvEnumRecords2 *r)
    2329             : {
    2330           0 :         struct dnsserver_state *dsstate;
    2331           0 :         struct dnsserver_zone *z;
    2332           0 :         WERROR ret;
    2333             : 
    2334        1262 :         ZERO_STRUCTP(r->out.pdwBufferLength);
    2335        1262 :         ZERO_STRUCTP(r->out.pBuffer);
    2336             : 
    2337        1262 :         if ((dsstate = dnsserver_connect(dce_call)) == NULL) {
    2338           0 :                 return WERR_DNS_ERROR_DS_UNAVAILABLE;
    2339             :         }
    2340             : 
    2341        1262 :         if (r->in.pszZone == NULL) {
    2342           0 :                 return WERR_DNS_ERROR_NAME_DOES_NOT_EXIST;
    2343             :         }
    2344             : 
    2345        1262 :         if (strcasecmp(r->in.pszZone, "..RootHints") == 0) {
    2346           3 :                 ret =  dnsserver_enumerate_root_records(dsstate, mem_ctx,
    2347           3 :                                         r->in.dwClientVersion,
    2348             :                                         r->in.pszNodeName,
    2349             :                                         r->in.wRecordType,
    2350             :                                         r->in.fSelectFlag,
    2351           3 :                                         r->out.pdwBufferLength,
    2352             :                                         r->out.pBuffer);
    2353             :         } else {
    2354        1259 :                 z = dnsserver_find_zone(dsstate->zones, r->in.pszZone);
    2355        1259 :                 if (z == NULL) {
    2356           0 :                         return WERR_DNS_ERROR_NAME_DOES_NOT_EXIST;
    2357             :                 }
    2358             : 
    2359        1259 :                 ret =  dnsserver_enumerate_records(dsstate, mem_ctx, z,
    2360        1259 :                                         r->in.dwClientVersion,
    2361             :                                         r->in.pszNodeName,
    2362             :                                         r->in.pszStartChild,
    2363             :                                         r->in.wRecordType,
    2364             :                                         r->in.fSelectFlag,
    2365             :                                         r->in.pszFilterStart,
    2366             :                                         r->in.pszFilterStop,
    2367        1259 :                                         r->out.pdwBufferLength,
    2368             :                                         r->out.pBuffer);
    2369             : 
    2370             :         }
    2371             : 
    2372        1262 :         if (W_ERROR_EQUAL(ret, WERR_CALL_NOT_IMPLEMENTED)) {
    2373           0 :                 NDR_PRINT_FUNCTION_DEBUG(DnssrvEnumRecords2, NDR_IN, r);
    2374             :         }
    2375        1262 :         return ret;
    2376             : }
    2377             : 
    2378        3995 : static WERROR dcesrv_DnssrvUpdateRecord2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct DnssrvUpdateRecord2 *r)
    2379             : {
    2380           0 :         struct dnsserver_state *dsstate;
    2381           0 :         struct dnsserver_zone *z;
    2382           0 :         WERROR ret;
    2383             : 
    2384        3995 :         if ((dsstate = dnsserver_connect(dce_call)) == NULL) {
    2385           0 :                 return WERR_DNS_ERROR_DS_UNAVAILABLE;
    2386             :         }
    2387             : 
    2388        3995 :         if (r->in.pszZone == NULL) {
    2389           0 :                 return WERR_DNS_ERROR_NAME_DOES_NOT_EXIST;
    2390             :         }
    2391             : 
    2392        3995 :         z = dnsserver_find_zone(dsstate->zones, r->in.pszZone);
    2393        3995 :         if (z == NULL) {
    2394           0 :                 return WERR_DNS_ERROR_NAME_DOES_NOT_EXIST;
    2395             :         }
    2396             : 
    2397        3995 :         ret = dnsserver_update_record(dsstate, mem_ctx, z,
    2398        3995 :                                         r->in.dwClientVersion,
    2399             :                                         r->in.pszNodeName,
    2400             :                                         r->in.pAddRecord,
    2401             :                                         r->in.pDeleteRecord);
    2402             : 
    2403        3995 :         if (W_ERROR_EQUAL(ret, WERR_CALL_NOT_IMPLEMENTED)) {
    2404           0 :                 NDR_PRINT_FUNCTION_DEBUG(DnssrvUpdateRecord2, NDR_IN, r);
    2405             :         }
    2406        3995 :         return ret;
    2407             : }
    2408             : 
    2409             : /* include the generated boilerplate */
    2410             : #include "librpc/gen_ndr/ndr_dnsserver_s.c"

Generated by: LCOV version 1.14