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-2017 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 is_password_env_var(const char *str)
98 {
99  return (strncmp(str, "password", 8) == 0);
100 }
101 
102 /* returns true if environmental variable safe to print to log */
103 static inline bool env_safe_to_print(const char *str)
104 {
105 #ifndef UNSAFE_DEBUG
106  if (is_password_env_var(str))
107  {
108  return false;
109  }
110 #endif
111  return true;
112 }
113 
114 /* returns true if environmental variable may be passed to an external program */
115 bool env_allowed(const char *str);
116 
117 const char **make_env_array(const struct env_set *es,
118  const bool check_allowed,
119  struct gc_arena *gc);
120 
121 #endif /* ifndef ENV_SET_H */
const char * env_set_get(const struct env_set *es, const char *name)
Definition: env_set.c:203
void setenv_counter(struct env_set *es, const char *name, counter_type value)
Definition: env_set.c:261
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:337
static bool env_safe_to_print(const char *str)
Definition: env_set.h:103
struct gc_arena * gc
Definition: env_set.h:43
void setenv_del(struct env_set *es, const char *name)
Definition: env_set.c:330
const char ** make_env_array(const struct env_set *es, const bool check_allowed, struct gc_arena *gc)
Definition: env_set.c:423
void setenv_int_i(struct env_set *es, const char *name, const int value, const int i)
Definition: env_set.c:397
void setenv_str_safe(struct env_set *es, const char *name, const char *value)
Definition: env_set.c:291
void setenv_long_long(struct env_set *es, const char *name, long long value)
Definition: env_set.c:277
void env_set_add(struct env_set *es, const char *str)
Definition: env_set.c:195
void env_set_print(int msglevel, const struct env_set *es)
Definition: env_set.c:214
void setenv_int(struct env_set *es, const char *name, int value)
Definition: env_set.c:269
void setenv_str_i(struct env_set *es, const char *name, const char *value, const int i)
Definition: env_set.c:406
struct env_item * list
Definition: env_set.h:44
void env_set_inherit(struct env_set *es, const struct env_set *src)
Definition: env_set.c:240
bool env_allowed(const char *str)
Definition: env_set.c:415
unsigned int counter_type
Definition: common.h:38
struct env_item * next
Definition: env_set.h:39
char * string
Definition: env_set.h:38
struct env_set * env_set_create(struct gc_arena *gc)
Definition: env_set.c:158
void setenv_str(struct env_set *es, const char *name, const char *value)
Definition: env_set.c:285
bool env_set_del(struct env_set *es, const char *str)
Definition: env_set.c:185
static bool is_password_env_var(const char *str)
Definition: env_set.h:97
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:307
Garbage collection arena used to keep track of dynamically allocated memory.
Definition: buffer.h:116
void env_set_destroy(struct env_set *es)
Definition: env_set.c:168