Parcourir la source

- user management support

Jan Janak il y a 20 ans
Parent
commit
3d9ea3015d

+ 9 - 1
doc/stylesheets/dbschema/xsl/common.xsl

@@ -3,7 +3,8 @@
     
     <xsl:key name="column_id" match="column" use="@id|xml:id"/>
 
-    <xsl:param name="prefix" select="."/>
+    <xsl:param name="prefix" select="_"/>
+    <xsl:param name="dir" select="mm"/>
 
     <xsl:variable name="sign-prefix">unsigned </xsl:variable>
     
@@ -56,6 +57,7 @@
 
 	<!-- Create all tables -->
 	<xsl:apply-templates select="table"/>
+	<xsl:apply-templates select="user"/>
     </xsl:template>
 
     <!-- ################ /DATABASE ################# -->
@@ -192,4 +194,10 @@
     <xsl:template match="value"/>
 
     <!-- ################ /VALUE ################# -->
+
+    <!-- ################ USER ################# -->
+
+    <xsl:template match="user"/>
+
+    <!-- ################ /USER ################# -->
 </xsl:stylesheet>

+ 4 - 1
doc/stylesheets/dbschema/xsl/dbtext.xsl

@@ -13,7 +13,7 @@
 	    <xsl:call-template name="get-name"/>
 	</xsl:variable>
 	
-	<xsl:variable name="path" select="concat($prefix, concat('/', $name))"/>
+	<xsl:variable name="path" select="concat($dir, concat('/', concat($prefix, $name)))"/>
 	<xsl:document 
 	    href="{$path}"
 	    method="text"
@@ -36,6 +36,9 @@
 	<xsl:call-template name="get-name"/>
 	<xsl:text>(</xsl:text>
 	<xsl:choose>
+	    <xsl:when test="db:type">
+		<xsl:value-of select="normalize-space(db:type)"/>
+	    </xsl:when>
 	    <xsl:when test="$type='char' or 
 		            $type='short' or 
                             $type='int' or

+ 165 - 0
doc/stylesheets/dbschema/xsl/mysql.xsl

@@ -29,6 +29,8 @@
 	<xsl:text>DROP DATABASE </xsl:text>
 	<xsl:value-of select="$database.name"/>
 	<xsl:text>;&#x0A;</xsl:text>
+
+	<xsl:apply-templates mode="drop"/>
     </xsl:template>
     
     <xsl:template name="table.close">
@@ -135,4 +137,167 @@
 	</xsl:if>
     </xsl:template>
 
+    <xsl:template match="user">
+	<xsl:text>GRANT ALL PRIVILEGES ON </xsl:text>	
+	<xsl:text>FLUSH PRIVILEGES;</xsl:text>
+    </xsl:template>
+
+
+    <xsl:template name="get-userid">
+	<xsl:param name="select" select="."/>
+	<xsl:param name="host" select="/.."/>
+	<xsl:text>'</xsl:text>
+	<xsl:choose>
+	    <!-- override test -->
+	    <xsl:when test="count($select/db:username)='1'">
+		<xsl:value-of select="normalize-space($select/db:username)"/>
+	    </xsl:when>
+	    <!-- No override, use the standard name -->
+	    <xsl:otherwise>
+		<xsl:value-of select="normalize-space($select/username)"/>
+	    </xsl:otherwise>
+	</xsl:choose>
+	<xsl:text>'</xsl:text>
+
+	<xsl:text>@'</xsl:text>
+	<xsl:choose>
+	    <xsl:when test="count($host)='1'">
+		<xsl:value-of select="normalize-space($host)"/>
+	    </xsl:when>
+	    <xsl:when test="count(db:host)='1'">
+		<xsl:value-of select="normalize-space(db:host)"/>
+	    </xsl:when>
+	    <xsl:when test="count(host)='1'">
+		<xsl:value-of select="normalize-space(host)"/>
+	    </xsl:when>
+	    <xsl:otherwise>
+		<xsl:text>%</xsl:text>
+	    </xsl:otherwise>
+	</xsl:choose>
+	<xsl:text>'</xsl:text>
+    </xsl:template>
+
+    <xsl:template match="user" mode="drop">
+	<xsl:variable name="database.name">
+	    <xsl:call-template name="get-name">
+		<xsl:with-param name="select" select="parent::database"/>
+	    </xsl:call-template>
+	</xsl:variable>
+	
+	<xsl:text>REVOKE ALL PRIVILEGES ON </xsl:text>
+	<xsl:value-of select="$database.name"/>
+	<xsl:text>.* FROM </xsl:text>
+
+	<xsl:call-template name="get-userid"/>
+
+	<xsl:text>;&#x0A;</xsl:text>
+
+	<xsl:text>DROP USER </xsl:text>
+	<xsl:call-template name="get-userid"/>
+	<xsl:text>;&#x0A;</xsl:text>
+
+	<!-- No host tag present means connect from anywhere so we need to
+	delete @localhost account as well -->
+	
+	<xsl:choose>
+	    <xsl:when test="count(db:host)='1'"/>
+	    <xsl:when test="count(host)='1'"/>
+	    <xsl:otherwise>
+		<xsl:text>REVOKE ALL PRIVILEGES ON </xsl:text>
+		<xsl:value-of select="$database.name"/>
+		<xsl:text>.* FROM </xsl:text>
+		<xsl:call-template name="get-userid">
+		    <xsl:with-param name="host">localhost</xsl:with-param>
+		</xsl:call-template>
+		<xsl:text>;&#x0A;</xsl:text>
+		<xsl:text>DROP USER </xsl:text>
+		<xsl:call-template name="get-userid">
+		    <xsl:with-param name="host">localhost</xsl:with-param>
+		</xsl:call-template>
+		<xsl:text>;&#x0A;</xsl:text>
+	    </xsl:otherwise>
+	</xsl:choose>
+
+	<xsl:text>FLUSH PRIVILEGES;</xsl:text>
+	<xsl:text>&#x0A;</xsl:text>
+    </xsl:template>
+
+
+    <xsl:template match="user">
+	<xsl:variable name="database.name">
+	    <xsl:call-template name="get-name">
+		<xsl:with-param name="select" select="parent::database"/>
+	    </xsl:call-template>
+	</xsl:variable>
+	
+	<xsl:text>GRANT </xsl:text>
+	<xsl:choose>
+	    <xsl:when test="count(db:privileges)='1'">
+		<xsl:value-of select="normalize-space(db:privileges)"/>
+	    </xsl:when>
+	    <xsl:otherwise>
+		<xsl:value-of select="normalize-space(privileges)"/>
+	    </xsl:otherwise>
+	</xsl:choose>
+	<xsl:text> ON </xsl:text>
+	<xsl:value-of select="$database.name"/>
+	<xsl:text>.* TO </xsl:text>
+	<xsl:call-template name="get-userid"/>
+	<xsl:choose>
+	    <xsl:when test="count(db:password)='1'">
+		<xsl:text> IDENTIFIED BY '</xsl:text>
+		<xsl:value-of select="normalize-space(db:password)"/>
+		<xsl:text>'</xsl:text>
+	    </xsl:when>
+	    <xsl:when test="count(password)='1'">
+		<xsl:text> IDENTIFIED BY '</xsl:text>
+		<xsl:value-of select="normalize-space(password)"/>
+		<xsl:text>'</xsl:text>
+	    </xsl:when>
+	</xsl:choose>
+	<xsl:text>;&#x0A;</xsl:text>
+
+	<!-- No host tag present means connect from anywhere so we need to
+	delete @localhost account as well -->
+	
+	<xsl:choose>
+	    <xsl:when test="count(db:host)='1'"/>
+	    <xsl:when test="count(host)='1'"/>
+	    <xsl:otherwise>
+		<xsl:text>GRANT </xsl:text>
+		<xsl:choose>
+		    <xsl:when test="count(db:privileges)='1'">
+			<xsl:value-of select="normalize-space(db:privileges)"/>
+		    </xsl:when>
+		    <xsl:otherwise>
+			<xsl:value-of select="normalize-space(privileges)"/>
+		    </xsl:otherwise>
+		</xsl:choose>
+		<xsl:text> ON </xsl:text>
+		<xsl:value-of select="$database.name"/>
+		<xsl:text>.* TO </xsl:text>
+		<xsl:call-template name="get-userid">
+		    <xsl:with-param name="host">localhost</xsl:with-param>
+		</xsl:call-template>
+		<xsl:choose>
+		    <xsl:when test="count(db:password)='1'">
+			<xsl:text> IDENTIFIED BY '</xsl:text>
+			<xsl:value-of select="normalize-space(db:password)"/>
+			<xsl:text>'</xsl:text>
+		    </xsl:when>
+		    <xsl:when test="count(password)='1'">
+			<xsl:text> IDENTIFIED BY '</xsl:text>
+			<xsl:value-of select="normalize-space(password)"/>
+			<xsl:text>'</xsl:text>
+		    </xsl:when>
+		</xsl:choose>
+		<xsl:text>;&#x0A;</xsl:text>
+	    </xsl:otherwise>
+	</xsl:choose>
+
+	<xsl:text>FLUSH PRIVILEGES;</xsl:text>
+	<xsl:text>&#x0A;</xsl:text>
+    </xsl:template>
+
+
 </xsl:stylesheet>

+ 3 - 3
doc/stylesheets/dbschema/xsl/sql.xsl

@@ -6,17 +6,17 @@
     <xsl:import href="common.xsl"/>
 
     <xsl:template match="/">
-	<xsl:variable name="createfile" select="concat($prefix, concat('/', 'create.sql'))"/>
+	<xsl:variable name="createfile" select="concat($dir, concat('/', concat($prefix, 'create.sql')))"/>
 	<xsl:document href="{$createfile}" method="text" indent="no" omit-xml-declaration="yes">
 	    <xsl:apply-templates select="/database[1]"/>
 	</xsl:document>
 
-	<xsl:variable name="dropfile" select="concat($prefix, concat('/', 'drop.sql'))"/>
+	<xsl:variable name="dropfile" select="concat($dir, concat('/', concat($prefix, 'drop.sql')))"/>
 	<xsl:document href="{$dropfile}" method="text" indent="no" omit-xml-declaration="yes">
 	    <xsl:apply-templates mode="drop" select="/database[1]"/>
 	</xsl:document>
     </xsl:template>
-
+    
 <!-- ################ DATABASE ################# -->
 
 <!-- ################ /DATABASE ################# -->