w3:winbind: Convert WINBINDD_LOOKUPRIDS to the new API
authorVolker Lendecke <vl@samba.org>
Thu, 27 Aug 2009 15:11:24 +0000 (17:11 +0200)
committerVolker Lendecke <vl@samba.org>
Sat, 29 Aug 2009 17:42:26 +0000 (19:42 +0200)
16 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/winbindd.c
source3/winbindd/winbindd_async.c
source3/winbindd/winbindd_domain.c
source3/winbindd/winbindd_dual_srv.c
source3/winbindd/winbindd_lookuprids.c [new file with mode: 0644]
source3/winbindd/winbindd_proto.h
source3/winbindd/winbindd_sid.c

index ac1b705b62c5652886df10c913ae526d691ebf64..6febc971a197ae7b0f37fb3eaecbbdf2c75cba34 100644 (file)
@@ -1199,6 +1199,7 @@ WINBINDD_OBJ1 = \
                winbindd/winbindd_getgrgid.o \
                winbindd/winbindd_getgrnam.o \
                winbindd/winbindd_getusersids.o \
+               winbindd/winbindd_lookuprids.o \
                winbindd/winbindd_setpwent.o \
                winbindd/winbindd_getpwent.o \
                winbindd/winbindd_endpwent.o \
index 3b38a4d43dca96fa5224c3e10181ab1c76c09a3c..55f3b3a5f7aeb83f37d7305f218cb705b111e4c1 100644 (file)
@@ -2297,3 +2297,164 @@ NTSTATUS rpccli_wbint_DsGetDcName(struct rpc_pipe_client *cli,
        return r.out.result;
 }
 
+struct rpccli_wbint_LookupRids_state {
+       struct wbint_LookupRids orig;
+       struct wbint_LookupRids tmp;
+       TALLOC_CTX *out_mem_ctx;
+       NTSTATUS (*dispatch_recv)(struct tevent_req *req, TALLOC_CTX *mem_ctx);
+};
+
+static void rpccli_wbint_LookupRids_done(struct tevent_req *subreq);
+
+struct tevent_req *rpccli_wbint_LookupRids_send(TALLOC_CTX *mem_ctx,
+                                               struct tevent_context *ev,
+                                               struct rpc_pipe_client *cli,
+                                               struct wbint_RidArray *_rids /* [in] [ref] */,
+                                               struct wbint_Principals *_names /* [out] [ref] */)
+{
+       struct tevent_req *req;
+       struct rpccli_wbint_LookupRids_state *state;
+       struct tevent_req *subreq;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct rpccli_wbint_LookupRids_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       state->out_mem_ctx = NULL;
+       state->dispatch_recv = cli->dispatch_recv;
+
+       /* In parameters */
+       state->orig.in.rids = _rids;
+
+       /* Out parameters */
+       state->orig.out.names = _names;
+
+       /* Result */
+       ZERO_STRUCT(state->orig.out.result);
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_IN_DEBUG(wbint_LookupRids, &state->orig);
+       }
+
+       state->out_mem_ctx = talloc_named_const(state, 0,
+                            "rpccli_wbint_LookupRids_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_LOOKUPRIDS,
+                                   &state->tmp);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, rpccli_wbint_LookupRids_done, req);
+       return req;
+}
+
+static void rpccli_wbint_LookupRids_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct rpccli_wbint_LookupRids_state *state = tevent_req_data(
+               req, struct rpccli_wbint_LookupRids_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.names = *state->tmp.out.names;
+
+       /* 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_LookupRids, &state->orig);
+       }
+
+       tevent_req_done(req);
+}
+
+NTSTATUS rpccli_wbint_LookupRids_recv(struct tevent_req *req,
+                                     TALLOC_CTX *mem_ctx,
+                                     NTSTATUS *result)
+{
+       struct rpccli_wbint_LookupRids_state *state = tevent_req_data(
+               req, struct rpccli_wbint_LookupRids_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_LookupRids(struct rpc_pipe_client *cli,
+                                TALLOC_CTX *mem_ctx,
+                                struct wbint_RidArray *rids /* [in] [ref] */,
+                                struct wbint_Principals *names /* [out] [ref] */)
+{
+       struct wbint_LookupRids r;
+       NTSTATUS status;
+
+       /* In parameters */
+       r.in.rids = rids;
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_IN_DEBUG(wbint_LookupRids, &r);
+       }
+
+       status = cli->dispatch(cli,
+                               mem_ctx,
+                               &ndr_table_wbint,
+                               NDR_WBINT_LOOKUPRIDS,
+                               &r);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_OUT_DEBUG(wbint_LookupRids, &r);
+       }
+
+       if (NT_STATUS_IS_ERR(status)) {
+               return status;
+       }
+
+       /* Return variables */
+       *names = *r.out.names;
+
+       /* Return result */
+       return r.out.result;
+}
+
index 148870dcf0faf3a0d58025d83fb7924666457aea..7f8cb12edd5fb3bffcd5dd59b1cea0eade609acd 100644 (file)
@@ -190,4 +190,16 @@ NTSTATUS rpccli_wbint_DsGetDcName(struct rpc_pipe_client *cli,
                                  const char *site_name /* [in] [unique,charset(UTF8)] */,
                                  uint32_t flags /* [in]  */,
                                  struct netr_DsRGetDCNameInfo **dc_info /* [out] [ref] */);
+struct tevent_req *rpccli_wbint_LookupRids_send(TALLOC_CTX *mem_ctx,
+                                               struct tevent_context *ev,
+                                               struct rpc_pipe_client *cli,
+                                               struct wbint_RidArray *_rids /* [in] [ref] */,
+                                               struct wbint_Principals *_names /* [out] [ref] */);
+NTSTATUS rpccli_wbint_LookupRids_recv(struct tevent_req *req,
+                                     TALLOC_CTX *mem_ctx,
+                                     NTSTATUS *result);
+NTSTATUS rpccli_wbint_LookupRids(struct rpc_pipe_client *cli,
+                                TALLOC_CTX *mem_ctx,
+                                struct wbint_RidArray *rids /* [in] [ref] */,
+                                struct wbint_Principals *names /* [out] [ref] */);
 #endif /* __CLI_WBINT__ */
index 8f07349d7afcbd01d0bf7a30ad5473f4dbbe1544..681d1da492eed7aeff449c2fda5f4feaa922bb3f 100644 (file)
@@ -1851,6 +1851,83 @@ _PUBLIC_ void ndr_print_wbint_DsGetDcName(struct ndr_print *ndr, const char *nam
        ndr->depth--;
 }
 
+static enum ndr_err_code ndr_push_wbint_LookupRids(struct ndr_push *ndr, int flags, const struct wbint_LookupRids *r)
+{
+       if (flags & NDR_IN) {
+               if (r->in.rids == NULL) {
+                       return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer");
+               }
+               NDR_CHECK(ndr_push_wbint_RidArray(ndr, NDR_SCALARS, r->in.rids));
+       }
+       if (flags & NDR_OUT) {
+               if (r->out.names == NULL) {
+                       return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer");
+               }
+               NDR_CHECK(ndr_push_wbint_Principals(ndr, NDR_SCALARS|NDR_BUFFERS, r->out.names));
+               NDR_CHECK(ndr_push_NTSTATUS(ndr, NDR_SCALARS, r->out.result));
+       }
+       return NDR_ERR_SUCCESS;
+}
+
+static enum ndr_err_code ndr_pull_wbint_LookupRids(struct ndr_pull *ndr, int flags, struct wbint_LookupRids *r)
+{
+       TALLOC_CTX *_mem_save_rids_0;
+       TALLOC_CTX *_mem_save_names_0;
+       if (flags & NDR_IN) {
+               ZERO_STRUCT(r->out);
+
+               if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {
+                       NDR_PULL_ALLOC(ndr, r->in.rids);
+               }
+               _mem_save_rids_0 = NDR_PULL_GET_MEM_CTX(ndr);
+               NDR_PULL_SET_MEM_CTX(ndr, r->in.rids, LIBNDR_FLAG_REF_ALLOC);
+               NDR_CHECK(ndr_pull_wbint_RidArray(ndr, NDR_SCALARS, r->in.rids));
+               NDR_PULL_SET_MEM_CTX(ndr, _mem_save_rids_0, LIBNDR_FLAG_REF_ALLOC);
+               NDR_PULL_ALLOC(ndr, r->out.names);
+               ZERO_STRUCTP(r->out.names);
+       }
+       if (flags & NDR_OUT) {
+               if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {
+                       NDR_PULL_ALLOC(ndr, r->out.names);
+               }
+               _mem_save_names_0 = NDR_PULL_GET_MEM_CTX(ndr);
+               NDR_PULL_SET_MEM_CTX(ndr, r->out.names, LIBNDR_FLAG_REF_ALLOC);
+               NDR_CHECK(ndr_pull_wbint_Principals(ndr, NDR_SCALARS|NDR_BUFFERS, r->out.names));
+               NDR_PULL_SET_MEM_CTX(ndr, _mem_save_names_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_LookupRids(struct ndr_print *ndr, const char *name, int flags, const struct wbint_LookupRids *r)
+{
+       ndr_print_struct(ndr, name, "wbint_LookupRids");
+       ndr->depth++;
+       if (flags & NDR_SET_VALUES) {
+               ndr->flags |= LIBNDR_PRINT_SET_VALUES;
+       }
+       if (flags & NDR_IN) {
+               ndr_print_struct(ndr, "in", "wbint_LookupRids");
+               ndr->depth++;
+               ndr_print_ptr(ndr, "rids", r->in.rids);
+               ndr->depth++;
+               ndr_print_wbint_RidArray(ndr, "rids", r->in.rids);
+               ndr->depth--;
+               ndr->depth--;
+       }
+       if (flags & NDR_OUT) {
+               ndr_print_struct(ndr, "out", "wbint_LookupRids");
+               ndr->depth++;
+               ndr_print_ptr(ndr, "names", r->out.names);
+               ndr->depth++;
+               ndr_print_wbint_Principals(ndr, "names", r->out.names);
+               ndr->depth--;
+               ndr_print_NTSTATUS(ndr, "result", r->out.result);
+               ndr->depth--;
+       }
+       ndr->depth--;
+}
+
 static const struct ndr_interface_call wbint_calls[] = {
        {
                "wbint_Ping",
@@ -1964,6 +2041,14 @@ static const struct ndr_interface_call wbint_calls[] = {
                (ndr_print_function_t) ndr_print_wbint_DsGetDcName,
                false,
        },
+       {
+               "wbint_LookupRids",
+               sizeof(struct wbint_LookupRids),
+               (ndr_push_flags_fn_t) ndr_push_wbint_LookupRids,
+               (ndr_pull_flags_fn_t) ndr_pull_wbint_LookupRids,
+               (ndr_print_function_t) ndr_print_wbint_LookupRids,
+               false,
+       },
        { NULL, 0, NULL, NULL, NULL, false }
 };
 
@@ -1993,7 +2078,7 @@ const struct ndr_interface_table ndr_table_wbint = {
                NDR_WBINT_VERSION
        },
        .helpstring     = NDR_WBINT_HELPSTRING,
-       .num_calls      = 14,
+       .num_calls      = 15,
        .calls          = wbint_calls,
        .endpoints      = &wbint_endpoints,
        .authservices   = &wbint_authservices
index 4b3096cb577de485a4c52472276a4f49edf80cdc..d183e348e6ed68a7b9c8c46b0ce53d5111eeb34a 100644 (file)
@@ -39,7 +39,9 @@ extern const struct ndr_interface_table ndr_table_wbint;
 
 #define NDR_WBINT_DSGETDCNAME (0x0d)
 
-#define NDR_WBINT_CALL_COUNT (14)
+#define NDR_WBINT_LOOKUPRIDS (0x0e)
+
+#define NDR_WBINT_CALL_COUNT (15)
 enum ndr_err_code ndr_push_wbint_userinfo(struct ndr_push *ndr, int ndr_flags, const struct wbint_userinfo *r);
 enum ndr_err_code ndr_pull_wbint_userinfo(struct ndr_pull *ndr, int ndr_flags, struct wbint_userinfo *r);
 void ndr_print_wbint_userinfo(struct ndr_print *ndr, const char *name, const struct wbint_userinfo *r);
@@ -72,4 +74,5 @@ void ndr_print_wbint_QuerySequenceNumber(struct ndr_print *ndr, const char *name
 void ndr_print_wbint_LookupGroupMembers(struct ndr_print *ndr, const char *name, int flags, const struct wbint_LookupGroupMembers *r);
 void ndr_print_wbint_QueryUserList(struct ndr_print *ndr, const char *name, int flags, const struct wbint_QueryUserList *r);
 void ndr_print_wbint_DsGetDcName(struct ndr_print *ndr, const char *name, int flags, const struct wbint_DsGetDcName *r);
+void ndr_print_wbint_LookupRids(struct ndr_print *ndr, const char *name, int flags, const struct wbint_LookupRids *r);
 #endif /* _HEADER_NDR_wbint */
index 5dbd6474b6282c5ec3144ffcb6297922faab7202..2cc750c4b57d741dd5403d2b8fdb46342008eba1 100644 (file)
@@ -1144,6 +1144,86 @@ static bool api_wbint_DsGetDcName(pipes_struct *p)
        return true;
 }
 
+static bool api_wbint_LookupRids(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_LookupRids *r;
+
+       call = &ndr_table_wbint.calls[NDR_WBINT_LOOKUPRIDS];
+
+       r = talloc(talloc_tos(), struct wbint_LookupRids);
+       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_LookupRids, r);
+       }
+
+       ZERO_STRUCT(r->out);
+       r->out.names = talloc_zero(r, struct wbint_Principals);
+       if (r->out.names == NULL) {
+               talloc_free(r);
+               return false;
+       }
+
+       r->out.result = _wbint_LookupRids(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_LookupRids, 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[] =
@@ -1162,6 +1242,7 @@ static struct api_struct api_wbint_cmds[] =
        {"WBINT_LOOKUPGROUPMEMBERS", NDR_WBINT_LOOKUPGROUPMEMBERS, api_wbint_LookupGroupMembers},
        {"WBINT_QUERYUSERLIST", NDR_WBINT_QUERYUSERLIST, api_wbint_QueryUserList},
        {"WBINT_DSGETDCNAME", NDR_WBINT_DSGETDCNAME, api_wbint_DsGetDcName},
+       {"WBINT_LOOKUPRIDS", NDR_WBINT_LOOKUPRIDS, api_wbint_LookupRids},
 };
 
 void wbint_get_pipe_fns(struct api_struct **fns, int *n_fns)
@@ -1361,6 +1442,18 @@ NTSTATUS rpc_wbint_dispatch(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, co
                        return NT_STATUS_OK;
                }
 
+               case NDR_WBINT_LOOKUPRIDS: {
+                       struct wbint_LookupRids *r = (struct wbint_LookupRids *)_r;
+                       ZERO_STRUCT(r->out);
+                       r->out.names = talloc_zero(mem_ctx, struct wbint_Principals);
+                       if (r->out.names == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+                       }
+
+                       r->out.result = _wbint_LookupRids(cli->pipes_struct, r);
+                       return NT_STATUS_OK;
+               }
+
                default:
                        return NT_STATUS_NOT_IMPLEMENTED;
        }
index a6dbd402653912b6aa84dd220a9c29773a49145d..1203a3f26ed9d322b239205a870ce4452bd26ea4 100644 (file)
@@ -15,6 +15,7 @@ NTSTATUS _wbint_QuerySequenceNumber(pipes_struct *p, struct wbint_QuerySequenceN
 NTSTATUS _wbint_LookupGroupMembers(pipes_struct *p, struct wbint_LookupGroupMembers *r);
 NTSTATUS _wbint_QueryUserList(pipes_struct *p, struct wbint_QueryUserList *r);
 NTSTATUS _wbint_DsGetDcName(pipes_struct *p, struct wbint_DsGetDcName *r);
+NTSTATUS _wbint_LookupRids(pipes_struct *p, struct wbint_LookupRids *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);
@@ -31,5 +32,6 @@ NTSTATUS _wbint_QuerySequenceNumber(pipes_struct *p, struct wbint_QuerySequenceN
 NTSTATUS _wbint_LookupGroupMembers(pipes_struct *p, struct wbint_LookupGroupMembers *r);
 NTSTATUS _wbint_QueryUserList(pipes_struct *p, struct wbint_QueryUserList *r);
 NTSTATUS _wbint_DsGetDcName(pipes_struct *p, struct wbint_DsGetDcName *r);
+NTSTATUS _wbint_LookupRids(pipes_struct *p, struct wbint_LookupRids *r);
 NTSTATUS rpc_wbint_init(void);
 #endif /* __SRV_WBINT__ */
index 31eaae2645786c0f875c0877d09cf255f1638b1f..ddea95b7fe2cade5813dbbde3cfc690cffa63d2a 100644 (file)
@@ -230,4 +230,17 @@ struct wbint_DsGetDcName {
 
 };
 
+
+struct wbint_LookupRids {
+       struct {
+               struct wbint_RidArray *rids;/* [ref] */
+       } in;
+
+       struct {
+               struct wbint_Principals *names;/* [ref] */
+               NTSTATUS result;
+       } out;
+
+};
+
 #endif /* _HEADER_wbint */
index fbbe5ef118819d2e86bad928f3e02fd75aab65cf..ab258c583270afe9a8d0f0b606c59f273ba9e411 100644 (file)
@@ -126,4 +126,9 @@ interface wbint
        [in]                                    uint32 flags,
        [out]                                   netr_DsRGetDCNameInfo **dc_info
        );
+
+    NTSTATUS wbint_LookupRids(
+       [in] wbint_RidArray *rids,
+       [out] wbint_Principals *names
+       );
 }
\ No newline at end of file
index a57412ab1480d12114e1517bf12ce300e31e0f44..10538d3f21b0b2006bf400330ecc6f64ce90e650 100644 (file)
@@ -447,10 +447,6 @@ static struct winbindd_dispatch_table {
        { WINBINDD_LIST_TRUSTDOM, winbindd_list_trusted_domains,
          "LIST_TRUSTDOM" },
 
-       /* SID related functions */
-
-       { WINBINDD_LOOKUPRIDS, winbindd_lookuprids, "LOOKUPRIDS" },
-
        /* Lookup related functions */
 
        { WINBINDD_ALLOCATE_UID, winbindd_allocate_uid, "ALLOCATE_UID" },
@@ -530,6 +526,8 @@ static struct winbindd_async_dispatch_table async_nonpriv_table[] = {
          winbindd_getgrnam_send, winbindd_getgrnam_recv },
        { WINBINDD_GETUSERSIDS, "GETUSERSIDS",
          winbindd_getusersids_send, winbindd_getusersids_recv },
+       { WINBINDD_LOOKUPRIDS, "LOOKUPRIDS",
+         winbindd_lookuprids_send, winbindd_lookuprids_recv },
        { WINBINDD_SETPWENT, "SETPWENT",
          winbindd_setpwent_send, winbindd_setpwent_recv },
        { WINBINDD_GETPWENT, "GETPWENT",
index d16a1f82885a2212d39568c328f626207e409cf9..1e63ed1fec82d449d80f6b5f5b2d641b7383cfce 100644 (file)
@@ -694,64 +694,6 @@ static bool parse_ridlist(TALLOC_CTX *mem_ctx, char *ridstr,
        return True;
 }
 
-enum winbindd_result winbindd_dual_lookuprids(struct winbindd_domain *domain,
-                                             struct winbindd_cli_state *state)
-{
-       uint32 *rids = NULL;
-       size_t i, buflen, num_rids = 0;
-       ssize_t len;
-       DOM_SID domain_sid;
-       char *domain_name;
-       char **names;
-       enum lsa_SidType *types;
-       NTSTATUS status;
-       char *result;
-
-       DEBUG(10, ("Looking up RIDs for domain %s (%s)\n",
-                  state->request->domain_name,
-                  state->request->data.sid));
-
-       if (!parse_ridlist(state->mem_ctx, state->request->extra_data.data,
-                          &rids, &num_rids)) {
-               DEBUG(5, ("Could not parse ridlist\n"));
-               return WINBINDD_ERROR;
-       }
-
-       if (!string_to_sid(&domain_sid, state->request->data.sid)) {
-               DEBUG(5, ("Could not parse domain sid %s\n",
-                         state->request->data.sid));
-               return WINBINDD_ERROR;
-       }
-
-       status = domain->methods->rids_to_names(domain, state->mem_ctx,
-                                               &domain_sid, rids, num_rids,
-                                               &domain_name,
-                                               &names, &types);
-
-       if (!NT_STATUS_IS_OK(status) &&
-           !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
-               return WINBINDD_ERROR;
-       }
-
-       len = 0;
-       buflen = 0;
-       result = NULL;
-
-       for (i=0; i<num_rids; i++) {
-               sprintf_append(state->mem_ctx, &result, &len, &buflen,
-                              "%d %s\n", types[i], names[i]);
-       }
-
-       fstrcpy(state->response->data.domain_name, domain_name);
-
-       if (result != NULL) {
-               state->response->extra_data.data = result;
-               state->response->length += len+1;
-       }
-
-       return WINBINDD_OK;
-}
-
 static void getsidaliases_recv(TALLOC_CTX *mem_ctx, bool success,
                               struct winbindd_response *response,
                               void *c, void *private_data)
index eb4e131259f02334899f0430cffae284139ca030..14376c62bf0725329c0d812fcef7eca25da747d0 100644 (file)
@@ -49,10 +49,6 @@ static const struct winbindd_child_dispatch_table domain_dispatch_table[] = {
                .name           = "LOOKUPNAME",
                .struct_cmd     = WINBINDD_LOOKUPNAME,
                .struct_fn      = winbindd_dual_lookupname,
-       },{
-               .name           = "LOOKUPRIDS",
-               .struct_cmd     = WINBINDD_LOOKUPRIDS,
-               .struct_fn      = winbindd_dual_lookuprids,
        },{
                .name           = "LIST_USERS",
                .struct_cmd     = WINBINDD_LIST_USERS,
index 6b1a4b36155a3f6ba488e04cefe6916ada3f3c51..b46b3d511e01ffed66f8b4f795f57daadcec7ced 100644 (file)
@@ -289,3 +289,43 @@ done:
 
        return status;
 }
+
+NTSTATUS _wbint_LookupRids(pipes_struct *p, struct wbint_LookupRids *r)
+{
+       struct winbindd_domain *domain = wb_child_domain();
+       char *domain_name;
+       char **names;
+       enum lsa_SidType *types;
+       struct wbint_Principal *result;
+       NTSTATUS status;
+       int i;
+
+       if (domain == NULL) {
+               return NT_STATUS_REQUEST_NOT_ACCEPTED;
+       }
+
+       status = domain->methods->rids_to_names(
+               domain, talloc_tos(), &domain->sid, r->in.rids->rids,
+               r->in.rids->num_rids, &domain_name, &names, &types);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       result = talloc_array(p->mem_ctx, struct wbint_Principal,
+                             r->in.rids->num_rids);
+       if (result == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       for (i=0; i<r->in.rids->num_rids; i++) {
+               sid_compose(&result[i].sid, &domain->sid, r->in.rids->rids[i]);
+               result[i].type = types[i];
+               result[i].name = talloc_move(result, &names[i]);
+       }
+       TALLOC_FREE(types);
+       TALLOC_FREE(names);
+
+       r->out.names->num_principals = r->in.rids->num_rids;
+       r->out.names->principals = result;
+       return NT_STATUS_OK;
+}
diff --git a/source3/winbindd/winbindd_lookuprids.c b/source3/winbindd/winbindd_lookuprids.c
new file mode 100644 (file)
index 0000000..f2cb879
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+   Unix SMB/CIFS implementation.
+   async implementation of WINBINDD_LOOKUPRIDS
+   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 winbindd_lookuprids_state {
+       struct tevent_context *ev;
+       const char *domain_name;
+       struct wbint_RidArray rids;
+       struct wbint_Principals names;
+};
+
+static bool parse_ridlist(TALLOC_CTX *mem_ctx, char *ridstr,
+                         uint32_t **prids, uint32_t *pnum_rids);
+
+static void winbindd_lookuprids_done(struct tevent_req *subreq);
+
+struct tevent_req *winbindd_lookuprids_send(TALLOC_CTX *mem_ctx,
+                                           struct tevent_context *ev,
+                                           struct winbindd_cli_state *cli,
+                                           struct winbindd_request *request)
+{
+       struct tevent_req *req, *subreq;
+       struct winbindd_lookuprids_state *state;
+       struct winbindd_domain *domain;
+       struct dom_sid sid;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct winbindd_lookuprids_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       state->ev = ev;
+
+       /* Ensure null termination */
+       request->data.sid[sizeof(request->data.sid)-1]='\0';
+
+       DEBUG(3, ("lookuprids (%s)\n", request->data.sid));
+
+       if (!string_to_sid(&sid, request->data.sid)) {
+               DEBUG(5, ("%s not a SID\n", request->data.sid));
+               tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+               return tevent_req_post(req, ev);
+       }
+
+       domain = find_domain_from_sid_noinit(&sid);
+       if (domain == NULL) {
+               DEBUG(5, ("Domain for sid %s not found\n",
+                         sid_string_dbg(&sid)));
+               tevent_req_nterror(req, NT_STATUS_NO_SUCH_DOMAIN);
+               return tevent_req_post(req, ev);
+       }
+
+       if (request->extra_data.data[request->extra_len-1] != '\0') {
+               DEBUG(5, ("extra_data not 0-terminated\n"));
+               tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+               return tevent_req_post(req, ev);
+       }
+
+       if (!parse_ridlist(state, request->extra_data.data,
+                          &state->rids.rids, &state->rids.num_rids)) {
+               DEBUG(5, ("parse_ridlist failed\n"));
+               tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+               return tevent_req_post(req, ev);
+       }
+
+       subreq = rpccli_wbint_LookupRids_send(
+               state, ev, domain->child.rpccli, &state->rids, &state->names);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, winbindd_lookuprids_done, req);
+       return req;
+}
+
+static void winbindd_lookuprids_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct winbindd_lookuprids_state *state = tevent_req_data(
+               req, struct winbindd_lookuprids_state);
+       NTSTATUS status, result;
+
+       status = rpccli_wbint_LookupRids_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 winbindd_lookuprids_recv(struct tevent_req *req,
+                                 struct winbindd_response *response)
+{
+       struct winbindd_lookuprids_state *state = tevent_req_data(
+               req, struct winbindd_lookuprids_state);
+       NTSTATUS status;
+       char *result;
+       int i;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               DEBUG(5, ("Lookuprids failed: %s\n",nt_errstr(status)));
+               return status;
+       }
+
+       result = talloc_strdup(response, "");
+       if (result == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       for (i=0; i<state->names.num_principals; i++) {
+               struct wbint_Principal *p = &state->names.principals[i];
+
+               result = talloc_asprintf_append_buffer(
+                       result, "%d %s\n", (int)p->type, p->name);
+               if (result == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+       }
+
+       fstrcpy(response->data.domain_name, state->domain_name);
+       response->extra_data.data = result;
+       response->length += talloc_get_size(result);
+       return NT_STATUS_OK;
+}
+
+static bool parse_ridlist(TALLOC_CTX *mem_ctx, char *ridstr,
+                         uint32_t **prids, uint32_t *pnum_rids)
+{
+       uint32_t i, num_rids;
+       uint32_t *rids;
+       char *p;
+
+       if (ridstr == NULL) {
+               return false;
+       }
+
+       p = ridstr;
+       num_rids = 0;
+
+       /* count rids */
+
+       while ((p = strchr(p, '\n')) != NULL) {
+               p += 1;
+               num_rids += 1;
+       }
+
+       if (num_rids == 0) {
+               *pnum_rids = 0;
+               *prids = NULL;
+               return true;
+       }
+
+       rids = talloc_array(mem_ctx, uint32_t, num_rids);
+       if (rids == NULL) {
+               return false;
+       }
+
+       p = ridstr;
+
+       for (i=0; i<num_rids; i++) {
+               char *q;
+               rids[i] = strtoul(p, &q, 10);
+               if (*q != '\n') {
+                       DEBUG(0, ("Got invalid ridstr: %s\n", p));
+                       return false;
+               }
+               p = q+1;
+       }
+
+       *pnum_rids = num_rids;
+       *prids = rids;
+       return true;
+}
index 930d48b458448593b7bf60859f181eaf3e14446c..bebfc9d9e4bf75ca8aa5a6ee03c64e1e9d0b0ee8 100644 (file)
@@ -102,8 +102,6 @@ bool print_sidlist(TALLOC_CTX *mem_ctx, const DOM_SID *sids,
                   size_t num_sids, char **result, ssize_t *len);
 bool parse_sidlist(TALLOC_CTX *mem_ctx, const char *sidstr,
                   DOM_SID **sids, size_t *num_sids);
-enum winbindd_result winbindd_dual_lookuprids(struct winbindd_domain *domain,
-                                             struct winbindd_cli_state *state);
 void winbindd_getsidaliases_async(struct winbindd_domain *domain,
                                  TALLOC_CTX *mem_ctx,
                                  const DOM_SID *sids, size_t num_sids,
@@ -848,6 +846,13 @@ struct tevent_req *winbindd_getusersids_send(TALLOC_CTX *mem_ctx,
 NTSTATUS winbindd_getusersids_recv(struct tevent_req *req,
                                   struct winbindd_response *response);
 
+struct tevent_req *winbindd_lookuprids_send(TALLOC_CTX *mem_ctx,
+                                           struct tevent_context *ev,
+                                           struct winbindd_cli_state *cli,
+                                           struct winbindd_request *request);
+NTSTATUS winbindd_lookuprids_recv(struct tevent_req *req,
+                                 struct winbindd_response *response);
+
 struct tevent_req *wb_query_user_list_send(TALLOC_CTX *mem_ctx,
                                           struct tevent_context *ev,
                                           struct winbindd_domain *domain);
index db000682ae9b299feb5840fadda97a43fdaf586d..8f09d5f7eb0e421bb34e0a431cf805e2d12ccc03 100644 (file)
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_WINBIND
 
-/* Convert a string  */
-
-void winbindd_lookuprids(struct winbindd_cli_state *state)
-{
-       struct winbindd_domain *domain;
-       DOM_SID domain_sid;
-       
-       /* Ensure null termination */
-       state->request->data.sid[sizeof(state->request->data.sid)-1]='\0';
-
-       DEBUG(10, ("lookup_rids: %s\n", state->request->data.sid));
-
-       if (!string_to_sid(&domain_sid, state->request->data.sid)) {
-               DEBUG(5, ("Could not convert %s to SID\n",
-                         state->request->data.sid));
-               request_error(state);
-               return;
-       }
-
-       domain = find_lookup_domain_from_sid(&domain_sid);
-       if (domain == NULL) {
-               DEBUG(10, ("Could not find domain for name %s\n",
-                          state->request->domain_name));
-               request_error(state);
-               return;
-       }
-
-       sendto_domain(state, domain);
-}
-
 static void set_mapping_recv(void *private_data, bool success)
 {
        struct winbindd_cli_state *state =