]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add '&' if it's not already there
authorAlan T. DeKok <aland@freeradius.org>
Tue, 18 Dec 2018 16:11:51 +0000 (11:11 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 18 Dec 2018 16:11:51 +0000 (11:11 -0500)
as a hack so that the user doesn't have to put '&' in all of the
LDAP entries.  We KNOW they're supposed to be attributes, so we
might as well FORCE them to be attributes.

src/lib/ldap/map.c

index dea4262ff2331fde1104e2262c675b559e48c8a7..72883cb8e3ed0752bec618f8c0c3d2e303b97aac 100644 (file)
@@ -75,14 +75,28 @@ int fr_ldap_map_getvalue(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, vp
                                fr_box_strvalue_len(self->values[i]->bv_val, self->values[i]->bv_len));
 
                        /*
-                        *      bv_val is NOT \0 terminated, so we need to make it
-                        *      safe (\0 terminate it) before passing it to any
-                        *      functions which take C strings and no lengths.
+                        *      The data in LDAP *must* be attribute
+                        *      names.  If there isn't a leading '&',
+                        *      just add one...
                         */
-                       attr_str = talloc_bstrndup(NULL, self->values[i]->bv_val, self->values[i]->bv_len);
-                       if (!attr_str) {
-                               RWDEBUG("Failed making attribute string safe");
-                               continue;
+                       if (self->values[i]->bv_val[0] != '&') {
+                               attr_str = talloc_zero_array(NULL, char, self->values[i]->bv_len + 2);
+                               if (!attr_str) goto alloc_fail;
+
+                               attr_str[0] = '&';
+                               memcpy(attr_str + 1, self->values[i]->bv_val, self->values[i]->bv_len);
+                       } else {
+                               /*
+                                *      bv_val is NOT \0 terminated, so we need to make it
+                                *      safe (\0 terminate it) before passing it to any
+                                *      functions which take C strings and no lengths.
+                                */
+                               attr_str = talloc_bstrndup(NULL, self->values[i]->bv_val, self->values[i]->bv_len);
+                               if (!attr_str) {
+                               alloc_fail:
+                                       RWDEBUG("Failed making attribute string safe");
+                                       continue;
+                               }
                        }
 
                        if (map_afrom_attr_str(ctx, &attr,