OpenVPN
misc.c
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 Inc <sales@openvpn.net>
9 * Copyright (C) 2014-2015 David Sommerseth <davids@redhat.com>
10 * Copyright (C) 2016-2025 David Sommerseth <davids@openvpn.net>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2
14 * as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, see <https://www.gnu.org/licenses/>.
23 */
24
25#ifdef HAVE_CONFIG_H
26#include "config.h"
27#endif
28
29#include "syshead.h"
30
31#include "buffer.h"
32#include "misc.h"
33#include "base64.h"
34#include "tun.h"
35#include "error.h"
36#include "otime.h"
37#include "plugin.h"
38#include "options.h"
39#include "manage.h"
40#include "crypto.h"
41#include "route.h"
42#include "console.h"
43#include "win32.h"
44
45#include "memdbg.h"
46
47#ifdef ENABLE_IPROUTE
48const char *iproute_path = IPROUTE_PATH; /* GLOBAL */
49#endif
50
51/*
52 * Set standard file descriptors to /dev/null
53 */
54void
55set_std_files_to_null(bool stdin_only)
56{
57#if defined(HAVE_DUP) && defined(HAVE_DUP2)
58 int fd;
59 if ((fd = open("/dev/null", O_RDWR, 0)) != -1)
60 {
61 dup2(fd, 0);
62 if (!stdin_only)
63 {
64 dup2(fd, 1);
65 dup2(fd, 2);
66 }
67 if (fd > 2)
68 {
69 close(fd);
70 }
71 }
72#endif
73}
74
75#if defined(__GNUC__) || defined(__clang__)
76#pragma GCC diagnostic push
77#pragma GCC diagnostic ignored "-Wconversion"
78#endif
79
80#ifdef ENABLE_MANAGEMENT
81/* Get username/password from the management interface */
82static bool
83auth_user_pass_mgmt(struct user_pass *up, const char *prefix, const unsigned int flags,
84 const char *auth_challenge)
85{
86 const char *sc = NULL;
87
89 {
90 management_auth_failure(management, prefix, "previous auth credentials failed");
91 }
92
94 {
95 sc = auth_challenge;
96 }
97 if (!management_query_user_pass(management, up, prefix, flags, sc))
98 {
99 if ((flags & GET_USER_PASS_NOFATAL) != 0)
100 {
101 return false;
102 }
103 else
104 {
105 msg(M_FATAL,
106 "ERROR: could not read %s username/password/ok/string from management interface",
107 prefix);
108 }
109 }
110 return true;
111}
112
126static struct auth_challenge_info *
128{
130
131 struct auth_challenge_info *ac;
132 const int len = strlen(auth_challenge);
133 char *work = (char *)gc_malloc(len + 1, false, gc);
134 char *cp;
135
136 struct buffer b;
138
140
141 /* parse prefix */
142 if (!buf_parse(&b, ':', work, len))
143 {
144 return NULL;
145 }
146 if (strcmp(work, "CRV1"))
147 {
148 return NULL;
149 }
150
151 /* parse flags */
152 if (!buf_parse(&b, ':', work, len))
153 {
154 return NULL;
155 }
156 for (cp = work; *cp != '\0'; ++cp)
157 {
158 const char c = *cp;
159 if (c == 'E')
160 {
161 ac->flags |= CR_ECHO;
162 }
163 else if (c == 'R')
164 {
165 ac->flags |= CR_RESPONSE;
166 }
167 }
168
169 /* parse state ID */
170 if (!buf_parse(&b, ':', work, len))
171 {
172 return NULL;
173 }
174 ac->state_id = string_alloc(work, gc);
175
176 /* parse user name */
177 if (!buf_parse(&b, ':', work, len))
178 {
179 return NULL;
180 }
181 ac->user = (char *)gc_malloc(strlen(work) + 1, true, gc);
182 openvpn_base64_decode(work, (void *)ac->user, -1);
183
184 /* parse challenge text */
185 ac->challenge_text = string_alloc(BSTR(&b), gc);
186
187 return ac;
188}
189
190#endif /* ifdef ENABLE_MANAGEMENT */
191
192#if defined(__GNUC__) || defined(__clang__)
193#pragma GCC diagnostic pop
194#endif
195
196/*
197 * Get and store a username/password
198 */
199
200bool
201get_user_pass_cr(struct user_pass *up, const char *auth_file, const char *prefix,
202 const unsigned int flags, const char *auth_challenge)
203{
204 struct gc_arena gc = gc_new();
205
206 if (!up->defined)
207 {
208 bool from_authfile = (auth_file && !streq(auth_file, "stdin"));
209 bool username_from_stdin = false;
210 bool password_from_stdin = false;
211 bool response_from_stdin = true;
212
215 {
216 msg(M_WARN, "Note: previous '%s' credentials failed", prefix);
217 }
218
219#ifdef ENABLE_MANAGEMENT
220 /*
221 * Get username/password from management interface?
222 */
223 if (management && (!from_authfile && (flags & GET_USER_PASS_MANAGEMENT))
225 {
226 response_from_stdin = false;
227 if (!auth_user_pass_mgmt(up, prefix, flags, auth_challenge))
228 {
229 return false;
230 }
231 }
232 else
233#endif /* ifdef ENABLE_MANAGEMENT */
234 /*
235 * Get NEED_OK confirmation from the console
236 */
237 if (flags & GET_USER_PASS_NEED_OK)
238 {
239 struct buffer user_prompt = alloc_buf_gc(128, &gc);
240
241 buf_printf(&user_prompt, "NEED-OK|%s|%s:", prefix, up->username);
243 USER_PASS_LEN, false))
244 {
245 msg(M_FATAL, "ERROR: could not read %s ok-confirmation from stdin", prefix);
246 }
247
248 if (!strlen(up->password))
249 {
250 strcpy(up->password, "ok");
251 }
252 }
253 else if (flags & GET_USER_PASS_INLINE_CREDS)
254 {
255 struct buffer buf;
256 buf_set_read(&buf, (uint8_t *)auth_file, strlen(auth_file) + 1);
257 if (!(flags & GET_USER_PASS_PASSWORD_ONLY))
258 {
259 buf_parse(&buf, '\n', up->username, USER_PASS_LEN);
260 }
261 buf_parse(&buf, '\n', up->password, USER_PASS_LEN);
262
263 if (strlen(up->password) == 0)
264 {
266 }
267 }
268 /*
269 * Read from auth file unless this is a dynamic challenge request.
270 */
271 else if (from_authfile && !(flags & GET_USER_PASS_DYNAMIC_CHALLENGE))
272 {
273 /*
274 * Try to get username/password from a file.
275 */
276 FILE *fp;
277 char password_buf[USER_PASS_LEN] = { '\0' };
278
279 fp = platform_fopen(auth_file, "r");
280 if (!fp)
281 {
282 msg(M_ERR, "Error opening '%s' auth file: %s", prefix, auth_file);
283 }
284
285 if ((flags & GET_USER_PASS_PASSWORD_ONLY) == 0)
286 {
287 /* Read username first */
288 if (fgets(up->username, USER_PASS_LEN, fp) == NULL)
289 {
290 msg(M_FATAL, "Error reading username from %s authfile: %s", prefix,
291 auth_file);
292 }
293 }
294 chomp(up->username);
295
297 {
299 }
300
301 if (flags & GET_USER_PASS_PASSWORD_ONLY && !password_buf[0])
302 {
303 msg(M_FATAL, "Error reading password from %s authfile: %s", prefix, auth_file);
304 }
305
306 if (password_buf[0])
307 {
309 }
310 /* The auth-file does not have the password: get both username
311 * and password from the management interface if possible.
312 * Otherwise set to read password from console.
313 */
314#if defined(ENABLE_MANAGEMENT)
315 else if (management && (flags & GET_USER_PASS_MANAGEMENT)
317 {
318 msg(D_LOW,
319 "No password found in %s authfile '%s'. Querying the management interface",
320 prefix, auth_file);
321 if (!auth_user_pass_mgmt(up, prefix, flags, auth_challenge))
322 {
323 fclose(fp);
324 return false;
325 }
326 }
327#endif
328 else
329 {
331 }
332
333 fclose(fp);
334
335 if (!(flags & GET_USER_PASS_PASSWORD_ONLY) && strlen(up->username) == 0)
336 {
337 msg(M_FATAL, "ERROR: username from %s authfile '%s' is empty", prefix,
338 auth_file);
339 }
340 }
341 else
342 {
343 username_from_stdin = true;
344 password_from_stdin = true;
345 }
346
347 /*
348 * Get username/password from standard input?
349 */
351 {
352#ifdef ENABLE_MANAGEMENT
354 {
356 if (ac)
357 {
358 char *response = (char *)gc_malloc(USER_PASS_LEN, false, &gc);
360
361 challenge = alloc_buf_gc(14 + strlen(ac->challenge_text), &gc);
362 buf_printf(&challenge, "CHALLENGE: %s", ac->challenge_text);
364
365 if (!query_user_SINGLE(BSTR(&challenge), BLEN(&challenge), response,
366 USER_PASS_LEN, BOOL_CAST(ac->flags & CR_ECHO)))
367 {
368 msg(M_FATAL, "ERROR: could not read challenge response from stdin");
369 }
370 strncpynt(up->username, ac->user, USER_PASS_LEN);
371 buf_printf(&packed_resp, "CRV1::%s::%s", ac->state_id, response);
372 }
373 else
374 {
375 msg(M_FATAL, "ERROR: received malformed challenge request from server");
376 }
377 }
378 else
379#endif /* ifdef ENABLE_MANAGEMENT */
380 {
381 struct buffer user_prompt = alloc_buf_gc(128, &gc);
382 struct buffer pass_prompt = alloc_buf_gc(128, &gc);
383
385 buf_printf(&user_prompt, "Enter %s Username:", prefix);
386 buf_printf(&pass_prompt, "Enter %s Password:", prefix);
387
389 {
391 USER_PASS_LEN, true);
392 }
393
395 {
397 USER_PASS_LEN, false);
398 }
399
400 if (!query_user_exec())
401 {
402 msg(M_FATAL, "ERROR: Failed retrieving username or password");
403 }
404
405 if (!(flags & GET_USER_PASS_PASSWORD_ONLY))
406 {
407 if (strlen(up->username) == 0)
408 {
409 msg(M_FATAL, "ERROR: %s username is empty", prefix);
410 }
411 }
412
413#ifdef ENABLE_MANAGEMENT
416 {
417 char *response = (char *)gc_malloc(USER_PASS_LEN, false, &gc);
419 char *pw64 = NULL, *resp64 = NULL;
420
422 buf_printf(&challenge, "CHALLENGE: %s", auth_challenge);
423
424 if (!query_user_SINGLE(BSTR(&challenge), BLEN(&challenge), response,
427 {
428 msg(M_FATAL, "ERROR: could not retrieve static challenge response");
429 }
431 {
432 if (openvpn_base64_encode(up->password, (int)strlen(up->password), &pw64) == -1
433 || openvpn_base64_encode(response, (int)strlen(response), &resp64) == -1)
434 {
435 msg(M_FATAL, "ERROR: could not base64-encode password/static_response");
436 }
438 buf_printf(&packed_resp, "SCRV1:%s:%s", pw64, resp64);
440 free(pw64);
442 free(resp64);
443 }
444 else
445 {
446 if (strlen(up->password) + strlen(response) >= USER_PASS_LEN)
447 {
448 msg(M_FATAL,
449 "ERROR: could not concatenate password/static_response: string too long");
450 }
451 strncat(up->password, response, USER_PASS_LEN - strlen(up->password) - 1);
452 }
453 }
454#endif /* ifdef ENABLE_MANAGEMENT */
455 }
456 }
457
460
461 up->defined = true;
462 }
463
464#if 0
465 msg(M_INFO, "GET_USER_PASS %s u='%s' p='%s'", prefix, up->username, up->password);
466#endif
467
468 gc_free(&gc);
469
470 return true;
471}
472
473void
474purge_user_pass(struct user_pass *up, const bool force)
475{
476 const bool nocache = up->nocache;
477 static bool warn_shown = false;
478 if (nocache || force)
479 {
480 secure_memzero(up, sizeof(*up));
481 up->nocache = nocache;
482 }
483 else
484 {
486 /*
487 * don't show warning if the pass has been replaced by a token: this is an
488 * artificial "auth-nocache"
489 */
490 if (!warn_shown)
491 {
492 msg(M_WARN,
493 "WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this");
494 warn_shown = true;
495 }
496 }
497}
498
499void
500set_auth_token(struct user_pass *tk, const char *token)
501{
502 if (strlen(token))
503 {
505 strncpynt(tk->password, token, USER_PASS_LEN);
506 tk->token_defined = true;
507
508 /*
509 * If username already set, tk is fully defined.
510 */
511 if (strlen(tk->username))
512 {
513 tk->defined = true;
514 }
516 }
517}
518
519void
520set_auth_token_user(struct user_pass *tk, const char *username)
521{
522 if (strlen(username))
523 {
525 /* Clear the username before decoding to ensure no old material is left
526 * and also allow decoding to not use all space to ensure the last byte is
527 * always 0 */
528 CLEAR(tk->username);
529 int len = openvpn_base64_decode(username, tk->username, USER_PASS_LEN - 1);
530 tk->defined = len > 0;
531 if (!tk->defined)
532 {
533 msg(D_PUSH, "Error decoding auth-token-username");
534 }
536 }
537}
538
539
540/*
541 * Process string received by untrusted peer before
542 * printing to console or log file.
543 *
544 * Assumes that string has been null terminated.
545 */
546const char *
547safe_print(const char *str, struct gc_arena *gc)
548{
549 return string_mod_const(str, CC_PRINT, CC_CRLF, '.', gc);
550}
551
552const char **
553make_arg_array(const char *first, const char *parms, struct gc_arena *gc)
554{
555 char **ret = NULL;
556 int base = 0;
557 const int max_parms = MAX_PARMS + 2;
558 int n = 0;
559
560 /* alloc return array */
561 ALLOC_ARRAY_CLEAR_GC(ret, char *, max_parms, gc);
562
563 /* process first parameter, if provided */
564 if (first)
565 {
566 ret[base++] = string_alloc(first, gc);
567 }
568
569 if (parms)
570 {
571 n = parse_line(parms, &ret[base], max_parms - base - 1, "make_arg_array", 0, M_WARN, gc);
572 ASSERT(n >= 0 && n + base + 1 <= max_parms);
573 }
574 ret[base + n] = NULL;
575
576 return (const char **)ret;
577}
578
579static const char **
580make_inline_array(const char *str, struct gc_arena *gc)
581{
583 struct buffer buf;
584 int len = 0;
585 char **ret = NULL;
586 int i = 0;
587
588 buf_set_read(&buf, (const uint8_t *)str, strlen(str));
589 while (buf_parse(&buf, '\n', line, sizeof(line)))
590 {
591 ++len;
592 }
593
594 /* alloc return array */
595 ALLOC_ARRAY_CLEAR_GC(ret, char *, len + 1, gc);
596
597 buf_set_read(&buf, (const uint8_t *)str, strlen(str));
598 while (buf_parse(&buf, '\n', line, sizeof(line)))
599 {
600 chomp(line);
601 ASSERT(i < len);
603 ++i;
604 }
605 ASSERT(i <= len);
606 ret[i] = NULL;
607 return (const char **)ret;
608}
609
610static const char **
611make_arg_copy(char **p, struct gc_arena *gc)
612{
613 char **ret = NULL;
614 const int len = string_array_len((const char **)p);
615 const int max_parms = len + 1;
616 int i;
617
618 /* alloc return array */
619 ALLOC_ARRAY_CLEAR_GC(ret, char *, max_parms, gc);
620
621 for (i = 0; i < len; ++i)
622 {
623 ret[i] = p[i];
624 }
625
626 return (const char **)ret;
627}
628
629const char **
631{
632 const int argc = string_array_len((const char **)p);
633 if (is_inline)
634 {
635 return make_inline_array(p[0], gc);
636 }
637 else if (argc == 0)
638 {
639 return make_arg_array(NULL, NULL, gc);
640 }
641 else if (argc == 1)
642 {
643 return make_arg_array(p[0], NULL, gc);
644 }
645 else if (argc == 2)
646 {
647 return make_arg_array(p[0], p[1], gc);
648 }
649 else
650 {
651 return make_arg_copy(p, gc);
652 }
653}
654
655/*
656 * Remove security-sensitive strings from control message
657 * so that they will not be output to log file.
658 */
659const char *
661{
662 char *ret = gc_malloc(strlen(src) + 1, false, gc);
663 char *dest = ret;
664 bool redact = false;
665 int skip = 0;
666
667 for (;;)
668 {
669 const char c = *src;
670 if (c == '\0')
671 {
672 break;
673 }
674 if (c == 'S' && !strncmp(src, "SESS_ID_", 8))
675 {
676 skip = 7;
677 redact = true;
678 }
679 else if (c == 'e' && !strncmp(src, "echo ", 5))
680 {
681 skip = 4;
682 redact = true;
683 }
684 else if (!check_debug_level(D_SHOW_KEYS) && (c == 'a' && !strncmp(src, "auth-token ", 11)))
685 {
686 /* Unless --verb is 7 or higher (D_SHOW_KEYS), hide
687 * the auth-token value coming in the src string
688 */
689 skip = 10;
690 redact = true;
691 }
692
693 if (c == ',') /* end of redacted item? */
694 {
695 skip = 0;
696 redact = false;
697 }
698
699 if (redact)
700 {
701 if (skip > 0)
702 {
703 --skip;
704 *dest++ = c;
705 }
706 }
707 else
708 {
709 *dest++ = c;
710 }
711
712 ++src;
713 }
714 *dest = '\0';
715 return ret;
716}
717
718/* helper to parse peer_info received from multi client, validate
719 * (this is untrusted data) and put into environment
720 */
721bool
723{
724 uint8_t c;
725 int state = 0;
726 while (*line)
727 {
728 c = *line;
729 switch (state)
730 {
731 case 0:
732 case 1:
733 if (c == '=' && state == 1)
734 {
735 state = 2;
736 }
737 else if (isalnum(c) || c == '_')
738 {
739 state = 1;
740 }
741 else
742 {
743 return false;
744 }
745 /* Intentional [[fallthrough]]; */
746 case 2:
747 /* after the '=', replace non-printable or shell meta with '_' */
748 if (!isprint(c) || isspace(c) || c == '$' || c == '(' || c == '`')
749 {
750 *line = '_';
751 }
752 }
753 line++;
754 }
755 return (state == 2);
756}
757
758void
759output_peer_info_env(struct env_set *es, const char *peer_info)
760{
761 char line[256];
762 struct buffer buf;
763 buf_set_read(&buf, (const uint8_t *)peer_info, strlen(peer_info));
764 while (buf_parse(&buf, '\n', line, sizeof(line)))
765 {
766 chomp(line);
768 && (strncmp(line, "IV_", 3) == 0 || strncmp(line, "UV_", 3) == 0))
769 {
770 msg(M_INFO, "peer info: %s", line);
772 }
773 else
774 {
775 msg(M_WARN, "validation failed on peer_info line received from client");
776 }
777 }
778}
779
780struct buffer
781prepend_dir(const char *dir, const char *path, struct gc_arena *gc)
782{
783 size_t len = strlen(dir) + strlen(PATH_SEPARATOR_STR) + strlen(path) + 1;
786 ASSERT(combined_path.len > 0);
787
788 return combined_path;
789}
790
791void
793{
794 if (up->protected)
795 {
796 return;
797 }
798#ifdef _WIN32
799 if (protect_buffer_win32(up->username, sizeof(up->username))
800 && protect_buffer_win32(up->password, sizeof(up->password)))
801 {
802 up->protected = true;
803 }
804 else
805 {
806 purge_user_pass(up, true);
807 }
808#endif
809}
810
811void
813{
814 if (!up->protected)
815 {
816 return;
817 }
818#ifdef _WIN32
819 if (unprotect_buffer_win32(up->username, sizeof(up->username))
820 && unprotect_buffer_win32(up->password, sizeof(up->password)))
821 {
822 up->protected = false;
823 }
824 else
825 {
826 purge_user_pass(up, true);
827 }
828#endif
829}
const char * skip_leading_whitespace(const char *str)
Definition buffer.c:579
bool buf_printf(struct buffer *buf, const char *format,...)
Definition buffer.c:241
void string_clear(char *str)
Definition buffer.c:691
void chomp(char *str)
Definition buffer.c:614
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
Definition buffer.c:336
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Definition buffer.c:89
bool string_mod(char *str, const unsigned int inclusive, const unsigned int exclusive, const char replace)
Modifies a string in place by replacing certain classes of characters of it with a specified characte...
Definition buffer.c:1041
const char * string_mod_const(const char *str, const unsigned int inclusive, const unsigned int exclusive, const char replace, struct gc_arena *gc)
Returns a copy of a string with certain classes of characters of it replaced with a specified charact...
Definition buffer.c:1091
int string_array_len(const char **array)
Definition buffer.c:703
bool buf_parse(struct buffer *buf, const int delim, char *line, const int size)
Definition buffer.c:825
char * string_alloc(const char *str, struct gc_arena *gc)
Definition buffer.c:649
#define BSTR(buf)
Definition buffer.h:128
#define ALLOC_ARRAY_CLEAR_GC(dptr, type, n, gc)
Definition buffer.h:1064
#define CC_CRLF
carriage return or newline
Definition buffer.h:904
static void buf_set_write(struct buffer *buf, uint8_t *data, int size)
Definition buffer.h:331
static void buf_set_read(struct buffer *buf, const uint8_t *data, size_t size)
Definition buffer.h:348
static void secure_memzero(void *data, size_t len)
Securely zeroise memory.
Definition buffer.h:414
#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc)
Definition buffer.h:1079
#define BLEN(buf)
Definition buffer.h:126
static void strncpynt(char *dest, const char *src, size_t maxlen)
Definition buffer.h:361
static void gc_free(struct gc_arena *a)
Definition buffer.h:1015
#define CC_PRINT
printable (>= 32, != 127)
Definition buffer.h:875
static struct gc_arena gc_new(void)
Definition buffer.h:1007
#define IPROUTE_PATH
Definition config.h:468
void query_user_clear(void)
Wipes all data put into all of the query_user structs.
Definition console.c:44
void query_user_add(char *prompt, size_t prompt_len, char *resp, size_t resp_len, bool echo)
Adds an item to ask the user for.
Definition console.c:56
static bool query_user_exec(void)
Wrapper function enabling query_user_exec() if no alternative methods have been enabled.
Definition console.h:105
static bool query_user_SINGLE(char *prompt, size_t prompt_len, char *resp, size_t resp_len, bool echo)
A plain "make Gert happy" wrapper.
Definition console.h:120
Data Channel Cryptography Module.
void env_set_add(struct env_set *es, const char *str)
Definition env_set.c:193
#define D_PUSH
Definition errlevel.h:82
#define D_SHOW_KEYS
Definition errlevel.h:120
#define D_LOW
Definition errlevel.h:96
#define M_INFO
Definition errlevel.h:54
void management_auth_failure(struct management *man, const char *type, const char *reason)
Definition manage.c:3124
bool management_query_user_pass(struct management *man, struct user_pass *up, const char *type, const unsigned int flags, const char *static_challenge)
Definition manage.c:3523
static bool management_query_user_pass_enabled(const struct management *man)
Definition manage.h:419
static const char ** make_inline_array(const char *str, struct gc_arena *gc)
Definition misc.c:580
void unprotect_user_pass(struct user_pass *up)
Decrypt username and password buffers in user_pass.
Definition misc.c:812
bool get_user_pass_cr(struct user_pass *up, const char *auth_file, const char *prefix, const unsigned int flags, const char *auth_challenge)
Retrieves the user credentials from various sources depending on the flags.
Definition misc.c:201
const char ** make_arg_array(const char *first, const char *parms, struct gc_arena *gc)
Definition misc.c:553
void purge_user_pass(struct user_pass *up, const bool force)
Definition misc.c:474
bool validate_peer_info_line(char *line)
Definition misc.c:722
void set_auth_token_user(struct user_pass *tk, const char *username)
Sets the auth-token username by base64 decoding the passed username.
Definition misc.c:520
void set_std_files_to_null(bool stdin_only)
Definition misc.c:55
void output_peer_info_env(struct env_set *es, const char *peer_info)
Definition misc.c:759
struct buffer prepend_dir(const char *dir, const char *path, struct gc_arena *gc)
Prepend a directory to a path.
Definition misc.c:781
static struct auth_challenge_info * parse_auth_challenge(const char *auth_challenge, struct gc_arena *gc)
Parses an authentication challenge string and returns an auth_challenge_info structure.
Definition misc.c:127
void protect_user_pass(struct user_pass *up)
Encrypt username and password buffers in user_pass.
Definition misc.c:792
const char ** make_extended_arg_array(char **p, bool is_inline, struct gc_arena *gc)
Definition misc.c:630
static const char ** make_arg_copy(char **p, struct gc_arena *gc)
Definition misc.c:611
const char * safe_print(const char *str, struct gc_arena *gc)
Definition misc.c:547
const char * sanitize_control_message(const char *src, struct gc_arena *gc)
Definition misc.c:660
static bool auth_user_pass_mgmt(struct user_pass *up, const char *prefix, const unsigned int flags, const char *auth_challenge)
Definition misc.c:83
void set_auth_token(struct user_pass *tk, const char *token)
Sets the auth-token to token.
Definition misc.c:500
#define USER_PASS_LEN
Definition misc.h:64
#define GET_USER_PASS_STATIC_CHALLENGE_CONCAT
indicates password and response should be concatenated
Definition misc.h:125
#define GET_USER_PASS_MANAGEMENT
Definition misc.h:110
#define GET_USER_PASS_PASSWORD_ONLY
Definition misc.h:112
#define GET_USER_PASS_STATIC_CHALLENGE_ECHO
SCRV1 protocol – echo response.
Definition misc.h:120
#define CR_ECHO
Definition misc.h:77
#define CR_RESPONSE
Definition misc.h:78
#define GET_USER_PASS_INLINE_CREDS
indicates that auth_file is actually inline creds
Definition misc.h:123
#define GET_USER_PASS_STATIC_CHALLENGE
SCRV1 protocol – static challenge.
Definition misc.h:119
#define GET_USER_PASS_NEED_OK
Definition misc.h:113
#define GET_USER_PASS_NOFATAL
Definition misc.h:114
#define GET_USER_PASS_PREVIOUS_CREDS_FAILED
Definition misc.h:116
#define GET_USER_PASS_DYNAMIC_CHALLENGE
CRV1 protocol – dynamic challenge.
Definition misc.h:118
#define BOOL_CAST(x)
Definition basic.h:26
#define CLEAR(x)
Definition basic.h:32
static bool check_debug_level(msglvl_t level)
Definition error.h:259
#define M_FATAL
Definition error.h:90
#define M_ERR
Definition error.h:106
#define msg(flags,...)
Definition error.h:152
#define ASSERT(x)
Definition error.h:219
#define M_WARN
Definition error.h:92
int parse_line(const char *line, char *p[], const int n, const char *file, const int line_num, msglvl_t msglevel, struct gc_arena *gc)
Definition options.c:4977
#define streq(x, y)
Definition options.h:727
#define MAX_PARMS
Definition options.h:51
#define OPTION_LINE_SIZE
Definition options.h:57
FILE * platform_fopen(const char *path, const char *mode)
Definition platform.c:504
int openvpn_base64_decode(const char *str, void *data, int size)
Definition base64.c:160
int openvpn_base64_encode(const void *data, int size, char **str)
Definition base64.c:51
static char * auth_challenge
Definition ssl.c:293
Wrapper structure for dynamically allocated memory.
Definition buffer.h:60
int len
Length in bytes of the actual content within the allocated memory.
Definition buffer.h:65
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:116
bool protected
Definition misc.h:58
bool defined
Definition misc.h:53
char password[USER_PASS_LEN]
Definition misc.h:68
bool nocache
Definition misc.h:57
char username[USER_PASS_LEN]
Definition misc.h:67
#define PATH_SEPARATOR_STR
Definition syshead.h:428
struct env_set * es
struct gc_arena gc
Definition test_ssl.c:131
bool unprotect_buffer_win32(char *buf, size_t len)
Decrypt a previously encrypted region of memory using CryptUnProtectMemory() with access restricted t...
Definition win32.c:1623
bool protect_buffer_win32(char *buf, size_t len)
Encrypt a region of memory using CryptProtectMemory() with access restricted to the current process.
Definition win32.c:1605