s3-dcerpc: Move common helpers into a common file
authorSimo Sorce <idra@samba.org>
Wed, 14 Jul 2010 16:18:49 +0000 (12:18 -0400)
committerGünther Deschner <gd@samba.org>
Thu, 15 Jul 2010 23:51:17 +0000 (01:51 +0200)
Signed-off-by: Günther Deschner <gd@samba.org>
source3/Makefile.in
source3/include/proto.h
source3/librpc/rpc/dcerpc.h
source3/librpc/rpc/dcerpc_helpers.c [new file with mode: 0644]
source3/rpc_client/cli_pipe.c

index a4b71f0765e0b547c71d9ea555e4a34c4b76cda5..99674268ed42f83b8a223fab778cb85bdf7f4a65 100644 (file)
@@ -564,6 +564,7 @@ LIBMSRPC_GEN_OBJ = librpc/gen_ndr/cli_lsa.o \
                   librpc/gen_ndr/cli_drsuapi.o \
                   librpc/gen_ndr/cli_spoolss.o \
                   ../librpc/rpc/dcerpc_util.o \
+                  librpc/rpc/dcerpc_helpers.o \
                   $(LIBNDR_GEN_OBJ) \
                   $(RPCCLIENT_NDR_OBJ)
 
index 04136a9a0d28c52c6f8230d2c8fadf01845b9449..735f5e2bf822c378868920923ccb35400a905cc7 100644 (file)
@@ -4852,26 +4852,6 @@ struct tevent_req *rpc_api_pipe_req_send(TALLOC_CTX *mem_ctx,
                                         prs_struct *req_data);
 NTSTATUS rpc_api_pipe_req_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
                               prs_struct *reply_pdu);
-NTSTATUS dcerpc_push_ncacn_packet(TALLOC_CTX *mem_ctx,
-                                 enum dcerpc_pkt_type ptype,
-                                 uint8_t pfc_flags,
-                                 uint16_t auth_length,
-                                 uint32_t call_id,
-                                 union dcerpc_payload *u,
-                                 DATA_BLOB *blob);
-NTSTATUS dcerpc_pull_ncacn_packet(TALLOC_CTX *mem_ctx,
-                                 const DATA_BLOB *blob,
-                                 struct ncacn_packet *r);
-NTSTATUS dcerpc_push_dcerpc_auth(TALLOC_CTX *mem_ctx,
-                                enum dcerpc_AuthType auth_type,
-                                enum dcerpc_AuthLevel auth_level,
-                                uint8_t auth_pad_length,
-                                uint32_t auth_context_id,
-                                const DATA_BLOB *credentials,
-                                DATA_BLOB *blob);
-NTSTATUS dcerpc_pull_dcerpc_auth(TALLOC_CTX *mem_ctx,
-                                const DATA_BLOB *blob,
-                                struct dcerpc_auth *r);
 struct tevent_req *rpc_pipe_bind_send(TALLOC_CTX *mem_ctx,
                                      struct event_context *ev,
                                      struct rpc_pipe_client *cli,
index 0c120dfef5efc41fc2207a488c73950ad22ab4cf..d18920ca0dba5cf58331ef91f0a8a497ca541c04 100644 (file)
@@ -111,4 +111,31 @@ _PUBLIC_ NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx,
                                             const struct dcerpc_binding *binding,
                                             struct epm_tower *tower);
 
+struct NL_AUTH_MESSAGE;
+
+/* The following definitions come from librpc/rpc/dcerpc_helpers.c  */
+NTSTATUS dcerpc_push_ncacn_packet(TALLOC_CTX *mem_ctx,
+                                 enum dcerpc_pkt_type ptype,
+                                 uint8_t pfc_flags,
+                                 uint16_t auth_length,
+                                 uint32_t call_id,
+                                 union dcerpc_payload *u,
+                                 DATA_BLOB *blob);
+NTSTATUS dcerpc_pull_ncacn_packet(TALLOC_CTX *mem_ctx,
+                                 const DATA_BLOB *blob,
+                                 struct ncacn_packet *r);
+NTSTATUS dcerpc_push_schannel_bind(TALLOC_CTX *mem_ctx,
+                                  struct NL_AUTH_MESSAGE *r,
+                                  DATA_BLOB *blob);
+NTSTATUS dcerpc_push_dcerpc_auth(TALLOC_CTX *mem_ctx,
+                                enum dcerpc_AuthType auth_type,
+                                enum dcerpc_AuthLevel auth_level,
+                                uint8_t auth_pad_length,
+                                uint32_t auth_context_id,
+                                const DATA_BLOB *credentials,
+                                DATA_BLOB *blob);
+NTSTATUS dcerpc_pull_dcerpc_auth(TALLOC_CTX *mem_ctx,
+                                const DATA_BLOB *blob,
+                                struct dcerpc_auth *r);
+
 #endif /* __DCERPC_H__ */
diff --git a/source3/librpc/rpc/dcerpc_helpers.c b/source3/librpc/rpc/dcerpc_helpers.c
new file mode 100644 (file)
index 0000000..ce48a69
--- /dev/null
@@ -0,0 +1,212 @@
+/*
+ *  DCERPC Helper routines
+ *  Günther Deschner <gd@samba.org> 2010.
+ *  Simo Sorce <idra@samba.org> 2010.
+ *
+ *  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"
+#include "librpc/gen_ndr/ndr_dcerpc.h"
+#include "librpc/gen_ndr/ndr_schannel.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_RPC_PARSE
+
+/**
+* @brief NDR Encodes a ncacn_packet
+*
+* @param mem_ctx       The memory context the blob will be allocated on
+* @param ptype         The DCERPC packet type
+* @param pfc_flags     The DCERPC PFC Falgs
+* @param auth_length   The length of the trailing auth blob
+* @param call_id       The call ID
+* @param u             The payload of the packet
+* @param blob [out]    The encoded blob if successful
+*
+* @return an NTSTATUS error code
+*/
+NTSTATUS dcerpc_push_ncacn_packet(TALLOC_CTX *mem_ctx,
+                                 enum dcerpc_pkt_type ptype,
+                                 uint8_t pfc_flags,
+                                 uint16_t auth_length,
+                                 uint32_t call_id,
+                                 union dcerpc_payload *u,
+                                 DATA_BLOB *blob)
+{
+       struct ncacn_packet r;
+       enum ndr_err_code ndr_err;
+
+       r.rpc_vers              = 5;
+       r.rpc_vers_minor        = 0;
+       r.ptype                 = ptype;
+       r.pfc_flags             = pfc_flags;
+       r.drep[0]               = DCERPC_DREP_LE;
+       r.drep[1]               = 0;
+       r.drep[2]               = 0;
+       r.drep[3]               = 0;
+       r.auth_length           = auth_length;
+       r.call_id               = call_id;
+       r.u                     = *u;
+
+       ndr_err = ndr_push_struct_blob(blob, mem_ctx, &r,
+               (ndr_push_flags_fn_t)ndr_push_ncacn_packet);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               return ndr_map_error2ntstatus(ndr_err);
+       }
+
+       dcerpc_set_frag_length(blob, blob->length);
+
+
+       if (DEBUGLEVEL >= 10) {
+               /* set frag len for print function */
+               r.frag_length = blob->length;
+               NDR_PRINT_DEBUG(ncacn_packet, &r);
+       }
+
+       return NT_STATUS_OK;
+}
+
+/**
+* @brief Decodes a ncacn_packet
+*
+* @param mem_ctx       The memory context on which to allocate the packet
+*                      elements
+* @param blob          The blob of data to decode
+* @param r             An empty ncacn_packet, must not be NULL
+*
+* @return a NTSTATUS error code
+*/
+NTSTATUS dcerpc_pull_ncacn_packet(TALLOC_CTX *mem_ctx,
+                                 const DATA_BLOB *blob,
+                                 struct ncacn_packet *r)
+{
+       enum ndr_err_code ndr_err;
+
+       ndr_err = ndr_pull_struct_blob(blob, mem_ctx, r,
+               (ndr_pull_flags_fn_t)ndr_pull_ncacn_packet);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               return ndr_map_error2ntstatus(ndr_err);
+       }
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_DEBUG(ncacn_packet, r);
+       }
+
+       return NT_STATUS_OK;
+}
+
+/**
+* @brief NDR Encodes a NL_AUTH_MESSAGE
+*
+* @param mem_ctx       The memory context the blob will be allocated on
+* @param r             The NL_AUTH_MESSAGE to encode
+* @param blob [out]    The encoded blob if successful
+*
+* @return a NTSTATUS error code
+*/
+NTSTATUS dcerpc_push_schannel_bind(TALLOC_CTX *mem_ctx,
+                                  struct NL_AUTH_MESSAGE *r,
+                                  DATA_BLOB *blob)
+{
+       enum ndr_err_code ndr_err;
+
+       ndr_err = ndr_push_struct_blob(blob, mem_ctx, r,
+               (ndr_push_flags_fn_t)ndr_push_NL_AUTH_MESSAGE);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               return ndr_map_error2ntstatus(ndr_err);
+       }
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_DEBUG(NL_AUTH_MESSAGE, r);
+       }
+
+       return NT_STATUS_OK;
+}
+
+/**
+* @brief NDR Encodes a dcerpc_auth structure
+*
+* @param mem_ctx         The memory context the blob will be allocated on
+* @param auth_type       The DCERPC Authentication Type
+* @param auth_level      The DCERPC Authentication Level
+* @param auth_pad_length  The padding added to the packet this blob will be
+*                         appended to.
+* @param auth_context_id  The context id
+* @param credentials     The authentication credentials blob (signature)
+* @param blob [out]      The encoded blob if successful
+*
+* @return a NTSTATUS error code
+*/
+NTSTATUS dcerpc_push_dcerpc_auth(TALLOC_CTX *mem_ctx,
+                                enum dcerpc_AuthType auth_type,
+                                enum dcerpc_AuthLevel auth_level,
+                                uint8_t auth_pad_length,
+                                uint32_t auth_context_id,
+                                const DATA_BLOB *credentials,
+                                DATA_BLOB *blob)
+{
+       struct dcerpc_auth r;
+       enum ndr_err_code ndr_err;
+
+       r.auth_type             = auth_type;
+       r.auth_level            = auth_level;
+       r.auth_pad_length       = auth_pad_length;
+       r.auth_reserved         = 0;
+       r.auth_context_id       = auth_context_id;
+       r.credentials           = *credentials;
+
+       ndr_err = ndr_push_struct_blob(blob, mem_ctx, &r,
+               (ndr_push_flags_fn_t)ndr_push_dcerpc_auth);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               return ndr_map_error2ntstatus(ndr_err);
+       }
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_DEBUG(dcerpc_auth, &r);
+       }
+
+       return NT_STATUS_OK;
+}
+
+/**
+* @brief Decodes a dcerpc_auth blob
+*
+* @param mem_ctx       The memory context on which to allocate the packet
+*                      elements
+* @param blob          The blob of data to decode
+* @param r             An empty dcerpc_auth structure, must not be NULL
+*
+* @return a NTSTATUS error code
+*/
+NTSTATUS dcerpc_pull_dcerpc_auth(TALLOC_CTX *mem_ctx,
+                                const DATA_BLOB *blob,
+                                struct dcerpc_auth *r)
+{
+       enum ndr_err_code ndr_err;
+
+       ndr_err = ndr_pull_struct_blob(blob, mem_ctx, r,
+               (ndr_pull_flags_fn_t)ndr_pull_dcerpc_auth);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               return ndr_map_error2ntstatus(ndr_err);
+       }
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_DEBUG(dcerpc_auth, r);
+       }
+
+       return NT_STATUS_OK;
+}
index 81bc0b308e080ec62b6a57364283d48f6c05aa9c..0f1d4a85db52d45d66084af535c672ef8d3ada1e 100644 (file)
@@ -42,6 +42,7 @@
 #include "../libcli/auth/ntlmssp.h"
 #include "rpc_client/cli_netlogon.h"
 #include "librpc/gen_ndr/ndr_dcerpc.h"
+#include "librpc/rpc/dcerpc.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_RPC_CLI
@@ -294,116 +295,6 @@ static bool rpc_grow_buffer(prs_struct *pdu, size_t size)
        return true;
 }
 
-/*******************************************************************
-*******************************************************************/
-
-NTSTATUS dcerpc_push_ncacn_packet(TALLOC_CTX *mem_ctx,
-                                 enum dcerpc_pkt_type ptype,
-                                 uint8_t pfc_flags,
-                                 uint16_t auth_length,
-                                 uint32_t call_id,
-                                 union dcerpc_payload *u,
-                                 DATA_BLOB *blob)
-{
-       struct ncacn_packet r;
-       enum ndr_err_code ndr_err;
-
-       r.rpc_vers              = 5;
-       r.rpc_vers_minor        = 0;
-       r.ptype                 = ptype;
-       r.pfc_flags             = pfc_flags;
-       r.drep[0]               = DCERPC_DREP_LE;
-       r.drep[1]               = 0;
-       r.drep[2]               = 0;
-       r.drep[3]               = 0;
-       r.auth_length           = auth_length;
-       r.call_id               = call_id;
-       r.u                     = *u;
-
-       ndr_err = ndr_push_struct_blob(blob, mem_ctx, &r,
-               (ndr_push_flags_fn_t)ndr_push_ncacn_packet);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               return ndr_map_error2ntstatus(ndr_err);
-       }
-
-       dcerpc_set_frag_length(blob, blob->length);
-
-
-       if (DEBUGLEVEL >= 10) {
-               /* set frag len for print function */
-               r.frag_length = blob->length;
-               NDR_PRINT_DEBUG(ncacn_packet, &r);
-       }
-
-       return NT_STATUS_OK;
-}
-
-/*******************************************************************
-*******************************************************************/
-
-NTSTATUS dcerpc_pull_ncacn_packet(TALLOC_CTX *mem_ctx,
-                                 const DATA_BLOB *blob,
-                                 struct ncacn_packet *r)
-{
-       enum ndr_err_code ndr_err;
-
-       ndr_err = ndr_pull_struct_blob(blob, mem_ctx, r,
-               (ndr_pull_flags_fn_t)ndr_pull_ncacn_packet);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               return ndr_map_error2ntstatus(ndr_err);
-       }
-
-       if (DEBUGLEVEL >= 10) {
-               NDR_PRINT_DEBUG(ncacn_packet, r);
-       }
-
-       return NT_STATUS_OK;
-}
-
-/*******************************************************************
- ********************************************************************/
-
-static NTSTATUS dcerpc_push_schannel_bind(TALLOC_CTX *mem_ctx,
-                                         struct NL_AUTH_MESSAGE *r,
-                                         DATA_BLOB *blob)
-{
-       enum ndr_err_code ndr_err;
-
-       ndr_err = ndr_push_struct_blob(blob, mem_ctx, r,
-               (ndr_push_flags_fn_t)ndr_push_NL_AUTH_MESSAGE);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               return ndr_map_error2ntstatus(ndr_err);
-       }
-
-       if (DEBUGLEVEL >= 10) {
-               NDR_PRINT_DEBUG(NL_AUTH_MESSAGE, r);
-       }
-
-       return NT_STATUS_OK;
-}
-
-/*******************************************************************
- ********************************************************************/
-
-NTSTATUS dcerpc_pull_dcerpc_auth(TALLOC_CTX *mem_ctx,
-                                const DATA_BLOB *blob,
-                                struct dcerpc_auth *r)
-{
-       enum ndr_err_code ndr_err;
-
-       ndr_err = ndr_pull_struct_blob(blob, mem_ctx, r,
-               (ndr_pull_flags_fn_t)ndr_pull_dcerpc_auth);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               return ndr_map_error2ntstatus(ndr_err);
-       }
-
-       if (DEBUGLEVEL >= 10) {
-               NDR_PRINT_DEBUG(dcerpc_auth, r);
-       }
-
-       return NT_STATUS_OK;
-}
-
 /*******************************************************************
  Use SMBreadX to get rest of one fragment's worth of rpc data.
  Reads the whole size or give an error message
@@ -1680,41 +1571,6 @@ static NTSTATUS rpc_api_pipe_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
        return NT_STATUS_OK;
 }
 
-/*******************************************************************
- Creates an auth_data blob.
- ********************************************************************/
-
-NTSTATUS dcerpc_push_dcerpc_auth(TALLOC_CTX *mem_ctx,
-                                enum dcerpc_AuthType auth_type,
-                                enum dcerpc_AuthLevel auth_level,
-                                uint8_t auth_pad_length,
-                                uint32_t auth_context_id,
-                                const DATA_BLOB *credentials,
-                                DATA_BLOB *blob)
-{
-       struct dcerpc_auth r;
-       enum ndr_err_code ndr_err;
-
-       r.auth_type             = auth_type;
-       r.auth_level            = auth_level;
-       r.auth_pad_length       = auth_pad_length;
-       r.auth_reserved         = 0;
-       r.auth_context_id       = auth_context_id;
-       r.credentials           = *credentials;
-
-       ndr_err = ndr_push_struct_blob(blob, mem_ctx, &r,
-               (ndr_push_flags_fn_t)ndr_push_dcerpc_auth);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               return ndr_map_error2ntstatus(ndr_err);
-       }
-
-       if (DEBUGLEVEL >= 10) {
-               NDR_PRINT_DEBUG(dcerpc_auth, &r);
-       }
-
-       return NT_STATUS_OK;
-}
-
 /*******************************************************************
  Creates krb5 auth bind.
  ********************************************************************/