You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by mi...@apache.org on 2024/08/28 10:41:28 UTC
svn commit: r1920247 - /apr/apr/trunk/ldap/apr_ldap.c
Author: minfrin
Date: Wed Aug 28 10:41:28 2024
New Revision: 1920247
URL: http://svn.apache.org/viewvc?rev=1920247&view=rev
Log:
apr_ldap: Add support for RFC4522 binary encoding option.
Modified:
apr/apr/trunk/ldap/apr_ldap.c
Modified: apr/apr/trunk/ldap/apr_ldap.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/ldap/apr_ldap.c?rev=1920247&r1=1920246&r2=1920247&view=diff
==============================================================================
--- apr/apr/trunk/ldap/apr_ldap.c (original)
+++ apr/apr/trunk/ldap/apr_ldap.c Wed Aug 28 10:41:28 2024
@@ -1568,16 +1568,32 @@ APU_DECLARE_LDAP(apr_status_t) apr_ldap_
if (vals) {
- int k, nvals;
+ int k, nvals, binary = 0;
+
+ char *sc = attr;
+
+ /* support for RFC4522 binary encoding option */
+ while ((sc = strchr(sc, ';'))) {
+ if (!strcasecmp(sc, ";binary") && (sc[7] == 0 || sc[7] == ';')) {
+ binary = 1;
+ break;
+ }
+ }
nvals = ldap_count_values_len(vals);
for (k = 0; k < nvals; k++) {
apr_buffer_t buf;
+ char *str = NULL;
- apr_buffer_mem_set(&buf, vals[k]->bv_val, vals[k]->bv_len);
-// fixme - tell cb if binary
+ if (binary) {
+ apr_buffer_mem_set(&buf, vals[k]->bv_val, vals[k]->bv_len);
+ }
+ else {
+ str = strndup(vals[k]->bv_val, vals[k]->bv_len);
+ apr_buffer_str_set(&buf, str, vals[k]->bv_len);
+ }
if (res->entry_cb.search) {
status = res->entry_cb.search(ldap, dn, res->nentries, nattrs, j,
@@ -1586,6 +1602,10 @@ APU_DECLARE_LDAP(apr_status_t) apr_ldap_
else {
status = apr_ldap_status(err->rc, APR_EGENERAL);
}
+
+ if (str) {
+ free(str);
+ }
}
}
Re: svn commit: r1920247 - /apr/apr/trunk/ldap/apr_ldap.c
Posted by Yann Ylavic <yl...@gmail.com>.
On Wed, Aug 28, 2024 at 3:47 PM Graham Leggett via dev
<de...@apr.apache.org> wrote:
>
> On 28 Aug 2024, at 13:02, Ruediger Pluem <rp...@apache.org> wrote:
>
> >> - apr_buffer_mem_set(&buf, vals[k]->bv_val, vals[k]->bv_len);
> >> -// fixme - tell cb if binary
> >> + if (binary) {
> >> + apr_buffer_mem_set(&buf, vals[k]->bv_val, vals[k]->bv_len);
> >> + }
> >> + else {
> >> + str = strndup(vals[k]->bv_val, vals[k]->bv_len);
> >
> > Why do we need the strndup?
>
> Further up we get the data from ldap_get_values_len(), which gives us fixed length results instead of strings.
>
> https://linux.die.net/man/3/ldap_get_values_len
>
> Alas ldap_get_values() is deprecated, so we can't use it.
But the "binary" buffer is not nul_terminated either so why the
non-binary should be if not provided as such in the first place?
Regards;
Yann.
Re: svn commit: r1920247 - /apr/apr/trunk/ldap/apr_ldap.c
Posted by Graham Leggett via dev <de...@apr.apache.org>.
On 28 Aug 2024, at 13:02, Ruediger Pluem <rp...@apache.org> wrote:
>> - apr_buffer_mem_set(&buf, vals[k]->bv_val, vals[k]->bv_len);
>> -// fixme - tell cb if binary
>> + if (binary) {
>> + apr_buffer_mem_set(&buf, vals[k]->bv_val, vals[k]->bv_len);
>> + }
>> + else {
>> + str = strndup(vals[k]->bv_val, vals[k]->bv_len);
>
> Why do we need the strndup?
Further up we get the data from ldap_get_values_len(), which gives us fixed length results instead of strings.
https://linux.die.net/man/3/ldap_get_values_len
Alas ldap_get_values() is deprecated, so we can't use it.
Regards,
Graham
--
Re: svn commit: r1920247 - /apr/apr/trunk/ldap/apr_ldap.c
Posted by Ruediger Pluem <rp...@apache.org>.
On 8/28/24 12:41 PM, minfrin@apache.org wrote:
> Author: minfrin
> Date: Wed Aug 28 10:41:28 2024
> New Revision: 1920247
>
> URL: http://svn.apache.org/viewvc?rev=1920247&view=rev
> Log:
> apr_ldap: Add support for RFC4522 binary encoding option.
>
> Modified:
> apr/apr/trunk/ldap/apr_ldap.c
>
> Modified: apr/apr/trunk/ldap/apr_ldap.c
> URL: http://svn.apache.org/viewvc/apr/apr/trunk/ldap/apr_ldap.c?rev=1920247&r1=1920246&r2=1920247&view=diff
> ==============================================================================
> --- apr/apr/trunk/ldap/apr_ldap.c (original)
> +++ apr/apr/trunk/ldap/apr_ldap.c Wed Aug 28 10:41:28 2024
> @@ -1568,16 +1568,32 @@ APU_DECLARE_LDAP(apr_status_t) apr_ldap_
>
> if (vals) {
>
> - int k, nvals;
> + int k, nvals, binary = 0;
> +
> + char *sc = attr;
> +
> + /* support for RFC4522 binary encoding option */
> + while ((sc = strchr(sc, ';'))) {
> + if (!strcasecmp(sc, ";binary") && (sc[7] == 0 || sc[7] == ';')) {
> + binary = 1;
> + break;
> + }
> + }
>
> nvals = ldap_count_values_len(vals);
>
> for (k = 0; k < nvals; k++) {
>
> apr_buffer_t buf;
> + char *str = NULL;
>
> - apr_buffer_mem_set(&buf, vals[k]->bv_val, vals[k]->bv_len);
> -// fixme - tell cb if binary
> + if (binary) {
> + apr_buffer_mem_set(&buf, vals[k]->bv_val, vals[k]->bv_len);
> + }
> + else {
> + str = strndup(vals[k]->bv_val, vals[k]->bv_len);
Why do we need the strndup?
> + apr_buffer_str_set(&buf, str, vals[k]->bv_len);
> + }
>
> if (res->entry_cb.search) {
> status = res->entry_cb.search(ldap, dn, res->nentries, nattrs, j,
Regards
Rüdiger
Re: svn commit: r1920247 - /apr/apr/trunk/ldap/apr_ldap.c
Posted by Yann Ylavic <yl...@gmail.com>.
On Wed, Aug 28, 2024 at 12:41 PM <mi...@apache.org> wrote:
>
> --- apr/apr/trunk/ldap/apr_ldap.c (original)
> +++ apr/apr/trunk/ldap/apr_ldap.c Wed Aug 28 10:41:28 2024
> @@ -1568,16 +1568,32 @@ APU_DECLARE_LDAP(apr_status_t) apr_ldap_
>
> if (vals) {
>
> - int k, nvals;
> + int k, nvals, binary = 0;
> +
> + char *sc = attr;
> +
> + /* support for RFC4522 binary encoding option */
> + while ((sc = strchr(sc, ';'))) {
> + if (!strcasecmp(sc, ";binary") && (sc[7] == 0 || sc[7] == ';')) {
strncasecmp(..., 7) or even apr_cstr_casecmpn() which does not depend
on the locale?
> + binary = 1;
> + break;
> + }
sc++ ?
> + }
Regards;
Yann.