winbindd: Do not use group_list->out.resume_index after free
[samba.git] / source4 / winbind / wb_xids2sids.c
index 843d292c070fc4daac3466ea9e7d6277b4fc8de1..aeec2ee5be6202da7a15576c4df3f2df734f8b89 100644 (file)
 #include "libcli/composite/composite.h"
 #include "winbind/wb_server.h"
 #include "smbd/service_task.h"
-#include "winbind/wb_helper.h"
-#include "libcli/security/proto.h"
-#include "winbind/idmap.h"
 
 struct xids2sids_state {
        struct composite_context *ctx;
        struct wbsrv_service *service;
-       struct id_mapping *ids;
+       struct id_map *ids;
        int count;
 };
 
 struct composite_context *wb_xids2sids_send(TALLOC_CTX *mem_ctx,
                                            struct wbsrv_service *service,
-                                           int count, struct id_mapping *ids)
+                                           unsigned int count, struct id_map *ids)
 {
        struct composite_context *result;
        struct xids2sids_state *state;
+       struct id_map **pointer_array;
+       unsigned int i;
 
-       DEBUG(0, ("wb_xids2sids_send called\n"));
+       DEBUG(5, ("wb_xids2sids_send called\n"));
 
        result = composite_create(mem_ctx, service->task->event_ctx);
        if (!result) return NULL;
@@ -55,8 +54,19 @@ struct composite_context *wb_xids2sids_send(TALLOC_CTX *mem_ctx,
        state->count = count;
        state->ids = ids;
 
+       /* We need to convert between calling conventions here - the
+        * values are filled in by reference, so we just need to
+        * provide pointers to them */
+       pointer_array = talloc_array(state, struct id_map *, count+1);
+       if (composite_nomem(pointer_array, result)) return result;
+
+       for (i=0; i < count; i++) {
+               pointer_array[i] = &ids[i];
+       }
+       pointer_array[i] = NULL;
+
        state->ctx->status = idmap_xids_to_sids(service->idmap_ctx, mem_ctx,
-                                               count, state->ids);
+                                               pointer_array);
        if (!composite_is_ok(state->ctx)) return result;
 
        composite_done(state->ctx);
@@ -64,18 +74,19 @@ struct composite_context *wb_xids2sids_send(TALLOC_CTX *mem_ctx,
 }
 
 NTSTATUS wb_xids2sids_recv(struct composite_context *ctx,
-                          struct id_mapping **ids)
+                          struct id_map **ids)
 {
        NTSTATUS status = composite_wait(ctx);
+       struct xids2sids_state *state = talloc_get_type(ctx->private_data,
+                                                       struct xids2sids_state);
 
-       DEBUG(0, ("wb_xids2sids_recv called.\n"));
+       DEBUG(5, ("wb_xids2sids_recv called.\n"));
+
+       /* We don't have to mess with pointer_array on the way out, as
+        * the results are filled into the pointers the caller
+        * supplied */
+       *ids = state->ids;
 
-       if (NT_STATUS_IS_OK(status)) {
-               struct xids2sids_state *state =
-                       talloc_get_type(ctx->private_data,
-                               struct xids2sids_state);
-               *ids = state->ids;
-       }
        talloc_free(ctx);
        return status;
 }