@@ -70,20 +70,34 @@ def ipt_ttl(*args):
70
70
# multiple copies shouldn't have overlapping subnets, or only the most-
71
71
# recently-started one will win (because we use "-I OUTPUT 1" instead of
72
72
# "-A OUTPUT").
73
+ < << << << HEAD
73
74
def do_iptables (port , dnsport , nslist , subnets ):
75
+ == == == =
76
+ def do_iptables (port , dnsport , route_username , excludedports , subnets ):
77
+ > >> >> >> pull / 29
74
78
chain = 'sshuttle-%s' % port
75
79
80
+ eportsargv = []
81
+ if excludedports :
82
+ eportsargv += ['--match' , 'multiport' , '!' , '--dport' , excludedports ]
83
+
76
84
# basic cleanup/setup of chains
77
85
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 )
79
90
nonfatal (ipt , '-D' , 'PREROUTING' , '-j' , chain )
80
91
nonfatal (ipt , '-F' , chain )
81
92
ipt ('-X' , chain )
82
93
83
94
if subnets or dnsport :
84
95
ipt ('-N' , chain )
85
96
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 )
87
101
ipt ('-I' , 'PREROUTING' , '1' , '-j' , chain )
88
102
89
103
if subnets :
@@ -101,8 +115,9 @@ def do_iptables(port, dnsport, nslist, subnets):
101
115
ipt_ttl ('-A' , chain , '-j' , 'REDIRECT' ,
102
116
'--dest' , '%s/%s' % (snet ,swidth ),
103
117
'-p' , 'tcp' ,
104
- '--to-ports' , str (port ))
105
-
118
+ '--to-ports' , str (port ),
119
+ * eportsargv )
120
+
106
121
if dnsport :
107
122
for ip in nslist :
108
123
ipt_ttl ('-A' , chain , '-j' , 'REDIRECT' ,
@@ -254,7 +269,11 @@ def ipfw(*args):
254
269
_call (argv )
255
270
256
271
272
+ < << << << HEAD
257
273
def do_ipfw (port , dnsport , nslist , subnets ):
274
+ == == == =
275
+ def do_ipfw (port , dnsport , route_username , excludedports , subnets ):
276
+ > >> >> >> pull / 29
258
277
sport = str (port )
259
278
xsport = str (port + 1 )
260
279
@@ -449,7 +468,11 @@ def ip_in_subnets(ip, subnets):
449
468
# exit. In case that fails, it's not the end of the world; future runs will
450
469
# supercede it in the transproxy list, at least, so the leftover rules
451
470
# are hopefully harmless.
471
+ < << << << HEAD
452
472
def main (port , dnsport , nslist , syslog ):
473
+ == == == =
474
+ def main (port , dnsport , syslog , route_username , excludedports ):
475
+ > >> >> >> pull / 29
453
476
assert (port > 0 )
454
477
assert (port <= 65535 )
455
478
assert (dnsport >= 0 )
@@ -514,7 +537,11 @@ def main(port, dnsport, nslist, syslog):
514
537
try :
515
538
if line :
516
539
debug1 ('firewall manager: starting transproxy.\n ' )
540
+ << << << < HEAD
517
541
do_wait = do_it (port , dnsport , nslist , subnets )
542
+ == == == =
543
+ do_wait = do_it (port , dnsport , route_username , excludedports , subnets )
544
+ >> >> >> > pull / 29
518
545
sys .stdout .write ('STARTED\n ' )
519
546
520
547
try :
@@ -544,5 +571,9 @@ def main(port, dnsport, nslist, syslog):
544
571
debug1 ('firewall manager: undoing changes.\n ' )
545
572
except :
546
573
pass
574
+ < << << << HEAD
547
575
do_it (port , 0 , [], [])
576
+ == == == =
577
+ do_it (port , 0 , route_username , excludedports , [])
578
+ >> >> >> > pull / 29
548
579
restore_etc_hosts (port )
0 commit comments