core: Defer adding --status-fd and --logger-fd to argument list

* src/engine-gpg.c (_append_to_arglist, _prepend_to_arglist): New.
(_add_arg): Use _append_to_arglist and _prepend_to_arglist.
(add_data_ext): New. Extends add_data.
(add_data): Uses add_data_ext.
(gpg_new): Do not add --status-fd and --logger-fd to argument list.
(start): Prepend --logger-fd and --status-fd to the argument list.
--

This change makes it possible to handle those two arguments differently
if gpgtar is used instead of gpg.

GnuPG-bug-id: 6342
This commit is contained in:
Ingo Klöcker 2023-01-18 10:54:39 +01:00
parent 7a68a1ca64
commit d56b3bc1cf
No known key found for this signature in database
GPG Key ID: F5A5D1692277A1E9

View File

@ -222,6 +222,27 @@ close_notify_handler (int fd, void *opaque)
} }
} }
static void
_append_to_arglist (engine_gpg_t gpg, struct arg_and_data_s *a)
{
a->next = NULL;
*gpg->argtail = a;
gpg->argtail = &a->next;
}
static void
_prepend_to_arglist (engine_gpg_t gpg, struct arg_and_data_s *a)
{
a->next = gpg->arglist;
if (!gpg->arglist)
{
/* If this is the first argument, we need to update the tail
pointer. */
gpg->argtail = &a->next;
}
gpg->arglist = a;
}
/* If FRONT is true, push at the front of the list. Use this for /* If FRONT is true, push at the front of the list. Use this for
options added late in the process. */ options added late in the process. */
static gpgme_error_t static gpgme_error_t
@ -247,22 +268,9 @@ _add_arg (engine_gpg_t gpg, const char *prefix, const char *arg, size_t arglen,
memcpy (a->arg + prefixlen, arg, arglen); memcpy (a->arg + prefixlen, arg, arglen);
a->arg[prefixlen + arglen] = 0; a->arg[prefixlen + arglen] = 0;
if (front) if (front)
{ _prepend_to_arglist (gpg, a);
a->next = gpg->arglist;
if (!gpg->arglist)
{
/* If this is the first argument, we need to update the tail
pointer. */
gpg->argtail = &a->next;
}
gpg->arglist = a;
}
else else
{ _append_to_arglist (gpg, a);
a->next = NULL;
*gpg->argtail = a;
gpg->argtail = &a->next;
}
return 0; return 0;
} }
@ -301,7 +309,7 @@ add_arg_len (engine_gpg_t gpg, const char *prefix,
static gpgme_error_t static gpgme_error_t
add_data (engine_gpg_t gpg, gpgme_data_t data, int dup_to, int inbound) add_data_ext (engine_gpg_t gpg, gpgme_data_t data, int dup_to, int inbound, int front)
{ {
struct arg_and_data_s *a; struct arg_and_data_s *a;
@ -311,7 +319,6 @@ add_data (engine_gpg_t gpg, gpgme_data_t data, int dup_to, int inbound)
a = malloc (offsetof (struct arg_and_data_s, arg)); a = malloc (offsetof (struct arg_and_data_s, arg));
if (!a) if (!a)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
a->next = NULL;
a->data = data; a->data = data;
a->inbound = inbound; a->inbound = inbound;
a->arg_locp = NULL; a->arg_locp = NULL;
@ -326,12 +333,22 @@ add_data (engine_gpg_t gpg, gpgme_data_t data, int dup_to, int inbound)
a->print_fd = 0; a->print_fd = 0;
a->dup_to = dup_to; a->dup_to = dup_to;
} }
*gpg->argtail = a;
gpg->argtail = &a->next; if (front)
_prepend_to_arglist (gpg, a);
else
_append_to_arglist (gpg, a);
return 0; return 0;
} }
static gpgme_error_t
add_data (engine_gpg_t gpg, gpgme_data_t data, int dup_to, int inbound)
{
return add_data_ext (gpg, data, dup_to, inbound, 0);
}
/* Return true if the engine's version is at least VERSION. */ /* Return true if the engine's version is at least VERSION. */
static int static int
have_gpg_version (engine_gpg_t gpg, const char *version) have_gpg_version (engine_gpg_t gpg, const char *version)
@ -547,18 +564,6 @@ gpg_new (void **engine, const char *file_name, const char *home_dir,
goto leave; goto leave;
} }
rc = add_arg (gpg, "--status-fd");
if (rc)
goto leave;
{
char buf[25];
_gpgme_io_fd2str (buf, sizeof (buf), gpg->status.fd[1]);
rc = add_arg_with_locp (gpg, buf, &gpg->status.arg_loc);
if (rc)
goto leave;
}
rc = add_arg (gpg, "--no-tty"); rc = add_arg (gpg, "--no-tty");
if (!rc) if (!rc)
rc = add_arg (gpg, "--charset"); rc = add_arg (gpg, "--charset");
@ -632,16 +637,6 @@ gpg_new (void **engine, const char *file_name, const char *home_dir,
} }
} }
rc = gpgme_data_new (&gpg->diagnostics);
if (rc)
goto leave;
rc = add_arg (gpg, "--logger-fd");
if (rc)
goto leave;
rc = add_data (gpg, gpg->diagnostics, -2, 1);
leave: leave:
if (rc) if (rc)
gpg_release (gpg); gpg_release (gpg);
@ -1547,6 +1542,30 @@ start (engine_gpg_t gpg)
if (!gpg->file_name && !_gpgme_get_default_gpg_name ()) if (!gpg->file_name && !_gpgme_get_default_gpg_name ())
return trace_gpg_error (GPG_ERR_INV_ENGINE); return trace_gpg_error (GPG_ERR_INV_ENGINE);
rc = gpgme_data_new (&gpg->diagnostics);
if (rc)
return rc;
rc = add_data_ext (gpg, gpg->diagnostics, -2, 1, 1);
if (rc)
return rc;
rc = add_arg_ext (gpg, "--logger-fd", 1);
if (rc)
return rc;
{
char buf[25];
_gpgme_io_fd2str (buf, sizeof (buf), gpg->status.fd[1]);
rc = add_arg_with_locp (gpg, buf, &gpg->status.arg_loc, 1);
if (rc)
return rc;
}
rc = add_arg_ext (gpg, "--status-fd", 1);
if (rc)
return rc;
if (gpg->lc_ctype) if (gpg->lc_ctype)
{ {
rc = add_arg_ext (gpg, gpg->lc_ctype, 1); rc = add_arg_ext (gpg, gpg->lc_ctype, 1);