From d416c8e07804b8af07c07bf8d9ab79d54a90a859 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 17 Jun 2024 13:08:47 +0200 Subject: [PATCH] util: Make show_msg call DEBUG just once format_debug_text() still splits up lines with separate write-calls, but DEBUGADD is something that I would like to get rid of. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/lib/util.c | 63 ++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/source3/lib/util.c b/source3/lib/util.c index 2e7cf649ebe..8f9b2ec424a 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -140,42 +140,55 @@ bool check_same_stat(const SMB_STRUCT_STAT *sbuf1, void show_msg(const char *buf) { + char *msg = NULL; int i; int bcc=0; if (!DEBUGLVL(5)) return; - DEBUG(5,("size=%d\nsmb_com=0x%x\nsmb_rcls=%d\nsmb_reh=%d\nsmb_err=%d\nsmb_flg=%d\nsmb_flg2=%d\n", - smb_len(buf), - (int)CVAL(buf,smb_com), - (int)CVAL(buf,smb_rcls), - (int)CVAL(buf,smb_reh), - (int)SVAL(buf,smb_err), - (int)CVAL(buf,smb_flg), - (int)SVAL(buf,smb_flg2))); - DEBUGADD(5,("smb_tid=%d\nsmb_pid=%d\nsmb_uid=%d\nsmb_mid=%d\n", - (int)SVAL(buf,smb_tid), - (int)SVAL(buf,smb_pid), - (int)SVAL(buf,smb_uid), - (int)SVAL(buf,smb_mid))); - DEBUGADD(5,("smt_wct=%d\n",(int)CVAL(buf,smb_wct))); - - for (i=0;i<(int)CVAL(buf,smb_wct);i++) - DEBUGADD(5,("smb_vwv[%2d]=%5d (0x%X)\n",i, - SVAL(buf,smb_vwv+2*i),SVAL(buf,smb_vwv+2*i))); + msg = talloc_asprintf( + talloc_tos(), + "size=%d\nsmb_com=0x%x\nsmb_rcls=%d\n" + "smb_reh=%d\nsmb_err=%d\nsmb_flg=%d\nsmb_flg2=%d\n" + "smb_tid=%d\nsmb_pid=%d\nsmb_uid=%d\nsmb_mid=%d\n" + "smt_wct=%d\n", + smb_len(buf), + (int)CVAL(buf, smb_com), + (int)CVAL(buf, smb_rcls), + (int)CVAL(buf, smb_reh), + (int)SVAL(buf, smb_err), + (int)CVAL(buf, smb_flg), + (int)SVAL(buf, smb_flg2), + (int)SVAL(buf, smb_tid), + (int)SVAL(buf, smb_pid), + (int)SVAL(buf, smb_uid), + (int)SVAL(buf, smb_mid), + (int)CVAL(buf, smb_wct)); + + for (i=0;i<(int)CVAL(buf,smb_wct);i++) { + talloc_asprintf_addbuf(&msg, + "smb_vwv[%2d]=%5d (0x%X)\n", + i, + SVAL(buf, smb_vwv + 2 * i), + SVAL(buf, smb_vwv + 2 * i)); + } bcc = (int)SVAL(buf,smb_vwv+2*(CVAL(buf,smb_wct))); - DEBUGADD(5,("smb_bcc=%d\n",bcc)); - - if (DEBUGLEVEL < 10) - return; + talloc_asprintf_addbuf(&msg, "smb_bcc=%d\n", bcc); - if (DEBUGLEVEL < 50) - bcc = MIN(bcc, 512); + if (DEBUGLEVEL >= 10) { + if (DEBUGLEVEL < 50) { + bcc = MIN(bcc, 512); + } + dump_data_addbuf((const uint8_t *)smb_buf_const(buf), + bcc, + &msg); + } - dump_data(10, (const uint8_t *)smb_buf_const(buf), bcc); + DEBUG(5, ("%s", msg)); + TALLOC_FREE(msg); } /******************************************************************* -- 2.47.2