~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/t/partition_symlink.test

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Test that must have symlink. eg. using DATA/INDEX DIR
 
2
# (DATA/INDEX DIR requires symlinks)
 
3
-- source include/have_partition.inc
 
4
-- source include/have_symlink.inc
 
5
# remove the not_windows line after fixing bug#33687
 
6
# symlinks must also work for files, not only directories
 
7
# as in --skip-symbolic-links
 
8
-- source include/not_windows.inc
 
9
-- disable_warnings
 
10
DROP TABLE IF EXISTS t1;
 
11
DROP DATABASE IF EXISTS mysqltest2;
 
12
-- enable_warnings
 
13
 
 
14
#
 
15
# Bug 32091: Security breach via directory changes
 
16
#
 
17
# The below test shows that a pre-existing table mysqltest2.t1 cannot be
 
18
# replaced by a user with no rights in 'mysqltest2'. The altered table
 
19
# test.t1 will be altered (remove partitioning) into the test directory
 
20
# and having its partitions removed from the mysqltest2 directory.
 
21
# (the partitions data files are named <tablename>#P#<partname>.MYD
 
22
# and will not collide with a non partitioned table's data files.) 
 
23
# NOTE: the privileges on files and directories are the same for all
 
24
# database users in mysqld, though mysqld enforces privileges on
 
25
# the database and table levels which in turn maps to directories and
 
26
# files, but not the other way around (any db-user can use any
 
27
# directory or file that the mysqld-process can use, via DATA/INDEX DIR)
 
28
# this is the security flaw that was used in bug#32091 and bug#32111
 
29
 
 
30
-- echo # Creating two non colliding tables mysqltest2.t1 and test.t1
 
31
-- echo # test.t1 have partitions in mysqltest2-directory!
 
32
-- echo # user root:
 
33
  CREATE USER mysqltest_1@localhost;
 
34
  CREATE DATABASE mysqltest2;
 
35
  USE mysqltest2;
 
36
  CREATE TABLE t1 (a INT);
 
37
  INSERT INTO t1 VALUES (0);
 
38
connect(con1,localhost,mysqltest_1,,);
 
39
-- echo # user mysqltest_1:
 
40
  USE test;
 
41
  -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 
42
  eval CREATE TABLE t1 (a INT)
 
43
   PARTITION BY LIST (a) (
 
44
    PARTITION p0 VALUES IN (0)
 
45
     DATA DIRECTORY '$MYSQLTEST_VARDIR/tmp'
 
46
     INDEX DIRECTORY '$MYSQLTEST_VARDIR/tmp',
 
47
    PARTITION p1 VALUES IN (1)
 
48
     DATA DIRECTORY '$MYSQLTEST_VARDIR/tmp'
 
49
     INDEX DIRECTORY '$MYSQLTEST_VARDIR/tmp',
 
50
    PARTITION p2 VALUES IN (2)
 
51
  );
 
52
  -- echo # without the patch for bug#32091 this would create
 
53
  -- echo # files mysqltest2/t1.MYD + .MYI and possible overwrite
 
54
  -- echo # the mysqltest2.t1 table (depending on bug#32111)
 
55
  -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 
56
  ALTER TABLE t1 REMOVE PARTITIONING;
 
57
  INSERT INTO t1 VALUES (1);
 
58
  SELECT * FROM t1;
 
59
connection default;
 
60
-- echo # user root:
 
61
  USE mysqltest2;
 
62
  FLUSH TABLES;
 
63
  -- echo # if the patch works, this should be different
 
64
  -- echo # and before the patch they were the same!
 
65
  SELECT * FROM t1;
 
66
  USE test;
 
67
  SELECT * FROM t1;
 
68
  DROP TABLE t1;
 
69
  DROP DATABASE mysqltest2;
 
70
# The below test shows that a pre-existing partition can not be
 
71
# destroyed by a new partition from another table.
 
72
# (Remember that a table or partition that uses the DATA/INDEX DIR
 
73
# is symlinked and thus has
 
74
# 1. the real file in the DATA/INDEX DIR and
 
75
# 2. a symlink in its default database directory pointing to
 
76
# the real file.
 
77
# So it is using/blocking 2 files in (in 2 different directories
 
78
-- echo # test that symlinks can not overwrite files when CREATE TABLE
 
79
-- echo # user root:
 
80
 
 
81
  CREATE DATABASE mysqltest2;
 
82
  USE mysqltest2;
 
83
  -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 
84
  eval CREATE TABLE t1 (a INT)
 
85
   PARTITION BY LIST (a) (
 
86
    PARTITION p0 VALUES IN (0)
 
87
     DATA DIRECTORY '$MYSQLTEST_VARDIR/tmp'
 
88
     INDEX DIRECTORY '$MYSQLTEST_VARDIR/tmp',
 
89
    PARTITION p1 VALUES IN (1)
 
90
     DATA DIRECTORY '$MYSQLTEST_VARDIR/tmp'
 
91
     INDEX DIRECTORY '$MYSQLTEST_VARDIR/tmp'
 
92
   );
 
93
connection con1;
 
94
-- echo # user mysqltest_1:
 
95
  USE test;
 
96
  -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 
97
  -- error 1,1
 
98
  eval CREATE TABLE t1 (a INT)
 
99
   PARTITION BY LIST (a) (
 
100
    PARTITION p0 VALUES IN (0)
 
101
     DATA DIRECTORY '$MYSQLTEST_VARDIR/tmp'
 
102
     INDEX DIRECTORY '$MYSQLTEST_VARDIR/tmp',
 
103
    PARTITION p1 VALUES IN (1)
 
104
     DATA DIRECTORY '$MYSQLTEST_VARDIR/tmp'
 
105
     INDEX DIRECTORY '$MYSQLTEST_VARDIR/tmp'
 
106
   );
 
107
  -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 
108
  -- error 1,1
 
109
  eval CREATE TABLE t1 (a INT)
 
110
   PARTITION BY LIST (a) (
 
111
    PARTITION p0 VALUES IN (0)
 
112
     DATA DIRECTORY '$MYSQLTEST_VARDIR/tmp'
 
113
     INDEX DIRECTORY '$MYSQLTEST_VARDIR/tmp',
 
114
    PARTITION p1 VALUES IN (1)
 
115
     DATA DIRECTORY '$MYSQLTEST_VARDIR/tmp'
 
116
     INDEX DIRECTORY '$MYSQLTEST_VARDIR/tmp'
 
117
  );
 
118
connection default;
 
119
-- echo # user root (cleanup):
 
120
  DROP DATABASE mysqltest2;
 
121
  USE test;
 
122
  DROP USER mysqltest_1@localhost;
 
123
  disconnect con1;
 
124
 
 
125
#
 
126
# Bug #24633 SQL MODE "NO_DIR_IN_CREATE" does not work with partitioned tables 
 
127
#
 
128
 
 
129
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR 
 
130
eval create table t2 (i int )
 
131
partition by range (i)
 
132
(
 
133
    partition p01 values less than (1000)
 
134
    data directory="$MYSQLTEST_VARDIR/tmp"
 
135
    index directory="$MYSQLTEST_VARDIR/tmp"
 
136
);
 
137
 
 
138
set @org_mode=@@sql_mode;
 
139
set @@sql_mode='NO_DIR_IN_CREATE';
 
140
select @@sql_mode;
 
141
create table t1 (i int )
 
142
partition by range (i)
 
143
(
 
144
    partition p01 values less than (1000)
 
145
    data directory='/not/existing'
 
146
    index directory='/not/existing'
 
147
);
 
148
 
 
149
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR 
 
150
show create table t2;
 
151
DROP TABLE t1, t2;
 
152
set @@sql_mode=@org_mode;
 
153
 
 
154
#
 
155
# Bug 21350: Data Directory problems
 
156
#
 
157
# Added ER_WRONG_TABLE_NAME and reported bug#39045
 
158
-- error ER_WRONG_ARGUMENTS, ER_WRONG_TABLE_NAME
 
159
create table t1 (a int)
 
160
partition by key (a)
 
161
(partition p0 DATA DIRECTORY 'part-data' INDEX DIRECTORY 'part-data');
 
162
 
 
163
#
 
164
# Insert a test that manages to create the first partition and fails with
 
165
# the second, ensure that we clean up afterwards in a proper manner.
 
166
#
 
167
# Added ER_WRONG_TABLE_NAME and reported bug#39045
 
168
--error ER_WRONG_ARGUMENTS, ER_WRONG_TABLE_NAME
 
169
create table t1 (a int)
 
170
partition by key (a)
 
171
(partition p0,
 
172
 partition p1 DATA DIRECTORY 'part-data' INDEX DIRECTORY 'part-data');