source: branches/samba-3.0/source/rpc_client/ndr.c

Last change on this file was 1, checked in by Paul Smedley, 19 years ago

Initial code import

File size: 2.1 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3
4 libndr interface
5
6 Copyright (C) Jelmer Vernooij 2006
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/
22
23#include "includes.h"
24
25
26NTSTATUS cli_do_rpc_ndr(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
27 int p_idx, int opnum, void *data,
28 ndr_pull_flags_fn_t pull_fn, ndr_push_flags_fn_t push_fn)
29{
30 prs_struct q_ps, r_ps;
31 struct ndr_pull *pull;
32 DATA_BLOB blob;
33 struct ndr_push *push;
34 NTSTATUS status;
35
36 SMB_ASSERT(cli->pipe_idx == p_idx);
37
38 push = ndr_push_init_ctx(mem_ctx);
39 if (!push) {
40 return NT_STATUS_NO_MEMORY;
41 }
42
43 status = push_fn(push, NDR_IN, data);
44 if (!NT_STATUS_IS_OK(status)) {
45 return status;
46 }
47
48 blob = ndr_push_blob(push);
49
50 if (!prs_init_data_blob(&q_ps, &blob, mem_ctx)) {
51 return NT_STATUS_NO_MEMORY;
52 }
53
54 talloc_free(push);
55
56 if (!prs_init( &r_ps, 0, mem_ctx, UNMARSHALL )) {
57 prs_mem_free( &q_ps );
58 return NT_STATUS_NO_MEMORY;
59 }
60
61 status = rpc_api_pipe_req(cli, opnum, &q_ps, &r_ps);
62
63 prs_mem_free( &q_ps );
64
65 if (!NT_STATUS_IS_OK(status)) {
66 prs_mem_free( &r_ps );
67 return status;
68 }
69
70 if (!prs_data_blob(&r_ps, &blob, mem_ctx)) {
71 prs_mem_free( &r_ps );
72 return NT_STATUS_NO_MEMORY;
73 }
74
75 prs_mem_free( &r_ps );
76
77 pull = ndr_pull_init_blob(&blob, mem_ctx);
78 if (pull == NULL) {
79 return NT_STATUS_NO_MEMORY;
80 }
81
82 /* have the ndr parser alloc memory for us */
83 pull->flags |= LIBNDR_FLAG_REF_ALLOC;
84 status = pull_fn(pull, NDR_OUT, data);
85 talloc_free(pull);
86
87 if (!NT_STATUS_IS_OK(status)) {
88 return status;
89 }
90
91 return NT_STATUS_OK;
92}
Note: See TracBrowser for help on using the repository browser.