aboutsummaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-04 21:36:55 +0200
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-04 21:36:55 +0200
commit42ef4ee31d73aca6aef41f66bc825a4296070cca (patch)
tree126ea3dc2121ced6bfd8a0924fb8362c4f35ea83 /src/client
parentc8bc6be028234a19693f9e59c98fa88d19a300df (diff)
downloadrspamd-42ef4ee31d73aca6aef41f66bc825a4296070cca.tar.gz
rspamd-42ef4ee31d73aca6aef41f66bc825a4296070cca.zip
[Feature] Allow to read password from console for rspamc
Issue: #644 Reported by: @dehnli
Diffstat (limited to 'src/client')
-rw-r--r--src/client/rspamc.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/client/rspamc.c b/src/client/rspamc.c
index 5280914b9..9c00a4bc8 100644
--- a/src/client/rspamc.c
+++ b/src/client/rspamc.c
@@ -67,12 +67,17 @@ static GList *children;
g_queue_push_tail ((o), nh); \
} while (0)
+static gboolean rspamc_password_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error);
+
static GOptionEntry entries[] =
{
{ "connect", 'h', 0, G_OPTION_ARG_STRING, &connect_str,
"Specify host and port", NULL },
- { "password", 'P', 0, G_OPTION_ARG_STRING, &password,
- "Specify control password", NULL },
+ { "password", 'P', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK,
+ &rspamc_password_callback, "Specify control password", NULL },
{ "classifier", 'c', 0, G_OPTION_ARG_STRING, &classifier,
"Classifier to learn spam or ham", NULL },
{ "weight", 'w', 0, G_OPTION_ARG_INT, &weight,
@@ -292,6 +297,31 @@ struct rspamc_callback_data {
gdouble start;
};
+gboolean
+rspamc_password_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ guint plen = 8192;
+
+ if (value != NULL) {
+ password = g_strdup (value);
+ }
+ else {
+ /* Read password from console */
+ password = g_malloc0 (plen);
+ plen = rspamd_read_passphrase (password, plen, 0, NULL);
+ }
+
+ if (plen == 0) {
+ rspamd_fprintf (stderr, "Invalid password\n");
+ exit (EXIT_FAILURE);
+ }
+
+ return TRUE;
+}
+
/*
* Parse command line
*/