From: Milan Crha Date: Wed, 16 Apr 2014 16:56:10 +0000 (+0200) Subject: [IMAPX] Do not expose user credentials in debug logs X-Git-Tag: submit/tizen/20140917.130222~30 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5fa3bda4dd018c2690c34d42505b359f077adc51;p=platform%2Fupstream%2Fevolution-data-server.git [IMAPX] Do not expose user credentials in debug logs And skip trailing \r\n in the io logs as well. --- diff --git a/camel/providers/imapx/camel-imapx-logger.c b/camel/providers/imapx/camel-imapx-logger.c index 30f9de9..6bfd9ce 100644 --- a/camel/providers/imapx/camel-imapx-logger.c +++ b/camel/providers/imapx/camel-imapx-logger.c @@ -112,6 +112,7 @@ imapx_logger_convert (GConverter *converter, CamelIMAPXLoggerPrivate *priv; GConverterResult result; gsize min_size; + const gchar *login_start; priv = CAMEL_IMAPX_LOGGER_GET_PRIVATE (converter); @@ -120,9 +121,31 @@ imapx_logger_convert (GConverter *converter, memcpy (outbuf, inbuf, min_size); *bytes_read = *bytes_written = min_size; - camel_imapx_debug ( - io, priv->prefix, "I/O: '%.*s'\n", - (gint) min_size, (gchar *) outbuf); + login_start = g_strstr_len (outbuf, min_size, " LOGIN "); + if (login_start > (const gchar *) outbuf) { + const gchar *space = g_strstr_len (outbuf, min_size, " "); + + if (space == login_start) { + camel_imapx_debug ( + io, priv->prefix, "I/O: '%.*s ...'\n", + (gint) (login_start - ((const gchar *) outbuf) + 6), (gchar *) outbuf); + } else { + /* To print the command the other way */ + login_start = NULL; + } + } + + if (!login_start) { + /* Skip ending '\n' '\r'; it may sometimes show wrong data, + when the input is divided into wrong chunks, but it will + usually work as is needed, no extra new-lines in the log */ + while (min_size > 0 && (((gchar *) outbuf)[min_size - 1] == '\r' || ((gchar *) outbuf)[min_size - 1] == '\n')) + min_size--; + + camel_imapx_debug ( + io, priv->prefix, "I/O: '%.*s'\n", + (gint) min_size, (gchar *) outbuf); + } if ((flags & G_CONVERTER_INPUT_AT_END) != 0) result = G_CONVERTER_FINISHED;