-structure ChooseDomain :> CHOOSE_DOMAIN = struct
-
-fun domains user =
- let
- val proc = Unix.execute ("/bin/sh", ["-c", "DOMTOOL_USER=hcoop /usr/local/bin/domtool-admin perms " ^ user])
- val inf = Unix.textInstreamOf proc
-
- fun loop () =
- case TextIO.inputLine inf of
- NONE => []
- | SOME line =>
- case String.tokens (fn ch => ch = #":") line of
- ["domain", domains] => String.tokens Char.isSpace domains
- | _ => loop ()
- in
- loop ()
- before ignore (Unix.reap proc)
- end
-
-fun yourDomain {user, domain} = List.exists (fn x => x = domain) (domains user)
-
-end
+structure ChooseDomain :> CHOOSE_DOMAIN = struct
+
+val domains = Domtool.perms "domain"
+
+fun yourDomain {user, domain} = Domtool.hasPerm "domain" user domain
+
+end
--- /dev/null
+signature DOMTOOL = sig
+ val perms : string -> string -> string list
+ val hasPerm : string -> string -> string -> bool
+end
-structure ChooseDomain :> CHOOSE_DOMAIN = struct
+structure Domtool :> DOMTOOL = struct
-fun domains user =
+fun perms class user =
let
val proc = Unix.execute ("/bin/sh", ["-c", "DOMTOOL_USER=hcoop /usr/local/bin/domtool-admin perms " ^ user])
val inf = Unix.textInstreamOf proc
NONE => []
| SOME line =>
case String.tokens (fn ch => ch = #":") line of
- ["domain", domains] => String.tokens Char.isSpace domains
+ [class', permissions] => if class' = class then String.tokens Char.isSpace permissions else loop ()
| _ => loop ()
in
loop ()
before ignore (Unix.reap proc)
end
-fun yourDomain {user, domain} = List.exists (fn x => x = domain) (domains user)
+fun hasPerm class user value =
+ List.exists (fn x => x = value) (perms class user)
end