Commit 7cd86ef sysdb: try dealing with binary-content attributes

4 files Authored by Jan Engelhardt 5 years ago , Committed by jhrozek 5 years ago ,
sysdb: try dealing with binary-content attributes

https://fedorahosted.org/sssd/ticket/1818

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 called on this blob, which is
the wrong thing to do. The result of strlen is then used to populate
the .v_length member of a struct ldb_val - and this will set it to
zero in this case. (There is also the problem that there may not be
a '\0' at all in the blob.)

Subsequently, .v_length being 0 makes ldb_modify(), called from
sysdb_set_entry_attr(), return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX. End
result is that users do not get stored in the sysdb, and programs like
`id` or `getent ...` show incomplete information.

The bug was encountered with sssd-1.8.5. sssd-1.5.11 seemed to behave
fine, but that may not mean that is the absolute lower boundary of
introduction of the problem.

    
 1 @@ -508,6 +508,16 @@
 2       return sysdb_attrs_add_val(attrs, name, &v);
 3   }
 4   
 5 + int sysdb_attrs_add_mem(struct sysdb_attrs *attrs, const char *name,
 6 +                         const void *mem, size_t size)
 7 + {
 8 + »       struct ldb_val v;
 9 + 
10 + »       v.data   = discard_const(mem);
11 + »       v.length = size;
12 + »       return sysdb_attrs_add_val(attrs, name, &v);
13 + }
14 + 
15   int sysdb_attrs_add_bool(struct sysdb_attrs *attrs,
16                            const char *name, bool value)
17   {
1 @@ -208,6 +208,8 @@
2                           const char *name, const struct ldb_val *val);
3   int sysdb_attrs_add_string(struct sysdb_attrs *attrs,
4                              const char *name, const char *str);
5 + int sysdb_attrs_add_mem(struct sysdb_attrs *, const char *,
6 +                         const void *, size_t);
7   int sysdb_attrs_add_bool(struct sysdb_attrs *attrs,
8                            const char *name, bool value);
9   int sysdb_attrs_add_long(struct sysdb_attrs *attrs,
 1 @@ -312,7 +312,6 @@
 2       const char **ocs;
 3       struct sdap_attr_map *map;
 4       int num_attrs;
 5 -     struct ldb_val v;
 6       int ret, i, a, mi;
 7       const char *name;
 8       size_t len;
 9 @@ -443,10 +442,9 @@
10               for (i=0; dval->vals[i].bv_val; i++) {
11                   DEBUG(9, ("Dereferenced attribute value: %s\n",
12                             dval->vals[i].bv_val));
13 -                 v.data = (uint8_t *) dval->vals[i].bv_val;
14 -                 v.length = dval->vals[i].bv_len;
15 - 
16 -                 ret = sysdb_attrs_add_val(res[mi]->attrs, name, &v);
17 +                 ret = sysdb_attrs_add_mem(res[mi]->attrs, name,
18 +                                           dval->vals[i].bv_val,
19 +                                           dval->vals[i].bv_len);
20                   if (ret) goto done;
21               }
22           }
 1 @@ -2214,8 +2214,8 @@
 2               DEBUG(SSSDBG_TRACE_INTERNAL, ("Adding %s [%s] to attributes "
 3                     "of [%s].\n", desc, el->values[i].data, objname));
 4   
 5 -             ret = sysdb_attrs_add_string(attrs, attr_name,
 6 -                                          (const char *) el->values[i].data);
 7 +             ret = sysdb_attrs_add_mem(attrs, attr_name, el->values[i].data,
 8 +                                       el->values[i].length);
 9               if (ret) {
10                   return ret;
11               }