diff options
author | Isaac Boukris <iboukris@gmail.com> | 2020-06-11 16:51:27 +0300 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2020-06-24 09:57:26 +0000 |
commit | 0e668997c83bcd4c736a86bd78803992225fd4dd (patch) | |
tree | 4d8ea5d06408d2f0bcd0dd84a835e1f37754e8f8 | |
parent | 60e7328219169d949e5a864e322fb2de57c4ffd3 (diff) | |
download | samba-0e668997c83bcd4c736a86bd78803992225fd4dd.tar.gz |
Properly handle msDS-AdditionalDnsHostName returned from Windows DC
Windows DC adds short names for each specified msDS-AdditionalDnsHostName
attribute, but these have a suffix of "\0$" and thus fail with
ldap_get_values(), use ldap_get_values_len() instead.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14406
Signed-off-by: Isaac Boukris <iboukris@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
-rw-r--r-- | selftest/knownfail.d/binary_addl_hostname | 3 | ||||
-rwxr-xr-x | source3/libads/ldap.c | 38 |
2 files changed, 35 insertions, 6 deletions
diff --git a/selftest/knownfail.d/binary_addl_hostname b/selftest/knownfail.d/binary_addl_hostname deleted file mode 100644 index 559db1df507..00000000000 --- a/selftest/knownfail.d/binary_addl_hostname +++ /dev/null @@ -1,3 +0,0 @@ -^samba4.blackbox.net_ads.dns alias1 check keytab -^samba4.blackbox.net_ads.dns alias2 check keytab -^samba4.blackbox.net_ads.addl short check keytab diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index f6fde5e19e1..ed52d4a969e 100755 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -3669,6 +3669,40 @@ out: /******************************************************************** ********************************************************************/ +static char **get_addl_hosts(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, + LDAPMessage *msg, size_t *num_values) +{ + const char *field = "msDS-AdditionalDnsHostName"; + struct berval **values = NULL; + char **ret = NULL; + size_t i, converted_size; + + values = ldap_get_values_len(ads->ldap.ld, msg, field); + if (values == NULL) { + return NULL; + } + + *num_values = ldap_count_values_len(values); + + ret = talloc_array(mem_ctx, char *, *num_values + 1); + if (ret == NULL) { + ldap_value_free_len(values); + return NULL; + } + + for (i = 0; i < *num_values; i++) { + if (!pull_utf8_talloc(mem_ctx, &ret[i], values[i]->bv_val, + &converted_size)) { + ldap_value_free_len(values); + return NULL; + } + } + ret[i] = NULL; + + ldap_value_free_len(values); + return ret; +} + ADS_STATUS ads_get_additional_dns_hostnames(TALLOC_CTX *mem_ctx, ADS_STRUCT *ads, const char *machine_name, @@ -3694,9 +3728,7 @@ ADS_STATUS ads_get_additional_dns_hostnames(TALLOC_CTX *mem_ctx, goto done; } - *hostnames_array = ads_pull_strings(ads, mem_ctx, res, - "msDS-AdditionalDnsHostName", - num_hostnames); + *hostnames_array = get_addl_hosts(ads, mem_ctx, res, num_hostnames); if (*hostnames_array == NULL) { DEBUG(1, ("Host account for %s does not have msDS-AdditionalDnsHostName.\n", machine_name)); |