Commit f90b4428 authored by David Woodhouse's avatar David Woodhouse

Move script_config_tun() to script.c

Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent 8f2d1a5c
......@@ -451,11 +451,11 @@ int win32_setup_tun(struct openconnect_info *vpninfo);
/* script.c */
int setenv_int(const char *opt, int value);
void set_script_env(struct openconnect_info *vpninfo);
int script_config_tun(struct openconnect_info *vpninfo, const char *reason);
/* tun.c */
int tun_mainloop(struct openconnect_info *vpninfo, int *timeout);
void shutdown_tun(struct openconnect_info *vpninfo);
int script_config_tun(struct openconnect_info *vpninfo, const char *reason);
/* dtls.c */
unsigned char unhex(const char *data);
......
......@@ -304,3 +304,45 @@ void set_script_env(struct openconnect_info *vpninfo)
setenv_cstp_opts(vpninfo);
}
int script_config_tun(struct openconnect_info *vpninfo, const char *reason)
{
int ret;
if (!vpninfo->vpnc_script || vpninfo->script_tun)
return 0;
setenv("reason", reason, 1);
ret = system(vpninfo->vpnc_script);
if (ret == -1) {
int e = errno;
vpn_progress(vpninfo, PRG_ERR,
_("Failed to spawn script '%s' for %s: %s\n"),
vpninfo->vpnc_script, reason, strerror(e));
return -e;
}
#ifdef _WIN32
if (ret == 0x2331) {
/* This is what cmd.exe returns for unrecognised commands */
vpn_progress(vpninfo, PRG_ERR,
_("Failed to spawn script '%s' for %s: %s\n"),
vpninfo->vpnc_script, reason, strerror(ENOENT));
return -ENOENT;
}
#else
if (!WIFEXITED(ret)) {
vpn_progress(vpninfo, PRG_ERR,
_("Script '%s' exited abnormally (%x)\n"),
vpninfo->vpnc_script, ret);
return -EIO;
}
ret = WEXITSTATUS(ret);
#endif
if (ret) {
vpn_progress(vpninfo, PRG_ERR,
_("Script '%s' returned error %d\n"),
vpninfo->vpnc_script, ret);
return -EIO;
}
return 0;
}
......@@ -91,48 +91,6 @@ static int set_tun_mtu(struct openconnect_info *vpninfo)
#endif
return 0;
}
int script_config_tun(struct openconnect_info *vpninfo, const char *reason)
{
int ret;
if (!vpninfo->vpnc_script || vpninfo->script_tun)
return 0;
setenv("reason", reason, 1);
ret = system(vpninfo->vpnc_script);
if (ret == -1) {
int e = errno;
vpn_progress(vpninfo, PRG_ERR,
_("Failed to spawn script '%s' for %s: %s\n"),
vpninfo->vpnc_script, reason, strerror(e));
return -e;
}
#ifdef _WIN32
if (ret == 0x2331) {
/* This is what cmd.exe returns for unrecognised commands */
vpn_progress(vpninfo, PRG_ERR,
_("Failed to spawn script '%s' for %s: %s\n"),
vpninfo->vpnc_script, reason, strerror(ENOENT));
return -ENOENT;
}
#else
if (!WIFEXITED(ret)) {
vpn_progress(vpninfo, PRG_ERR,
_("Script '%s' exited abnormally (%x)\n"),
vpninfo->vpnc_script, ret);
return -EIO;
}
ret = WEXITSTATUS(ret);
#endif
if (ret) {
vpn_progress(vpninfo, PRG_ERR,
_("Script '%s' returned error %d\n"),
vpninfo->vpnc_script, ret);
return -EIO;
}
return 0;
}
#ifdef __sun__
static int link_proto(int unit_nr, const char *devname, uint64_t flags)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment