LCOV - code coverage report
Current view: top level - source4/dns_server - dns_utils.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 26 33 78.8 %
Date: 2024-04-21 15:09:00 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        2817 : 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        2817 :         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        2684 : 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        2684 :         return dns_common_wildcard_lookup(dns->samdb, mem_ctx, dn,
      62             :                                  records, rec_count);
      63             : }
      64             : 
      65        1228 : 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        1228 :         uint32_t dwSerial = 110;
      74        1228 :         return dns_common_replace(dns->samdb, mem_ctx, dn,
      75             :                                   needs_add, dwSerial, records, rec_count);
      76             : }
      77             : 
      78        2681 : bool dns_authoritative_for_zone(struct dns_server *dns,
      79             :                                 const char *name)
      80             : {
      81           0 :         const struct dns_server_zone *z;
      82        2681 :         size_t host_part_len = 0;
      83             : 
      84        2681 :         if (name == NULL) {
      85           0 :                 return false;
      86             :         }
      87             : 
      88        2681 :         if (strcmp(name, "") == 0) {
      89           0 :                 return true;
      90             :         }
      91        4683 :         for (z = dns->zones; z != NULL; z = z->next) {
      92           0 :                 bool match;
      93             : 
      94        4648 :                 match = dns_name_match(z->name, name, &host_part_len);
      95        4648 :                 if (match) {
      96        2646 :                         break;
      97             :                 }
      98             :         }
      99        2681 :         if (z == NULL) {
     100          35 :                 return false;
     101             :         }
     102             : 
     103        2646 :         return true;
     104             : }
     105             : 
     106        2589 : const char *dns_get_authoritative_zone(struct dns_server *dns,
     107             :                                        const char *name)
     108             : {
     109           0 :         const struct dns_server_zone *z;
     110        2589 :         size_t host_part_len = 0;
     111             : 
     112        4428 :         for (z = dns->zones; z != NULL; z = z->next) {
     113           0 :                 bool match;
     114        4428 :                 match = dns_name_match(z->name, name, &host_part_len);
     115        4428 :                 if (match) {
     116        2589 :                         return z->name;
     117             :                 }
     118             :         }
     119           0 :         return NULL;
     120             : }
     121             : 
     122        7897 : WERROR dns_name2dn(struct dns_server *dns,
     123             :                    TALLOC_CTX *mem_ctx,
     124             :                    const char *name,
     125             :                    struct ldb_dn **dn)
     126             : {
     127        7897 :         return dns_common_name2dn(dns->samdb, dns->zones,
     128             :                                   mem_ctx, name, dn);
     129             : }
     130             : 

Generated by: LCOV version 1.14