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

Re: Is getpass(3) really obsolete?

From
Jeff King <peff@peff.net>
Date
Oct 29, 2021, 20:27 UTC
Message-ID
<YXxZFaqHq9/aEQCO@coredump.intra.peff.net>
In-Reply-To
<73ac38a2-c287-4cc1-4e9c-0f9766ac4c0c@gmail.com>
On Fri, Oct 29, 2021 at 01:28:56PM +0200, Alejandro Colomar (man-pages) wrote:
> > As a real example, git(1) uses getpass(3).
> > <https://github.com/git/git/blob/master/compat/terminal.c>

Sort of. It is the compile-time fallback of last resort. Most builds would use either termios with /dev/tty or a Windows-native equivalent.

You can see all the reasons we stopped using getpass() in the commit below.

-- >8 --
commit 21aeafceda2382d26bfa73a98ba45a937d65d77a
Author: Jeff King <peff@peff.net>
Date:   Sat Dec 10 05:41:01 2011 -0500
    add generic terminal prompt function
    
    When we need to prompt the user for input interactively, we
    want to access their terminal directly. We can't rely on
    stdio because it may be connected to pipes or files, rather
    than the terminal. Instead, we use "getpass()", because it
    abstracts the idea of prompting and reading from the
    terminal.  However, it has some problems:
    
      1. It never echoes the typed characters, which makes it OK
         for passwords but annoying for other input (like usernames).
    
      2. Some implementations of getpass() have an extremely
         small input buffer (e.g., Solaris 8 is reported to
         support only 8 characters).
    
      3. Some implementations of getpass() will fall back to
         reading from stdin (e.g., glibc). We explicitly don't
         want this, because our stdin may be connected to a pipe
         speaking a particular protocol, and reading will
         disrupt the protocol flow (e.g., the remote-curl
         helper).
    
      4. Some implementations of getpass() turn off signals, so
         that hitting "^C" on the terminal does not break out of
         the password prompt. This can be a mild annoyance.
    
    Instead, let's provide an abstract "git_terminal_prompt"
    function that addresses these concerns. This patch includes
    an implementation based on /dev/tty, enabled by setting
    HAVE_DEV_TTY. The fallback is to use getpass() as before.
    
    Signed-off-by: Jeff King <peff@peff.net>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Previous: Alejandro Colomar
Message 20 of 20 in “Re: Is getpass(3) really obsolete?”
  1. Alejandro Colomar (man-pages)Oct 29, 2021
  2. Ævar Arnfjörð BjarmasonOct 29, 2021
  3. Alejandro Colomar (man-pages)Oct 29, 2021
  4. Joseph MyersOct 29, 2021
  5. Alejandro Colomar (man-pages)Oct 30, 2021
  6. Joseph MyersNov 1, 2021
  7. rsbecker@nexbridge.comOct 29, 2021
  8. Eugene SyromyatnikovOct 29, 2021
  9. Theo de RaadtOct 29, 2021
  10. rsbecker@nexbridge.comOct 29, 2021
  11. Theo de RaadtOct 29, 2021
  12. rsbecker@nexbridge.comOct 29, 2021
  13. Alejandro Colomar (man-pages)Oct 29, 2021
  14. rsbecker@nexbridge.comOct 29, 2021
  15. Zack WeinbergOct 29, 2021
  16. readpassphrase(3) in glibc, and agetpass() (Was: Is getpass(3) really obsolete?)Alejandro Colomar, Sep 27, 2022
  17. Alex ColomarSep 27, 2022
  18. Sam JamesSep 27, 2022
  19. getpass.3: SYNOPSIS: Mark getpass() as [[deprecated]]Alejandro Colomar, Oct 29, 2021
  20. Jeff KingOct 29, 2021

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.