On Tue, Nov 13, 2012 at 05:46:20PM +0100, Petr Spacek wrote:
> Hello,
> 
> I found the bug in dn_to_dnsname() during my work on
> https://fedorahosted.org/bind-dyndb-ldap/ticket/91
> "Cache is not flushed properly if renamed/deleted zone has superior zone in 
> LDAP"
> 
> Consider this change as part of solution for ticket #91:
> 
>     Fix origin handling in dn_to_dnsname() for zone DNs.
> 
>     This patch fixes case where DN is zone (i.e. DN with single idnsName
>     component) and origin is non-NULL.
> 
>     Function str_to_isc_buffer() was fixed to not truncate last character.

Ack

> From 840dd9d6ee6eefde0baf00930590bb279e73db75 Mon Sep 17 00:00:00 2001
> From: Petr Spacek <pspa...@redhat.com>
> Date: Tue, 13 Nov 2012 17:29:05 +0100
> Subject: [PATCH] Fix origin handling in dn_to_dnsname() for zone DNs.
> 
> This patch fixes case where DN is zone (i.e. DN with single idnsName
> component) and origin is non-NULL.
> 
> Function str_to_isc_buffer() was fixed to not truncate last character.
> 
> Signed-off-by: Petr Spacek <pspa...@redhat.com>
> ---
>  src/ldap_convert.c | 39 +++++++++++++++++++++++++--------------
>  src/str.c          |  2 +-
>  2 files changed, 26 insertions(+), 15 deletions(-)
> 
> diff --git a/src/ldap_convert.c b/src/ldap_convert.c
> index 
> 3352c573cafc54421c77b0b770657841b90ebd71..394d8d036c1d4e0f8a82499282d1acef7d442bcd
>  100644
> --- a/src/ldap_convert.c
> +++ b/src/ldap_convert.c
> @@ -91,12 +91,11 @@ dn_to_dnsname(isc_mem_t *mctx, const char *dn, dns_name_t 
> *target,
>  
>       CHECK(dn_to_text(dn, str, ostr));
>       str_to_isc_buffer(str, &buffer);
> -     CHECK(dns_name_fromtext(&name, &buffer, dns_rootname, 0, NULL));
> +     CHECK(dns_name_fromtext(&name, &buffer, NULL, 0, NULL));
>  
>       if (otarget != NULL) {
>               str_to_isc_buffer(ostr, &buffer);
> -             CHECK(dns_name_fromtext(&origin, &buffer, dns_rootname, 0,
> -                   NULL));
> +             CHECK(dns_name_fromtext(&origin, &buffer, NULL, 0, NULL));
>       }
>  
>  cleanup:
> @@ -124,14 +123,26 @@ cleanup:
>       return result;
>  }
>  
> -/*
> - * Convert LDAP dn to DNS name.
> +/**
> + * Convert LDAP DN to absolute DNS name.
>   *
> - * Example:
> - * dn = "idnsName=foo, idnsName=bar, idnsName=example.org, cn=dns,"
> - *      "dc=example, dc=org"
> + * @param[out] target Absolute DNS name derived from the all idnsNames.
> + * @param[out] origin Absolute DNS name derived from the last idnsName
> + *                    component of DN, i.e. zone. Can be NULL.
>   *
> - * The resulting string will be "foo.bar.example.org."
> + * @code
> + * Examples:
> + * dn = "idnsName=foo, idnsName=bar, idnsName=example.org,"
> + *      "cn=dns, dc=example, dc=org"
> + * target = "foo.bar.example.org."
> + * origin = "example.org."
> + *
> + * dn = "idnsname=89, idnsname=4.34.10.in-addr.arpa.",
> + *      " cn=dns, dc=example, dc=org"
> + * target = "89.4.34.10.in-addr.arpa."
> + * origin = "4.34.10.in-addr.arpa."
> + * (The dot at the end is not doubled when it's already present.)
> + * @endcode
>   */
>  isc_result_t
>  dn_to_text(const char *dn, ld_string_t *target, ld_string_t *origin)
> @@ -159,24 +170,24 @@ dn_to_text(const char *dn, ld_string_t *target, 
> ld_string_t *origin)
>  
>               CHECK(explode_rdn(exploded_dn[i], &exploded_rdn, 1));
>               CHECK(str_cat_char(target, exploded_rdn[0]));
> -             CHECK(str_cat_char(target, "."));
> +             if (str_buf(target)[str_len(target)-1] != '.')
> +                     CHECK(str_cat_char(target, "."));
>       }
>  
>       if (origin != NULL) {
>               str_clear(origin);
>  
>               /*
>                * If we have DNs with only one idnsName part,
> -              * treat them as absolute.
> +              * treat them as absolute zone name.
>                */
> -
>               if (i < 2)
>                       CHECK(str_init_char(origin, "."));
>               else {
>                       CHECK(str_cat_char(origin, exploded_rdn[0]));
> -                     CHECK(str_cat_char(origin, "."));
> +                     if (str_buf(origin)[str_len(origin)-1] != '.')
> +                             CHECK(str_cat_char(origin, "."));
>               }
> -                     
>       }
>  
>       if (str_len(target) == 0)
> diff --git a/src/str.c b/src/str.c
> index 
> 83645365ee6eff7bda5fbeda6837f30d4dec41ae..1be3f5b61250cb6900820dd4bf1375a3ed77359c
>  100644
> --- a/src/str.c
> +++ b/src/str.c
> @@ -465,7 +465,7 @@ str_to_isc_buffer(const ld_string_t *src, isc_buffer_t 
> *dest)
>       REQUIRE(src != NULL);
>       REQUIRE(dest != NULL);
>  
> -     len = str_len_internal(src) - 1;
> +     len = str_len_internal(src);
>  
>       isc_buffer_init(dest, src->data, len);
>       isc_buffer_add(dest, len);
> -- 
> 1.7.11.7
> 


-- 
Adam Tkac, Red Hat, Inc.

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to