* Exim - an Internet mail transport agent *
*************************************************/
+/* Copyright (c) The Exim Maintainers 2020 - 2022 */
/* Copyright (c) University of Cambridge 1995 - 2018 */
/* See the file NOTICE for conditions of use and distribution. */
/* Now add this connection to the chain of cached connections */
- lcp = store_get(sizeof(LDAP_CONNECTION), FALSE);
+ lcp = store_get(sizeof(LDAP_CONNECTION), GET_UNTAINTED);
lcp->host = host ? string_copy(host) : NULL;
lcp->bound = FALSE;
lcp->user = NULL;
uschar *user = NULL;
uschar *password = NULL;
uschar *local_servers = NULL;
-uschar *server;
const uschar *list;
-uschar buffer[512];
while (isspace(*url)) url++;
&defer_break, user, password, sizelimit, timelimit, tcplimit, dereference,
referrals);
-/* Loop through the default servers until OK or FAIL. Use local_servers list
- * if defined in the lookup, otherwise use the global default list */
-list = !local_servers ? eldap_default_servers : local_servers;
-while ((server = string_nextinlist(&list, &sep, buffer, sizeof(buffer))))
+/* Loop through the servers until OK or FAIL. Use local_servers list
+if defined in the lookup, otherwise use the global default list */
+
+list = local_servers ? local_servers : eldap_default_servers;
+for (uschar * server; server = string_nextinlist(&list, &sep, NULL, 0); )
{
- int rc;
- int port = 0;
+ int rc, port = 0;
uschar *colon = Ustrchr(server, ':');
if (colon)
{
int length, uschar ** result, uschar ** errmsg, uint * do_cache,
const uschar * opts)
{
-/* Keep picky compilers happy */
-do_cache = do_cache;
return(control_ldap_search(ldap_url, SEARCH_LDAP_SINGLE, result, errmsg));
}
int length, uschar ** result, uschar ** errmsg, uint * do_cache,
const uschar * opts)
{
-/* Keep picky compilers happy */
-do_cache = do_cache;
return(control_ldap_search(ldap_url, SEARCH_LDAP_MULTIPLE, result, errmsg));
}
int length, uschar ** result, uschar ** errmsg, uint * do_cache,
const uschar * opts)
{
-/* Keep picky compilers happy */
-do_cache = do_cache;
return(control_ldap_search(ldap_url, SEARCH_LDAP_DN, result, errmsg));
}
eldapauth_find(void * handle, const uschar * filename, const uschar * ldap_url,
int length, uschar ** result, uschar ** errmsg, uint * do_cache)
{
-/* Keep picky compilers happy */
-do_cache = do_cache;
return(control_ldap_search(ldap_url, SEARCH_LDAP_AUTH, result, errmsg));
}
static void
eldap_tidy(void)
{
-LDAP_CONNECTION *lcp = NULL;
eldap_dn = NULL;
-while ((lcp = ldap_connections) != NULL)
+for (LDAP_CONNECTION *lcp; lcp = ldap_connections; ldap_connections = lcp->next)
{
- DEBUG(D_lookup) debug_printf_indent("unbind LDAP connection to %s:%d\n", lcp->host,
- lcp->port);
- if(lcp->bound == TRUE)
- ldap_unbind(lcp->ld);
- ldap_connections = lcp->next;
+ DEBUG(D_lookup) debug_printf_indent("unbind LDAP connection to %s:%d\n",
+ lcp->host, lcp->port);
+ if(lcp->bound) ldap_unbind(lcp->ld);
}
}
s the string to be quoted
opt additional option text or NULL if none
only "dn" is recognized
+ idx lookup type index
Returns: the processed string or NULL for a bad option
*/
static uschar *
-eldap_quote(uschar *s, uschar *opt)
+eldap_quote(uschar * s, uschar * opt, unsigned idx)
{
-register int c;
-int count = 0;
-int len = 0;
+int c, count = 0, len = 0;
BOOL dn = FALSE;
-uschar *t = s;
-uschar *quoted;
+uschar * t = s, * quoted;
/* Test for a DN quotation. */
-if (opt != NULL)
+if (opt)
{
if (Ustrcmp(opt, "dn") != 0) return NULL; /* No others recognized */
dn = TRUE;
possibly escaped character. The really fast way would be just to test for
non-alphanumerics, but it is probably better to spot a few others that are
never escaped, because if there are no specials at all, we can avoid copying
-the string. */
+the string.
+XXX No longer true; we always copy, to support quoted-enforcement */
-while ((c = *t++) != 0)
+while ((c = *t++))
{
len++;
if (!isalnum(c) && Ustrchr(ALWAYS_LITERAL, c) == NULL) count += 5;
}
-if (count == 0) return s;
+/*if (count == 0) return s;*/
/* Get sufficient store to hold the quoted string */
-t = quoted = store_get(len + count + 1, is_tainted(s));
+t = quoted = store_get_quoted(len + count + 1, s, idx);
/* Handle plain quote_ldap */
if (!dn)
{
- while ((c = *s++) != 0)
+ while ((c = *s++))
{
if (!isalnum(c))
{
else
{
- uschar *ss = s + len;
+ uschar * ss = s + len;
/* Find the last char before any trailing spaces */
#include "../version.h"
-void
-ldap_version_report(FILE *f)
+gstring *
+ldap_version_report(gstring * g)
{
#ifdef DYNLOOKUP
-fprintf(f, "Library version: LDAP: Exim version %s\n", EXIM_VERSION_STR);
+g = string_fmt_append(g, "Library version: LDAP: Exim version %s\n", EXIM_VERSION_STR);
#endif
+return g;
}
static lookup_info ldap_lookup_info = {
- US"ldap", /* lookup name */
- lookup_querystyle, /* query-style lookup */
- eldap_open, /* open function */
- NULL, /* check function */
- eldap_find, /* find function */
- NULL, /* no close function */
- eldap_tidy, /* tidy function */
- eldap_quote, /* quoting function */
- ldap_version_report /* version reporting */
+ .name = US"ldap", /* lookup name */
+ .type = lookup_querystyle, /* query-style lookup */
+ .open = eldap_open, /* open function */
+ .check = NULL, /* check function */
+ .find = eldap_find, /* find function */
+ .close = NULL, /* no close function */
+ .tidy = eldap_tidy, /* tidy function */
+ .quote = eldap_quote, /* quoting function */
+ .version_report = ldap_version_report /* version reporting */
};
static lookup_info ldapdn_lookup_info = {
- US"ldapdn", /* lookup name */
- lookup_querystyle, /* query-style lookup */
- eldap_open, /* sic */ /* open function */
- NULL, /* check function */
- eldapdn_find, /* find function */
- NULL, /* no close function */
- eldap_tidy, /* sic */ /* tidy function */
- eldap_quote, /* sic */ /* quoting function */
- NULL /* no version reporting (redundant) */
+ .name = US"ldapdn", /* lookup name */
+ .type = lookup_querystyle, /* query-style lookup */
+ .open = eldap_open, /* sic */ /* open function */
+ .check = NULL, /* check function */
+ .find = eldapdn_find, /* find function */
+ .close = NULL, /* no close function */
+ .tidy = eldap_tidy, /* sic */ /* tidy function */
+ .quote = eldap_quote, /* sic */ /* quoting function */
+ .version_report = NULL /* no version reporting (redundant) */
};
static lookup_info ldapm_lookup_info = {
- US"ldapm", /* lookup name */
- lookup_querystyle, /* query-style lookup */
- eldap_open, /* sic */ /* open function */
- NULL, /* check function */
- eldapm_find, /* find function */
- NULL, /* no close function */
- eldap_tidy, /* sic */ /* tidy function */
- eldap_quote, /* sic */ /* quoting function */
- NULL /* no version reporting (redundant) */
+ .name = US"ldapm", /* lookup name */
+ .type = lookup_querystyle, /* query-style lookup */
+ .open = eldap_open, /* sic */ /* open function */
+ .check = NULL, /* check function */
+ .find = eldapm_find, /* find function */
+ .close = NULL, /* no close function */
+ .tidy = eldap_tidy, /* sic */ /* tidy function */
+ .quote = eldap_quote, /* sic */ /* quoting function */
+ .version_report = NULL /* no version reporting (redundant) */
};
#ifdef DYNLOOKUP