aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-05-20 15:37:30 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-05-20 15:37:30 +0100
commit5c43b0d60977d26e7894592853462b751a8aff11 (patch)
treeb8e47c0a106258d5beb16a27a6cdaa8a26190a41 /src/libutil
parent0ee303d595cc351e78fabb8d3902a8fc730e3e38 (diff)
downloadrspamd-5c43b0d60977d26e7894592853462b751a8aff11.tar.gz
rspamd-5c43b0d60977d26e7894592853462b751a8aff11.zip
[Minor] Make read_passphrase utility more universal
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.c12
-rw-r--r--src/libutil/util.h15
2 files changed, 21 insertions, 6 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c
index 253b651ad..f9fef347f 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -1351,10 +1351,11 @@ read_pass_tmp_sig_handler (int s)
#endif
gint
-rspamd_read_passphrase (gchar *buf, gint size, gint rwflag, gpointer key)
+rspamd_read_passphrase_with_prompt (const gchar *prompt, gchar *buf, gint size, bool echo, gpointer key)
{
#ifdef HAVE_READPASSPHRASE_H
- if (readpassphrase ("Enter passphrase: ", buf, size, RPP_ECHO_OFF |
+ int flags = echo ? RPP_ECHO_ON : RPP_ECHO_OFF;
+ if (readpassphrase (prompt, buf, size, flags |
RPP_REQUIRE_TTY) == NULL) {
return 0;
}
@@ -1383,7 +1384,10 @@ restart:
}
memcpy (&term, &oterm, sizeof(term));
- term.c_lflag &= ~(ECHO | ECHONL);
+
+ if (!echo) {
+ term.c_lflag &= ~(ECHO | ECHONL);
+ }
if (tcsetattr (input, TCSAFLUSH, &term) == -1) {
errno = ENOTTY;
@@ -1391,7 +1395,7 @@ restart:
return 0;
}
- g_assert (write (output, "Enter passphrase: ", sizeof ("Enter passphrase: ") -
+ g_assert (write (output, prompt, sizeof ("Enter passphrase: ") -
1) != -1);
/* Save the current sighandler */
diff --git a/src/libutil/util.h b/src/libutil/util.h
index ccc642adb..907bcd33f 100644
--- a/src/libutil/util.h
+++ b/src/libutil/util.h
@@ -281,11 +281,22 @@ void rspamd_hash_table_copy (GHashTable *src, GHashTable *dst,
* Read passphrase from tty
* @param buf buffer to fill with a password
* @param size size of the buffer
- * @param rwflag unused flag
+ * @param echo turn echo on or off
* @param key unused key
* @return size of password read
*/
-gint rspamd_read_passphrase (gchar *buf, gint size, gint rwflag, gpointer key);
+#define rspamd_read_passphrase(buf, size, echo, key) (rspamd_read_passphrase_with_prompt("Enter passphrase: ", (buf), (size), (echo), (key)))
+
+/**
+ * Read passphrase from tty with prompt
+ * @param prompt
+ * @param buf
+ * @param size
+ * @param echo
+ * @param key
+ * @return
+ */
+gint rspamd_read_passphrase_with_prompt (const gchar *prompt, gchar *buf, gint size, bool echo, gpointer key);
/**
* Portably return the current clock ticks as seconds