2010-10-01 12:59:22 -07:00
/*
Unix SMB / CIFS implementation .
DNS server utils
Copyright ( C ) 2010 Kai Blin < kai @ samba . org >
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
# include "libcli/util/ntstatus.h"
2010-10-11 23:39:44 +02:00
# include "libcli/util/werror.h"
2010-10-01 12:59:22 -07:00
# include "librpc/ndr/libndr.h"
# include "librpc/gen_ndr/ndr_dns.h"
# include "librpc/gen_ndr/ndr_dnsp.h"
# include <ldb.h>
# include "dsdb/samdb/samdb.h"
# include "dsdb/common/util.h"
# include "dns_server/dns_server.h"
2013-01-14 01:14:29 +01:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_DNS
2011-12-16 09:24:18 +01:00
2017-08-03 15:12:02 +12:00
/*
* Lookup a DNS record , performing an exact match .
* i . e . DNS wild card records are not considered .
*/
2011-12-16 09:43:47 +01:00
WERROR dns_lookup_records ( struct dns_server * dns ,
TALLOC_CTX * mem_ctx ,
struct ldb_dn * dn ,
struct dnsp_DnssrvRpcRecord * * records ,
uint16_t * rec_count )
{
2014-07-31 08:54:17 +02:00
return dns_common_lookup ( dns - > samdb , mem_ctx , dn ,
records , rec_count , NULL ) ;
2011-12-16 09:43:47 +01:00
}
2017-08-03 15:12:02 +12:00
/*
* Lookup a DNS record , will match DNS wild card records if an exact match
* is not found .
*/
WERROR dns_lookup_records_wildcard ( struct dns_server * dns ,
TALLOC_CTX * mem_ctx ,
struct ldb_dn * dn ,
struct dnsp_DnssrvRpcRecord * * records ,
uint16_t * rec_count )
{
return dns_common_wildcard_lookup ( dns - > samdb , mem_ctx , dn ,
records , rec_count ) ;
}
2011-12-16 14:21:52 +01:00
WERROR dns_replace_records ( struct dns_server * dns ,
TALLOC_CTX * mem_ctx ,
struct ldb_dn * dn ,
bool needs_add ,
2014-07-31 11:32:02 +02:00
struct dnsp_DnssrvRpcRecord * records ,
2011-12-16 14:21:52 +01:00
uint16_t rec_count )
{
2014-07-30 18:27:56 +02:00
/* TODO: Autogenerate this somehow */
uint32_t dwSerial = 110 ;
return dns_common_replace ( dns - > samdb , mem_ctx , dn ,
needs_add , dwSerial , records , rec_count ) ;
2011-12-16 14:21:52 +01:00
}
2016-05-31 10:48:15 +12:00
bool dns_authoritative_for_zone ( struct dns_server * dns ,
const char * name )
2012-03-27 13:36:16 +02:00
{
const struct dns_server_zone * z ;
size_t host_part_len = 0 ;
if ( name = = NULL ) {
return false ;
}
if ( strcmp ( name , " " ) = = 0 ) {
return true ;
}
for ( z = dns - > zones ; z ! = NULL ; z = z - > next ) {
bool match ;
match = dns_name_match ( z - > name , name , & host_part_len ) ;
if ( match ) {
break ;
}
}
if ( z = = NULL ) {
return false ;
}
return true ;
}
2014-10-29 13:35:36 +01:00
const char * dns_get_authoritative_zone ( struct dns_server * dns ,
const char * name )
{
const struct dns_server_zone * z ;
size_t host_part_len = 0 ;
for ( z = dns - > zones ; z ! = NULL ; z = z - > next ) {
bool match ;
match = dns_name_match ( z - > name , name , & host_part_len ) ;
if ( match ) {
return z - > name ;
}
}
return NULL ;
}
2010-10-11 23:39:44 +02:00
WERROR dns_name2dn ( struct dns_server * dns ,
TALLOC_CTX * mem_ctx ,
const char * name ,
2015-09-22 12:10:00 +12:00
struct ldb_dn * * dn )
2010-10-01 12:59:22 -07:00
{
2015-09-22 12:10:00 +12:00
return dns_common_name2dn ( dns - > samdb , dns - > zones ,
mem_ctx , name , dn ) ;
2010-10-01 12:59:22 -07:00
}
2013-05-25 13:21:33 +02:00