s4:winbind Change idmap API to match that used by the source3/ idmap subsystem
authorAndrew Bartlett <abartlet@samba.org>
Mon, 24 May 2010 04:58:07 +0000 (14:58 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 24 May 2010 13:08:57 +0000 (23:08 +1000)
This makes it much easier to write an idmap module that bridges the gap.

We should finish the change to the new API, but for the moment this
choke point works for the conversion.

Andrew Bartlett

source4/winbind/idmap.c
source4/winbind/wb_sids2xids.c
source4/winbind/wb_xids2sids.c

index 1b2d358b8b9c18a9d6fb928eac301f8f75071ed8..b5a01ae6a12c14fc319595ee605596cce91e0574 100644 (file)
@@ -613,31 +613,31 @@ failed:
  */
 
 NTSTATUS idmap_xids_to_sids(struct idmap_context *idmap_ctx,
-                           TALLOC_CTX *mem_ctx, int count,
-                           struct id_map *id)
+                           TALLOC_CTX *mem_ctx,
+                           struct id_map **id)
 {
-       int i;
-       int error_count = 0;
+       unsigned int i, error_count = 0;
        NTSTATUS status;
 
-       for (i = 0; i < count; ++i) {
+       for (i = 0; id && id[i]; i++) {
                status = idmap_xid_to_sid(idmap_ctx, mem_ctx,
-                                               &id[i].xid, &id[i].sid);
+                                               &id[i]->xid, &id[i]->sid);
                if (NT_STATUS_EQUAL(status, NT_STATUS_RETRY)) {
                        status = idmap_xid_to_sid(idmap_ctx, mem_ctx,
-                                                       &id[i].xid,
-                                                       &id[i].sid);
+                                                       &id[i]->xid,
+                                                       &id[i]->sid);
                }
                if (!NT_STATUS_IS_OK(status)) {
-                       DEBUG(1, ("idmapping xid_to_sid failed for id[%d]\n", i));
+                       DEBUG(1, ("idmapping xid_to_sid failed for id[%d]=%lu: %s\n",
+                                 i, (unsigned long)id[i]->xid.id, nt_errstr(status)));
                        error_count++;
-                       id[i].status = ID_UNMAPPED;
+                       id[i]->status = ID_UNMAPPED;
                } else {
-                       id[i].status = ID_MAPPED;
+                       id[i]->status = ID_MAPPED;
                }
        }
 
-       if (error_count == count) {
+       if (error_count == i) {
                /* Mapping did not work at all. */
                return NT_STATUS_NONE_MAPPED;
        } else if (error_count > 0) {
@@ -662,31 +662,33 @@ NTSTATUS idmap_xids_to_sids(struct idmap_context *idmap_ctx,
  */
 
 NTSTATUS idmap_sids_to_xids(struct idmap_context *idmap_ctx,
-                           TALLOC_CTX *mem_ctx, int count,
-                           struct id_map *id)
+                           TALLOC_CTX *mem_ctx,
+                           struct id_map **id)
 {
-       int i;
-       int error_count = 0;
+       unsigned int i, error_count = 0;
        NTSTATUS status;
 
-       for (i = 0; i < count; ++i) {
+       for (i = 0; id && id[i]; i++) {
                status = idmap_sid_to_xid(idmap_ctx, mem_ctx,
-                                               id[i].sid, &id[i].xid);
+                                         id[i]->sid, &id[i]->xid);
                if (NT_STATUS_EQUAL(status, NT_STATUS_RETRY)) {
                        status = idmap_sid_to_xid(idmap_ctx, mem_ctx,
-                                                       id[i].sid,
-                                                       &id[i].xid);
+                                                 id[i]->sid,
+                                                 &id[i]->xid);
                }
                if (!NT_STATUS_IS_OK(status)) {
-                       DEBUG(1, ("idmapping sid_to_xid failed for id[%d]\n", i));
+                       char *str = dom_sid_string(mem_ctx, id[i]->sid);
+                       DEBUG(1, ("idmapping sid_to_xid failed for id[%d]=%s: %s\n",
+                                 i, str, nt_errstr(status)));
+                       talloc_free(str);
                        error_count++;
-                       id[i].status = ID_UNMAPPED;
+                       id[i]->status = ID_UNMAPPED;
                } else {
-                       id[i].status = ID_MAPPED;
+                       id[i]->status = ID_MAPPED;
                }
        }
 
-       if (error_count == count) {
+       if (error_count == i) {
                /* Mapping did not work at all. */
                return NT_STATUS_NONE_MAPPED;
        } else if (error_count > 0) {
index 617318ce52480a4b7d15ae533f2564d664b91e41..c966c40dc07900d84ce1cf5f00050bc836a83d8b 100644 (file)
@@ -33,10 +33,12 @@ struct sids2xids_state {
 
 struct composite_context *wb_sids2xids_send(TALLOC_CTX *mem_ctx,
                                            struct wbsrv_service *service,
-                                           int count, struct id_map *ids)
+                                           unsigned int count, struct id_map *ids)
 {
        struct composite_context *result;
        struct sids2xids_state *state;
+       struct id_map **pointer_array;
+       unsigned int i;
 
        DEBUG(5, ("wb_sids2xids_send called\n"));
 
@@ -52,8 +54,19 @@ struct composite_context *wb_sids2xids_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_sids_to_xids(service->idmap_ctx, mem_ctx,
-                                               count, state->ids);
+                                               pointer_array);
        if (!composite_is_ok(state->ctx)) return result;
 
        composite_done(state->ctx);
@@ -69,6 +82,9 @@ NTSTATUS wb_sids2xids_recv(struct composite_context *ctx,
 
        DEBUG(5, ("wb_sids2xids_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;
 
        talloc_free(ctx);
index 9d95ac012cc89a3876529b73376053dffca40098..aeec2ee5be6202da7a15576c4df3f2df734f8b89 100644 (file)
@@ -33,10 +33,12 @@ struct xids2sids_state {
 
 struct composite_context *wb_xids2sids_send(TALLOC_CTX *mem_ctx,
                                            struct wbsrv_service *service,
-                                           int count, struct id_map *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(5, ("wb_xids2sids_send called\n"));
 
@@ -52,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);
@@ -69,6 +82,9 @@ NTSTATUS wb_xids2sids_recv(struct composite_context *ctx,
 
        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;
 
        talloc_free(ctx);