summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2009-08-03 23:44:46 +0200
committerVolker Lendecke <vl@samba.org>2009-08-05 03:21:20 -0400
commitbb359c780aee3fd7e1074db93a28c95590ae5d36 (patch)
tree20da9d2b875a3b93fc09f9c2ec74d7c9928f19cf
parent2d6589fb0243cb2b73615de1aaea38a3059c08ed (diff)
downloadsamba-bb359c780aee3fd7e1074db93a28c95590ae5d36.tar.gz
samba-bb359c780aee3fd7e1074db93a28c95590ae5d36.tar.bz2
samba-bb359c780aee3fd7e1074db93a28c95590ae5d36.zip
s3:winbind: Add async wb_lookupsid
-rw-r--r--source3/Makefile.in1
-rw-r--r--source3/librpc/gen_ndr/cli_wbint.c171
-rw-r--r--source3/librpc/gen_ndr/cli_wbint.h16
-rw-r--r--source3/librpc/gen_ndr/ndr_wbint.c184
-rw-r--r--source3/librpc/gen_ndr/ndr_wbint.h5
-rw-r--r--source3/librpc/gen_ndr/srv_wbint.c115
-rw-r--r--source3/librpc/gen_ndr/srv_wbint.h2
-rw-r--r--source3/librpc/gen_ndr/wbint.h16
-rw-r--r--source3/librpc/idl/wbint.idl10
-rw-r--r--source3/winbindd/wb_lookupsid.c132
-rw-r--r--source3/winbindd/winbindd_dual_srv.c24
-rw-r--r--source3/winbindd/winbindd_proto.h7
12 files changed, 681 insertions, 2 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 1686a9c809..a9f9c16598 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -1152,6 +1152,7 @@ WINBINDD_OBJ1 = \
winbindd/winbindd_locator.o \
winbindd/winbindd_ndr.o \
winbindd/wb_ping.o \
+ winbindd/wb_lookupsid.o \
auth/token_util.o \
../nsswitch/libwbclient/wb_reqtrans.o \
smbd/connection.o
diff --git a/source3/librpc/gen_ndr/cli_wbint.c b/source3/librpc/gen_ndr/cli_wbint.c
index 044fdf9d1c..491413ee76 100644
--- a/source3/librpc/gen_ndr/cli_wbint.c
+++ b/source3/librpc/gen_ndr/cli_wbint.c
@@ -157,3 +157,174 @@ NTSTATUS rpccli_wbint_Ping(struct rpc_pipe_client *cli,
return NT_STATUS_OK;
}
+struct rpccli_wbint_LookupSid_state {
+ struct wbint_LookupSid orig;
+ struct wbint_LookupSid tmp;
+ TALLOC_CTX *out_mem_ctx;
+ NTSTATUS (*dispatch_recv)(struct tevent_req *req, TALLOC_CTX *mem_ctx);
+};
+
+static void rpccli_wbint_LookupSid_done(struct tevent_req *subreq);
+
+struct tevent_req *rpccli_wbint_LookupSid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct rpc_pipe_client *cli,
+ struct dom_sid *_sid /* [in] [ref] */,
+ enum lsa_SidType *_type /* [out] [ref] */,
+ const char **_domain /* [out] [ref,charset(UTF8)] */,
+ const char **_name /* [out] [ref,charset(UTF8)] */)
+{
+ struct tevent_req *req;
+ struct rpccli_wbint_LookupSid_state *state;
+ struct tevent_req *subreq;
+
+ req = tevent_req_create(mem_ctx, &state,
+ struct rpccli_wbint_LookupSid_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ state->out_mem_ctx = NULL;
+ state->dispatch_recv = cli->dispatch_recv;
+
+ /* In parameters */
+ state->orig.in.sid = _sid;
+
+ /* Out parameters */
+ state->orig.out.type = _type;
+ state->orig.out.domain = _domain;
+ state->orig.out.name = _name;
+
+ /* Result */
+ ZERO_STRUCT(state->orig.out.result);
+
+ if (DEBUGLEVEL >= 10) {
+ NDR_PRINT_IN_DEBUG(wbint_LookupSid, &state->orig);
+ }
+
+ state->out_mem_ctx = talloc_named_const(state, 0,
+ "rpccli_wbint_LookupSid_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_LOOKUPSID,
+ &state->tmp);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, rpccli_wbint_LookupSid_done, req);
+ return req;
+}
+
+static void rpccli_wbint_LookupSid_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct rpccli_wbint_LookupSid_state *state = tevent_req_data(
+ req, struct rpccli_wbint_LookupSid_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.domain = *state->tmp.out.domain;
+ *state->orig.out.name = *state->tmp.out.name;
+
+ /* 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_LookupSid, &state->orig);
+ }
+
+ tevent_req_done(req);
+}
+
+NTSTATUS rpccli_wbint_LookupSid_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ NTSTATUS *result)
+{
+ struct rpccli_wbint_LookupSid_state *state = tevent_req_data(
+ req, struct rpccli_wbint_LookupSid_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_LookupSid(struct rpc_pipe_client *cli,
+ TALLOC_CTX *mem_ctx,
+ struct dom_sid *sid /* [in] [ref] */,
+ enum lsa_SidType *type /* [out] [ref] */,
+ const char **domain /* [out] [ref,charset(UTF8)] */,
+ const char **name /* [out] [ref,charset(UTF8)] */)
+{
+ struct wbint_LookupSid r;
+ NTSTATUS status;
+
+ /* In parameters */
+ r.in.sid = sid;
+
+ if (DEBUGLEVEL >= 10) {
+ NDR_PRINT_IN_DEBUG(wbint_LookupSid, &r);
+ }
+
+ status = cli->dispatch(cli,
+ mem_ctx,
+ &ndr_table_wbint,
+ NDR_WBINT_LOOKUPSID,
+ &r);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ if (DEBUGLEVEL >= 10) {
+ NDR_PRINT_OUT_DEBUG(wbint_LookupSid, &r);
+ }
+
+ if (NT_STATUS_IS_ERR(status)) {
+ return status;
+ }
+
+ /* Return variables */
+ *type = *r.out.type;
+ *domain = *r.out.domain;
+ *name = *r.out.name;
+
+ /* Return result */
+ return r.out.result;
+}
+
diff --git a/source3/librpc/gen_ndr/cli_wbint.h b/source3/librpc/gen_ndr/cli_wbint.h
index 25b13f2b64..b79fd19a36 100644
--- a/source3/librpc/gen_ndr/cli_wbint.h
+++ b/source3/librpc/gen_ndr/cli_wbint.h
@@ -12,4 +12,20 @@ NTSTATUS rpccli_wbint_Ping(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx,
uint32_t in_data /* [in] */,
uint32_t *out_data /* [out] [ref] */);
+struct tevent_req *rpccli_wbint_LookupSid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct rpc_pipe_client *cli,
+ struct dom_sid *_sid /* [in] [ref] */,
+ enum lsa_SidType *_type /* [out] [ref] */,
+ const char **_domain /* [out] [ref,charset(UTF8)] */,
+ const char **_name /* [out] [ref,charset(UTF8)] */);
+NTSTATUS rpccli_wbint_LookupSid_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ NTSTATUS *result);
+NTSTATUS rpccli_wbint_LookupSid(struct rpc_pipe_client *cli,
+ TALLOC_CTX *mem_ctx,
+ struct dom_sid *sid /* [in] [ref] */,
+ enum lsa_SidType *type /* [out] [ref] */,
+ const char **domain /* [out] [ref,charset(UTF8)] */,
+ const char **name /* [out] [ref,charset(UTF8)] */);
#endif /* __CLI_WBINT__ */
diff --git a/source3/librpc/gen_ndr/ndr_wbint.c b/source3/librpc/gen_ndr/ndr_wbint.c
index fed1ce2f1e..1e8ea207b7 100644
--- a/source3/librpc/gen_ndr/ndr_wbint.c
+++ b/source3/librpc/gen_ndr/ndr_wbint.c
@@ -3,6 +3,7 @@
#include "includes.h"
#include "librpc/gen_ndr/ndr_wbint.h"
+#include "librpc/gen_ndr/ndr_lsa.h"
static enum ndr_err_code ndr_push_wbint_Ping(struct ndr_push *ndr, int flags, const struct wbint_Ping *r)
{
if (flags & NDR_IN) {
@@ -64,6 +65,179 @@ _PUBLIC_ void ndr_print_wbint_Ping(struct ndr_print *ndr, const char *name, int
ndr->depth--;
}
+static enum ndr_err_code ndr_push_wbint_LookupSid(struct ndr_push *ndr, int flags, const struct wbint_LookupSid *r)
+{
+ if (flags & NDR_IN) {
+ if (r->in.sid == NULL) {
+ return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer");
+ }
+ NDR_CHECK(ndr_push_dom_sid(ndr, NDR_SCALARS, r->in.sid));
+ }
+ 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.domain == NULL) {
+ return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer");
+ }
+ NDR_CHECK(ndr_push_unique_ptr(ndr, *r->out.domain));
+ if (*r->out.domain) {
+ NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(*r->out.domain, CH_UTF8)));
+ NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
+ NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(*r->out.domain, CH_UTF8)));
+ NDR_CHECK(ndr_push_charset(ndr, NDR_SCALARS, *r->out.domain, ndr_charset_length(*r->out.domain, CH_UTF8), sizeof(uint8_t), CH_UTF8));
+ }
+ if (r->out.name == NULL) {
+ return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer");
+ }
+ NDR_CHECK(ndr_push_unique_ptr(ndr, *r->out.name));
+ if (*r->out.name) {
+ NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(*r->out.name, CH_UTF8)));
+ NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
+ NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(*r->out.name, CH_UTF8)));
+ NDR_CHECK(ndr_push_charset(ndr, NDR_SCALARS, *r->out.name, ndr_charset_length(*r->out.name, CH_UTF8), sizeof(uint8_t), CH_UTF8));
+ }
+ NDR_CHECK(ndr_push_NTSTATUS(ndr, NDR_SCALARS, r->out.result));
+ }
+ return NDR_ERR_SUCCESS;
+}
+
+static enum ndr_err_code ndr_pull_wbint_LookupSid(struct ndr_pull *ndr, int flags, struct wbint_LookupSid *r)
+{
+ uint32_t _ptr_domain;
+ uint32_t _ptr_name;
+ TALLOC_CTX *_mem_save_sid_0;
+ TALLOC_CTX *_mem_save_type_0;
+ TALLOC_CTX *_mem_save_domain_0;
+ TALLOC_CTX *_mem_save_domain_1;
+ TALLOC_CTX *_mem_save_name_0;
+ TALLOC_CTX *_mem_save_name_1;
+ if (flags & NDR_IN) {
+ ZERO_STRUCT(r->out);
+
+ if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {
+ NDR_PULL_ALLOC(ndr, r->in.sid);
+ }
+ _mem_save_sid_0 = NDR_PULL_GET_MEM_CTX(ndr);
+ NDR_PULL_SET_MEM_CTX(ndr, r->in.sid, LIBNDR_FLAG_REF_ALLOC);
+ NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, r->in.sid));
+ NDR_PULL_SET_MEM_CTX(ndr, _mem_save_sid_0, LIBNDR_FLAG_REF_ALLOC);
+ NDR_PULL_ALLOC(ndr, r->out.type);
+ ZERO_STRUCTP(r->out.type);
+ NDR_PULL_ALLOC(ndr, r->out.domain);
+ ZERO_STRUCTP(r->out.domain);
+ NDR_PULL_ALLOC(ndr, r->out.name);
+ ZERO_STRUCTP(r->out.name);
+ }
+ 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.domain);
+ }
+ _mem_save_domain_0 = NDR_PULL_GET_MEM_CTX(ndr);
+ NDR_PULL_SET_MEM_CTX(ndr, r->out.domain, LIBNDR_FLAG_REF_ALLOC);
+ NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_domain));
+ if (_ptr_domain) {
+ NDR_PULL_ALLOC(ndr, *r->out.domain);
+ } else {
+ *r->out.domain = NULL;
+ }
+ if (*r->out.domain) {
+ _mem_save_domain_1 = NDR_PULL_GET_MEM_CTX(ndr);
+ NDR_PULL_SET_MEM_CTX(ndr, *r->out.domain, 0);
+ NDR_CHECK(ndr_pull_array_size(ndr, r->out.domain));
+ NDR_CHECK(ndr_pull_array_length(ndr, r->out.domain));
+ if (ndr_get_array_length(ndr, r->out.domain) > ndr_get_array_size(ndr, r->out.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->out.domain), ndr_get_array_length(ndr, r->out.domain));
+ }
+ NDR_CHECK(ndr_check_string_terminator(ndr, ndr_get_array_length(ndr, r->out.domain), sizeof(uint8_t)));
+ NDR_CHECK(ndr_pull_charset(ndr, NDR_SCALARS, r->out.domain, ndr_get_array_length(ndr, r->out.domain), sizeof(uint8_t), CH_UTF8));
+ NDR_PULL_SET_MEM_CTX(ndr, _mem_save_domain_1, 0);
+ }
+ NDR_PULL_SET_MEM_CTX(ndr, _mem_save_domain_0, LIBNDR_FLAG_REF_ALLOC);
+ if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {
+ NDR_PULL_ALLOC(ndr, r->out.name);
+ }
+ _mem_save_name_0 = NDR_PULL_GET_MEM_CTX(ndr);
+ NDR_PULL_SET_MEM_CTX(ndr, r->out.name, LIBNDR_FLAG_REF_ALLOC);
+ NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_name));
+ if (_ptr_name) {
+ NDR_PULL_ALLOC(ndr, *r->out.name);
+ } else {
+ *r->out.name = NULL;
+ }
+ if (*r->out.name) {
+ _mem_save_name_1 = NDR_PULL_GET_MEM_CTX(ndr);
+ NDR_PULL_SET_MEM_CTX(ndr, *r->out.name, 0);
+ NDR_CHECK(ndr_pull_array_size(ndr, r->out.name));
+ NDR_CHECK(ndr_pull_array_length(ndr, r->out.name));
+ if (ndr_get_array_length(ndr, r->out.name) > ndr_get_array_size(ndr, r->out.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->out.name), ndr_get_array_length(ndr, r->out.name));
+ }
+ NDR_CHECK(ndr_check_string_terminator(ndr, ndr_get_array_length(ndr, r->out.name), sizeof(uint8_t)));
+ NDR_CHECK(ndr_pull_charset(ndr, NDR_SCALARS, r->out.name, ndr_get_array_length(ndr, r->out.name), sizeof(uint8_t), CH_UTF8));
+ NDR_PULL_SET_MEM_CTX(ndr, _mem_save_name_1, 0);
+ }
+ NDR_PULL_SET_MEM_CTX(ndr, _mem_save_name_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_LookupSid(struct ndr_print *ndr, const char *name, int flags, const struct wbint_LookupSid *r)
+{
+ ndr_print_struct(ndr, name, "wbint_LookupSid");
+ ndr->depth++;
+ if (flags & NDR_SET_VALUES) {
+ ndr->flags |= LIBNDR_PRINT_SET_VALUES;
+ }
+ if (flags & NDR_IN) {
+ ndr_print_struct(ndr, "in", "wbint_LookupSid");
+ ndr->depth++;
+ ndr_print_ptr(ndr, "sid", r->in.sid);
+ ndr->depth++;
+ ndr_print_dom_sid(ndr, "sid", r->in.sid);
+ ndr->depth--;
+ ndr->depth--;
+ }
+ if (flags & NDR_OUT) {
+ ndr_print_struct(ndr, "out", "wbint_LookupSid");
+ 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, "domain", r->out.domain);
+ ndr->depth++;
+ ndr_print_ptr(ndr, "domain", *r->out.domain);
+ ndr->depth++;
+ if (*r->out.domain) {
+ ndr_print_string(ndr, "domain", *r->out.domain);
+ }
+ ndr->depth--;
+ ndr->depth--;
+ ndr_print_ptr(ndr, "name", r->out.name);
+ ndr->depth++;
+ ndr_print_ptr(ndr, "name", *r->out.name);
+ ndr->depth++;
+ if (*r->out.name) {
+ ndr_print_string(ndr, "name", *r->out.name);
+ }
+ ndr->depth--;
+ ndr->depth--;
+ ndr_print_NTSTATUS(ndr, "result", r->out.result);
+ ndr->depth--;
+ }
+ ndr->depth--;
+}
+
static const struct ndr_interface_call wbint_calls[] = {
{
"wbint_Ping",
@@ -73,6 +247,14 @@ static const struct ndr_interface_call wbint_calls[] = {
(ndr_print_function_t) ndr_print_wbint_Ping,
false,
},
+ {
+ "wbint_LookupSid",
+ sizeof(struct wbint_LookupSid),
+ (ndr_push_flags_fn_t) ndr_push_wbint_LookupSid,
+ (ndr_pull_flags_fn_t) ndr_pull_wbint_LookupSid,
+ (ndr_print_function_t) ndr_print_wbint_LookupSid,
+ false,
+ },
{ NULL, 0, NULL, NULL, NULL, false }
};
@@ -102,7 +284,7 @@ const struct ndr_interface_table ndr_table_wbint = {
NDR_WBINT_VERSION
},
.helpstring = NDR_WBINT_HELPSTRING,
- .num_calls = 1,
+ .num_calls = 2,
.calls = wbint_calls,
.endpoints = &wbint_endpoints,
.authservices = &wbint_authservices
diff --git a/source3/librpc/gen_ndr/ndr_wbint.h b/source3/librpc/gen_ndr/ndr_wbint.h
index 6c38087687..9a76cddd99 100644
--- a/source3/librpc/gen_ndr/ndr_wbint.h
+++ b/source3/librpc/gen_ndr/ndr_wbint.h
@@ -13,6 +13,9 @@
extern const struct ndr_interface_table ndr_table_wbint;
#define NDR_WBINT_PING (0x00)
-#define NDR_WBINT_CALL_COUNT (1)
+#define NDR_WBINT_LOOKUPSID (0x01)
+
+#define NDR_WBINT_CALL_COUNT (2)
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);
#endif /* _HEADER_NDR_wbint */
diff --git a/source3/librpc/gen_ndr/srv_wbint.c b/source3/librpc/gen_ndr/srv_wbint.c
index 0a3569b874..85ebf5dd3a 100644
--- a/source3/librpc/gen_ndr/srv_wbint.c
+++ b/source3/librpc/gen_ndr/srv_wbint.c
@@ -86,11 +86,104 @@ static bool api_wbint_Ping(pipes_struct *p)
return true;
}
+static bool api_wbint_LookupSid(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_LookupSid *r;
+
+ call = &ndr_table_wbint.calls[NDR_WBINT_LOOKUPSID];
+
+ r = talloc(talloc_tos(), struct wbint_LookupSid);
+ 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_LookupSid, 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.domain = talloc_zero(r, const char *);
+ if (r->out.domain == NULL) {
+ talloc_free(r);
+ return false;
+ }
+
+ r->out.name = talloc_zero(r, const char *);
+ if (r->out.name == NULL) {
+ talloc_free(r);
+ return false;
+ }
+
+ r->out.result = _wbint_LookupSid(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_LookupSid, 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},
};
void wbint_get_pipe_fns(struct api_struct **fns, int *n_fns)
@@ -119,6 +212,28 @@ NTSTATUS rpc_wbint_dispatch(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, co
return NT_STATUS_OK;
}
+ case NDR_WBINT_LOOKUPSID: {
+ struct wbint_LookupSid *r = (struct wbint_LookupSid *)_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.domain = talloc_zero(mem_ctx, const char *);
+ if (r->out.domain == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ r->out.name = talloc_zero(mem_ctx, const char *);
+ if (r->out.name == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ r->out.result = _wbint_LookupSid(cli->pipes_struct, r);
+ return NT_STATUS_OK;
+ }
+
default:
return NT_STATUS_NOT_IMPLEMENTED;
}
diff --git a/source3/librpc/gen_ndr/srv_wbint.h b/source3/librpc/gen_ndr/srv_wbint.h
index af3d21a43d..6e6183989c 100644
--- a/source3/librpc/gen_ndr/srv_wbint.h
+++ b/source3/librpc/gen_ndr/srv_wbint.h
@@ -2,8 +2,10 @@
#ifndef __SRV_WBINT__
#define __SRV_WBINT__
void _wbint_Ping(pipes_struct *p, struct wbint_Ping *r);
+NTSTATUS _wbint_LookupSid(pipes_struct *p, struct wbint_LookupSid *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 rpc_wbint_init(void);
#endif /* __SRV_WBINT__ */
diff --git a/source3/librpc/gen_ndr/wbint.h b/source3/librpc/gen_ndr/wbint.h
index 641d960a1b..2cc59b3f96 100644
--- a/source3/librpc/gen_ndr/wbint.h
+++ b/source3/librpc/gen_ndr/wbint.h
@@ -4,6 +4,7 @@
#include "libcli/util/ntstatus.h"
+#include "librpc/gen_ndr/lsa.h"
#ifndef _HEADER_wbint
#define _HEADER_wbint
@@ -19,4 +20,19 @@ struct wbint_Ping {
};
+
+struct wbint_LookupSid {
+ struct {
+ struct dom_sid *sid;/* [ref] */
+ } in;
+
+ struct {
+ enum lsa_SidType *type;/* [ref] */
+ const char **domain;/* [ref,charset(UTF8)] */
+ const char **name;/* [ref,charset(UTF8)] */
+ NTSTATUS result;
+ } out;
+
+};
+
#endif /* _HEADER_wbint */
diff --git a/source3/librpc/idl/wbint.idl b/source3/librpc/idl/wbint.idl
index 40a4545a3a..d0611e8a1b 100644
--- a/source3/librpc/idl/wbint.idl
+++ b/source3/librpc/idl/wbint.idl
@@ -1,3 +1,6 @@
+#include "idl_types.h"
+import "lsa.idl";
+
[
uuid("bf09192c-ed60-4928-9dff-d0d7bcb03ed8"),
endpoint("ncalrpc:"),
@@ -11,4 +14,11 @@ interface wbint
[in] uint32 in_data,
[out] uint32 *out_data
);
+
+ NTSTATUS wbint_LookupSid(
+ [in] dom_sid *sid,
+ [out] lsa_SidType *type,
+ [out,string,charset(UTF8)] char **domain,
+ [out,string,charset(UTF8)] char **name
+ );
} \ No newline at end of file
diff --git a/source3/winbindd/wb_lookupsid.c b/source3/winbindd/wb_lookupsid.c
new file mode 100644
index 0000000000..f258828048
--- /dev/null
+++ b/source3/winbindd/wb_lookupsid.c
@@ -0,0 +1,132 @@
+/*
+ Unix SMB/CIFS implementation.
+ async lookupsid
+ 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_lookupsid_state {
+ struct tevent_context *ev;
+ struct winbindd_domain *lookup_domain;
+ struct dom_sid sid;
+ enum lsa_SidType type;
+ const char *domname;
+ const char *name;
+};
+
+static void wb_lookupsid_done(struct tevent_req *subreq);
+
+struct tevent_req *wb_lookupsid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ const struct dom_sid *sid)
+{
+ struct tevent_req *req, *subreq;
+ struct wb_lookupsid_state *state;
+ char *dom_name, *name;
+ NTSTATUS status;
+
+ req = tevent_req_create(mem_ctx, &state, struct wb_lookupsid_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ sid_copy(&state->sid, sid);
+ state->ev = ev;
+
+ state->lookup_domain = find_lookup_domain_from_sid(sid);
+ if (state->lookup_domain == NULL) {
+ DEBUG(5, ("Could not find domain for sid %s\n",
+ sid_string_dbg(sid)));
+ tevent_req_nterror(req, NT_STATUS_NONE_MAPPED);
+ return tevent_req_post(req, ev);
+ }
+
+ status = wcache_sid_to_name(state->lookup_domain, sid, state,
+ &dom_name, &name, &state->type);
+ if (NT_STATUS_IS_OK(status)) {
+ state->domname = dom_name;
+ state->name = name;
+ tevent_req_done(req);
+ return tevent_req_post(req, ev);
+ }
+
+ subreq = rpccli_wbint_LookupSid_send(
+ state, ev, state->lookup_domain->child.rpccli,
+ &state->sid, &state->type, &state->domname, &state->name);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, wb_lookupsid_done, req);
+ return req;
+}
+
+static void wb_lookupsid_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct wb_lookupsid_state *state = tevent_req_data(
+ req, struct wb_lookupsid_state);
+ struct winbindd_domain *forest_root;
+ NTSTATUS status, result;
+
+ status = rpccli_wbint_LookupSid_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_done(req);
+ return;
+ }
+
+ /*
+ * Let's try the forest root
+ */
+ forest_root = find_root_domain();
+ if ((forest_root == NULL) || (forest_root == state->lookup_domain)) {
+ tevent_req_nterror(req, result);
+ return;
+ }
+ state->lookup_domain = forest_root;
+
+ subreq = rpccli_wbint_LookupSid_send(
+ state, state->ev, state->lookup_domain->child.rpccli,
+ &state->sid, &state->type, &state->domname, &state->name);
+ if (tevent_req_nomem(subreq, req)) {
+ return;
+ }
+ tevent_req_set_callback(subreq, wb_lookupsid_done, req);
+}
+
+NTSTATUS wb_lookupsid_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+ enum lsa_SidType *type, const char **domain,
+ const char **name)
+{
+ struct wb_lookupsid_state *state = tevent_req_data(
+ req, struct wb_lookupsid_state);
+ NTSTATUS status;
+
+ if (tevent_req_is_nterror(req, &status)) {
+ return status;
+ }
+ *type = state->type;
+ *domain = talloc_move(mem_ctx, &state->domname);
+ *name = talloc_move(mem_ctx, &state->name);
+ return NT_STATUS_OK;
+}
diff --git a/source3/winbindd/winbindd_dual_srv.c b/source3/winbindd/winbindd_dual_srv.c
index 5d2d7f389d..b4e18c82c1 100644
--- a/source3/winbindd/winbindd_dual_srv.c
+++ b/source3/winbindd/winbindd_dual_srv.c
@@ -28,3 +28,27 @@ void _wbint_Ping(pipes_struct *p, struct wbint_Ping *r)
{
*r->out.out_data = r->in.in_data;
}
+
+NTSTATUS _wbint_LookupSid(pipes_struct *p, struct wbint_LookupSid *r)
+{
+ struct winbindd_domain *domain = wb_child_domain();
+ char *dom_name;
+ char *name;
+ enum lsa_SidType type;
+ NTSTATUS status;
+
+ if (domain == NULL) {
+ return NT_STATUS_REQUEST_NOT_ACCEPTED;
+ }
+
+ status = domain->methods->sid_to_name(domain, p->mem_ctx, r->in.sid,
+ &dom_name, &name, &type);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ *r->out.domain = dom_name;
+ *r->out.name = name;
+ *r->out.type = type;
+ return NT_STATUS_OK;
+}
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index 182534a1fa..172e143ba0 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -606,4 +606,11 @@ struct rpc_pipe_client *wbint_rpccli_create(TALLOC_CTX *mem_ctx,
enum winbindd_result winbindd_dual_ndrcmd(struct winbindd_domain *domain,
struct winbindd_cli_state *state);
+struct tevent_req *wb_lookupsid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ const struct dom_sid *sid);
+NTSTATUS wb_lookupsid_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+ enum lsa_SidType *type, const char **domain,
+ const char **name);
+
#endif /* _WINBINDD_PROTO_H_ */