Mercurial Hosting > luan
comparison src/luan/modules/IoLuan.java @ 1330:f41919741100
fix security
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 11 Feb 2019 01:38:55 -0700 |
parents | 15af473045c4 |
children | 25746915a241 |
comparison
equal
deleted
inserted
replaced
1329:5a39b006acd1 | 1330:f41919741100 |
---|---|
26 import java.net.MalformedURLException; | 26 import java.net.MalformedURLException; |
27 import java.net.UnknownHostException; | 27 import java.net.UnknownHostException; |
28 import java.nio.file.Files; | 28 import java.nio.file.Files; |
29 import java.util.Enumeration; | 29 import java.util.Enumeration; |
30 import java.util.Map; | 30 import java.util.Map; |
31 import luan.Luan; | |
31 import luan.LuanState; | 32 import luan.LuanState; |
32 import luan.LuanTable; | 33 import luan.LuanTable; |
33 import luan.LuanFunction; | 34 import luan.LuanFunction; |
34 import luan.LuanException; | 35 import luan.LuanException; |
35 import luan.modules.url.LuanUrl; | 36 import luan.modules.url.LuanUrl; |
638 } catch(UnknownHostException e) { | 639 } catch(UnknownHostException e) { |
639 return null; | 640 return null; |
640 } | 641 } |
641 } | 642 } |
642 | 643 |
643 public static LuanTable my_ips(LuanState luan) throws IOException { | 644 public static LuanTable my_ips(LuanState luan) throws IOException, LuanException { |
644 LuanTable tbl = new LuanTable(luan); | 645 LuanTable tbl = new LuanTable(luan); |
645 for( Enumeration<NetworkInterface> e1 = NetworkInterface.getNetworkInterfaces(); e1.hasMoreElements(); ) { | 646 for( Enumeration<NetworkInterface> e1 = NetworkInterface.getNetworkInterfaces(); e1.hasMoreElements(); ) { |
646 NetworkInterface ni = e1.nextElement(); | 647 NetworkInterface ni = e1.nextElement(); |
647 for( Enumeration<InetAddress> e2 = ni.getInetAddresses(); e2.hasMoreElements(); ) { | 648 for( Enumeration<InetAddress> e2 = ni.getInetAddresses(); e2.hasMoreElements(); ) { |
648 InetAddress ia = e2.nextElement(); | 649 InetAddress ia = e2.nextElement(); |
649 if( ia instanceof Inet4Address ) | 650 if( ia instanceof Inet4Address ) |
650 tbl.rawPut(ia.getHostAddress(),true); | 651 tbl.put(ia.getHostAddress(),true); |
651 } | 652 } |
652 } | 653 } |
653 return tbl; | 654 return tbl; |
654 } | 655 } |
655 | 656 |
656 | 657 |
657 // security | |
658 | |
659 public static void unrestricted(LuanState luan) throws LuanException { | |
660 JavaLuan.check(luan); | |
661 luan.javaOk.unrestrictedIo = true; | |
662 } | |
663 | |
664 public interface Security { | |
665 public void check(LuanState luan,String name) throws LuanException; | |
666 } | |
667 | |
668 private static String SECURITY_KEY = "Io.Security"; | |
669 | |
670 private static void check(LuanState luan,String name) throws LuanException { | 658 private static void check(LuanState luan,String name) throws LuanException { |
671 if( luan.javaOk.unrestrictedIo ) | 659 Luan.checkSecurity(luan,"uri",name); |
672 return; | 660 } |
673 Security s = (Security)luan.registry().get(SECURITY_KEY); | 661 |
674 if( s!=null ) | |
675 s.check(luan,name); | |
676 } | |
677 | |
678 public static void setSecurity(LuanState luan,Security s) { | |
679 luan.registry().put(SECURITY_KEY,s); | |
680 } | |
681 | 662 |
682 private void IoLuan() {} // never | 663 private void IoLuan() {} // never |
683 } | 664 } |