#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;
}
}
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;
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 */
* 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