Commit 427f7a73 authored by Jondy Zhao's avatar Jondy Zhao

Add c files as openvpn scripts, so that we can use native

windows openvpn. Fix problem: openvpn process could not be
stop in normay way.
parent 7e7588d8
#include <stdio.h>
int main(int argc, char *argv[])
{
char *p;
int pd;
char buf[512];
int n;
char *s, *s1, *s2;
s = (char*)getenv("script_type");
if (s == NULL) {
fprintf(stderr, "no script_type\n");
return 1;
}
if (strcmp(s, "up") == 0)
return 0;
if (argc < 2) {
fprintf(stderr, "missing pipe\n");
return 1;
}
pd = strtol(argv[1], &p, 10);
if (! (*p == 0)) {
fprintf(stderr, "invalid pipe %s\n", argv[1]);
return 1;
}
/* %(script_type)s %(common_name)s %(OPENVPN_external_ip)s */
s1 = (char*)getenv("common_name");
s2 = (char*)getenv("OPENVPN_external_ip");
if ( (s1 == NULL) || (s2 == NULL)) {
fprintf(stderr, "missing common_name and OPENVPN_external_ip\n");
return 1;
}
n = snprintf(buf, 512, "%s %s %s\n", s, s1, s2);
if (n >= 512) {
fprintf(stderr, "buffer overflow\n");
return 1;
}
if (write(pd, buf, n) == -1) {
fprintf(stderr, "write pipe failed\n");
return 1;
}
return 0;
}
#include <stdio.h>
/*
if os.environ['script_type'] == 'client-connect':
# Send client its external ip address
with open(sys.argv[2], 'w') as f:
f.write('push "setenv-safe external_ip %s"\n'
% os.environ['trusted_ip'])
# Write into pipe connect/disconnect events
arg1 = sys.argv[1]
if arg1 != 'None':
os.write(int(arg1), '%(script_type)s %(common_name)s %(trusted_ip)s\n'
% os.environ)
*/
int main(int argc, char *argv[])
{
char *p;
int pd;
char buf[512];
int n;
char *s, *s1, *s2;
int fd;
s = (char*)getenv("script_type");
if (s == NULL) {
fprintf(stderr, "no script_type\n");
return 1;
}
s2 = (char*)getenv("trusted_ip");
if (s2 == NULL) {
fprintf(stderr, "no trusted_ip\n");
return 1;
}
if (strcmp(s, "client-connect") == 0) {
if (argc < 3) {
fprintf(stderr, "missing filename\n");
return 1;
}
n = snprintf(buf, 512, "push \"setenv-safe external_ip %s\"\n", s2);
if (n >= 512) {
fprintf(stderr, "buffer overflow\n");
return 1;
}
/* O_WRONLY == 1 */
fd = open(argv[2], 1);
if (fd == -1) {
fprintf(stderr, "open %s failed\n", argv[2]);
return 1;
}
if (write(fd, buf, n) == -1) {
fprintf(stderr, "write %s failed\n", argv[2]);
close(fd);
return 1;
}
close(fd);
}
if (argc < 2) {
fprintf(stderr, "missing pipe\n");
return 1;
}
if (strcmp(argv[1], "None") == 0)
return 0;
pd = strtol(argv[1], &p, 10);
if (! (*p == 0)) {
fprintf(stderr, "invalid pipe %s\n", argv[1]);
return 1;
}
/* %(script_type)s %(common_name)s %(OPENVPN_external_ip)s */
s1 = (char*)getenv("common_name");
if (s1 == NULL) {
fprintf(stderr, "missing common_name\n");
return 1;
}
n = snprintf(buf, 512, "%s %s %s\n", s, s1, s2);
if (n >= 512) {
fprintf(stderr, "buffer overflow\n");
return 1;
}
if (write(pd, buf, n) == -1) {
fprintf(stderr, "write pipe failed\n");
return 1;
}
return 0;
}
......@@ -2,8 +2,9 @@ import logging, errno, os, sys
from . import utils
here = os.path.realpath(os.path.dirname(__file__))
ovpn_server = os.path.join(here, 'ovpn-server')
ovpn_client = os.path.join(here, 'ovpn-client')
script_ext = '.exe' if sys.platform == 'cygwin' else ''
ovpn_server = os.path.join(here, 'ovpn-server' + script_ext)
ovpn_client = os.path.join(here, 'ovpn-client' + script_ext)
ovpn_log = None
def openvpn(iface, encrypt, *args, **kw):
......
......@@ -359,7 +359,7 @@ def main():
exit(1)
t = threading.Thread(target=check_no_default_route)
t.daemon = True
# t.start()
t.start()
if not sys.platform == 'cygwin':
ip('route', 'unreachable', *x)
......
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