Module: sip-router
Branch: master
Commit: 73655cc83851f1f406ce23b8d6130632d731ef2d
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=73655cc…
Author: Henning Westerholt <henning.westerholt(a)1und1.de>
Committer: Henning Westerholt <henning.westerholt(a)1und1.de>
Date: Thu Jan 21 19:26:08 2010 +0100
ldap(k): fix ldapsearch with empty filter
* fix ldapsearch with empty filter
* When in routing script ldapsearch() is executed on LDAP query URL without
the ‘filter’ section, request forming fails:
ERROR: ldap [ldap_api_fn.c:193]: vsnprintf failed
* Workaround for administrators can be filling filter section with
‘(objectclass=*)’, what is anyway substituted by ldap library to request
in case filter parameter set to NULL.
* Please notice that va_end() call is missing in original code.
* Patch FS#23 from andrey dot utkin at wildix dot com
---
modules_k/ldap/ldap_api_fn.c | 44 +++++++++++++++++++++++------------------
1 files changed, 25 insertions(+), 19 deletions(-)
diff --git a/modules_k/ldap/ldap_api_fn.c b/modules_k/ldap/ldap_api_fn.c
index c2176fc..20fd869 100644
--- a/modules_k/ldap/ldap_api_fn.c
+++ b/modules_k/ldap/ldap_api_fn.c
@@ -158,6 +158,7 @@ int ldap_params_search(
{
int rc;
static char filter_str[LDAP_MAX_FILTER_LEN];
+ char *filter_ptr = NULL;
va_list filter_vars;
/*
@@ -174,24 +175,29 @@ int ldap_params_search(
return -1;
}
- /*
- * vsnprintf
- */
- va_start(filter_vars, _filter);
- rc = vsnprintf(filter_str, (size_t)LDAP_MAX_FILTER_LEN, _filter,
- filter_vars);
- if (rc >= LDAP_MAX_FILTER_LEN)
- {
- LM_ERR( "[%s]: filter string too long (len [%d], max len [%d])\n",
- _lds_name,
- rc,
- LDAP_MAX_FILTER_LEN);
- return -1;
- }
- else if (rc < 0)
- {
- LM_ERR("vsnprintf failed\n");
- return -1;
+ if (_filter) {
+ /*
+ * vsnprintf
+ */
+ va_start(filter_vars, _filter);
+ rc = vsnprintf(filter_str, (size_t)LDAP_MAX_FILTER_LEN, _filter,
+ filter_vars);
+ va_end(filter_vars);
+
+ if (rc >= LDAP_MAX_FILTER_LEN)
+ {
+ LM_ERR( "[%s]: filter string too long (len [%d], max len [%d])\n",
+ _lds_name,
+ rc,
+ LDAP_MAX_FILTER_LEN);
+ return -1;
+ }
+ else if (rc < 0)
+ {
+ LM_ERR("vsnprintf failed\n");
+ return -1;
+ }
+ filter_ptr = filter_str;
}
/*
@@ -200,7 +206,7 @@ int ldap_params_search(
if (lds_search(_lds_name,
_dn,
_scope,
- filter_str,
+ filter_ptr,
_attrs,
NULL,
_ld_result_count,