mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
tests: Simplify fake-pinentry to use the option only.
* tests/openpgp/fake-pinentry.c (parse_pinentry_user_data): New. (main): Don't use PINENTRY_USER_DATA env var. -- Since environment variable is unreliable, use the option only. Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
7c6b014d3b
commit
0a93b5b96a
@ -196,26 +196,20 @@ option_value (const char *line, const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
static int
|
||||
parse_pinentry_user_data (const char *args,
|
||||
char **r_passphrase)
|
||||
{
|
||||
char *args;
|
||||
char *option_user_data = NULL;
|
||||
char *logfile;
|
||||
char *passphrasefile;
|
||||
char *passphrase;
|
||||
|
||||
/* We get our options via PINENTRY_USER_DATA. */
|
||||
(void) argc, (void) argv;
|
||||
*r_passphrase = NULL;
|
||||
|
||||
setvbuf (stdin, NULL, _IOLBF, BUFSIZ);
|
||||
setvbuf (stdout, NULL, _IOLBF, BUFSIZ);
|
||||
if (log_stream)
|
||||
fclose (log_stream);
|
||||
log_stream = NULL;
|
||||
|
||||
args = getenv ("PINENTRY_USER_DATA");
|
||||
if (! args)
|
||||
args = "";
|
||||
|
||||
restart:
|
||||
logfile = option_value (args, "--logfile");
|
||||
if (logfile)
|
||||
{
|
||||
@ -230,7 +224,7 @@ main (int argc, char **argv)
|
||||
if (! log_stream)
|
||||
{
|
||||
perror (logfile);
|
||||
return 1;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,20 +243,31 @@ main (int argc, char **argv)
|
||||
{
|
||||
reply ("# Passphrasefile '%s' is empty. Terminating.\n",
|
||||
passphrasefile);
|
||||
return 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rstrip (passphrase);
|
||||
}
|
||||
else
|
||||
{
|
||||
passphrase = skip_options (args);
|
||||
if (*passphrase == 0)
|
||||
passphrase = "no PINENTRY_USER_DATA -- using default passphrase";
|
||||
passphrase = strdup (skip_options (args));
|
||||
|
||||
*r_passphrase = passphrase;
|
||||
return 0;
|
||||
}
|
||||
|
||||
reply ("# fake-pinentry(%u) started. Passphrase='%s'.\n",
|
||||
(unsigned int)getpid (), passphrase);
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
char *passphrase = NULL;
|
||||
|
||||
/* We get our options via PINENTRY_USER_DATA. */
|
||||
(void) argc, (void) argv;
|
||||
|
||||
setvbuf (stdin, NULL, _IOLBF, BUFSIZ);
|
||||
setvbuf (stdout, NULL, _IOLBF, BUFSIZ);
|
||||
|
||||
reply ("# fake-pinentry(%u) started.\n", (unsigned int)getpid ());
|
||||
reply ("OK - what's up?\n");
|
||||
|
||||
while (! feof (stdin))
|
||||
@ -280,7 +285,12 @@ main (int argc, char **argv)
|
||||
#define OPT_USER_DATA "OPTION pinentry-user-data="
|
||||
|
||||
if (strncmp (buffer, "GETPIN", 6) == 0)
|
||||
{
|
||||
if (passphrase)
|
||||
reply ("D %s\n", passphrase);
|
||||
else
|
||||
reply ("D deafult\n");
|
||||
}
|
||||
else if (strncmp (buffer, "BYE", 3) == 0)
|
||||
{
|
||||
reply ("OK\n");
|
||||
@ -288,13 +298,12 @@ main (int argc, char **argv)
|
||||
}
|
||||
else if (strncmp (buffer, OPT_USER_DATA, strlen (OPT_USER_DATA)) == 0)
|
||||
{
|
||||
/* Prefer interactive data to the one from environment variable. */
|
||||
if (log_stream)
|
||||
fclose (log_stream);
|
||||
log_stream = NULL;
|
||||
free (option_user_data);
|
||||
option_user_data = args = strdup (buffer + strlen (OPT_USER_DATA));
|
||||
goto restart;
|
||||
if (parse_pinentry_user_data (buffer + strlen (OPT_USER_DATA),
|
||||
&passphrase) < 0)
|
||||
{
|
||||
/* Failure. */
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
reply ("OK\n");
|
||||
@ -306,6 +315,7 @@ main (int argc, char **argv)
|
||||
if (log_stream)
|
||||
fclose (log_stream);
|
||||
|
||||
free (option_user_data);
|
||||
if (passphrase)
|
||||
free (passphrase);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user