Ports: Remove obsolete openssh password prompt patch

As of 8dd11ae, we have `/dev/tty`, which is used by openssh's built-in
read_passphrase function to access the TTY, making our patch
unnecessary.

Removing it also fixes a subtle issue: we did not handle the case of
stdout not being a TTY correctly, so prompts failed to show up when e.g.
the ssh process was being piped to. This made `git clone` not work when
the server's fingerprint was not already verified.
This commit is contained in:
Daniel Bertalan 2021-12-12 15:18:46 +01:00 committed by Andreas Kling
parent 8dd11ae717
commit edb810f854
Notes: sideshowbarker 2024-07-17 22:49:53 +09:00

View File

@ -1,101 +0,0 @@
81548c85897681d42968dd7ca228c6b128ac39f1 Reimplement read_passphrase as a C version of Core::get_password
diff --git a/readpass.c b/readpass.c
index 974d67f0..3496eebe 100644
--- a/readpass.c
+++ b/readpass.c
@@ -47,6 +47,10 @@
#include "ssh.h"
#include "uidswap.h"
+#ifdef __serenity__
+#include <termios.h>
+#endif
+
static char *
ssh_askpass(char *askpass, const char *msg, const char *env_hint)
{
@@ -122,62 +126,35 @@ ssh_askpass(char *askpass, const char *msg, const char *env_hint)
char *
read_passphrase(const char *prompt, int flags)
{
- char cr = '\r', *askpass = NULL, *ret, buf[1024];
- int rppflags, use_askpass = 0, ttyfd;
- const char *askpass_hint = NULL;
+ // Reimplementation of Core::get_password
+ fwrite(prompt, sizeof(char), strlen(prompt), stdout);
+ fflush(stdout);
+
+ struct termios original;
+ tcgetattr(STDIN_FILENO, &original);
- 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;
- }
- } else {
- rppflags |= RPP_REQUIRE_TTY;
- ttyfd = open(_PATH_TTY, O_RDWR);
- if (ttyfd >= 0) {
- /*
- * If we're on a tty, ensure that show the prompt at
- * the beginning of the line. This will hopefully
- * clobber any password characters the user has
- * optimistically typed before echo is disabled.
- */
- (void)write(ttyfd, &cr, 1);
- close(ttyfd);
- } else {
- debug("read_passphrase: can't open %s: %s", _PATH_TTY,
- strerror(errno));
- use_askpass = 1;
- }
+ struct termios no_echo = original;
+ no_echo.c_lflag &= ~ECHO;
+ if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &no_echo) < 0) {
+ perror("Failed to turn off echo for passphrase");
+ exit(errno);
}
- if ((flags & RP_USE_ASKPASS) && getenv("DISPLAY") == NULL)
- return (flags & RP_ALLOW_EOF) ? NULL : xstrdup("");
+ char* password = NULL;
+ size_t n = 0;
- if (use_askpass && getenv("DISPLAY")) {
- if (getenv(SSH_ASKPASS_ENV))
- askpass = getenv(SSH_ASKPASS_ENV);
- else
- askpass = _PATH_SSH_ASKPASS_DEFAULT;
- if ((flags & RP_ASK_PERMISSION) != 0)
- askpass_hint = "confirm";
- if ((ret = ssh_askpass(askpass, prompt, askpass_hint)) == NULL)
- if (!(flags & RP_ALLOW_EOF))
- return xstrdup("");
- return ret;
+ int ret = getline(&password, &n, stdin);
+ tcsetattr(STDIN_FILENO, TCSAFLUSH, &original);
+ putchar('\n');
+ if (ret < 0) {
+ perror("Failed to read passphrase");
+ exit(errno);
}
- if (readpassphrase(prompt, buf, sizeof buf, rppflags) == NULL) {
- if (flags & RP_ALLOW_EOF)
- return NULL;
- return xstrdup("");
- }
+ // Bit of a dirty way of removing the newline in password
+ password[strcspn(password, "\n")] = '\0';
- ret = xstrdup(buf);
- explicit_bzero(buf, sizeof(buf));
- return ret;
+ return password;
}
int