structure Sec :> SEC = struct open Init Util Sql structure Req = RequestH(struct val table = "Sec" val adminGroup = "server" fun subject _ = "Security permissions change request" val template = "sec" val descr = "change" fun body {node, mail, data = req} = (Mail.mwrite (mail, req); Mail.mwrite (mail, "\n")) end) fun findSubusers uname = let val uname_under = uname ^ "_" val inf = TextIO.openIn "/etc/passwd" fun loop subs = case TextIO.inputLine inf of NONE => ListMergeSort.sort (fn (x, y) => String.compare (x, y) = GREATER) subs | SOME line => case String.fields (fn ch => ch = #":") line of uname'::_ => if size uname' >= size uname_under andalso String.substring (uname', 0, size uname_under) = uname_under then loop (uname' :: subs) else loop subs | _ => loop subs in loop [] before TextIO.closeIn inf end datatype socket_perms = ANY | CLIENT_ONLY | SERVER_ONLY | NADA fun socketPerms {node, uname} = let val proc = Unix.execute ("/bin/sh", ["-c", "DOMTOOL_USER=apache2.deleuze.hcoop.net /usr/local/bin/domtool-admin sockperm " ^ Init.nodeName node ^ " " ^ uname]) val inf = Unix.textInstreamOf proc val p = case TextIO.inputLine inf of SOME "Any\n" => ANY | SOME "Client\n" => CLIENT_ONLY | SOME "Server\n" => SERVER_ONLY | _ => NADA in TextIO.closeIn inf; if OS.Process.isSuccess (Unix.reap proc) then p else NADA end fun checkIt cmd {node, uname} = OS.Process.isSuccess (OS.Process.system ("DOMTOOL_USER=apache2.deleuze.hcoop.net /usr/local/bin/domtool-admin " ^ cmd ^ " " ^ Init.nodeName node ^ " " ^ uname ^ " >/dev/null 2>/dev/null")) val isTpe = checkIt "tpe" val cronAllowed = checkIt "cron" val ftpAllowed = checkIt "ftp" fun findFirewallRules {node, uname} = let val proc = Unix.execute ("/bin/sh", ["-c", "DOMTOOL_USER=apache2.deleuze.hcoop.net /usr/local/bin/domtool-admin firewall " ^ Init.nodeName node ^ " " ^ uname]) val inf = Unix.textInstreamOf proc fun readEm lines = case TextIO.inputLine inf of SOME line => readEm (String.substring (line, 0, size line - 1) :: lines) | NONE => rev lines val lines = readEm [] in TextIO.closeIn inf; if OS.Process.isSuccess (Unix.reap proc) then lines else [] end end