OpenVPN
error.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-2026 OpenVPN 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 along
20 * with this program; if not, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include "syshead.h"
28
29#include "error.h"
30#include "buffer.h"
31#include "init.h"
32#include "misc.h"
33#include "win32.h"
34#include "socket.h"
35#include "tun.h"
36#include "otime.h"
37#include "status.h"
38#include "integer.h"
39#include "ps.h"
40
41#if SYSLOG_CAPABILITY
42#ifndef LOG_OPENVPN
43#define LOG_OPENVPN LOG_DAEMON
44#endif
45#endif
46
47/* Globals */
49
50/* Mute state */
51static int mute_cutoff; /* GLOBAL */
52static int mute_count; /* GLOBAL */
53static msglvl_t mute_category; /* GLOBAL */
54
55/*
56 * Output mode priorities are as follows:
57 *
58 * (1) --log-x overrides everything
59 * (2) syslog is used if --daemon is defined and not --log-x
60 * (3) if OPENVPN_DEBUG_COMMAND_LINE is defined, output
61 * to constant logfile name.
62 * (4) Output to stdout.
63 */
64
65/* If true, indicates that stdin/stdout/stderr
66 * have been redirected due to --log */
67static bool std_redir; /* GLOBAL */
68
69/* Should messages be written to the syslog? */
70static bool use_syslog; /* GLOBAL */
71
72/* Should stdout/stderr be be parsable and always be prefixed with time
73 * and message flags */
74static bool machine_readable_output; /* GLOBAL */
75
76/* Should timestamps be included on messages to stdout/stderr? */
77static bool suppress_timestamps; /* GLOBAL */
78
79/* The program name passed to syslog */
80#if SYSLOG_CAPABILITY
81static char *pgmname_syslog; /* GLOBAL */
82#endif
83
84/* If non-null, messages should be written here (used for debugging only) */
85static FILE *msgfp; /* GLOBAL */
86
87/* our default output targets */
88static FILE *default_out; /* GLOBAL */
89static FILE *default_err; /* GLOBAL */
90
91/* If true, we forked from main OpenVPN process */
92static bool forked; /* GLOBAL */
93
94#if PORT_SHARE
95void
96msg_forked(void)
97{
98 forked = true;
99}
100#endif
101
102bool
103set_debug_level(const int level, const unsigned int flags)
104{
105 if (level >= 0 && (unsigned int)level <= M_DEBUG_LEVEL)
106 {
107 x_debug_level = (msglvl_t)level;
108 return true;
109 }
110 else if (flags & SDL_CONSTRAIN)
111 {
113 return true;
114 }
115 return false;
116}
117
118bool
119set_mute_cutoff(const int cutoff)
120{
121 if (cutoff >= 0)
122 {
123 mute_cutoff = cutoff;
124 return true;
125 }
126 else
127 {
128 return false;
129 }
130}
131
134{
135 return x_debug_level;
136}
137
138int
140{
141 return mute_cutoff;
142}
143
144void
146{
147 suppress_timestamps = suppressed;
148}
149
150void
152{
153 machine_readable_output = parsable;
154}
155
156void
158{
159 use_syslog = std_redir = false;
160 suppress_timestamps = false;
162 x_debug_level = 1;
163 mute_cutoff = 0;
164 mute_count = 0;
165 mute_category = 0;
168
169#ifdef OPENVPN_DEBUG_COMMAND_LINE
170 msgfp = fopen(OPENVPN_DEBUG_FILE, "w");
171 if (!msgfp)
172 {
174 }
175#else
176 msgfp = NULL;
177#endif
178}
179
180void
185
186/*
187 * Return a file to print messages to before syslog is opened.
188 */
189FILE *
190msg_fp(const msglvl_t flags)
191{
192 FILE *fp = msgfp;
193 if (!fp)
194 {
195 fp = (flags & (M_FATAL | M_USAGE_SMALL)) ? default_err : default_out;
196 }
197 if (!fp)
198 {
200 }
201 return fp;
202}
203
204#define SWAP \
205 { \
206 tmp = m1; \
207 m1 = m2; \
208 m2 = tmp; \
209 }
210
211int x_msg_line_num; /* GLOBAL */
212
213void
214x_msg(const msglvl_t flags, const char *format, ...)
215{
216 va_list arglist;
217 va_start(arglist, format);
218 x_msg_va(flags, format, arglist);
219 va_end(arglist);
220}
221
222#if defined(_WIN32) && (defined(__GNUC__) || defined(__clang__))
223#pragma GCC diagnostic push
224#pragma GCC diagnostic ignored "-Wsign-conversion"
225#endif
226
227static const char *
228openvpn_strerror(int err, bool crt_error, struct gc_arena *gc)
229{
230#ifdef _WIN32
231 if (!crt_error)
232 {
233 return strerror_win32(err, gc);
234 }
235#endif
236 return strerror(err);
237}
238
239void
240x_msg_va(const msglvl_t flags, const char *format, va_list arglist)
241{
242 struct gc_arena gc;
243#if SYSLOG_CAPABILITY
244 int level;
245#endif
246 char *m1;
247 char *m2;
248 char *tmp;
249 int e;
250 const char *prefix;
251 const char *prefix_sep;
252
253 void usage_small(void);
254
255 /* the macro has checked this otherwise */
256 if (!msg_test(flags))
257 {
258 return;
259 }
260
261 bool crt_error = false;
262 e = openvpn_errno_maybe_crt(&crt_error);
263
264 /*
265 * Apply muting filter.
266 */
267 /* the macro has checked this otherwise */
268 if (!dont_mute(flags))
269 {
270 return;
271 }
272
273 gc_init(&gc);
274
275 m1 = (char *)gc_malloc(ERR_BUF_SIZE, false, &gc);
276 m2 = (char *)gc_malloc(ERR_BUF_SIZE, false, &gc);
277
278 vsnprintf(m1, ERR_BUF_SIZE, format, arglist);
279 m1[ERR_BUF_SIZE - 1] = 0; /* windows vsnprintf needs this */
280
281 if ((flags & M_ERRNO) && e)
282 {
283 snprintf(m2, ERR_BUF_SIZE, "%s: %s (errno=%d)", m1, openvpn_strerror(e, crt_error, &gc), e);
284 SWAP;
285 }
286
287 if (flags & M_OPTERR)
288 {
289 snprintf(m2, ERR_BUF_SIZE, "Options error: %s", m1);
290 SWAP;
291 }
292
293#if SYSLOG_CAPABILITY
294 if (flags & (M_FATAL | M_NONFATAL | M_USAGE_SMALL))
295 {
296 level = LOG_ERR;
297 }
298 else if (flags & M_WARN)
299 {
300 level = LOG_WARNING;
301 }
302 else
303 {
304 level = LOG_NOTICE;
305 }
306#endif
307
308 /* set up client prefix */
309 if (flags & M_NOIPREFIX)
310 {
311 prefix = NULL;
312 }
313 else
314 {
315 prefix = msg_get_prefix();
316 }
317 prefix_sep = " ";
318 if (!prefix)
319 {
320 prefix_sep = prefix = "";
321 }
322
323 /* virtual output capability used to copy output to management subsystem */
324 if (!forked)
325 {
326 const struct virtual_output *vo = msg_get_virtual_output();
327 if (vo)
328 {
329 snprintf(m2, ERR_BUF_SIZE, "%s%s%s", prefix, prefix_sep, m1);
330 virtual_output_print(vo, flags, m2);
331 }
332 }
333
334 if (!(flags & M_MSG_VIRT_OUT))
335 {
336 if (use_syslog && !std_redir && !forked)
337 {
338#if SYSLOG_CAPABILITY
339 syslog(level, "%s%s%s", prefix, prefix_sep, m1);
340#endif
341 }
342 else
343 {
344 FILE *fp = msg_fp(flags);
345 const bool show_usec = check_debug_level(DEBUG_LEVEL_USEC_TIME);
346
348 {
349 struct timeval tv;
350 gettimeofday(&tv, NULL);
351
352 fprintf(fp, "%" PRIi64 ".%06ld %x %s%s%s%s", (int64_t)tv.tv_sec, (long)tv.tv_usec,
353 flags, prefix, prefix_sep, m1, "\n");
354 }
355 else if ((flags & M_NOPREFIX) || suppress_timestamps)
356 {
357 fprintf(fp, "%s%s%s%s", prefix, prefix_sep, m1, (flags & M_NOLF) ? "" : "\n");
358 }
359 else
360 {
361 fprintf(fp, "%s %s%s%s%s", time_string(0, 0, show_usec, &gc), prefix, prefix_sep,
362 m1, (flags & M_NOLF) ? "" : "\n");
363 }
364 fflush(fp);
366 }
367 }
368
369 if (flags & M_FATAL)
370 {
371 msg(M_INFO, "Exiting due to fatal error");
372 }
373
374 if (flags & M_FATAL)
375 {
376 openvpn_exit(OPENVPN_EXIT_STATUS_ERROR); /* exit point */
377 }
378 if (flags & M_USAGE_SMALL)
379 {
380 usage_small();
381 }
382
383 gc_free(&gc);
384}
385
386/*
387 * Apply muting filter.
388 */
389bool
391{
392 bool ret = true;
393 if (mute_cutoff > 0 && !(flags & M_NOMUTE))
394 {
395 const msglvl_t mute_level = DECODE_MUTE_LEVEL(flags);
396 if (mute_level == mute_category)
397 {
398 if (mute_count == mute_cutoff)
399 {
400 msg(M_INFO | M_NOMUTE, "NOTE: --mute triggered...");
401 }
402 if (++mute_count > mute_cutoff)
403 {
404 ret = false;
405 }
406 }
407 else
408 {
409 const int suppressed = mute_count - mute_cutoff;
410 if (suppressed > 0)
411 {
413 "%d variation(s) on previous %d message(s) suppressed by --mute", suppressed,
415 }
416 mute_count = 1;
417 mute_category = mute_level;
418 }
419 }
420 return ret;
421}
422
423void
424assert_failed(const char *filename, int line, const char *condition)
425{
426 if (condition)
427 {
428 msg(M_FATAL, "Assertion failed at %s:%d (%s)", filename, line, condition);
429 }
430 else
431 {
432 msg(M_FATAL, "Assertion failed at %s:%d", filename, line);
433 }
434 _exit(1);
435}
436
437/*
438 * Fail memory allocation. Don't use msg() because it tries
439 * to allocate memory as part of its operation.
440 */
441void
443{
444 fprintf(stderr, PACKAGE_NAME ": Out of Memory\n");
445 exit(1);
446}
447
448void
449open_syslog(const char *pgmname, bool stdio_to_null)
450{
451#if SYSLOG_CAPABILITY
452 if (!msgfp && !std_redir)
453 {
454 if (!use_syslog)
455 {
456 pgmname_syslog = string_alloc(pgmname ? pgmname : PACKAGE, NULL);
457 openlog(pgmname_syslog, LOG_PID, LOG_OPENVPN);
458 use_syslog = true;
459
460 /* Better idea: somehow pipe stdout/stderr output to msg() */
461 if (stdio_to_null)
462 {
464 }
465 }
466 }
467#else /* if SYSLOG_CAPABILITY */
468 msg(M_WARN,
469 "Warning on use of --daemon: this operating system lacks daemon logging features, therefore when I become a daemon, I won't be able to log status or error messages");
470#endif
471}
472
473void
475{
476#if SYSLOG_CAPABILITY
477 if (use_syslog)
478 {
479 closelog();
480 use_syslog = false;
481 free(pgmname_syslog);
482 pgmname_syslog = NULL;
483 }
484#endif
485}
486
487#ifdef _WIN32
488static int orig_stderr;
489
490int
492{
493 return orig_stderr ? orig_stderr : _fileno(stderr);
494}
495#endif
496
497void
498redirect_stdout_stderr(const char *file, bool append)
499{
500#if defined(_WIN32)
501 if (!std_redir)
502 {
503 struct gc_arena gc = gc_new();
504 HANDLE log_handle;
505 int log_fd;
506
507 SECURITY_ATTRIBUTES saAttr;
508 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
509 saAttr.bInheritHandle = TRUE;
510 saAttr.lpSecurityDescriptor = NULL;
511
512 log_handle = CreateFileW(wide_string(file, &gc), GENERIC_WRITE, FILE_SHARE_READ, &saAttr,
513 append ? OPEN_ALWAYS : CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
514
515 gc_free(&gc);
516
517 if (log_handle == INVALID_HANDLE_VALUE)
518 {
519 msg(M_WARN | M_ERRNO, "Warning: cannot open --log file: %s", file);
520 return;
521 }
522
523 /* append to logfile? */
524 if (append)
525 {
526 if (SetFilePointer(log_handle, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
527 {
528 msg(M_ERR, "Error: cannot seek to end of --log file: %s", file);
529 }
530 }
531
532 /* save original stderr for password prompts */
533 orig_stderr = _dup(_fileno(stderr));
534 if (orig_stderr == -1)
535 {
537 "Warning: cannot duplicate stderr, password prompts will appear in log file instead of console.");
538 orig_stderr = _fileno(stderr);
539 }
540
541 /* direct stdout/stderr to point to log_handle */
542 log_fd = _open_osfhandle((intptr_t)log_handle, _O_TEXT);
543 if (log_fd == -1)
544 {
545 msg(M_ERR, "Error: --log redirect failed due to _open_osfhandle failure");
546 }
547
548 /* open log_handle as FILE stream */
549 ASSERT(msgfp == NULL);
550 msgfp = _fdopen(log_fd, "wt");
551 if (msgfp == NULL)
552 {
553 msg(M_ERR, "Error: --log redirect failed due to _fdopen");
554 }
555
556 /* redirect C-library stdout/stderr to log file */
557 if (_dup2(log_fd, 1) == -1 || _dup2(log_fd, 2) == -1)
558 {
559 msg(M_WARN, "Error: --log redirect of stdout/stderr failed");
560 }
561
562 std_redir = true;
563 }
564#elif defined(HAVE_DUP2)
565 if (!std_redir)
566 {
567 int out = open(file, O_CREAT | O_WRONLY | (append ? O_APPEND : O_TRUNC), S_IRUSR | S_IWUSR);
568
569 if (out < 0)
570 {
571 msg(M_WARN | M_ERRNO, "Warning: Error redirecting stdout/stderr to --log file: %s",
572 file);
573 return;
574 }
575
576 if (dup2(out, 1) == -1)
577 {
578 msg(M_ERR, "--log file redirection error on stdout");
579 }
580 if (dup2(out, 2) == -1)
581 {
582 msg(M_ERR, "--log file redirection error on stderr");
583 }
584
585 if (out > 2)
586 {
587 close(out);
588 }
589
590 std_redir = true;
591 }
592
593#else /* if defined(_WIN32) */
594 msg(M_WARN,
595 "WARNING: The --log option is not supported on this OS because it lacks the dup2 function");
596#endif /* if defined(_WIN32) */
597}
598
599/*
600 * Functions used to check return status
601 * of I/O operations.
602 */
603
604unsigned int x_cs_info_level; /* GLOBAL */
605unsigned int x_cs_verbose_level; /* GLOBAL */
606unsigned int x_cs_err_delay_ms; /* GLOBAL */
607
608void
610{
611 x_cs_info_level = 0;
613}
614
615void
616set_check_status(unsigned int info_level, unsigned int verbose_level)
617{
618 x_cs_info_level = info_level;
619 x_cs_verbose_level = verbose_level;
620}
621
622/*
623 * Called after most socket or tun/tap operations, via the inline
624 * function check_status().
625 *
626 * Decide if we should print an error message, and see if we can
627 * extract any useful info from the error, such as a Path MTU hint
628 * from the OS.
629 */
630void
631x_check_status(ssize_t status, const char *description, struct link_socket *sock, const struct tuntap *tt)
632{
633 const char *extended_msg = NULL;
634
635 bool crt_error = false;
636 int my_errno = openvpn_errno_maybe_crt(&crt_error);
637
638 msg(x_cs_verbose_level, "%s %s returned %zd",
639 sock ? proto2ascii(sock->info.proto, sock->info.af, true) : "", description, status);
640
641 if (status < 0)
642 {
643 struct gc_arena gc = gc_new();
644#if EXTENDED_SOCKET_ERROR_CAPABILITY
645 /* get extended socket error message and possible PMTU hint from OS */
646 if (sock)
647 {
648 int mtu;
649 extended_msg = format_extended_socket_error(sock->sd, &mtu, &gc);
650 if (mtu > 0 && sock->mtu != mtu)
651 {
652 sock->mtu = mtu;
653 sock->info.mtu_changed = true;
654 }
655 }
656#endif /* EXTENDED_SOCKET_ERROR_CAPABILITY */
657
658#ifdef _WIN32
659 /* get possible driver error from TAP-Windows driver */
660 if (tuntap_defined(tt))
661 {
662 extended_msg = tap_win_getinfo(tt, &gc);
663 }
664#endif
665
666 if (!ignore_sys_error(my_errno, crt_error))
667 {
668 if (extended_msg)
669 {
670 msg(x_cs_info_level, "%s %s [%s]: %s (fd=" SOCKET_PRINTF ",code=%d)",
671 description,
672 sock ? proto2ascii(sock->info.proto, sock->info.af, true) : "",
673 extended_msg,
674 openvpn_strerror(my_errno, crt_error, &gc),
675 sock ? sock->sd : SOCKET_UNDEFINED,
676 my_errno);
677 }
678 else
679 {
680 msg(x_cs_info_level, "%s %s: %s (fd=" SOCKET_PRINTF ",code=%d)",
681 description,
682 sock ? proto2ascii(sock->info.proto, sock->info.af, true) : "",
683 openvpn_strerror(my_errno, crt_error, &gc),
684 sock ? sock->sd : SOCKET_UNDEFINED,
685 my_errno);
686 }
687
689 {
691 }
692 }
693 gc_free(&gc);
694 }
695}
696
697#if defined(_WIN32) && (defined(__GNUC__) || defined(__clang__))
698#pragma GCC diagnostic pop
699#endif
700
701/*
702 * In multiclient mode, put a client-specific prefix
703 * before each message.
704 */
705const char *x_msg_prefix; /* GLOBAL */
706
707/*
708 * Allow MSG to be redirected through a virtual_output object
709 */
710
711const struct virtual_output *x_msg_virtual_output; /* GLOBAL */
712
713/*
714 * Exiting.
715 */
716
717void
719{
720 if (!forked)
721 {
722 tun_abort();
723
724#ifdef _WIN32
725 uninit_win32();
726#endif
728
729 close_syslog();
730
731#ifdef ENABLE_PLUGIN
732 plugin_abort();
733#endif
734
735#if PORT_SHARE
736 if (port_share)
737 {
738 port_share_abort(port_share);
739 }
740#endif
741
742#ifdef ABORT_ON_ERROR
744 {
745 abort();
746 }
747#endif
748 }
749
750 exit(status);
751}
752
753/*
754 * Translate msg flags into a string
755 */
756const char *
758{
759 struct buffer out = alloc_buf_gc(16, gc);
760 if (flags == M_INFO)
761 {
762 buf_printf(&out, "I");
763 }
764 if (flags & M_FATAL)
765 {
766 buf_printf(&out, "F");
767 }
768 if (flags & M_NONFATAL)
769 {
770 buf_printf(&out, "N");
771 }
772 if (flags & M_WARN)
773 {
774 buf_printf(&out, "W");
775 }
776 if (flags & M_DEBUG)
777 {
778 buf_printf(&out, "D");
779 }
780 return BSTR(&out);
781}
782
783#ifdef _WIN32
784
785const char *
787{
788 /*
789 * This code can be omitted, though often the Windows
790 * WSA error messages are less informative than the
791 * Posix equivalents.
792 */
793#if 1
794 switch (errnum)
795 {
796 /*
797 * When the TAP-Windows driver returns STATUS_UNSUCCESSFUL, this code
798 * gets returned to user space.
799 */
801 return "General failure (ERROR_GEN_FAILURE)";
802
803 case ERROR_IO_PENDING:
804 return "I/O Operation in progress (ERROR_IO_PENDING)";
805
807 return "I/O Operation in progress (WSA_IO_INCOMPLETE)";
808
809 case WSAEINTR:
810 return "Interrupted system call (WSAEINTR)";
811
812 case WSAEBADF:
813 return "Bad file number (WSAEBADF)";
814
815 case WSAEACCES:
816 return "Permission denied (WSAEACCES)";
817
818 case WSAEFAULT:
819 return "Bad address (WSAEFAULT)";
820
821 case WSAEINVAL:
822 return "Invalid argument (WSAEINVAL)";
823
824 case WSAEMFILE:
825 return "Too many open files (WSAEMFILE)";
826
827 case WSAEWOULDBLOCK:
828 return "Operation would block (WSAEWOULDBLOCK)";
829
830 case WSAEINPROGRESS:
831 return "Operation now in progress (WSAEINPROGRESS)";
832
833 case WSAEALREADY:
834 return "Operation already in progress (WSAEALREADY)";
835
836 case WSAEDESTADDRREQ:
837 return "Destination address required (WSAEDESTADDRREQ)";
838
839 case WSAEMSGSIZE:
840 return "Message too long (WSAEMSGSIZE)";
841
842 case WSAEPROTOTYPE:
843 return "Protocol wrong type for socket (WSAEPROTOTYPE)";
844
845 case WSAENOPROTOOPT:
846 return "Bad protocol option (WSAENOPROTOOPT)";
847
849 return "Protocol not supported (WSAEPROTONOSUPPORT)";
850
852 return "Socket type not supported (WSAESOCKTNOSUPPORT)";
853
854 case WSAEOPNOTSUPP:
855 return "Operation not supported on socket (WSAEOPNOTSUPP)";
856
857 case WSAEPFNOSUPPORT:
858 return "Protocol family not supported (WSAEPFNOSUPPORT)";
859
860 case WSAEAFNOSUPPORT:
861 return "Address family not supported by protocol family (WSAEAFNOSUPPORT)";
862
863 case WSAEADDRINUSE:
864 return "Address already in use (WSAEADDRINUSE)";
865
866 case WSAENETDOWN:
867 return "Network is down (WSAENETDOWN)";
868
869 case WSAENETUNREACH:
870 return "Network is unreachable (WSAENETUNREACH)";
871
872 case WSAENETRESET:
873 return "Net dropped connection or reset (WSAENETRESET)";
874
875 case WSAECONNABORTED:
876 return "Software caused connection abort (WSAECONNABORTED)";
877
878 case WSAECONNRESET:
879 return "Connection reset by peer (WSAECONNRESET)";
880
881 case WSAENOBUFS:
882 return "No buffer space available (WSAENOBUFS)";
883
884 case WSAEISCONN:
885 return "Socket is already connected (WSAEISCONN)";
886
887 case WSAENOTCONN:
888 return "Socket is not connected (WSAENOTCONN)";
889
890 case WSAETIMEDOUT:
891 return "Connection timed out (WSAETIMEDOUT)";
892
893 case WSAECONNREFUSED:
894 return "Connection refused (WSAECONNREFUSED)";
895
896 case WSAELOOP:
897 return "Too many levels of symbolic links (WSAELOOP)";
898
899 case WSAENAMETOOLONG:
900 return "File name too long (WSAENAMETOOLONG)";
901
902 case WSAEHOSTDOWN:
903 return "Host is down (WSAEHOSTDOWN)";
904
905 case WSAEHOSTUNREACH:
906 return "No Route to Host (WSAEHOSTUNREACH)";
907
908 case WSAENOTEMPTY:
909 return "Directory not empty (WSAENOTEMPTY)";
910
911 case WSAEPROCLIM:
912 return "Too many processes (WSAEPROCLIM)";
913
914 case WSAEUSERS:
915 return "Too many users (WSAEUSERS)";
916
917 case WSAEDQUOT:
918 return "Disc Quota Exceeded (WSAEDQUOT)";
919
920 case WSAESTALE:
921 return "Stale NFS file handle (WSAESTALE)";
922
923 case WSASYSNOTREADY:
924 return "Network SubSystem is unavailable (WSASYSNOTREADY)";
925
927 return "WINSOCK DLL Version out of range (WSAVERNOTSUPPORTED)";
928
930 return "Successful WSASTARTUP not yet performed (WSANOTINITIALISED)";
931
932 case WSAEREMOTE:
933 return "Too many levels of remote in path (WSAEREMOTE)";
934
936 return "Host not found (WSAHOST_NOT_FOUND)";
937
938 default:
939 break;
940 }
941#endif /* if 1 */
942
943 /* format a windows error message */
944 {
945 wchar_t wmessage[256];
946 char *message = NULL;
947 struct buffer out = alloc_buf_gc(256, gc);
948 const DWORD status =
952 if (status)
953 {
955 }
956 if (!status || !message)
957 {
958 buf_printf(&out, "[Unknown Win32 Error]");
959 }
960 else
961 {
962 char *cp;
963 for (cp = message; *cp != '\0'; ++cp)
964 {
965 if (*cp == '\n' || *cp == '\r')
966 {
967 *cp = ' ';
968 }
969 }
970
971 buf_printf(&out, "%s", message);
972 }
973
974 return BSTR(&out);
975 }
976}
977
978#endif /* ifdef _WIN32 */
bool buf_printf(struct buffer *buf, const char *format,...)
printf-style append to a buffer with overflow check.
Definition buffer.c:231
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
Allocate memory and, optionally, zero it.
Definition buffer.c:321
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Allocate a buffer of the given size under garbage collection.
Definition buffer.c:77
char * string_alloc(const char *str, struct gc_arena *gc)
Duplicate a string, allocating memory under garbage collection.
Definition buffer.c:618
Buffer management functions and garbage collection.
#define BSTR(buf)
Return the buffer content pointer cast to char *.
Definition buffer.h:157
static void gc_init(struct gc_arena *a)
Initialise a garbage collection arena to an empty state.
Definition buffer.h:1932
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
Definition buffer.h:1974
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
Definition buffer.h:1958
#define PACKAGE_NAME
Definition config.h:492
#define PACKAGE
Definition config.h:486
#define DEBUG_LEVEL_USEC_TIME
Definition errlevel.h:32
#define M_INFO
Definition errlevel.h:54
void remove_pid_file(void)
Definition init.c:4921
void tun_abort(void)
Definition init.c:2095
static int constrain_int(int x, int min, int max)
Definition integer.h:118
static SERVICE_STATUS status
Definition interactive.c:52
void set_std_files_to_null(bool stdin_only)
Definition misc.c:55
#define SIZE(x)
Definition basic.h:29
static FILE * msgfp
Definition error.c:85
void error_reset(void)
Definition error.c:157
const struct virtual_output * x_msg_virtual_output
Definition error.c:711
void out_of_memory(void)
Definition error.c:442
msglvl_t get_debug_level(void)
Definition error.c:133
void errors_to_stderr(void)
Definition error.c:181
void open_syslog(const char *pgmname, bool stdio_to_null)
Definition error.c:449
void close_syslog(void)
Definition error.c:474
static FILE * default_err
Definition error.c:89
unsigned int x_cs_info_level
Definition error.c:604
void x_msg(const msglvl_t flags, const char *format,...)
Definition error.c:214
static bool forked
Definition error.c:92
msglvl_t x_debug_level
Definition error.c:48
const char * strerror_win32(DWORD errnum, struct gc_arena *gc)
Definition error.c:786
const char * x_msg_prefix
Definition error.c:705
int x_msg_line_num
Definition error.c:211
bool dont_mute(msglvl_t flags)
Check muting filter.
Definition error.c:390
static int orig_stderr
Definition error.c:488
int get_orig_stderr(void)
Definition error.c:491
static FILE * default_out
Definition error.c:88
static bool use_syslog
Definition error.c:70
void redirect_stdout_stderr(const char *file, bool append)
Definition error.c:498
void assert_failed(const char *filename, int line, const char *condition)
Definition error.c:424
static int mute_cutoff
Definition error.c:51
bool set_mute_cutoff(const int cutoff)
Definition error.c:119
#define SWAP
Definition error.c:204
void set_check_status(unsigned int info_level, unsigned int verbose_level)
Definition error.c:616
static msglvl_t mute_category
Definition error.c:53
unsigned int x_cs_verbose_level
Definition error.c:605
void openvpn_exit(const int status)
Definition error.c:718
void reset_check_status(void)
Definition error.c:609
static bool machine_readable_output
Definition error.c:74
void x_check_status(ssize_t status, const char *description, struct link_socket *sock, const struct tuntap *tt)
Definition error.c:631
void x_msg_va(const msglvl_t flags, const char *format, va_list arglist)
Definition error.c:240
static bool std_redir
Definition error.c:67
int get_mute_cutoff(void)
Definition error.c:139
void set_suppress_timestamps(bool suppressed)
Definition error.c:145
void set_machine_readable_output(bool parsable)
Definition error.c:151
FILE * msg_fp(const msglvl_t flags)
Definition error.c:190
static const char * openvpn_strerror(int err, bool crt_error, struct gc_arena *gc)
Definition error.c:228
bool set_debug_level(const int level, const unsigned int flags)
Definition error.c:103
static int mute_count
Definition error.c:52
static bool suppress_timestamps
Definition error.c:77
const char * msg_flags_string(const msglvl_t flags, struct gc_arena *gc)
Definition error.c:757
unsigned int x_cs_err_delay_ms
Definition error.c:606
#define M_OPTERR
Definition error.h:101
static bool check_debug_level(msglvl_t level)
Definition error.h:253
#define SDL_CONSTRAIN
Definition error.h:203
#define M_NOIPREFIX
Definition error.h:103
#define OPENVPN_DEBUG_FILE
Definition error.h:66
#define M_NOPREFIX
Definition error.h:98
#define DECODE_MUTE_LEVEL(flags)
Definition error.h:120
#define M_DEBUG_LEVEL
Definition error.h:88
#define ERR_BUF_SIZE
Definition error.h:34
static const char * msg_get_prefix(void)
Definition error.h:340
static bool msg_test(msglvl_t flags)
Return true if flags represent an enabled, not muted log level.
Definition error.h:260
#define M_NOMUTE
Definition error.h:97
#define M_FATAL
Definition error.h:90
#define OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE
Definition error.h:55
#define OPENVPN_MSG_FP
Definition error.h:45
#define OPENVPN_EXIT_STATUS_ERROR
Definition error.h:53
#define M_NONFATAL
Definition error.h:91
#define M_NOLF
Definition error.h:102
static bool ignore_sys_error(const int err, bool crt_error)
Definition error.h:370
#define M_ERR
Definition error.h:106
#define msg(flags,...)
Definition error.h:152
static int openvpn_errno_maybe_crt(bool *crt_error)
Definition error.h:415
unsigned int msglvl_t
Definition error.h:77
#define ASSERT(x)
Definition error.h:221
#define M_DEBUG
Definition error.h:93
#define M_WARN
Definition error.h:92
#define M_MSG_VIRT_OUT
Definition error.h:100
#define M_USAGE_SMALL
Definition error.h:99
#define M_ERRNO
Definition error.h:95
static const struct virtual_output * msg_get_virtual_output(void)
Definition error.h:360
#define OPENVPN_ERROR_FP
Definition error.h:46
void usage_small(void)
Definition options.c:3397
const char * time_string(time_t t, tv_usec_t usec, bool show_usec, struct gc_arena *gc)
Definition otime.c:104
void platform_sleep_milliseconds(unsigned int n)
Definition platform.c:478
void plugin_abort(void)
Definition plugin.c:903
const char * proto2ascii(int proto, sa_family_t af, bool display_form)
static void virtual_output_print(const struct virtual_output *vo, const unsigned int flags, const char *str)
Definition status.h:39
Wrapper structure for dynamically allocated memory.
Definition buffer.h:71
int len
Length in bytes of the actual content within the allocated memory.
Definition buffer.h:76
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:127
Definition tun.h:181
#define SOCKET_UNDEFINED
Definition syshead.h:439
#define SOCKET_PRINTF
Definition syshead.h:440
struct gc_arena gc
Definition test_ssl.c:138
const char * tap_win_getinfo(const struct tuntap *tt, struct gc_arena *gc)
Definition tun.c:6142
static bool tuntap_defined(const struct tuntap *tt)
Definition tun.h:252
char * utf16to8(const wchar_t *utf16, struct gc_arena *gc)
Definition win32-util.c:124
WCHAR * wide_string(const char *utf8, struct gc_arena *gc)
Definition win32-util.c:45
void uninit_win32(void)
Definition win32.c:123