diff options
author | Volker Lendecke <vl@samba.org> | 2009-08-04 15:23:13 -0400 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2009-08-05 03:21:22 -0400 |
commit | 7077492778dbda30e5f865ae1d0ab0237e00f54f (patch) | |
tree | a51af896169011db394654f703665673860442e7 /source3 | |
parent | 360227a0feb443fbbcc420295d5666da5823685a (diff) | |
download | samba-7077492778dbda30e5f865ae1d0ab0237e00f54f.tar.gz samba-7077492778dbda30e5f865ae1d0ab0237e00f54f.tar.bz2 samba-7077492778dbda30e5f865ae1d0ab0237e00f54f.zip |
s3:winbind: Add async wb_queryuser
Diffstat (limited to 'source3')
-rw-r--r-- | source3/Makefile.in | 1 | ||||
-rw-r--r-- | source3/librpc/gen_ndr/cli_wbint.c | 161 | ||||
-rw-r--r-- | source3/librpc/gen_ndr/cli_wbint.h | 12 | ||||
-rw-r--r-- | source3/librpc/gen_ndr/ndr_wbint.c | 255 | ||||
-rw-r--r-- | source3/librpc/gen_ndr/ndr_wbint.h | 8 | ||||
-rw-r--r-- | source3/librpc/gen_ndr/srv_wbint.c | 93 | ||||
-rw-r--r-- | source3/librpc/gen_ndr/srv_wbint.h | 2 | ||||
-rw-r--r-- | source3/librpc/gen_ndr/wbint.h | 23 | ||||
-rw-r--r-- | source3/librpc/idl/wbint.idl | 15 | ||||
-rw-r--r-- | source3/winbindd/wb_queryuser.c | 121 | ||||
-rw-r--r-- | source3/winbindd/winbindd_dual_srv.c | 27 | ||||
-rw-r--r-- | source3/winbindd/winbindd_proto.h | 5 |
12 files changed, 721 insertions, 2 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in index f7801d17a2..b3f54e092b 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -1158,6 +1158,7 @@ WINBINDD_OBJ1 = \ winbindd/wb_sid2gid.o \ winbindd/wb_uid2sid.o \ winbindd/wb_gid2sid.o \ + winbindd/wb_queryuser.o \ winbindd/winbindd_lookupsid.o \ winbindd/winbindd_lookupname.o \ winbindd/winbindd_sid_to_uid.o \ diff --git a/source3/librpc/gen_ndr/cli_wbint.c b/source3/librpc/gen_ndr/cli_wbint.c index 4176e94a3f..9fdca8ecba 100644 --- a/source3/librpc/gen_ndr/cli_wbint.c +++ b/source3/librpc/gen_ndr/cli_wbint.c @@ -1162,3 +1162,164 @@ NTSTATUS rpccli_wbint_Gid2Sid(struct rpc_pipe_client *cli, return r.out.result; } +struct rpccli_wbint_QueryUser_state { + struct wbint_QueryUser orig; + struct wbint_QueryUser tmp; + TALLOC_CTX *out_mem_ctx; + NTSTATUS (*dispatch_recv)(struct tevent_req *req, TALLOC_CTX *mem_ctx); +}; + +static void rpccli_wbint_QueryUser_done(struct tevent_req *subreq); + +struct tevent_req *rpccli_wbint_QueryUser_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct rpc_pipe_client *cli, + struct dom_sid *_sid /* [in] [ref] */, + struct wbint_userinfo *_info /* [out] [ref] */) +{ + struct tevent_req *req; + struct rpccli_wbint_QueryUser_state *state; + struct tevent_req *subreq; + + req = tevent_req_create(mem_ctx, &state, + struct rpccli_wbint_QueryUser_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.info = _info; + + /* Result */ + ZERO_STRUCT(state->orig.out.result); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(wbint_QueryUser, &state->orig); + } + + state->out_mem_ctx = talloc_named_const(state, 0, + "rpccli_wbint_QueryUser_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_QUERYUSER, + &state->tmp); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, rpccli_wbint_QueryUser_done, req); + return req; +} + +static void rpccli_wbint_QueryUser_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct rpccli_wbint_QueryUser_state *state = tevent_req_data( + req, struct rpccli_wbint_QueryUser_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.info = *state->tmp.out.info; + + /* 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_QueryUser, &state->orig); + } + + tevent_req_done(req); +} + +NTSTATUS rpccli_wbint_QueryUser_recv(struct tevent_req *req, + TALLOC_CTX *mem_ctx, + NTSTATUS *result) +{ + struct rpccli_wbint_QueryUser_state *state = tevent_req_data( + req, struct rpccli_wbint_QueryUser_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_QueryUser(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, + struct dom_sid *sid /* [in] [ref] */, + struct wbint_userinfo *info /* [out] [ref] */) +{ + struct wbint_QueryUser r; + NTSTATUS status; + + /* In parameters */ + r.in.sid = sid; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(wbint_QueryUser, &r); + } + + status = cli->dispatch(cli, + mem_ctx, + &ndr_table_wbint, + NDR_WBINT_QUERYUSER, + &r); + + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(wbint_QueryUser, &r); + } + + if (NT_STATUS_IS_ERR(status)) { + return status; + } + + /* Return variables */ + *info = *r.out.info; + + /* 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 55fe22bd8f..ebceddea5f 100644 --- a/source3/librpc/gen_ndr/cli_wbint.h +++ b/source3/librpc/gen_ndr/cli_wbint.h @@ -102,4 +102,16 @@ NTSTATUS rpccli_wbint_Gid2Sid(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 *rpccli_wbint_QueryUser_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct rpc_pipe_client *cli, + struct dom_sid *_sid /* [in] [ref] */, + struct wbint_userinfo *_info /* [out] [ref] */); +NTSTATUS rpccli_wbint_QueryUser_recv(struct tevent_req *req, + TALLOC_CTX *mem_ctx, + NTSTATUS *result); +NTSTATUS rpccli_wbint_QueryUser(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, + struct dom_sid *sid /* [in] [ref] */, + struct wbint_userinfo *info /* [out] [ref] */); #endif /* __CLI_WBINT__ */ diff --git a/source3/librpc/gen_ndr/ndr_wbint.c b/source3/librpc/gen_ndr/ndr_wbint.c index f6e53eef96..2b773f3f45 100644 --- a/source3/librpc/gen_ndr/ndr_wbint.c +++ b/source3/librpc/gen_ndr/ndr_wbint.c @@ -4,6 +4,174 @@ #include "librpc/gen_ndr/ndr_wbint.h" #include "librpc/gen_ndr/ndr_lsa.h" +_PUBLIC_ enum ndr_err_code ndr_push_wbint_userinfo(struct ndr_push *ndr, int ndr_flags, const struct wbint_userinfo *r) +{ + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_push_align(ndr, 8)); + NDR_CHECK(ndr_push_unique_ptr(ndr, r->acct_name)); + NDR_CHECK(ndr_push_unique_ptr(ndr, r->full_name)); + NDR_CHECK(ndr_push_unique_ptr(ndr, r->homedir)); + NDR_CHECK(ndr_push_unique_ptr(ndr, r->shell)); + NDR_CHECK(ndr_push_hyper(ndr, NDR_SCALARS, r->primary_gid)); + NDR_CHECK(ndr_push_dom_sid(ndr, NDR_SCALARS, &r->user_sid)); + NDR_CHECK(ndr_push_dom_sid(ndr, NDR_SCALARS, &r->group_sid)); + } + if (ndr_flags & NDR_BUFFERS) { + if (r->acct_name) { + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(r->acct_name, CH_UTF8))); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0)); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(r->acct_name, CH_UTF8))); + NDR_CHECK(ndr_push_charset(ndr, NDR_SCALARS, r->acct_name, ndr_charset_length(r->acct_name, CH_UTF8), sizeof(uint8_t), CH_UTF8)); + } + if (r->full_name) { + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(r->full_name, CH_UTF8))); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0)); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(r->full_name, CH_UTF8))); + NDR_CHECK(ndr_push_charset(ndr, NDR_SCALARS, r->full_name, ndr_charset_length(r->full_name, CH_UTF8), sizeof(uint8_t), CH_UTF8)); + } + if (r->homedir) { + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(r->homedir, CH_UTF8))); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0)); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(r->homedir, CH_UTF8))); + NDR_CHECK(ndr_push_charset(ndr, NDR_SCALARS, r->homedir, ndr_charset_length(r->homedir, CH_UTF8), sizeof(uint8_t), CH_UTF8)); + } + if (r->shell) { + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(r->shell, CH_UTF8))); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0)); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_charset_length(r->shell, CH_UTF8))); + NDR_CHECK(ndr_push_charset(ndr, NDR_SCALARS, r->shell, ndr_charset_length(r->shell, CH_UTF8), sizeof(uint8_t), CH_UTF8)); + } + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ enum ndr_err_code ndr_pull_wbint_userinfo(struct ndr_pull *ndr, int ndr_flags, struct wbint_userinfo *r) +{ + uint32_t _ptr_acct_name; + TALLOC_CTX *_mem_save_acct_name_0; + uint32_t _ptr_full_name; + TALLOC_CTX *_mem_save_full_name_0; + uint32_t _ptr_homedir; + TALLOC_CTX *_mem_save_homedir_0; + uint32_t _ptr_shell; + TALLOC_CTX *_mem_save_shell_0; + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_pull_align(ndr, 8)); + NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_acct_name)); + if (_ptr_acct_name) { + NDR_PULL_ALLOC(ndr, r->acct_name); + } else { + r->acct_name = NULL; + } + NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_full_name)); + if (_ptr_full_name) { + NDR_PULL_ALLOC(ndr, r->full_name); + } else { + r->full_name = NULL; + } + NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_homedir)); + if (_ptr_homedir) { + NDR_PULL_ALLOC(ndr, r->homedir); + } else { + r->homedir = NULL; + } + NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_shell)); + if (_ptr_shell) { + NDR_PULL_ALLOC(ndr, r->shell); + } else { + r->shell = NULL; + } + NDR_CHECK(ndr_pull_hyper(ndr, NDR_SCALARS, &r->primary_gid)); + NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, &r->user_sid)); + NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, &r->group_sid)); + } + if (ndr_flags & NDR_BUFFERS) { + if (r->acct_name) { + _mem_save_acct_name_0 = NDR_PULL_GET_MEM_CTX(ndr); + NDR_PULL_SET_MEM_CTX(ndr, r->acct_name, 0); + NDR_CHECK(ndr_pull_array_size(ndr, &r->acct_name)); + NDR_CHECK(ndr_pull_array_length(ndr, &r->acct_name)); + if (ndr_get_array_length(ndr, &r->acct_name) > ndr_get_array_size(ndr, &r->acct_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->acct_name), ndr_get_array_length(ndr, &r->acct_name)); + } + NDR_CHECK(ndr_check_string_terminator(ndr, ndr_get_array_length(ndr, &r->acct_name), sizeof(uint8_t))); + NDR_CHECK(ndr_pull_charset(ndr, NDR_SCALARS, &r->acct_name, ndr_get_array_length(ndr, &r->acct_name), sizeof(uint8_t), CH_UTF8)); + NDR_PULL_SET_MEM_CTX(ndr, _mem_save_acct_name_0, 0); + } + if (r->full_name) { + _mem_save_full_name_0 = NDR_PULL_GET_MEM_CTX(ndr); + NDR_PULL_SET_MEM_CTX(ndr, r->full_name, 0); + NDR_CHECK(ndr_pull_array_size(ndr, &r->full_name)); + NDR_CHECK(ndr_pull_array_length(ndr, &r->full_name)); + if (ndr_get_array_length(ndr, &r->full_name) > ndr_get_array_size(ndr, &r->full_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->full_name), ndr_get_array_length(ndr, &r->full_name)); + } + NDR_CHECK(ndr_check_string_terminator(ndr, ndr_get_array_length(ndr, &r->full_name), sizeof(uint8_t))); + NDR_CHECK(ndr_pull_charset(ndr, NDR_SCALARS, &r->full_name, ndr_get_array_length(ndr, &r->full_name), sizeof(uint8_t), CH_UTF8)); + NDR_PULL_SET_MEM_CTX(ndr, _mem_save_full_name_0, 0); + } + if (r->homedir) { + _mem_save_homedir_0 = NDR_PULL_GET_MEM_CTX(ndr); + NDR_PULL_SET_MEM_CTX(ndr, r->homedir, 0); + NDR_CHECK(ndr_pull_array_size(ndr, &r->homedir)); + NDR_CHECK(ndr_pull_array_length(ndr, &r->homedir)); + if (ndr_get_array_length(ndr, &r->homedir) > ndr_get_array_size(ndr, &r->homedir)) { + return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE, "Bad array size %u should exceed array length %u", ndr_get_array_size(ndr, &r->homedir), ndr_get_array_length(ndr, &r->homedir)); + } + NDR_CHECK(ndr_check_string_terminator(ndr, ndr_get_array_length(ndr, &r->homedir), sizeof(uint8_t))); + NDR_CHECK(ndr_pull_charset(ndr, NDR_SCALARS, &r->homedir, ndr_get_array_length(ndr, &r->homedir), sizeof(uint8_t), CH_UTF8)); + NDR_PULL_SET_MEM_CTX(ndr, _mem_save_homedir_0, 0); + } + if (r->shell) { + _mem_save_shell_0 = NDR_PULL_GET_MEM_CTX(ndr); + NDR_PULL_SET_MEM_CTX(ndr, r->shell, 0); + NDR_CHECK(ndr_pull_array_size(ndr, &r->shell)); + NDR_CHECK(ndr_pull_array_length(ndr, &r->shell)); + if (ndr_get_array_length(ndr, &r->shell) > ndr_get_array_size(ndr, &r->shell)) { + return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE, "Bad array size %u should exceed array length %u", ndr_get_array_size(ndr, &r->shell), ndr_get_array_length(ndr, &r->shell)); + } + NDR_CHECK(ndr_check_string_terminator(ndr, ndr_get_array_length(ndr, &r->shell), sizeof(uint8_t))); + NDR_CHECK(ndr_pull_charset(ndr, NDR_SCALARS, &r->shell, ndr_get_array_length(ndr, &r->shell), sizeof(uint8_t), CH_UTF8)); + NDR_PULL_SET_MEM_CTX(ndr, _mem_save_shell_0, 0); + } + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ void ndr_print_wbint_userinfo(struct ndr_print *ndr, const char *name, const struct wbint_userinfo *r) +{ + ndr_print_struct(ndr, name, "wbint_userinfo"); + ndr->depth++; + ndr_print_ptr(ndr, "acct_name", r->acct_name); + ndr->depth++; + if (r->acct_name) { + ndr_print_string(ndr, "acct_name", r->acct_name); + } + ndr->depth--; + ndr_print_ptr(ndr, "full_name", r->full_name); + ndr->depth++; + if (r->full_name) { + ndr_print_string(ndr, "full_name", r->full_name); + } + ndr->depth--; + ndr_print_ptr(ndr, "homedir", r->homedir); + ndr->depth++; + if (r->homedir) { + ndr_print_string(ndr, "homedir", r->homedir); + } + ndr->depth--; + ndr_print_ptr(ndr, "shell", r->shell); + ndr->depth++; + if (r->shell) { + ndr_print_string(ndr, "shell", r->shell); + } + ndr->depth--; + ndr_print_hyper(ndr, "primary_gid", r->primary_gid); + ndr_print_dom_sid(ndr, "user_sid", &r->user_sid); + ndr_print_dom_sid(ndr, "group_sid", &r->group_sid); + ndr->depth--; +} + static enum ndr_err_code ndr_push_wbint_Ping(struct ndr_push *ndr, int flags, const struct wbint_Ping *r) { if (flags & NDR_IN) { @@ -770,6 +938,83 @@ _PUBLIC_ void ndr_print_wbint_Gid2Sid(struct ndr_print *ndr, const char *name, i ndr->depth--; } +static enum ndr_err_code ndr_push_wbint_QueryUser(struct ndr_push *ndr, int flags, const struct wbint_QueryUser *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.info == NULL) { + return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer"); + } + NDR_CHECK(ndr_push_wbint_userinfo(ndr, NDR_SCALARS|NDR_BUFFERS, r->out.info)); + NDR_CHECK(ndr_push_NTSTATUS(ndr, NDR_SCALARS, r->out.result)); + } + return NDR_ERR_SUCCESS; +} + +static enum ndr_err_code ndr_pull_wbint_QueryUser(struct ndr_pull *ndr, int flags, struct wbint_QueryUser *r) +{ + TALLOC_CTX *_mem_save_sid_0; + TALLOC_CTX *_mem_save_info_0; + 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.info); + ZERO_STRUCTP(r->out.info); + } + if (flags & NDR_OUT) { + if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) { + NDR_PULL_ALLOC(ndr, r->out.info); + } + _mem_save_info_0 = NDR_PULL_GET_MEM_CTX(ndr); + NDR_PULL_SET_MEM_CTX(ndr, r->out.info, LIBNDR_FLAG_REF_ALLOC); + NDR_CHECK(ndr_pull_wbint_userinfo(ndr, NDR_SCALARS|NDR_BUFFERS, r->out.info)); + NDR_PULL_SET_MEM_CTX(ndr, _mem_save_info_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_QueryUser(struct ndr_print *ndr, const char *name, int flags, const struct wbint_QueryUser *r) +{ + ndr_print_struct(ndr, name, "wbint_QueryUser"); + ndr->depth++; + if (flags & NDR_SET_VALUES) { + ndr->flags |= LIBNDR_PRINT_SET_VALUES; + } + if (flags & NDR_IN) { + ndr_print_struct(ndr, "in", "wbint_QueryUser"); + 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_QueryUser"); + ndr->depth++; + ndr_print_ptr(ndr, "info", r->out.info); + ndr->depth++; + ndr_print_wbint_userinfo(ndr, "info", r->out.info); + ndr->depth--; + ndr_print_NTSTATUS(ndr, "result", r->out.result); + ndr->depth--; + } + ndr->depth--; +} + static const struct ndr_interface_call wbint_calls[] = { { "wbint_Ping", @@ -827,6 +1072,14 @@ static const struct ndr_interface_call wbint_calls[] = { (ndr_print_function_t) ndr_print_wbint_Gid2Sid, false, }, + { + "wbint_QueryUser", + sizeof(struct wbint_QueryUser), + (ndr_push_flags_fn_t) ndr_push_wbint_QueryUser, + (ndr_pull_flags_fn_t) ndr_pull_wbint_QueryUser, + (ndr_print_function_t) ndr_print_wbint_QueryUser, + false, + }, { NULL, 0, NULL, NULL, NULL, false } }; @@ -856,7 +1109,7 @@ const struct ndr_interface_table ndr_table_wbint = { NDR_WBINT_VERSION }, .helpstring = NDR_WBINT_HELPSTRING, - .num_calls = 7, + .num_calls = 8, .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 d8843a3c0c..5db488e69c 100644 --- a/source3/librpc/gen_ndr/ndr_wbint.h +++ b/source3/librpc/gen_ndr/ndr_wbint.h @@ -25,7 +25,12 @@ extern const struct ndr_interface_table ndr_table_wbint; #define NDR_WBINT_GID2SID (0x06) -#define NDR_WBINT_CALL_COUNT (7) +#define NDR_WBINT_QUERYUSER (0x07) + +#define NDR_WBINT_CALL_COUNT (8) +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); 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); @@ -33,4 +38,5 @@ void ndr_print_wbint_Sid2Uid(struct ndr_print *ndr, const char *name, int flags, 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); +void ndr_print_wbint_QueryUser(struct ndr_print *ndr, const char *name, int flags, const struct wbint_QueryUser *r); #endif /* _HEADER_NDR_wbint */ diff --git a/source3/librpc/gen_ndr/srv_wbint.c b/source3/librpc/gen_ndr/srv_wbint.c index a04aa8245f..121d3fa79d 100644 --- a/source3/librpc/gen_ndr/srv_wbint.c +++ b/source3/librpc/gen_ndr/srv_wbint.c @@ -584,6 +584,86 @@ static bool api_wbint_Gid2Sid(pipes_struct *p) return true; } +static bool api_wbint_QueryUser(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_QueryUser *r; + + call = &ndr_table_wbint.calls[NDR_WBINT_QUERYUSER]; + + r = talloc(talloc_tos(), struct wbint_QueryUser); + 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_QueryUser, r); + } + + ZERO_STRUCT(r->out); + r->out.info = talloc_zero(r, struct wbint_userinfo); + if (r->out.info == NULL) { + talloc_free(r); + return false; + } + + r->out.result = _wbint_QueryUser(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_QueryUser, 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[] = @@ -595,6 +675,7 @@ static struct api_struct api_wbint_cmds[] = {"WBINT_SID2GID", NDR_WBINT_SID2GID, api_wbint_Sid2Gid}, {"WBINT_UID2SID", NDR_WBINT_UID2SID, api_wbint_Uid2Sid}, {"WBINT_GID2SID", NDR_WBINT_GID2SID, api_wbint_Gid2Sid}, + {"WBINT_QUERYUSER", NDR_WBINT_QUERYUSER, api_wbint_QueryUser}, }; void wbint_get_pipe_fns(struct api_struct **fns, int *n_fns) @@ -710,6 +791,18 @@ NTSTATUS rpc_wbint_dispatch(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, co return NT_STATUS_OK; } + case NDR_WBINT_QUERYUSER: { + struct wbint_QueryUser *r = (struct wbint_QueryUser *)_r; + ZERO_STRUCT(r->out); + r->out.info = talloc_zero(mem_ctx, struct wbint_userinfo); + if (r->out.info == NULL) { + return NT_STATUS_NO_MEMORY; + } + + r->out.result = _wbint_QueryUser(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 9311e6b641..ddefa6acce 100644 --- a/source3/librpc/gen_ndr/srv_wbint.h +++ b/source3/librpc/gen_ndr/srv_wbint.h @@ -8,6 +8,7 @@ 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 _wbint_QueryUser(pipes_struct *p, struct wbint_QueryUser *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); @@ -17,5 +18,6 @@ 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 _wbint_QueryUser(pipes_struct *p, struct wbint_QueryUser *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 d6f344e5c9..eb3dd0cd33 100644 --- a/source3/librpc/gen_ndr/wbint.h +++ b/source3/librpc/gen_ndr/wbint.h @@ -8,6 +8,16 @@ #ifndef _HEADER_wbint #define _HEADER_wbint +struct wbint_userinfo { + const char *acct_name;/* [unique,charset(UTF8)] */ + const char *full_name;/* [unique,charset(UTF8)] */ + const char *homedir;/* [unique,charset(UTF8)] */ + const char *shell;/* [unique,charset(UTF8)] */ + uint64_t primary_gid; + struct dom_sid user_sid; + struct dom_sid group_sid; +}/* [public] */; + struct wbint_Ping { struct { @@ -107,4 +117,17 @@ struct wbint_Gid2Sid { }; + +struct wbint_QueryUser { + struct { + struct dom_sid *sid;/* [ref] */ + } in; + + struct { + struct wbint_userinfo *info;/* [ref] */ + NTSTATUS result; + } out; + +}; + #endif /* _HEADER_wbint */ diff --git a/source3/librpc/idl/wbint.idl b/source3/librpc/idl/wbint.idl index 93627fbe07..15c4e1f302 100644 --- a/source3/librpc/idl/wbint.idl +++ b/source3/librpc/idl/wbint.idl @@ -53,4 +53,19 @@ interface wbint [in] hyper gid, [out] dom_sid *sid ); + + typedef [public] struct { + [string,charset(UTF8)] char *acct_name; + [string,charset(UTF8)] char *full_name; + [string,charset(UTF8)] char *homedir; + [string,charset(UTF8)] char *shell; + hyper primary_gid; + dom_sid user_sid; + dom_sid group_sid; + } wbint_userinfo; + + NTSTATUS wbint_QueryUser( + [in] dom_sid *sid, + [out] wbint_userinfo *info + ); }
\ No newline at end of file diff --git a/source3/winbindd/wb_queryuser.c b/source3/winbindd/wb_queryuser.c new file mode 100644 index 0000000000..27b8d29951 --- /dev/null +++ b/source3/winbindd/wb_queryuser.c @@ -0,0 +1,121 @@ +/* + Unix SMB/CIFS implementation. + async queryuser + 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_queryuser_state { + struct dom_sid sid; + struct wbint_userinfo info; +}; + +static void wb_queryuser_done(struct tevent_req *subreq); + +struct tevent_req *wb_queryuser_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + const struct dom_sid *user_sid) +{ + struct tevent_req *req, *subreq; + struct wb_queryuser_state *state; + struct winbindd_domain *domain; + struct winbind_userinfo info; + NTSTATUS status; + + req = tevent_req_create(mem_ctx, &state, struct wb_queryuser_state); + if (req == NULL) { + return NULL; + } + sid_copy(&state->sid, user_sid); + + domain = find_domain_from_sid_noinit(user_sid); + if (domain == NULL) { + tevent_req_nterror(req, NT_STATUS_NO_SUCH_USER); + return tevent_req_post(req, ev); + } + + status = wcache_query_user(domain, state, &state->sid, &info); + if (NT_STATUS_IS_OK(status)) { + state->info.acct_name = info.acct_name; + state->info.full_name = info.full_name; + state->info.homedir = info.homedir; + state->info.shell = info.shell; + state->info.primary_gid = info.primary_gid; + sid_copy(&state->info.user_sid, &info.user_sid); + sid_copy(&state->info.group_sid, &info.group_sid); + tevent_req_done(req); + return tevent_req_post(req, ev); + } + + subreq = rpccli_wbint_QueryUser_send(state, ev, domain->child.rpccli, + &state->sid, &state->info); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, wb_queryuser_done, req); + return req; +} + +static void wb_queryuser_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct wb_queryuser_state *state = tevent_req_data( + req, struct wb_queryuser_state); + NTSTATUS status, result; + + status = rpccli_wbint_QueryUser_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_queryuser_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, + struct winbind_userinfo **pinfo) +{ + struct wb_queryuser_state *state = tevent_req_data( + req, struct wb_queryuser_state); + struct winbind_userinfo *info; + NTSTATUS status; + + if (tevent_req_is_nterror(req, &status)) { + return status; + } + + info = talloc(mem_ctx, struct winbind_userinfo); + if (info == NULL) { + return NT_STATUS_NO_MEMORY; + } + info->acct_name = talloc_move(info, &state->info.acct_name); + info->full_name = talloc_move(info, &state->info.full_name); + info->homedir = talloc_move(info, &state->info.homedir); + info->shell = talloc_move(info, &state->info.shell); + info->primary_gid = state->info.primary_gid; + sid_copy(&info->user_sid, &state->info.user_sid); + sid_copy(&info->group_sid, &state->info.group_sid); + *pinfo = info; + return NT_STATUS_OK; +} diff --git a/source3/winbindd/winbindd_dual_srv.c b/source3/winbindd/winbindd_dual_srv.c index 35fecbd08e..202cca4434 100644 --- a/source3/winbindd/winbindd_dual_srv.c +++ b/source3/winbindd/winbindd_dual_srv.c @@ -117,3 +117,30 @@ NTSTATUS _wbint_Gid2Sid(pipes_struct *p, struct wbint_Gid2Sid *r) } return NT_STATUS_OK; } + +NTSTATUS _wbint_QueryUser(pipes_struct *p, struct wbint_QueryUser *r) +{ + struct winbindd_domain *domain = wb_child_domain(); + WINBIND_USERINFO uinfo; + NTSTATUS status; + + if (domain == NULL) { + return NT_STATUS_REQUEST_NOT_ACCEPTED; + } + + status = domain->methods->query_user(domain, p->mem_ctx, r->in.sid, + &uinfo); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + r->out.info->acct_name = uinfo.acct_name; + r->out.info->full_name = uinfo.full_name; + r->out.info->homedir = uinfo.homedir; + r->out.info->shell = uinfo.shell; + r->out.info->primary_gid = uinfo.primary_gid; + sid_copy(&r->out.info->user_sid, &uinfo.user_sid); + sid_copy(&r->out.info->group_sid, &uinfo.group_sid); + + return NT_STATUS_OK; +} diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h index 1f0d5b5d5b..5f93391363 100644 --- a/source3/winbindd/winbindd_proto.h +++ b/source3/winbindd/winbindd_proto.h @@ -685,5 +685,10 @@ struct tevent_req *winbindd_gid_to_sid_send(TALLOC_CTX *mem_ctx, NTSTATUS winbindd_gid_to_sid_recv(struct tevent_req *req, struct winbindd_response *response); +struct tevent_req *wb_queryuser_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + const struct dom_sid *user_sid); +NTSTATUS wb_queryuser_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, + struct winbind_userinfo **pinfo); #endif /* _WINBINDD_PROTO_H_ */ |