[Greater-commits] r303 - trunk/GREAT-ER-DB/impl/postgresql
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Jun 29 15:13:34 CEST 2011
Author: bricks
Date: 2011-06-29 15:13:33 +0200 (Wed, 29 Jun 2011)
New Revision: 303
Modified:
trunk/GREAT-ER-DB/impl/postgresql/gdagreater_pg.pgc
Log:
Implement lda_strtolower and lda_strtoupper functions to be able to convert strings
before connecting to the db
Use uppercase letters for variables which contain user_id for greater tables
and user lowercase letters for variables that contain the login db user_id
Modified: trunk/GREAT-ER-DB/impl/postgresql/gdagreater_pg.pgc
===================================================================
--- trunk/GREAT-ER-DB/impl/postgresql/gdagreater_pg.pgc 2011-06-29 12:56:13 UTC (rev 302)
+++ trunk/GREAT-ER-DB/impl/postgresql/gdagreater_pg.pgc 2011-06-29 13:13:33 UTC (rev 303)
@@ -45,6 +45,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <ctype.h>
#include <time.h>
@@ -82,6 +83,32 @@
/**************************************************************************
* LIBRARY INTERAL (LOCAL) FUNCTIONS
**************************************************************************/
+
+void lda_strntoupper(char * dest, const char * source, int length) {
+ int i;
+
+ for (i = 0; i < length; i++) {
+ dest[i] = toupper(source[i]);
+ }
+ dest[length] = '\0';
+}
+
+void lda_strtoupper(char * dest, const char *source) {
+ lda_strntoupper(dest, source, strlen(source));
+}
+
+void lda_strntolower(char * dest, const char *source, int length) {
+ int i;
+
+ for (i = 0; i < length; i++) {
+ dest[i] = tolower(source[i]);
+ }
+ dest[length] = '\0';
+}
+
+void lda_strtolower(char * dest, const char *source) {
+ lda_strntolower(dest, source, strlen(source));
+}
/*********************************************************************
* Name : lda_init_debug_info
*
@@ -344,6 +371,9 @@
long vp_data_privs)
{
+ char h_user_id[31];
+ lda_strtolower(h_user_id, vp_data_user_id);
+
/* ----------------- *
* start of function
* ----------------- */
@@ -362,8 +392,8 @@
/* current db-user is GREAT-ER table owner => Acc right.: VIEW/EDIT */
return(DA_A_VIEWEDIT);
}
-
- if (strcmp(vg_db_user_info.user_id, vp_data_user_id) == 0)
+ // vg_db_user_info.user_id must be lowercase
+ if (strcmp(vg_db_user_info.user_id, h_user_id) == 0)
{
/* ------------------------------------------------- *
* 2) DATA OWNER = <current DB user>
@@ -4082,7 +4112,7 @@
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO not_a_valid_db_user;
- strcpy(h_user_id, db_con->user_id);
+ lda_strtolower(h_user_id, db_con->user_id);
strcpy(h_usrid_passwd, db_con->user_passwd);
strcpy(h_con_name, db_con->con_name);
strcpy(h_dbname, db_con->connection_target);
@@ -4116,9 +4146,10 @@
EXEC SQL SELECT GROUP_ID
INTO :h_group_id
FROM USER_TAB
- WHERE USER_ID = :h_user_id;
+ WHERE USER_ID = UPPER(:h_user_id);
- strcpy(vg_db_user_info.user_id, h_user_id);
+ // vg_db_user_info.user_id must be lowercase
+ lgda_strtolower(vg_db_user_info.user_id, h_user_id);
vg_db_user_info.group_id = h_group_id;
vg_db_user_info.admin = 0;
@@ -4263,7 +4294,7 @@
/* database connect descriptor specified */
strcpy(dbname, vp_connect_descr);
- strcpy(h_user_id, vp_userid);
+ lda_strtolower(h_user_id, vp_userid);
strcpy(h_usrid_passwd, vp_passwd);
strcpy(h_con_name, db_con->con_name);
@@ -4279,23 +4310,17 @@
* it is then set global with information about connected user
* if user is table owner, then set administration rights; this
* is only done inside this special connect method ! */
- strcpy(h_user_id, vp_userid);
errln = 20;
EXEC SQL WHENEVER NOT FOUND GOTO not_a_valid_user;
- errln = 30;
- EXEC SQL SELECT UPPER(:h_user_id)
- INTO :h_user_id INDICATOR :h_ind_user_id;
-
-
errln = 40;
EXEC SQL SELECT GROUP_ID
INTO :h_group_id
FROM USER_TAB
WHERE USER_ID = UPPER(:h_user_id);
-
- strcpy(vg_db_user_info.user_id, h_user_id);
+ // vg_db_user_info.user_id must be lowercase
+ lda_strtolower(vg_db_user_info.user_id, h_user_id);
vg_db_user_info.group_id = h_group_id;
vg_db_user_info.admin = 0;
@@ -4674,14 +4699,15 @@
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
+ lda_strtolower(h_user_id, vp_userid);
+
/* check, if the given user is equal to the connected user */
if (strcmp(vp_userid, vg_db_user_info.user_id) == 0)
{
/* initialise information for change of password */
- strcpy(h_user_id, vp_userid);
strcpy(h_passwd, vp_passwd);
strcpy(h_con_name, db_con->con_name);
- sprintf(sql_statement, "ALTER USER %s IDENTIFIED BY %s",
+ sprintf(sql_statement, "ALTER USER %s PASSWORD '%s'",
h_user_id, h_passwd);
/* set the current db connection */
@@ -5151,7 +5177,7 @@
* copy passed record into host variable
*/
h_catch.privs = vp_catch->privs;
- strcpy (h_catch.user_id , vg_db_user_info.user_id);
+ lda_strtoupper(h_catch.user_id, vg_db_user_info.user_id);
strcpy (h_catch.status , vp_catch->status);
strcpy (h_catch.name , vp_catch->name);
strcpy (h_catch.remark , vp_catch->remark);
@@ -9868,7 +9894,7 @@
h_bin_obj.privs = vp_bin_obj->privs;
strcpy(h_bin_obj.name, vp_bin_obj->name);
- strcpy(h_bin_obj.user_id, vg_db_user_info.user_id);
+ lda_strtoupper(h_bin_obj.user_id, vg_db_user_info.user_id);
strcpy(h_bin_obj.obj_type, vp_bin_obj->obj_type);
strcpy(h_bin_obj.obj_sub_type, vp_bin_obj->obj_sub_type);
strcpy(h_bin_obj.file_type, vp_bin_obj->file_type);
@@ -12134,7 +12160,7 @@
h_sess.temp_sess_db_sid = vp_sess->temp_sess_db_sid;
strcpy(h_sess.name , vp_sess->name);
- strcpy(h_sess.user_id , vg_db_user_info.user_id);
+ lda_strtoupper(h_sess.user_id, vg_db_user_info.user_id);
strcpy(h_sess.status , vp_sess->status);
strcpy(h_sess.is_temp_sess, vp_sess->is_temp_sess);
@@ -12886,7 +12912,7 @@
h_sess.sess_disch_id = -1;
h_sess.privs = 3;
strcpy(h_sess.name , "Unnamed");
- strcpy(h_temp_user_id , vg_db_user_info.user_id);
+ lda_strtoupper(h_temp_user_id, vg_db_user_info.user_id);
strcpy(h_sess.status , "TEMP");
strcpy(h_sess.remark , "");
@@ -12969,7 +12995,7 @@
strcpy(v_sess_buf.remark , h_sess.remark);
v_sess_buf.next_element = NULL;
- strcpy(h_temp_user_id, vg_db_user_info.user_id);
+ lda_strtoupper(h_temp_user_id, vg_db_user_info.user_id);
/*
* check if source session is already marked as temp. session
@@ -13713,7 +13739,7 @@
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
- strcpy(h_user_id, vg_db_user_info.user_id);
+ lda_strtoupper(h_user_id, vg_db_user_info.user_id);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
@@ -14388,7 +14414,7 @@
h_sess_disch.disch_class_id = vp_sess_disch->disch_class_id;
h_sess_disch.privs = vp_sess_disch->privs;
strcpy(h_sess_disch.name , vp_sess_disch->name);
- strcpy(h_sess_disch.user_id , vg_db_user_info.user_id);
+ lda_strtoupper(h_sess_disch.user_id, vg_db_user_info.user_id);
strcpy(h_sess_disch.status , vp_sess_disch->status);
strcpy(h_sess_disch.pop , vp_sess_disch->pop);
strcpy(h_sess_disch.dwf , vp_sess_disch->dwf);
@@ -15758,7 +15784,7 @@
h_subst.subst_id = h_subst_id_new;
h_subst.privs = vp_subst->privs;
strcpy (h_subst.name , vp_subst->name);
- strcpy (h_subst.user_id , vg_db_user_info.user_id);
+ lda_strtoupper(h_subst.user_id , vg_db_user_info.user_id);
strcpy (h_subst.status , vp_subst->status);
strcpy (h_subst.is_templ , vp_subst->is_templ);
strcpy (h_subst.remark , vp_subst->remark);
@@ -17434,7 +17460,7 @@
h_env.env_id = h_env_id_new;
h_env.privs = vp_env->privs;
strcpy (h_env.name , vp_env->name);
- strcpy (h_env.user_id , vg_db_user_info.user_id);
+ lda_strtoupper(h_env.user_id , vg_db_user_info.user_id);
strcpy (h_env.status , vp_env->status);
strcpy (h_env.is_templ , vp_env->is_templ);
strcpy (h_env.remark , vp_env->remark);
@@ -19141,7 +19167,7 @@
h_market.catch_id = vp_market->catch_id;
h_market.privs = vp_market->privs;
strcpy(h_market.name , vp_market->name);
- strcpy(h_market.user_id , vg_db_user_info.user_id);
+ lda_strtoupper(h_market.user_id, vg_db_user_info.user_id);
strcpy(h_market.status , vp_market->status);
strcpy(h_market.consumption, vp_market->consumption);
strcpy(h_market.flux_nondom, vp_market->flux_nondom);
@@ -20033,14 +20059,14 @@
INTO :h_mod_id_new,
:h_mod.cre_date,
:h_mod.mod_date;
-
+
/*
* copy passed record into host variable
*/
h_mod.mod_id = h_mod_id_new;
h_mod.privs = vp_mod->privs;
strcpy (h_mod.name , vp_mod->name);
- strcpy (h_mod.user_id , vg_db_user_info.user_id);
+ lda_strtoupper(h_mod.user_id, vg_db_user_info.user_id);
strcpy (h_mod.status , vp_mod->status);
strcpy (h_mod.remark , vp_mod->remark);
More information about the Greater-commits
mailing list