From 5981adce3d8a38bbf1b01f4efe3fb6f5b10ec5d3 Mon Sep 17 00:00:00 2001 From: Ian Zimmerman Date: Fri, 8 Feb 2019 11:40:43 -0800 Subject: [PATCH] Adjust symbolic logging levels to avoid level 4, to be PROGRESS Adjust remaining uses of symbolic loglevels. Mostly this means changing mutt_socket_readln to mutt_socket_readln_d with MUTT_SOCK_LOG_FULL in cases where (in my very limited understanding) private information *might* be logged. --- imap/command.c | 2 +- imap/imap_private.h | 2 +- mutt_socket.h | 2 +- nntp/nntp.c | 42 +++++++++++++++++------------------------- pop/pop_auth.c | 2 +- pop/pop_lib.c | 10 ++++------ smtp.c | 2 +- 7 files changed, 26 insertions(+), 36 deletions(-) diff --git a/imap/command.c b/imap/command.c index 675dbaed0..319569ff0 100644 --- a/imap/command.c +++ b/imap/command.c @@ -1083,7 +1083,7 @@ int imap_cmd_step(struct ImapAccountData *adata) /* back up over '\0' */ if (len) len--; - c = mutt_socket_readln(adata->buf + len, adata->blen - len, adata->conn); + c = mutt_socket_readln_d(adata->buf + len, adata->blen - len, adata->conn, MUTT_SOCK_LOG_FULL); if (c <= 0) { mutt_debug(1, "Error reading server response.\n"); diff --git a/imap/imap_private.h b/imap/imap_private.h index c6049ad60..6cf879f3d 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -46,7 +46,7 @@ struct Progress; /* logging levels */ #define IMAP_LOG_CMD 2 -#define IMAP_LOG_LTRL 4 +#define IMAP_LOG_LTRL 3 #define IMAP_LOG_PASS 5 /* IMAP command responses. Used in ImapCommand.state too */ diff --git a/mutt_socket.h b/mutt_socket.h index 3f95014df..1551fd0ec 100644 --- a/mutt_socket.h +++ b/mutt_socket.h @@ -29,7 +29,7 @@ struct Connection; /* logging levels */ #define MUTT_SOCK_LOG_CMD 2 #define MUTT_SOCK_LOG_HDR 3 -#define MUTT_SOCK_LOG_FULL 4 +#define MUTT_SOCK_LOG_FULL 5 struct Connection *mutt_conn_find(const struct Connection *start, const struct ConnAccount *account); struct Connection *mutt_conn_new(const struct ConnAccount *account); diff --git a/nntp/nntp.c b/nntp/nntp.c index 3ac2845d6..e81681001 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -431,8 +431,8 @@ static int nntp_attempt_features(struct NntpAccountData *adata) mutt_mem_realloc(&adata->overview_fmt, buflen); } - const int chunk = - mutt_socket_readln(adata->overview_fmt + off, buflen - off, conn); + const int chunk = mutt_socket_readln_d(adata->overview_fmt + off, + buflen - off, conn, MUTT_SOCK_LOG_HDR); if (chunk < 0) { FREE(&adata->overview_fmt); @@ -590,7 +590,7 @@ static int nntp_auth(struct NntpAccountData *adata) mutt_message(_("Authenticating (%s)..."), method); snprintf(buf, sizeof(buf), "AUTHINFO USER %s\r\n", conn->account.user); if (mutt_socket_send(conn, buf) < 0 || - mutt_socket_readln(buf, sizeof(buf), conn) < 0) + mutt_socket_readln_d(buf, sizeof(buf), conn, MUTT_SOCK_LOG_FULL) < 0) { break; } @@ -602,11 +602,10 @@ static int nntp_auth(struct NntpAccountData *adata) /* username accepted, sending password */ if (mutt_str_startswith(buf, "381", CASE_MATCH)) { - if (DebugLevel < MUTT_SOCK_LOG_FULL) - mutt_debug(MUTT_SOCK_LOG_CMD, "%d> AUTHINFO PASS *\n", conn->fd); + mutt_debug(MUTT_SOCK_LOG_FULL, "%d> AUTHINFO PASS *\n", conn->fd); snprintf(buf, sizeof(buf), "AUTHINFO PASS %s\r\n", conn->account.pass); if (mutt_socket_send_d(conn, buf, MUTT_SOCK_LOG_FULL) < 0 || - mutt_socket_readln(buf, sizeof(buf), conn) < 0) + mutt_socket_readln_d(buf, sizeof(buf), conn, MUTT_SOCK_LOG_FULL) < 0) { break; } @@ -675,16 +674,13 @@ static int nntp_auth(struct NntpAccountData *adata) } mutt_str_strcat(buf, sizeof(buf), "\r\n"); - if (DebugLevel < MUTT_SOCK_LOG_FULL) + if (strchr(buf, ' ')) { - if (strchr(buf, ' ')) - { - mutt_debug(MUTT_SOCK_LOG_CMD, "%d> AUTHINFO SASL %s%s\n", - conn->fd, method, client_len ? " sasl_data" : ""); - } - else - mutt_debug(MUTT_SOCK_LOG_CMD, "%d> sasl_data\n", conn->fd); + mutt_debug(MUTT_SOCK_LOG_CMD, "%d> AUTHINFO SASL %s%s\n", conn->fd, + method, client_len ? " sasl_data" : ""); } + else + mutt_debug(MUTT_SOCK_LOG_CMD, "%d> sasl_data\n", conn->fd); client_len = 0; if (mutt_socket_send_d(conn, buf, MUTT_SOCK_LOG_FULL) < 0 || mutt_socket_readln_d(inbuf, sizeof(inbuf), conn, MUTT_SOCK_LOG_FULL) < 0) @@ -694,15 +690,11 @@ static int nntp_auth(struct NntpAccountData *adata) if (!mutt_str_startswith(inbuf, "283 ", CASE_MATCH) && !mutt_str_startswith(inbuf, "383 ", CASE_MATCH)) { - if (DebugLevel < MUTT_SOCK_LOG_FULL) - mutt_debug(MUTT_SOCK_LOG_CMD, "%d< %s\n", conn->fd, inbuf); + mutt_debug(MUTT_SOCK_LOG_FULL, "%d< %s\n", conn->fd, inbuf); break; } - if (DebugLevel < MUTT_SOCK_LOG_FULL) - { - inbuf[3] = '\0'; - mutt_debug(MUTT_SOCK_LOG_CMD, "%d< %s sasl_data\n", conn->fd, inbuf); - } + inbuf[3] = '\0'; + mutt_debug(MUTT_SOCK_LOG_FULL, "%d< %s sasl_data\n", conn->fd, inbuf); if (strcmp("=", inbuf + 4) == 0) len = 0; @@ -890,7 +882,7 @@ static int nntp_fetch_lines(struct NntpMboxData *mdata, char *query, size_t qlen while (true) { char *p = NULL; - int chunk = mutt_socket_readln_d(buf, sizeof(buf), mdata->adata->conn, MUTT_SOCK_LOG_HDR); + int chunk = mutt_socket_readln_d(buf, sizeof(buf), mdata->adata->conn, MUTT_SOCK_LOG_FULL); if (chunk < 0) { mdata->adata->status = NNTP_NONE; @@ -2026,7 +2018,7 @@ int nntp_post(struct Mailbox *m, const char *msg) buf[len] = '\0'; } if (mutt_socket_send_d(mdata->adata->conn, buf[1] == '.' ? buf : buf + 1, - MUTT_SOCK_LOG_HDR) < 0) + MUTT_SOCK_LOG_FULL) < 0) { mutt_file_fclose(&fp); return nntp_connect_error(mdata->adata); @@ -2035,8 +2027,8 @@ int nntp_post(struct Mailbox *m, const char *msg) mutt_file_fclose(&fp); if ((buf[strlen(buf) - 1] != '\n' && - mutt_socket_send_d(mdata->adata->conn, "\r\n", MUTT_SOCK_LOG_HDR) < 0) || - mutt_socket_send_d(mdata->adata->conn, ".\r\n", MUTT_SOCK_LOG_HDR) < 0 || + mutt_socket_send_d(mdata->adata->conn, "\r\n", MUTT_SOCK_LOG_FULL) < 0) || + mutt_socket_send_d(mdata->adata->conn, ".\r\n", MUTT_SOCK_LOG_FULL) < 0 || mutt_socket_readln(buf, sizeof(buf), mdata->adata->conn) < 0) { return nntp_connect_error(mdata->adata); diff --git a/pop/pop_auth.c b/pop/pop_auth.c index d06c63d2e..ea5ae61e7 100644 --- a/pop/pop_auth.c +++ b/pop/pop_auth.c @@ -113,7 +113,7 @@ static enum PopAuthRes pop_auth_sasl(struct PopAccountData *adata, const char *m { mutt_str_strfcpy(buf + olen, "\r\n", bufsize - olen); mutt_socket_send(adata->conn, buf); - if (mutt_socket_readln(inbuf, sizeof(inbuf), adata->conn) < 0) + if (mutt_socket_readln_d(inbuf, sizeof(inbuf), adata->conn, MUTT_SOCK_LOG_FULL) < 0) { sasl_dispose(&saslconn); adata->status = POP_DISCONNECTED; diff --git a/pop/pop_lib.c b/pop/pop_lib.c index ff07d33dd..e2aa1a60d 100644 --- a/pop/pop_lib.c +++ b/pop/pop_lib.c @@ -447,26 +447,23 @@ void pop_logout(struct Mailbox *m) */ int pop_query_d(struct PopAccountData *adata, char *buf, size_t buflen, char *msg) { - int dbg = MUTT_SOCK_LOG_CMD; - if (adata->status != POP_CONNECTED) return -1; /* print msg instead of real command */ if (msg) { - dbg = MUTT_SOCK_LOG_FULL; mutt_debug(MUTT_SOCK_LOG_CMD, "> %s", msg); } - mutt_socket_send_d(adata->conn, buf, dbg); + mutt_socket_send_d(adata->conn, buf, MUTT_SOCK_LOG_FULL); char *c = strpbrk(buf, " \r\n"); if (c) *c = '\0'; snprintf(adata->err_msg, sizeof(adata->err_msg), "%s: ", buf); - if (mutt_socket_readln(buf, buflen, adata->conn) < 0) + if (mutt_socket_readln_d(buf, buflen, adata->conn, MUTT_SOCK_LOG_FULL) < 0) { adata->status = POP_DISCONNECTED; return -1; @@ -509,7 +506,8 @@ int pop_fetch_data(struct PopAccountData *adata, const char *query, while (true) { - const int chunk = mutt_socket_readln_d(buf, sizeof(buf), adata->conn, MUTT_SOCK_LOG_HDR); + const int chunk = + mutt_socket_readln_d(buf, sizeof(buf), adata->conn, MUTT_SOCK_LOG_FULL); if (chunk < 0) { adata->status = POP_DISCONNECTED; diff --git a/smtp.c b/smtp.c index 61f949c46..008bd0121 100644 --- a/smtp.c +++ b/smtp.c @@ -453,7 +453,7 @@ static int smtp_auth_sasl(struct Connection *conn, const char *mechlist) { if (mutt_socket_send(conn, buf) < 0) goto fail; - rc = mutt_socket_readln(buf, bufsize, conn); + rc = mutt_socket_readln_d(buf, bufsize, conn, MUTT_SOCK_LOG_FULL); if (rc < 0) goto fail; if (!valid_smtp_code(buf, rc, &rc)) -- 2.40.0