Generalize querying domtool permissions
authorClinton Ebadi <clinton@unknownlamer.org>
Fri, 11 Apr 2014 17:54:26 +0000 (13:54 -0400)
committerClinton Ebadi <clinton@unknownlamer.org>
Fri, 11 Apr 2014 17:54:26 +0000 (13:54 -0400)
chooseDomain.sml
domtool.sig [new file with mode: 0644]
domtool.sml [copied from chooseDomain.sml with 59% similarity]

dissimilarity index 90%
index e2029d7..4e25fd3 100644 (file)
@@ -1,22 +1,7 @@
-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
diff --git a/domtool.sig b/domtool.sig
new file mode 100644 (file)
index 0000000..38db509
--- /dev/null
@@ -0,0 +1,4 @@
+signature DOMTOOL = sig
+    val perms : string -> string -> string list
+    val hasPerm : string -> string -> string -> bool
+end
similarity index 59%
copy from chooseDomain.sml
copy to domtool.sml
index e2029d7..6558774 100644 (file)
@@ -1,6 +1,6 @@
-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
@@ -10,13 +10,14 @@ fun domains user =
                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