1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

agent: New option --change-std-env-name.

* common/session-env.c (stdenvnames): Add field "disabled".
(INITIAL_ARRAYSIZE): Increase size a bit.
(session_env_mod_stdenvnames): New.
(session_env_list_stdenvnames): Handle the disabled flag.
* agent/gpg-agent.c (oChangeStdEnvName): New.
(opts): Add --change-std-env-name.
(main): Implement option.
--

GnuPG-bug-id: 7522
This commit is contained in:
Werner Koch 2025-02-12 11:15:21 +01:00
parent 8c753cb7c9
commit 7a47252516
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
4 changed files with 60 additions and 7 deletions

View file

@ -63,6 +63,7 @@ static struct
{
const char *name;
const char *assname; /* Name used by Assuan or NULL. */
unsigned int disabled;/* The entry is not valid */
} stdenvnames[] = {
{ "GPG_TTY", "ttyname" }, /* GnuPG specific envvar. */
{ "TERM", "ttytype" }, /* Used to set ttytype. */
@ -97,11 +98,41 @@ static struct
allocation. Note that this is not reentrant if used with a
preemptive thread model. */
static size_t lastallocatedarraysize;
#define INITIAL_ARRAYSIZE 8 /* Let's use the number of stdenvnames. */
#define CHUNK_ARRAYSIZE 10
#define INITIAL_ARRAYSIZE 14 /* Let's use the number of stdenvnames. */
#define CHUNK_ARRAYSIZE 16
#define MAXDEFAULT_ARRAYSIZE (INITIAL_ARRAYSIZE + CHUNK_ARRAYSIZE * 5)
/* Modify the list of environment names which are known to gpg-agent.
* This function must be called before the session names are used and
* should not be changed later. The syntax for NAME is:
*
* -FOO := Remove the environment variable FOO from the list
* [+]FOO := Add the environment variable FOO to the list
* [+]FOO:bar := Ditto, but also add "bar" as Assuan alias.
*
* Note that adding environment variables is not yet supported and
* silently ignored.
*/
void
session_env_mod_stdenvnames (const char *name)
{
int idx;
if (*name != '-')
return;
name++;
if (!*name)
return;
for (idx = 0; idx < DIM (stdenvnames); idx++)
{
if (!strcmp (stdenvnames[idx].name, name))
stdenvnames[idx].disabled = 1;
}
}
/* Return the names of standard environment variables one after the
other. The caller needs to set the value at the address of
ITERATOR initially to 0 and then call this function until it
@ -133,6 +164,8 @@ session_env_list_stdenvnames (int *iterator, const char **r_assname)
p = commastring;
for (idx = 0; idx < DIM (stdenvnames); idx++)
{
if (stdenvnames[idx].disabled)
continue;
if (idx)
*p++ = ',';
p = stpcpy (p, stdenvnames[idx].name);
@ -142,10 +175,14 @@ session_env_list_stdenvnames (int *iterator, const char **r_assname)
return commastring;
}
idx = *iterator;
if (idx < 0 || idx >= DIM (stdenvnames))
return NULL;
*iterator = idx + 1;
do
{
idx = *iterator;
if (idx < 0 || idx >= DIM (stdenvnames))
return NULL;
*iterator = idx + 1;
}
while (stdenvnames[idx].disabled);
if (r_assname)
*r_assname = stdenvnames[idx].assname;
return stdenvnames[idx].name;

View file

@ -33,6 +33,7 @@
struct session_environment_s;
typedef struct session_environment_s *session_env_t;
void session_env_mod_stdenvnames (const char *name);
const char *session_env_list_stdenvnames (int *iterator,
const char **r_assname);