[SSSD] [PATCH] sysdb: try dealing with binary-content attributes

Jan Engelhardt jengelh at inai.de
Thu Feb 21 12:20:47 UTC 2013


I have here a LDAP user entry which has this attribute

	loginAllowedTimeMap::
	 AAAAAAAAAP///38AAP///38AAP///38AAP///38AAP///38AAAAAAAAA

In the function sysdb_attrs_add_string(), called from
sdap_attrs_add_ldap_attr(), strlen() is used to populate the .v_length
member of a struct ldb_val - and this will set it to zero.

Subsequently, this makes ldb_modify(), called from
sysdb_set_entry_attr(), return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX.
---
 src/db/sysdb.c                  |   10 ++++++++++
 src/db/sysdb.h                  |    2 ++
 src/providers/ldap/sdap_async.c |    4 ++--
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index e7524f4..7c34791 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -512,6 +512,16 @@ int sysdb_attrs_add_string(struct sysdb_attrs *attrs,
     return sysdb_attrs_add_val(attrs, name, &v);
 }
 
+int sysdb_attrs_add_mem(struct sysdb_attrs *attrs, const char *name,
+                        const void *mem, size_t size)
+{
+	struct ldb_val v;
+
+	v.data   = discard_const(mem);
+	v.length = size;
+	return sysdb_attrs_add_val(attrs, name, &v);
+}
+
 int sysdb_attrs_add_bool(struct sysdb_attrs *attrs,
                          const char *name, bool value)
 {
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index fff97a8..23cbbb0 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -250,6 +250,8 @@ int sysdb_attrs_add_val(struct sysdb_attrs *attrs,
                         const char *name, const struct ldb_val *val);
 int sysdb_attrs_add_string(struct sysdb_attrs *attrs,
                            const char *name, const char *str);
+int sysdb_attrs_add_mem(struct sysdb_attrs *, const char *,
+                        const void *, size_t);
 int sysdb_attrs_add_bool(struct sysdb_attrs *attrs,
                          const char *name, bool value);
 int sysdb_attrs_add_long(struct sysdb_attrs *attrs,
diff --git a/src/providers/ldap/sdap_async.c b/src/providers/ldap/sdap_async.c
index 84497b7..b7d9839 100644
--- a/src/providers/ldap/sdap_async.c
+++ b/src/providers/ldap/sdap_async.c
@@ -2226,8 +2226,8 @@ sdap_attrs_add_ldap_attr(struct sysdb_attrs *ldap_attrs,
             DEBUG(SSSDBG_TRACE_INTERNAL, ("Adding %s [%s] to attributes "
                   "of [%s].\n", desc, el->values[i].data, objname));
 
-            ret = sysdb_attrs_add_string(attrs, attr_name,
-                                         (const char *) el->values[i].data);
+            ret = sysdb_attrs_add_mem(attrs, attr_name, el->values[i].data,
+                                      el->values[i].length);
             if (ret) {
                 return ret;
             }
-- 
1.7.10.4




More information about the sssd-devel mailing list