зеркало из https://github.com/github/putty.git
Unix Pageant: options to select askpass type.
Mostly for debugging purposes, because I'm tired of having to use 'setsid' to force Pageant to select the GUI passphrase prompt when I'm trying to fix bugs in gtkask.c. But I can also imagine situations in which the ability to force a GUI prompt window might be useful to end users, for example if the process does _technically_ have a controlling terminal but it's not a user-visible one (say, in the back end of some automation tool like expect(1)). For symmetry, I also provide an option to force the tty prompt. That's less obviously useful, because that's already the preferred prompt type when both methods are available - so the only use for it would be if you wanted to ensure that Pageant didn't _accidentally_ try to launch a GUI prompt, and aborted with an error if it couldn't use a tty prompt.
This commit is contained in:
Родитель
a3503fd234
Коммит
e6b06c900f
|
@ -127,6 +127,8 @@ static void usage(void)
|
|||
printf("Other options:\n");
|
||||
printf(" -v verbose mode (in agent mode)\n");
|
||||
printf(" -s -c force POSIX or C shell syntax (in agent mode)\n");
|
||||
printf(" --tty-prompt force tty-based passphrase prompt (in -a mode)\n");
|
||||
printf(" --gui-prompt force GUI-based passphrase prompt (in -a mode)\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -337,10 +339,12 @@ enum {
|
|||
LIFE_UNSPEC, LIFE_X11, LIFE_TTY, LIFE_DEBUG, LIFE_PERM, LIFE_EXEC
|
||||
} life = LIFE_UNSPEC;
|
||||
const char *display = NULL;
|
||||
enum {
|
||||
PROMPT_UNSPEC, PROMPT_TTY, PROMPT_GUI
|
||||
} prompt_type = PROMPT_UNSPEC;
|
||||
|
||||
static char *askpass(const char *comment)
|
||||
static char *askpass_tty(const char *comment)
|
||||
{
|
||||
if (have_controlling_tty()) {
|
||||
int ret;
|
||||
prompts_t *p = new_prompts(NULL);
|
||||
p->to_server = FALSE;
|
||||
|
@ -360,7 +364,10 @@ static char *askpass(const char *comment)
|
|||
free_prompts(p);
|
||||
return passphrase;
|
||||
}
|
||||
} else if (display) {
|
||||
}
|
||||
|
||||
static char *askpass_gui(const char *comment)
|
||||
{
|
||||
char *prompt, *passphrase;
|
||||
int success;
|
||||
|
||||
|
@ -380,6 +387,32 @@ static char *askpass(const char *comment)
|
|||
passphrase = NULL;
|
||||
}
|
||||
return passphrase;
|
||||
}
|
||||
|
||||
static char *askpass(const char *comment)
|
||||
{
|
||||
if (prompt_type == PROMPT_TTY) {
|
||||
if (!have_controlling_tty()) {
|
||||
fprintf(stderr, "no controlling terminal available "
|
||||
"for passphrase prompt\n");
|
||||
return NULL;
|
||||
}
|
||||
return askpass_tty(comment);
|
||||
}
|
||||
|
||||
if (prompt_type == PROMPT_GUI) {
|
||||
if (!display) {
|
||||
fprintf(stderr, "no graphical display available "
|
||||
"for passphrase prompt\n");
|
||||
return NULL;
|
||||
}
|
||||
return askpass_gui(comment);
|
||||
}
|
||||
|
||||
if (have_controlling_tty()) {
|
||||
return askpass_tty(comment);
|
||||
} else if (display) {
|
||||
return askpass_gui(comment);
|
||||
} else {
|
||||
fprintf(stderr, "no way to read a passphrase without tty or "
|
||||
"X display\n");
|
||||
|
@ -1026,6 +1059,10 @@ int main(int argc, char **argv)
|
|||
"after --exec\n");
|
||||
exit(1);
|
||||
}
|
||||
} else if (!strcmp(p, "--tty-prompt")) {
|
||||
prompt_type = PROMPT_TTY;
|
||||
} else if (!strcmp(p, "--gui-prompt")) {
|
||||
prompt_type = PROMPT_GUI;
|
||||
} else if (!strcmp(p, "--")) {
|
||||
doing_opts = FALSE;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче