Share RPC binding string utility functions.
[kai/samba.git] / source3 / rpc_client / ndr.c
index 82b9079a28d3a02ea9e36371abf6f2941c9a869f..9ada47a3f5d901aeecbe456dd82a990e4ee0b771 100644 (file)
@@ -7,7 +7,7 @@
    
    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 2 of the License, or
+   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,
    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, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 
 
-NTSTATUS cli_do_rpc_ndr(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, 
-                       int p_idx, int opnum, void *data, 
-                       ndr_pull_flags_fn_t pull_fn, ndr_push_flags_fn_t push_fn)
+NTSTATUS cli_do_rpc_ndr(struct rpc_pipe_client *cli,
+                       TALLOC_CTX *mem_ctx,
+                       const struct ndr_interface_table *table,
+                       uint32 opnum, void *r)
 {
        prs_struct q_ps, r_ps;
+       const struct ndr_interface_call *call;
        struct ndr_pull *pull;
        DATA_BLOB blob;
        struct ndr_push *push;
        NTSTATUS status;
+       enum ndr_err_code ndr_err;
 
-       SMB_ASSERT(cli->pipe_idx == p_idx);
+       SMB_ASSERT(ndr_syntax_id_equal(&table->syntax_id,
+                                      &cli->abstract_syntax));
+       SMB_ASSERT(table->num_calls > opnum);
 
-       push = ndr_push_init_ctx(mem_ctx);
+       call = &table->calls[opnum];
+
+       push = ndr_push_init_ctx(mem_ctx, NULL);
        if (!push) {
                return NT_STATUS_NO_MEMORY;
        }
 
-       status = push_fn(push, NDR_IN, data);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
+       ndr_err = call->ndr_push(push, NDR_IN, r);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               return ndr_map_error2ntstatus(ndr_err);
        }
 
        blob = ndr_push_blob(push);
@@ -53,11 +59,8 @@ NTSTATUS cli_do_rpc_ndr(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
 
        talloc_free(push);
 
-       if (!prs_init( &r_ps, 0, mem_ctx, UNMARSHALL )) {
-               prs_mem_free( &q_ps );
-               return NT_STATUS_NO_MEMORY;
-       }
-       
+       prs_init_empty( &r_ps, mem_ctx, UNMARSHALL );
+
        status = rpc_api_pipe_req(cli, opnum, &q_ps, &r_ps); 
 
        prs_mem_free( &q_ps );
@@ -74,18 +77,18 @@ NTSTATUS cli_do_rpc_ndr(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
 
        prs_mem_free( &r_ps );
 
-       pull = ndr_pull_init_blob(&blob, mem_ctx);
+       pull = ndr_pull_init_blob(&blob, mem_ctx, NULL);
        if (pull == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
 
        /* have the ndr parser alloc memory for us */
        pull->flags |= LIBNDR_FLAG_REF_ALLOC;
-       status = pull_fn(pull, NDR_OUT, data);
+       ndr_err = call->ndr_pull(pull, NDR_OUT, r);
        talloc_free(pull);
 
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               return ndr_map_error2ntstatus(ndr_err);
        }
 
        return NT_STATUS_OK;