LCOV - code coverage report
Current view: top level - source4/dns_server - dns_utils.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 26 29 89.7 %
Date: 2021-09-23 10:06:22 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       88382 : 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       88382 :         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       98444 : 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       98444 :         return dns_common_wildcard_lookup(dns->samdb, mem_ctx, dn,
      62             :                                  records, rec_count);
      63             : }
      64             : 
      65        1369 : 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        1369 :         uint32_t dwSerial = 110;
      74        1369 :         return dns_common_replace(dns->samdb, mem_ctx, dn,
      75             :                                   needs_add, dwSerial, records, rec_count);
      76             : }
      77             : 
      78       94757 : bool dns_authoritative_for_zone(struct dns_server *dns,
      79             :                                 const char *name)
      80             : {
      81             :         const struct dns_server_zone *z;
      82       94757 :         size_t host_part_len = 0;
      83             : 
      84       94757 :         if (name == NULL) {
      85           0 :                 return false;
      86             :         }
      87             : 
      88       94757 :         if (strcmp(name, "") == 0) {
      89           0 :                 return true;
      90             :         }
      91      154481 :         for (z = dns->zones; z != NULL; z = z->next) {
      92             :                 bool match;
      93             : 
      94      154445 :                 match = dns_name_match(z->name, name, &host_part_len);
      95      154445 :                 if (match) {
      96       94653 :                         break;
      97             :                 }
      98             :         }
      99       94757 :         if (z == NULL) {
     100          36 :                 return false;
     101             :         }
     102             : 
     103       94721 :         return true;
     104             : }
     105             : 
     106       88238 : const char *dns_get_authoritative_zone(struct dns_server *dns,
     107             :                                        const char *name)
     108             : {
     109             :         const struct dns_server_zone *z;
     110       88238 :         size_t host_part_len = 0;
     111             : 
     112      141379 :         for (z = dns->zones; z != NULL; z = z->next) {
     113             :                 bool match;
     114      141379 :                 match = dns_name_match(z->name, name, &host_part_len);
     115      141379 :                 if (match) {
     116       88238 :                         return z->name;
     117             :                 }
     118             :         }
     119           0 :         return NULL;
     120             : }
     121             : 
     122      189524 : WERROR dns_name2dn(struct dns_server *dns,
     123             :                    TALLOC_CTX *mem_ctx,
     124             :                    const char *name,
     125             :                    struct ldb_dn **dn)
     126             : {
     127      189524 :         return dns_common_name2dn(dns->samdb, dns->zones,
     128             :                                   mem_ctx, name, dn);
     129             : }
     130             : 

Generated by: LCOV version 1.13