summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2022-12-02 08:55:49 +0100
committerNIIBE Yutaka <gniibe@fsij.org>2022-12-02 08:55:49 +0100
commit0a93b5b96a3bfcca52a8288e9847f06e495b461e (patch)
tree9b73e1c1c1327dea7ba9dd6af2f586b6c36ba295
parenttests: Fix fake-pinentry for Windows. (diff)
downloadgnupg2-0a93b5b96a3bfcca52a8288e9847f06e495b461e.tar.xz
gnupg2-0a93b5b96a3bfcca52a8288e9847f06e495b461e.zip
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>
-rw-r--r--tests/openpgp/fake-pinentry.c72
1 files changed, 41 insertions, 31 deletions
diff --git a/tests/openpgp/fake-pinentry.c b/tests/openpgp/fake-pinentry.c
index 02c4e0d13..18b60574b 100644
--- a/tests/openpgp/fake-pinentry.c
+++ b/tests/openpgp/fake-pinentry.c
@@ -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;
-
- setvbuf (stdin, NULL, _IOLBF, BUFSIZ);
- setvbuf (stdout, NULL, _IOLBF, BUFSIZ);
+ *r_passphrase = NULL;
- args = getenv ("PINENTRY_USER_DATA");
- if (! args)
- args = "";
+ if (log_stream)
+ fclose (log_stream);
+ log_stream = NULL;
- 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)
- reply ("D %s\n", passphrase);
+ {
+ 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;
}