Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 27 additions & 59 deletions cdb2api/cdb2api.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ static int cdb2_iam_identity_set_from_env = 0;

static int donate_unused_connections = 1; /* on by default */
static int cdb2_donate_unused_connections_set_from_env = 0;
/* Fix last set repeat, disable if this breaks anything */
static int disable_fix_last_set = 0;
static int cdb2_disable_fix_last_set_set_from_env = 0;

/* Skip dbinfo query if sockpool provides connection */
static int get_dbinfo = 0;
Expand Down Expand Up @@ -1618,6 +1621,8 @@ static void read_comdb2db_environment_cfg(cdb2_hndl_tp *hndl, const char *comdb2
process_env_var_str_on_off("COMDB2_FEATURE_IAM_IDENTITY", &iam_identity, &cdb2_iam_identity_set_from_env);
process_env_var_str_on_off("COMDB2_FEATURE_DONATE_UNUSED_CONNECTIONS", &donate_unused_connections,
&cdb2_donate_unused_connections_set_from_env);
process_env_var_str_on_off("COMDB2_FEATURE_DISABLE_FIX_LAST_SET", &disable_fix_last_set,
&cdb2_disable_fix_last_set_set_from_env);
process_env_var_str_on_off("COMDB2_FEATURE_USE_FTRUNCATE", &cdb2_use_ftruncate,
&cdb2_use_ftruncate_set_from_env);
process_env_var_str("COMDB2_CONFIG_ROOM", (char *)&cdb2_machine_room, sizeof(cdb2_machine_room),
Expand Down Expand Up @@ -1788,6 +1793,9 @@ static void read_comdb2db_cfg(cdb2_hndl_tp *hndl, SBUF2 *s, const char *comdb2db
tok = strtok_r(NULL, " =:,", &last);
if (tok)
donate_unused_connections = value_on_off(tok, &err);
} else if (!cdb2_disable_fix_last_set_set_from_env && (strcasecmp("disable_fix_last_set", tok) == 0)) {
tok = strtok_r(NULL, " =:,", &last);
disable_fix_last_set = value_on_off(tok, &err);
} else if (!cdb2_use_ftruncate_set_from_env && (strcasecmp("use_ftruncate", tok) == 0)) {
tok = strtok_r(NULL, " =:,", &last);
if (tok)
Expand Down Expand Up @@ -5552,8 +5560,12 @@ static void process_set_local(cdb2_hndl_tp *hndl, const char *set_command)
p += sizeof("TRANSACTION");
cdb2_skipws(p);
// only set is chunk to true, don't set to false here
if (strncasecmp(p, "chunk", 5) == 0)
hndl->is_chunk = CHUNK_IN_PROGRESS;
if (strncasecmp(p, "chunk", 5) == 0) {
p += sizeof("CHUNK");
cdb2_skipws(p);
if (strncasecmp(p, "throttle", 8) != 0)
hndl->is_chunk = CHUNK_IN_PROGRESS;
}
return;
}
}
Expand Down Expand Up @@ -5769,8 +5781,6 @@ static int process_set_stmt_return_types(cdb2_hndl_tp *hndl, const char *sql)

static int process_set_command(cdb2_hndl_tp *hndl, const char *sql)
{
int i, j, k;

hndl->is_set = 1;
if (hndl->in_trans) {
sprintf(hndl->errstr, "Can't run set query inside transaction.");
Expand All @@ -5785,73 +5795,31 @@ static int process_set_command(cdb2_hndl_tp *hndl, const char *sql)
if ((rc = process_set_stmt_return_types(hndl, sql)) >= 0)
return rc;

int i, j, k;
i = hndl->num_set_commands;
if (i > 0) {
int skip_len = 4;
char *dup_sql = strdup(sql + skip_len);
char *rest = NULL;
char *set_tok = strtok_r(dup_sql, " ", &rest);
if (set_tok) {
/* special case for spversion */
if (strcasecmp(set_tok, "spversion") == 0) {
skip_len += 10;
set_tok = strtok_r(rest, " ", &rest);
/* special case for transaction chunk */
} else if (strncasecmp(set_tok, "transaction", 11) == 0) {
char *set_tok2 = strtok_r(rest, " ", &rest);
if (set_tok2 && strncasecmp(set_tok2, "chunk", 5) == 0) {
/* skip "transaction" if chunk, set we can set
* both transaction and chunk mode
*/
skip_len += 12;
set_tok = set_tok2;
set_tok2 = NULL;
hndl->is_chunk = CHUNK_IN_PROGRESS;
}
} else if (strncasecmp(set_tok, "partition", 9) == 0) {
skip_len += 10;
set_tok = strtok_r(rest, " ", &rest);
}
}
if (!set_tok) {
free(dup_sql);
return 0;
}
int len = strlen(set_tok);

for (j = 0; j < i; j++) {
/* If this matches any of the previous commands. */
if ((strncasecmp(&hndl->commands[j][skip_len], set_tok, len) ==
0) &&
(hndl->commands[j][len + skip_len] == ' ')) {
free(dup_sql);
if ((strcmp(hndl->commands[j], sql) == 0)) {
if (j == (i - 1)) {
if (strcmp(hndl->commands[j], sql) == 0) {
/* Do Nothing. */
} else {
hndl->commands[i - 1] =
realloc(hndl->commands[i - 1], strlen(sql) + 1);
strcpy(hndl->commands[i - 1], sql);
}
} else {
char *cmd = hndl->commands[j];
/* Move all the commands down the array. */
for (k = j; k < i - 1; k++) {
hndl->commands[k] = hndl->commands[k + 1];
}
if (strcmp(cmd, sql) == 0) {
hndl->commands[i - 1] = cmd;
} else {
hndl->commands[i - 1] = realloc(cmd, strlen(sql) + 1);
strcpy(hndl->commands[i - 1], sql);
/* Do Nothing; But send the set again!. */
if (!disable_fix_last_set) {
if (hndl->num_set_commands_sent)
hndl->num_set_commands_sent--;
}
return 0;
}
char *cmd = hndl->commands[j];
/* Move all the commands down the array. */
for (k = j; k < i - 1; k++) {
hndl->commands[k] = hndl->commands[k + 1];
}
hndl->commands[i - 1] = cmd;
if (hndl->num_set_commands_sent)
hndl->num_set_commands_sent--;
return 0;
}
}
free(dup_sql);
}
hndl->num_set_commands++;
hndl->commands =
Expand Down
1 change: 1 addition & 0 deletions tests/auth.test/t10.0.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[select 1] failed with rc -106 access denied
3 changes: 3 additions & 0 deletions tests/auth.test/t10.0.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set user ""
set password ""
select 1
1 change: 1 addition & 0 deletions tests/auth.test/t10.1.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[select 1] failed with rc -3 set user: '"' is an incorrectly quoted string
3 changes: 3 additions & 0 deletions tests/auth.test/t10.1.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set user "
set password "
select 1
1 change: 1 addition & 0 deletions tests/auth.test/t10.2.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[select 1] failed with rc -106 access denied
3 changes: 3 additions & 0 deletions tests/auth.test/t10.2.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set user ''
set password ''
select 1
1 change: 1 addition & 0 deletions tests/auth.test/t10.3.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[select 1] failed with rc -3 set user: ''' is an incorrectly quoted string
3 changes: 3 additions & 0 deletions tests/auth.test/t10.3.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set user '
set password '
select 1
1 change: 1 addition & 0 deletions tests/auth.test/t10.4.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[select 1] failed with rc -3 set user: ''test' is an incorrectly quoted string
3 changes: 3 additions & 0 deletions tests/auth.test/t10.4.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set user 'test
set password 'test
select 1
1 change: 1 addition & 0 deletions tests/auth.test/t10.5.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[select 1] failed with rc -3 set user: '"test' is an incorrectly quoted string
3 changes: 3 additions & 0 deletions tests/auth.test/t10.5.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set user "test
set password "test
select 1
1 change: 1 addition & 0 deletions tests/auth.test/t10.6.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[select 1] failed with rc -3 set user: ''test"' is an incorrectly quoted string
3 changes: 3 additions & 0 deletions tests/auth.test/t10.6.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set user 'test"
set password 'test"
select 1
1 change: 1 addition & 0 deletions tests/auth.test/t10.7.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[select 1] failed with rc -3 set user: '"test'' is an incorrectly quoted string
3 changes: 3 additions & 0 deletions tests/auth.test/t10.7.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set user "test'
set password "test'
select 1
5 changes: 5 additions & 0 deletions tests/auth.test/t10.8.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[select 1] failed with rc -106 access denied
[select 1] failed with rc -106 access denied
[select 1] failed with rc -106 access denied
[select 1] failed with rc -106 access denied
[select 1] failed with rc -106 access denied
15 changes: 15 additions & 0 deletions tests/auth.test/t10.8.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set user 'test'
set password 'test'
select 1
set user t'est
set password t'est
select 1
set user t"est
set password t"est
select 1
set user test'
set password test'
select 1
set user test"
set password test"
select 1
13 changes: 0 additions & 13 deletions tests/auth.test/t10.expected

This file was deleted.

39 changes: 0 additions & 39 deletions tests/auth.test/t10.req

This file was deleted.

1 change: 1 addition & 0 deletions tests/cdb2api.test/t34.0.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[select 1] failed with rc -3 Invalid set command 'invalid'
4 changes: 4 additions & 0 deletions tests/cdb2api.test/t34.0.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set readonly on
set transaction invalid
# should get an error on this
select 1
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[select 1] failed with rc -3 Invalid set command 'invalid'
(1=1)
[INSERT INTO t1 (x,y,z,w) VALUES (1,2,3,4)] failed with rc -21 connection/database in read-only mode
[INSERT INTO t1 (x,y,z,w) VALUES (1,2,3,4)] failed with rc 299 add key constraint duplicate key 'KEY' on table 't1' index 0
5 changes: 0 additions & 5 deletions tests/cdb2api.test/t34.req → tests/cdb2api.test/t34.1.req
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
set readonly on
set transaction invalid
# should get an error on this
select 1

#this should override earlier set command
set transaction blocksql
select 1

Expand Down
2 changes: 1 addition & 1 deletion tests/simple_remsql.test/t8_13.req.exp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[SELECT 1] failed with rc -3 Invalid set command 'READ'
(1=1)
[SELECT 1] failed with rc -3 Invalid set command 'READ'
4 changes: 2 additions & 2 deletions tests/simple_remsql.test/t8_13.req.src
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SET REMOTE READ
SELECT 1
SET REMOTE READ DUMMY
SELECT 1
SET REMOTE READ
SELECT 1
2 changes: 1 addition & 1 deletion tests/userschema.test/runit
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ for testreq in `ls t*.req` ; do
# First drop the table (its ok if this fails,
# the table probably doesn't exist).
# Then add the table.
testname=`echo $testreq | cut -d "." -f 1`
testname=${testreq%.*}
echo preparing db for $testname
for schema in `ls $testname.*.csc2 2> /dev/null` ; do
table=`echo $schema | cut -d "." -f2`
Expand Down
16 changes: 16 additions & 0 deletions tests/userschema.test/t09.0.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[select * from test] failed with rc -106 access denied
[select * from comdb2_tablepermissions order by tablename] failed with rc -106 access denied
(t=2)
(t=2)
(t=2)
(t=2)
(tablename='forecast@dcba', username='abcd', READ='N', WRITE='N', DDL='N')
(tablename='forecast@dcba', username='dcba', READ='Y', WRITE='Y', DDL='Y')
(tablename='forecast@dcba', username='mohit', READ='Y', WRITE='Y', DDL='Y')
(tablename='test@dcba', username='abcd', READ='N', WRITE='N', DDL='N')
(tablename='test@dcba', username='dcba', READ='Y', WRITE='Y', DDL='Y')
(tablename='test@dcba', username='mohit', READ='Y', WRITE='Y', DDL='Y')
[select * from test] failed with rc -106 access denied
[select * from comdb2_tablepermissions order by tablename] failed with rc -106 access denied
[select * from test] failed with rc -3 set user: '1234567890123456' exceeds 15 characters
[select * from comdb2_tablepermissions order by tablename] failed with rc -3 set user: '1234567890123456' exceeds 15 characters
17 changes: 17 additions & 0 deletions tests/userschema.test/t09.0.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
select * from test
select * from comdb2_tablepermissions order by tablename

set user dcba
set password dcba
select * from test
select * from comdb2_tablepermissions order by tablename

set user garbage garbazh
set password garbaj garbanj
select * from test
select * from comdb2_tablepermissions order by tablename

set user 1234567890123456
set password 1234567890123456789
select * from test
select * from comdb2_tablepermissions order by tablename
2 changes: 2 additions & 0 deletions tests/userschema.test/t09.1.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[select * from test] failed with rc -3 set password: password length exceeds 18 characters
[select * from comdb2_tablepermissions order by tablename] failed with rc -3 set password: password length exceeds 18 characters
4 changes: 4 additions & 0 deletions tests/userschema.test/t09.1.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set user 123456789012345
set password 1234567890123456789
select * from test
select * from comdb2_tablepermissions order by tablename
2 changes: 2 additions & 0 deletions tests/userschema.test/t09.2.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[select * from test] failed with rc -3 set user: '1234567890123456' exceeds 15 characters
[select * from comdb2_tablepermissions order by tablename] failed with rc -3 set user: '1234567890123456' exceeds 15 characters
4 changes: 4 additions & 0 deletions tests/userschema.test/t09.2.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set user 1234567890123456
set password 123456789012345678
select * from test
select * from comdb2_tablepermissions order by tablename
2 changes: 2 additions & 0 deletions tests/userschema.test/t09.3.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[select * from test] failed with rc -3 set user: '1234567890123456' exceeds 15 characters
[select * from comdb2_tablepermissions order by tablename] failed with rc -3 set user: '1234567890123456' exceeds 15 characters
4 changes: 4 additions & 0 deletions tests/userschema.test/t09.3.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set user "1234567890123456"
set password "1234567890123456789"
select * from test
select * from comdb2_tablepermissions order by tablename
2 changes: 2 additions & 0 deletions tests/userschema.test/t09.4.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[select * from test] failed with rc -3 set password: password length exceeds 18 characters
[select * from comdb2_tablepermissions order by tablename] failed with rc -3 set password: password length exceeds 18 characters
4 changes: 4 additions & 0 deletions tests/userschema.test/t09.4.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set user "123456789012345"
set password "1234567890123456789"
select * from test
select * from comdb2_tablepermissions order by tablename
2 changes: 2 additions & 0 deletions tests/userschema.test/t09.5.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[select * from test] failed with rc -3 set user: '1234567890123456' exceeds 15 characters
[select * from comdb2_tablepermissions order by tablename] failed with rc -3 set user: '1234567890123456' exceeds 15 characters
4 changes: 4 additions & 0 deletions tests/userschema.test/t09.5.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set user "1234567890123456"
set password "123456789012345678"
select * from test
select * from comdb2_tablepermissions order by tablename
9 changes: 9 additions & 0 deletions tests/userschema.test/t09.6.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(comdb2_user()='mohit')
[put password '1234567890123456789' for '1234567890123456'] failed with rc -3 Password is too long
[put password '1234567890123456789' for '123456789012345'] failed with rc -3 Password is too long
[put password '123456789012345678' for '1234567890123456'] failed with rc -3 User name is too long
(username='123456789012345', isOP='Y')
(username='abcd', isOP='N')
(username='dcba', isOP='N')
(username='mohit', isOP='Y')
[select 1] failed with rc -3 set user: '1234567890123456' exceeds 15 characters
Loading