summaryrefslogtreecommitdiff
path: root/source3/librpc/rpc/dcerpc.c
blob: 7609757417a2403cb1ad2aa477a2da7ed92689b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* 
   Unix SMB/CIFS implementation.
   Samba utility functions
   Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
   
   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 "librpc/rpc/dcerpc.h"

struct rpc_request *dcerpc_ndr_request_send(struct dcerpc_pipe *p, const struct GUID *object, 
					    const struct ndr_interface_table *table, uint32_t opnum, 
					    TALLOC_CTX *mem_ctx, void *r)
{
	const struct ndr_interface_call *call;
	struct ndr_push *push;
	struct rpc_request *ret = talloc(mem_ctx, struct rpc_request);
	enum ndr_err_code ndr_err;
	DATA_BLOB blob;

	if (ret == NULL)
		return NULL;

	SMB_ASSERT(p->table->num_calls > opnum);

	call = &p->table->calls[opnum];

	ret->call = call;
	ret->r = r;

	push = ndr_push_init_ctx(mem_ctx);
	if (!push) {
		return NULL;
	}

	ndr_err = call->ndr_push(push, NDR_IN, r);
	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
		/* FIXME: ndr_map_error2ntstatus(ndr_err); */
		return NULL;
	}

	blob = ndr_push_blob(push);

	if (!prs_init_data_blob(&ret->q_ps, &blob, mem_ctx)) {
		return NULL;
	}

	talloc_free(push);

	ret->opnum = opnum;

	return ret;
}

NTSTATUS dcerpc_ndr_request_recv(struct rpc_request *req)
{
	prs_struct r_ps;
	struct ndr_pull *pull;
	NTSTATUS status;
	DATA_BLOB blob;
	enum ndr_err_code ndr_err;

	prs_init_empty( &r_ps, req, UNMARSHALL );

	status = rpc_api_pipe_req(req->pipe->cli, req->opnum, &req->q_ps, &r_ps); 

	prs_mem_free( &req->q_ps );

	if (!NT_STATUS_IS_OK(status)) {
		prs_mem_free( &r_ps );
		return status;
	}

	if (!prs_data_blob(&r_ps, &blob, req)) {
		prs_mem_free( &r_ps );
		return NT_STATUS_NO_MEMORY;
	}

	prs_mem_free( &r_ps );

	pull = ndr_pull_init_blob(&blob, req);
	if (pull == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	/* have the ndr parser alloc memory for us */
	pull->flags |= LIBNDR_FLAG_REF_ALLOC;
	ndr_err = req->call->ndr_pull(pull, NDR_OUT, req->r);
	talloc_free(pull);

	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
		return ndr_map_error2ntstatus(ndr_err);
	}



	return NT_STATUS_NOT_IMPLEMENTED;
}

_PUBLIC_ NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx, struct dcerpc_pipe **pp, 
				      const char *binding_string, const struct ndr_interface_table *table, 
				      struct cli_credentials *credentials, struct event_context *ev, 
				      struct loadparm_context *lp_ctx)
{
	struct dcerpc_pipe *p = talloc(parent_ctx, struct dcerpc_pipe);
	struct dcerpc_binding *binding;
	NTSTATUS nt_status;

	nt_status = dcerpc_parse_binding(p, binding_string, &binding);

	if (NT_STATUS_IS_ERR(nt_status)) {
		DEBUG(1, ("Unable to parse binding string '%s'", binding));
		return nt_status;
	}

	/* FIXME: Actually use loadparm_context.. */

	/* FIXME: actually use credentials */

	nt_status = cli_full_connection(&p->cli, global_myname(), binding->host,
					NULL, 0, 
					"IPC$", "IPC",
					get_cmdline_auth_info_username(),
					lp_workgroup(),
					get_cmdline_auth_info_password(),
					get_cmdline_auth_info_use_kerberos() ? CLI_FULL_CONNECTION_USE_KERBEROS : 0,
					get_cmdline_auth_info_signing_state(), NULL);

	p->table = table;

	*pp = p;

	return nt_status;
}