File dhcp-4.2.4-ldap-0004-subclass-name-and-data-quoting-escaping.patch of Package dhcp.openSUSE_12.1_Update

From c7aa273d17d0dffe132db34e76707c722ebdcbb0 Mon Sep 17 00:00:00 2001
From: Marius Tomaschewski <mt@suse.de>
Date: Fri, 30 Nov 2012 13:00:32 +0100
References: bnc#788787
Upstream: sent [ISC-Bugs #32217]
Subject: [PATCH] Fixed subclass class-name and data quoting/escaping

---
 server/ldap.c |   84 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 Datei geändert, 77 Zeilen hinzugefügt(+), 7 Zeilen entfernt(-)

diff --git a/server/ldap.c b/server/ldap.c
index e269716..fb7b504 100644
--- a/server/ldap.c
+++ b/server/ldap.c
@@ -373,11 +373,44 @@ ldap_parse_class (struct ldap_config_stack *item, struct parse *cfile)
   ldap_value_free_len (tempbv);
 }
 
+static int
+is_hex_string(const char *str)
+{
+  int colon = 1;
+  int xdigit = 0;
+  size_t i;
+
+  if (!str)
+    return 0;
+
+  if (*str == '-')
+    str++;
+
+  for (i=0; str[i]; ++i)
+    {
+      if (str[i] == ':')
+        {
+          xdigit = 0;
+          if(++colon > 1)
+            return 0;
+        }
+      else if(isxdigit((unsigned char)str[i]))
+        {
+          colon = 0;
+          if (++xdigit > 2)
+            return 0;
+        }
+      else
+        return 0;
+    }
+  return i > 0 && !colon;
+}
 
 static void
 ldap_parse_subclass (struct ldap_config_stack *item, struct parse *cfile)
 {
   struct berval **tempbv, **classdata;
+  char *tmp;
 
   if ((tempbv = ldap_get_values_len (ld, item->ldent, "cn")) == NULL ||
       tempbv[0] == NULL)
@@ -399,11 +432,22 @@ ldap_parse_subclass (struct ldap_config_stack *item, struct parse *cfile)
       return;
     }
 
-  x_parser_strcat (cfile, "subclass ");
+  x_parser_strcat (cfile, "subclass \"");
   x_parser_strcat (cfile, classdata[0]->bv_val);
-  x_parser_strcat (cfile, " ");
-  x_parser_strcat (cfile, tempbv[0]->bv_val);
-  x_parser_strcat (cfile, " {\n");
+  if (is_hex_string(tempbv[0]->bv_val))
+    {
+      x_parser_strcat (cfile, "\" ");
+      x_parser_strcat (cfile, tempbv[0]->bv_val);
+      x_parser_strcat (cfile, " {\n");
+    }
+  else
+    {
+      tmp = quotify_string(tempbv[0]->bv_val, MDL);
+      x_parser_strcat (cfile, "\" \"");
+      x_parser_strcat (cfile, tmp);
+      x_parser_strcat (cfile, "\" {\n");
+      dfree(tmp, MDL);
+    }
 
   item->close_brace = 1;
   ldap_value_free_len (tempbv);
@@ -2503,7 +2547,10 @@ find_subclass_in_ldap (struct class *class, struct class **newclass,
   int ret, lease_limit;
   isc_result_t status;
   ldap_dn_node *curr;
-  char buf[1024];
+  char buf[2048];
+  struct berval bv_class;
+  struct berval bv_cdata;
+  char *hex_1;
 
   if (local_family != AF_INET)
     return (0);
@@ -2516,10 +2563,33 @@ find_subclass_in_ldap (struct class *class, struct class **newclass,
   if (ld == NULL)
     return (0);
 
+  hex_1 = print_hex_1 (data->len, data->data, 1024);
+  if (*hex_1 == '"')
+    {
+      /* result is a quotted not hex string: ldap escape the original string */
+      if (_do_ldap_str2esc_filter_bv(data->data, data->len, &bv_cdata) == NULL)
+        {
+          log_error ("Cannot escape ldap filter value %s: %m", hex_1);
+          return (0);
+        }
+        hex_1 = NULL;
+    }
+  if (_do_ldap_str2esc_filter_bv(class->name, strlen (class->name), &bv_class) == NULL)
+    {
+      log_error ("Cannot escape ldap filter value %s: %m", class->name);
+      if (hex_1 == NULL)
+        ber_memfree(bv_cdata.bv_val);
+      return (0);
+    }
+
   snprintf (buf, sizeof (buf),
             "(&(objectClass=dhcpSubClass)(cn=%s)(dhcpClassData=%s))",
-            print_hex_1 (data->len, data->data, 60),
-            print_hex_2 (strlen (class->name), (u_int8_t *) class->name, 60));
+            (hex_1 == NULL ? bv_cdata.bv_val : hex_1), bv_class.bv_val);
+
+  if (hex_1 == NULL)
+    ber_memfree(bv_cdata.bv_val);
+  ber_memfree(bv_class.bv_val);
+
 #if defined (DEBUG_LDAP)
   log_info ("Searching LDAP for %s", buf);
 #endif
-- 
1.7.10.4

openSUSE Build Service is sponsored by