LCOV - code coverage report
Current view: top level - source4/dns_server - dns_utils.c (source / functions) Hit Total Coverage
Test: coverage report for master 6248eab5 Lines: 26 29 89.7 %
Date: 2021-08-25 13:27:56 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    DNS server utils
       5             : 
       6             :    Copyright (C) 2010 Kai Blin  <kai@samba.org>
       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 "libcli/util/ntstatus.h"
      24             : #include "libcli/util/werror.h"
      25             : #include "librpc/ndr/libndr.h"
      26             : #include "librpc/gen_ndr/ndr_dns.h"
      27             : #include "librpc/gen_ndr/ndr_dnsp.h"
      28             : #include <ldb.h>
      29             : #include "dsdb/samdb/samdb.h"
      30             : #include "dsdb/common/util.h"
      31             : #include "dns_server/dns_server.h"
      32             : 
      33             : #undef DBGC_CLASS
      34             : #define DBGC_CLASS DBGC_DNS
      35             : 
      36             : 
      37             : /*
      38             :  * Lookup a DNS record, performing an exact match.
      39             :  * i.e. DNS wild card records are not considered.
      40             :  */
      41       84448 : WERROR dns_lookup_records(struct dns_server *dns,
      42             :                           TALLOC_CTX *mem_ctx,
      43             :                           struct ldb_dn *dn,
      44             :                           struct dnsp_DnssrvRpcRecord **records,
      45             :                           uint16_t *rec_count)
      46             : {
      47       84448 :         return dns_common_lookup(dns->samdb, mem_ctx, dn,
      48             :                                  records, rec_count, NULL);
      49             : }
      50             : 
      51             : /*
      52             :  * Lookup a DNS record, will match DNS wild card records if an exact match
      53             :  * is not found.
      54             :  */
      55       98143 : WERROR dns_lookup_records_wildcard(struct dns_server *dns,
      56             :                           TALLOC_CTX *mem_ctx,
      57             :                           struct ldb_dn *dn,
      58             :                           struct dnsp_DnssrvRpcRecord **records,
      59             :                           uint16_t *rec_count)
      60             : {
      61       98143 :         return dns_common_wildcard_lookup(dns->samdb, mem_ctx, dn,
      62             :                                  records, rec_count);
      63             : }
      64             : 
      65        1911 : WERROR dns_replace_records(struct dns_server *dns,
      66             :                            TALLOC_CTX *mem_ctx,
      67             :                            struct ldb_dn *dn,
      68             :                            bool needs_add,
      69             :                            struct dnsp_DnssrvRpcRecord *records,
      70             :                            uint16_t rec_count)
      71             : {
      72             :         /* TODO: Autogenerate this somehow */
      73        1911 :         uint32_t dwSerial = 110;
      74        1911 :         return dns_common_replace(dns->samdb, mem_ctx, dn,
      75             :                                   needs_add, dwSerial, records, rec_count);
      76             : }
      77             : 
      78       90883 : bool dns_authoritative_for_zone(struct dns_server *dns,
      79             :                                 const char *name)
      80             : {
      81             :         const struct dns_server_zone *z;
      82       90883 :         size_t host_part_len = 0;
      83             : 
      84       90883 :         if (name == NULL) {
      85           0 :                 return false;
      86             :         }
      87             : 
      88       90883 :         if (strcmp(name, "") == 0) {
      89           0 :                 return true;
      90             :         }
      91      148829 :         for (z = dns->zones; z != NULL; z = z->next) {
      92             :                 bool match;
      93             : 
      94      148778 :                 match = dns_name_match(z->name, name, &host_part_len);
      95      148778 :                 if (match) {
      96       90764 :                         break;
      97             :                 }
      98             :         }
      99       90883 :         if (z == NULL) {
     100          51 :                 return false;
     101             :         }
     102             : 
     103       90832 :         return true;
     104             : }
     105             : 
     106       84305 : const char *dns_get_authoritative_zone(struct dns_server *dns,
     107             :                                        const char *name)
     108             : {
     109             :         const struct dns_server_zone *z;
     110       84305 :         size_t host_part_len = 0;
     111             : 
     112      135576 :         for (z = dns->zones; z != NULL; z = z->next) {
     113             :                 bool match;
     114      135576 :                 match = dns_name_match(z->name, name, &host_part_len);
     115      135576 :                 if (match) {
     116       84305 :                         return z->name;
     117             :                 }
     118             :         }
     119           0 :         return NULL;
     120             : }
     121             : 
     122      186375 : WERROR dns_name2dn(struct dns_server *dns,
     123             :                    TALLOC_CTX *mem_ctx,
     124             :                    const char *name,
     125             :                    struct ldb_dn **dn)
     126             : {
     127      186375 :         return dns_common_name2dn(dns->samdb, dns->zones,
     128             :                                   mem_ctx, name, dn);
     129             : }
     130             : 

Generated by: LCOV version 1.13