Commit | Line | Data |
---|---|---|
dfb0d0d7 AC |
1 | structure Sec :> SEC = struct |
2 | ||
3 | open Init Util Sql | |
4 | ||
3d2ed222 AC |
5 | structure Req = RequestH(struct |
6 | val table = "Sec" | |
7 | val adminGroup = "server" | |
8 | fun subject _ = "Security permissions change request" | |
9 | val template = "sec" | |
10 | val descr = "change" | |
11 | fun body {node, mail, data = req} = | |
12 | (Mail.mwrite (mail, req); | |
13 | Mail.mwrite (mail, "\n")) | |
14 | end) | |
dfb0d0d7 AC |
15 | |
16 | fun findSubusers uname = | |
17 | let | |
18 | val uname_under = uname ^ "_" | |
19 | val inf = TextIO.openIn "/etc/passwd" | |
20 | ||
21 | fun loop subs = | |
22 | case TextIO.inputLine inf of | |
23 | NONE => ListMergeSort.sort (fn (x, y) => String.compare (x, y) = GREATER) subs | |
24 | | SOME line => | |
25 | case String.fields (fn ch => ch = #":") line of | |
26 | uname'::_ => | |
27 | if size uname' >= size uname_under | |
28 | andalso String.substring (uname', 0, size uname_under) = uname_under then | |
29 | loop (uname' :: subs) | |
30 | else | |
31 | loop subs | |
32 | | _ => loop subs | |
33 | in | |
34 | loop [] | |
35 | before TextIO.closeIn inf | |
36 | end | |
37 | ||
38 | datatype socket_perms = | |
39 | ANY | |
40 | | CLIENT_ONLY | |
41 | | SERVER_ONLY | |
42 | | NADA | |
43 | ||
3d2ed222 | 44 | fun socketPerms {node, uname} = |
dfb0d0d7 | 45 | let |
3d2ed222 AC |
46 | val proc = Unix.execute ("/bin/sh", |
47 | ["-c", | |
48 | "DOMTOOL_USER=apache2.deleuze.hcoop.net /usr/local/bin/domtool-admin sockperm " | |
49 | ^ Init.nodeName node ^ " " ^ uname]) | |
50 | ||
51 | val inf = Unix.textInstreamOf proc | |
dfb0d0d7 | 52 | |
3d2ed222 AC |
53 | val p = case TextIO.inputLine inf of |
54 | SOME "Any\n" => ANY | |
55 | | SOME "Client\n" => CLIENT_ONLY | |
56 | | SOME "Server\n" => SERVER_ONLY | |
57 | | _ => NADA | |
dfb0d0d7 | 58 | in |
3d2ed222 AC |
59 | TextIO.closeIn inf; |
60 | if OS.Process.isSuccess (Unix.reap proc) then | |
61 | p | |
dfb0d0d7 | 62 | else |
3d2ed222 AC |
63 | NADA |
64 | end | |
dfb0d0d7 | 65 | |
3d2ed222 AC |
66 | fun checkIt cmd {node, uname} = |
67 | OS.Process.isSuccess (OS.Process.system | |
68 | ("DOMTOOL_USER=apache2.deleuze.hcoop.net /usr/local/bin/domtool-admin " | |
69 | ^ cmd ^ " " ^ Init.nodeName node ^ " " ^ uname ^ " >/dev/null 2>/dev/null")) | |
dfb0d0d7 | 70 | |
3d2ed222 AC |
71 | val isTpe = checkIt "tpe" |
72 | val cronAllowed = checkIt "cron" | |
73 | val ftpAllowed = checkIt "ftp" | |
e510b9bd | 74 | |
3d2ed222 | 75 | fun findFirewallRules {node, uname} = |
e510b9bd | 76 | let |
3d2ed222 AC |
77 | val proc = Unix.execute ("/bin/sh", |
78 | ["-c", | |
79 | "DOMTOOL_USER=apache2.deleuze.hcoop.net /usr/local/bin/domtool-admin firewall " | |
80 | ^ Init.nodeName node ^ " " ^ uname]) | |
81 | ||
82 | val inf = Unix.textInstreamOf proc | |
e510b9bd | 83 | |
3d2ed222 | 84 | fun readEm lines = |
e510b9bd | 85 | case TextIO.inputLine inf of |
3d2ed222 AC |
86 | SOME line => readEm (String.substring (line, 0, size line - 1) :: lines) |
87 | | NONE => rev lines | |
88 | ||
89 | val lines = readEm [] | |
e510b9bd | 90 | in |
3d2ed222 AC |
91 | TextIO.closeIn inf; |
92 | if OS.Process.isSuccess (Unix.reap proc) then | |
93 | lines | |
94 | else | |
95 | [] | |
e510b9bd AC |
96 | end |
97 | ||
dfb0d0d7 | 98 | end |