aboutsummaryrefslogtreecommitdiffstats
path: root/src/rspamadm/pw.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-12-02 14:54:18 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-12-02 14:54:18 +0000
commit174f6f63dfd6d4cfd43a31f29871eb707d1f55b6 (patch)
tree2d812887a64d80b6210e13084b521d7fb06284e2 /src/rspamadm/pw.c
parentf5df796a9f91bdecb3f3e35e67fd0c52adedb685 (diff)
downloadrspamd-174f6f63dfd6d4cfd43a31f29871eb707d1f55b6.tar.gz
rspamd-174f6f63dfd6d4cfd43a31f29871eb707d1f55b6.zip
[Feature] Export password encryption routines to Redis
Diffstat (limited to 'src/rspamadm/pw.c')
-rw-r--r--src/rspamadm/pw.c49
1 files changed, 44 insertions, 5 deletions
diff --git a/src/rspamadm/pw.c b/src/rspamadm/pw.c
index 4345ff1c5..3299c479d 100644
--- a/src/rspamadm/pw.c
+++ b/src/rspamadm/pw.c
@@ -23,6 +23,7 @@
static void rspamadm_pw (gint argc, gchar **argv);
static const char *rspamadm_pw_help (gboolean full_help);
+static void rspamadm_pw_lua_subrs (gpointer pL);
static gboolean do_encrypt = FALSE;
static gboolean do_check = FALSE;
@@ -36,7 +37,7 @@ struct rspamadm_command pw_command = {
.flags = 0,
.help = rspamadm_pw_help,
.run = rspamadm_pw,
- .lua_subrs = NULL,
+ .lua_subrs = rspamadm_pw_lua_subrs,
};
static GOptionEntry entries[] = {
@@ -97,12 +98,13 @@ rspamadm_get_pbkdf (void)
return NULL;
}
-static void
-rspamadm_pw_encrypt (void)
+static char *
+rspamadm_pw_encrypt (char *password)
{
const struct rspamd_controller_pbkdf *pbkdf;
guchar *salt, *key;
gchar *encoded_salt, *encoded_key;
+ GString *result;
gsize plen;
pbkdf = rspamadm_get_pbkdf ();
@@ -133,13 +135,18 @@ rspamadm_pw_encrypt (void)
encoded_salt = rspamd_encode_base32 (salt, pbkdf->salt_len);
encoded_key = rspamd_encode_base32 (key, pbkdf->key_len);
- rspamd_printf ("$%d$%s$%s\n", pbkdf->id, encoded_salt,
+ result = g_string_new ("");
+ rspamd_printf_gstring (result, "$%d$%s$%s", pbkdf->id, encoded_salt,
encoded_key);
g_free (encoded_salt);
g_free (encoded_key);
rspamd_explicit_memzero (password, plen);
g_free (password);
+ password = result->str;
+ g_string_free (result, FALSE); /* Not freeing memory */
+
+ return password;
}
static const gchar *
@@ -302,6 +309,36 @@ rspamadm_pw_check (void)
}
}
+static gint
+rspamadm_pw_lua_encrypt (lua_State *L)
+{
+ const gchar *pw_in = NULL;
+ gchar *ret, *tmp = NULL;
+
+ if (lua_type (L, 1) == LUA_TSTRING) {
+ pw_in = lua_tostring (L, 1);
+ tmp = g_strdup (pw_in);
+ }
+
+ ret = rspamadm_pw_encrypt (tmp);
+
+ lua_pushstring (L, ret);
+ g_free (ret);
+
+ return 1;
+}
+
+
+static void
+rspamadm_pw_lua_subrs (gpointer pL)
+{
+ lua_State *L = pL;
+
+ lua_pushstring (L, "pw_encrypt");
+ lua_pushcfunction (L, rspamadm_pw_lua_encrypt);
+ lua_settable (L, -3);
+}
+
static void
rspamadm_alg_list (void)
{
@@ -346,7 +383,9 @@ rspamadm_pw (gint argc, gchar **argv)
}
if (do_encrypt) {
- rspamadm_pw_encrypt ();
+ gchar *encr = rspamadm_pw_encrypt (password);
+ rspamd_printf ("%s\n", encr);
+ g_free (encr);
}
else if (do_check) {
rspamadm_pw_check ();