Changeset: 49d4903a4dff for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=49d4903a4dff
Added Files:
        
sql/jdbc/tests/Tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.SQL.bat
        
sql/jdbc/tests/Tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.SQL.sh
        
sql/jdbc/tests/Tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.stable.err
        
sql/jdbc/tests/Tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.stable.out
Modified Files:
        sql/backends/monet5/sql_upgrades.c
        sql/jdbc/tests/Tests/All
        sql/scripts/25_debug.sql
        sql/scripts/51_sys_schema_extension.sql
        sql/test/Tests/systemfunctions.stable.out
        sql/test/Tests/systemfunctions.stable.out.int128
        sql/test/emptydb/Tests/check.stable.out
        sql/test/emptydb/Tests/check.stable.out.32bit
        sql/test/emptydb/Tests/check.stable.out.int128
        sql/test/leaks/Tests/check1.stable.out.int128
        sql/test/leaks/Tests/check2.stable.out.int128
        sql/test/leaks/Tests/check3.stable.out.int128
        sql/test/leaks/Tests/check4.stable.out.int128
        sql/test/leaks/Tests/check5.stable.out.int128
        sql/test/leaks/Tests/select1.stable.out.int128
        sql/test/leaks/Tests/select2.stable.out.int128
        sql/test/leaks/Tests/temp1.stable.out.int128
Branch: Jul2017
Log Message:

Added GRANT SELECT TO PUBLIC for 8 system tables and 1 system view
and GRANT EXECUTE for 1 system function.
This solves issue reported in bug 6388.


diffs (truncated from 732 to 300 lines):

diff --git a/sql/backends/monet5/sql_upgrades.c 
b/sql/backends/monet5/sql_upgrades.c
--- a/sql/backends/monet5/sql_upgrades.c
+++ b/sql/backends/monet5/sql_upgrades.c
@@ -327,7 +327,7 @@ create function sys.\"epoch\"(ts TIMESTA
        pos += snprintf(buf + pos, bufsize - pos,
                        "insert into sys.systemfunctions (select id from 
sys.functions where name = 'epoch' and schema_id = (select id from sys.schemas 
where name = 'sys') and id not in (select function_id from 
sys.systemfunctions));\n");
 
-       if (schema) 
+       if (schema)
                pos += snprintf(buf + pos, bufsize - pos, "set schema 
\"%s\";\n", schema);
 
        assert(pos < bufsize);
@@ -548,7 +548,7 @@ sql_update_jun2016(Client c, mvc *sql)
        pos += snprintf(buf + pos, bufsize - pos,
                        "delete from sys.systemfunctions where function_id not 
in (select id from sys.functions);\n");
 
-       if (schema) 
+       if (schema)
                pos += snprintf(buf + pos, bufsize - pos, "set schema 
\"%s\";\n", schema);
 
        assert(pos < bufsize);
@@ -596,7 +596,7 @@ sql_update_geom(Client c, mvc *sql, int 
                        pos += snprintf(buf + pos, bufsize - pos, "insert into 
sys.types values (%d, '%s', '%s', %u, %u, %d, %d, %d);\n", t->base.id, 
t->base.name, t->sqlname, t->digits, t->scale, t->radix, t->eclass, t->s ? 
t->s->base.id : s->base.id);
        }
 
-       if (schema) 
+       if (schema)
                pos += snprintf(buf + pos, bufsize - pos, "set schema 
\"%s\";\n", schema);
 
        assert(pos < bufsize);
@@ -813,7 +813,7 @@ sql_update_dec2016(Client c, mvc *sql)
        pos += snprintf(buf + pos, bufsize - pos,
                        "delete from systemfunctions where function_id not in 
(select id from functions);\n");
 
-       if (schema) 
+       if (schema)
                pos += snprintf(buf + pos, bufsize - pos, "set schema 
\"%s\";\n", schema);
 
        assert(pos < bufsize);
@@ -887,7 +887,7 @@ sql_update_nowrd(Client c, mvc *sql)
        pos += snprintf(buf + pos, bufsize - pos,
                        "delete from systemfunctions where function_id not in 
(select id from functions);\n");
 
-       if (schema) 
+       if (schema)
                pos += snprintf(buf + pos, bufsize - pos, "set schema 
\"%s\";\n", schema);
 
        assert(pos < bufsize);
@@ -1338,7 +1338,9 @@ sql_update_dec2016_sp3(Client c, mvc *sq
        char *buf = GDKmalloc(bufsize), *err = NULL;
        char *schema = stack_get_string(sql, "current_schema");
 
-       pos += snprintf(buf + pos, bufsize - pos, 
+       if (buf == NULL)
+               throw(SQL, "sql_update_dec2016_sp3", MAL_MALLOC_FAIL);
+       pos += snprintf(buf + pos, bufsize - pos,
                        "set schema \"sys\";\n"
                        "drop procedure sys.settimeout(bigint);\n"
                        "drop procedure sys.settimeout(bigint,bigint);\n"
@@ -1348,7 +1350,7 @@ sql_update_dec2016_sp3(Client c, mvc *sq
                        "create procedure sys.setsession(\"timeout\" bigint) 
external name clients.setsession;\n"
                        "insert into sys.systemfunctions (select id from 
sys.functions where name in ('settimeout', 'setsession') and schema_id = 
(select id from sys.schemas where name = 'sys') and id not in (select 
function_id from sys.systemfunctions));\n"
                        "delete from systemfunctions where function_id not in 
(select id from functions);\n");
-       if (schema) 
+       if (schema)
                pos += snprintf(buf + pos, bufsize - pos, "set schema 
\"%s\";\n", schema);
        assert(pos < bufsize);
 
@@ -1369,7 +1371,7 @@ sql_update_jul2017(Client c, mvc *sql)
        BAT *b;
 
        if( buf== NULL)
-               throw(SQL, "sql_default", MAL_MALLOC_FAIL);
+               throw(SQL, "sql_update_jul2017", MAL_MALLOC_FAIL);
        pos += snprintf(buf + pos, bufsize - pos, "set schema \"sys\";\n");
 
        pos += snprintf(buf + pos, bufsize - pos,
@@ -1476,6 +1478,54 @@ sql_update_jul2017(Client c, mvc *sql)
        return err;             /* usually MAL_SUCCEED */
 }
 
+static str
+sql_update_jul2017_sp2(Client c)
+{
+       char *qry = "select obj_id from sys.privileges where auth_id = 1 and 
obj_id in (select id from sys._tables where name in ('keywords', 'table_types', 
'dependency_types', 'function_types', 'function_languages', 'key_types', 
'index_types', 'privilege_codes', 'environment')) and privileges = 1;\n";
+       char *err = NULL;
+       res_table *output;
+       BAT *b;
+
+       err = SQLstatementIntern(c, &qry, "update", 1, 0, &output);
+       if (err) {
+               return err;
+       }
+
+       b = BATdescriptor(output->cols[0].b);
+       if (b) {
+               if (BATcount(b) < 9) {
+                       /* we are missing grants on these system tables, add 
them */
+                       size_t bufsize = 2048, pos = 0;
+                       char *buf = GDKmalloc(bufsize);
+
+                       if (buf== NULL)
+                               throw(SQL, "sql_update_jul2017_sp2", 
MAL_MALLOC_FAIL);
+
+                       /* 51_sys_schema_extensions.sql and 25_debug.sql */
+                       pos += snprintf(buf + pos, bufsize - pos,
+                               "GRANT SELECT ON sys.keywords TO PUBLIC;\n"
+                               "GRANT SELECT ON sys.table_types TO PUBLIC;\n"
+                               "GRANT SELECT ON sys.dependency_types TO 
PUBLIC;\n"
+                               "GRANT SELECT ON sys.function_types TO 
PUBLIC;\n"
+                               "GRANT SELECT ON sys.function_languages TO 
PUBLIC;\n"
+                               "GRANT SELECT ON sys.key_types TO PUBLIC;\n"
+                               "GRANT SELECT ON sys.index_types TO PUBLIC;\n"
+                               "GRANT SELECT ON sys.privilege_codes TO 
PUBLIC;\n"
+                               "GRANT EXECUTE ON FUNCTION sys.environment() TO 
PUBLIC;\n"
+                               "GRANT SELECT ON sys.environment TO PUBLIC;\n"
+                               );
+                       assert(pos < bufsize);
+                       printf("Running database upgrade commands:\n%s\n", buf);
+                       err = SQLstatementIntern(c, &buf, "update", 1, 0, NULL);
+                       GDKfree(buf);
+               }
+               BBPunfix(b->batCacheid);
+       }
+       res_tables_destroy(output);
+
+       return err;             /* usually NULL */
+}
+
 void
 SQLupgrades(Client c, mvc *m)
 {
@@ -1603,4 +1653,9 @@ SQLupgrades(Client c, mvc *m)
                        freeException(err);
                }
        }
+
+       if ((err = sql_update_jul2017_sp2(c)) != NULL) {
+               fprintf(stderr, "!%s\n", err);
+               freeException(err);
+       }
 }
diff --git a/sql/jdbc/tests/Tests/All b/sql/jdbc/tests/Tests/All
--- a/sql/jdbc/tests/Tests/All
+++ b/sql/jdbc/tests/Tests/All
@@ -38,3 +38,4 @@ HAVE_JDBCTESTS?BugSetQueryTimeout_Bug_33
 HAVE_JDBCTESTS?BugDecimalRound_Bug_3561
 HAVE_JDBCTESTS?BugResultSetMetaData_Bug_6183
 HAVE_JDBCTESTS?Bug_PrepStmtSetObject_CLOB_6349
+HAVE_JDBCTESTS?Bug_Connect_as_voc_getMetaData_Failure_Bug_6388
diff --git 
a/sql/jdbc/tests/Tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.SQL.bat 
b/sql/jdbc/tests/Tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.SQL.bat
new file mode 100755
--- /dev/null
+++ 
b/sql/jdbc/tests/Tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.SQL.bat
@@ -0,0 +1,1 @@
+@call "%TSTSRCDIR%\Test.SQL.bat" %*
diff --git 
a/sql/jdbc/tests/Tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.SQL.sh 
b/sql/jdbc/tests/Tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.SQL.sh
new file mode 100755
--- /dev/null
+++ 
b/sql/jdbc/tests/Tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.SQL.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+$TSTSRCDIR/Test.SQL.sh $*
diff --git 
a/sql/jdbc/tests/Tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.stable.err
 
b/sql/jdbc/tests/Tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.stable.err
new file mode 100644
--- /dev/null
+++ 
b/sql/jdbc/tests/Tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.stable.err
@@ -0,0 +1,41 @@
+stderr of test 'Bug_Connect_as_voc_getMetaData_Failure_Bug_6388` in directory 
'sql/jdbc/tests` itself:
+
+
+# 16:57:20 >  
+# 16:57:20 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=35703" "--set" 
"mapi_usock=/var/tmp/mtest-30293/.s.monetdb.35703" "--set" "monet_prompt=" 
"--forcemito" 
"--dbpath=/export/scratch2/dinther/INSTALL/var/MonetDB/mTests_sql_jdbc_tests" 
"--set" "embedded_r=yes" "--set" "embedded_py=true"
+# 16:57:20 >  
+
+# builtin opt  gdk_dbpath = 
/export/scratch1/dinther/INSTALL/var/monetdb5/dbfarm/demo
+# builtin opt  gdk_debug = 0
+# builtin opt  gdk_vmtrim = no
+# builtin opt  monet_prompt = >
+# builtin opt  monet_daemon = no
+# builtin opt  mapi_port = 50000
+# builtin opt  mapi_open = false
+# builtin opt  mapi_autosense = false
+# builtin opt  sql_optimizer = default_pipe
+# builtin opt  sql_debug = 0
+# cmdline opt  gdk_nr_threads = 0
+# cmdline opt  mapi_open = true
+# cmdline opt  mapi_port = 35703
+# cmdline opt  mapi_usock = /var/tmp/mtest-30293/.s.monetdb.35703
+# cmdline opt  monet_prompt = 
+# cmdline opt  gdk_dbpath = 
/export/scratch1/dinther/INSTALL/var/MonetDB/mTests_sql_jdbc_tests
+# cmdline opt  embedded_r = yes
+# cmdline opt  embedded_py = true
+# cmdline opt  gdk_debug = 536870922
+
+# 16:57:21 >  
+# 16:57:21 >  "./Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.SQL.sh" 
"Bug_Connect_as_voc_getMetaData_Failure_Bug_6388"
+# 16:57:21 >  
+
+
+# 16:57:21 >  
+# 16:57:21 >  java Bug_Connect_as_voc_getMetaData_Failure_Bug_6388 
"jdbc:monetdb://toulouse:35703/mTests_sql_jdbc_tests?user=monetdb&password=monetdb"
+# 16:57:21 >  
+
+
+# 16:57:22 >  
+# 16:57:22 >  "Done."
+# 16:57:22 >  
+
diff --git 
a/sql/jdbc/tests/Tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.stable.out
 
b/sql/jdbc/tests/Tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.stable.out
new file mode 100644
--- /dev/null
+++ 
b/sql/jdbc/tests/Tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.stable.out
@@ -0,0 +1,122 @@
+stdout of test 'Bug_Connect_as_voc_getMetaData_Failure_Bug_6388` in directory 
'sql/jdbc/tests` itself:
+
+
+# 16:57:20 >  
+# 16:57:20 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=35703" "--set" 
"mapi_usock=/var/tmp/mtest-30293/.s.monetdb.35703" "--set" "monet_prompt=" 
"--forcemito" 
"--dbpath=/export/scratch1/dinther/INSTALL/var/MonetDB/mTests_sql_jdbc_tests" 
"--set" "embedded_r=yes" "--set" "embedded_py=true"
+# 16:57:20 >  
+
+# MonetDB 5 server v11.27.5
+# Serving database 'mTests_sql_jdbc_tests', using 8 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 128bit integers
+# Found 15.588 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2017 MonetDB B.V., all rights reserved
+# Visit https://www.monetdb.org/ for further information
+# Listening for connection requests on mapi:monetdb://toulouse.da.cwi.nl:35703/
+# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-30293/.s.monetdb.35703
+# MonetDB/GIS module loaded
+# MonetDB/SQL module loaded
+# MonetDB/Python2 module loaded
+# MonetDB/R   module loaded
+
+Ready.
+# SQL catalog created, loading sql scripts once
+# loading sql script: 09_like.sql
+# loading sql script: 10_math.sql
+# loading sql script: 11_times.sql
+# loading sql script: 12_url.sql
+# loading sql script: 13_date.sql
+# loading sql script: 14_inet.sql
+# loading sql script: 15_querylog.sql
+# loading sql script: 16_tracelog.sql
+# loading sql script: 17_temporal.sql
+# loading sql script: 18_index.sql
+# loading sql script: 20_vacuum.sql
+# loading sql script: 21_dependency_functions.sql
+# loading sql script: 22_clients.sql
+# loading sql script: 23_skyserver.sql
+# loading sql script: 25_debug.sql
+# loading sql script: 26_sysmon.sql
+# loading sql script: 27_rejects.sql
+# loading sql script: 39_analytics.sql
+# loading sql script: 39_analytics_hge.sql
+# loading sql script: 40_geom.sql
+# loading sql script: 40_json.sql
+# loading sql script: 40_json_hge.sql
+# loading sql script: 41_md5sum.sql
+# loading sql script: 45_uuid.sql
+# loading sql script: 46_profiler.sql
+# loading sql script: 51_sys_schema_extension.sql
+# loading sql script: 60_wlcr.sql
+# loading sql script: 72_fits.sql
+# loading sql script: 74_netcdf.sql
+# loading sql script: 75_lidar.sql
+# loading sql script: 75_shp.sql
+# loading sql script: 75_storagemodel.sql
+# loading sql script: 80_statistics.sql
+# loading sql script: 80_udf.sql
+# loading sql script: 80_udf_hge.sql
+# loading sql script: 85_bam.sql
+# loading sql script: 90_generator.sql
+# loading sql script: 90_generator_hge.sql
+# loading sql script: 99_system.sql
+
+# 16:57:21 >  
+# 16:57:21 >  "./Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.SQL.sh" 
"Bug_Connect_as_voc_getMetaData_Failure_Bug_6388"
+# 16:57:21 >  
+
+
+# 16:57:21 >  
+# 16:57:21 >  java Bug_Connect_as_voc_getMetaData_Failure_Bug_6388 
"jdbc:monetdb://toulouse:35703/mTests_sql_jdbc_tests?user=monetdb&password=monetdb"
+# 16:57:21 >  
+
+1. CREATE USER voc
+2. CREATE SCHEMA voc
+3. ALTER USER voc
+creation succeeded :)
+4.1. connect as user: voc
+connected :)
+4.2. getUserName()
+UserName = voc
+4.3. getMaxConnections()
+MaxConnections = 64
+4.4. getDatabaseProductVersion()
+DatabaseProductVersion = 11.27.+
+4.5. getDatabaseMajorVersion()
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to