]> git.netwichtig.de Git - user/henk/code/exim.git/blobdiff - src/src/lookups/ldap.c
More abstraction of the gstring API
[user/henk/code/exim.git] / src / src / lookups / ldap.c
index ba77c98c25c94d6469b4543350ba697065b45138..82d6954ff09592620bc2443f72a0046e308996e0 100644 (file)
@@ -326,17 +326,19 @@ if (!lcp)
     g = string_catn(NULL, ldap_url, init_ptr - ldap_url);
     g = string_fmt_append(g, "//%s:%d/", shost, port);
     }
-  string_from_gstring(g);
 
   /* Call ldap_initialize() and check the result */
+   {
+    const uschar * s = string_from_gstring(g);
 
-  DEBUG(D_lookup) debug_printf_indent("ldap_initialize with URL %s\n", g->s);
-  if ((rc = ldap_initialize(&ld, CS g->s)) != LDAP_SUCCESS)
-    {
-    *errmsg = string_sprintf("ldap_initialize: (error %d) URL \"%s\"\n",
-      rc, g->s);
-    goto RETURN_ERROR;
-    }
+    DEBUG(D_lookup) debug_printf_indent("ldap_initialize with URL %s\n", s);
+    if ((rc = ldap_initialize(&ld, CS s)) != LDAP_SUCCESS)
+      {
+      *errmsg = string_sprintf("ldap_initialize: (error %d) URL \"%s\"\n",
+       rc, s);
+      goto RETURN_ERROR;
+      }
+   }
   store_reset(reset_point);   /* Might as well save memory when we can */
 
 
@@ -1470,20 +1472,27 @@ t = quoted = store_get_quoted(len + count + 1, s, idx);
 /* Handle plain quote_ldap */
 
 if (!dn)
-  for (; c = *s++; *t++ = c)
+  {
+  while ((c = *s++))
+    {
     if (!isalnum(c))
       {
       if (Ustrchr(LDAP_QUOTE, c) != NULL)
         {
         sprintf(CS t, "%%5C%02X", c);        /* e.g. * => %5C2A */
         t += 5;
+        continue;
         }
-      else if (Ustrchr(URL_NONQUOTE, c) == NULL)  /* e.g. ] => %5D */
+      if (Ustrchr(URL_NONQUOTE, c) == NULL)  /* e.g. ] => %5D */
         {
         sprintf(CS t, "%%%02X", c);
         t += 3;
+        continue;
         }
       }
+    *t++ = c;                                /* unquoted character */
+    }
+  }
 
 /* Handle quote_ldap_dn */
 
@@ -1513,7 +1522,7 @@ else
       {
       if (Ustrchr(LDAP_DN_QUOTE, c) != NULL)
         {
-        Ustrcpy(t, US"%5C");                   /* insert \ where needed */
+        memcpy(t, US"%5C", 3);                 /* insert \ where needed */
         t += 3;                                        /* fall through to check URL */
         }
       if (Ustrchr(URL_NONQUOTE, c) == NULL)  /* e.g. ] => %5D */
@@ -1530,7 +1539,7 @@ else
 
   while (*ss++)
     {
-    Ustrcpy(t, US"%5C%20");
+    memcpy(t, US"%5C%20", 6);
     t += 6;
     }
   }