static bool get_console_input_systemd(const char *prompt, const bool echo, char *input, const int capacity) { int std_out; bool ret = false; struct argv argv = argv_new(); argv_printf(&argv, SYSTEMD_ASK_PASSWORD_PATH); #ifdef SYSTEMD_NEWER_THAN_216 /* the --echo support arrived in upstream systemd 217 */ if (echo) { argv_printf_cat(&argv, "--echo"); } #endif argv_printf_cat(&argv, "--icon network-vpn"); argv_printf_cat(&argv, "%s", prompt); if ((std_out = openvpn_popen(&argv, NULL)) < 0) { return false; } memset(input, 0, capacity); if (read(std_out, input, capacity-1) != 0) { chomp(input); ret = true; } close(std_out); argv_reset(&argv); return ret; }
static prog_args* prog_new() { prog_args* prog = (prog_args*)malloc(sizeof(prog_args)); if (prog==NULL) raise_error(PARSER_MALLOC); argv_new(prog); return prog; }
static bool tls_crypt_v2_verify_metadata(const struct tls_wrap_ctx *ctx, const struct tls_options *opt) { bool ret = false; struct gc_arena gc = gc_new(); const char *tmp_file = NULL; struct buffer metadata = ctx->tls_crypt_v2_metadata; int metadata_type = buf_read_u8(&metadata); if (metadata_type < 0) { msg(M_WARN, "ERROR: no metadata type"); goto cleanup; } tmp_file = platform_create_temp_file(opt->tmp_dir, "tls_crypt_v2_metadata_", &gc); if (!tmp_file || !buffer_write_file(tmp_file, &metadata)) { msg(M_WARN, "ERROR: could not write metadata to file"); goto cleanup; } char metadata_type_str[4] = { 0 }; /* Max value: 255 */ openvpn_snprintf(metadata_type_str, sizeof(metadata_type_str), "%i", metadata_type); struct env_set *es = env_set_create(NULL); setenv_str(es, "script_type", "tls-crypt-v2-verify"); setenv_str(es, "metadata_type", metadata_type_str); setenv_str(es, "metadata_file", tmp_file); struct argv argv = argv_new(); argv_parse_cmd(&argv, opt->tls_crypt_v2_verify_script); argv_msg_prefix(D_TLS_DEBUG, &argv, "Executing tls-crypt-v2-verify"); ret = openvpn_run_script(&argv, es, 0, "--tls-crypt-v2-verify"); argv_reset(&argv); env_set_destroy(es); if (!platform_unlink(tmp_file)) { msg(M_WARN, "WARNING: failed to remove temp file '%s", tmp_file); } if (ret) { msg(D_HANDSHAKE, "TLS CRYPT V2 VERIFY SCRIPT OK"); } else { msg(D_HANDSHAKE, "TLS CRYPT V2 VERIFY SCRIPT ERROR"); } cleanup: gc_free(&gc); return ret; }
int set_lladdr(const char *ifname, const char *lladdr, const struct env_set *es) { struct argv argv = argv_new(); int r; if (!ifname || !lladdr) { return -1; } #if defined(TARGET_LINUX) #ifdef ENABLE_IPROUTE argv_printf(&argv, "%s link set addr %s dev %s", iproute_path, lladdr, ifname); #else argv_printf(&argv, "%s %s hw ether %s", IFCONFIG_PATH, ifname, lladdr); #endif #elif defined(TARGET_SOLARIS) argv_printf(&argv, "%s %s ether %s", IFCONFIG_PATH, ifname, lladdr); #elif defined(TARGET_OPENBSD) argv_printf(&argv, "%s %s lladdr %s", IFCONFIG_PATH, ifname, lladdr); #elif defined(TARGET_DARWIN) argv_printf(&argv, "%s %s lladdr %s", IFCONFIG_PATH, ifname, lladdr); #elif defined(TARGET_FREEBSD) argv_printf(&argv, "%s %s ether %s", IFCONFIG_PATH, ifname, lladdr); #else /* if defined(TARGET_LINUX) */ msg(M_WARN, "Sorry, but I don't know how to configure link layer addresses on this operating system."); return -1; #endif /* if defined(TARGET_LINUX) */ argv_msg(M_INFO, &argv); r = openvpn_execve_check(&argv, es, M_WARN, "ERROR: Unable to set link layer address."); if (r) { msg(M_INFO, "TUN/TAP link layer address set to %s", lladdr); } argv_reset(&argv); return r; }
static cmds* cmd_new() { cmds* cmd = (cmds*)malloc(sizeof(cmds)); if (cmd==NULL) raise_error(PARSER_MALLOC); cmd->kind=PROG; cmd->next=NULL; argv_new(&(cmd->prog)); return cmd; }
/* * GuizmOVPN_updown (const char *command, const struct plugin_list *plugins, int plugin_type, const char *arg, const char *dev_type, int tun_mtu, int link_mtu, const char *ifconfig_local, const char* ifconfig_remote, const char *context, const char *signal_text, const char *script_type, struct env_set *es) : * Run external script */ void GuizmOVPN_updown (const char *command, const struct plugin_list *plugins, int plugin_type, const char *arg, const char *dev_type, int tun_mtu, int link_mtu, const char *ifconfig_local, const char* ifconfig_remote, const char *context, const char *signal_text, const char *script_type, struct env_set *es) { if (signal_text) setenv_str (es, "signal", signal_text); setenv_str (es, "script_context", context); setenv_int (es, "tun_mtu", tun_mtu); setenv_int (es, "link_mtu", link_mtu); setenv_str (es, "dev", arg); if (!ifconfig_local) ifconfig_local = ""; if (!ifconfig_remote) { ifconfig_remote = ""; } setenv_str (es, "InfosGateway", tapemu_ip_to_string(tapemu_get_remote_ip())); if (!context) context = ""; static struct argv guizmovpn_argv; argv_reset(&guizmovpn_argv); guizmovpn_argv = argv_new (); ASSERT (arg); setenv_str (es, "script_type", script_type); char szTemp[32]; szTemp[0]='\0'; GuizmOVPN_ReadPrefs("DNSPush",szTemp); if(strcmp(szTemp,"NO") != 0) { setenv_str (es, "DNSPush", "Y"); } GuizmOVPN_ReadPrefs("DNSKeep",szTemp); if(strcmp(szTemp,"NO") != 0) { setenv_str (es, "DNSKeep", "Y"); } szTemp[0]='\0'; GuizmOVPN_ReadPrefs("Multicast",szTemp); if(dev_type!=NULL && !strcmp(dev_type,"tap") && strcmp(szTemp,"NO") != 0) { setenv_str (es, "Multicast", "Y"); } /* if(client_proxy_infos.active) { setenv_str (es, "ClientProxyIP", client_proxy_infos.server_ip); setenv_int (es, "ClientProxyPort", client_proxy_infos.port); }*/ argv_printf (&guizmovpn_argv, "%sc %s %d %d %s %s %s", GUIZMOVPN_COMMAND, arg, tun_mtu, link_mtu, ifconfig_local, ifconfig_remote, context); openvpn_execve (&guizmovpn_argv, es, 0); }
/* * Pass tunnel endpoint and MTU parms to a user-supplied script. * Used to execute the up/down script/plugins. */ void run_up_down (const char *command, const struct plugin_list *plugins, int plugin_type, const char *arg, const char *dev_type, int tun_mtu, int link_mtu, const char *ifconfig_local, const char* ifconfig_remote, const char *context, const char *signal_text, const char *script_type, struct env_set *es) { struct gc_arena gc = gc_new (); if (signal_text) setenv_str (es, "signal", signal_text); setenv_str (es, "script_context", context); setenv_int (es, "tun_mtu", tun_mtu); setenv_int (es, "link_mtu", link_mtu); setenv_str (es, "dev", arg); if (dev_type) setenv_str (es, "dev_type", dev_type); if (!ifconfig_local) ifconfig_local = ""; if (!ifconfig_remote) ifconfig_remote = ""; if (!context) context = ""; if (plugin_defined (plugins, plugin_type)) { struct argv argv = argv_new (); ASSERT (arg); argv_printf (&argv, "%s %d %d %s %s %s", arg, tun_mtu, link_mtu, ifconfig_local, ifconfig_remote, context); if (plugin_call (plugins, plugin_type, &argv, NULL, es) != OPENVPN_PLUGIN_FUNC_SUCCESS) msg (M_FATAL, "ERROR: up/down plugin call failed"); argv_reset (&argv); } if (command) { struct argv argv = argv_new (); ASSERT (arg); setenv_str (es, "script_type", script_type); argv_printf (&argv, "%sc %s %d %d %s %s %s", command, arg, tun_mtu, link_mtu, ifconfig_local, ifconfig_remote, context); argv_msg (M_INFO, &argv); openvpn_run_script (&argv, es, S_FATAL, "--up/--down"); argv_reset (&argv); } gc_free (&gc); }