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-2024 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, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#ifndef ENV_SET_H
26#define ENV_SET_H
27
28#include "argv.h"
29#include "basic.h"
30#include "buffer.h"
31#include "common.h"
32
33/*
34 * Handle environmental variable lists
35 */
36
37struct env_item {
38 char *string;
39 struct env_item *next;
40};
41
42struct env_set {
43 struct gc_arena *gc;
44 struct env_item *list;
45};
46
47/* set/delete environmental variable */
48void setenv_str_ex(struct env_set *es,
49 const char *name,
50 const char *value,
51 const unsigned int name_include,
52 const unsigned int name_exclude,
53 const char name_replace,
54 const unsigned int value_include,
55 const unsigned int value_exclude,
56 const char value_replace);
57
58void setenv_counter(struct env_set *es, const char *name, counter_type value);
59
60void setenv_int(struct env_set *es, const char *name, int value);
61
62void setenv_long_long(struct env_set *es, const char *name, long long value);
63
64void setenv_str(struct env_set *es, const char *name, const char *value);
65
66void setenv_str_safe(struct env_set *es, const char *name, const char *value);
67
68void setenv_del(struct env_set *es, const char *name);
69
74void setenv_str_incr(struct env_set *es, const char *name, const char *value);
75
76void setenv_int_i(struct env_set *es, const char *name, const int value, const int i);
77
78void setenv_str_i(struct env_set *es, const char *name, const char *value, const int i);
79
80/* struct env_set functions */
81
82struct env_set *env_set_create(struct gc_arena *gc);
83
84void env_set_destroy(struct env_set *es);
85
86bool env_set_del(struct env_set *es, const char *str);
87
88void env_set_add(struct env_set *es, const char *str);
89
90const char *env_set_get(const struct env_set *es, const char *name);
91
92void env_set_print(int msglevel, const struct env_set *es);
93
94void env_set_inherit(struct env_set *es, const struct env_set *src);
95
96/* returns true if environmental variable name starts with 'password' */
97static inline bool
98is_password_env_var(const char *str)
99{
100 return (strncmp(str, "password", 8) == 0);
101}
102
103/* returns true if environmental variable safe to print to log */
104static inline bool
105env_safe_to_print(const char *str)
106{
107#ifndef UNSAFE_DEBUG
108 if (is_password_env_var(str))
109 {
110 return false;
111 }
112#endif
113 return true;
114}
115
116/* returns true if environmental variable may be passed to an external program */
117bool env_allowed(const char *str);
118
119const char **make_env_array(const struct env_set *es,
120 const bool check_allowed,
121 struct gc_arena *gc);
122
123#endif /* ifndef ENV_SET_H */
uint64_t counter_type
Definition common.h:30
void setenv_counter(struct env_set *es, const char *name, counter_type value)
Definition env_set.c:259
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:267
void setenv_int_i(struct env_set *es, const char *name, const int value, const int i)
Definition env_set.c:395
void setenv_str_i(struct env_set *es, const char *name, const char *value, const int i)
Definition env_set.c:404
void setenv_str(struct env_set *es, const char *name, const char *value)
Definition env_set.c:283
const char ** make_env_array(const struct env_set *es, const bool check_allowed, struct gc_arena *gc)
Definition env_set.c:421
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:98
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:335
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:238
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:305
void setenv_str_safe(struct env_set *es, const char *name, const char *value)
Definition env_set.c:289
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:413
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:105
void setenv_long_long(struct env_set *es, const char *name, long long value)
Definition env_set.c:275
void setenv_del(struct env_set *es, const char *name)
Definition env_set.c:328
char * string
Definition env_set.h:38
struct env_item * next
Definition env_set.h:39
struct env_item * list
Definition env_set.h:44
struct gc_arena * gc
Definition env_set.h:43
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:117
struct env_set * es
struct gc_arena gc
Definition test_ssl.c:155