s3:winbind: Add async wb_lookupname
authorVolker Lendecke <vl@samba.org>
Tue, 4 Aug 2009 11:22:34 +0000 (07:22 -0400)
committerVolker Lendecke <vl@samba.org>
Wed, 5 Aug 2009 07:21:20 +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_lookupname.c [new file with mode: 0644]
source3/winbindd/winbindd_dual_srv.c
source3/winbindd/winbindd_proto.h

index df37cff8ad31e5544396ba68e3044be4e9d0c059..0f97d66cada8840763e558f60a614ee84216ce74 100644 (file)
@@ -1153,6 +1153,7 @@ WINBINDD_OBJ1 = \
                winbindd/winbindd_ndr.o \
                winbindd/wb_ping.o \
                winbindd/wb_lookupsid.o \
+               winbindd/wb_lookupname.o \
                winbindd/winbindd_lookupsid.o \
                auth/token_util.o \
                ../nsswitch/libwbclient/wb_reqtrans.o \
index 491413ee76bfb4f15f30635f485e960b49f7e180..7502d5f5e483499ecba91b184829ce2da665538d 100644 (file)
@@ -328,3 +328,177 @@ NTSTATUS rpccli_wbint_LookupSid(struct rpc_pipe_client *cli,
        return r.out.result;
 }
 
+struct rpccli_wbint_LookupName_state {
+       struct wbint_LookupName orig;
+       struct wbint_LookupName tmp;
+       TALLOC_CTX *out_mem_ctx;
+       NTSTATUS (*dispatch_recv)(struct tevent_req *req, TALLOC_CTX *mem_ctx);
+};
+
+static void rpccli_wbint_LookupName_done(struct tevent_req *subreq);
+
+struct tevent_req *rpccli_wbint_LookupName_send(TALLOC_CTX *mem_ctx,
+                                               struct tevent_context *ev,
+                                               struct rpc_pipe_client *cli,
+                                               const char *_domain /* [in] [ref,charset(UTF8)] */,
+                                               const char *_name /* [in] [ref,charset(UTF8)] */,
+                                               uint32_t _flags /* [in]  */,
+                                               enum lsa_SidType *_type /* [out] [ref] */,
+                                               struct dom_sid *_sid /* [out] [ref] */)
+{
+       struct tevent_req *req;
+       struct rpccli_wbint_LookupName_state *state;
+       struct tevent_req *subreq;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct rpccli_wbint_LookupName_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       state->out_mem_ctx = NULL;
+       state->dispatch_recv = cli->dispatch_recv;
+
+       /* In parameters */
+       state->orig.in.domain = _domain;
+       state->orig.in.name = _name;
+       state->orig.in.flags = _flags;
+
+       /* Out parameters */
+       state->orig.out.type = _type;
+       state->orig.out.sid = _sid;
+
+       /* Result */
+       ZERO_STRUCT(state->orig.out.result);
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_IN_DEBUG(wbint_LookupName, &state->orig);
+       }
+
+       state->out_mem_ctx = talloc_named_const(state, 0,
+                            "rpccli_wbint_LookupName_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_LOOKUPNAME,
+                                   &state->tmp);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, rpccli_wbint_LookupName_done, req);
+       return req;
+}
+
+static void rpccli_wbint_LookupName_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct rpccli_wbint_LookupName_state *state = tevent_req_data(
+               req, struct rpccli_wbint_LookupName_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.type = *state->tmp.out.type;
+       *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_LookupName, &state->orig);
+       }
+
+       tevent_req_done(req);
+}
+
+NTSTATUS rpccli_wbint_LookupName_recv(struct tevent_req *req,
+                                     TALLOC_CTX *mem_ctx,
+                                     NTSTATUS *result)
+{
+       struct rpccli_wbint_LookupName_state *state = tevent_req_data(
+               req, struct rpccli_wbint_LookupName_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_LookupName(struct rpc_pipe_client *cli,
+                                TALLOC_CTX *mem_ctx,
+                                const char *domain /* [in] [ref,charset(UTF8)] */,
+                                const char *name /* [in] [ref,charset(UTF8)] */,
+                                uint32_t flags /* [in]  */,
+                                enum lsa_SidType *type /* [out] [ref] */,
+                                struct dom_sid *sid /* [out] [ref] */)
+{
+       struct wbint_LookupName r;
+       NTSTATUS status;
+
+       /* In parameters */
+       r.in.domain = domain;
+       r.in.name = name;
+       r.in.flags = flags;
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_IN_DEBUG(wbint_LookupName, &r);
+       }
+
+       status = cli->dispatch(cli,
+                               mem_ctx,
+                               &ndr_table_wbint,
+                               NDR_WBINT_LOOKUPNAME,
+                               &r);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_OUT_DEBUG(wbint_LookupName, &r);
+       }
+
+       if (NT_STATUS_IS_ERR(status)) {
+               return status;
+       }
+
+       /* Return variables */
+       *type = *r.out.type;
+       *sid = *r.out.sid;
+
+       /* Return result */
+       return r.out.result;
+}
+
index b79fd19a368314fbb53fced5d4956640b7dcf05e..e2cb9639703b3310fe9d2af27d14a8ec70cfc9b9 100644 (file)
@@ -28,4 +28,22 @@ NTSTATUS rpccli_wbint_LookupSid(struct rpc_pipe_client *cli,
                                enum lsa_SidType *type /* [out] [ref] */,
                                const char **domain /* [out] [ref,charset(UTF8)] */,
                                const char **name /* [out] [ref,charset(UTF8)] */);
+struct tevent_req *rpccli_wbint_LookupName_send(TALLOC_CTX *mem_ctx,
+                                               struct tevent_context *ev,
+                                               struct rpc_pipe_client *cli,
+                                               const char *_domain /* [in] [ref,charset(UTF8)] */,
+                                               const char *_name /* [in] [ref,charset(UTF8)] */,
+                                               uint32_t _flags /* [in]  */,
+                                               enum lsa_SidType *_type /* [out] [ref] */,
+                                               struct dom_sid *_sid /* [out] [ref] */);
+NTSTATUS rpccli_wbint_LookupName_recv(struct tevent_req *req,
+                                     TALLOC_CTX *mem_ctx,
+                                     NTSTATUS *result);
+NTSTATUS rpccli_wbint_LookupName(struct rpc_pipe_client *cli,
+                                TALLOC_CTX *mem_ctx,
+                                const char *domain /* [in] [ref,charset(UTF8)] */,
+                                const char *name /* [in] [ref,charset(UTF8)] */,
+                                uint32_t flags /* [in]  */,
+                                enum lsa_SidType *type /* [out] [ref] */,
+                                struct dom_sid *sid /* [out] [ref] */);
 #endif /* __CLI_WBINT__ */
index 1e8ea207b777e7e152a4519e6ee626e121dc9ea6..40554c0fd1041b8b97a9349d0cff5618b6a9689f 100644 (file)
@@ -238,6 +238,124 @@ _PUBLIC_ void ndr_print_wbint_LookupSid(struct ndr_print *ndr, const char *name,
        ndr->depth--;
 }
 
+static enum ndr_err_code ndr_push_wbint_LookupName(struct ndr_push *ndr, int flags, const struct wbint_LookupName *r)
+{
+       if (flags & NDR_IN) {
+               if (r->in.domain == NULL) {
+                       return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer");
+               }
+               NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(r->in.domain, CH_UTF8)));
+               NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
+               NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(r->in.domain, CH_UTF8)));
+               NDR_CHECK(ndr_push_charset(ndr, NDR_SCALARS, r->in.domain, ndr_charset_length(r->in.domain, CH_UTF8), sizeof(uint8_t), CH_UTF8));
+               if (r->in.name == NULL) {
+                       return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer");
+               }
+               NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(r->in.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.name, CH_UTF8)));
+               NDR_CHECK(ndr_push_charset(ndr, NDR_SCALARS, r->in.name, ndr_charset_length(r->in.name, CH_UTF8), sizeof(uint8_t), CH_UTF8));
+               NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->in.flags));
+       }
+       if (flags & NDR_OUT) {
+               if (r->out.type == NULL) {
+                       return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer");
+               }
+               NDR_CHECK(ndr_push_lsa_SidType(ndr, NDR_SCALARS, *r->out.type));
+               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_LookupName(struct ndr_pull *ndr, int flags, struct wbint_LookupName *r)
+{
+       TALLOC_CTX *_mem_save_type_0;
+       TALLOC_CTX *_mem_save_sid_0;
+       if (flags & NDR_IN) {
+               ZERO_STRUCT(r->out);
+
+               NDR_CHECK(ndr_pull_array_size(ndr, &r->in.domain));
+               NDR_CHECK(ndr_pull_array_length(ndr, &r->in.domain));
+               if (ndr_get_array_length(ndr, &r->in.domain) > ndr_get_array_size(ndr, &r->in.domain)) {
+                       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.domain), ndr_get_array_length(ndr, &r->in.domain));
+               }
+               NDR_CHECK(ndr_check_string_terminator(ndr, ndr_get_array_length(ndr, &r->in.domain), sizeof(uint8_t)));
+               NDR_CHECK(ndr_pull_charset(ndr, NDR_SCALARS, &r->in.domain, ndr_get_array_length(ndr, &r->in.domain), sizeof(uint8_t), CH_UTF8));
+               NDR_CHECK(ndr_pull_array_size(ndr, &r->in.name));
+               NDR_CHECK(ndr_pull_array_length(ndr, &r->in.name));
+               if (ndr_get_array_length(ndr, &r->in.name) > ndr_get_array_size(ndr, &r->in.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.name), ndr_get_array_length(ndr, &r->in.name));
+               }
+               NDR_CHECK(ndr_check_string_terminator(ndr, ndr_get_array_length(ndr, &r->in.name), sizeof(uint8_t)));
+               NDR_CHECK(ndr_pull_charset(ndr, NDR_SCALARS, &r->in.name, ndr_get_array_length(ndr, &r->in.name), sizeof(uint8_t), CH_UTF8));
+               NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->in.flags));
+               NDR_PULL_ALLOC(ndr, r->out.type);
+               ZERO_STRUCTP(r->out.type);
+               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.type);
+               }
+               _mem_save_type_0 = NDR_PULL_GET_MEM_CTX(ndr);
+               NDR_PULL_SET_MEM_CTX(ndr, r->out.type, LIBNDR_FLAG_REF_ALLOC);
+               NDR_CHECK(ndr_pull_lsa_SidType(ndr, NDR_SCALARS, r->out.type));
+               NDR_PULL_SET_MEM_CTX(ndr, _mem_save_type_0, LIBNDR_FLAG_REF_ALLOC);
+               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_LookupName(struct ndr_print *ndr, const char *name, int flags, const struct wbint_LookupName *r)
+{
+       ndr_print_struct(ndr, name, "wbint_LookupName");
+       ndr->depth++;
+       if (flags & NDR_SET_VALUES) {
+               ndr->flags |= LIBNDR_PRINT_SET_VALUES;
+       }
+       if (flags & NDR_IN) {
+               ndr_print_struct(ndr, "in", "wbint_LookupName");
+               ndr->depth++;
+               ndr_print_ptr(ndr, "domain", r->in.domain);
+               ndr->depth++;
+               ndr_print_string(ndr, "domain", r->in.domain);
+               ndr->depth--;
+               ndr_print_ptr(ndr, "name", r->in.name);
+               ndr->depth++;
+               ndr_print_string(ndr, "name", r->in.name);
+               ndr->depth--;
+               ndr_print_uint32(ndr, "flags", r->in.flags);
+               ndr->depth--;
+       }
+       if (flags & NDR_OUT) {
+               ndr_print_struct(ndr, "out", "wbint_LookupName");
+               ndr->depth++;
+               ndr_print_ptr(ndr, "type", r->out.type);
+               ndr->depth++;
+               ndr_print_lsa_SidType(ndr, "type", *r->out.type);
+               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",
@@ -255,6 +373,14 @@ static const struct ndr_interface_call wbint_calls[] = {
                (ndr_print_function_t) ndr_print_wbint_LookupSid,
                false,
        },
+       {
+               "wbint_LookupName",
+               sizeof(struct wbint_LookupName),
+               (ndr_push_flags_fn_t) ndr_push_wbint_LookupName,
+               (ndr_pull_flags_fn_t) ndr_pull_wbint_LookupName,
+               (ndr_print_function_t) ndr_print_wbint_LookupName,
+               false,
+       },
        { NULL, 0, NULL, NULL, NULL, false }
 };
 
@@ -284,7 +410,7 @@ const struct ndr_interface_table ndr_table_wbint = {
                NDR_WBINT_VERSION
        },
        .helpstring     = NDR_WBINT_HELPSTRING,
-       .num_calls      = 2,
+       .num_calls      = 3,
        .calls          = wbint_calls,
        .endpoints      = &wbint_endpoints,
        .authservices   = &wbint_authservices
index 9a76cddd997aae80a7677f507186745a2413243c..c2d7ad3f3acff36055a5f23b6c792aa249cb1bf9 100644 (file)
@@ -15,7 +15,10 @@ extern const struct ndr_interface_table ndr_table_wbint;
 
 #define NDR_WBINT_LOOKUPSID (0x01)
 
-#define NDR_WBINT_CALL_COUNT (2)
+#define NDR_WBINT_LOOKUPNAME (0x02)
+
+#define NDR_WBINT_CALL_COUNT (3)
 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);
 #endif /* _HEADER_NDR_wbint */
index 85ebf5dd3adcf442e3852b1f221d42cc9a8da924..25e32460042ffc5a14d95f6f74439c8bce741983 100644 (file)
@@ -178,12 +178,99 @@ static bool api_wbint_LookupSid(pipes_struct *p)
        return true;
 }
 
+static bool api_wbint_LookupName(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_LookupName *r;
+
+       call = &ndr_table_wbint.calls[NDR_WBINT_LOOKUPNAME];
+
+       r = talloc(talloc_tos(), struct wbint_LookupName);
+       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_LookupName, r);
+       }
+
+       ZERO_STRUCT(r->out);
+       r->out.type = talloc_zero(r, enum lsa_SidType);
+       if (r->out.type == NULL) {
+               talloc_free(r);
+               return false;
+       }
+
+       r->out.sid = talloc_zero(r, struct dom_sid);
+       if (r->out.sid == NULL) {
+               talloc_free(r);
+               return false;
+       }
+
+       r->out.result = _wbint_LookupName(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_LookupName, 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[] =
 {
        {"WBINT_PING", NDR_WBINT_PING, api_wbint_Ping},
        {"WBINT_LOOKUPSID", NDR_WBINT_LOOKUPSID, api_wbint_LookupSid},
+       {"WBINT_LOOKUPNAME", NDR_WBINT_LOOKUPNAME, api_wbint_LookupName},
 };
 
 void wbint_get_pipe_fns(struct api_struct **fns, int *n_fns)
@@ -234,6 +321,23 @@ NTSTATUS rpc_wbint_dispatch(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, co
                        return NT_STATUS_OK;
                }
 
+               case NDR_WBINT_LOOKUPNAME: {
+                       struct wbint_LookupName *r = (struct wbint_LookupName *)_r;
+                       ZERO_STRUCT(r->out);
+                       r->out.type = talloc_zero(mem_ctx, enum lsa_SidType);
+                       if (r->out.type == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+                       }
+
+                       r->out.sid = talloc_zero(mem_ctx, struct dom_sid);
+                       if (r->out.sid == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+                       }
+
+                       r->out.result = _wbint_LookupName(cli->pipes_struct, r);
+                       return NT_STATUS_OK;
+               }
+
                default:
                        return NT_STATUS_NOT_IMPLEMENTED;
        }
index 6e6183989c21ce23d1c766ce45b258219813276e..259eef7c4f6268547e9d99e1efaf06cac57a08f2 100644 (file)
@@ -3,9 +3,11 @@
 #define __SRV_WBINT__
 void _wbint_Ping(pipes_struct *p, struct wbint_Ping *r);
 NTSTATUS _wbint_LookupSid(pipes_struct *p, struct wbint_LookupSid *r);
+NTSTATUS _wbint_LookupName(pipes_struct *p, struct wbint_LookupName *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);
 NTSTATUS _wbint_LookupSid(pipes_struct *p, struct wbint_LookupSid *r);
+NTSTATUS _wbint_LookupName(pipes_struct *p, struct wbint_LookupName *r);
 NTSTATUS rpc_wbint_init(void);
 #endif /* __SRV_WBINT__ */
index 2cc59b3f963badaa1b8e35993728fb0cf0f654e3..a007b95b18b0ae9e74486bd7c8e4d9639d587366 100644 (file)
@@ -35,4 +35,20 @@ struct wbint_LookupSid {
 
 };
 
+
+struct wbint_LookupName {
+       struct {
+               const char *domain;/* [ref,charset(UTF8)] */
+               const char *name;/* [ref,charset(UTF8)] */
+               uint32_t flags;
+       } in;
+
+       struct {
+               enum lsa_SidType *type;/* [ref] */
+               struct dom_sid *sid;/* [ref] */
+               NTSTATUS result;
+       } out;
+
+};
+
 #endif /* _HEADER_wbint */
index d0611e8a1be2eed325de5810d2767ae37de87148..d72309bd80b3fb04e8c8f2eaf39443a7f1d7a0e8 100644 (file)
@@ -21,4 +21,12 @@ interface wbint
        [out,string,charset(UTF8)] char **domain,
        [out,string,charset(UTF8)] char **name
        );
+
+    NTSTATUS wbint_LookupName(
+       [in,string,charset(UTF8)] char *domain,
+       [in,string,charset(UTF8)] char *name,
+       [in] uint32 flags,
+       [out] lsa_SidType *type,
+       [out] dom_sid *sid
+       );
 }
\ No newline at end of file
diff --git a/source3/winbindd/wb_lookupname.c b/source3/winbindd/wb_lookupname.c
new file mode 100644 (file)
index 0000000..d4e9b9a
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+   Unix SMB/CIFS implementation.
+   async lookupname
+   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_lookupname_state {
+       struct dom_sid sid;
+       enum lsa_SidType type;
+};
+
+static void wb_lookupname_done(struct tevent_req *subreq);
+
+struct tevent_req *wb_lookupname_send(TALLOC_CTX *mem_ctx,
+                                     struct tevent_context *ev,
+                                     const char *dom_name, const char *name,
+                                     uint32_t flags)
+{
+       struct tevent_req *req, *subreq;
+       struct wb_lookupname_state *state;
+       struct winbindd_domain *domain;
+       NTSTATUS status;
+
+       req = tevent_req_create(mem_ctx, &state, struct wb_lookupname_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       domain = find_lookup_domain_from_name(dom_name);
+       if (domain == NULL) {
+               DEBUG(5, ("Could not find domain for %s\n", dom_name));
+               tevent_req_nterror(req, NT_STATUS_NONE_MAPPED);
+               return tevent_req_post(req, ev);
+       }
+
+       status = wcache_name_to_sid(domain, dom_name, name,
+                                   &state->sid, &state->type);
+       if (NT_STATUS_IS_OK(status)) {
+               tevent_req_done(req);
+               return tevent_req_post(req, ev);
+       }
+
+       subreq = rpccli_wbint_LookupName_send(
+               state, ev, domain->child.rpccli, dom_name, name, flags,
+               &state->type, &state->sid);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, wb_lookupname_done, req);
+       return req;
+}
+
+static void wb_lookupname_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct wb_lookupname_state *state = tevent_req_data(
+               req, struct wb_lookupname_state);
+       NTSTATUS status, result;
+
+       status = rpccli_wbint_LookupName_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_lookupname_recv(struct tevent_req *req, struct dom_sid *sid,
+                           enum lsa_SidType *type)
+{
+       struct wb_lookupname_state *state = tevent_req_data(
+               req, struct wb_lookupname_state);
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               return status;
+       }
+       sid_copy(sid, &state->sid);
+       *type = state->type;
+       return NT_STATUS_OK;
+}
index b4e18c82c1ebe818698e597f402515d742ea1a53..568084fd543f8dd003c35826d1703d67604b21dc 100644 (file)
@@ -52,3 +52,16 @@ NTSTATUS _wbint_LookupSid(pipes_struct *p, struct wbint_LookupSid *r)
        *r->out.type = type;
        return NT_STATUS_OK;
 }
+
+NTSTATUS _wbint_LookupName(pipes_struct *p, struct wbint_LookupName *r)
+{
+       struct winbindd_domain *domain = wb_child_domain();
+
+       if (domain == NULL) {
+               return NT_STATUS_REQUEST_NOT_ACCEPTED;
+       }
+
+       return domain->methods->name_to_sid(
+               domain, p->mem_ctx, r->in.domain, r->in.name, r->in.flags,
+               r->out.sid, r->out.type);
+}
index e76e0cde1fb3814189532aee7dc93e56c879f512..2b493b2a675805e1a160f7a37540239e221e2d3a 100644 (file)
@@ -624,5 +624,12 @@ struct tevent_req *winbindd_lookupsid_send(TALLOC_CTX *mem_ctx,
 NTSTATUS winbindd_lookupsid_recv(struct tevent_req *req,
                                 struct winbindd_response *response);
 
+struct tevent_req *wb_lookupname_send(TALLOC_CTX *mem_ctx,
+                                     struct tevent_context *ev,
+                                     const char *dom_name, const char *name,
+                                     uint32_t flags);
+NTSTATUS wb_lookupname_recv(struct tevent_req *req, struct dom_sid *sid,
+                           enum lsa_SidType *type);
+
 
 #endif /*  _WINBINDD_PROTO_H_  */