s3:winbind: Add async wb_gid2sid
authorVolker Lendecke <vl@samba.org>
Tue, 4 Aug 2009 18:19:03 +0000 (14:19 -0400)
committerVolker Lendecke <vl@samba.org>
Wed, 5 Aug 2009 07:21:22 +0000 (03:21 -0400)
12 files changed:
source3/Makefile.in
source3/librpc/gen_ndr/cli_wbint.c
source3/librpc/gen_ndr/cli_wbint.h
source3/librpc/gen_ndr/ndr_wbint.c
source3/librpc/gen_ndr/ndr_wbint.h
source3/librpc/gen_ndr/srv_wbint.c
source3/librpc/gen_ndr/srv_wbint.h
source3/librpc/gen_ndr/wbint.h
source3/librpc/idl/wbint.idl
source3/winbindd/wb_gid2sid.c [new file with mode: 0644]
source3/winbindd/winbindd_dual_srv.c
source3/winbindd/winbindd_proto.h

index 48f6a9ad2e6215cdd7a0539075470b9bc1b8d03d..4a872fe88557abc51009bb14573c67471322c37b 100644 (file)
@@ -1157,6 +1157,7 @@ WINBINDD_OBJ1 = \
                winbindd/wb_sid2uid.o \
                winbindd/wb_sid2gid.o \
                winbindd/wb_uid2sid.o \
+               winbindd/wb_gid2sid.o \
                winbindd/winbindd_lookupsid.o \
                winbindd/winbindd_lookupname.o \
                winbindd/winbindd_sid_to_uid.o \
index 847c937fe8f7a1cfb299ea4000a1c1439706d6df..4176e94a3fc7faf126ee67ac1f2f902b7036c2f1 100644 (file)
@@ -997,3 +997,168 @@ NTSTATUS rpccli_wbint_Uid2Sid(struct rpc_pipe_client *cli,
        return r.out.result;
 }
 
+struct rpccli_wbint_Gid2Sid_state {
+       struct wbint_Gid2Sid orig;
+       struct wbint_Gid2Sid tmp;
+       TALLOC_CTX *out_mem_ctx;
+       NTSTATUS (*dispatch_recv)(struct tevent_req *req, TALLOC_CTX *mem_ctx);
+};
+
+static void rpccli_wbint_Gid2Sid_done(struct tevent_req *subreq);
+
+struct tevent_req *rpccli_wbint_Gid2Sid_send(TALLOC_CTX *mem_ctx,
+                                            struct tevent_context *ev,
+                                            struct rpc_pipe_client *cli,
+                                            const char *_dom_name /* [in] [unique,charset(UTF8)] */,
+                                            uint64_t _gid /* [in]  */,
+                                            struct dom_sid *_sid /* [out] [ref] */)
+{
+       struct tevent_req *req;
+       struct rpccli_wbint_Gid2Sid_state *state;
+       struct tevent_req *subreq;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct rpccli_wbint_Gid2Sid_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       state->out_mem_ctx = NULL;
+       state->dispatch_recv = cli->dispatch_recv;
+
+       /* In parameters */
+       state->orig.in.dom_name = _dom_name;
+       state->orig.in.gid = _gid;
+
+       /* Out parameters */
+       state->orig.out.sid = _sid;
+
+       /* Result */
+       ZERO_STRUCT(state->orig.out.result);
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_IN_DEBUG(wbint_Gid2Sid, &state->orig);
+       }
+
+       state->out_mem_ctx = talloc_named_const(state, 0,
+                            "rpccli_wbint_Gid2Sid_out_memory");
+       if (tevent_req_nomem(state->out_mem_ctx, req)) {
+               return tevent_req_post(req, ev);
+       }
+
+       /* make a temporary copy, that we pass to the dispatch function */
+       state->tmp = state->orig;
+
+       subreq = cli->dispatch_send(state, ev, cli,
+                                   &ndr_table_wbint,
+                                   NDR_WBINT_GID2SID,
+                                   &state->tmp);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, rpccli_wbint_Gid2Sid_done, req);
+       return req;
+}
+
+static void rpccli_wbint_Gid2Sid_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct rpccli_wbint_Gid2Sid_state *state = tevent_req_data(
+               req, struct rpccli_wbint_Gid2Sid_state);
+       NTSTATUS status;
+       TALLOC_CTX *mem_ctx;
+
+       if (state->out_mem_ctx) {
+               mem_ctx = state->out_mem_ctx;
+       } else {
+               mem_ctx = state;
+       }
+
+       status = state->dispatch_recv(subreq, mem_ctx);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
+       }
+
+       /* Copy out parameters */
+       *state->orig.out.sid = *state->tmp.out.sid;
+
+       /* Copy result */
+       state->orig.out.result = state->tmp.out.result;
+
+       /* Reset temporary structure */
+       ZERO_STRUCT(state->tmp);
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_OUT_DEBUG(wbint_Gid2Sid, &state->orig);
+       }
+
+       tevent_req_done(req);
+}
+
+NTSTATUS rpccli_wbint_Gid2Sid_recv(struct tevent_req *req,
+                                  TALLOC_CTX *mem_ctx,
+                                  NTSTATUS *result)
+{
+       struct rpccli_wbint_Gid2Sid_state *state = tevent_req_data(
+               req, struct rpccli_wbint_Gid2Sid_state);
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               tevent_req_received(req);
+               return status;
+       }
+
+       /* Steal possbile out parameters to the callers context */
+       talloc_steal(mem_ctx, state->out_mem_ctx);
+
+       /* Return result */
+       *result = state->orig.out.result;
+
+       tevent_req_received(req);
+       return NT_STATUS_OK;
+}
+
+NTSTATUS rpccli_wbint_Gid2Sid(struct rpc_pipe_client *cli,
+                             TALLOC_CTX *mem_ctx,
+                             const char *dom_name /* [in] [unique,charset(UTF8)] */,
+                             uint64_t gid /* [in]  */,
+                             struct dom_sid *sid /* [out] [ref] */)
+{
+       struct wbint_Gid2Sid r;
+       NTSTATUS status;
+
+       /* In parameters */
+       r.in.dom_name = dom_name;
+       r.in.gid = gid;
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_IN_DEBUG(wbint_Gid2Sid, &r);
+       }
+
+       status = cli->dispatch(cli,
+                               mem_ctx,
+                               &ndr_table_wbint,
+                               NDR_WBINT_GID2SID,
+                               &r);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_OUT_DEBUG(wbint_Gid2Sid, &r);
+       }
+
+       if (NT_STATUS_IS_ERR(status)) {
+               return status;
+       }
+
+       /* Return variables */
+       *sid = *r.out.sid;
+
+       /* Return result */
+       return r.out.result;
+}
+
index 458e69211b8048ebeea841e69ed4ac4898b1cdbb..55fe22bd8fc66201e9dca10e57f89bb667003d54 100644 (file)
@@ -88,4 +88,18 @@ NTSTATUS rpccli_wbint_Uid2Sid(struct rpc_pipe_client *cli,
                              const char *dom_name /* [in] [unique,charset(UTF8)] */,
                              uint64_t uid /* [in]  */,
                              struct dom_sid *sid /* [out] [ref] */);
+struct tevent_req *rpccli_wbint_Gid2Sid_send(TALLOC_CTX *mem_ctx,
+                                            struct tevent_context *ev,
+                                            struct rpc_pipe_client *cli,
+                                            const char *_dom_name /* [in] [unique,charset(UTF8)] */,
+                                            uint64_t _gid /* [in]  */,
+                                            struct dom_sid *_sid /* [out] [ref] */);
+NTSTATUS rpccli_wbint_Gid2Sid_recv(struct tevent_req *req,
+                                  TALLOC_CTX *mem_ctx,
+                                  NTSTATUS *result);
+NTSTATUS rpccli_wbint_Gid2Sid(struct rpc_pipe_client *cli,
+                             TALLOC_CTX *mem_ctx,
+                             const char *dom_name /* [in] [unique,charset(UTF8)] */,
+                             uint64_t gid /* [in]  */,
+                             struct dom_sid *sid /* [out] [ref] */);
 #endif /* __CLI_WBINT__ */
index 90a4fcf883e3bba5aac639c2ae253689223fa5d0..f6e53eef96ffccae451c0c9d68acdcb28fe6532c 100644 (file)
@@ -673,6 +673,103 @@ _PUBLIC_ void ndr_print_wbint_Uid2Sid(struct ndr_print *ndr, const char *name, i
        ndr->depth--;
 }
 
+static enum ndr_err_code ndr_push_wbint_Gid2Sid(struct ndr_push *ndr, int flags, const struct wbint_Gid2Sid *r)
+{
+       if (flags & NDR_IN) {
+               NDR_CHECK(ndr_push_unique_ptr(ndr, r->in.dom_name));
+               if (r->in.dom_name) {
+                       NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(r->in.dom_name, CH_UTF8)));
+                       NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
+                       NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(r->in.dom_name, CH_UTF8)));
+                       NDR_CHECK(ndr_push_charset(ndr, NDR_SCALARS, r->in.dom_name, ndr_charset_length(r->in.dom_name, CH_UTF8), sizeof(uint8_t), CH_UTF8));
+               }
+               NDR_CHECK(ndr_push_hyper(ndr, NDR_SCALARS, r->in.gid));
+       }
+       if (flags & NDR_OUT) {
+               if (r->out.sid == NULL) {
+                       return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer");
+               }
+               NDR_CHECK(ndr_push_dom_sid(ndr, NDR_SCALARS, r->out.sid));
+               NDR_CHECK(ndr_push_NTSTATUS(ndr, NDR_SCALARS, r->out.result));
+       }
+       return NDR_ERR_SUCCESS;
+}
+
+static enum ndr_err_code ndr_pull_wbint_Gid2Sid(struct ndr_pull *ndr, int flags, struct wbint_Gid2Sid *r)
+{
+       uint32_t _ptr_dom_name;
+       TALLOC_CTX *_mem_save_dom_name_0;
+       TALLOC_CTX *_mem_save_sid_0;
+       if (flags & NDR_IN) {
+               ZERO_STRUCT(r->out);
+
+               NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_dom_name));
+               if (_ptr_dom_name) {
+                       NDR_PULL_ALLOC(ndr, r->in.dom_name);
+               } else {
+                       r->in.dom_name = NULL;
+               }
+               if (r->in.dom_name) {
+                       _mem_save_dom_name_0 = NDR_PULL_GET_MEM_CTX(ndr);
+                       NDR_PULL_SET_MEM_CTX(ndr, r->in.dom_name, 0);
+                       NDR_CHECK(ndr_pull_array_size(ndr, &r->in.dom_name));
+                       NDR_CHECK(ndr_pull_array_length(ndr, &r->in.dom_name));
+                       if (ndr_get_array_length(ndr, &r->in.dom_name) > ndr_get_array_size(ndr, &r->in.dom_name)) {
+                               return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE, "Bad array size %u should exceed array length %u", ndr_get_array_size(ndr, &r->in.dom_name), ndr_get_array_length(ndr, &r->in.dom_name));
+                       }
+                       NDR_CHECK(ndr_check_string_terminator(ndr, ndr_get_array_length(ndr, &r->in.dom_name), sizeof(uint8_t)));
+                       NDR_CHECK(ndr_pull_charset(ndr, NDR_SCALARS, &r->in.dom_name, ndr_get_array_length(ndr, &r->in.dom_name), sizeof(uint8_t), CH_UTF8));
+                       NDR_PULL_SET_MEM_CTX(ndr, _mem_save_dom_name_0, 0);
+               }
+               NDR_CHECK(ndr_pull_hyper(ndr, NDR_SCALARS, &r->in.gid));
+               NDR_PULL_ALLOC(ndr, r->out.sid);
+               ZERO_STRUCTP(r->out.sid);
+       }
+       if (flags & NDR_OUT) {
+               if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {
+                       NDR_PULL_ALLOC(ndr, r->out.sid);
+               }
+               _mem_save_sid_0 = NDR_PULL_GET_MEM_CTX(ndr);
+               NDR_PULL_SET_MEM_CTX(ndr, r->out.sid, LIBNDR_FLAG_REF_ALLOC);
+               NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, r->out.sid));
+               NDR_PULL_SET_MEM_CTX(ndr, _mem_save_sid_0, LIBNDR_FLAG_REF_ALLOC);
+               NDR_CHECK(ndr_pull_NTSTATUS(ndr, NDR_SCALARS, &r->out.result));
+       }
+       return NDR_ERR_SUCCESS;
+}
+
+_PUBLIC_ void ndr_print_wbint_Gid2Sid(struct ndr_print *ndr, const char *name, int flags, const struct wbint_Gid2Sid *r)
+{
+       ndr_print_struct(ndr, name, "wbint_Gid2Sid");
+       ndr->depth++;
+       if (flags & NDR_SET_VALUES) {
+               ndr->flags |= LIBNDR_PRINT_SET_VALUES;
+       }
+       if (flags & NDR_IN) {
+               ndr_print_struct(ndr, "in", "wbint_Gid2Sid");
+               ndr->depth++;
+               ndr_print_ptr(ndr, "dom_name", r->in.dom_name);
+               ndr->depth++;
+               if (r->in.dom_name) {
+                       ndr_print_string(ndr, "dom_name", r->in.dom_name);
+               }
+               ndr->depth--;
+               ndr_print_hyper(ndr, "gid", r->in.gid);
+               ndr->depth--;
+       }
+       if (flags & NDR_OUT) {
+               ndr_print_struct(ndr, "out", "wbint_Gid2Sid");
+               ndr->depth++;
+               ndr_print_ptr(ndr, "sid", r->out.sid);
+               ndr->depth++;
+               ndr_print_dom_sid(ndr, "sid", r->out.sid);
+               ndr->depth--;
+               ndr_print_NTSTATUS(ndr, "result", r->out.result);
+               ndr->depth--;
+       }
+       ndr->depth--;
+}
+
 static const struct ndr_interface_call wbint_calls[] = {
        {
                "wbint_Ping",
@@ -722,6 +819,14 @@ static const struct ndr_interface_call wbint_calls[] = {
                (ndr_print_function_t) ndr_print_wbint_Uid2Sid,
                false,
        },
+       {
+               "wbint_Gid2Sid",
+               sizeof(struct wbint_Gid2Sid),
+               (ndr_push_flags_fn_t) ndr_push_wbint_Gid2Sid,
+               (ndr_pull_flags_fn_t) ndr_pull_wbint_Gid2Sid,
+               (ndr_print_function_t) ndr_print_wbint_Gid2Sid,
+               false,
+       },
        { NULL, 0, NULL, NULL, NULL, false }
 };
 
@@ -751,7 +856,7 @@ const struct ndr_interface_table ndr_table_wbint = {
                NDR_WBINT_VERSION
        },
        .helpstring     = NDR_WBINT_HELPSTRING,
-       .num_calls      = 6,
+       .num_calls      = 7,
        .calls          = wbint_calls,
        .endpoints      = &wbint_endpoints,
        .authservices   = &wbint_authservices
index 169487079d2527066aeb8144740bf3e1cfa8b8dd..d8843a3c0ce8182d9b38774dddf6a1b9c61813ac 100644 (file)
@@ -23,11 +23,14 @@ extern const struct ndr_interface_table ndr_table_wbint;
 
 #define NDR_WBINT_UID2SID (0x05)
 
-#define NDR_WBINT_CALL_COUNT (6)
+#define NDR_WBINT_GID2SID (0x06)
+
+#define NDR_WBINT_CALL_COUNT (7)
 void ndr_print_wbint_Ping(struct ndr_print *ndr, const char *name, int flags, const struct wbint_Ping *r);
 void ndr_print_wbint_LookupSid(struct ndr_print *ndr, const char *name, int flags, const struct wbint_LookupSid *r);
 void ndr_print_wbint_LookupName(struct ndr_print *ndr, const char *name, int flags, const struct wbint_LookupName *r);
 void ndr_print_wbint_Sid2Uid(struct ndr_print *ndr, const char *name, int flags, const struct wbint_Sid2Uid *r);
 void ndr_print_wbint_Sid2Gid(struct ndr_print *ndr, const char *name, int flags, const struct wbint_Sid2Gid *r);
 void ndr_print_wbint_Uid2Sid(struct ndr_print *ndr, const char *name, int flags, const struct wbint_Uid2Sid *r);
+void ndr_print_wbint_Gid2Sid(struct ndr_print *ndr, const char *name, int flags, const struct wbint_Gid2Sid *r);
 #endif /* _HEADER_NDR_wbint */
index 7a76f53959d7283391c70a11a9c87ba7b7d7bfe0..a04aa8245fbd3596b0439cae1b852998f3670873 100644 (file)
@@ -504,6 +504,86 @@ static bool api_wbint_Uid2Sid(pipes_struct *p)
        return true;
 }
 
+static bool api_wbint_Gid2Sid(pipes_struct *p)
+{
+       const struct ndr_interface_call *call;
+       struct ndr_pull *pull;
+       struct ndr_push *push;
+       enum ndr_err_code ndr_err;
+       DATA_BLOB blob;
+       struct wbint_Gid2Sid *r;
+
+       call = &ndr_table_wbint.calls[NDR_WBINT_GID2SID];
+
+       r = talloc(talloc_tos(), struct wbint_Gid2Sid);
+       if (r == NULL) {
+               return false;
+       }
+
+       if (!prs_data_blob(&p->in_data.data, &blob, r)) {
+               talloc_free(r);
+               return false;
+       }
+
+       pull = ndr_pull_init_blob(&blob, r, NULL);
+       if (pull == NULL) {
+               talloc_free(r);
+               return false;
+       }
+
+       pull->flags |= LIBNDR_FLAG_REF_ALLOC;
+       ndr_err = call->ndr_pull(pull, NDR_IN, r);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               talloc_free(r);
+               return false;
+       }
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_IN_DEBUG(wbint_Gid2Sid, r);
+       }
+
+       ZERO_STRUCT(r->out);
+       r->out.sid = talloc_zero(r, struct dom_sid);
+       if (r->out.sid == NULL) {
+               talloc_free(r);
+               return false;
+       }
+
+       r->out.result = _wbint_Gid2Sid(p, r);
+
+       if (p->rng_fault_state) {
+               talloc_free(r);
+               /* Return true here, srv_pipe_hnd.c will take care */
+               return true;
+       }
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_OUT_DEBUG(wbint_Gid2Sid, r);
+       }
+
+       push = ndr_push_init_ctx(r, NULL);
+       if (push == NULL) {
+               talloc_free(r);
+               return false;
+       }
+
+       ndr_err = call->ndr_push(push, NDR_OUT, r);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               talloc_free(r);
+               return false;
+       }
+
+       blob = ndr_push_blob(push);
+       if (!prs_copy_data_in(&p->out_data.rdata, (const char *)blob.data, (uint32_t)blob.length)) {
+               talloc_free(r);
+               return false;
+       }
+
+       talloc_free(r);
+
+       return true;
+}
+
 
 /* Tables */
 static struct api_struct api_wbint_cmds[] =
@@ -514,6 +594,7 @@ static struct api_struct api_wbint_cmds[] =
        {"WBINT_SID2UID", NDR_WBINT_SID2UID, api_wbint_Sid2Uid},
        {"WBINT_SID2GID", NDR_WBINT_SID2GID, api_wbint_Sid2Gid},
        {"WBINT_UID2SID", NDR_WBINT_UID2SID, api_wbint_Uid2Sid},
+       {"WBINT_GID2SID", NDR_WBINT_GID2SID, api_wbint_Gid2Sid},
 };
 
 void wbint_get_pipe_fns(struct api_struct **fns, int *n_fns)
@@ -617,6 +698,18 @@ NTSTATUS rpc_wbint_dispatch(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, co
                        return NT_STATUS_OK;
                }
 
+               case NDR_WBINT_GID2SID: {
+                       struct wbint_Gid2Sid *r = (struct wbint_Gid2Sid *)_r;
+                       ZERO_STRUCT(r->out);
+                       r->out.sid = talloc_zero(mem_ctx, struct dom_sid);
+                       if (r->out.sid == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+                       }
+
+                       r->out.result = _wbint_Gid2Sid(cli->pipes_struct, r);
+                       return NT_STATUS_OK;
+               }
+
                default:
                        return NT_STATUS_NOT_IMPLEMENTED;
        }
index d1141b0a0262e05ed9941124c9cd7edd416e44b6..9311e6b6415fce5a535920a374c4dfd482caefd3 100644 (file)
@@ -7,6 +7,7 @@ NTSTATUS _wbint_LookupName(pipes_struct *p, struct wbint_LookupName *r);
 NTSTATUS _wbint_Sid2Uid(pipes_struct *p, struct wbint_Sid2Uid *r);
 NTSTATUS _wbint_Sid2Gid(pipes_struct *p, struct wbint_Sid2Gid *r);
 NTSTATUS _wbint_Uid2Sid(pipes_struct *p, struct wbint_Uid2Sid *r);
+NTSTATUS _wbint_Gid2Sid(pipes_struct *p, struct wbint_Gid2Sid *r);
 void wbint_get_pipe_fns(struct api_struct **fns, int *n_fns);
 NTSTATUS rpc_wbint_dispatch(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, const struct ndr_interface_table *table, uint32_t opnum, void *r);
 void _wbint_Ping(pipes_struct *p, struct wbint_Ping *r);
@@ -15,5 +16,6 @@ NTSTATUS _wbint_LookupName(pipes_struct *p, struct wbint_LookupName *r);
 NTSTATUS _wbint_Sid2Uid(pipes_struct *p, struct wbint_Sid2Uid *r);
 NTSTATUS _wbint_Sid2Gid(pipes_struct *p, struct wbint_Sid2Gid *r);
 NTSTATUS _wbint_Uid2Sid(pipes_struct *p, struct wbint_Uid2Sid *r);
+NTSTATUS _wbint_Gid2Sid(pipes_struct *p, struct wbint_Gid2Sid *r);
 NTSTATUS rpc_wbint_init(void);
 #endif /* __SRV_WBINT__ */
index 03f58c813fc78f0cb4e86a68d9559053f9738257..d6f344e5c9b40c8585f96c11d7bbd520e4b20d5f 100644 (file)
@@ -93,4 +93,18 @@ struct wbint_Uid2Sid {
 
 };
 
+
+struct wbint_Gid2Sid {
+       struct {
+               const char *dom_name;/* [unique,charset(UTF8)] */
+               uint64_t gid;
+       } in;
+
+       struct {
+               struct dom_sid *sid;/* [ref] */
+               NTSTATUS result;
+       } out;
+
+};
+
 #endif /* _HEADER_wbint */
index bc10b23f5630aa10d577a1ca9642b83b29d927e7..93627fbe075b78865592975d63c816b748cb3750 100644 (file)
@@ -47,4 +47,10 @@ interface wbint
        [in] hyper uid,
        [out] dom_sid *sid
        );
+
+    NTSTATUS wbint_Gid2Sid(
+       [in,unique,string,charset(UTF8)] char *dom_name,
+       [in] hyper gid,
+       [out] dom_sid *sid
+       );
 }
\ No newline at end of file
diff --git a/source3/winbindd/wb_gid2sid.c b/source3/winbindd/wb_gid2sid.c
new file mode 100644 (file)
index 0000000..a0ae850
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+   Unix SMB/CIFS implementation.
+   async gid2sid
+   Copyright (C) Volker Lendecke 2009
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "winbindd.h"
+#include "librpc/gen_ndr/cli_wbint.h"
+
+struct wb_gid2sid_state {
+       struct tevent_context *ev;
+       char *dom_name;
+       struct dom_sid sid;
+};
+
+static void wb_gid2sid_done(struct tevent_req *subreq);
+
+struct tevent_req *wb_gid2sid_send(TALLOC_CTX *mem_ctx,
+                                  struct tevent_context *ev,
+                                  gid_t gid)
+{
+       struct tevent_req *req, *subreq;
+       struct wb_gid2sid_state *state;
+       struct winbindd_domain *domain;
+       struct winbindd_child *child;
+       bool expired;
+
+       req = tevent_req_create(mem_ctx, &state, struct wb_gid2sid_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       if (winbindd_use_idmap_cache()
+           && idmap_cache_find_gid2sid(gid, &state->sid, &expired)) {
+
+               DEBUG(10, ("idmap_cache_find_gid2sid found %d%s\n",
+                          (int)gid, expired ? " (expired)": ""));
+
+               if (!expired || idmap_is_offline()) {
+                       if (is_null_sid(&state->sid)) {
+                               tevent_req_nterror(req,
+                                                  NT_STATUS_NONE_MAPPED);
+                       } else {
+                               tevent_req_done(req);
+                       }
+                       return tevent_req_post(req, ev);
+               }
+       }
+
+       state->dom_name = NULL;
+
+       for (domain = domain_list(); domain != NULL; domain = domain->next) {
+               if (domain->have_idmap_config
+                   && (gid >= domain->id_range_low)
+                   && (gid <= domain->id_range_high)) {
+                       state->dom_name = domain->name;
+                       break;
+               }
+       }
+
+       child = idmap_child();
+
+       subreq = rpccli_wbint_Gid2Sid_send(
+               state, ev, child->rpccli, state->dom_name,
+               gid, &state->sid);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, wb_gid2sid_done, req);
+       return req;
+}
+
+static void wb_gid2sid_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct wb_gid2sid_state *state = tevent_req_data(
+               req, struct wb_gid2sid_state);
+       NTSTATUS status, result;
+
+       status = rpccli_wbint_Gid2Sid_recv(subreq, state, &result);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
+       }
+       if (!NT_STATUS_IS_OK(result)) {
+               tevent_req_nterror(req, result);
+               return;
+       }
+       tevent_req_done(req);
+}
+
+NTSTATUS wb_gid2sid_recv(struct tevent_req *req, struct dom_sid *sid)
+{
+       struct wb_gid2sid_state *state = tevent_req_data(
+               req, struct wb_gid2sid_state);
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               return status;
+       }
+       sid_copy(sid, &state->sid);
+       return NT_STATUS_OK;
+}
index bad9cd585a1c6c0a04382630f60e30d4fce46582..35fecbd08ed071fecb11c7d4785d8c00f749a241 100644 (file)
@@ -105,3 +105,15 @@ NTSTATUS _wbint_Uid2Sid(pipes_struct *p, struct wbint_Uid2Sid *r)
        }
        return NT_STATUS_OK;
 }
+
+NTSTATUS _wbint_Gid2Sid(pipes_struct *p, struct wbint_Gid2Sid *r)
+{
+       NTSTATUS status;
+
+       status = idmap_gid_to_sid(r->in.dom_name ? r->in.dom_name : "",
+                                 r->out.sid, r->in.gid);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+       return NT_STATUS_OK;
+}
index f1fb7e0a8784ddd73132f6cfa64db3d576b90579..d8bd9845904fd94c5fa682461881f145d9e4c203 100644 (file)
@@ -670,5 +670,10 @@ struct tevent_req *winbindd_uid_to_sid_send(TALLOC_CTX *mem_ctx,
 NTSTATUS winbindd_uid_to_sid_recv(struct tevent_req *req,
                                  struct winbindd_response *response);
 
+struct tevent_req *wb_gid2sid_send(TALLOC_CTX *mem_ctx,
+                                  struct tevent_context *ev,
+                                  gid_t gid);
+NTSTATUS wb_gid2sid_recv(struct tevent_req *req, struct dom_sid *sid);
+
 
 #endif /*  _WINBINDD_PROTO_H_  */