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 
37 struct env_item {
38  char *string;
39  struct env_item *next;
40 };
41 
42 struct env_set {
43  struct gc_arena *gc;
44  struct env_item *list;
45 };
46 
47 /* set/delete environmental variable */
48 void 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 
58 void setenv_counter(struct env_set *es, const char *name, counter_type value);
59 
60 void setenv_int(struct env_set *es, const char *name, int value);
61 
62 void setenv_long_long(struct env_set *es, const char *name, long long value);
63 
64 void setenv_str(struct env_set *es, const char *name, const char *value);
65 
66 void setenv_str_safe(struct env_set *es, const char *name, const char *value);
67 
68 void setenv_del(struct env_set *es, const char *name);
69 
74 void setenv_str_incr(struct env_set *es, const char *name, const char *value);
75 
76 void setenv_int_i(struct env_set *es, const char *name, const int value, const int i);
77 
78 void setenv_str_i(struct env_set *es, const char *name, const char *value, const int i);
79 
80 /* struct env_set functions */
81 
82 struct env_set *env_set_create(struct gc_arena *gc);
83 
84 void env_set_destroy(struct env_set *es);
85 
86 bool env_set_del(struct env_set *es, const char *str);
87 
88 void env_set_add(struct env_set *es, const char *str);
89 
90 const char *env_set_get(const struct env_set *es, const char *name);
91 
92 void env_set_print(int msglevel, const struct env_set *es);
93 
94 void env_set_inherit(struct env_set *es, const struct env_set *src);
95 
96 /* returns true if environmental variable name starts with 'password' */
97 static inline bool
98 is_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 */
104 static inline bool
105 env_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 */
117 bool env_allowed(const char *str);
118 
119 const 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 */
make_env_array
const char ** make_env_array(const struct env_set *es, const bool check_allowed, struct gc_arena *gc)
Definition: env_set.c:421
env_item::next
struct env_item * next
Definition: env_set.h:39
env_set::gc
struct gc_arena * gc
Definition: env_set.h:43
env_set_destroy
void env_set_destroy(struct env_set *es)
Definition: env_set.c:166
env_set_add
void env_set_add(struct env_set *es, const char *str)
Definition: env_set.c:193
env_item::string
char * string
Definition: env_set.h:38
es
struct env_set * es
Definition: test_pkcs11.c:133
setenv_int
void setenv_int(struct env_set *es, const char *name, int value)
Definition: env_set.c:267
setenv_str_i
void setenv_str_i(struct env_set *es, const char *name, const char *value, const int i)
Definition: env_set.c:404
env_set_print
void env_set_print(int msglevel, const struct env_set *es)
Definition: env_set.c:212
env_set_get
const char * env_set_get(const struct env_set *es, const char *name)
Definition: env_set.c:201
setenv_counter
void setenv_counter(struct env_set *es, const char *name, counter_type value)
Definition: env_set.c:259
env_set_inherit
void env_set_inherit(struct env_set *es, const struct env_set *src)
Definition: env_set.c:238
env_set::list
struct env_item * list
Definition: env_set.h:44
setenv_str_safe
void setenv_str_safe(struct env_set *es, const char *name, const char *value)
Definition: env_set.c:289
env_allowed
bool env_allowed(const char *str)
Definition: env_set.c:413
setenv_long_long
void setenv_long_long(struct env_set *es, const char *name, long long value)
Definition: env_set.c:275
counter_type
uint64_t counter_type
Definition: common.h:30
argv.h
env_set_create
struct env_set * env_set_create(struct gc_arena *gc)
Definition: env_set.c:156
is_password_env_var
static bool is_password_env_var(const char *str)
Definition: env_set.h:98
buffer.h
gc_arena
Garbage collection arena used to keep track of dynamically allocated memory.
Definition: buffer.h:116
env_set
Definition: env_set.h:42
common.h
basic.h
setenv_str
void setenv_str(struct env_set *es, const char *name, const char *value)
Definition: env_set.c:283
env_item
Definition: env_set.h:37
setenv_str_ex
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
env_set_del
bool env_set_del(struct env_set *es, const char *str)
Definition: env_set.c:183
env_safe_to_print
static bool env_safe_to_print(const char *str)
Definition: env_set.h:105
setenv_int_i
void setenv_int_i(struct env_set *es, const char *name, const int value, const int i)
Definition: env_set.c:395
setenv_del
void setenv_del(struct env_set *es, const char *name)
Definition: env_set.c:328
setenv_str_incr
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