idmap: Handle gid->SID mapping
[jelmer/samba4-debian.git] / source / winbind / wb_gid2sid.c
index 5c0b87118d1d4591bed0a046307fe6d37eb8d868..f2577029aaba2c3dec46e21ea567abecfbb49d6b 100644 (file)
@@ -25,6 +25,7 @@
 #include "smbd/service_task.h"
 #include "winbind/wb_helper.h"
 #include "libcli/security/proto.h"
+#include "winbind/idmap.h"
 
 struct gid2sid_state {
        struct composite_context *ctx;
@@ -50,10 +51,14 @@ struct composite_context *wb_gid2sid_send(TALLOC_CTX *mem_ctx,
        result->private_data = state;
        state->service = service;
 
-       /* FIXME: This is a stub so far.
-        * We cheat by just using the gid as RID with the domain SID.*/
-       state->sid = dom_sid_add_rid(result, service->primary_sid, gid);
-       if (composite_nomem(state->sid, state->ctx)) return result;
+       state->ctx->status = idmap_gid_to_sid(service->idmap_ctx, mem_ctx, gid,
+                                             &state->sid);
+       if (NT_STATUS_EQUAL(state->ctx->status, NT_STATUS_RETRY)) {
+               state->ctx->status = idmap_gid_to_sid(service->idmap_ctx,
+                                                     mem_ctx, gid,
+                                                     &state->sid);
+       }
+       if (!composite_is_ok(state->ctx)) return result;
 
        composite_done(state->ctx);
        return result;