From: Johannes Sixt <j.sixt@viscovery.net>
To: Frank Li <lznuaa@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com
Subject: Re: [PATCH v2 2/3] git-core: Support retrieving passwords with GIT_ASKPASS
Date: Fri, 26 Feb 2010 08:34:21 +0100 [thread overview]
Message-ID: <4B87797D.7030905@viscovery.net> (raw)
In-Reply-To: <1267143154-5020-1-git-send-email-lznuaa@gmail.com>
Frank Li schrieb:
> connect.c | 40 ++++++++++++++++++++++++++++++++++++++++
> http.c | 4 ++--
> imap-send.c | 2 +-
I don't see any header file changes. Don't you get warnings about an
undeclared function git_getpass() at the call sites?
> +char *git_getpass(char *prompt)
char *git_getpass(const char *prompt)
> + askpass = getenv("GIT_ASKPASS");
> + if (askpass && strlen(askpass) != 0) {
> + args[0] = getenv("GIT_ASKPASS");
if (askpass && *askpass) {
args[0] = askpass;
BTW, to save a level of indentation, you could handle the "trivial" case
early like this:
if (!askpass || !*askpass)
return get_pass(prompt);
and continue without an 'else' branch.
> + args[1] = prompt;
> + args[2] = NULL;
> +
> + memset(&pass, 0, sizeof(pass));
> + pass.argv = args;
> + pass.out = -1;
> + pass.no_stdin = 1;
> + pass.no_stderr = 1;
Is it such a good idea to redirect stdin and stderr to /dev/null? What if
my password prompt program depends on them? I think it should not matter
for your use-case, where a GUI is invoked, to just inherit all channels.
OTOH, it may be worthwhile to set
pass.use_shell = 1;
to allow commands that are not just a single plain word. But perhaps this
has security implications - I don't know.
> +
> + if (start_command(&pass)) {
> + error("could not run %s\n", askpass);
> + return getpass(prompt);
I don't think this is a good idea. The user instructed to use GIT_ASKPASS,
and you fall back to asking a password from the terminal. I think the most
sensible thing to do here is to 'exit(1)' (start_command has already
printed an error message that included the command), because there are
callers that do not expect NULL.
> + }
> +
> + strbuf_read(&buffer, pass.out, 20);
> + close(pass.out);
> + for (i = 0; i < buffer.len; i++)
> + if (buffer.buf[i] == '\n' || buffer.buf[i] == '\r') {
> + buffer.buf[i] = '\0';
> + buffer.len = i;
> + }
> + return strbuf_detach(&buffer, NULL);
You don't call finish_command() anywhere. Call it after the close() call.
> +
> + } else {
> + return getpass(prompt);
You handle the return value in different ways. getpass() returns a pointer
to a static buffer, but in the 'then' branch you return an allocated
buffer. Not that it matters a lot, though. You could add a comment that
you are aware that the memory is leaked.
> + }
> + return NULL;
What is this good for?
-- Hannes
next prev parent reply other threads:[~2010-02-26 7:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-26 0:12 [PATCH v2 2/3] git-core: Support retrieving passwords with GIT_ASKPASS Frank Li
2010-02-26 0:50 ` Miklos Vajna
2010-02-26 2:17 ` Frank Li
2010-02-26 7:34 ` Johannes Sixt [this message]
2010-02-26 7:50 ` Junio C Hamano
2010-02-26 9:32 ` Johannes Sixt
2010-02-26 17:50 ` Junio C Hamano
2010-02-26 10:01 ` Frank Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4B87797D.7030905@viscovery.net \
--to=j.sixt@viscovery.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=lznuaa@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.