From: Vsevolod Stakhov Date: Fri, 17 Feb 2017 12:40:22 +0000 (+0000) Subject: [Minor] Allow to use password in file in rspamc X-Git-Tag: 1.5.0~93 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8b18feb6bc086a9ae7f2eef31f78325221707476;p=rspamd.git [Minor] Allow to use password in file in rspamc Issue: #1415 Submitted by: @urusha --- diff --git a/src/client/rspamc.c b/src/client/rspamc.c index 0c8a270df..b756d6722 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -328,9 +328,36 @@ rspamc_password_callback (const gchar *option_name, GError **error) { guint plen = 8192; + guint8 *map, *end; + gsize sz; if (value != NULL) { - password = g_strdup (value); + if (value[0] == '/' || value[0] == '.') { + /* Try to open file */ + map = rspamd_file_xmap (value, PROT_READ, &sz); + + if (map == NULL) { + /* Just use it as a string */ + password = g_strdup (value); + } + else { + /* Strip trailing spaces */ + g_assert (sz > 0); + end = map + sz - 1; + + while (g_ascii_isspace (*end) && end > map) { + end --; + } + + end ++; + password = g_malloc (end - map + 1); + rspamd_strlcpy (password, map, end - map + 1); + munmap (map, sz); + } + } + else { + password = g_strdup (value); + } } else { /* Read password from console */