[libgda] Added the CREATE_USER server operation for PostgreSQL



commit 85be5cec47c227ad594a58d41c95789474c7d765
Author: Vivien Malerba <malerba gnome-db org>
Date:   Thu May 20 22:44:04 2010 +0200

    Added the CREATE_USER server operation for PostgreSQL

 doc/C/server-operation.xml                         |   56 ++++++++++
 doc/C/tmpl/gda-server-operation.sgml               |    3 +
 libgda/gda-server-operation.c                      |    2 +
 libgda/gda-server-operation.h                      |    4 +
 libgda/gda-server-provider.c                       |    9 ++
 providers/postgres/Makefile.am                     |    3 +-
 providers/postgres/gda-postgres-ddl.c              |  109 ++++++++++++++++++++
 providers/postgres/gda-postgres-ddl.h              |    3 +
 providers/postgres/gda-postgres-provider.c         |    5 +
 .../postgres/postgres_specs_create_user.xml.in     |   23 ++++
 10 files changed, 216 insertions(+), 1 deletions(-)
---
diff --git a/doc/C/server-operation.xml b/doc/C/server-operation.xml
index 65caf92..2524d0e 100644
--- a/doc/C/server-operation.xml
+++ b/doc/C/server-operation.xml
@@ -682,6 +682,62 @@
 	  </table>
 	</para>
       </listitem>
+
+      <listitem>
+        <para>Named and required information for GDA_SERVER_OPERATION_CREATE_USER:
+	  <table frame="all">
+            <tgroup cols="4" colsep="1" rowsep="1" align="justify">
+              <thead>
+		<row>
+                  <entry>Path</entry>
+                  <entry>Type</entry>
+                  <entry>Required?</entry>
+                  <entry>Description</entry>
+		</row>
+              </thead>
+              <tbody>
+		<row>
+                  <entry>/USER_DEF_P</entry>
+                  <entry>PARAMLIST</entry>
+		  <entry>Yes</entry>
+                  <entry>User's description</entry>
+		</row>
+		<row>
+                  <entry>/USER_DEF_P/USER_NAME</entry>
+                  <entry>PARAM</entry>
+		  <entry>Yes</entry>
+                  <entry>User name (string)</entry>
+		</row>
+                <row>
+                  <entry>/USER_DEF_P/PASSWORD</entry>
+                  <entry>PARAM</entry>
+                  <entry></entry>
+                  <entry>User's password (string)</entry>
+                </row>
+		<row>
+                  <entry>/USER_DEF_P/CAP_CREATEDB</entry>
+                  <entry>PARAM</entry>
+		  <entry></entry>
+                  <entry>Set to TRUE if the user is allowed to create databases (boolean)</entry>
+		</row>
+		<row>
+                  <entry>/USER_DEF_P/CAP_CREATEUSER</entry>
+                  <entry>PARAM</entry>
+		  <entry></entry>
+                  <entry>Set to TRUE if the user is allowed to create users (boolean)</entry>
+		</row>
+		<row>
+                  <entry>/USER_DEF_P/VALIDITY</entry>
+                  <entry>PARAM</entry>
+		  <entry></entry>
+                  <entry>Set the expiration timestamp (timestamp)</entry>
+		</row>
+	      </tbody>
+	    </tgroup>
+	  </table>
+	</para>
+      </listitem>
+
     </itemizedlist>
   </sect3>
   
diff --git a/doc/C/tmpl/gda-server-operation.sgml b/doc/C/tmpl/gda-server-operation.sgml
index 9452de9..7de4655 100644
--- a/doc/C/tmpl/gda-server-operation.sgml
+++ b/doc/C/tmpl/gda-server-operation.sgml
@@ -104,6 +104,9 @@ Handles any DDL query in an abstract way
 @GDA_SERVER_OPERATION_DROP_VIEW: 
 @GDA_SERVER_OPERATION_COMMENT_TABLE: 
 @GDA_SERVER_OPERATION_COMMENT_COLUMN: 
+ GDA_SERVER_OPERATION_CREATE_USER: 
+ GDA_SERVER_OPERATION_ALTER_USER: 
+ GDA_SERVER_OPERATION_DROP_USER: 
 @GDA_SERVER_OPERATION_LAST: 
 
 <!-- ##### FUNCTION gda_server_operation_get_op_type ##### -->
diff --git a/libgda/gda-server-operation.c b/libgda/gda-server-operation.c
index 7c03ebf..aea93c3 100644
--- a/libgda/gda-server-operation.c
+++ b/libgda/gda-server-operation.c
@@ -1223,6 +1223,8 @@ gda_server_operation_op_type_to_string (GdaServerOperationType type)
 		return "CREATE_VIEW";
 	case GDA_SERVER_OPERATION_DROP_VIEW:
 		return "DROP_VIEW";
+	case GDA_SERVER_OPERATION_CREATE_USER:
+		return "CREATE_USER";
 	default:
 		g_error (_("Non handled GdaServerOperationType, please report error to "
 			   "http://bugzilla.gnome.org/ for the \"libgda\" product"));
diff --git a/libgda/gda-server-operation.h b/libgda/gda-server-operation.h
index 028c8fd..440e386 100644
--- a/libgda/gda-server-operation.h
+++ b/libgda/gda-server-operation.h
@@ -59,6 +59,10 @@ typedef enum {
 	GDA_SERVER_OPERATION_COMMENT_TABLE,
 	GDA_SERVER_OPERATION_COMMENT_COLUMN,
 
+	GDA_SERVER_OPERATION_CREATE_USER,
+	GDA_SERVER_OPERATION_ALTER_USER,
+	GDA_SERVER_OPERATION_DROP_USER,
+
 	GDA_SERVER_OPERATION_LAST
 } GdaServerOperationType;
 
diff --git a/libgda/gda-server-provider.c b/libgda/gda-server-provider.c
index 8b837de..dc01ce9 100644
--- a/libgda/gda-server-provider.c
+++ b/libgda/gda-server-provider.c
@@ -429,6 +429,13 @@ static OpReq op_req_DROP_VIEW [] = {
 	{NULL}
 };
 
+static OpReq op_req_CREATE_USER [] = {
+	{"/USER_DEF_P",               GDA_SERVER_OPERATION_NODE_PARAMLIST, 0},
+	{"/USER_DEF_P/USER_NAME",     GDA_SERVER_OPERATION_NODE_PARAM, G_TYPE_STRING},
+	{NULL}
+};
+
+
 /**
  * gda_server_provider_create_operation
  * @provider: a #GdaServerProvider object
@@ -477,6 +484,8 @@ gda_server_provider_create_operation (GdaServerProvider *provider, GdaConnection
 
 		op_req_table [GDA_SERVER_OPERATION_COMMENT_TABLE] = op_req_COMMENT_TABLE;
 		op_req_table [GDA_SERVER_OPERATION_COMMENT_COLUMN] = op_req_COMMENT_COLUMN;
+
+		op_req_table [GDA_SERVER_OPERATION_CREATE_USER] = op_req_CREATE_USER;
 	}
 	g_static_mutex_unlock (&init_mutex);
 
diff --git a/providers/postgres/Makefile.am b/providers/postgres/Makefile.am
index da6a176..f015e2d 100644
--- a/providers/postgres/Makefile.am
+++ b/providers/postgres/Makefile.am
@@ -45,7 +45,8 @@ xml_in_files = \
         postgres_specs_add_column.xml.in \
         postgres_specs_drop_column.xml.in \
         postgres_specs_create_view.xml.in \
-        postgres_specs_drop_view.xml.in
+        postgres_specs_drop_view.xml.in \
+	postgres_specs_create_user.xml.in
 
 @INTLTOOL_XML_RULE@
 
diff --git a/providers/postgres/gda-postgres-ddl.c b/providers/postgres/gda-postgres-ddl.c
index 34b9791..19666cc 100644
--- a/providers/postgres/gda-postgres-ddl.c
+++ b/providers/postgres/gda-postgres-ddl.c
@@ -749,3 +749,112 @@ gda_postgres_render_DROP_VIEW (GdaServerProvider *provider, GdaConnection *cnc,
 
 	return sql;
 }
+
+gchar *
+gda_postgres_render_CREATE_USER (GdaServerProvider *provider, GdaConnection *cnc, 
+				 GdaServerOperation *op, GError **error)
+{
+	GString *string;
+	const GValue *value;
+	gchar *sql = NULL;
+	gchar *tmp;
+	gboolean with = FALSE;
+
+	string = g_string_new ("CREATE USER ");
+
+	tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/USER_DEF_P/USER_NAME");
+	g_string_append (string, tmp);
+	g_free (tmp);
+
+	value = gda_server_operation_get_value_at (op, "/USER_DEF_P/PASSWORD");
+	if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) &&
+	    g_value_get_string (value) && (*g_value_get_string (value))) {
+		GdaDataHandler *dh;
+		const GValue *value2;
+
+		g_string_append (string, " WITH");
+		with = TRUE;
+
+		value2 = gda_server_operation_get_value_at (op, "/USER_DEF_P/PASSWORD_ENCRYPTED");
+		if (value2 && G_VALUE_HOLDS (value2, G_TYPE_BOOLEAN) && g_value_get_boolean (value2))
+			g_string_append (string, " ENCRYPTED");
+
+		g_string_append (string, " PASSWORD ");
+		dh = gda_server_provider_get_data_handler_g_type (provider, cnc, G_TYPE_STRING);
+		if (!dh)
+			dh = gda_get_default_handler (G_TYPE_STRING);
+
+		tmp = gda_data_handler_get_sql_from_value (dh, value);
+		g_string_append (string, tmp);
+		g_free (tmp);
+	}
+
+	value = gda_server_operation_get_value_at (op, "/USER_DEF_P/UID");
+	if (value && G_VALUE_HOLDS (value, G_TYPE_UINT)) {
+		if (!with) {
+			g_string_append (string, " WITH");
+			with = TRUE;
+		}
+		g_string_append_printf (string, "SYSID %u", g_value_get_uint (value));
+	}
+
+	value = gda_server_operation_get_value_at (op, "/USER_DEF_P/CAP_CREATEDB");
+	if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value)) {
+		if (!with) {
+			g_string_append (string, " WITH");
+			with = TRUE;
+		}
+		g_string_append (string, " CREATEDB");
+	}
+
+	value = gda_server_operation_get_value_at (op, "/USER_DEF_P/CAP_CREATEUSER");
+	if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value)) {
+		if (!with) {
+			g_string_append (string, " WITH");
+			with = TRUE;
+		}
+		g_string_append (string, " CREATEUSER");
+	}
+	
+	value = gda_server_operation_get_value_at (op, "/USER_DEF_P/GROUPS");
+	if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) &&
+	    g_value_get_string (value) && (*g_value_get_string (value))) {
+		GdaDataHandler *dh;		
+
+		g_string_append (string, " IN GROUP ");
+		dh = gda_server_provider_get_data_handler_g_type (provider, cnc, G_TYPE_STRING);
+		if (!dh)
+			dh = gda_get_default_handler (G_TYPE_STRING);
+
+		tmp = gda_data_handler_get_sql_from_value (dh, value);
+		g_string_append (string, tmp);
+		g_free (tmp);
+	}
+	
+	value = gda_server_operation_get_value_at (op, "/USER_DEF_P/VALIDITY");
+	if (value && G_VALUE_HOLDS (value, GDA_TYPE_TIMESTAMP)) {
+		const GdaTimestamp *ts;
+
+		ts = gda_value_get_timestamp (value);
+		if (value) {
+			GdaDataHandler *dh;
+			if (!with) {
+				g_string_append (string, " WITH");
+				with = TRUE;
+			}
+			dh = gda_server_provider_get_data_handler_g_type (provider, cnc, GDA_TYPE_TIMESTAMP);
+			if (!dh)
+				dh = gda_get_default_handler (GDA_TYPE_TIMESTAMP);
+			
+			g_string_append (string, " VALID UNTIL ");
+			tmp = gda_data_handler_get_sql_from_value (dh, value);
+			g_string_append (string, tmp);
+			g_free (tmp);
+		}
+	}
+
+	sql = string->str;
+	g_string_free (string, FALSE);
+
+	return sql;
+}
diff --git a/providers/postgres/gda-postgres-ddl.h b/providers/postgres/gda-postgres-ddl.h
index b4221ad..b8c0ecd 100644
--- a/providers/postgres/gda-postgres-ddl.h
+++ b/providers/postgres/gda-postgres-ddl.h
@@ -50,6 +50,9 @@ gchar *gda_postgres_render_CREATE_VIEW  (GdaServerProvider *provider, GdaConnect
                                          GdaServerOperation *op, GError **error);
 gchar *gda_postgres_render_DROP_VIEW    (GdaServerProvider *provider, GdaConnection *cnc,
                                          GdaServerOperation *op, GError **error);
+gchar *gda_postgres_render_CREATE_USER  (GdaServerProvider *provider, GdaConnection *cnc,
+                                         GdaServerOperation *op, GError **error);
+
 G_END_DECLS
 
 #endif
diff --git a/providers/postgres/gda-postgres-provider.c b/providers/postgres/gda-postgres-provider.c
index 1966a9f..7587061 100644
--- a/providers/postgres/gda-postgres-provider.c
+++ b/providers/postgres/gda-postgres-provider.c
@@ -702,6 +702,8 @@ gda_postgres_provider_supports_operation (GdaServerProvider *provider, GdaConnec
 
         case GDA_SERVER_OPERATION_CREATE_VIEW:
         case GDA_SERVER_OPERATION_DROP_VIEW:
+
+        case GDA_SERVER_OPERATION_CREATE_USER:
                 return TRUE;
         default:
                 return FALSE;
@@ -822,6 +824,9 @@ gda_postgres_provider_render_operation (GdaServerProvider *provider, GdaConnecti
         case GDA_SERVER_OPERATION_DROP_VIEW:
                 sql = gda_postgres_render_DROP_VIEW (provider, cnc, op, error);
                 break;
+        case GDA_SERVER_OPERATION_CREATE_USER:
+                sql = gda_postgres_render_CREATE_USER (provider, cnc, op, error);
+                break;
         default:
                 g_assert_not_reached ();
         }
diff --git a/providers/postgres/postgres_specs_create_user.xml.in b/providers/postgres/postgres_specs_create_user.xml.in
new file mode 100644
index 0000000..ea18664
--- /dev/null
+++ b/providers/postgres/postgres_specs_create_user.xml.in
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<serv_op>
+  <parameters id="USER_DEF_P" _name="User's definition">
+    <parameter id="USER_NAME" _name="Name" _descr="User's name" gdatype="gchararray" nullok="FALSE"/>
+    <parameter id="PASSWORD" _name="Password" _descr="User's password" gdatype="gchararray" plugin="string:HIDDEN=true"/>
+    <parameter id="PASSWORD_ENCRYPTED" _name="Encrypt password" _descr="Controls whether the password is stored encrypted in the system catalogs. If the presented password string is already in MD5-encrypted format, then it is stored encrypted as-is." gdatype="gboolean">
+      <gda_value>FALSE</gda_value>
+    </parameter>
+
+    <parameter id="UID" _name="User ID" _descr="Can be used to choose the PostgreSQL user ID of the new user" gdatype="guint"/>
+    <parameter id="CAP_CREATEDB" _name="Can create databases" _descr="Set to TRUE if the user is allowed to create databases" gdatype="gboolean">
+      <gda_value>FALSE</gda_value>
+    </parameter>
+    <parameter id="CAP_CREATEUSER" _name="Can create users" _descr="Set to TRUE if the user is allowed to create users" gdatype="gboolean">
+      <gda_value>FALSE</gda_value>
+    </parameter>
+
+    <parameter id="GROUPS" _name="Groups" _descr="Comma separated list of groups the user will belong to" gdatype="gchararray"/>
+
+    <parameter id="VALIDITY" _name="Valid until" _descr="Specifies an expiration time for a password only (not for the user account per se: the expiration time is not enforced when logging in using a non-password-based authentication method)" gdatype="timestamp"/>
+
+  </parameters>
+</serv_op>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]