@@ -70,20 +70,26 @@ 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- def do_iptables (port , dnsport , subnets ):
73+ def do_iptables (port , dnsport , route_username , subnets ):
7474 chain = 'sshuttle-%s' % port
7575
7676 # basic cleanup/setup of chains
7777 if ipt_chain_exists (chain ):
78- nonfatal (ipt , '-D' , 'OUTPUT' , '-j' , chain )
78+ if not route_username :
79+ nonfatal (ipt , '-D' , 'OUTPUT' , '-j' , chain )
80+ else :
81+ nonfatal (ipt , '-m' , 'owner' , '--uid-owner' , route_username , '-D' , 'OUTPUT' , '-j' , chain )
7982 nonfatal (ipt , '-D' , 'PREROUTING' , '-j' , chain )
8083 nonfatal (ipt , '-F' , chain )
8184 ipt ('-X' , chain )
8285
8386 if subnets or dnsport :
8487 ipt ('-N' , chain )
8588 ipt ('-F' , chain )
86- ipt ('-I' , 'OUTPUT' , '1' , '-j' , chain )
89+ if not route_username :
90+ ipt ('-I' , 'OUTPUT' , '1' , '-j' , chain )
91+ else :
92+ ipt ('-m' , 'owner' , '--uid-owner' , route_username , '-I' , 'OUTPUT' , '1' , '-j' , chain )
8793 ipt ('-I' , 'PREROUTING' , '1' , '-j' , chain )
8894
8995 if subnets :
@@ -255,7 +261,7 @@ def ipfw(*args):
255261 _call (argv )
256262
257263
258- def do_ipfw (port , dnsport , subnets ):
264+ def do_ipfw (port , dnsport , route_username , subnets ):
259265 sport = str (port )
260266 xsport = str (port + 1 )
261267
@@ -451,7 +457,7 @@ def ip_in_subnets(ip, subnets):
451457# exit. In case that fails, it's not the end of the world; future runs will
452458# supercede it in the transproxy list, at least, so the leftover rules
453459# are hopefully harmless.
454- def main (port , dnsport , syslog ):
460+ def main (port , dnsport , syslog , route_username ):
455461 assert (port > 0 )
456462 assert (port <= 65535 )
457463 assert (dnsport >= 0 )
@@ -516,7 +522,7 @@ def main(port, dnsport, syslog):
516522 try :
517523 if line :
518524 debug1 ('firewall manager: starting transproxy.\n ' )
519- do_wait = do_it (port , dnsport , subnets )
525+ do_wait = do_it (port , dnsport , route_username , subnets )
520526 sys .stdout .write ('STARTED\n ' )
521527
522528 try :
@@ -546,5 +552,5 @@ def main(port, dnsport, syslog):
546552 debug1 ('firewall manager: undoing changes.\n ' )
547553 except :
548554 pass
549- do_it (port , 0 , [])
555+ do_it (port , 0 , route_username , [])
550556 restore_etc_hosts (port )
0 commit comments