Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Joanne Hugé
re6stnet
Commits
891a9ca2
Commit
891a9ca2
authored
Sep 01, 2013
by
Jondy Zhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use DuplicateHandle to fix writing pipe problem
parent
c52ee536
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
31 deletions
+63
-31
re6st/ovpn-client.c
re6st/ovpn-client.c
+15
-9
re6st/ovpn-pipe.c
re6st/ovpn-pipe.c
+23
-0
re6st/ovpn-server.c
re6st/ovpn-server.c
+14
-20
re6st/plib.py
re6st/plib.py
+1
-1
re6st/tunnel.py
re6st/tunnel.py
+1
-1
re6st/utils.py
re6st/utils.py
+9
-0
No files found.
re6st/ovpn-client.c
View file @
891a9ca2
#include <windows.h>
#include <stdio.h>
HANDLE
open_pipe
(
const
char
*
pname
);
int
main
(
int
argc
,
char
*
argv
[])
{
int
pd
;
HANDLE
pd
;
DWORD
m
;
char
buf
[
512
];
int
n
;
char
*
s
,
*
s1
,
*
s2
;
...
...
@@ -21,12 +25,6 @@ int main(int argc, char *argv[])
return
1
;
}
pd
=
open
(
argv
[
1
],
1
);
if
(
pd
==
-
1
)
{
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"
);
...
...
@@ -42,10 +40,18 @@ int main(int argc, char *argv[])
return
1
;
}
if
(
write
(
pd
,
buf
,
n
)
==
-
1
)
{
pd
=
open_pipe
(
argv
[
1
]);
if
(
pd
==
NULL
)
{
fprintf
(
stderr
,
"invalid pipe %s
\n
"
,
argv
[
1
]);
return
1
;
}
if
(
!
WriteFile
(
pd
,
buf
,
n
,
&
m
,
NULL
))
{
fprintf
(
stderr
,
"write pipe failed
\n
"
);
CloseHandle
(
pd
);
return
1
;
}
CloseHandle
(
pd
);
return
0
;
}
re6st/ovpn-pipe.c
0 → 100644
View file @
891a9ca2
#include <windows.h>
extern
sscanf
(
const
char
*
,
const
char
*
,
...);
HANDLE
open_pipe
(
const
char
*
pname
)
{
HANDLE
proc
,
pipe_hdl
,
nio_hdl
=
NULL
;
int
pid
,
rwflags
=
1
;
/* O_WRONLY */
sscanf
(
pname
,
"/proc/%d/fd/pipe:[%d]"
,
&
pid
,
(
int
*
)
&
pipe_hdl
);
if
(
!
(
proc
=
OpenProcess
(
PROCESS_DUP_HANDLE
,
FALSE
,
pid
)))
{
return
NULL
;
}
if
(
!
DuplicateHandle
(
proc
,
pipe_hdl
,
GetCurrentProcess
(),
&
nio_hdl
,
0
,
FALSE
,
DUPLICATE_SAME_ACCESS
))
{
return
NULL
;
}
CloseHandle
(
proc
);
return
nio_hdl
;
}
re6st/ovpn-server.c
View file @
891a9ca2
#include <windows.h>
#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)
*/
HANDLE
open_pipe
(
const
char
*
pname
);
int
main
(
int
argc
,
char
*
argv
[])
{
int
pd
;
HANDLE
pd
;
DWORD
m
;
char
buf
[
512
];
int
n
;
char
*
s
,
*
s1
,
*
s2
;
...
...
@@ -66,12 +58,6 @@ int main(int argc, char *argv[])
if
(
strcmp
(
argv
[
1
],
"None"
)
==
0
)
return
0
;
pd
=
open
(
argv
[
1
],
1
);
if
(
pd
==
-
1
)
{
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
)
{
...
...
@@ -85,10 +71,18 @@ int main(int argc, char *argv[])
return
1
;
}
if
(
write
(
pd
,
buf
,
n
)
==
-
1
)
{
pd
=
open_pipe
(
argv
[
1
]);
if
(
pd
==
NULL
)
{
fprintf
(
stderr
,
"invalid pipe %s
\n
"
,
argv
[
1
]);
return
1
;
}
if
(
!
WriteFile
(
pd
,
buf
,
n
,
&
m
,
NULL
))
{
fprintf
(
stderr
,
"write pipe failed
\n
"
);
CloseHandle
(
pd
);
return
1
;
}
CloseHandle
(
pd
);
return
0
;
}
re6st/plib.py
View file @
891a9ca2
...
...
@@ -31,7 +31,7 @@ def openvpn(iface, encrypt, *args, **kw):
def
server
(
iface
,
max_clients
,
dh_path
,
pipe_fd
,
port
,
proto
,
encrypt
,
*
args
,
**
kw
):
client_script
=
'%s
/proc/%u/fd/%s'
%
(
ovpn_server
,
os
.
getpid
(),
pipe_fd
)
client_script
=
'%s
%s'
%
(
ovpn_server
,
utils
.
get_pipename
(
pipe_fd
)
)
if
pipe_fd
is
not
None
:
args
=
(
'--client-disconnect'
,
client_script
)
+
args
return
openvpn
(
iface
,
encrypt
,
...
...
re6st/tunnel.py
View file @
891a9ca2
...
...
@@ -65,7 +65,7 @@ class Connection(object):
'--resolv-retry'
,
'0'
,
'--connect-retry-max'
,
'3'
,
'--tls-exit'
,
'--ping-exit'
,
str
(
timeout
),
'--route-up'
,
'%s
/proc/%u/fd/%u'
%
(
plib
.
ovpn_client
,
os
.
getpid
(),
write_pipe
),
'--route-up'
,
'%s
%s'
%
(
plib
.
ovpn_client
,
utils
.
get_pipename
(
write_pipe
)
),
*
ovpn_args
)
_retry
+=
1
self
.
_retry
=
_retry
<
len
(
self
.
address_list
)
and
(
...
...
re6st/utils.py
View file @
891a9ca2
...
...
@@ -178,3 +178,12 @@ def encrypt(cert, data):
if
p
.
returncode
:
raise
subprocess
.
CalledProcessError
(
p
.
returncode
,
'openssl'
,
err
)
return
out
def
get_pipename
(
pipe_id
):
if
pipe_id
is
not
None
:
path
=
'/proc/%u'
%
os
.
getpid
()
with
open
(
os
.
path
.
join
(
path
,
'winpid'
),
'r'
)
as
f
:
winpid
=
f
.
readline
()
r
=
os
.
path
.
realpath
(
'%s/fd/%s'
%
(
path
,
pipe_id
)).
split
(
'/'
)
r
[
1
]
=
winpid
return
'/'
.
join
(
r
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment