[PATCH] Avoid crippled getpass function on Solaris

Subsystems: the rest

DORMANTno replies

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] Avoid crippled getpass function on Solaris

From: Ben Walton <hidden>
Date: 2016-06-15 22:54:25

On Solaris getpass() returns at most 8 characters which cripples the
credential reading for accounts using longer passwords.  The alternate
function getpassphrase() was introduced in SunOS 5.6 and will return
up to 256 characters.

Ensure that git_terminal_prompt uses the more able function when
building on Solaris.

Signed-off-by: Ben Walton <redacted>
---

Hi Jeff and Junio,

I considered making this minor change a few different ways but settled
on this as it seemed (to my eye) to most closely adhere to the way
other such things were done in the compatibility code. I'm entirely
open to modifying this if it's felt that there is a clearer/cleaner
way to do it.

I'd even considered making the function swap generic enough to be
driven by the build system.  That seemed over the top though, given
that most systems either have a decent getpass() or don't use this
code path at all.

I've also briefly dabbled with getting Solaris to simply use the
HAVE_DEV_TTY code path but the terminal echo stuff hasn't worked
nicely for me just yet.  (It reads the password with nothing echoed
but then displays the string after reading the newline.)  This might
still be a better approach in the future, but for now, having long
password reading capability will still be a benefit to users on this
platform.

Thanks
-Ben

 compat/terminal.c |    2 +-
 compat/terminal.h |    9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/compat/terminal.c b/compat/terminal.c
index 6d16c8f..e1ab536 100644
--- a/compat/terminal.c
+++ b/compat/terminal.c
@@ -75,7 +75,7 @@ char *git_terminal_prompt(const char *prompt, int echo)
 
 char *git_terminal_prompt(const char *prompt, int echo)
 {
-	return getpass(prompt);
+	return GETPASS(prompt);
 }
 
 #endif
diff --git a/compat/terminal.h b/compat/terminal.h
index 97db7cd..8d7b3f9 100644
--- a/compat/terminal.h
+++ b/compat/terminal.h
@@ -3,4 +3,13 @@
 
 char *git_terminal_prompt(const char *prompt, int echo);
 
+/* getpass() returns at most 8 characters on solaris so use
+   getpassphrase() which returns up to 256. */
+# if defined (__SVR4) && defined (__sun) /* solaris */
+#define GETPASS getpassphrase
+#else
+#define GETPASS getpass
+#endif
+
+
 #endif /* COMPAT_TERMINAL_H */
-- 
1.7.10.3

Re: [PATCH] Avoid crippled getpass function on Solaris

From: Tay Ray Chuan <hidden>
Date: 2016-06-15 22:54:25

On Mon, Aug 6, 2012 at 7:17 AM, Ben Walton [off-list ref] wrote:
I've also briefly dabbled with getting Solaris to simply use the
HAVE_DEV_TTY code path but the terminal echo stuff hasn't worked
nicely for me just yet.  (It reads the password with nothing echoed
but then displays the string after reading the newline.)  This might
still be a better approach in the future, but for now, having long
password reading capability will still be a benefit to users on this
platform.
Replacing

	if (!echo) {
		putc('\n', fh);
		fflush(fh);
	}

with

	if (!echo)
		write(term_fd, "\n", 1);

fixed that. Using fd's instead of FILE* was mentioned at [1]. Perhaps
that is the direction to go in.

[1] http://mid.gmane.org/[off-list ref]

-- 
Cheers,
Ray Chuan

Re: [PATCH] Avoid crippled getpass function on Solaris

From: Ben Walton <hidden>
Date: 2016-06-15 22:54:25

Excerpts from Tay Ray Chuan's message of Sun Aug 05 21:56:55 -0400 2012:
quoted
I've also briefly dabbled with getting Solaris to simply use the
HAVE_DEV_TTY code path but the terminal echo stuff hasn't worked
nicely for me just yet.  (It reads the password with nothing
echoed but then displays the string after reading the newline.)
This might still be a better approach in the future, but for now,
having long password reading capability will still be a benefit to
users on this platform.
Replacing

    if (!echo) {
        putc('\n', fh);
        fflush(fh);
    }

with

    if (!echo)
        write(term_fd, "\n", 1);

fixed that. Using fd's instead of FILE* was mentioned at [1]. Perhaps
that is the direction to go in.
Oh, interesting.  I'd missed your update of this thread earlier
today.  It may make sense to do everything via file descriptors
directly as you suggested in your comments on that patch.

Thanks
-Ben
--
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help