OpenVPN
env_set.h
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2002-2025 OpenVPN Technologies, Inc. <sales@openvpn.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program (see the file COPYING included with this
21 * distribution); if not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef ENV_SET_H
25#define ENV_SET_H
26
27#include "argv.h"
28#include "basic.h"
29#include "buffer.h"
30#include "common.h"
31
32/*
33 * Handle environmental variable lists
34 */
35
37{
38 char *string;
39 struct env_item *next;
40};
41
42struct env_set
43{
44 struct gc_arena *gc;
45 struct env_item *list;
46};
47
48/* set/delete environmental variable */
49void setenv_str_ex(struct env_set *es, const char *name, const char *value,
50 const unsigned int name_include, const unsigned int name_exclude,
51 const char name_replace, const unsigned int value_include,
52 const unsigned int value_exclude, const char value_replace);
53
54void setenv_counter(struct env_set *es, const char *name, counter_type value);
55
56void setenv_int(struct env_set *es, const char *name, int value);
57
58void setenv_long_long(struct env_set *es, const char *name, long long value);
59
60void setenv_str(struct env_set *es, const char *name, const char *value);
61
62void setenv_str_safe(struct env_set *es, const char *name, const char *value);
63
64void setenv_del(struct env_set *es, const char *name);
65
70void setenv_str_incr(struct env_set *es, const char *name, const char *value);
71
72void setenv_int_i(struct env_set *es, const char *name, const int value, const int i);
73
74void setenv_str_i(struct env_set *es, const char *name, const char *value, const int i);
75
76/* struct env_set functions */
77
78struct env_set *env_set_create(struct gc_arena *gc);
79
80void env_set_destroy(struct env_set *es);
81
82bool env_set_del(struct env_set *es, const char *str);
83
84void env_set_add(struct env_set *es, const char *str);
85
86const char *env_set_get(const struct env_set *es, const char *name);
87
88void env_set_print(int msglevel, const struct env_set *es);
89
96void env_set_write_file(const char *path, const struct env_set *es);
97
98void env_set_inherit(struct env_set *es, const struct env_set *src);
99
100/* returns true if environmental variable name starts with 'password' */
101static inline bool
102is_password_env_var(const char *str)
103{
104 return (strncmp(str, "password", 8) == 0);
105}
106
107/* returns true if environmental variable safe to print to log */
108static inline bool
109env_safe_to_print(const char *str)
110{
111#ifndef UNSAFE_DEBUG
112 if (is_password_env_var(str))
113 {
114 return false;
115 }
116#endif
117 return true;
118}
119
120/* returns true if environmental variable may be passed to an external program */
121bool env_allowed(const char *str);
122
123const char **make_env_array(const struct env_set *es, const bool check_allowed,
124 struct gc_arena *gc);
125
126#endif /* ifndef ENV_SET_H */
uint64_t counter_type
Definition common.h:29
void setenv_counter(struct env_set *es, const char *name, counter_type value)
Definition env_set.c:283
void env_set_print(int msglevel, const struct env_set *es)
Definition env_set.c:212
void env_set_destroy(struct env_set *es)
Definition env_set.c:166
void setenv_int(struct env_set *es, const char *name, int value)
Definition env_set.c:291
void setenv_int_i(struct env_set *es, const char *name, const int value, const int i)
Definition env_set.c:414
void setenv_str_i(struct env_set *es, const char *name, const char *value, const int i)
Definition env_set.c:423
void env_set_write_file(const char *path, const struct env_set *es)
Write a struct env_set to a file.
Definition env_set.c:238
void setenv_str(struct env_set *es, const char *name, const char *value)
Definition env_set.c:307
const char ** make_env_array(const struct env_set *es, const bool check_allowed, struct gc_arena *gc)
Definition env_set.c:440
void env_set_add(struct env_set *es, const char *str)
Definition env_set.c:193
static bool is_password_env_var(const char *str)
Definition env_set.h:102
void setenv_str_ex(struct env_set *es, const char *name, const char *value, const unsigned int name_include, const unsigned int name_exclude, const char name_replace, const unsigned int value_include, const unsigned int value_exclude, const char value_replace)
Definition env_set.c:359
const char * env_set_get(const struct env_set *es, const char *name)
Definition env_set.c:201
void env_set_inherit(struct env_set *es, const struct env_set *src)
Definition env_set.c:262
void setenv_str_incr(struct env_set *es, const char *name, const char *value)
Store the supplied name value pair in the env_set.
Definition env_set.c:329
void setenv_str_safe(struct env_set *es, const char *name, const char *value)
Definition env_set.c:313
struct env_set * env_set_create(struct gc_arena *gc)
Definition env_set.c:156
bool env_allowed(const char *str)
Definition env_set.c:432
bool env_set_del(struct env_set *es, const char *str)
Definition env_set.c:183
static bool env_safe_to_print(const char *str)
Definition env_set.h:109
void setenv_long_long(struct env_set *es, const char *name, long long value)
Definition env_set.c:299
void setenv_del(struct env_set *es, const char *name)
Definition env_set.c:352
char * string
Definition env_set.h:38
struct env_item * next
Definition env_set.h:39
struct env_item * list
Definition env_set.h:45
struct gc_arena * gc
Definition env_set.h:44
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:116
struct env_set * es
struct gc_arena gc
Definition test_ssl.c:154