changeset 1134:e54ae41e9501

cleaner security
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 17 Jan 2018 21:44:46 -0700
parents ba4daf107e07
children 707a5d874f3e
files src/luan/LuanJavaOk.java src/luan/modules/Io.luan src/luan/modules/IoLuan.java src/luan/modules/JavaLuan.java src/luan/modules/lucene/Lucene.luan
diffstat 5 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/LuanJavaOk.java	Wed Jan 17 20:59:42 2018 -0700
+++ b/src/luan/LuanJavaOk.java	Wed Jan 17 21:44:46 2018 -0700
@@ -3,10 +3,12 @@
 
 public final class LuanJavaOk implements LuanCloneable {
 	public boolean ok = false;
+	public boolean unrestrictedIo = false;
 
 	@Override public LuanJavaOk shallowClone() {
 		LuanJavaOk javaOk = new LuanJavaOk();
 		javaOk.ok = ok;
+		javaOk.unrestrictedIo = unrestrictedIo;
 		return javaOk;
 	}
 
--- a/src/luan/modules/Io.luan	Wed Jan 17 20:59:42 2018 -0700
+++ b/src/luan/modules/Io.luan	Wed Jan 17 21:44:46 2018 -0700
@@ -13,6 +13,7 @@
 Io.socket_server = IoLuan.socket_server
 Io.stdout = IoLuan.textWriter(System.out)
 Io.stderr = IoLuan.textWriter(System.err)
+Io.unrestricted = IoLuan.unrestricted
 
 -- used by http and rpc
 Io.password = "password"
--- a/src/luan/modules/IoLuan.java	Wed Jan 17 20:59:42 2018 -0700
+++ b/src/luan/modules/IoLuan.java	Wed Jan 17 21:44:46 2018 -0700
@@ -946,6 +946,11 @@
 
 	// security
 
+	public static void unrestricted(LuanState luan) throws LuanException {
+		JavaLuan.check(luan);
+		luan.javaOk.unrestrictedIo = true;
+	}
+
 	public interface Security {
 		public void check(LuanState luan,String name) throws LuanException;
 	}
@@ -953,7 +958,7 @@
 	private static String SECURITY_KEY = "Io.Security";
 
 	private static void check(LuanState luan,String name) throws LuanException {
-		if( luan.javaOk.ok )
+		if( luan.javaOk.unrestrictedIo )
 			return;
 		Security s = (Security)luan.registry().get(SECURITY_KEY);
 		if( s!=null )
--- a/src/luan/modules/JavaLuan.java	Wed Jan 17 20:59:42 2018 -0700
+++ b/src/luan/modules/JavaLuan.java	Wed Jan 17 21:44:46 2018 -0700
@@ -28,7 +28,7 @@
 public final class JavaLuan {
 
 	public static void java(LuanState luan) throws LuanException {
-		check(luan,LuanException.currentSource());
+		check(luan);
 		luan.javaOk.ok = true;
 	}
 
@@ -482,10 +482,12 @@
 
 	private static String SECURITY_KEY = "Java.Security";
 
-	private static void check(LuanState luan,String name) throws LuanException {
+	static void check(LuanState luan) throws LuanException {
 		Security s = (Security)luan.registry().get(SECURITY_KEY);
-		if( s!=null )
+		if( s!=null ) {
+			String name = LuanException.currentSource();
 			s.check(luan,name);
+		}
 	}
 
 	public static void setSecurity(LuanState luan,Security s) {
--- a/src/luan/modules/lucene/Lucene.luan	Wed Jan 17 20:59:42 2018 -0700
+++ b/src/luan/modules/lucene/Lucene.luan	Wed Jan 17 21:44:46 2018 -0700
@@ -6,6 +6,7 @@
 local set_metatable = Luan.set_metatable or error()
 local Html = require "luan:Html.luan"
 local Io = require "luan:Io.luan"
+Io.unrestricted()
 local uri = Io.uri or error()
 local String = require "luan:String.luan"
 local matches = String.matches or error()