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

Re: [PATCH] compat: add a getpass() compatibility function

From
Erik Faye-Lund <kusmabite@gmail.com>
Date
May 19, 2011, 12:17 UTC
Message-ID
<BANLkTinPHeSfZXRb7pqt7-XWkR5fH=wAjg@mail.gmail.com>
In-Reply-To
<563395AE-A3E5-45FF-9063-F807C2CE3AD0@gieschke.de>
On Thu, May 19, 2011 at 1:37 PM, Rafael Gieschke <rafael@gieschke.de> wrote:
>
> If NO_GETPASS is set, getpass is provided in compat/getpass.c from
> https://github.com/CyanogenMod/android_external_dropbear/raw/master/netbsd_getpass.c
> (getpass was renamed to gitgetpass).
Nice.

But I can't help to think that this implementation of getpass looks a bit heavy, especially since we already have our own getpass implementation in compat/mingw.c.

Do we really need two implementations? Wouldn't it be better to factor out the mingw-version to a separate source file, and then improve it?

Windows doesn't have /dev/tty, but the logic in this version handles that by using stdin/stderr instead. The signal-stuff has a comment that indicates it might not even be correct. tcgetattr/tcsetattr isn't supported on Windows, but it's not needed if we use getch (as the version in compat/mingw.c does). POSIX/curses getch respects the echo-setting, while Windows getch never echo.

Given the information above, it sounds to me like we can enhance the version we already have to behave as it should also on non-Windows platforms, without having to maintain two versions. But it might not be worth it, given the simplicity of the Windows version and the increased dependency of curses, I dunno.

As a Windows-guy, I'm not entirely comfortable with putting something in compat/[function-name].c that is only portable to POSIX-platforms. This is not the current trend, but that might not be a conscious choice.

Show 46 quoted lines
> diff --git a/compat/getpass.c b/compat/getpass.c
> new file mode 100644
> index 0000000..e13f29f
> --- /dev/null
> +++ b/compat/getpass.c
> @@ -0,0 +1,114 @@
> +/*     $NetBSD: getpass.c,v 1.15 2003/08/07 16:42:50 agc Exp $ */
> +
> +/*
> + * Copyright (c) 1988, 1993
> + *     The Regents of the University of California.  All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + * 3. Neither the name of the University nor the names of its contributors
> + *    may be used to endorse or promote products derived from this software
> + *    without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + */
> +
> +#if 0
> +#include <sys/cdefs.h>
> +#if defined(LIBC_SCCS) && !defined(lint)
> +#if 0
> +static char sccsid[] = "@(#)getpass.c  8.1 (Berkeley) 6/4/93";
> +#else
> +__RCSID("$NetBSD: getpass.c,v 1.15 2003/08/07 16:42:50 agc Exp $");
> +#endif
> +#endif /* LIBC_SCCS and not lint */

We usually don't keep dead code around. Since you've already edited the file, perhaps you should just delete those lines?

Show 6 quoted lines
> +
> +#if 0
> +#ifdef __weak_alias
> +__weak_alias(getpass,_getpass)
> +#endif
> +#endif
Same here.
Show 11 quoted lines
> +
> +char *
> +gitgetpass(prompt)
> +       const char *prompt;
> +{
> +       struct termios term;
> +       int ch;
> +       char *p;
> +       FILE *fp, *outfp;
> +       int echo;
> +       static char buf[_PASSWORD_LEN + 1];

Is _PASSWORD_LEN portable? A google search of "site:opengroup.org _PASSWORD_LEN " returns nothing...

The getpass implementation in compat/mingw.c uses a strbuf, so it doesn't have a limit on the password-length. Perhaps that would be an improvement here?

Show 5 quoted lines
> +       sigset_t oset, nset;
> +
> +#if 0
> +       _DIAGASSERT(prompt != NULL);
> +#endif
Again, dead code.
Show 6 quoted lines
> +
> +       /*
> +        * read and write to /dev/tty if possible; else read from
> +        * stdin and write to stderr.
> +        */
> +       if ((outfp = fp = fopen(_PATH_TTY, "w+")) == NULL) {

Is _PATH_TTY portable? A google search of "site:opengroup.org _PATH_TTY" returns nothing...

Previous: Rafael GieschkeNext: Junio C Hamano
Message 2 of 19 in “compat: add a getpass() compatibility function”
  1. compat: add a getpass() compatibility functionRafael Gieschke, May 19, 2011
  2. Erik Faye-LundMay 19, 2011
  3. Junio C HamanoMay 19, 2011
  4. Rafael GieschkeMay 19, 2011
  5. Junio C HamanoMay 19, 2011
  6. Erik Faye-LundMay 19, 2011
  7. Rafael GieschkeMay 19, 2011
  8. Erik Faye-LundMay 19, 2011
  9. Rafael GieschkeMay 19, 2011
  10. Erik Faye-LundMay 19, 2011
  11. Erik Faye-LundMay 19, 2011
  12. Rafael GieschkeMay 20, 2011
  13. Erik Faye-LundMay 20, 2011
  14. Junio C HamanoMay 20, 2011
  15. Erik Faye-LundMay 20, 2011
  16. Erik Faye-LundMay 19, 2011
  17. Jonathan NiederMay 19, 2011
  18. Erik Faye-LundMay 19, 2011
  19. Junio C HamanoMay 19, 2011

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.