diff options
author | 2018-04-06 13:02:39 +0000 | |
---|---|---|
committer | 2018-04-06 13:02:39 +0000 | |
commit | 34bc3227dd379bb38f7d29ff56418216acba8e02 (patch) | |
tree | d823bd4f84295c18a559afec02c306999e66d508 /usr.bin/ssh/readconf.c | |
parent | After processing of a range request httpd would never close the (diff) | |
download | wireguard-openbsd-34bc3227dd379bb38f7d29ff56418216acba8e02.tar.xz wireguard-openbsd-34bc3227dd379bb38f7d29ff56418216acba8e02.zip |
Allow "SendEnv -PATTERN" to clear environment variables previously
labeled for sendind. bz#1285 ok dtucker@
Diffstat (limited to 'usr.bin/ssh/readconf.c')
-rw-r--r-- | usr.bin/ssh/readconf.c | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/usr.bin/ssh/readconf.c b/usr.bin/ssh/readconf.c index 9ad882f9fd2..51fb141a973 100644 --- a/usr.bin/ssh/readconf.c +++ b/usr.bin/ssh/readconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: readconf.c,v 1.285 2018/04/06 03:51:27 djm Exp $ */ +/* $OpenBSD: readconf.c,v 1.286 2018/04/06 13:02:39 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -669,6 +669,35 @@ match_cfg_line(Options *options, char **condition, struct passwd *pw, return result; } +/* Remove environment variable by pattern */ +static void +rm_env(Options *options, const char *arg, const char *filename, int linenum) +{ + int i, j; + char *cp; + + /* Remove an environment variable */ + for (i = 0; i < options->num_send_env; ) { + cp = xstrdup(options->send_env[i]); + if (!match_pattern(cp, arg + 1)) { + free(cp); + i++; + continue; + } + debug3("%s line %d: removing environment %s", + filename, linenum, cp); + free(cp); + free(options->send_env[i]); + options->send_env[i] = NULL; + for (j = i; j < options->num_send_env - 1; j++) { + options->send_env[j] = options->send_env[j + 1]; + options->send_env[j + 1] = NULL; + } + options->num_send_env--; + /* NB. don't increment i */ + } +} + /* * Returns the number of the token pointed to by cp or oBadOption. */ @@ -1344,11 +1373,18 @@ parse_keytypes: filename, linenum); if (!*activep) continue; - if (options->num_send_env >= MAX_SEND_ENV) - fatal("%s line %d: too many send env.", - filename, linenum); - options->send_env[options->num_send_env++] = - xstrdup(arg); + if (*arg == '-') { + /* Removing an env var */ + rm_env(options, arg, filename, linenum); + continue; + } else { + /* Adding an env var */ + if (options->num_send_env >= MAX_SEND_ENV) + fatal("%s line %d: too many send env.", + filename, linenum); + options->send_env[options->num_send_env++] = + xstrdup(arg); + } } break; |