Squashed 'OpenVPN Adapter/Vendors/openvpn/' content from commit da99df6

git-subtree-dir: OpenVPN Adapter/Vendors/openvpn
git-subtree-split: da99df69492256d7a18bbea303ae98457782a4bf
This commit is contained in:
Sergey Abramchuk
2017-04-09 14:13:07 +03:00
commit f65d76170b
519 changed files with 88163 additions and 0 deletions

5
win/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
*.pyc
cli.exe
cli.obj
*.pdb
.vs

75
win/build.py Normal file
View File

@@ -0,0 +1,75 @@
#!/c/python27/python
import os
from utils import *
def cli_cpp(parms):
return os.path.join(parms['OVPN3'], "core", "test", "ovpncli", "cli.cpp")
def src_fn(parms, srcfile):
# Get source file name
if srcfile:
if '.' not in os.path.basename(srcfile):
srcfile += ".cpp"
else:
srcfile = cli_cpp(parms)
return srcfile
def src_fn_argv(parms, argv):
srcfile = None
if len(argv) >= 1:
srcfile = argv[0]
return src_fn(parms, srcfile)
def build(parms, srcfile):
# Debug?
if parms['DEBUG']:
dbg_rel_flags = "/Zi"
else:
dbg_rel_flags = "/O2"
# Dictionary we will use to substitute parameters
# onto VC command line.
options = {
"ovpn3" : parms['OVPN3'],
"tap" : os.path.join(parms['TAP'], 'src'),
"tap_component_id" : parms['TAP_WIN_COMPONENT_ID'],
"asio" : os.path.join(build_dir(parms), "asio"),
"mbedtls" : os.path.join(build_dir(parms), "mbedtls"),
"lz4" : os.path.join(build_dir(parms), "lz4", "lib"),
"srcfile" : srcfile,
"extra_defs" : parms['CPP_EXTRA'],
"extra_inc" : "",
"extra_lib_path" : "",
"extra_lib" : "",
}
vc_parms(parms, options)
# Do we need to support XP and Win 2003?
arch = os.environ.get("ARCH", parms['ARCH'])
if arch == "x86_xp":
options['extra_defs'] += " /D_WIN32_WINNT=0x0501" # pre-Vista
else:
options['extra_defs'] += " /D_WIN32_WINNT=0x0600" # Vista and later
options['extra_lib'] += " fwpuclnt.lib"
# Add jsoncpp (optional)
if 'jsoncpp' in parms['LIB_VERSIONS']:
options["jsoncpp"] = os.path.join(build_dir(parms), "jsoncpp")
options['extra_inc'] += " /DHAVE_JSONCPP /I %(jsoncpp)s/dist" % options
options['extra_lib_path'] += " /LIBPATH:%(jsoncpp)s/dist" % options
options['extra_lib'] += " jsoncpp.lib"
# Build OpenVPN Connect
if parms.get("CONNECT"):
options['extra_inc'] += " /I " + os.path.join(parms['OVPN3'], "common")
# build it
vc_cmd(parms, r"cl %(extra_defs)s /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /DUSE_ASIO /DASIO_STANDALONE /DASIO_NO_DEPRECATED /I %(asio)s\asio\include /DUSE_MBEDTLS /I %(mbedtls)s\include /DHAVE_LZ4 /I %(lz4)s%(extra_inc)s -DTAP_WIN_COMPONENT_ID=%(tap_component_id)s /I %(tap)s /I %(ovpn3)s\core /GL /EHsc %(link_static_dynamic_flags)s /W0 %(dbg_rel_flags)s /nologo %(srcfile)s /link /LIBPATH:%(mbedtls)s\library /LIBPATH:%(lz4)s%(extra_lib_path)s mbedtls.lib lz4.lib%(extra_lib)s ws2_32.lib crypt32.lib iphlpapi.lib winmm.lib user32.lib gdi32.lib advapi32.lib wininet.lib shell32.lib ole32.lib rpcrt4.lib" % options, arch=os.environ.get("ARCH"))
if __name__ == "__main__":
import sys
from parms import PARMS
build(PARMS, src_fn_argv(PARMS, sys.argv[1:]))

92
win/buildep.py Normal file
View File

@@ -0,0 +1,92 @@
import os, re
from utils import *
def compile_one_file(parms, srcfile, incdirs):
extra = {
"srcfile" : srcfile,
"incdirs" : ' '.join([r"/I %s" % (x,) for x in incdirs]),
}
vc_parms(parms, extra)
vc_cmd(parms, r"cl /c /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS %(incdirs)s /EHsc %(link_static_dynamic_flags)s /W3 %(dbg_rel_flags)s /nologo %(srcfile)s" % extra, arch=os.environ.get("ARCH"))
def build_asio(parms):
print "**************** ASIO"
with Cd(build_dir(parms)) as cd:
with ModEnv('PATH', "%s\\bin;%s" % (parms.get('GIT'), os.environ['PATH'])):
dist = os.path.realpath('asio')
rmtree(dist)
d = expand('asio', parms['DEP'], parms.get('LIB_VERSIONS'))
os.rename(d, dist)
def build_mbedtls(parms):
print "**************** MBEDTLS"
with Cd(build_dir(parms)) as cd:
with ModEnv('PATH', "%s\\bin;%s" % (parms.get('GIT'), os.environ['PATH'])):
dist = os.path.realpath('mbedtls')
rmtree(dist)
d = expand('mbedtls', parms['DEP'], parms.get('LIB_VERSIONS'))
if d.endswith("-apache"):
d = d[:-7]
os.rename(d, dist)
# edit mbedTLS config.h
conf_fn = os.path.join(dist, 'include', 'mbedtls', 'config.h')
with open(conf_fn) as f:
conf = f.read()
conf = re.sub(r"^//(?=#define MBEDTLS_MD4_C)", "", conf, flags=re.M);
with open(conf_fn, 'w') as f:
f.write(conf)
# compile the source files
os.chdir(os.path.join(dist, "library"))
obj = []
for dirpath, dirnames, filenames in os.walk("."):
for f in filenames:
if f.endswith(".c"):
compile_one_file(parms, f, (r"..\include",))
obj.append(f[:-2]+".obj")
break
# collect object files into mbedtls.lib
vc_cmd(parms, r"lib /OUT:mbedtls.lib " + ' '.join(obj))
def build_lz4(parms):
print "**************** LZ4"
with Cd(build_dir(parms)) as cd:
with ModEnv('PATH', "%s\\bin;%s" % (parms.get('GIT'), os.environ['PATH'])):
dist = os.path.realpath('lz4')
rmtree(dist)
d = expand('lz4', parms['DEP'], parms.get('LIB_VERSIONS'))
os.rename(d, dist)
os.chdir(os.path.join(dist, "lib"))
compile_one_file(parms, "lz4.c", ())
vc_cmd(parms, r"lib /OUT:lz4.lib lz4.obj")
def build_jsoncpp(parms):
if 'jsoncpp' in parms['LIB_VERSIONS']:
print "**************** JSONCPP"
with Cd(build_dir(parms)) as cd:
with ModEnv('PATH', "%s\\bin;%s" % (parms.get('GIT'), os.environ['PATH'])):
dist = os.path.realpath('jsoncpp')
rmtree(dist)
d = expand('jsoncpp', parms['DEP'], parms.get('LIB_VERSIONS'))
os.rename(d, dist)
os.chdir(dist)
call(["python", "amalgamate.py"])
os.chdir(os.path.join(dist, "dist"))
compile_one_file(parms, "jsoncpp.cpp", (".",))
vc_cmd(parms, r"lib /OUT:jsoncpp.lib jsoncpp.obj")
def build_all(parms):
wipetree(build_dir(parms))
build_asio(parms)
build_mbedtls(parms)
build_lz4(parms)
build_jsoncpp(parms)
if __name__ == "__main__":
from parms import PARMS
build_all(PARMS)

19
win/parms.py Normal file
View File

@@ -0,0 +1,19 @@
PARMS = {
"DEBUG" : False,
"STATIC" : True,
"OVPN3" : "c:\\src\\ovpn3",
"TAP" : "c:\\src\\tap-windows6",
"TAP_WIN_COMPONENT_ID" : "tap0901", # Community: tap0901, Access Server: tapoas
"DEP" : "z:\\james\\downloads",
"BUILD" : "c:\\src\\ovpn3-build",
"PATCH" : "c:\\src\\as\\pyovpn\\patch",
"GIT" : "c:\\Program Files (x86)\\Git",
"CPP_EXTRA" : "",
"MSVC_DIR" : "c:\\Program Files (x86)\\Microsoft Visual Studio 14.0",
"ARCH" : "amd64", # one of amd64, x86, or x86_xp (note that x86_xp requires vcvarsall.bat patch)
"LIB_VERSIONS" : {
'asio' : "asio-20170227",
'mbedtls' : "mbedtls-2.4.0",
'lz4' : "lz4-1.7.5",
}
}

59
win/unused/buildep.py Normal file
View File

@@ -0,0 +1,59 @@
import os, re
from utils import *
from parms import PARMS
def build_openssl(parms):
print "**************** OpenSSL"
with Cd(parms['BUILD']) as cd:
with ModEnv('PATH', "%s;%s\\bin;%s" % (parms.get('NASM'), parms.get('GIT'), os.environ['PATH'])):
dist = os.path.realpath('openssl')
rmtree(dist)
d = expand('openssl', parms['DEP'], parms.get('LIB_VERSIONS'))
os.chdir(d)
patch("ossl-win", parms['PATCH'])
makedirs(dist)
# needs more work for x64, see:
# http://stackoverflow.com/questions/158232/how-do-you-compile-openssl-for-x64
targets = {
'x86' : "VC-WIN32",
'amd64' : "VC-WIN64A",
}
call(['perl', 'Configure', targets[parms['ARCH']], 'no-idea', 'no-mdc2', 'no-rc5', '--prefix=%s' % (dist,)])
archscripts = {
'x86' : "ms\\do_nasm",
'amd64' : "ms\\do_win64a",
}
vc_cmd(parms, archscripts[parms['ARCH']])
vc_cmd(parms, "nmake -f ms\\ntdll.mak")
vc_cmd(parms, "nmake -f ms\\ntdll.mak install")
# copy DLLs to PARMS['DIST']
cp(os.path.join(dist, "bin", "libeay32.dll"), PARMS['DIST'])
cp(os.path.join(dist, "bin", "ssleay32.dll"), PARMS['DIST'])
def build_boost(parms):
print "**************** Boost"
with Cd(parms['BUILD']) as cd:
d = expand('boost', parms['DEP'], parms.get('LIB_VERSIONS'))
os.chdir(d)
archopts = {
'x86' : "",
'amd64' : "architecture=x86 address-model=64",
}
vc_cmd(parms, "bootstrap", arch="x86")
vc_cmd(parms, "b2 --toolset=msvc-12.0 --with-system --with-thread --with-atomic --with-date_time --with-regex link=shared threading=multi runtime-link=shared %s stage" % (archopts[parms['ARCH']],))
# copy DLLs to PARMS['DIST']
r = re.compile(r"boost_(atomic|chrono|system|thread)-vc\d+-mt-[\d_]+\.dll")
os.chdir(os.path.join("stage", "lib"))
for dirpath, dirnames, filenames in os.walk('.'):
for f in filenames:
if re.match(r, f):
cp(f, PARMS['DIST'])
break
wipetree(PARMS['BUILD'])
wipetree(PARMS['DIST'])
build_openssl(PARMS)
build_boost(PARMS)

233
win/utils.py Normal file
View File

@@ -0,0 +1,233 @@
import os, sys, re, stat, shutil, tarfile, subprocess
j = os.path.join
class Cd(object):
"""
Cd is a context manager that allows
you to temporary change the working directory.
with Cd(dir) as cd:
...
"""
def __init__(self, directory):
self._dir = directory
def orig(self):
return self._orig
def __enter__(self):
self._orig = os.getcwd()
os.chdir(self._dir)
return self
def __exit__(self, *args):
os.chdir(self._orig)
class ModEnv(object):
"""
Context manager for temporarily
modifying an env var. Normally used to make
changes to PATH.
"""
def __init__(self, key, value):
self.key = key;
self.value = value;
def __enter__(self):
self.orig_value = os.environ.get(self.key)
os.environ[self.key] = self.value
return self
def __exit__(self, *args):
if self.orig_value is not None:
os.environ[self.key] = self.orig_value
def rmtree(dir):
print "RMTREE", dir
shutil.rmtree(dir, ignore_errors=True)
def rm(fn, silent=False):
if os.path.exists(fn):
if not silent:
print "RM", fn
os.remove(fn)
def makedirs(dir):
print "MAKEDIRS", dir
os.makedirs(dir)
def cp(src, dest):
print "COPY %s %s" % (src, dest)
shutil.copy2(src, dest)
def wipetree(dir, wipe=True):
def onerror(func, path, exc_info):
"""
Error handler for ``shutil.rmtree``.
If the error is due to an access error (read only file)
it attempts to add write permission and then retries.
If the error is for another reason it ignores.
Usage : ``shutil.rmtree(path, onerror=onerror)``
"""
if not os.access(path, os.W_OK):
# Is the error an access error ?
try:
os.chmod(path, stat.S_IWUSR)
func(path)
except:
pass
if wipe:
print "WIPETREE", dir
shutil.rmtree(dir, ignore_errors=False, onerror=onerror)
if not os.path.isdir(dir):
makedirs(dir)
def extract_dict(d, k, default=None):
if k in d:
v = d[k]
del d[k]
else:
v = default
return v
def scan_prefixes(prefix, dir, filt=None):
fns = []
for dirpath, dirnames, filenames in os.walk(dir):
for f in filenames:
if f.startswith(prefix) and (filt is None or filt(f)):
fns.append(f)
break
return fns
def one_prefix(prefix, dir, filt=None):
f = scan_prefixes(prefix, dir, filt)
if len(f) == 0:
raise ValueError("prefix %r not found in dir %r" % (prefix, dir))
elif len(f) >= 2:
raise ValueError("prefix %r is ambiguous in dir %r: %r" % (prefix, dir, f))
return f[0]
def tarsplit(fn):
if fn.endswith(".tar.gz"):
t = 'gz'
b = fn[:-7]
elif fn.endswith(".tgz"):
t = 'gz'
b = fn[:-4]
elif fn.endswith(".tar.bz2"):
t = 'bz2'
b = fn[:-8]
elif fn.endswith(".tbz"):
t = 'bz2'
b = fn[:-4]
elif fn.endswith(".tar.xz"):
t = 'xz'
b = fn[:-7]
else:
raise ValueError("unrecognized tar file type: %r" % (fn,))
return b, t
def tarsplit_filt(fn):
try:
tarsplit(fn)
except:
return False
else:
return True
def tarextract(fn, t):
print "TAR EXTRACT %s [%s]" % (fn, t)
tar = tarfile.open(fn, mode='r:'+t)
try:
tar.extractall()
finally:
tar.close()
def expand(pkg_prefix, srcdir, lib_versions=None, noop=False):
if lib_versions and pkg_prefix in lib_versions:
f = one_prefix(lib_versions[pkg_prefix], srcdir, tarsplit_filt)
else:
f = one_prefix(pkg_prefix, srcdir, tarsplit_filt)
b, t = tarsplit(f)
if not noop:
# remove previous directory
rmtree(os.path.realpath(b))
# expand it
tarextract(os.path.join(srcdir, f), t)
return b
def call(cmd, **kw):
print "***", cmd
ignore_errors = extract_dict(kw, 'ignore_errors', False)
extra_env = extract_dict(kw, 'extra_env', None)
if extra_env:
env = kw.get('env', os.environ).copy()
env.update(extra_env)
kw['env'] = env
succeed = extract_dict(kw, 'succeed', 0)
# show environment
se = kw.get('env')
if se:
show_env(se)
print "***"
ret = subprocess.call(cmd, **kw)
if not ignore_errors and ret != succeed:
raise ValueError("command failed with status %r (expected %r)" % (ret, succeed))
def vc_cmd(parms, cmd, arch=None, succeed=0):
# arch should be one of amd64 (alias x64), x86, x86_xp, or None
# (if None, use parms.py value)
if arch is None:
arch = parms['ARCH']
if arch == "x64":
arch = "amd64"
with ModEnv('PATH', "%s;%s\\VC" % (os.environ['PATH'], parms['MSVC_DIR'])):
status = call('vcvarsall.bat %s && %s' % (arch, cmd), shell=True, succeed=succeed)
def vc_parms(parms, cmd_dict):
cmd_dict["dbg_rel_flags"] = "/Zi" if parms['DEBUG'] else "/O2"
cmd_dict["link_static_dynamic_flags"] = "/MT" if parms['STATIC'] else "/MD"
def patchfile(pkg_prefix, patchdir):
return os.path.join(patchdir, one_prefix(pkg_prefix, patchdir))
def patch(pkg_prefix, patchdir):
patch_fn = patchfile(pkg_prefix, patchdir)
print "PATCH", patch_fn
call(['patch', '-p1', '-i', patch_fn])
def build_dir(parms):
return os.path.join(parms['BUILD'], parms['ARCH'])
# remove .obj files
def rm_obj(dir):
fns = []
for dirpath, dirnames, filenames in os.walk(dir):
for f in filenames:
path = os.path.join(dirpath, f)
if f.endswith(".obj"):
rm(path)
# zip a directory
# sample usage:
# zipf = zipfile.ZipFile('Python.zip', 'w')
# zipdir('tmp/', zipf)
# zipf.close()
def zipdir(path, ziph):
# ziph is zipfile handle
for root, dirs, files in os.walk(path):
for file in files:
ziph.write(os.path.join(root, file))

27
win/vcvarsall.patch Normal file
View File

@@ -0,0 +1,27 @@
--- vcvarsall.bat.orig Mon Apr 4 02:58:07 2016
+++ vcvarsall.bat Mon Apr 4 15:55:42 2016
@@ -20,6 +20,7 @@
:check_platform
if /i %1 == x86 goto x86
+if /i %1 == x86_xp goto x86_xp
if /i %1 == amd64 goto amd64
if /i %1 == x64 goto amd64
if /i %1 == arm goto arm
@@ -32,6 +33,16 @@
:x86
if not exist "%~dp0bin\vcvars32.bat" goto missing
call "%~dp0bin\vcvars32.bat" %2 %3
+goto :SetVisualStudioVersion
+
+:x86_xp
+if not exist "%~dp0bin\vcvars32.bat" goto missing
+call "%~dp0bin\vcvars32.bat" %2 %3
+set INCLUDE=%ProgramFiles(x86)%\Microsoft SDKs\Windows\7.1A\Include;%INCLUDE%
+set PATH=%ProgramFiles(x86)%\Microsoft SDKs\Windows\7.1A\Bin;%PATH%
+set LIB=%ProgramFiles(x86)%\Microsoft SDKs\Windows\7.1A\Lib;%LIB%
+set CL=/D_USING_V110_SDK71_;%CL%