Commit 22cc954c authored by Stas Korobeynikov's avatar Stas Korobeynikov Committed by Pavel Vainerman

add readpassphrase for read passphrase

parent bb0e2260
......@@ -126,46 +126,64 @@ read_passphrase(const char *prompt, int flags)
char *askpass = NULL, *ret, buf[1024];
int rppflags, use_askpass = 0, ttyfd;
rppflags = (flags & RP_ECHO) ? RPP_ECHO_ON : RPP_ECHO_OFF;
if (flags & RP_USE_ASKPASS)
use_askpass = 1;
else if (flags & RP_ALLOW_STDIN) {
if (!isatty(STDIN_FILENO)) {
debug("read_passphrase: stdin is not a tty");
use_askpass = 1;
if (!NxAuthOnlyModeEnabled && !NxModeEnabled && !NXStdinPassEnabled) {
rppflags = (flags & RP_ECHO) ? RPP_ECHO_ON : RPP_ECHO_OFF;
if (flags & RP_ALLOW_STDIN) {
if (!isatty(STDIN_FILENO)) {
use_askpass = 1;
}
} else {
rppflags |= RPP_REQUIRE_TTY;
ttyfd = open(_PATH_TTY, O_RDWR);
if (ttyfd >= 0)
close(ttyfd);
else {
debug("read_passphrase: can't open %s: %s", _PATH_TTY,
strerror(errno));
use_askpass = 1;
}
}
} else {
rppflags |= RPP_REQUIRE_TTY;
ttyfd = open(_PATH_TTY, O_RDWR);
if (ttyfd >= 0)
close(ttyfd);
else {
debug("read_passphrase: can't open %s: %s", _PATH_TTY,
strerror(errno));
use_askpass = 1;
if ((flags & RP_USE_ASKPASS) && getenv("DISPLAY") == NULL)
return (flags & RP_ALLOW_EOF) ? NULL : xstrdup("");
if (use_askpass && getenv("DISPLAY")) {
if (getenv(SSH_ASKPASS_ENV))
askpass = getenv(SSH_ASKPASS_ENV);
else
askpass = _PATH_SSH_ASKPASS_DEFAULT;
return ssh_askpass(askpass, prompt);
}
}
if ((flags & RP_USE_ASKPASS) && getenv("DISPLAY") == NULL)
return (flags & RP_ALLOW_EOF) ? NULL : xstrdup("");
if (use_askpass && getenv("DISPLAY")) {
if (getenv(SSH_ASKPASS_ENV))
askpass = getenv(SSH_ASKPASS_ENV);
else
askpass = _PATH_SSH_ASKPASS_DEFAULT;
if ((ret = ssh_askpass(askpass, prompt)) == NULL)
if (!(flags & RP_ALLOW_EOF))
return xstrdup("");
return ret;
}
if (readpassphrase(prompt, buf, sizeof buf, rppflags) == NULL) {
if (flags & RP_ALLOW_EOF)
return NULL;
return xstrdup("");
if (readpassphrase(prompt, buf, sizeof buf, rppflags) == NULL) {
if (flags & RP_ALLOW_EOF)
return NULL;
return xstrdup("");
}
} else {
size_t len;
int retr;
fprintf(stdout, "%s", prompt);
fflush(stdout);
len = retr = 0;
do {
retr = read(STDIN_FILENO, buf + len, sizeof(buf) - 1 - len);
if (retr == -1 && errno == EINTR)
continue;
if (retr <= 0)
break;
len += retr;
} while (sizeof(buf) - 1 - len > 0 && buf[len] == '\n');
buf[len-1] = '\0';
fprintf(stdout, "\n");
fflush(stdout);
}
ret = xstrdup(buf);
explicit_bzero(buf, sizeof(buf));
return ret;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment