Skip to content

Commit 284ebd2

Browse files
committed
Merge branch 'pull/29'
* Merging pull request apenwarr#29.
2 parents d34b64d + 1b6165d commit 284ebd2

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

client.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ def original_dst(sock):
9696

9797

9898
class FirewallClient:
99+
<<<<<<< HEAD
99100
def __init__(self, port, subnets_include, subnets_exclude, dnsport, dns_hosts):
101+
=======
102+
def __init__(self, port, subnets_include, subnets_exclude, dnsport, route_username, excludedports):
103+
>>>>>>> pull/29
100104
self.port = port
101105
self.auto_nets = []
102106
self.subnets_include = subnets_include
@@ -105,7 +109,9 @@ def __init__(self, port, subnets_include, subnets_exclude, dnsport, dns_hosts):
105109
self.dns_hosts = dns_hosts
106110
argvbase = ([sys.argv[1], sys.argv[0], sys.argv[1]] +
107111
['-v'] * (helpers.verbose or 0) +
108-
['--firewall', str(port), str(dnsport)])
112+
['--firewall', str(port), str(dnsport),
113+
'--username', route_username or '',
114+
'--eports', excludedports or ''])
109115
if ssyslog._p:
110116
argvbase += ['--syslog']
111117
if dnsport:
@@ -343,7 +349,7 @@ def onhostlist(hostlist):
343349
def main(listenip, ssh_cmd, remotename, python, latency_control,
344350
dns, dns_hosts,
345351
seed_hosts, auto_nets,
346-
subnets_include, subnets_exclude, syslog, daemon, pidfile):
352+
subnets_include, subnets_exclude, syslog, daemon, pidfile, route_username, excludedports):
347353
if syslog:
348354
ssyslog.start_syslog()
349355
if daemon:
@@ -393,7 +399,11 @@ def main(listenip, ssh_cmd, remotename, python, latency_control,
393399
dnslistener = None
394400
dns_hosts = []
395401

402+
<<<<<<< HEAD
396403
fw = FirewallClient(listenip[1], subnets_include, subnets_exclude, dnsport, dns_hosts)
404+
=======
405+
fw = FirewallClient(listenip[1], subnets_include, subnets_exclude, dnsport, route_username, excludedports)
406+
>>>>>>> pull/29
397407

398408
try:
399409
return _main(listener, fw, ssh_cmd, remotename,

firewall.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,34 @@ def ipt_ttl(*args):
7070
# multiple copies shouldn't have overlapping subnets, or only the most-
7171
# recently-started one will win (because we use "-I OUTPUT 1" instead of
7272
# "-A OUTPUT").
73+
<<<<<<< HEAD
7374
def do_iptables(port, dnsport, nslist, subnets):
75+
=======
76+
def do_iptables(port, dnsport, route_username, excludedports, subnets):
77+
>>>>>>> pull/29
7478
chain = 'sshuttle-%s' % port
7579

80+
eportsargv = []
81+
if excludedports:
82+
eportsargv += ['--match', 'multiport', '!', '--dport', excludedports]
83+
7684
# basic cleanup/setup of chains
7785
if ipt_chain_exists(chain):
78-
nonfatal(ipt, '-D', 'OUTPUT', '-j', chain)
86+
if not route_username:
87+
nonfatal(ipt, '-D', 'OUTPUT', '-j', chain)
88+
else:
89+
nonfatal(ipt, '-m', 'owner', '--uid-owner', route_username, '-D', 'OUTPUT', '-j', chain)
7990
nonfatal(ipt, '-D', 'PREROUTING', '-j', chain)
8091
nonfatal(ipt, '-F', chain)
8192
ipt('-X', chain)
8293

8394
if subnets or dnsport:
8495
ipt('-N', chain)
8596
ipt('-F', chain)
86-
ipt('-I', 'OUTPUT', '1', '-j', chain)
97+
if not route_username:
98+
ipt('-I', 'OUTPUT', '1', '-j', chain)
99+
else:
100+
ipt('-m', 'owner', '--uid-owner', route_username, '-I', 'OUTPUT', '1', '-j', chain)
87101
ipt('-I', 'PREROUTING', '1', '-j', chain)
88102

89103
if subnets:
@@ -101,8 +115,9 @@ def do_iptables(port, dnsport, nslist, subnets):
101115
ipt_ttl('-A', chain, '-j', 'REDIRECT',
102116
'--dest', '%s/%s' % (snet,swidth),
103117
'-p', 'tcp',
104-
'--to-ports', str(port))
105-
118+
'--to-ports', str(port),
119+
*eportsargv)
120+
106121
if dnsport:
107122
for ip in nslist:
108123
ipt_ttl('-A', chain, '-j', 'REDIRECT',
@@ -254,7 +269,11 @@ def ipfw(*args):
254269
_call(argv)
255270

256271

272+
<<<<<<< HEAD
257273
def do_ipfw(port, dnsport, nslist, subnets):
274+
=======
275+
def do_ipfw(port, dnsport, route_username, excludedports, subnets):
276+
>>>>>>> pull/29
258277
sport = str(port)
259278
xsport = str(port+1)
260279

@@ -449,7 +468,11 @@ def ip_in_subnets(ip, subnets):
449468
# exit. In case that fails, it's not the end of the world; future runs will
450469
# supercede it in the transproxy list, at least, so the leftover rules
451470
# are hopefully harmless.
471+
<<<<<<< HEAD
452472
def main(port, dnsport, nslist, syslog):
473+
=======
474+
def main(port, dnsport, syslog, route_username, excludedports):
475+
>>>>>>> pull/29
453476
assert(port > 0)
454477
assert(port <= 65535)
455478
assert(dnsport >= 0)
@@ -514,7 +537,11 @@ def main(port, dnsport, nslist, syslog):
514537
try:
515538
if line:
516539
debug1('firewall manager: starting transproxy.\n')
540+
<<<<<<< HEAD
517541
do_wait = do_it(port, dnsport, nslist, subnets)
542+
=======
543+
do_wait = do_it(port, dnsport, route_username, excludedports, subnets)
544+
>>>>>>> pull/29
518545
sys.stdout.write('STARTED\n')
519546

520547
try:
@@ -544,5 +571,9 @@ def main(port, dnsport, nslist, syslog):
544571
debug1('firewall manager: undoing changes.\n')
545572
except:
546573
pass
574+
<<<<<<< HEAD
547575
do_it(port, 0, [], [])
576+
=======
577+
do_it(port, 0, route_username, excludedports, [])
578+
>>>>>>> pull/29
548579
restore_etc_hosts(port)

main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def parse_ipport(s):
6868
V,version print sshuttle's version number
6969
syslog send log messages to syslog (default if you use --daemon)
7070
pidfile= pidfile name (only if using --daemon) [./sshuttle.pid]
71+
u,username= route packets only from the specified username (required iptables with -m owner support)
72+
eports= Exclude this list of ports (separated by comma with no spaces)
7173
server (internal use only)
7274
firewall (internal use only)
7375
hostwatch (internal use only)
@@ -95,9 +97,13 @@ def parse_ipport(s):
9597
elif opt.firewall:
9698
if len(extra) != 2:
9799
o.fatal('exactly two arguments expected')
100+
<<<<<<< HEAD
98101
port, dnsport = int(extra[0]), int(extra[1])
99102
nslist = re.split(r'[\s,]+', opt.dns_hosts.strip()) if dnsport else []
100103
sys.exit(firewall.main(port, dnsport, nslist, opt.syslog))
104+
=======
105+
sys.exit(firewall.main(int(extra[0]), int(extra[1]), opt.syslog, opt.username, str(opt.eports)))
106+
>>>>>>> pull/29
101107
elif opt.hostwatch:
102108
sys.exit(hostwatch.hw_main(extra))
103109
else:
@@ -133,7 +139,7 @@ def parse_ipport(s):
133139
opt.auto_nets,
134140
parse_subnets(includes),
135141
parse_subnets(excludes),
136-
opt.syslog, opt.daemon, opt.pidfile))
142+
opt.syslog, opt.daemon, opt.pidfile, opt.username, str(opt.eports)))
137143
except FatalNeedsReboot, e:
138144
log('You must reboot before using sshuttle.\n')
139145
sys.exit(EXITCODE_NEEDS_REBOOT)

0 commit comments

Comments
 (0)