spoolss: hand-marshall the spoolss_StringArray2 struct for spoolss_EnumPrinterKey.
[Samba.git] / source3 / librpc / rpc / dcerpc.c
blobe6c4cb446b60abf4c5fd70ebe009a9e272bcf9a7
1 /*
2 Unix SMB/CIFS implementation.
3 Samba 4-compatible DCE/RPC API on top of the Samba 3 DCE/RPC client library.
4 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "librpc/rpc/dcerpc.h"
23 /**
24 * Send a struct-based RPC request using the Samba 3 RPC client library.
26 struct rpc_request *dcerpc_ndr_request_send(struct dcerpc_pipe *p, const struct GUID *object,
27 const struct ndr_interface_table *table, uint32_t opnum,
28 TALLOC_CTX *mem_ctx, void *r)
30 const struct ndr_interface_call *call;
31 struct ndr_push *push;
32 struct rpc_request *ret = talloc(mem_ctx, struct rpc_request);
33 enum ndr_err_code ndr_err;
34 DATA_BLOB blob;
36 if (ret == NULL)
37 return NULL;
39 SMB_ASSERT(p->table->num_calls > opnum);
41 call = &p->table->calls[opnum];
43 ret->call = call;
44 ret->r = r;
46 push = ndr_push_init_ctx(mem_ctx, NULL);
47 if (!push) {
48 return NULL;
51 ndr_err = call->ndr_push(push, NDR_IN, r);
52 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
53 /* FIXME: ndr_map_error2ntstatus(ndr_err); */
54 return NULL;
57 blob = ndr_push_blob(push);
59 if (!prs_init_data_blob(&ret->q_ps, &blob, mem_ctx)) {
60 return NULL;
63 talloc_free(push);
65 ret->opnum = opnum;
67 ret->pipe = p;
69 return ret;
72 #if 0
74 Completely unfinished and unused -- vl :-)
76 /**
77 * Wait for a DCE/RPC request.
79 * @note at the moment this is still sync, even though the API is async.
81 NTSTATUS dcerpc_ndr_request_recv(struct rpc_request *req)
83 prs_struct r_ps;
84 struct ndr_pull *pull;
85 NTSTATUS status;
86 DATA_BLOB blob;
87 enum ndr_err_code ndr_err;
89 prs_init_empty( &r_ps, req, UNMARSHALL );
91 status = rpc_api_pipe_req(req, req->pipe->rpc_cli, req->opnum,
92 &req->q_ps, &r_ps);
94 prs_mem_free( &req->q_ps );
96 if (!NT_STATUS_IS_OK(status)) {
97 prs_mem_free( &r_ps );
98 return status;
101 if (!prs_data_blob(&r_ps, &blob, req)) {
102 prs_mem_free( &r_ps );
103 return NT_STATUS_NO_MEMORY;
106 prs_mem_free( &r_ps );
108 pull = ndr_pull_init_blob(&blob, req, NULL);
109 if (pull == NULL) {
110 return NT_STATUS_NO_MEMORY;
113 /* have the ndr parser alloc memory for us */
114 pull->flags |= LIBNDR_FLAG_REF_ALLOC;
115 ndr_err = req->call->ndr_pull(pull, NDR_OUT, req->r);
116 talloc_free(pull);
118 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
119 return ndr_map_error2ntstatus(ndr_err);
122 return NT_STATUS_OK;
126 * Connect to a DCE/RPC interface.
128 * @note lp_ctx and ev are ignored at the moment but present
129 * for API compatibility.
131 _PUBLIC_ NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx, struct dcerpc_pipe **pp,
132 const char *binding_string, const struct ndr_interface_table *table,
133 struct cli_credentials *credentials, struct event_context *ev,
134 struct loadparm_context *lp_ctx)
136 struct dcerpc_pipe *p = talloc(parent_ctx, struct dcerpc_pipe);
137 struct dcerpc_binding *binding;
138 NTSTATUS nt_status;
140 nt_status = dcerpc_parse_binding(p, binding_string, &binding);
142 if (NT_STATUS_IS_ERR(nt_status)) {
143 DEBUG(1, ("Unable to parse binding string '%s'", binding_string));
144 talloc_free(p);
145 return nt_status;
148 if (binding->transport != NCACN_NP) {
149 DEBUG(0, ("Only ncacn_np supported"));
150 talloc_free(p);
151 return NT_STATUS_NOT_SUPPORTED;
154 /* FIXME: Actually use loadparm_context.. */
156 /* FIXME: actually use credentials */
158 nt_status = cli_full_connection(&p->cli, global_myname(), binding->host,
159 NULL, 0,
160 "IPC$", "IPC",
161 get_cmdline_auth_info_username(),
162 lp_workgroup(),
163 get_cmdline_auth_info_password(),
164 get_cmdline_auth_info_use_kerberos() ? CLI_FULL_CONNECTION_USE_KERBEROS : 0,
165 get_cmdline_auth_info_signing_state(), NULL);
167 if (NT_STATUS_IS_ERR(nt_status)) {
168 talloc_free(p);
169 return nt_status;
172 nt_status = cli_rpc_pipe_open_noauth(p->cli, &table->syntax_id,
173 &p->rpc_cli);
175 if (!NT_STATUS_IS_OK(nt_status)) {
176 talloc_free(p);
177 return nt_status;
180 p->table = table;
182 *pp = p;
184 return nt_status;
187 #endif