Skip to content

Commit 7a47252

Browse files
committed
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
1 parent 8c753cb commit 7a47252

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

agent/gpg-agent.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ enum cmd_and_opt_values
146146
oAutoExpandSecmem,
147147
oListenBacklog,
148148
oInactivityTimeout,
149+
oChangeStdEnvName,
149150

150151
oWriteEnvFile,
151152

@@ -239,7 +240,7 @@ static gpgrt_opt_t opts[] = {
239240
ARGPARSE_s_i (oListenBacklog, "listen-backlog", "@"),
240241
ARGPARSE_op_u (oAutoExpandSecmem, "auto-expand-secmem", "@"),
241242
ARGPARSE_s_s (oFakedSystemTime, "faked-system-time", "@"),
242-
243+
ARGPARSE_s_s (oChangeStdEnvName, "change-std-env-name", "@"),
243244

244245
ARGPARSE_header ("Security", N_("Options controlling the security")),
245246

@@ -1299,6 +1300,10 @@ main (int argc, char **argv)
12991300
case oKeepTTY: opt.keep_tty = 1; break;
13001301
case oKeepDISPLAY: opt.keep_display = 1; break;
13011302

1303+
case oChangeStdEnvName:
1304+
session_env_mod_stdenvnames (pargs.r.ret_str);
1305+
break;
1306+
13021307
case oSSHSupport:
13031308
ssh_support = 1;
13041309
break;

common/session-env.c

+43-6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static struct
6363
{
6464
const char *name;
6565
const char *assname; /* Name used by Assuan or NULL. */
66+
unsigned int disabled;/* The entry is not valid */
6667
} stdenvnames[] = {
6768
{ "GPG_TTY", "ttyname" }, /* GnuPG specific envvar. */
6869
{ "TERM", "ttytype" }, /* Used to set ttytype. */
@@ -97,11 +98,41 @@ static struct
9798
allocation. Note that this is not reentrant if used with a
9899
preemptive thread model. */
99100
static size_t lastallocatedarraysize;
100-
#define INITIAL_ARRAYSIZE 8 /* Let's use the number of stdenvnames. */
101-
#define CHUNK_ARRAYSIZE 10
101+
#define INITIAL_ARRAYSIZE 14 /* Let's use the number of stdenvnames. */
102+
#define CHUNK_ARRAYSIZE 16
102103
#define MAXDEFAULT_ARRAYSIZE (INITIAL_ARRAYSIZE + CHUNK_ARRAYSIZE * 5)
103104

104105

106+
/* Modify the list of environment names which are known to gpg-agent.
107+
* This function must be called before the session names are used and
108+
* should not be changed later. The syntax for NAME is:
109+
*
110+
* -FOO := Remove the environment variable FOO from the list
111+
* [+]FOO := Add the environment variable FOO to the list
112+
* [+]FOO:bar := Ditto, but also add "bar" as Assuan alias.
113+
*
114+
* Note that adding environment variables is not yet supported and
115+
* silently ignored.
116+
*/
117+
void
118+
session_env_mod_stdenvnames (const char *name)
119+
{
120+
int idx;
121+
122+
if (*name != '-')
123+
return;
124+
name++;
125+
if (!*name)
126+
return;
127+
128+
for (idx = 0; idx < DIM (stdenvnames); idx++)
129+
{
130+
if (!strcmp (stdenvnames[idx].name, name))
131+
stdenvnames[idx].disabled = 1;
132+
}
133+
}
134+
135+
105136
/* Return the names of standard environment variables one after the
106137
other. The caller needs to set the value at the address of
107138
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)
133164
p = commastring;
134165
for (idx = 0; idx < DIM (stdenvnames); idx++)
135166
{
167+
if (stdenvnames[idx].disabled)
168+
continue;
136169
if (idx)
137170
*p++ = ',';
138171
p = stpcpy (p, stdenvnames[idx].name);
@@ -142,10 +175,14 @@ session_env_list_stdenvnames (int *iterator, const char **r_assname)
142175
return commastring;
143176
}
144177

145-
idx = *iterator;
146-
if (idx < 0 || idx >= DIM (stdenvnames))
147-
return NULL;
148-
*iterator = idx + 1;
178+
do
179+
{
180+
idx = *iterator;
181+
if (idx < 0 || idx >= DIM (stdenvnames))
182+
return NULL;
183+
*iterator = idx + 1;
184+
}
185+
while (stdenvnames[idx].disabled);
149186
if (r_assname)
150187
*r_assname = stdenvnames[idx].assname;
151188
return stdenvnames[idx].name;

common/session-env.h

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
struct session_environment_s;
3434
typedef struct session_environment_s *session_env_t;
3535

36+
void session_env_mod_stdenvnames (const char *name);
3637
const char *session_env_list_stdenvnames (int *iterator,
3738
const char **r_assname);
3839

doc/gpg-agent.texi

+10
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,16 @@ Ignore requests to change the current @code{tty} or X window system's
588588
@code{DISPLAY} variable respectively. This is useful to lock the
589589
pinentry to pop up at the @code{tty} or display you started the agent.
590590

591+
@item --change-std-env-name -@var{name}
592+
@opindex change-std-env-name
593+
The agent uses a fixed list of environment variables which are passed
594+
on to the Pinentry. This option allows to remove variables from that
595+
list. For example:
596+
@smallexample
597+
change-std-env-name -DBUS_SESSION_BUS_ADDRESS
598+
@end smallexample
599+
600+
591601
@item --listen-backlog @var{n}
592602
@opindex listen-backlog
593603
Set the size of the queue for pending connections. The default is 64.

0 commit comments

Comments
 (0)