diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-02-17 12:40:22 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-02-17 12:48:35 +0000 |
commit | 8b18feb6bc086a9ae7f2eef31f78325221707476 (patch) | |
tree | 823d94b475019788e7d51b0a1b47376e7afb8324 /src/client/rspamc.c | |
parent | 690b006dab61b2430b78c3fdb4ad56c345ba8d01 (diff) | |
download | rspamd-8b18feb6bc086a9ae7f2eef31f78325221707476.tar.gz rspamd-8b18feb6bc086a9ae7f2eef31f78325221707476.zip |
[Minor] Allow to use password in file in rspamc
Issue: #1415
Submitted by: @urusha
Diffstat (limited to 'src/client/rspamc.c')
-rw-r--r-- | src/client/rspamc.c | 29 |
1 files changed, 28 insertions, 1 deletions
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 */ |