Re: [PATCH] Prompt for a username when an HTTP request 401s
- From
Shawn O. Pearce <spearce@spearce.org>
- Date
- Mar 19, 2010, 14:32 UTC
- Message-ID
- <20100319143205.GB16211@spearce.org>
- In-Reply-To
- <d411cc4a1003182041p67a93bf6i1528a8eaaab5c805@mail.gmail.com>
Scott Chacon <schacon@gmail.com> wrote:
Show 14 quoted lines
> @@ -815,7 +815,18 @@ static int http_request(const char *url, void
> *result, int target, int options)
> ret = HTTP_OK;
> else if (missing_target(&results))
> ret = HTTP_MISSING_TARGET;
> - else
> + else if (results.http_code == 401) {
> + if (user_name) {
> + ret = HTTP_NOAUTH;
> + } else {
> + // it is neccesary to use getpass here because
> + // there appears to be no other clean way to
> + // read/write stdout/stdin
> + user_name = xstrdup(getpass("Username: "));No, getpass is needed here because its very likely stdin/stdout are pipes to our parent process. So we instead need to use /dev/tty, but that is non-portable. Using getpass() can at least be stubbed on other platforms with a different implementation if/when necessary.
-- Shawn.