Skip to content

Commit 42732cc

Browse files
Dyre Tjeldvollgipulla
authored andcommitted
Bug#25092566: CREATE TABLE WITH DATA DIRECTORY CLAUSE DOES NOT REQUIRE SPECIAL
PRIVILEGES Require FILE privilege when creating tables using external data directory or index directory.
1 parent 53230ba commit 42732cc

File tree

5 files changed

+59
-3
lines changed

5 files changed

+59
-3
lines changed

mysql-test/r/partition_symlink.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ DROP DATABASE IF EXISTS mysqltest2;
44
# test.t1 have partitions in mysqltest2-directory!
55
# user root:
66
CREATE USER mysqltest_1@localhost;
7+
# Need FILE permission to use external datadir or indexdir.
8+
GRANT FILE ON *.* TO mysqltest_1@localhost;
79
CREATE DATABASE mysqltest2;
810
USE mysqltest2;
911
CREATE TABLE t1 (a INT) ENGINE = MyISAM;

mysql-test/t/partition_symlink.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ DROP DATABASE IF EXISTS mysqltest2;
3232
-- echo # test.t1 have partitions in mysqltest2-directory!
3333
-- echo # user root:
3434
CREATE USER mysqltest_1@localhost;
35+
-- echo # Need FILE permission to use external datadir or indexdir.
36+
GRANT FILE ON *.* TO mysqltest_1@localhost;
3537
CREATE DATABASE mysqltest2;
3638
USE mysqltest2;
3739
CREATE TABLE t1 (a INT) ENGINE = MyISAM;

sql/partition_info.cc

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -2550,6 +2550,30 @@ void partition_info::print_debug(const char *str, uint *value)
25502550
DBUG_PRINT("info", ("parser: %s", str));
25512551
DBUG_VOID_RETURN;
25522552
}
2553+
2554+
bool has_external_data_or_index_dir(partition_info &pi)
2555+
{
2556+
List_iterator<partition_element> part_it(pi.partitions);
2557+
for (partition_element *part= part_it++; part; part= part_it++)
2558+
{
2559+
if (part->data_file_name != NULL || part->index_file_name != NULL)
2560+
{
2561+
return true;
2562+
}
2563+
List_iterator<partition_element> subpart_it(part->subpartitions);
2564+
for (const partition_element *subpart= subpart_it++;
2565+
subpart;
2566+
subpart= subpart_it++)
2567+
{
2568+
if (subpart->data_file_name != NULL || subpart->index_file_name != NULL)
2569+
{
2570+
return true;
2571+
}
2572+
}
2573+
}
2574+
return false;
2575+
}
2576+
25532577
#else /* WITH_PARTITION_STORAGE_ENGINE */
25542578
/*
25552579
For builds without partitioning we need to define these functions

sql/partition_info.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef PARTITION_INFO_INCLUDED
22
#define PARTITION_INFO_INCLUDED
33

4-
/* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
4+
/* Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -349,4 +349,15 @@ void init_all_partitions_iterator(partition_info *part_info,
349349
part_iter->get_next= get_next_partition_id_range;
350350
}
351351

352+
/**
353+
Predicate which returns true if any partition or subpartition uses
354+
an external data directory or external index directory.
355+
356+
@param pi partitioning information
357+
@retval true if any partition or subpartition has an external
358+
data directory or external index directory.
359+
@retval false otherwise
360+
*/
361+
bool has_external_data_or_index_dir(partition_info &pi);
362+
352363
#endif /* PARTITION_INFO_INCLUDED */

sql/sql_parse.cc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
#include "sql_insert.h" // mysql_insert
3636
#include "sql_update.h" // mysql_update, mysql_multi_update
3737
#include "sql_partition.h" // struct partition_info
38+
#ifdef WITH_PARTITION_STORAGE_ENGINE
39+
#include "partition_info.h" // has_external_data_or_index_dir
40+
#endif /* WITH_PARTITION_STORAGE_ENGINE */
3841
#include "sql_db.h" // mysql_change_db, mysql_create_db,
3942
// mysql_rm_db, mysql_upgrade_db,
4043
// mysql_alter_db,
@@ -2413,14 +2416,22 @@ case SQLCOM_PREPARE:
24132416
copy.
24142417
*/
24152418
Alter_info alter_info(lex->alter_info, thd->mem_root);
2416-
24172419
if (thd->is_fatal_error)
24182420
{
24192421
/* If out of memory when creating a copy of alter_info. */
24202422
res= 1;
24212423
goto end_with_restore_list;
24222424
}
24232425

2426+
if (((lex->create_info.used_fields & HA_CREATE_USED_DATADIR) != 0 ||
2427+
(lex->create_info.used_fields & HA_CREATE_USED_INDEXDIR) != 0) &&
2428+
check_access(thd, FILE_ACL, NULL, NULL, NULL, FALSE, FALSE))
2429+
{
2430+
res= 1;
2431+
my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "FILE");
2432+
goto end_with_restore_list;
2433+
}
2434+
24242435
if ((res= create_table_precheck(thd, select_tables, create_table)))
24252436
goto end_with_restore_list;
24262437

@@ -2458,6 +2469,12 @@ case SQLCOM_PREPARE:
24582469
#ifdef WITH_PARTITION_STORAGE_ENGINE
24592470
{
24602471
partition_info *part_info= thd->lex->part_info;
2472+
if (part_info != NULL && has_external_data_or_index_dir(*part_info) &&
2473+
check_access(thd, FILE_ACL, NULL, NULL, NULL, FALSE, FALSE))
2474+
{
2475+
res= -1;
2476+
goto end_with_restore_list;
2477+
}
24612478
if (part_info && !(part_info= thd->lex->part_info->get_clone(true)))
24622479
{
24632480
res= -1;

0 commit comments

Comments
 (0)