aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-12-02 13:25:50 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-12-02 13:25:50 +0000
commit5b1a87305b3c8fde5db68b191f1ac239343d01a4 (patch)
tree8c5944d4e525f0e939bad8a4a34823859c317b04 /src
parent1953688d8d11fd560912691494f7584ba3b7bc20 (diff)
downloadrspamd-5b1a87305b3c8fde5db68b191f1ac239343d01a4.tar.gz
rspamd-5b1a87305b3c8fde5db68b191f1ac239343d01a4.zip
[Minor] Allow to read passphrase from Lua
Diffstat (limited to 'src')
-rw-r--r--src/lua/lua_util.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index 6ca9f35ab..c6c339033 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -378,11 +378,18 @@ LUA_FUNCTION_DEF (util, is_valid_utf8);
/***
* @function util.readline([prompt])
* Returns string read from stdin with history and editing support
- * @return {boolean} true if a string is spoofed
+ * @return {string} string read from the input (with line endings stripped)
*/
LUA_FUNCTION_DEF (util, readline);
/***
+ * @function util.readpassphrase([prompt])
+ * Returns string read from stdin disabling echo
+ * @return {string} string read from the input (with line endings stripped)
+ */
+LUA_FUNCTION_DEF (util, readpassphrase);
+
+/***
* @function util.file_exists(file)
* Checks if a specified file exists and is available for reading
* @return {boolean} true if file exists
@@ -533,6 +540,7 @@ static const struct luaL_reg utillib_f[] = {
LUA_INTERFACE_DEF (util, is_utf_spoofed),
LUA_INTERFACE_DEF (util, is_valid_utf8),
LUA_INTERFACE_DEF (util, readline),
+ LUA_INTERFACE_DEF (util, readpassphrase),
LUA_INTERFACE_DEF (util, file_exists),
LUA_INTERFACE_DEF (util, get_hostname),
LUA_INTERFACE_DEF (util, pack),
@@ -2094,6 +2102,32 @@ lua_util_readline (lua_State *L)
}
static gint
+lua_util_readpassphrase (lua_State *L)
+{
+ const gchar *prompt = NULL;
+ gchar test_password[8192];
+ gsize r;
+
+ if (lua_type (L, 1) == LUA_TSTRING) {
+ prompt = lua_tostring (L, 1);
+ }
+
+ r = rspamd_read_passphrase (test_password, sizeof (test_password), 0, NULL);
+
+ if (r > 0) {
+ lua_pushlstring (L, test_password, r);
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ /* In fact, we still pass it to Lua which is not very safe */
+ rspamd_explicit_memzero (test_password, sizeof (test_password));
+
+ return 1;
+}
+
+static gint
lua_util_file_exists (lua_State *L)
{
const gchar *fname = luaL_checkstring (L, 1);