librpc: Unify packet dumping on ndr_pull() failure
authorAndrew Bartlett <abartlet@samba.org>
Mon, 11 Nov 2019 02:02:30 +0000 (15:02 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 20 Nov 2019 02:14:56 +0000 (02:14 +0000)
There were two duplicate implementations of packet dumping just for the s4 RPC server!

This unifies them and makes them easier to find because they are not triggered
from the generated server stub any more.

The behaviour have unified on setting "dcesrv:stubs directory" and
being compiled with --enable-developer.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Samuel Cabrero <scabrero@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Wed Nov 20 02:14:56 UTC 2019 on sn-devel-184

librpc/rpc/dcerpc_util.c
librpc/rpc/dcesrv_core.c
librpc/rpc/rpc_common.h
pidl/lib/Parse/Pidl/Samba4/COM/Stub.pm
pidl/lib/Parse/Pidl/Samba4/NDR/Server.pm
source4/librpc/rpc/dcerpc.h
source4/rpc_server/remote/dcesrv_remote.c
source4/torture/rpc/spoolss_notify.c

index 32df534d5d9f426dbfb8a50509b2defe89eb066b..7e2d06e0cef5133c1243d0e93136bb3396c7aefd 100644 (file)
@@ -1410,25 +1410,30 @@ NTSTATUS dcerpc_ncacn_push_auth(DATA_BLOB *blob,
   log a rpc packet in a format suitable for ndrdump. This is especially useful
   for sealed packets, where ethereal cannot easily see the contents
 
-  this triggers on a debug level of >= 10
+  this triggers if "dcesrv:stubs directory" is set and present
+  for all packets that fail to parse
 */
-void dcerpc_log_packet(const char *lockdir,
-                      const struct ndr_interface_table *ndr,
+void dcerpc_log_packet(const char *packet_log_dir,
+                      const char *interface_name,
                       uint32_t opnum, uint32_t flags,
-                      const DATA_BLOB *pkt)
+                      const DATA_BLOB *pkt,
+                      const char *why)
 {
        const int num_examples = 20;
        int i;
 
-       if (lockdir == NULL) return;
+       if (packet_log_dir == NULL) {
+               return;
+       }
 
        for (i=0;i<num_examples;i++) {
                char *name=NULL;
                int ret;
                bool saved;
-               ret = asprintf(&name, "%s/rpclog/%s-%u.%d.%s",
-                              lockdir, ndr->name, opnum, i,
-                              (flags&NDR_IN)?"in":"out");
+               ret = asprintf(&name, "%s/%s-%u.%d.%s.%s",
+                              packet_log_dir, interface_name, opnum, i,
+                              (flags&NDR_IN)?"in":"out",
+                              why);
                if (ret == -1) {
                        return;
                }
index 902e82887f7308ac75d2fe75050445a19816f915..b7360abfcf79b71f8698c0fcb1f0e18f9d8d5d11 100644 (file)
@@ -541,7 +541,10 @@ _PUBLIC_ NTSTATUS dcesrv_endpoint_connect(struct dcesrv_context *dce_ctx,
 
        p->dce_ctx = dce_ctx;
        p->endpoint = ep;
-       p->packet_log_dir = lpcfg_lock_directory(dce_ctx->lp_ctx);
+       p->packet_log_dir = lpcfg_parm_string(dce_ctx->lp_ctx,
+                                             NULL,
+                                             "dcesrv",
+                                             "stubs directory");
        p->event_ctx = event_ctx;
        p->state_flags = state_flags;
        p->allow_bind = true;
@@ -1693,21 +1696,12 @@ static void dcesrv_alter_done(struct tevent_req *subreq)
 static void dcesrv_save_call(struct dcesrv_call_state *call, const char *why)
 {
 #ifdef DEVELOPER
-       char *fname;
-       const char *dump_dir;
-       dump_dir = lpcfg_parm_string(call->conn->dce_ctx->lp_ctx, NULL, "dcesrv", "stubs directory");
-       if (!dump_dir) {
-               return;
-       }
-       fname = talloc_asprintf(call, "%s/RPC-%s-%u-%s.dat",
-                               dump_dir,
-                               call->context->iface->name,
-                               call->pkt.u.request.opnum,
-                               why);
-       if (file_save(fname, call->pkt.u.request.stub_and_verifier.data, call->pkt.u.request.stub_and_verifier.length)) {
-               DEBUG(0,("RPC SAVED %s\n", fname));
-       }
-       talloc_free(fname);
+       dcerpc_log_packet(call->conn->packet_log_dir,
+                         call->context->iface->name,
+                         call->pkt.u.request.opnum,
+                         NDR_IN,
+                         &call->pkt.u.request.stub_and_verifier,
+                         why);
 #endif
 }
 
index 9812146d0bae833a3f46e276bbda106c58f3a004..3e98c205fcfa44384dab1a22eb1eabf1eb030027 100644 (file)
@@ -452,9 +452,10 @@ NTSTATUS dcerpc_ncacn_push_auth(DATA_BLOB *blob,
                                struct ncacn_packet *pkt,
                                struct dcerpc_auth *auth_info);
 
-void dcerpc_log_packet(const char *lockdir,
-                      const struct ndr_interface_table *ndr,
+void dcerpc_log_packet(const char *packet_log_dir,
+                      const char *interface_name,
                       uint32_t opnum, uint32_t flags,
-                      const DATA_BLOB *pkt);
+                      const DATA_BLOB *pkt,
+                      const char *why);
 
 #endif /* __DEFAULT_LIBRPC_RPCCOMMON_H__ */
index 239f5baaeedf96883e37553d652cfc2036d9d495..746b384a4624739ff5900b699276199b621e1393 100644 (file)
@@ -125,8 +125,6 @@ static NTSTATUS $name\__op_ndr_pull(struct dcesrv_call_state *dce_call, TALLOC_C
         /* unravel the NDR for the packet */
        status = dcerpc_table_$name.calls[opnum].ndr_pull(pull, NDR_IN, *r);
        if (!NT_STATUS_IS_OK(status)) {
-               dcerpc_log_packet(&dcerpc_table_$name, opnum, NDR_IN,
-                                 &dce_call->pkt.u.request.stub_and_verifier);
                dce_call->fault_code = DCERPC_FAULT_NDR;
                return NT_STATUS_NET_WRITE_FAULT;
        }
@@ -152,8 +150,6 @@ pidl "
        }
 
        if (dce_call->fault_code != 0) {
-               dcerpc_log_packet(&dcerpc_table_$name, opnum, NDR_IN,
-                                 &dce_call->pkt.u.request.stub_and_verifier);
                return NT_STATUS_NET_WRITE_FAULT;
        }
 
@@ -175,8 +171,6 @@ pidl "
        }
 
        if (dce_call->fault_code != 0) {
-               dcerpc_log_packet(&dcerpc_table_$name, opnum, NDR_IN,
-                                 &dce_call->pkt.u.request.stub_and_verifier);
                return NT_STATUS_NET_WRITE_FAULT;
        }
 
index 945c0ffcee0f5e9ddea2ed183d09bf711b9e80eb..f87975cf9398012c24608fe2761e35bb21afef20 100644 (file)
@@ -120,9 +120,6 @@ static NTSTATUS $name\__op_ndr_pull(struct dcesrv_call_state *dce_call, TALLOC_C
         /* unravel the NDR for the packet */
        ndr_err = ndr_table_$name.calls[opnum].ndr_pull(pull, NDR_IN, *r);
        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               dcerpc_log_packet(dce_call->conn->packet_log_dir, 
-                                 &ndr_table_$name, opnum, NDR_IN,
-                                 &dce_call->pkt.u.request.stub_and_verifier);
                dce_call->fault_code = DCERPC_FAULT_NDR;
                return NT_STATUS_NET_WRITE_FAULT;
        }
@@ -145,9 +142,6 @@ pidl "
        }
 
        if (dce_call->fault_code != 0) {
-               dcerpc_log_packet(dce_call->conn->packet_log_dir, 
-                         &ndr_table_$name, opnum, NDR_IN,
-                                 &dce_call->pkt.u.request.stub_and_verifier);
                return NT_STATUS_NET_WRITE_FAULT;
        }
 
@@ -169,9 +163,6 @@ pidl "
        }
 
        if (dce_call->fault_code != 0) {
-               dcerpc_log_packet(dce_call->conn->packet_log_dir,
-                         &ndr_table_$name, opnum, NDR_IN,
-                                 &dce_call->pkt.u.request.stub_and_verifier);
                return NT_STATUS_NET_WRITE_FAULT;
        }
 
index b5ef1fd3be429ebb4deb05b1164f96d31a30e68d..6b0b841d64dee6dcef70acf7f22a8c6279d0b721 100644 (file)
@@ -258,9 +258,5 @@ NTSTATUS dcerpc_secondary_auth_connection(struct dcerpc_pipe *p,
 
 struct composite_context* dcerpc_secondary_connection_send(struct dcerpc_pipe *p,
                                                           const struct dcerpc_binding *b);
-void dcerpc_log_packet(const char *lockdir, 
-                      const struct ndr_interface_table *ndr,
-                      uint32_t opnum, uint32_t flags,
-                      const DATA_BLOB *pkt);
 
 #endif /* __S4_DCERPC_H__ */
index 916e59e5f4b5275dd1c97c4d5d792a873a330dcd..8de9190e03e02538b404f9e172ffb771e036b5a7 100644 (file)
@@ -277,9 +277,6 @@ static NTSTATUS remote_op_ndr_pull(struct dcesrv_call_state *dce_call, TALLOC_CT
         /* unravel the NDR for the packet */
        ndr_err = table->calls[opnum].ndr_pull(pull, NDR_IN, *r);
        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               dcerpc_log_packet(dce_call->conn->packet_log_dir,
-                                                 table, opnum, NDR_IN,
-                                 &dce_call->pkt.u.request.stub_and_verifier);
                dce_call->fault_code = DCERPC_FAULT_NDR;
                return NT_STATUS_NET_WRITE_FAULT;
        }
index 33d49c9092afbf2c813a6b97841318ecf32942be..fa2b917c8d9783a4be274c1c24ac375d92087abc 100644 (file)
@@ -68,9 +68,6 @@ static NTSTATUS spoolss__op_ndr_pull(struct dcesrv_call_state *dce_call, TALLOC_
         /* unravel the NDR for the packet */
        ndr_err = ndr_table_spoolss.calls[opnum].ndr_pull(pull, NDR_IN, *r);
        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               dcerpc_log_packet(dce_call->conn->packet_log_dir,
-                                                 &ndr_table_spoolss, opnum, NDR_IN,
-                                 &dce_call->pkt.u.request.stub_and_verifier);
                dce_call->fault_code = DCERPC_FAULT_NDR;
                return NT_STATUS_NET_WRITE_FAULT;
        }
@@ -185,9 +182,6 @@ static NTSTATUS spoolss__op_dispatch(struct dcesrv_call_state *dce_call, TALLOC_
        }
 
        if (dce_call->fault_code != 0) {
-               dcerpc_log_packet(dce_call->conn->packet_log_dir,
-                                                 &ndr_table_spoolss, opnum, NDR_IN,
-                                 &dce_call->pkt.u.request.stub_and_verifier);
                return NT_STATUS_NET_WRITE_FAULT;
        }
        return NT_STATUS_OK;