diff options
author | Gary Lockyer <gary@catalyst.net.nz> | 2018-11-07 15:08:04 +1300 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2018-11-28 08:22:24 +0100 |
commit | 9a12a001466b21cfb27cb77ee01b11d84bcb36b4 (patch) | |
tree | 2f4015df7de2586f8e940097191974466852c61c /source4/dns_server | |
parent | 2b00f8fa9fdcecbd6951f09d528531c5585b9778 (diff) | |
download | samba-9a12a001466b21cfb27cb77ee01b11d84bcb36b4.tar.gz |
CVE-2018-16852 dcerpc dnsserver: refactor common properties handling
dnsserver_common.c and dnsutils.c both share similar code to process
zone properties. This patch extracts the common code and moves it to
dnsserver_common.c.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13669
Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4/dns_server')
-rw-r--r-- | source4/dns_server/dnsserver_common.c | 129 | ||||
-rw-r--r-- | source4/dns_server/dnsserver_common.h | 3 |
2 files changed, 96 insertions, 36 deletions
diff --git a/source4/dns_server/dnsserver_common.c b/source4/dns_server/dnsserver_common.c index 1a032b4aa9f..656d7ca6bff 100644 --- a/source4/dns_server/dnsserver_common.c +++ b/source4/dns_server/dnsserver_common.c @@ -742,6 +742,94 @@ bool dns_name_is_static(struct dnsp_DnssrvRpcRecord *records, return false; } +/* + * Helper function to copy a dnsp_ip4_array struct to an IP4_ARRAY struct. + * The new structure and it's data are allocated on the supplied talloc context + */ +static struct IP4_ARRAY *copy_ip4_array(TALLOC_CTX *ctx, + const char *name, + struct dnsp_ip4_array array) +{ + + struct IP4_ARRAY *ip4_array = NULL; + unsigned int i; + + ip4_array = talloc_zero(ctx, struct IP4_ARRAY); + if (ip4_array == NULL) { + DBG_ERR("Out of memory copying property [%s]\n", name); + return NULL; + } + + ip4_array->AddrCount = array.addrCount; + if (ip4_array->AddrCount == 0) { + return ip4_array; + } + + ip4_array->AddrArray = + talloc_array(ip4_array, uint32_t, ip4_array->AddrCount); + if (ip4_array->AddrArray == NULL) { + TALLOC_FREE(ip4_array); + DBG_ERR("Out of memory copying property [%s] values\n", name); + return NULL; + } + + for (i = 0; i < ip4_array->AddrCount; i++) { + ip4_array->AddrArray[i] = array.addr[i]; + } + + return ip4_array; +} + +bool dns_zoneinfo_load_zone_property(struct dnsserver_zoneinfo *zoneinfo, + struct dnsp_DnsProperty *prop) +{ + switch (prop->id) { + case DSPROPERTY_ZONE_TYPE: + zoneinfo->dwZoneType = prop->data.zone_type; + break; + case DSPROPERTY_ZONE_ALLOW_UPDATE: + zoneinfo->fAllowUpdate = prop->data.allow_update_flag; + break; + case DSPROPERTY_ZONE_NOREFRESH_INTERVAL: + zoneinfo->dwNoRefreshInterval = prop->data.norefresh_hours; + break; + case DSPROPERTY_ZONE_REFRESH_INTERVAL: + zoneinfo->dwRefreshInterval = prop->data.refresh_hours; + break; + case DSPROPERTY_ZONE_AGING_STATE: + zoneinfo->fAging = prop->data.aging_enabled; + break; + case DSPROPERTY_ZONE_SCAVENGING_SERVERS: + zoneinfo->aipScavengeServers = copy_ip4_array( + zoneinfo, "ZONE_SCAVENGING_SERVERS", prop->data.servers); + if (zoneinfo->aipScavengeServers == NULL) { + return false; + } + break; + case DSPROPERTY_ZONE_AGING_ENABLED_TIME: + zoneinfo->dwAvailForScavengeTime = + prop->data.next_scavenging_cycle_hours; + break; + case DSPROPERTY_ZONE_MASTER_SERVERS: + zoneinfo->aipLocalMasters = copy_ip4_array( + zoneinfo, "ZONE_MASTER_SERVERS", prop->data.master_servers); + if (zoneinfo->aipLocalMasters == NULL) { + return false; + } + break; + case DSPROPERTY_ZONE_EMPTY: + case DSPROPERTY_ZONE_SECURE_TIME: + case DSPROPERTY_ZONE_DELETED_FROM_HOSTNAME: + case DSPROPERTY_ZONE_AUTO_NS_SERVERS: + case DSPROPERTY_ZONE_DCPROMO_CONVERT: + case DSPROPERTY_ZONE_SCAVENGING_SERVERS_DA: + case DSPROPERTY_ZONE_MASTER_SERVERS_DA: + case DSPROPERTY_ZONE_NS_SERVERS_DA: + case DSPROPERTY_ZONE_NODE_DBFLAGS: + break; + } + return true; +} WERROR dns_get_zone_properties(struct ldb_context *samdb, TALLOC_CTX *mem_ctx, struct ldb_dn *zone_dn, @@ -774,6 +862,7 @@ WERROR dns_get_zone_properties(struct ldb_context *samdb, } for (i = 0; i < element->num_values; i++) { + bool valid_property; prop = talloc_zero(mem_ctx, struct dnsp_DnsProperty); if (prop == NULL) { return WERR_NOT_ENOUGH_MEMORY; @@ -787,42 +876,10 @@ WERROR dns_get_zone_properties(struct ldb_context *samdb, return DNS_ERR(SERVER_FAILURE); } - switch (prop->id) { - case DSPROPERTY_ZONE_AGING_STATE: - zoneinfo->fAging = prop->data.aging_enabled; - break; - case DSPROPERTY_ZONE_NOREFRESH_INTERVAL: - zoneinfo->dwNoRefreshInterval = - prop->data.norefresh_hours; - break; - case DSPROPERTY_ZONE_REFRESH_INTERVAL: - zoneinfo->dwRefreshInterval = prop->data.refresh_hours; - break; - case DSPROPERTY_ZONE_ALLOW_UPDATE: - zoneinfo->fAllowUpdate = prop->data.allow_update_flag; - break; - case DSPROPERTY_ZONE_AGING_ENABLED_TIME: - zoneinfo->dwAvailForScavengeTime = - prop->data.next_scavenging_cycle_hours; - break; - case DSPROPERTY_ZONE_SCAVENGING_SERVERS: - zoneinfo->aipScavengeServers->AddrCount = - prop->data.servers.addrCount; - zoneinfo->aipScavengeServers->AddrArray = - prop->data.servers.addr; - break; - case DSPROPERTY_ZONE_EMPTY: - case DSPROPERTY_ZONE_TYPE: - case DSPROPERTY_ZONE_SECURE_TIME: - case DSPROPERTY_ZONE_DELETED_FROM_HOSTNAME: - case DSPROPERTY_ZONE_MASTER_SERVERS: - case DSPROPERTY_ZONE_AUTO_NS_SERVERS: - case DSPROPERTY_ZONE_DCPROMO_CONVERT: - case DSPROPERTY_ZONE_SCAVENGING_SERVERS_DA: - case DSPROPERTY_ZONE_MASTER_SERVERS_DA: - case DSPROPERTY_ZONE_NS_SERVERS_DA: - case DSPROPERTY_ZONE_NODE_DBFLAGS: - break; + valid_property = + dns_zoneinfo_load_zone_property(zoneinfo, prop); + if (!valid_property) { + return DNS_ERR(SERVER_FAILURE); } } diff --git a/source4/dns_server/dnsserver_common.h b/source4/dns_server/dnsserver_common.h index 380f61b8dbc..60ecde4fa91 100644 --- a/source4/dns_server/dnsserver_common.h +++ b/source4/dns_server/dnsserver_common.h @@ -87,4 +87,7 @@ NTSTATUS dns_common_zones(struct ldb_context *samdb, TALLOC_CTX *mem_ctx, struct ldb_dn *base_dn, struct dns_server_zone **zones_ret); + +bool dns_zoneinfo_load_zone_property(struct dnsserver_zoneinfo *zoneinfo, + struct dnsp_DnsProperty *prop); #endif /* __DNSSERVER_COMMON_H__ */ |