int openconnect_setup_tun_script(struct openconnect_info *vpninfo, char *tun_script) { pid_t child; int fds[2]; vpninfo->vpnc_script = tun_script; vpninfo->script_tun = 1; set_script_env(vpninfo); if (socketpair(AF_UNIX, SOCK_DGRAM, 0, fds)) { vpn_progress(vpninfo, PRG_ERR, _("socketpair failed: %s\n"), strerror(errno)); return -EIO; } child = fork(); if (child < 0) { vpn_progress(vpninfo, PRG_ERR, _("fork failed: %s\n"), strerror(errno)); return -EIO; } else if (!child) { if (setpgid(0, getpid()) < 0) perror(_("setpgid")); close(fds[0]); setenv_int("VPNFD", fds[1]); execl("/bin/sh", "/bin/sh", "-c", vpninfo->vpnc_script, NULL); perror(_("execl")); exit(1); } close(fds[1]); vpninfo->script_tun = child; vpninfo->ifname = strdup(_("(script)")); return openconnect_setup_tun_fd(vpninfo, fds[0]); }
void setenv_int_i(struct env_set *es, const char *name, const int value, const int i) { struct gc_arena gc = gc_new(); const char *name_str = setenv_format_indexed_name(name, i, &gc); setenv_int(es, name_str, value); gc_free(&gc); }
/* * 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); }
static int process_split_xxclude(struct openconnect_info *vpninfo, int include, const char *route, int *v4_incs, int *v6_incs) { struct in_addr addr; const char *in_ex = include ? "IN" : "EX"; char envname[80]; char *slash; slash = strchr(route, '/'); if (!slash) { badinc: if (include) vpn_progress(vpninfo, PRG_ERR, _("Discard bad split include: \"%s\"\n"), route); else vpn_progress(vpninfo, PRG_ERR, _("Discard bad split exclude: \"%s\"\n"), route); return -EINVAL; } *slash = 0; if (strchr(route, ':')) { snprintf(envname, 79, "CISCO_IPV6_SPLIT_%sC_%d_ADDR", in_ex, *v6_incs); setenv(envname, route, 1); snprintf(envname, 79, "CISCO_IPV6_SPLIT_%sC_%d_MASKLEN", in_ex, *v6_incs); setenv(envname, slash+1, 1); (*v6_incs)++; return 0; } if (!inet_aton(route, &addr)) { *slash = '/'; goto badinc; } envname[79] = 0; snprintf(envname, 79, "CISCO_SPLIT_%sC_%d_ADDR", in_ex, *v4_incs); setenv(envname, route, 1); /* Put it back how we found it */ *slash = '/'; if (!inet_aton(slash+1, &addr)) goto badinc; snprintf(envname, 79, "CISCO_SPLIT_%sC_%d_MASK", in_ex, *v4_incs); setenv(envname, slash+1, 1); snprintf(envname, 79, "CISCO_SPLIT_%sC_%d_MASKLEN", in_ex, *v4_incs); setenv_int(envname, netmasklen(addr)); (*v4_incs)++; return 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); }