s4/lib/policy/gp_ldap: use ldb API to find messages
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 10 Apr 2019 04:43:10 +0000 (16:43 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 10 May 2019 01:15:18 +0000 (01:15 +0000)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/lib/policy/gp_ldap.c

index 5a1ee7d8ed65e18316634be84eeddc5d902e579d..67b329b12957d95f4771437fcef1ea01df8b5ecb 100644 (file)
@@ -398,7 +398,7 @@ NTSTATUS gp_get_gplinks(struct gp_context *gp_ctx, const char *dn_str, struct gp
        struct gp_link **gplinks;
        char *gplink_str;
        int rv;
-       unsigned int i, j;
+       unsigned int i;
        NTSTATUS status;
 
        /* Create a forked memory context, as a base for everything here */
@@ -415,18 +415,18 @@ NTSTATUS gp_get_gplinks(struct gp_context *gp_ctx, const char *dn_str, struct gp
        }
 
        for (i = 0; i < result->count; i++) {
-               for (j = 0; j < result->msgs[i]->num_elements; j++) {
-                       struct ldb_message_element *element = &result->msgs[i]->elements[j];
-
-                       if (strcmp(element->name, "gPLink") == 0) {
-                               SMB_ASSERT(element->num_values > 0);
-                               gplink_str = talloc_strdup(mem_ctx, (char *) element->values[0].data);
-                               if (gplink_str == NULL) {
-                                       TALLOC_FREE(mem_ctx);
-                                       return NT_STATUS_NO_MEMORY;
-                               }
-                               goto found;
+               struct ldb_message_element *element = \
+                       ldb_msg_find_element(result->msgs[i], "gPLink");
+               if (element != NULL) {
+                       SMB_ASSERT(element->num_values > 0);
+                       gplink_str = talloc_strdup(
+                               mem_ctx,
+                               (char *) element->values[0].data);
+                       if (gplink_str == NULL) {
+                               TALLOC_FREE(mem_ctx);
+                               return NT_STATUS_NO_MEMORY;
                        }
+                       goto found;
                }
        }
        gplink_str = talloc_strdup(mem_ctx, "");