git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Avoid crippled getpass function on Solaris

From
Ben Walton <bwalton@artsci.utoronto.ca>
Date
Aug 5, 2012, 23:17 UTC
Message-ID
<1344208672-20028-1-git-send-email-bwalton@artsci.utoronto.ca>

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 <bwalton@artsci.utoronto.ca>
---
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
Next: Tay Ray Chuan
Message 1 of 27 in “Avoid crippled getpass function on Solaris”
  1. Avoid crippled getpass function on SolarisBen Walton, Aug 5, 2012
  2. Tay Ray ChuanAug 6, 2012
  3. Ben WaltonAug 6, 2012
  4. Junio C HamanoAug 6, 2012
  5. Ben WaltonAug 6, 2012
  6. Jeff KingAug 6, 2012
  7. Junio C HamanoAug 6, 2012
  8. Ben WaltonAug 6, 2012
  9. Jeff KingAug 6, 2012
  10. Ben WaltonAug 6, 2012
  11. Jeff KingAug 6, 2012
  12. Ben WaltonAug 6, 2012
  13. Jeff KingAug 6, 2012
  14. Ben WaltonAug 6, 2012
  15. Jeff KingAug 7, 2012
  16. Andreas SchwabAug 6, 2012
  17. Jeff KingAug 7, 2012
  18. Jeff KingAug 7, 2012
  19. Tay Ray ChuanAug 7, 2012
  20. Ben WaltonAug 7, 2012
  21. Enable HAVE_DEV_TTY for SolarisBen Walton, Aug 7, 2012
  22. Junio C HamanoAug 7, 2012
  23. Jeff KingAug 7, 2012
  24. Jeff KingAug 7, 2012
  25. Ben WaltonAug 7, 2012
  26. Erik Faye-LundAug 8, 2012
  27. Jeff KingAug 8, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.