Commit 32718418 authored by Michael Widenius's avatar Michael Widenius

Merging of changes from myisam -> maria missing in last 5.1 - 5.1->maria merge

MARIA_MAX_MSG_BUF -> HA_MAX_MSG_BUF

include/maria.h:
  Remove MARIA_MAX_MSG_BUF; We are now using HA_MAX_MSG_BUF
  Added maria_test_invalid_symlink
storage/maria/ha_maria.cc:
  MARIA_MAX_MSG_BUF -> HA_MAX_MSG_BUF
storage/maria/ma_check.c:
  Removed tab in string constant
  Add extra argument to ma_open_datafile()
storage/maria/ma_create.c:
  Set error number if table is in use
storage/maria/ma_open.c:
  Added name argument to open functions for security check if filename is linked to another file in database directory
storage/maria/ma_static.c:
  Default functions for checking if wrong symlink
storage/maria/maria_chk.c:
  Add extra argument to _ma_open_datafile()
storage/maria/maria_def.h:
  Add extra argument to _ma_open_datafile()
parent 058916ae
......@@ -43,7 +43,6 @@ extern "C" {
#define MARIA_MAX_KEY MAX_INDEXES /* Max allowed keys */
#endif
#define MARIA_MAX_MSG_BUF 1024 /* used in CHECK TABLE, REPAIR TABLE */
#define MARIA_NAME_IEXT ".MAI"
#define MARIA_NAME_DEXT ".MAD"
/* Max extra space to use when sorting keys */
......@@ -273,6 +272,12 @@ extern my_off_t maria_max_temp_length;
extern ulong maria_bulk_insert_tree_size, maria_data_pointer_size;
extern PAGECACHE maria_pagecache_var, *maria_pagecache;
extern MY_TMPDIR *maria_tmpdir;
/*
This is used to check if a symlink points into the mysql data home,
which is normally forbidden as it can be used to get access to
not privileged data
*/
extern int (*maria_test_invalid_symlink)(const char *filename);
/* Prototypes for maria-functions */
......
......@@ -241,7 +241,7 @@ static void _ma_check_print_msg(HA_CHECK *param, const char *msg_type,
THD *thd= (THD *) param->thd;
Protocol *protocol= thd->protocol;
uint length, msg_length;
char msgbuf[MARIA_MAX_MSG_BUF];
char msgbuf[HA_MAX_MSG_BUF];
char name[NAME_LEN * 2 + 2];
msg_length= my_vsnprintf(msgbuf, sizeof(msgbuf), fmt, args);
......@@ -3097,6 +3097,11 @@ static int ha_maria_init(void *p)
((force_start_after_recovery_failures != 0) && mark_recovery_success()) ||
ma_checkpoint_init(checkpoint_interval);
maria_multi_threaded= maria_in_ha_maria= TRUE;
#if defined(HAVE_REALPATH) && !defined(HAVE_purify) && !defined(HAVE_BROKEN_REALPATH)
/* We can only test for sub paths if my_symlink.c is using realpath */
maria_test_invalid_symlink= test_if_data_home_dir;
#endif
return res ? HA_ERR_INITIALIZATION : 0;
}
......
......@@ -2097,14 +2097,14 @@ int maria_chk_data_link(HA_CHECK *param, MARIA_HA *info, my_bool extend)
if (param->del_blocks != share->state.state.del)
{
_ma_check_print_warning(param,
"Found %10s deleted blocks Should be: %s",
"Found %10s deleted blocks. Should be: %s",
llstr(param->del_blocks,llbuff),
llstr(share->state.state.del,llbuff2));
}
if (param->splits != share->state.split)
{
_ma_check_print_warning(param,
"Found %10s parts Should be: %s parts",
"Found %10s key parts. Should be: %s",
llstr(param->splits, llbuff),
llstr(share->state.split,llbuff2));
}
......@@ -2685,7 +2685,7 @@ int maria_repair(HA_CHECK *param, register MARIA_HA *info,
(param->testflag & T_BACKUP_DATA ?
MYF(MY_REDEL_MAKE_BACKUP): MYF(0)) |
sync_dir) ||
_ma_open_datafile(info, share, -1))
_ma_open_datafile(info, share, NullS, -1))
{
goto err;
}
......@@ -3794,7 +3794,7 @@ int maria_repair_by_sort(HA_CHECK *param, register MARIA_HA *info,
(param->testflag & T_BACKUP_DATA ?
MYF(MY_REDEL_MAKE_BACKUP): MYF(0)) |
sync_dir) ||
_ma_open_datafile(info, share, -1))
_ma_open_datafile(info, share, NullS, -1))
{
_ma_check_print_error(param, "Couldn't change to new data file");
goto err;
......@@ -4402,7 +4402,7 @@ err:
MYF((param->testflag & T_BACKUP_DATA ?
MY_REDEL_MAKE_BACKUP : 0) |
sync_dir)) ||
_ma_open_datafile(info,share,-1))
_ma_open_datafile(info,share, NullS, -1))
got_error=1;
}
}
......
......@@ -836,6 +836,7 @@ int maria_create(const char *name, enum data_file_type datafile_type,
my_printf_error(0, "MARIA table '%s' is in use "
"(most likely by a MERGE table). Try FLUSH TABLES.",
MYF(0), name + dirname_length(name));
my_errno= HA_ERR_TABLE_EXIST;
goto err;
}
......
......@@ -85,8 +85,8 @@ MARIA_HA *_ma_test_if_reopen(const char *filename)
*/
static MARIA_HA *maria_clone_internal(MARIA_SHARE *share, int mode,
File data_file)
static MARIA_HA *maria_clone_internal(MARIA_SHARE *share, const char *name,
int mode, File data_file)
{
int save_errno;
uint errpos;
......@@ -104,7 +104,7 @@ static MARIA_HA *maria_clone_internal(MARIA_SHARE *share, int mode,
}
if (data_file >= 0)
info.dfile.file= data_file;
else if (_ma_open_datafile(&info, share, -1))
else if (_ma_open_datafile(&info, share, name, -1))
goto err;
errpos= 5;
......@@ -236,7 +236,7 @@ MARIA_HA *maria_clone(MARIA_SHARE *share, int mode)
{
MARIA_HA *new_info;
pthread_mutex_lock(&THR_LOCK_maria);
new_info= maria_clone_internal(share, mode,
new_info= maria_clone_internal(share, NullS, mode,
share->data_file_type == BLOCK_RECORD ?
share->bitmap.file.file : -1);
pthread_mutex_unlock(&THR_LOCK_maria);
......@@ -256,7 +256,7 @@ MARIA_HA *maria_clone(MARIA_SHARE *share, int mode)
MARIA_HA *maria_open(const char *name, int mode, uint open_flags)
{
int kfile,open_mode,save_errno;
uint i,j,len,errpos,head_length,base_pos,info_length,keys,
uint i,j,len,errpos,head_length,base_pos,info_length,keys, realpath_err,
key_parts,unique_key_parts,fulltext_keys,uniques;
char name_buff[FN_REFLEN], org_name[FN_REFLEN], index_name[FN_REFLEN],
data_name[FN_REFLEN];
......@@ -277,8 +277,16 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags)
head_length=sizeof(share_buff.state.header);
bzero((uchar*) &info,sizeof(info));
my_realpath(name_buff, fn_format(org_name,name,"",MARIA_NAME_IEXT,
MY_UNPACK_FILENAME),MYF(0));
realpath_err= my_realpath(name_buff, fn_format(org_name, name, "",
MARIA_NAME_IEXT,
MY_UNPACK_FILENAME),MYF(0));
if (my_is_symlink(org_name) &&
(realpath_err || (*maria_test_invalid_symlink)(name_buff)))
{
my_errno= HA_WRONG_CREATE_OPTION;
DBUG_RETURN(0);
}
pthread_mutex_lock(&THR_LOCK_maria);
old_info= 0;
if ((open_flags & HA_OPEN_COPY) ||
......@@ -347,7 +355,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags)
if (!strcmp(name_buff, org_name) ||
my_readlink(index_name, org_name, MYF(0)) == -1)
(void) strmov(index_name, org_name);
*strrchr(org_name, '.')= '\0';
*strrchr(org_name, FN_EXTCHAR)= '\0';
(void) fn_format(data_name,org_name,"",MARIA_NAME_DEXT,
MY_APPEND_EXT|MY_UNPACK_FILENAME|MY_RESOLVE_SYMLINKS);
......@@ -739,7 +747,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags)
if ((share->data_file_type == BLOCK_RECORD ||
share->data_file_type == COMPRESSED_RECORD))
{
if (_ma_open_datafile(&info, share, -1))
if (_ma_open_datafile(&info, share, name, -1))
goto err;
data_file= info.dfile.file;
}
......@@ -884,7 +892,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags)
data_file= share->bitmap.file.file; /* Only opened once */
}
if (!(m_info= maria_clone_internal(share, mode, data_file)))
if (!(m_info= maria_clone_internal(share, name, mode, data_file)))
goto err;
pthread_mutex_unlock(&THR_LOCK_maria);
......@@ -1729,9 +1737,27 @@ void _ma_set_index_pagecache_callbacks(PAGECACHE_FILE *file,
exist a dup()-like call that would give us two different file descriptors.
*************************************************************************/
int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share,
int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share, const char *org_name,
File file_to_dup __attribute__((unused)))
{
char *data_name= share->data_file_name.str;
char real_data_name[FN_REFLEN];
if (org_name)
{
fn_format(real_data_name, org_name, "", MARIA_NAME_DEXT, 4);
if (my_is_symlink(real_data_name))
{
if (my_realpath(real_data_name, real_data_name, MYF(0)) ||
(*maria_test_invalid_symlink)(real_data_name))
{
my_errno= HA_WRONG_CREATE_OPTION;
return 1;
}
data_name= real_data_name;
}
}
info->dfile.file= share->bitmap.file.file=
my_open(share->data_file_name.str, share->mode | O_SHARE,
MYF(MY_WME));
......
......@@ -13,6 +13,15 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
static int always_valid(const char *filename __attribute__((unused)))
{
return 0;
}
int (*maria_test_invalid_symlink)(const char *filename)= always_valid;
/*
Static variables for MARIA library. All definied here for easy making of
a shared library
......
......@@ -1189,7 +1189,7 @@ static int maria_chk(HA_CHECK *param, char *filename)
VOID(my_close(info->dfile.file, MYF(MY_WME))); /* Close new file */
error|=maria_change_to_newfile(filename,MARIA_NAME_DEXT,DATA_TMP_EXT,
MYF(0));
if (_ma_open_datafile(info,info->s, -1))
if (_ma_open_datafile(info,info->s, NullS, -1))
error=1;
param->out_flag&= ~O_NEW_DATA; /* We are using new datafile */
param->read_cache.file= info->dfile.file;
......
......@@ -1100,7 +1100,8 @@ void _ma_def_scan_restore_pos(MARIA_HA *info, MARIA_RECORD_POS lastpos);
extern MARIA_HA *_ma_test_if_reopen(const char *filename);
my_bool _ma_check_table_is_closed(const char *name, const char *where);
int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share, File file_to_dup);
int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share, const char *org_name,
File file_to_dup);
int _ma_open_keyfile(MARIA_SHARE *share);
void _ma_setup_functions(register MARIA_SHARE *share);
my_bool _ma_dynmap_file(MARIA_HA *info, my_off_t size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment