• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/openvpn-2.3.1/src/openvpn/

Lines Matching defs:man

67 static void man_output_standalone (struct management *man, volatile int *signal_received);
68 static void man_reset_client_socket (struct management *man, const bool exiting);
163 man_welcome (struct management *man)
167 if (man->persist.special_state_msg)
168 msg (M_CLIENT, "%s", man->persist.special_state_msg);
172 man_password_needed (struct management *man)
174 return man->settings.up.defined && !man->connection.password_verified;
178 man_check_password (struct management *man, const char *line)
180 if (man_password_needed (man))
182 if (streq (line, man->settings.up.password))
184 man->connection.password_verified = true;
186 man_welcome (man);
190 man->connection.password_verified = false;
192 if (++man->connection.password_tries >= MANAGEMENT_N_PASSWORD_RETRIES)
196 man->connection.halt = true;
203 man_update_io_state (struct management *man)
205 if (socket_defined (man->connection.sd_cli))
207 if (buffer_list_defined (man->connection.out))
209 man->connection.state = MS_CC_WAIT_WRITE;
213 man->connection.state = MS_CC_WAIT_READ;
219 man_output_list_push_finalize (struct management *man)
221 if (management_connected (man))
223 man_update_io_state (man);
224 if (!man->persist.standalone_disabled)
227 man_output_standalone (man, &signal_received);
233 man_output_list_push_str (struct management *man, const char *str)
235 if (management_connected (man) && str)
237 buffer_list_push (man->connection.out, (const unsigned char *) str);
242 man_output_list_push (struct management *man, const char *str)
244 man_output_list_push_str (man, str);
245 man_output_list_push_finalize (man);
249 man_prompt (struct management *man)
251 if (man_password_needed (man))
252 man_output_list_push (man, "ENTER PASSWORD:");
255 man_output_list_push (man, ">");
260 man_delete_unix_socket (struct management *man)
263 if ((man->settings.flags & (MF_UNIX_SOCK|MF_CONNECT_AS_CLIENT)) == MF_UNIX_SOCK)
264 socket_delete_unix (&man->settings.local_unix);
269 man_close_socket (struct management *man, const socket_descriptor_t sd)
276 if (man->persist.callback.delete_event)
277 (*man->persist.callback.delete_event) (man->persist.callback.arg, sd);
285 struct management *man = (struct management *) arg;
307 man->persist.standalone_disabled = false;
310 log_history_add (man->persist.log, &e);
312 if (!man_password_needed (man))
316 else if (man->connection.log_realtime)
323 man_output_list_push_str (man, out);
331 man_output_list_push_str (man, out);
340 man_output_list_push_finalize (man);
342 man_reset_client_socket (man, true);
353 man_mod_signal (const struct management *man, const int signum)
355 const unsigned int flags = man->settings.mansig;
373 man_signal (struct management *man, const char *name)
378 const int sig_mod = man_mod_signal (man, sig);
386 if (man->persist.special_state_msg)
387 msg (M_CLIENT, "%s", man->persist.special_state_msg);
399 man_status (struct management *man, const int version, struct status_output *so)
401 if (man->persist.callback.status)
403 (*man->persist.callback.status) (man->persist.callback.arg, version, so);
412 man_bytecount (struct management *man, const int update_seconds)
415 man->connection.bytecount_update_seconds = update_seconds;
417 man->connection.bytecount_update_seconds = 0;
422 man_bytecount_output_client (struct management *man)
427 openvpn_snprintf (in, sizeof (in), counter_format, man->persist.bytes_in);
428 openvpn_snprintf (out, sizeof (out), counter_format, man->persist.bytes_out);
430 man->connection.bytecount_last_update = now;
436 man_bytecount_output_server (struct management *man,
453 man_kill (struct management *man, const char *victim)
457 if (man->persist.callback.kill_by_cn && man->persist.callback.kill_by_addr)
478 n_killed = (*man->persist.callback.kill_by_addr) (man->persist.callback.arg, addr, port);
506 n_killed = (*man->persist.callback.kill_by_cn) (man->persist.callback.arg, p1);
534 man_history (struct management *man,
566 virtual_output_callback_func (man, M_CLIENT, out);
580 man_log (struct management *man, const char *parm)
582 man_history (man,
585 man->persist.log,
586 &man->connection.log_realtime,
591 man_echo (struct management *man, const char *parm)
593 man_history (man,
596 man->persist.echo,
597 &man->connection.echo_realtime,
602 man_state (struct management *man, const char *parm)
604 man_history (man,
607 man->persist.state,
608 &man->connection.state_realtime,
614 man_up_finalize (struct management *man)
616 switch (man->connection.up_query_mode)
619 if (!strlen (man->connection.up_query.username))
625 if (strlen (man->connection.up_query.password))
626 man->connection.up_query.defined = true;
629 man->connection.up_query.defined = false;
637 man_query_user_pass (struct management *man,
647 ASSERT (man->connection.up_query_type);
648 if (streq (man->connection.up_query_type, type))
651 man_up_finalize (man);
660 man->connection.up_query_type);
669 man_query_username (struct management *man, const char *type, const char *string)
671 const bool needed = ((man->connection.up_query_mode == UP_QUERY_USER_PASS
672 ) && man->connection.up_query_type);
673 man_query_user_pass (man, type, string, needed, "username", man->connection.up_query.username, USER_PASS_LEN);
677 man_query_password (struct management *man, const char *type, const char *string)
679 const bool needed = ((man->connection.up_query_mode == UP_QUERY_PASS
680 || man->connection.up_query_mode == UP_QUERY_USER_PASS
681 ) && man->connection.up_query_type);
684 man_query_user_pass (man, type, string, needed, "password", man->connection.up_query.password, USER_PASS_LEN);
688 man_query_need_ok (struct management *man, const char *type, const char *action)
690 const bool needed = ((man->connection.up_query_mode == UP_QUERY_NEED_OK) && man->connection.up_query_type);
691 man_query_user_pass (man, type, action, needed, "needok-confirmation", man->connection.up_query.password, USER_PASS_LEN);
695 man_query_need_str (struct management *man, const char *type, const char *action)
697 const bool needed = ((man->connection.up_query_mode == UP_QUERY_NEED_STR) && man->connection.up_query_type);
698 man_query_user_pass (man, type, action, needed, "needstr-string", man->connection.up_query.password, USER_PASS_LEN);
702 man_forget_passwords (struct management *man)
711 man_net (struct management *man)
713 if (man->persist.callback.show_net)
715 (*man->persist.callback.show_net) (man->persist.callback.arg, M_CLIENT);
726 man_pkcs11_id_count (struct management *man)
732 man_pkcs11_id_get (struct management *man, const int index)
751 man_hold (struct management *man, const char *cmd)
757 man->settings.flags |= MF_HOLD;
762 man->settings.flags &= ~MF_HOLD;
767 man->persist.hold_release = true;
776 msg (M_CLIENT, "SUCCESS: hold=%d", BOOL_CAST(man->settings.flags & MF_HOLD));
808 in_extra_dispatch (struct management *man)
810 switch (man->connection.in_extra_cmd)
814 if (man->persist.callback.client_auth)
816 const bool status = (*man->persist.callback.client_auth)
817 (man->persist.callback.arg,
818 man->connection.in_extra_cid,
819 man->connection.in_extra_kid,
823 man->connection.in_extra);
824 man->connection.in_extra = NULL;
842 if (man->persist.callback.client_pf)
844 const bool status = (*man->persist.callback.client_pf)
845 (man->persist.callback.arg,
846 man->connection.in_extra_cid,
847 man->connection.in_extra);
848 man->connection.in_extra = NULL;
866 man->connection.ext_key_state = EKS_READY;
867 buffer_list_free (man->connection.ext_key_input);
868 man->connection.ext_key_input = man->connection.in_extra;
869 man->connection.in_extra = NULL;
873 in_extra_reset (&man->connection, IER_RESET);
905 man_client_auth (struct management *man, const char *cid_str, const char *kid_str, const bool extra)
907 struct man_connection *mc = &man->connection;
916 in_extra_dispatch (man);
921 man_client_deny (struct management *man, const char *cid_str, const char *kid_str, const char *reason, const char *client_reason)
927 if (man->persist.callback.client_auth)
929 const bool status = (*man->persist.callback.client_auth)
930 (man->persist.callback.arg,
954 man_client_kill (struct management *man, const char *cid_str, const char *kill_msg)
959 if (man->persist.callback.kill_by_cid)
961 const bool status = (*man->persist.callback.kill_by_cid) (man->persist.callback.arg, cid, kill_msg);
979 man_client_n_clients (struct management *man)
981 if (man->persist.callback.n_clients)
983 const int nclients = (*man->persist.callback.n_clients) (man->persist.callback.arg);
993 man_env_filter (struct management *man, const int level)
995 man->connection.env_filter_level = level;
1002 man_client_pf (struct management *man, const char *cid_str)
1004 struct man_connection *mc = &man->connection;
1020 man_rsa_sig (struct management *man)
1022 struct man_connection *mc = &man->connection;
1036 man_load_stats (struct management *man)
1042 if (man->persist.callback.n_clients)
1043 nclients = (*man->persist.callback.n_clients) (man->persist.callback.arg);
1053 man_need (struct management *man, const char **p, const int n, unsigned int flags)
1073 man_proxy (struct management *man, const char **p)
1075 if (man->persist.callback.proxy_cmd)
1077 const bool status = (*man->persist.callback.proxy_cmd)(man->persist.callback.arg, p);
1088 man_remote (struct management *man, const char **p)
1090 if (man->persist.callback.remote_cmd)
1092 const bool status = (*man->persist.callback.remote_cmd)(man->persist.callback.arg, p);
1109 man_dispatch_command (struct management *man, struct status_output *so, const char **p, const int nparms)
1116 man->connection.halt = true;
1136 man_client_n_clients (man);
1143 man_env_filter (man, level);
1148 if (man_need (man, p, 1, 0))
1149 man_signal (man, p[1]);
1153 man_load_stats (man);
1160 man_status (man, version, so);
1164 if (man_need (man, p, 1, 0))
1165 man_kill (man, p[1]);
1213 man_state (man, "1");
1218 man_state (man, p[1]);
1220 man_state (man, p[2]);
1225 if (man_need (man, p, 1, MN_AT_LEAST))
1228 man_log (man, p[1]);
1230 man_log (man, p[2]);
1235 if (man_need (man, p, 1, MN_AT_LEAST))
1238 man_echo (man, p[1]);
1240 man_echo (man, p[2]);
1245 if (man_need (man, p, 2, 0))
1246 man_query_username (man, p[1], p[2]);
1250 if (man_need (man, p, 2, 0))
1251 man_query_password (man, p[1], p[2]);
1255 man_forget_passwords (man);
1259 if (man_need (man, p, 2, 0))
1260 man_query_need_ok (man, p[1], p[2]);
1264 if (man_need (man, p, 2, 0))
1265 man_query_need_str (man, p[1], p[2]);
1269 man_net (man);
1273 man_hold (man, p[1]);
1277 if (man_need (man, p, 1, 0))
1278 man_bytecount (man, atoi(p[1]));
1283 if (man_need (man, p, 1, MN_AT_LEAST))
1284 man_client_kill (man, p[1], p[2]);
1288 if (man_need (man, p, 3, MN_AT_LEAST))
1289 man_client_deny (man, p[1], p[2], p[3], p[4]);
1293 if (man_need (man, p, 2, 0))
1294 man_client_auth (man, p[1], p[2], false);
1298 if (man_need (man, p, 2, 0))
1299 man_client_auth (man, p[1], p[2], true);
1304 if (man_need (man, p, 1, 0))
1305 man_client_pf (man, p[1]);
1312 man_rsa_sig (man);
1318 man_pkcs11_id_count (man);
1322 if (man_need (man, p, 1, 0))
1323 man_pkcs11_id_get (man, atoi(p[1]));
1328 if (man_need (man, p, 1, MN_AT_LEAST))
1329 man_proxy (man, p);
1333 if (man_need (man, p, 1, MN_AT_LEAST))
1334 man_remote (man, p);
1339 if (man_need (man, p, 1, 0))
1362 man_start_ne32 (struct management *man)
1364 switch (man->connection.state)
1367 net_event_win32_start (&man->connection.ne32, FD_ACCEPT, man->connection.sd_top);
1371 net_event_win32_start (&man->connection.ne32, FD_READ|FD_WRITE|FD_CLOSE, man->connection.sd_cli);
1379 man_stop_ne32 (struct management *man)
1381 net_event_win32_stop (&man->connection.ne32);
1387 man_record_peer_info (struct management *man)
1390 if (man->settings.write_peer_info_file)
1394 if (socket_defined (man->connection.sd_cli))
1401 status = getsockname (man->connection.sd_cli, (struct sockaddr *)&addr, &addrlen);
1406 FILE *fp = platform_fopen (man->settings.write_peer_info_file, "w");
1419 man->settings.write_peer_info_file);
1427 man_connection_settings_reset (struct management *man)
1429 man->connection.state_realtime = false;
1430 man->connection.log_realtime = false;
1431 man->connection.echo_realtime = false;
1432 man->connection.bytecount_update_seconds = 0;
1433 man->connection.password_verified = false;
1434 man->connection.password_tries = 0;
1435 man->connection.halt = false;
1436 man->connection.state = MS_CC_WAIT_WRITE;
1440 man_new_connection_post (struct management *man, const char *description)
1444 set_nonblock (man->connection.sd_cli);
1445 set_cloexec (man->connection.sd_cli);
1447 man_connection_settings_reset (man);
1450 man_start_ne32 (man);
1454 if (man->settings.flags & MF_UNIX_SOCK)
1458 sockaddr_unix_name (&man->settings.local_unix, "NULL"));
1464 print_sockaddr (&man->settings.local, &gc));
1466 buffer_list_reset (man->connection.out);
1468 if (!man_password_needed (man))
1469 man_welcome (man);
1470 man_prompt (man);
1471 man_update_io_state (man);
1478 man_verify_unix_peer_uid_gid (struct management *man, const socket_descriptor_t sd)
1480 if (socket_defined (sd) && (man->settings.client_uid != -1 || man->settings.client_gid != -1))
1484 if (unix_socket_get_peer_uid_gid (man->connection.sd_cli, &uid, &gid))
1486 if (man->settings.client_uid != -1 && man->settings.client_uid != uid)
1489 err_prefix, uid, man->settings.client_uid);
1492 if (man->settings.client_gid != -1 && man->settings.client_gid != gid)
1495 err_prefix, gid, man->settings.client_gid);
1510 man_accept (struct management *man)
1519 if (man->settings.flags & MF_UNIX_SOCK)
1522 man->connection.sd_cli = socket_accept_unix (man->connection.sd_top, &remote);
1523 if (!man_verify_unix_peer_uid_gid (man, man->connection.sd_cli))
1524 sd_close (&man->connection.sd_cli);
1528 man->connection.sd_cli = socket_do_accept (man->connection.sd_top, &act, false);
1530 if (socket_defined (man->connection.sd_cli))
1532 man->connection.remote = act.dest;
1534 if (socket_defined (man->connection.sd_top))
1537 man_stop_ne32 (man);
1541 man_new_connection_post (man, "Client connected from");
1546 man_listen (struct management *man)
1553 man->connection.state = MS_LISTEN;
1554 man->connection.sd_cli = SOCKET_UNDEFINED;
1559 if (man->connection.sd_top == SOCKET_UNDEFINED)
1562 if (man->settings.flags & MF_UNIX_SOCK)
1564 man_delete_unix_socket (man);
1565 man->connection.sd_top = create_socket_unix ();
1566 socket_bind_unix (man->connection.sd_top, &man->settings.local_unix, "MANAGEMENT");
1571 man->connection.sd_top = create_socket_tcp (AF_INET);
1572 socket_bind (man->connection.sd_top, &man->settings.local, "MANAGEMENT");
1578 if (listen (man->connection.sd_top, 1))
1584 set_nonblock (man->connection.sd_top);
1585 set_cloexec (man->connection.sd_top);
1588 if (man->settings.flags & MF_UNIX_SOCK)
1591 sockaddr_unix_name (&man->settings.local_unix, "NULL"));
1596 print_sockaddr (&man->settings.local, &gc));
1600 man_start_ne32 (man);
1607 man_connect (struct management *man)
1616 man->connection.state = MS_INITIAL;
1617 man->connection.sd_top = SOCKET_UNDEFINED;
1620 if (man->settings.flags & MF_UNIX_SOCK)
1622 man->connection.sd_cli = create_socket_unix ();
1623 status = socket_connect_unix (man->connection.sd_cli, &man->settings.local_unix);
1624 if (!status && !man_verify_unix_peer_uid_gid (man, man->connection.sd_cli))
1631 sd_close (&man->connection.sd_cli);
1637 man->connection.sd_cli = create_socket_tcp (AF_INET);
1638 status = openvpn_connect (man->connection.sd_cli,
1639 &man->settings.local,
1653 if (man->settings.flags & MF_UNIX_SOCK)
1657 sockaddr_unix_name (&man->settings.local_unix, "NULL"),
1664 print_sockaddr (&man->settings.local, &gc),
1670 man_record_peer_info (man);
1671 man_new_connection_post (man, "Connected to management server at");
1678 man_reset_client_socket (struct management *man, const bool exiting)
1680 if (socket_defined (man->connection.sd_cli))
1683 man_stop_ne32 (man);
1685 man_close_socket (man, man->connection.sd_cli);
1686 man->connection.sd_cli = SOCKET_UNDEFINED;
1687 man->connection.state = MS_INITIAL;
1688 command_line_reset (man->connection.in);
1689 buffer_list_reset (man->connection.out);
1691 in_extra_reset (&man->connection, IER_RESET);
1698 if (man->settings.flags & MF_FORGET_DISCONNECT)
1701 if (man->settings.flags & MF_SIGNAL) {
1702 int mysig = man_mod_signal (man, SIGUSR1);
1710 if (man->settings.flags & MF_CONNECT_AS_CLIENT)
1716 man_listen (man);
1721 man_process_command (struct management *man, const char *line)
1729 so = status_open (NULL, 0, -1, &man->persist.vout, 0);
1731 in_extra_reset (&man->connection, IER_RESET);
1734 if (man_password_needed (man))
1736 man_check_password (man, line);
1756 man_dispatch_command (man, so, (const char **)parms, nparms);
1765 man_io_error (struct management *man, const char *prefix)
1783 man_read (struct management *man)
1791 len = recv (man->connection.sd_cli, buf, sizeof (buf), MSG_NOSIGNAL);
1794 man_reset_client_socket (man, false);
1801 command_line_add (man->connection.in, buf, len);
1806 buffer_list_reset (man->connection.out);
1813 while ((line = command_line_get (man->connection.in)))
1816 if (man->connection.in_extra)
1819 in_extra_dispatch (man);
1821 buffer_list_push (man->connection.in_extra, line);
1825 man_process_command (man, (char *) line);
1826 if (man->connection.halt)
1828 command_line_next (man->connection.in);
1836 if (man->connection.halt)
1838 man_reset_client_socket (man, false);
1844 man_prompt (man);
1845 man_update_io_state (man);
1850 if (man_io_error (man, "recv"))
1851 man_reset_client_socket (man, false);
1857 man_write (struct management *man)
1863 buffer_list_aggregate(man->connection.out, size_hint);
1864 buf = buffer_list_peek (man->connection.out);
1868 sent = send (man->connection.sd_cli, BPTR (buf), len, MSG_NOSIGNAL);
1871 buffer_list_advance (man->connection.out, sent);
1875 if (man_io_error (man, "send"))
1876 man_reset_client_socket (man, false);
1883 man_update_io_state (man);
1902 man_persist_init (struct management *man,
1907 struct man_persist *mp = &man->persist;
1921 mp->vout.arg = man;
1928 man->persist.echo = log_history_init (echo_buffer_size);
1933 man->persist.state = log_history_init (state_buffer_size);
2063 man_connection_init (struct management *man)
2065 if (man->connection.state == MS_INITIAL)
2072 net_event_win32_init (&man->connection.ne32);
2079 man->connection.in = command_line_new (1024);
2080 man->connection.out = buffer_list_new (0);
2088 man->connection.es = event_set_init (&maxevents, EVENT_METHOD_FAST);
2094 if (man->settings.flags & MF_CONNECT_AS_CLIENT)
2095 man_connect (man);
2097 man_listen (man);
2102 man_connection_close (struct management *man)
2104 struct man_connection *mc = &man->connection;
2113 man_close_socket (man, mc->sd_top);
2114 man_delete_unix_socket (man);
2117 man_close_socket (man, mc->sd_cli);
2123 in_extra_reset (&man->connection, IER_RESET);
2134 struct management *man;
2135 ALLOC_OBJ_CLEAR (man, struct management);
2137 man_persist_init (man,
2142 man_connection_clear (&man->connection);
2144 return man;
2148 management_open (struct management *man,
2167 man_settings_init (&man->settings,
2184 log_history_resize (man->persist.log, man->settings.log_history_cache);
2185 log_history_resize (man->persist.echo, man->settings.echo_buffer_size);
2186 log_history_resize (man->persist.state, man->settings.state_buffer_size);
2192 if (man->connection.state == MS_INITIAL)
2194 if (!man->settings.management_over_tunnel)
2196 man_connection_init (man);
2205 management_close (struct management *man)
2207 man_output_list_push_finalize (man); /* flush output queue */
2208 man_connection_close (man);
2209 man_settings_close (&man->settings);
2210 man_persist_close (&man->persist);
2211 free (man);
2215 management_set_callback (struct management *man,
2218 man->persist.standalone_disabled = true;
2219 man->persist.callback = *cb;
2223 management_clear_callback (struct management *man)
2225 man->persist.standalone_disabled = false;
2226 man->persist.hold_release = false;
2227 CLEAR (man->persist.callback);
2228 man_output_list_push_finalize (man); /* flush output queue */
2232 management_set_state (struct management *man,
2238 if (man->persist.state && (!(man->settings.flags & MF_SERVER) || state < OPENVPN_STATE_CLIENT_BASE))
2252 log_history_add (man->persist.state, &e);
2254 if (man->connection.state_realtime)
2264 man_output_list_push (man, out);
2327 man_output_extra_env (struct management *man, const char *prefix)
2331 if (man->persist.callback.n_clients)
2333 const int nclients = (*man->persist.callback.n_clients) (man->persist.callback.arg);
2336 man_output_env (es, false, man->connection.env_filter_level, prefix);
2341 management_up_down(struct management *man, const char *updown, const struct env_set *es)
2343 if (man->settings.flags & MF_UP_DOWN)
2351 management_notify(struct management *man, const char *severity, const char *type, const char *text)
2357 management_notify_generic (struct management *man, const char *str)
2392 man_output_peer_info_env (struct management *man, struct man_def_auth_context *mdac)
2395 if (man->persist.callback.get_peer_info)
2397 const char *peer_info = (*man->persist.callback.get_peer_info) (man->persist.callback.arg, mdac->cid);
2479 management_echo (struct management *man, const char *string, const bool pull)
2481 if (man->persist.echo)
2493 log_history_add (man->persist.echo, &e);
2495 if (man->connection.echo_realtime)
2499 man_output_list_push (man, out);
2506 management_post_tunnel_open (struct management *man, const in_addr_t tun_local_ip)
2512 if (man->settings.management_over_tunnel
2513 && man->connection.state == MS_INITIAL)
2516 man->settings.local.addr.in4.sin_addr.s_addr = htonl (tun_local_ip);
2517 man_connection_init (man);
2523 management_pre_tunnel_close (struct management *man)
2525 if (man->settings.management_over_tunnel)
2526 man_connection_close (man);
2530 management_auth_failure (struct management *man, const char *type, const char *reason)
2539 management_auth_token (struct management *man, const char *token)
2559 management_socket_set (struct management *man,
2564 if (man->connection.state != MS_INITIAL)
2566 event_t ev = net_event_win32_get_event (&man->connection.ne32);
2567 net_event_win32_reset_write (&man->connection.ne32);
2569 switch (man->connection.state)
2590 management_io (struct management *man)
2592 if (man->connection.state != MS_INITIAL)
2595 net_event_win32_reset (&man->connection.ne32);
2596 net_events = net_event_win32_get_event_mask (&man->connection.ne32);
2600 man_reset_client_socket (man, false);
2604 if (man->connection.state == MS_LISTEN)
2608 man_accept (man);
2609 net_event_win32_clear_selected_events (&man->connection.ne32, FD_ACCEPT);
2612 else if (man->connection.state == MS_CC_WAIT_READ || man->connection.state == MS_CC_WAIT_WRITE)
2616 while (man_read (man) > 0)
2618 net_event_win32_clear_selected_events (&man->connection.ne32, FD_READ);
2624 status = man_write (man);
2627 net_event_win32_clear_selected_events (&man->connection.ne32, FD_WRITE);
2638 management_socket_set (struct management *man,
2643 switch (man->connection.state)
2647 event_ctl (es, man->connection.sd_top, EVENT_READ, arg);
2651 event_ctl (es, man->connection.sd_cli, EVENT_READ, arg);
2655 event_ctl (es, man->connection.sd_cli, EVENT_WRITE, arg);
2665 management_io (struct management *man)
2667 switch (man->connection.state)
2670 man_accept (man);
2673 man_read (man);
2676 man_write (man);
2688 man_standalone_ok (const struct management *man)
2690 return !man->settings.management_over_tunnel && man->connection.state != MS_INITIAL;
2709 man_block (struct management *man, volatile int *signal_received, const time_t expire)
2715 if (man_standalone_ok (man))
2719 event_reset (man->connection.es);
2720 management_socket_set (man, man->connection.es, NULL, NULL);
2728 status = event_wait (man->connection.es, &tv, &esr, 1);
2755 man_output_standalone (struct management *man, volatile int *signal_received)
2757 if (man_standalone_ok (man))
2759 while (man->connection.state == MS_CC_WAIT_WRITE)
2761 management_io (man);
2762 if (man->connection.state == MS_CC_WAIT_WRITE)
2763 man_block (man, signal_received, 0);
2774 man_standalone_event_loop (struct management *man, volatile int *signal_received, const time_t expire)
2777 if (man_standalone_ok (man))
2779 status = man_block (man, signal_received, expire);
2781 management_io (man);
2794 man_wait_for_client_connection (struct management *man,
2799 ASSERT (man_standalone_ok (man));
2800 if (man->connection.state == MS_LISTEN)
2809 man_standalone_event_loop (man, signal_received, expire);
2812 } while (man->connection.state == MS_LISTEN || man_password_needed (man));
2820 management_event_loop_n_seconds (struct management *man, int sec)
2822 if (man_standalone_ok (man))
2825 const bool standalone_disabled_save = man->persist.standalone_disabled;
2828 man->persist.standalone_disabled = false; /* This is so M_CLIENT messages will be correctly passed through msg() */
2836 man_wait_for_client_connection (man, &signal_received, expire, 0);
2843 man_standalone_event_loop (man, &signal_received, expire);
2851 man->persist.standalone_disabled = standalone_disabled_save;
2863 management_query_user_pass (struct management *man,
2872 if (man_standalone_ok (man))
2875 const bool standalone_disabled_save = man->persist.standalone_disabled;
2884 man->persist.standalone_disabled = false; /* This is so M_CLIENT messages will be correctly passed through msg() */
2885 man->persist.special_state_msg = NULL;
2887 CLEAR (man->connection.up_query);
2932 man_wait_for_client_connection (man, &signal_received, 0, MWCC_PASSWORD_WAIT);
2938 man->persist.special_state_msg = BSTR (&alert_msg);
2939 msg (M_CLIENT, "%s", man->persist.special_state_msg);
2942 man->connection.up_query_mode = up_query_mode;
2943 man->connection.up_query_type = type;
2948 man_standalone_event_loop (man, &signal_received, 0);
2956 } while (!man->connection.up_query.defined);
2960 man->connection.up_query_mode = UP_QUERY_DISABLED;
2961 man->connection.up_query_type = NULL;
2962 man->persist.standalone_disabled = standalone_disabled_save;
2963 man->persist.special_state_msg = NULL;
2966 if (!strcmp (man->connection.up_query.password, blank_up))
2967 CLEAR (man->connection.up_query.password);
2975 man->connection.up_query.nocache = up->nocache; /* preserve caller's nocache setting */
2976 *up = man->connection.up_query;
2978 CLEAR (man->connection.up_query);
2988 management_query_rsa_sig (struct management *man,
2996 const bool standalone_disabled_save = man->persist.standalone_disabled;
2997 struct man_connection *mc = &man->connection;
2999 if (man_standalone_ok (man))
3001 man->persist.standalone_disabled = false; /* This is so M_CLIENT messages will be correctly passed through msg() */
3002 man->persist.special_state_msg = NULL;
3009 man_wait_for_client_connection (man, &signal_received, 0, MWCC_OTHER_WAIT);
3014 man->persist.special_state_msg = BSTR (&alert_msg);
3015 msg (M_CLIENT, "%s", man->persist.special_state_msg);
3020 man_standalone_event_loop (man, &signal_received, 0);
3048 man->persist.standalone_disabled = standalone_disabled_save;
3049 man->persist.special_state_msg = NULL;
3065 management_would_hold (struct management *man)
3067 return (man->settings.flags & MF_HOLD) && !man->persist.hold_release && man_standalone_ok (man);
3075 management_should_daemonize (struct management *man)
3077 return management_would_hold (man) || (man->settings.flags & MF_QUERY_PASSWORDS);
3085 management_hold (struct management *man)
3087 if (management_would_hold (man))
3090 const bool standalone_disabled_save = man->persist.standalone_disabled;
3092 man->persist.standalone_disabled = false; /* This is so M_CLIENT messages will be correctly passed through msg() */
3093 man->persist.special_state_msg = NULL;
3094 man->settings.mansig |= MANSIG_IGNORE_USR1_HUP;
3096 man_wait_for_client_connection (man, &signal_received, 0, MWCC_HOLD_WAIT);
3100 man->persist.special_state_msg = ">HOLD:Waiting for hold release";
3101 msg (M_CLIENT, "%s", man->persist.special_state_msg);
3106 man_standalone_event_loop (man, &signal_received, 0);
3111 } while (!man->persist.hold_release);
3115 man->persist.standalone_disabled = standalone_disabled_save;
3116 man->persist.special_state_msg = NULL;
3117 man->settings.mansig &= ~MANSIG_IGNORE_USR1_HUP;