mysql-fixperms
authorAdam Chlipala <adamc@hcoop.net>
Sun, 14 Oct 2007 01:25:38 +0000 (01:25 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Sun, 14 Oct 2007 01:25:38 +0000 (01:25 +0000)
Makefile
bin/.cvsignore
src/.cvsignore
src/main-mysql-fixperms.sml [new file with mode: 0644]
src/main.sig
src/main.sml
src/msg.sml
src/msgTypes.sml

index 68feaf0..f538e94 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ config.sml:
 
 mlton: bin/domtool-server bin/domtool-client bin/domtool-slave \
        bin/domtool-admin bin/domtool-doc bin/dbtool bin/vmail \
 
 mlton: bin/domtool-server bin/domtool-client bin/domtool-slave \
        bin/domtool-admin bin/domtool-doc bin/dbtool bin/vmail \
-       bin/smtplog bin/setsa
+       bin/smtplog bin/setsa bin/mysql-fixperms
 
 smlnj: $(COMMON_DEPS) openssl/smlnj/FFI/libssl.h.cm src/domtool.cm
 
 
 smlnj: $(COMMON_DEPS) openssl/smlnj/FFI/libssl.h.cm src/domtool.cm
 
@@ -81,6 +81,10 @@ src/smtplog.mlb: src/prefix.mlb src/sources src/suffix.mlb
        $(MAKE_MLB_BASE) >src/smtplog.mlb
        echo "main-smtplog.sml" >>src/smtplog.mlb
 
        $(MAKE_MLB_BASE) >src/smtplog.mlb
        echo "main-smtplog.sml" >>src/smtplog.mlb
 
+src/mysql-fixperms.mlb: src/prefix.mlb src/sources src/suffix.mlb
+       $(MAKE_MLB_BASE) >src/mysql-fixperms.mlb
+       echo "main-mysql-fixperms.sml" >>src/mysql-fixperms.mlb
+
 openssl/smlnj/FFI/libssl.h.cm: openssl/openssl_sml.h
        cd openssl/smlnj ; ml-nlffigen -d FFI -lh LibsslH.libh -include ../libssl-h.sml \
        -cm libssl.h.cm -D__builtin_va_list="void*" \
 openssl/smlnj/FFI/libssl.h.cm: openssl/openssl_sml.h
        cd openssl/smlnj ; ml-nlffigen -d FFI -lh LibsslH.libh -include ../libssl-h.sml \
        -cm libssl.h.cm -D__builtin_va_list="void*" \
@@ -137,6 +141,9 @@ bin/setsa: $(COMMON_MLTON_DEPS) src/setsa.mlb
 bin/smtplog: $(COMMON_MLTON_DEPS) src/smtplog.mlb
        $(MLTON) -output bin/smtplog src/smtplog.mlb
 
 bin/smtplog: $(COMMON_MLTON_DEPS) src/smtplog.mlb
        $(MLTON) -output bin/smtplog src/smtplog.mlb
 
+bin/mysql-fixperms: $(COMMON_MLTON_DEPS) src/mysql-fixperms.mlb
+       $(MLTON) -output bin/mysql-fixperms src/mysql-fixperms.mlb
+
 install:
        cp scripts/domtool-publish /usr/local/sbin/
        cp scripts/domtool-reset-global /usr/local/sbin/
 install:
        cp scripts/domtool-publish /usr/local/sbin/
        cp scripts/domtool-reset-global /usr/local/sbin/
@@ -161,6 +168,7 @@ install:
        -cp bin/vmail /usr/local/bin/
        -cp bin/setsa /usr/local/bin/
        -cp bin/smtplog /usr/local/bin/
        -cp bin/vmail /usr/local/bin/
        -cp bin/setsa /usr/local/bin/
        -cp bin/smtplog /usr/local/bin/
+       -cp bin/mysql-fixperms /usr/local/bin/
        cp src/plugins/domtool-postgres /usr/local/sbin/
        cp src/plugins/domtool-mysql /usr/local/sbin/
 
        cp src/plugins/domtool-postgres /usr/local/sbin/
        cp src/plugins/domtool-mysql /usr/local/sbin/
 
index fe46df0..452990c 100644 (file)
@@ -7,3 +7,4 @@ dbtool
 vmail
 setsa
 smtplog
 vmail
 setsa
 smtplog
+mysql-fixperms
index 28d4055..cc5a2d9 100644 (file)
@@ -11,3 +11,4 @@ dbtool.mlb
 vmail.mlb
 setsa.mlb
 smtplog.mlb
 vmail.mlb
 setsa.mlb
 smtplog.mlb
+mysql-fixperms.mlb
diff --git a/src/main-mysql-fixperms.sml b/src/main-mysql-fixperms.sml
new file mode 100644 (file)
index 0000000..1e49f0f
--- /dev/null
@@ -0,0 +1,24 @@
+(* HCoop Domtool (http://hcoop.sourceforge.net/)
+ * Copyright (c) 2007, Adam Chlipala
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *)
+
+(* Driver for requesting MySQL DROP permission granting *)
+
+val _ =
+    case CommandLine.arguments () of
+       [] => Main.requestMysqlFixperms ()
+      | _ => print "Invalid command-line arguments\n"
index 97231f5..55ad560 100644 (file)
@@ -73,6 +73,8 @@ signature MAIN = sig
 
     val requestSmtpLog : string -> unit
 
 
     val requestSmtpLog : string -> unit
 
+    val requestMysqlFixperms : unit -> unit
+
     val requestApt : {node : string, pkg : string} -> OS.Process.status
     val requestCron : {node : string, uname : string} -> OS.Process.status
     val requestFtp : {node : string, uname : string} -> OS.Process.status
     val requestApt : {node : string, pkg : string} -> OS.Process.status
     val requestCron : {node : string, uname : string} -> OS.Process.status
     val requestFtp : {node : string, uname : string} -> OS.Process.status
index 3b54316..d57b867 100644 (file)
@@ -680,6 +680,21 @@ fun requestSmtpLog domain =
        OpenSSL.close bio
     end
 
        OpenSSL.close bio
     end
 
+fun requestMysqlFixperms () =
+    let
+       val (_, bio) = requestBio (fn () => ())
+    in
+       Msg.send (bio, MsgMysqlFixperms);
+       case Msg.recv bio of
+           NONE => print "Server closed connection unexpectedly.\n"
+         | SOME m =>
+           case m of
+               MsgOk => print "Permissions granted.\n"
+             | MsgError s => print ("Failed: " ^ s ^ "\n")
+             | _ => print "Unexpected server reply.\n";
+       OpenSSL.close bio
+    end
+
 fun requestApt {node, pkg} =
     let
        val (user, context) = requestContext (fn () => ())
 fun requestApt {node, pkg} =
     let
        val (user, context) = requestContext (fn () => ())
@@ -1433,6 +1448,16 @@ fun service () =
                                                  NONE)))
                                      (fn () => ())
 
                                                  NONE)))
                                      (fn () => ())
 
+                              | MsgMysqlFixperms =>
+                                doIt (fn () => if OS.Process.isSuccess
+                                                      (OS.Process.system "/usr/bin/sudo -H /afs/hcoop.net/common/etc/scripts/mysql-grant-table-drop") then
+                                                   ("Requested mysql-fixperms",
+                                                    NONE)
+                                                else
+                                                    ("Requested mysql-fixperms, but execution failed!",
+                                                     SOME "Script execution failed."))
+                                     (fn () => ())
+
                               | _ =>
                                 doIt (fn () => ("Unexpected command",
                                                 SOME "Unexpected command"))
                               | _ =>
                                 doIt (fn () => ("Unexpected command",
                                                 SOME "Unexpected command"))
index a8aea97..64837b9 100644 (file)
@@ -228,6 +228,7 @@ fun send (bio, m) =
       | MsgGrantDb {dbtype, dbname} => (OpenSSL.writeInt (bio, 37);
                                        OpenSSL.writeString (bio, dbtype);
                                        OpenSSL.writeString (bio, dbname))
       | MsgGrantDb {dbtype, dbname} => (OpenSSL.writeInt (bio, 37);
                                        OpenSSL.writeString (bio, dbtype);
                                        OpenSSL.writeString (bio, dbname))
+      | MsqMysqlFixperms => OpenSSL.writeInt (bio, 38)
 
 fun checkIt v =
     case v of
 
 fun checkIt v =
     case v of
@@ -337,6 +338,7 @@ fun recv bio =
                                (SOME dbtype, SOME dbname) =>
                                SOME (MsgGrantDb {dbtype = dbtype, dbname = dbname})
                              | _ => NONE)
                                (SOME dbtype, SOME dbname) =>
                                SOME (MsgGrantDb {dbtype = dbtype, dbname = dbname})
                              | _ => NONE)
+                  | 38 => SOME MsgMysqlFixperms
                   | _ => NONE)
         
 end
                   | _ => NONE)
         
 end
index 1c2abcc..0c367ec 100644 (file)
@@ -118,5 +118,7 @@ datatype msg =
        (* MsgRegenerate without actual publishing of configuration *)
        | MsgGrantDb of {dbtype : string, dbname : string}
        (* Grant all allowed privileges on a DBMS database to the user *)
        (* MsgRegenerate without actual publishing of configuration *)
        | MsgGrantDb of {dbtype : string, dbname : string}
        (* Grant all allowed privileges on a DBMS database to the user *)
+       | MsgMysqlFixperms
+       (* Run the script to grant DROP privileges on MySQL tables to owning users *)
 
 end
 
 end