Go to the documentation of this file.
30 #ifdef ENABLE_MANAGEMENT
52 #define MANAGEMENT_ECHO_PULL_INFO 0
54 #if MANAGEMENT_ECHO_PULL_INFO
55 #define MANAGEMENT_ECHO_FLAGS LOG_PRINT_INTVAL
57 #define MANAGEMENT_ECHO_FLAGS 0
75 msg(
M_CLIENT,
"auth-retry t : Auth failure retry mode (none,interact,nointeract).");
76 msg(
M_CLIENT,
"bytecount n : Show bytes in/out, update every n secs (0=off).");
77 msg(
M_CLIENT,
"echo [on|off] [N|all] : Like log, but only show messages in echo buffer.");
78 msg(
M_CLIENT,
"cr-response response : Send a challenge response answer via CR_RESPONSE to server");
79 msg(
M_CLIENT,
"exit|quit : Close management session.");
80 msg(
M_CLIENT,
"forget-passwords : Forget passwords entered so far.");
82 msg(
M_CLIENT,
"hold [on|off|release] : Set/show hold flag to on/off state, or");
83 msg(
M_CLIENT,
" release current hold and start tunnel.");
84 msg(
M_CLIENT,
"kill cn : Kill the client instance(s) having common name cn.");
85 msg(
M_CLIENT,
"kill IP:port : Kill the client instance connecting from IP:port.");
86 msg(
M_CLIENT,
"load-stats : Show global server load stats.");
87 msg(
M_CLIENT,
"log [on|off] [N|all] : Turn on/off realtime log display");
88 msg(
M_CLIENT,
" + show last N lines or 'all' for entire history.");
89 msg(
M_CLIENT,
"mute [n] : Set log mute level to n, or show level if n is absent.");
90 msg(
M_CLIENT,
"needok type action : Enter confirmation for NEED-OK request of 'type',");
92 msg(
M_CLIENT,
"needstr type action : Enter confirmation for NEED-STR request of 'type',");
94 msg(
M_CLIENT,
"net : (Windows only) Show network info and routing table.");
95 msg(
M_CLIENT,
"password type p : Enter password p for a queried OpenVPN password.");
96 msg(
M_CLIENT,
"remote type [host port] : Override remote directive, type=ACCEPT|MOD|SKIP.");
97 msg(
M_CLIENT,
"remote-entry-count : Get number of available remote entries.");
98 msg(
M_CLIENT,
"remote-entry-get i|all [j]: Get remote entry at index = i to to j-1 or all.");
99 msg(
M_CLIENT,
"proxy type [host port flags] : Enter dynamic proxy server info.");
100 msg(
M_CLIENT,
"pid : Show process ID of the current OpenVPN process.");
102 msg(
M_CLIENT,
"pkcs11-id-count : Get number of available PKCS#11 identities.");
103 msg(
M_CLIENT,
"pkcs11-id-get index : Get PKCS#11 identity at index.");
105 msg(
M_CLIENT,
"client-auth CID KID : Authenticate client-id/key-id CID/KID (MULTILINE)");
106 msg(
M_CLIENT,
"client-auth-nt CID KID : Authenticate client-id/key-id CID/KID");
107 msg(
M_CLIENT,
"client-deny CID KID R [CR] : Deny auth client-id/key-id CID/KID with log reason");
108 msg(
M_CLIENT,
" text R and optional client reason text CR");
109 msg(
M_CLIENT,
"client-pending-auth CID KID MSG timeout : Instruct OpenVPN to send AUTH_PENDING and INFO_PRE msg");
110 msg(
M_CLIENT,
" to the client and wait for a final client-auth/client-deny");
111 msg(
M_CLIENT,
"client-kill CID [M] : Kill client instance CID with message M (def=RESTART)");
112 msg(
M_CLIENT,
"env-filter [level] : Set env-var filter level");
113 msg(
M_CLIENT,
"rsa-sig : Enter a signature in response to >RSA_SIGN challenge");
114 msg(
M_CLIENT,
" Enter signature base64 on subsequent lines followed by END");
115 msg(
M_CLIENT,
"pk-sig : Enter a signature in response to >PK_SIGN challenge");
116 msg(
M_CLIENT,
" Enter signature base64 on subsequent lines followed by END");
117 msg(
M_CLIENT,
"certificate : Enter a client certificate in response to >NEED-CERT challenge");
118 msg(
M_CLIENT,
" Enter certificate base64 on subsequent lines followed by END");
119 msg(
M_CLIENT,
"signal s : Send signal s to daemon,");
120 msg(
M_CLIENT,
" s = SIGHUP|SIGTERM|SIGUSR1|SIGUSR2.");
121 msg(
M_CLIENT,
"state [on|off] [N|all] : Like log, but show state history.");
122 msg(
M_CLIENT,
"status [n] : Show current daemon status info using format #n.");
123 msg(
M_CLIENT,
"test n : Produce n lines of output for testing/debugging.");
124 msg(
M_CLIENT,
"username type u : Enter username u for a queried OpenVPN username.");
125 msg(
M_CLIENT,
"verb [n] : Set log verbosity level to n, or show if n is absent.");
126 msg(
M_CLIENT,
"version [n] : Set client's version to n or show current version of daemon.");
160 return "RECONNECTING";
169 return "TCP_CONNECT";
172 return "AUTH_PENDING";
182 msg(
M_CLIENT,
">INFO:OpenVPN Management Interface Version %d -- type 'help' for more info",
218 msg(
M_WARN,
"MAN: client connection rejected after %d failed password attempts",
250 volatile int signal_received = 0;
297 msg(
M_CLIENT,
"SUCCESS: %s command succeeded", command);
301 msg(
M_CLIENT,
"ERROR: %s command failed", command);
308 #if UNIX_SOCK_SUPPORT
311 socket_delete_unix(&man->
settings.local_unix);
336 static int recursive_level = 0;
338 #define AF_DID_PUSH (1<<0)
339 #define AF_DID_RESET (1<<1)
340 if (recursive_level < 5)
344 const char *out = NULL;
345 unsigned int action_flags = 0;
410 printf(
"virtual_output: message to management interface "
411 "dropped due to recursion: <%s>\n", str);
437 if (s == SIGHUP || s == SIGUSR1)
459 msg(
M_CLIENT,
"ERROR: signal '%s' is currently ignored", name);
468 msg(
M_CLIENT,
"ERROR: signal '%s' is not a known signal type", name);
475 msg(
M_CLIENT,
"ERROR: The '%s' command is not supported by the current daemon mode", command_name);
494 if (update_seconds > 0)
506 msg(
M_CLIENT,
"SUCCESS: bytecount interval changed");
549 buf_set_read(&buf, (uint8_t *) victim, strlen(victim) + 1);
553 if (strlen(p1) && strlen(p2))
560 const int port = atoi(p2);
561 if (port > 0 && port < 65536)
566 msg(
M_CLIENT,
"SUCCESS: %d client(s) at address %s:%d killed",
573 msg(
M_CLIENT,
"ERROR: client at address %s:%d not found",
580 msg(
M_CLIENT,
"ERROR: port number is out of range: %s", p2);
585 msg(
M_CLIENT,
"ERROR: error parsing IP address: %s", p1);
594 msg(
M_CLIENT,
"SUCCESS: common name '%s' found, %d client(s) killed", p1, n_killed);
598 msg(
M_CLIENT,
"ERROR: common name '%s' not found", p1);
624 const unsigned int lep_flags)
629 if (
streq(parm,
"on"))
632 msg(
M_CLIENT,
"SUCCESS: real-time %s notification set to ON", type);
634 else if (
streq(parm,
"off"))
637 msg(
M_CLIENT,
"SUCCESS: real-time %s notification set to OFF", type);
639 else if (
streq(parm,
"all") || (n = atoi(parm)) > 0)
642 const int start = (n ? n : size) - 1;
645 for (i = start; i >= 0; --i)
658 msg(
M_CLIENT,
"ERROR: %s parameter must be 'on' or 'off' or some number n or 'all'", type);
744 msg(
M_CLIENT,
"SUCCESS: '%s' %s entered, but not yet verified",
750 msg(
M_CLIENT,
"ERROR: %s of type '%s' entered, but we need one of type '%s'",
758 msg(
M_CLIENT,
"ERROR: no %s is currently needed at this time", prompt);
802 msg(
M_CLIENT,
"SUCCESS: Passwords were forgotten");
844 msg(
M_CLIENT,
">PKCS11ID-COUNT:%d", pkcs11_management_id_count());
848 man_pkcs11_id_get(
struct management *man,
const int index)
853 if (pkcs11_management_id_get(index, &
id, &base64))
855 msg(
M_CLIENT,
">PKCS11ID-ENTRY:'%d', ID:'%s', BLOB:'%s'", index,
id, base64);
894 unsigned int from = (
unsigned int) atoi(p1);
895 unsigned int to = p2 ? (
unsigned int) atoi(p2) : from + 1;
897 if (!strcmp(p1,
"all"))
903 for (
unsigned int i = from; i <
min_uint(to, count); i++)
926 if (
streq(cmd,
"on"))
931 else if (
streq(cmd,
"off"))
936 else if (
streq(cmd,
"release"))
943 msg(
M_CLIENT,
"ERROR: bad hold command parameter");
1023 if (sscanf(str,
"%lu", cid) == 1)
1035 parse_uint(
const char *str,
const char *what,
unsigned int *uint)
1037 if (sscanf(str,
"%u", uint) == 1)
1060 const char *kid_str,
const char *extra,
1061 const char *timeout_str)
1063 unsigned long cid = 0;
1064 unsigned int kid = 0;
1065 unsigned int timeout = 0;
1067 &&
parse_uint(timeout_str,
"TIMEOUT", &timeout))
1076 msg(
M_CLIENT,
"SUCCESS: client-pending-auth command succeeded");
1080 msg(
M_CLIENT,
"ERROR: client-pending-auth command failed."
1081 " Extra parameter might be too long");
1112 unsigned long cid = 0;
1113 unsigned int kid = 0;
1128 msg(
M_CLIENT,
"SUCCESS: client-deny command succeeded");
1132 msg(
M_CLIENT,
"ERROR: client-deny command failed");
1145 unsigned long cid = 0;
1153 msg(
M_CLIENT,
"SUCCESS: client-kill command succeeded");
1157 msg(
M_CLIENT,
"ERROR: client-kill command failed");
1185 msg(
M_CLIENT,
"SUCCESS: env_filter_level=%d", level);
1201 msg(
M_CLIENT,
"ERROR: The %s command is not currently available", cmd_name);
1217 msg(
M_CLIENT,
"ERROR: The certificate command is not currently available");
1238 #define MN_AT_LEAST (1<<0)
1253 for (i = 1; i <= n; ++i)
1257 msg(
M_CLIENT,
"ERROR: the '%s' command requires %s%d parameter%s",
1296 #ifdef TARGET_ANDROID
1298 man_network_change(
struct management *man,
bool samenetwork)
1310 msg(
M_CLIENT,
"PROTECTFD: fd '%d' sent to be protected", fd);
1334 if (
streq(p[0],
"exit") ||
streq(p[0],
"quit"))
1339 else if (
streq(p[0],
"help"))
1343 else if (
streq(p[0],
"version") && p[1])
1347 else if (
streq(p[0],
"version"))
1353 else if (
streq(p[0],
"pid"))
1357 else if (
streq(p[0],
"nclients"))
1361 else if (
streq(p[0],
"env-filter"))
1370 else if (
streq(p[0],
"signal"))
1377 #ifdef TARGET_ANDROID
1378 else if (
streq(p[0],
"network-change"))
1380 bool samenetwork =
false;
1381 if (p[1] &&
streq(p[1],
"samenetwork"))
1386 man_network_change(man, samenetwork);
1389 else if (
streq(p[0],
"load-stats"))
1393 else if (
streq(p[0],
"status"))
1398 version = atoi(p[1]);
1402 else if (
streq(p[0],
"kill"))
1409 else if (
streq(p[0],
"verb"))
1413 const int level = atoi(p[1]);
1420 msg(
M_CLIENT,
"ERROR: verb level is out of range");
1428 else if (
streq(p[0],
"mute"))
1432 const int level = atoi(p[1]);
1439 msg(
M_CLIENT,
"ERROR: mute level is out of range");
1447 else if (
streq(p[0],
"auth-retry"))
1453 msg(
M_CLIENT,
"SUCCESS: auth-retry parameter changed");
1465 else if (
streq(p[0],
"state"))
1483 else if (
streq(p[0],
"log"))
1497 else if (
streq(p[0],
"echo"))
1511 else if (
streq(p[0],
"username"))
1518 else if (
streq(p[0],
"password"))
1525 else if (
streq(p[0],
"forget-passwords"))
1529 else if (
streq(p[0],
"needok"))
1536 else if (
streq(p[0],
"needstr"))
1543 else if (
streq(p[0],
"cr-response"))
1550 else if (
streq(p[0],
"net"))
1554 else if (
streq(p[0],
"hold"))
1558 else if (
streq(p[0],
"bytecount"))
1565 else if (
streq(p[0],
"client-kill"))
1572 else if (
streq(p[0],
"client-deny"))
1579 else if (
streq(p[0],
"client-auth-nt"))
1586 else if (
streq(p[0],
"client-auth"))
1593 else if (
streq(p[0],
"client-pending-auth"))
1600 else if (
streq(p[0],
"rsa-sig"))
1604 else if (
streq(p[0],
"pk-sig"))
1608 else if (
streq(p[0],
"certificate"))
1612 #ifdef ENABLE_PKCS11
1613 else if (
streq(p[0],
"pkcs11-id-count"))
1615 man_pkcs11_id_count(man);
1617 else if (
streq(p[0],
"pkcs11-id-get"))
1621 man_pkcs11_id_get(man, atoi(p[1]));
1625 else if (
streq(p[0],
"remote-entry-count"))
1629 else if (
streq(p[0],
"remote-entry-get"))
1636 else if (
streq(p[0],
"proxy"))
1643 else if (
streq(p[0],
"remote"))
1651 else if (
streq(p[0],
"test"))
1656 const int n = atoi(p[1]);
1657 for (i = 0; i < n; ++i)
1659 msg(
M_CLIENT,
"[%d] The purpose of this command is to generate large amounts of output.", i);
1666 msg(
M_CLIENT,
"ERROR: unknown command [%s], enter 'help' for more options", p[0]);
1728 #if UNIX_SOCK_SUPPORT
1733 sockaddr_unix_name(&man->
settings.local_unix,
"NULL"));
1745 struct sockaddr_storage addr;
1746 socklen_t addrlen =
sizeof(addr);
1771 #if UNIX_SOCK_SUPPORT
1777 static const char err_prefix[] =
"MANAGEMENT: unix domain socket client connection rejected --";
1783 msg(
D_MANAGEMENT,
"%s UID of socket peer (%d) doesn't match required value (%d) as given by --management-client-user",
1789 msg(
D_MANAGEMENT,
"%s GID of socket peer (%d) doesn't match required value (%d) as given by --management-client-group",
1796 msg(
D_MANAGEMENT,
"%s cannot get UID/GID of socket peer", err_prefix);
1813 #if UNIX_SOCK_SUPPORT
1816 struct sockaddr_un remote;
1858 #if UNIX_SOCK_SUPPORT
1878 msg(
M_ERR,
"MANAGEMENT: listen() failed");
1886 #if UNIX_SOCK_SUPPORT
1890 sockaddr_unix_name(&man->
settings.local_unix,
"NULL"));
1895 const struct sockaddr *man_addr = man->
settings.
local->ai_addr;
1896 struct sockaddr_storage addr;
1897 socklen_t addrlen =
sizeof(addr);
1898 if (!getsockname(man->
connection.
sd_top, (
struct sockaddr *) &addr, &addrlen))
1900 man_addr = (
struct sockaddr *) &addr;
1905 "Failed to get the management socket address");
1924 int signal_received = 0;
1932 #if UNIX_SOCK_SUPPORT
1957 if (signal_received)
1965 #if UNIX_SOCK_SUPPORT
1969 "MANAGEMENT: connect to unix socket %s failed",
1970 sockaddr_unix_name(&man->
settings.local_unix,
"NULL"));
1975 "MANAGEMENT: connect to %s failed",
2052 if (parms[0] &&
streq(parms[0],
"password"))
2056 else if (!
streq(line,
"load-stats"))
2065 for (i = 0; i < nparms; ++i)
2086 bool crt_error =
false;
2103 #ifdef TARGET_ANDROID
2105 man_send_with_fd(
int fd,
void *ptr,
size_t nbytes,
int flags,
int sendfd)
2107 struct msghdr
msg = { 0 };
2108 struct iovec iov[1];
2112 char control[CMSG_SPACE(
sizeof(
int))];
2114 struct cmsghdr *cmptr;
2116 msg.msg_control = control_un.control;
2117 msg.msg_controllen =
sizeof(control_un.control);
2119 cmptr = CMSG_FIRSTHDR(&
msg);
2120 cmptr->cmsg_len = CMSG_LEN(
sizeof(
int));
2121 cmptr->cmsg_level = SOL_SOCKET;
2122 cmptr->cmsg_type = SCM_RIGHTS;
2123 *((
int *) CMSG_DATA(cmptr)) = sendfd;
2125 msg.msg_name = NULL;
2126 msg.msg_namelen = 0;
2128 iov[0].iov_base = ptr;
2129 iov[0].iov_len = nbytes;
2133 return (sendmsg(fd, &
msg, flags));
2137 man_recv_with_fd(
int fd,
void *ptr,
size_t nbytes,
int flags,
int *recvfd)
2139 struct msghdr msghdr = { 0 };
2140 struct iovec iov[1];
2145 char control[CMSG_SPACE(
sizeof(
int))];
2147 struct cmsghdr *cmptr;
2149 msghdr.msg_control = control_un.control;
2150 msghdr.msg_controllen =
sizeof(control_un.control);
2152 msghdr.msg_name = NULL;
2153 msghdr.msg_namelen = 0;
2155 iov[0].iov_base = ptr;
2156 iov[0].iov_len = nbytes;
2157 msghdr.msg_iov = iov;
2158 msghdr.msg_iovlen = 1;
2160 if ( (n = recvmsg(fd, &msghdr, flags)) <= 0)
2165 if ( (cmptr = CMSG_FIRSTHDR(&msghdr)) != NULL
2166 && cmptr->cmsg_len == CMSG_LEN(
sizeof(
int)))
2168 if (cmptr->cmsg_level != SOL_SOCKET)
2170 msg(
M_ERR,
"control level != SOL_SOCKET");
2172 if (cmptr->cmsg_type != SCM_RIGHTS)
2174 msg(
M_ERR,
"control type != SCM_RIGHTS");
2176 *recvfd = *((
int *) CMSG_DATA(cmptr));
2191 management_android_control(
struct management *man,
const char *command,
const char *
msg)
2195 msg(
M_FATAL,
"Required management interface not available.");
2199 strncpy(up.username,
msg,
sizeof(up.username)-1);
2202 return strcmp(
"ok", up.password)==0;
2212 managment_android_persisttun_action(
struct management *man)
2216 strcpy(up.username,
"tunmethod");
2219 if (!strcmp(
"NOACTION", up.password))
2221 return ANDROID_KEEP_OLD_TUN;
2223 else if (!strcmp(
"OPEN_BEFORE_CLOSE", up.password))
2225 return ANDROID_OPEN_BEFORE_CLOSE;
2229 msg(
M_ERR,
"Got unrecognised '%s' from management for PERSIST_TUN_ACTION query", up.password);
2233 return ANDROID_OPEN_BEFORE_CLOSE;
2245 unsigned char buf[256];
2248 #ifdef TARGET_ANDROID
2265 bool processed_command =
false;
2267 ASSERT(len <= (
int)
sizeof(buf));
2284 if (!strcmp(line,
"END"))
2302 processed_command =
true;
2316 if (processed_command)
2336 const int size_hint = 1024;
2338 const struct buffer *buf;
2342 if (buf &&
BLEN(buf))
2345 #ifdef TARGET_ANDROID
2390 const int log_history_cache,
2391 const int echo_buffer_size,
2392 const int state_buffer_size)
2452 const char *pass_file,
2453 const char *client_user,
2454 const char *client_group,
2455 const int log_history_cache,
2456 const int echo_buffer_size,
2457 const int state_buffer_size,
2458 const int remap_sigusr1,
2459 const unsigned int flags)
2497 #if UNIX_SOCK_SUPPORT
2500 sockaddr_unix_init(&ms->local_unix, addr);
2525 NULL, AF_UNSPEC, &ms->
local);
2540 if (remap_sigusr1 == SIGHUP)
2544 else if (remap_sigusr1 == SIGTERM)
2558 freeaddrinfo(ms->
local);
2658 const char *pass_file,
2659 const char *client_user,
2660 const char *client_group,
2661 const int log_history_cache,
2662 const int echo_buffer_size,
2663 const int state_buffer_size,
2664 const int remap_sigusr1,
2665 const unsigned int flags)
2740 const in_addr_t *tun_local_ip,
2741 const struct in6_addr *tun_local_ip6,
2749 const char *out = NULL;
2798 static const char *env_names[] = {
2805 "ifconfig_netmask=",
2806 "daemon_start_time=",
2809 "ifconfig_pool_remote_ip=",
2810 "ifconfig_pool_netmask=",
2818 if (env_filter_level == 0)
2822 else if (env_filter_level <= 1 && !strncmp(env_str,
"X509_", 5))
2826 else if (env_filter_level <= 2)
2829 for (i = 0; i <
SIZE(env_names); ++i)
2831 const char *en = env_names[i];
2832 const size_t len = strlen(en);
2833 if (!strncmp(env_str, en, len))
2890 msg(
M_CLIENT,
">NOTIFY:%s,%s,%s", severity, type, text);
2909 buf_set_read(&buf, (
const uint8_t *) peer_info, strlen(peer_info));
2910 while (
buf_parse(&buf,
'\n', line,
sizeof(line)))
2919 msg(
D_MANAGEMENT,
"validation failed on peer_info line received from client");
2928 const unsigned int mda_key_id,
2934 const char *mode =
"CONNECT";
2954 const char *response)
2962 mdac->
cid, mda_key_id, response);
3021 const char *out = NULL;
3058 char buf[INET_ADDRSTRLEN];
3060 ia.s_addr = htonl(tun_local_ip);
3061 inet_ntop(AF_INET, &ia, buf,
sizeof(buf));
3084 msg(
M_CLIENT,
">PASSWORD:Verification Failed: '%s' ['%s']", type, reason);
3088 msg(
M_CLIENT,
">PASSWORD:Verification Failed: '%s'", type);
3103 if (*persistent == (
unsigned int)n)
3118 unsigned int *persistent)
3163 if (net_events & FD_CLOSE)
3171 if (net_events & FD_ACCEPT)
3179 if (net_events & FD_READ)
3187 if (net_events & FD_WRITE)
3191 if (
status < 0 && WSAGetLastError() == WSAEWOULDBLOCK)
3207 unsigned int *persistent)
3276 if (signal_received)
3279 if (*signal_received)
3327 else if (expire &&
now >= expire)
3331 if (signal_received)
3333 *signal_received = SIGINT;
3361 if (signal_received && *signal_received)
3387 #define MWCC_PASSWORD_WAIT (1<<0)
3388 #define MWCC_HOLD_WAIT (1<<1)
3389 #define MWCC_OTHER_WAIT (1<<2)
3396 volatile int *signal_received,
3397 const time_t expire,
3405 msg(
D_MANAGEMENT,
"Need password(s) from management interface, waiting...");
3409 msg(
D_MANAGEMENT,
"Need hold release from management interface, waiting...");
3413 msg(
D_MANAGEMENT,
"Need information from management interface, waiting...");
3418 if (signal_received && *signal_received)
3434 volatile int signal_received = 0;
3449 if (signal_received)
3458 if (!signal_received)
3462 if (signal_received)
3467 }
while (expire && expire >
now);
3485 const unsigned int flags,
3486 const char *static_challenge)
3493 volatile int signal_received = 0;
3496 const char *alert_type = NULL;
3497 const char *prefix = NULL;
3498 unsigned int up_query_mode = 0;
3499 const char *sc = NULL;
3510 alert_type =
"confirmation";
3515 prefix =
"NEED-STR";
3516 alert_type =
"string";
3521 prefix =
"PASSWORD";
3522 alert_type =
"password";
3527 prefix =
"PASSWORD";
3528 alert_type =
"username/password";
3529 if (static_challenge)
3531 sc = static_challenge;
3552 if (signal_received)
3570 if (!signal_received)
3574 if (signal_received)
3613 const char *b64_data,
const char *prompt,
const char *cmd,
int *state,
struct buffer_list **input)
3617 volatile int signal_received = 0;
3631 alert_msg =
alloc_buf_gc(strlen(b64_data)+strlen(prompt)+3, &gc);
3632 buf_printf(&alert_msg,
">%s:%s", prompt, b64_data);
3642 if (signal_received)
3654 if (!signal_received)
3658 if (signal_received)
3670 msg(
M_CLIENT,
"SUCCESS: %s command succeeded", cmd);
3690 const char *b64_data,
const char *prompt,
const char *cmd,
int *
state,
struct buffer_list **input)
3693 char *result = NULL;
3701 if (buf &&
BLEN(buf) > 0)
3703 result = (
char *) malloc(
BLEN(buf)+1);
3705 memcpy(result, buf->
data,
BLEN(buf));
3706 result[
BLEN(buf)] =
'\0';
3719 const char *b64_data,
const char *prompt,
const char *cmd,
int *state,
struct buffer_list **input)
3722 char *result = NULL;
3730 if (buf &&
BLEN(buf) > 0)
3732 result = (
char *) malloc(
BLEN(buf)+1);
3734 memcpy(result, buf->
data,
BLEN(buf));
3735 result[
BLEN(buf)] =
'\0';
3748 const char *algorithm)
3750 const char *prompt =
"PK_SIGN";
3751 const char *desc =
"pk-sign";
3752 struct buffer buf_data =
alloc_buf(strlen(b64_data) + strlen(algorithm) + 20);
3756 prompt =
"RSA_SIGN";
3760 buf_write(&buf_data, b64_data, (
int) strlen(b64_data));
3763 buf_write(&buf_data,
",", (
int) strlen(
","));
3764 buf_write(&buf_data, algorithm, (
int) strlen(algorithm));
3767 (
char *)
buf_bptr(&buf_data), prompt, desc,
3776 const char prompt_1[] =
"NEED-CERTIFICATE:";
3778 buf_write(&buf_prompt, prompt_1, strlen(prompt_1));
3779 buf_write(&buf_prompt, cert_name, strlen(cert_name)+1);
3783 NULL, (
char *)
buf_bptr(&buf_prompt),
"certificate",
3817 volatile int signal_received = 0;
3827 if (!signal_received)
3830 buf_printf(&out,
">HOLD:Waiting for hold release:%d", holdtime);
3838 if (!signal_received)
3842 if (signal_received)
3898 for (i = 0; i < len; ++i)
3914 const char *ret = NULL;
4044 for (i = 0; i < h->
size; ++i)
4090 for (i = 0; i < h->
size; ++i)
4103 if (index >= 0 && index < h->size)
struct status_output * status_open(const char *filename, const int refresh_freq, const int msglevel, const struct virtual_output *vout, const unsigned int flags)
#define UP_QUERY_USER_PASS
bool(* client_auth)(void *arg, const unsigned long cid, const unsigned int mda_key_id, const bool auth, const char *reason, const char *client_reason, struct buffer_list *cc_config)
void management_set_state(struct management *man, const int state, const char *detail, const in_addr_t *tun_local_ip, const struct in6_addr *tun_local_ip6, const struct openvpn_sockaddr *local, const struct openvpn_sockaddr *remote)
struct man_settings settings
#define GETADDR_WARN_ON_SIGNAL
static void man_signal(struct management *man, const char *name)
static void man_proxy(struct management *man, const char **p)
union openvpn_sockaddr::@14 addr
static unsigned int min_uint(unsigned int x, unsigned int y)
void management_auth_token(struct management *man, const char *token)
static void man_query_password(struct management *man, const char *type, const char *string)
void management_post_tunnel_open(struct management *man, const in_addr_t tun_local_ip)
#define UP_QUERY_DISABLED
#define ALLOC_ARRAY_CLEAR(dptr, type, n)
static void in_extra_dispatch(struct management *man)
static void man_query_username(struct management *man, const char *type, const char *string)
static struct gc_arena gc_new(void)
static void man_command_unsupported(const char *command_name)
#define LOG_PRINT_MSG_FLAGS
#define MANAGEMENT_ECHO_FLAGS
static const char * print_sockaddr(const struct sockaddr *addr, struct gc_arena *gc)
struct openvpn_sockaddr remote_sock
#define OPENVPN_STATE_EXITING
static int management_query_multiline(struct management *man, const char *b64_data, const char *prompt, const char *cmd, int *state, struct buffer_list **input)
void management_socket_set(struct management *man, struct event_set *es, void *arg, unsigned int *persistent)
int len
Length in bytes of the actual content within the allocated memory.
#define GET_USER_PASS_STATIC_CHALLENGE_ECHO
bool management_hold(struct management *man, int holdtime)
static void man_client_deny(struct management *man, const char *cid_str, const char *kid_str, const char *reason, const char *client_reason)
void sd_close(socket_descriptor_t *sd)
#define LOG_PRINT_STATE_PREFIX
static void man_check_password(struct management *man, const char *line)
void management_auth_failure(struct management *man, const char *type, const char *reason)
char *(* get_peer_info)(void *arg, const unsigned long cid)
void management_sleep(const int n)
A sleep function that services the management layer for n seconds rather than doing nothing.
static bool buf_copy_excess(struct buffer *dest, struct buffer *src, int len)
Contains all state information for one tunnel.
bool management_open(struct management *man, const char *addr, const char *port, const char *pass_file, const char *client_user, const char *client_group, const int log_history_cache, const int echo_buffer_size, const int state_buffer_size, const int remap_sigusr1, const unsigned int flags)
socket_descriptor_t sd_top
static void man_log(struct management *man, const char *parm)
char username[USER_PASS_LEN]
bool management_query_user_pass(struct management *man, struct user_pass *up, const char *type, const unsigned int flags, const char *static_challenge)
static void man_close_socket(struct management *man, const socket_descriptor_t sd)
static void man_query_need_str(struct management *man, const char *type, const char *action)
#define PS_DONT_SHOW_FAMILY
int capacity
Size in bytes of memory allocated by malloc().
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
void command_line_add(struct command_line *cl, const unsigned char *buf, const int len)
bool set_debug_level(const int level, const unsigned int flags)
const char * special_state_msg
struct log_history * state
struct net_event_win32 ne32
#define D_MANAGEMENT_DEBUG
bool(* remote_cmd)(void *arg, const char **p)
static void man_client_pending_auth(struct management *man, const char *cid_str, const char *kid_str, const char *extra, const char *timeout_str)
Will send a notification to the client that succesful authentication will require an additional step ...
void net_event_win32_reset(struct net_event_win32 *ne)
static uint8_t * buf_bptr(const struct buffer *buf)
struct buffer * buffer_list_peek(struct buffer_list *ol)
Retrieve the head buffer.
int parse_line(const char *line, char *p[], const int n, const char *file, const int line_num, int msglevel, struct gc_arena *gc)
void buffer_list_aggregate_separator(struct buffer_list *bl, const size_t max_len, const char *sep)
Aggregates as many buffers as possible from bl in a new buffer of maximum length max_len .
void buf_clear(struct buffer *buf)
int(* kill_by_cn)(void *arg, const char *common_name)
static void man_wait_for_client_connection(struct management *man, volatile int *signal_received, const time_t expire, unsigned int flags)
struct openvpn_sockaddr remote
void net_event_win32_start(struct net_event_win32 *ne, long network_events, socket_descriptor_t sd)
#define OPENVPN_STATE_ASSIGN_IP
socket_descriptor_t sd_cli
#define DAF_CONNECTION_CLOSED
static bool buf_copy(struct buffer *dest, const struct buffer *src)
static void man_certificate(struct management *man)
static struct buffer clear_buf(void)
Return an empty struct buffer.
int dco_get_peer_stats(struct context *c)
static void event_timeout_init(struct event_timeout *et, interval_t n, const time_t last)
Initialises a timer struct.
static void man_connection_settings_reset(struct management *man)
static bool man_io_error(struct management *man, const char *prefix)
#define MANAGEMENT_N_PASSWORD_RETRIES
void management_notify_client_cr_response(unsigned mda_key_id, const struct man_def_auth_context *mdac, const struct env_set *es, const char *response)
unsigned int in_extra_kid
static void man_history(struct management *man, const char *parm, const char *type, struct log_history *log, bool *realtime, const unsigned int lep_flags)
static int modulo_add(int x, int y, int mod)
static void man_env_filter(struct management *man, const int level)
static void man_listen(struct management *man)
void setenv_int(struct env_set *es, const char *name, int value)
static void man_hold(struct management *man, const char *cmd)
int openvpn_getaddrinfo(unsigned int flags, const char *hostname, const char *servname, int resolve_retry_seconds, struct signal_info *sig_info, int ai_family, struct addrinfo **res)
void throw_signal_soft(const int signum, const char *signal_text)
Throw a soft global signal.
void management_check_bytecount(struct context *c, struct management *man, struct timeval *timeval)
static const char * man_state_name(const int state)
static void log_entry_free_contents(struct log_entry *e)
static void man_forget_passwords(struct management *man)
void management_notify_generic(struct management *man, const char *str)
const char * command_line_get(struct command_line *cl)
const char * log_entry_print(const struct log_entry *e, unsigned int flags, struct gc_arena *gc)
static void man_pk_sig(struct management *man, const char *cmd_name)
void management_echo(struct management *man, const char *string, const bool pull)
static void man_help(void)
bool management_should_daemonize(struct management *man)
#define OPENVPN_STATE_INITIAL
static bool man_check_for_signals(volatile int *signal_received)
struct in6_addr local_ip6
static void man_prompt(struct management *man)
void net_event_win32_stop(struct net_event_win32 *ne)
void man_persist_client_stats(struct management *man, struct context *c)
#define CC_NEWLINE
newline
static void event_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *arg)
struct context_2 c2
Level 2 context.
#define OPENVPN_STATE_AUTH
in_addr_t getaddr(unsigned int flags, const char *hostname, int resolve_retry_seconds, bool *succeeded, struct signal_info *sig_info)
Translate an IPv4 addr or hostname from string form to in_addr_t.
char * string_alloc(const char *str, struct gc_arena *gc)
static void secure_memzero(void *data, size_t len)
Securely zeroise memory.
const char * print_in6_addr(struct in6_addr a6, unsigned int flags, struct gc_arena *gc)
void buf_chomp(struct buffer *buf)
counter_type link_read_bytes_global
int parse_signal(const char *signame)
void management_notify(struct management *man, const char *severity, const char *type, const char *text)
static void man_query_need_ok(struct management *man, const char *type, const char *action)
void command_line_reset(struct command_line *cl)
static bool ignore_sys_error(const int err, bool crt_error)
bool ssl_clean_auth_token(void)
static void man_state(struct management *man, const char *parm)
bool(* kill_by_cid)(void *arg, const unsigned long cid, const char *kill_msg)
static long net_event_win32_get_event_mask(const struct net_event_win32 *ne)
static void report_command_status(const bool status, const char *command)
Small function to report the success or failure of a command to the management interface.
void management_notify_client_close(struct management *management, struct man_def_auth_context *mdac, const struct env_set *es)
#define ALLOC_OBJ(dptr, type)
int get_mute_cutoff(void)
const char * signal_name(const int sig, const bool upper)
static bool buf_write_u8(struct buffer *dest, uint8_t data)
#define OPENVPN_STATE_WAIT
struct buffer_list * ext_cert_input
static void man_up_finalize(struct management *man)
void(* func)(void *arg, const unsigned int flags, const char *str)
#define CC_PRINT
printable (>= 32, != 127)
static void update_time(void)
static int man_block(struct management *man, volatile int *signal_received, const time_t expire)
const struct log_entry * log_history_ref(const struct log_history *h, const int index)
#define OPENVPN_STATE_TCP_CONNECT
#define MF_QUERY_PASSWORDS
void buffer_list_push(struct buffer_list *ol, const char *str)
Allocates and appends a new buffer containing str as data to ol.
void management_notify_client_needing_auth(struct management *management, const unsigned int mda_key_id, struct man_def_auth_context *mdac, const struct env_set *es)
int get_debug_level(void)
counter_type dco_write_bytes
void log_history_close(struct log_history *h)
bool management_over_tunnel
struct buffer_list * in_extra
struct management * management_init(void)
struct options options
Options loaded from command line or configuration file.
static bool parse_uint(const char *str, const char *what, unsigned int *uint)
static void man_remote_entry_get(struct management *man, const char *p1, const char *p2)
static bool management_connected(const struct management *man)
static void man_output_env(const struct env_set *es, const bool tail, const int env_filter_level, const char *prefix)
#define OPENVPN_STATE_CONNECTING
static void man_dispatch_command(struct management *man, struct status_output *so, const char **p, const int nparms)
bool char_class(const unsigned char c, const unsigned int flags)
static void man_remote_entry_count(struct management *man)
static void man_net(struct management *man)
void throw_signal(const int signum)
Throw a hard signal.
static void man_client_n_clients(struct management *man)
unsigned int(* remote_entry_count)(void *arg)
static void man_welcome(struct management *man)
void log_history_add(struct log_history *h, const struct log_entry *le)
#define MANAGEMENT_VERSION
static void man_remote(struct management *man, const char **p)
static int man_standalone_event_loop(struct management *man, volatile int *signal_received, const time_t expire)
static void man_output_extra_env(struct management *man, const char *prefix)
void man_bytecount_output_server(const counter_type *bytes_in_total, const counter_type *bytes_out_total, struct man_def_auth_context *mdac)
static bool get_user_pass(struct user_pass *up, const char *auth_file, const char *prefix, const unsigned int flags)
Retrieves the user credentials from various sources depending on the flags.
void(* show_net)(void *arg, const int msglevel)
#define MF_FORGET_DISCONNECT
char * management_query_pk_sig(struct management *man, const char *b64_data, const char *algorithm)
static const char blank_up[]
void win32_sleep(const int n)
static void msg_set_virtual_output(const struct virtual_output *vo)
void set_nonblock(socket_descriptor_t fd)
static void man_output_list_push_finalize(struct management *man)
struct command_line * command_line_new(const int buf_len)
void management_up_down(struct management *man, const char *updown, const struct env_set *es)
Wrapper structure for dynamically allocated memory.
static char * management_query_multiline_flatten_newline(struct management *man, const char *b64_data, const char *prompt, const char *cmd, int *state, struct buffer_list **input)
static void man_connect(struct management *man)
static void log_history_free_contents(struct log_history *h)
static void man_output_standalone(struct management *man, volatile int *signal_received)
int bytecount_update_seconds
#define LOG_PRINT_INT_DATE
static void event_reset(struct event_set *es)
struct log_history * log_history_init(const int capacity)
static void man_output_list_push(struct management *man, const char *str)
const char * print_sockaddr_ex(const struct sockaddr *sa, const char *separator, const unsigned int flags, struct gc_arena *gc)
static void man_delete_unix_socket(struct management *man)
struct buffer_list * buffer_list_new(void)
Allocate an empty buffer list of capacity max_size.
bool set_mute_cutoff(const int cutoff)
static int socket_defined(const socket_descriptor_t sd)
static void in_extra_reset(struct man_connection *mc, const int mode)
const char * print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)
static bool buf_write(struct buffer *dest, const void *src, size_t size)
static void man_send_cc_message(struct management *man, const char *message, const char *parameters)
bool(* client_pending_auth)(void *arg, const unsigned long cid, const unsigned int kid, const char *extra, unsigned int timeout)
#define LOG_PRINT_LOG_PREFIX
struct env_set * env_set_create(struct gc_arena *gc)
void(* status)(void *arg, const int version, struct status_output *so)
#define MANSIG_IGNORE_USR1_HUP
#define EVENT_METHOD_FAST
void management_event_loop_n_seconds(struct management *man, int sec)
#define OPENVPN_STATE_GET_CONFIG
void command_line_free(struct command_line *cl)
static void man_stop_ne32(struct management *man)
bool status_close(struct status_output *so)
void management_connection_established(struct management *management, struct man_def_auth_context *mdac, const struct env_set *es)
#define LOG_PRINT_ECHO_PREFIX
#define DAF_CONNECTION_ESTABLISHED
const char * auth_retry_print(void)
#define LOG_PRINT_REMOTE_IP
struct buffer_list * ext_key_input
#define OPENVPN_STATE_RECONNECTING
static void log_history_obj_init(struct log_history *h, int capacity)
Garbage collection arena used to keep track of dynamically allocated memory.
static int openvpn_errno_maybe_crt(bool *crt_error)
#define GETADDR_MSG_VIRT_OUT
bool(* remote_entry_get)(void *arg, unsigned int index, char **remote)
static void man_bytecount(struct management *man, const int update_seconds)
static int log_index(const struct log_history *h, int i)
static void man_reset_client_socket(struct management *man, const bool exiting)
#define MWCC_PASSWORD_WAIT
static void strncpynt(char *dest, const char *src, size_t maxlen)
static int man_read(struct management *man)
const char * mroute_addr_print_ex(const struct mroute_addr *ma, const unsigned int flags, struct gc_arena *gc)
const char * msg_flags_string(const unsigned int flags, struct gc_arena *gc)
static void man_accept(struct management *man)
static void man_update_io_state(struct management *man)
static void set_client_version(struct management *man, const char *version)
static void man_connection_init(struct management *man)
static bool dco_enabled(const struct options *o)
Returns whether the current configuration has dco enabled.
void free_buf(struct buffer *buf)
static void net_event_win32_clear_selected_events(struct net_event_win32 *ne, long selected_events)
int memcmp_constant_time(const void *a, const void *b, size_t size)
As memcmp(), but constant-time.
SOCKET socket_descriptor_t
static void man_echo(struct management *man, const char *parm)
void net_event_win32_reset_write(struct net_event_win32 *ne)
#define MANAGEMENT_LOG_HISTORY_INITIAL_SIZE
static void man_output_peer_info_env(struct management *man, const struct man_def_auth_context *mdac)
void management_pre_tunnel_close(struct management *man)
static void event_free(struct event_set *es)
bool(* send_cc_message)(void *arg, const char *message, const char *parameter)
static char * management_query_multiline_flatten(struct management *man, const char *b64_data, const char *prompt, const char *cmd, int *state, struct buffer_list **input)
static void management_bytes_client(struct management *man, const int size_in, const int size_out)
struct management_callback callback
#define OPENVPN_STATE_AUTH_PENDING
static int buf_len(const struct buffer *buf)
#define GETADDR_HOST_ORDER
static void man_persist_close(struct man_persist *mp)
static void man_start_ne32(struct management *man)
bool event_timeout_trigger(struct event_timeout *et, struct timeval *tv, const int et_const_retry)
This is the principal function for testing and triggering recurring timers.
static void virtual_output_callback_func(void *arg, const unsigned int flags, const char *str)
static bool addr_defined(const struct openvpn_sockaddr *addr)
bool(* proxy_cmd)(void *arg, const char **p)
counter_type link_write_bytes_global
#define MF_CONNECT_AS_CLIENT
void buffer_list_advance(struct buffer_list *ol, int n)
static bool man_standalone_ok(const struct management *man)
static bool man_need(struct management *man, const char **p, const int n, unsigned int flags)
Checks if the correct number of arguments to a management command are present and otherwise prints an...
void ssl_purge_auth(const bool auth_user_pass_only)
static void man_process_command(struct management *man, const char *line)
static struct rw_handle * net_event_win32_get_event(struct net_event_win32 *ne)
counter_type dco_read_bytes
static SERVICE_STATUS status
#define MANAGEMENT_STATE_BUFFER_SIZE
static void man_settings_close(struct man_settings *ms)
struct user_pass up_query
#define OPENVPN_STATE_CONNECTED
struct management * management
static int min_int(int x, int y)
static int man_write(struct management *man)
static void gc_free(struct gc_arena *a)
struct event_set * event_set_init(int *maxevents, unsigned int flags)
static bool env_filter_match(const char *env_str, const int env_filter_level)
#define GET_USER_PASS_PASSWORD_ONLY
#define GET_USER_PASS_NEED_OK
void management_close(struct management *man)
bool buffer_list_defined(const struct buffer_list *ol)
Checks if the list is valid and non-empty.
#define MANSIG_MAP_USR1_TO_HUP
#define ALLOC_OBJ_CLEAR(dptr, type)
static void man_bytecount_output_client(struct management *man, counter_type dco_read_bytes, counter_type dco_write_bytes)
static int man_mod_signal(const struct management *man, const int signum)
#define OPENVPN_STATE_RESOLVE
struct openvpn_sockaddr local_sock
socket_descriptor_t socket_do_accept(socket_descriptor_t sd, struct link_socket_actual *act, const bool nowait)
static void man_settings_init(struct man_settings *ms, const char *addr, const char *port, const char *pass_file, const char *client_user, const char *client_group, const int log_history_cache, const int echo_buffer_size, const int state_buffer_size, const int remap_sigusr1, const unsigned int flags)
struct log_history * echo
static bool parse_cid(const char *str, unsigned long *cid)
#define openvpn_close_socket(s)
static void man_connection_clear(struct man_connection *mc)
static void man_load_stats(struct management *man)
static void man_status(struct management *man, const int version, struct status_output *so)
bool validate_peer_info_line(char *line)
#define OPENVPN_STATE_ADD_ROUTES
#define MANAGEMENT_ECHO_BUFFER_SIZE
void buffer_list_free(struct buffer_list *ol)
Frees a buffer list and all the buffers in it.
void buffer_list_aggregate(struct buffer_list *bl, const size_t max)
Aggregates as many buffers as possible from bl in a new buffer of maximum length max_len .
int(* kill_by_addr)(void *arg, const in_addr_t addr, const int port)
int openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote, int connect_timeout, volatile int *signal_received)
struct virtual_output vout
static void man_client_kill(struct management *man, const char *cid_str, const char *kill_msg)
void command_line_next(struct command_line *cl)
void management_set_callback(struct management *man, const struct management_callback *cb)
bool management_would_hold(struct management *man)
void management_clear_callback(struct management *man)
#define IA_EMPTY_IF_UNDEF
void net_event_win32_close(struct net_event_win32 *ne)
static void man_persist_init(struct management *man, const int log_history_cache, const int echo_buffer_size, const int state_buffer_size)
void management_learn_addr(struct management *management, struct man_def_auth_context *mdac, const struct mroute_addr *addr, const bool primary)
static void check_malloc_return(void *p)
char password[USER_PASS_LEN]
static void get_signal(volatile int *sig)
Copy the global signal_received (if non-zero) to the passed-in argument sig.
unsigned long in_extra_cid
int buf_substring_len(const struct buffer *buf, int delim)
const char * up_query_type
char * management_query_cert(struct management *man, const char *cert_name)
time_t bytecount_last_update
void net_event_win32_init(struct net_event_win32 *ne)
void log_history_resize(struct log_history *h, const int capacity)
struct openvpn_sockaddr dest
#define LOG_PRINT_LOCAL_IP
static void event_timeout_clear(struct event_timeout *et)
Clears the timeout and reset all values to 0.
static void man_output_list_push_str(struct management *man, const char *str)
static int log_history_size(const struct log_history *h)
socket_descriptor_t create_socket_tcp(struct addrinfo *addrinfo)
#define GET_USER_PASS_NEED_STR
void socket_bind(socket_descriptor_t sd, struct addrinfo *local, int ai_family, const char *prefix, bool ipv6only)
unsigned int flags_default
struct buffer alloc_buf(size_t size)
void(* delete_event)(void *arg, event_t event)
#define OPENVPN_STATE_CLIENT_BASE
static void man_new_connection_post(struct management *man, const char *description)
bool auth_retry_set(const int msglevel, const char *option)
void buffer_list_reset(struct buffer_list *ol)
Empty the list ol and frees all the contained buffers.
const char title_string[]
struct event_timeout bytecount_update_interval
static void man_query_user_pass(struct management *man, const char *type, const char *string, const bool needed, const char *prompt, char *dest, int len)
static void man_kill(struct management *man, const char *victim)
bool buf_printf(struct buffer *buf, const char *format,...)
static bool man_password_needed(struct management *man)
static bool man_persist_state(unsigned int *persistent, const int n)
void management_io(struct management *man)
#define MANSIG_MAP_USR1_TO_TERM
#define UP_QUERY_NEED_STR
static void buf_set_read(struct buffer *buf, const uint8_t *data, size_t size)
static void man_client_auth(struct management *man, const char *cid_str, const char *kid_str, const bool extra)
static int event_wait(struct event_set *es, const struct timeval *tv, struct event_set_return *out, int outlen)
int(* n_clients)(void *arg)
struct man_persist persist
struct man_connection connection
static void man_connection_close(struct management *man)
uint8_t * data
Pointer to the allocated memory.
bool buf_parse(struct buffer *buf, const int delim, char *line, const int size)