[systemd-commits] 2 commits - src/ask-password-api.c
Lennart Poettering
lennart at kemper.freedesktop.org
Mon Mar 28 14:29:53 PDT 2011
src/ask-password-api.c | 45 +++++++++++++++++++++++++++++++++------------
1 file changed, 33 insertions(+), 12 deletions(-)
New commits:
commit 58fc840b8325395d24ab70e84cb69880c6daa9ee
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Mar 28 23:27:04 2011 +0200
ask-password: use TAB instead of backspace to disable asterisk password echo
diff --git a/src/ask-password-api.c b/src/ask-password-api.c
index 022f1ca..cb05590 100644
--- a/src/ask-password-api.c
+++ b/src/ask-password-api.c
@@ -36,6 +36,18 @@
#include "ask-password-api.h"
+static void backspace_chars(int ttyfd, size_t p) {
+
+ if (ttyfd < 0)
+ return;
+
+ while (p > 0) {
+ p--;
+
+ loop_write(ttyfd, "\b \b", 3, false);
+ }
+}
+
int ask_password_tty(
const char *message,
usec_t until,
@@ -156,24 +168,30 @@ int ask_password_tty(
if (c == '\n')
break;
- else if (c == 21) {
- while (p > 0) {
- p--;
+ else if (c == 21) { /* C-u */
- if (ttyfd >= 0)
- loop_write(ttyfd, "\b \b", 3, false);
- }
+ if (!silent_mode)
+ backspace_chars(ttyfd, p);
+ p = 0;
} else if (c == '\b' || c == 127) {
- if (p == 0 && !silent_mode) {
- silent_mode = true;
- loop_write(ttyfd, "(no echo) ", 10, false);
- } else if (p > 0) {
+
+ if (p > 0) {
+
+ if (!silent_mode)
+ backspace_chars(ttyfd, 1);
+
p--;
+ } else if (ttyfd >= 0)
+ loop_write(ttyfd, "\a", 1, false);
- if (ttyfd >= 0)
- loop_write(ttyfd, "\b \b", 3, false);
- }
+ } else if (c == '\t' && !silent_mode) {
+
+ backspace_chars(ttyfd, p);
+ silent_mode = true;
+
+ if (ttyfd >= 0)
+ loop_write(ttyfd, "(no echo) ", 10, false);
} else {
passphrase[p++] = c;
commit d167623084f20d6286c8385de15c8ca0e2fc551d
Author: Jan Engelhardt <jengelh at medozas.de>
Date: Sun Mar 27 23:52:11 2011 +0200
crypto: to show stars or not to show them
On Friday 2011-03-18 01:41, Lennart Poettering wrote:
>On Fri, 18.03.11 00:18, Jan Engelhardt (jengelh at medozas.de) wrote:
>
>> Meanwhile, I have two new suggestions.
>
>I have one too (or actually Kay came up with it), and I think you are
>going to like it:
>
>Start with showing input feedback as we currently do. If the user then
>presses TAB the stars disappear, and instead we show "(no echo)" or
>so. Then, the user can proceed with typing his password without
>asterisks.
>[...]
Incorporating Graham's suggestion to use BKSP instead:
The following changes since commit 65c9e467528daa438167853cc91d37bfcb875836:
tainted: don't check if /usr is a mount point, only if it's not already mounted at startup (2011-03-24 22:32:21 +0100)
are available in the git repository at:
git://dev.medozas.de/systemd master
Jan Engelhardt (1):
ask-password: provide a way to activate a silent prompt
src/ask-password-api.c | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/ask-password-api.c b/src/ask-password-api.c
index 5d17d4c..022f1ca 100644
--- a/src/ask-password-api.c
+++ b/src/ask-password-api.c
@@ -18,7 +18,7 @@
You should have received a copy of the GNU General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-
+#include <stdbool.h>
#include <termios.h>
#include <unistd.h>
#include <sys/poll.h>
@@ -48,6 +48,7 @@ int ask_password_tty(
int r, ttyfd = -1, notify = -1;
struct pollfd pollfd[2];
bool reset_tty = false;
+ bool silent_mode = false;
enum {
POLL_TTY,
POLL_INOTIFY
@@ -156,7 +157,6 @@ int ask_password_tty(
if (c == '\n')
break;
else if (c == 21) {
-
while (p > 0) {
p--;
@@ -165,7 +165,10 @@ int ask_password_tty(
}
} else if (c == '\b' || c == 127) {
- if (p > 0) {
+ if (p == 0 && !silent_mode) {
+ silent_mode = true;
+ loop_write(ttyfd, "(no echo) ", 10, false);
+ } else if (p > 0) {
p--;
if (ttyfd >= 0)
@@ -174,7 +177,7 @@ int ask_password_tty(
} else {
passphrase[p++] = c;
- if (ttyfd >= 0)
+ if (!silent_mode && ttyfd >= 0)
loop_write(ttyfd, "*", 1, false);
}
}
More information about the systemd-commits
mailing list