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_init (&argv);
  argv_printf (&argv, SYSTEMD_ASK_PASSWORD_PATH);
  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;
}
示例#2
0
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;
}
示例#3
0
文件: lladdr.c 项目: benjdag/openvpn
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;
}
示例#4
0
/*
 * 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);
}
示例#5
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);
}