@@ -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
7374def 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
257273def 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
452472def 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 )
0 commit comments