cvsimport
[hcoop/zz_old/portal.git] / sec.sml
diff --git a/sec.sml b/sec.sml
index 782fdf7..5712940 100644 (file)
--- a/sec.sml
+++ b/sec.sml
@@ -45,7 +45,7 @@ fun socketPerms {node, uname} =
     let
        val proc = Unix.execute ("/bin/sh",
                                 ["-c",
-                                 "DOMTOOL_USER=apache2.deleuze.hcoop.net /usr/local/bin/domtool-admin sockperm "
+                                 "DOMTOOL_USER=hcoop /usr/local/bin/domtool-admin sockperm "
                                  ^ Init.nodeName node ^ " " ^ uname])
                   
        val inf = Unix.textInstreamOf proc
@@ -65,7 +65,7 @@ fun socketPerms {node, uname} =
 
 fun checkIt cmd {node, uname} =
     OS.Process.isSuccess (OS.Process.system
-                             ("DOMTOOL_USER=apache2.deleuze.hcoop.net /usr/local/bin/domtool-admin "
+                             ("DOMTOOL_USER=hcoop /usr/local/bin/domtool-admin "
                               ^ cmd ^ " " ^ Init.nodeName node ^ " " ^ uname ^ " >/dev/null 2>/dev/null"))
 
 val isTpe = checkIt "tpe"
@@ -76,7 +76,7 @@ fun findFirewallRules {node, uname} =
     let
        val proc = Unix.execute ("/bin/sh",
                                 ["-c",
-                                 "DOMTOOL_USER=apache2.deleuze.hcoop.net /usr/local/bin/domtool-admin firewall "
+                                 "DOMTOOL_USER=hcoop /usr/local/bin/domtool-admin firewall "
                                  ^ Init.nodeName node ^ " " ^ uname])
                   
        val inf = Unix.textInstreamOf proc
@@ -95,4 +95,48 @@ fun findFirewallRules {node, uname} =
            []
     end
 
+fun intFromString s =
+    if CharVector.all Char.isDigit s andalso size s > 0 then
+       Int.fromString s
+    else
+       NONE
+
+fun validPort port =
+    case intFromString port of
+       NONE => false
+      | SOME n => n > 0
+
+fun validPortPiece pp =
+    case String.fields (fn ch => ch = #":") pp of
+       [port] => validPort port
+      | [port1, port2] => validPort port1 andalso validPort port2
+
+fun validPorts ports =
+    List.all validPortPiece (String.fields (fn ch => ch = #",") ports)
+
+fun validIp s =
+    case map intFromString (String.fields (fn ch => ch = #".") s) of
+        [SOME n1, SOME n2, SOME n3, SOME n4] =>
+        n1 >= 0 andalso n1 < 256 andalso n2 >= 0 andalso n2 < 256 andalso n3 >= 0 andalso n3 < 256 andalso n4 >= 0 andalso n4 < 256
+      | _ => false
+
+fun isIdent ch = Char.isLower ch orelse Char.isDigit ch
+
+fun validHost s =
+    size s > 0 andalso size s < 20
+    andalso CharVector.all (fn ch => isIdent ch orelse ch = #"-") s
+
+fun validDomain s =
+    size s > 0 andalso size s < 100
+    andalso List.all validHost (String.fields (fn ch => ch = #".") s)
+
+val validHosts = List.all (fn x => validIp x orelse validDomain x)
+
+fun validRule rule =
+    case String.tokens Char.isSpace rule of
+       "Client" :: ports :: hosts => validPorts ports andalso validHosts hosts
+      | "Server" :: ports :: hosts => validPorts ports andalso validHosts hosts
+      | ["LocalServer", ports] => validPorts ports
+      | _ => false
+
 end