Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sshuttle
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pub
sshuttle
Commits
2ef3a301
Commit
2ef3a301
authored
Dec 05, 2010
by
Roger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
run in background (daemon) and option
parent
41fd0348
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
9 deletions
+58
-9
client.py
client.py
+46
-3
helpers.py
helpers.py
+8
-4
main.py
main.py
+4
-2
No files found.
client.py
View file @
2ef3a301
...
@@ -4,6 +4,7 @@ import helpers, ssnet, ssh
...
@@ -4,6 +4,7 @@ import helpers, ssnet, ssh
from
ssnet
import
SockWrapper
,
Handler
,
Proxy
,
Mux
,
MuxWrapper
from
ssnet
import
SockWrapper
,
Handler
,
Proxy
,
Mux
,
MuxWrapper
from
helpers
import
*
from
helpers
import
*
import
os
,
sys
,
atexit
,
signal
,
syslog
def
original_dst
(
sock
):
def
original_dst
(
sock
):
try
:
try
:
...
@@ -97,14 +98,40 @@ class FirewallClient:
...
@@ -97,14 +98,40 @@ class FirewallClient:
if
rv
:
if
rv
:
raise
Fatal
(
'cleanup:
%
r returned
%
d'
%
(
self
.
argv
,
rv
))
raise
Fatal
(
'cleanup:
%
r returned
%
d'
%
(
self
.
argv
,
rv
))
def
exit_cleanup
():
debug1
(
'exit cleanup
\n
'
)
os
.
unlink
(
'sshuttle.pid'
)
def
_main
(
listener
,
fw
,
ssh_cmd
,
remotename
,
python
,
seed_hosts
,
auto_nets
):
def
_main
(
listener
,
fw
,
ssh_cmd
,
remotename
,
python
,
seed_hosts
,
auto_nets
,
background
):
handlers
=
[]
handlers
=
[]
if
helpers
.
verbose
>=
1
:
if
helpers
.
verbose
>=
1
:
helpers
.
logprefix
=
'c : '
helpers
.
logprefix
=
'c : '
else
:
else
:
helpers
.
logprefix
=
'client: '
helpers
.
logprefix
=
'client: '
debug1
(
'connecting to server...
\n
'
)
debug1
(
'connecting to server...
\n
'
)
if
background
:
helpers
.
do_syslog
=
True
syslog
.
openlog
(
'sshuttle'
)
# we're redirecting the standard outputs here early so that
# the stderr debug message of ssh subprocess would be
# redirected properly
# TODO: redirecting stderr of ssh to syslog
sys
.
stdout
.
flush
()
sys
.
stderr
.
flush
()
si
=
file
(
'/dev/null'
,
'r'
)
so
=
file
(
'/dev/null'
,
'a+'
)
se
=
file
(
'/dev/null'
,
'a+'
,
0
)
os
.
dup2
(
si
.
fileno
(),
sys
.
stdin
.
fileno
())
os
.
dup2
(
so
.
fileno
(),
sys
.
stdout
.
fileno
())
os
.
dup2
(
se
.
fileno
(),
sys
.
stderr
.
fileno
())
si
.
close
()
so
.
close
()
se
.
close
()
try
:
try
:
(
serverproc
,
serversock
)
=
ssh
.
connect
(
ssh_cmd
,
remotename
,
python
)
(
serverproc
,
serversock
)
=
ssh
.
connect
(
ssh_cmd
,
remotename
,
python
)
except
socket
.
error
,
e
:
except
socket
.
error
,
e
:
...
@@ -126,6 +153,22 @@ def _main(listener, fw, ssh_cmd, remotename, python, seed_hosts, auto_nets):
...
@@ -126,6 +153,22 @@ def _main(listener, fw, ssh_cmd, remotename, python, seed_hosts, auto_nets):
raise
Fatal
(
'expected server init string
%
r; got
%
r'
raise
Fatal
(
'expected server init string
%
r; got
%
r'
%
(
expected
,
initstring
))
%
(
expected
,
initstring
))
debug1
(
'connected.
\n
'
)
debug1
(
'connected.
\n
'
)
if
background
:
debug1
(
'daemonizing
\n
'
)
if
os
.
fork
():
os
.
_exit
(
0
)
os
.
setsid
()
if
os
.
fork
():
os
.
_exit
(
0
)
outfd
=
os
.
open
(
'sshuttle.pid'
,
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_EXCL
)
os
.
write
(
outfd
,
'
%
i'
%
os
.
getpid
())
os
.
close
(
outfd
)
atexit
.
register
(
exit_cleanup
)
# Normal exit when killed, or atexit won't work
signal
.
signal
(
signal
.
SIGTERM
,
lambda
signum
,
stack_frame
:
sys
.
exit
(
1
))
def
onroutes
(
routestr
):
def
onroutes
(
routestr
):
if
auto_nets
:
if
auto_nets
:
...
@@ -182,7 +225,7 @@ def _main(listener, fw, ssh_cmd, remotename, python, seed_hosts, auto_nets):
...
@@ -182,7 +225,7 @@ def _main(listener, fw, ssh_cmd, remotename, python, seed_hosts, auto_nets):
def
main
(
listenip
,
ssh_cmd
,
remotename
,
python
,
seed_hosts
,
auto_nets
,
def
main
(
listenip
,
ssh_cmd
,
remotename
,
python
,
seed_hosts
,
auto_nets
,
subnets_include
,
subnets_exclude
):
subnets_include
,
subnets_exclude
,
background
):
debug1
(
'Starting sshuttle proxy.
\n
'
)
debug1
(
'Starting sshuttle proxy.
\n
'
)
listener
=
socket
.
socket
()
listener
=
socket
.
socket
()
listener
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
listener
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
...
@@ -213,6 +256,6 @@ def main(listenip, ssh_cmd, remotename, python, seed_hosts, auto_nets,
...
@@ -213,6 +256,6 @@ def main(listenip, ssh_cmd, remotename, python, seed_hosts, auto_nets,
try
:
try
:
return
_main
(
listener
,
fw
,
ssh_cmd
,
remotename
,
return
_main
(
listener
,
fw
,
ssh_cmd
,
remotename
,
python
,
seed_hosts
,
auto_nets
)
python
,
seed_hosts
,
auto_nets
,
background
)
finally
:
finally
:
fw
.
done
()
fw
.
done
()
helpers.py
View file @
2ef3a301
import
sys
,
os
import
sys
,
os
,
syslog
logprefix
=
''
logprefix
=
''
verbose
=
0
verbose
=
0
do_syslog
=
False
def
log
(
s
):
def
log
(
s
):
try
:
try
:
if
do_syslog
:
syslog
.
syslog
(
logprefix
+
s
)
else
:
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
sys
.
stderr
.
write
(
logprefix
+
s
)
sys
.
stderr
.
write
(
logprefix
+
s
)
sys
.
stderr
.
flush
()
sys
.
stderr
.
flush
()
...
...
main.py
View file @
2ef3a301
...
@@ -45,10 +45,11 @@ def parse_ipport(s):
...
@@ -45,10 +45,11 @@ def parse_ipport(s):
optspec
=
"""
optspec
=
"""
sshuttle [-l [ip:]port] [-r [username@]sshserver[:port]] <subnets...>
sshuttle [-
b] [-
l [ip:]port] [-r [username@]sshserver[:port]] <subnets...>
sshuttle --firewall <port> <subnets...>
sshuttle --firewall <port> <subnets...>
sshuttle --server
sshuttle --server
--
--
b,background run in background as daemon
l,listen= transproxy to this ip address and port number [0.0.0.0:0]
l,listen= transproxy to this ip address and port number [0.0.0.0:0]
H,auto-hosts scan for remote hostnames and update local /etc/hosts
H,auto-hosts scan for remote hostnames and update local /etc/hosts
N,auto-nets automatically determine subnets to route
N,auto-nets automatically determine subnets to route
...
@@ -104,7 +105,8 @@ try:
...
@@ -104,7 +105,8 @@ try:
sh
,
sh
,
opt
.
auto_nets
,
opt
.
auto_nets
,
parse_subnets
(
includes
),
parse_subnets
(
includes
),
parse_subnets
(
excludes
)))
parse_subnets
(
excludes
),
opt
.
background
))
except
Fatal
,
e
:
except
Fatal
,
e
:
log
(
'fatal:
%
s
\n
'
%
e
)
log
(
'fatal:
%
s
\n
'
%
e
)
sys
.
exit
(
99
)
sys
.
exit
(
99
)
...
...
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