Commit e71bd28f authored by Olivier Bertrand's avatar Olivier Bertrand

- Fix bug MDEV-5486 (fail to create or drop a table dbn.tbn when no default database)

modified:
  storage/connect/ha_connect.cc
  storage/connect/ha_connect.h

- Typo

modified:
  storage/connect/odbconn.cpp
  storage/connect/user_connect.h
parent 32284eba
...@@ -2749,8 +2749,10 @@ int ha_connect::delete_all_rows() ...@@ -2749,8 +2749,10 @@ int ha_connect::delete_all_rows()
} // end of delete_all_rows } // end of delete_all_rows
bool ha_connect::check_privileges(THD *thd, PTOS options) bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn)
{ {
const char *db= (dbn && *dbn) ? dbn : NULL;
if (!options->type) { if (!options->type) {
if (options->srcdef) if (options->srcdef)
options->type= "MYSQL"; options->type= "MYSQL";
...@@ -2800,7 +2802,7 @@ bool ha_connect::check_privileges(THD *thd, PTOS options) ...@@ -2800,7 +2802,7 @@ bool ha_connect::check_privileges(THD *thd, PTOS options)
case TAB_MAC: case TAB_MAC:
case TAB_WMI: case TAB_WMI:
case TAB_OEM: case TAB_OEM:
return check_access(thd, FILE_ACL, NULL, NULL, NULL, 0, 0); return check_access(thd, FILE_ACL, db, NULL, NULL, 0, 0);
// This is temporary until a solution is found // This is temporary until a solution is found
case TAB_TBL: case TAB_TBL:
...@@ -3026,12 +3028,6 @@ int ha_connect::external_lock(THD *thd, int lock_type) ...@@ -3026,12 +3028,6 @@ int ha_connect::external_lock(THD *thd, int lock_type)
if (!g) if (!g)
DBUG_RETURN(HA_ERR_INTERNAL_ERROR); DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
if (lock_type != F_UNLCK && check_privileges(thd, options)) {
strcpy(g->Message, "This operation requires the FILE privilege");
printf("%s\n", g->Message);
DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
} // endif check_privileges
// Action will depend on lock_type // Action will depend on lock_type
switch (lock_type) { switch (lock_type) {
case F_WRLCK: case F_WRLCK:
...@@ -3167,6 +3163,14 @@ int ha_connect::external_lock(THD *thd, int lock_type) ...@@ -3167,6 +3163,14 @@ int ha_connect::external_lock(THD *thd, int lock_type)
DBUG_RETURN(rc); DBUG_RETURN(rc);
} // endif MODE_ANY } // endif MODE_ANY
DBUG_ASSERT(table && table->s);
if (check_privileges(thd, options, table->s->db.str)) {
strcpy(g->Message, "This operation requires the FILE privilege");
printf("%s\n", g->Message);
DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
} // endif check_privileges
// Table mode depends on the query type // Table mode depends on the query type
newmode= CheckMode(g, thd, newmode, &xcheck, &cras); newmode= CheckMode(g, thd, newmode, &xcheck, &cras);
...@@ -3212,9 +3216,6 @@ int ha_connect::external_lock(THD *thd, int lock_type) ...@@ -3212,9 +3216,6 @@ int ha_connect::external_lock(THD *thd, int lock_type)
xmod= newmode; xmod= newmode;
if (!table)
rc= 3; // Logical error
// Delay open until used fields are known // Delay open until used fields are known
} // endif tdbp } // endif tdbp
...@@ -3327,7 +3328,7 @@ filename_to_dbname_and_tablename(const char *filename, ...@@ -3327,7 +3328,7 @@ filename_to_dbname_and_tablename(const char *filename,
memcpy(database, d.str, d.length); memcpy(database, d.str, d.length);
database[d.length]= '\0'; database[d.length]= '\0';
return false; return false;
} } // end of filename_to_dbname_and_tablename
/** /**
...@@ -3385,7 +3386,7 @@ int ha_connect::delete_or_rename_table(const char *name, const char *to) ...@@ -3385,7 +3386,7 @@ int ha_connect::delete_or_rename_table(const char *name, const char *to)
// Now we can work // Now we can work
pos= share->option_struct; pos= share->option_struct;
if (check_privileges(thd, pos)) if (check_privileges(thd, pos, db))
{ {
free_table_share(share); free_table_share(share);
DBUG_RETURN(HA_ERR_INTERNAL_ERROR); DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
...@@ -4360,6 +4361,28 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, ...@@ -4360,6 +4361,28 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
return HA_ERR_INTERNAL_ERROR; return HA_ERR_INTERNAL_ERROR;
} // end of connect_assisted_discovery } // end of connect_assisted_discovery
/**
Get the database name from a qualified table name.
*/
char *ha_connect::GetDBfromName(const char *name)
{
char *db, dbname[128], tbname[128];
if (filename_to_dbname_and_tablename(name, dbname, sizeof(dbname),
tbname, sizeof(tbname)))
*dbname= 0;
if (*dbname) {
assert(xp && xp->g);
db= (char*)PlugSubAlloc(xp->g, NULL, strlen(dbname + 1));
strcpy(db, dbname);
} else
db= NULL;
return db;
} // end of GetDBfromName
/** /**
@brief @brief
create() is called to create a database. The variable name will have the name create() is called to create a database. The variable name will have the name
...@@ -4418,7 +4441,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, ...@@ -4418,7 +4441,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
DBUG_RETURN(HA_ERR_INTERNAL_ERROR); DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
} // endif ttp } // endif ttp
if (check_privileges(thd, options)) if (check_privileges(thd, options, GetDBfromName(name)))
DBUG_RETURN(HA_ERR_INTERNAL_ERROR); DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
if (options->data_charset) { if (options->data_charset) {
......
...@@ -445,8 +445,9 @@ const char *GetValStr(OPVAL vop, bool neg); ...@@ -445,8 +445,9 @@ const char *GetValStr(OPVAL vop, bool neg);
int optimize(THD* thd, HA_CHECK_OPT* check_opt); int optimize(THD* thd, HA_CHECK_OPT* check_opt);
protected: protected:
bool check_privileges(THD *thd, PTOS options); bool check_privileges(THD *thd, PTOS options, char *dbn);
MODE CheckMode(PGLOBAL g, THD *thd, MODE newmode, bool *chk, bool *cras); MODE CheckMode(PGLOBAL g, THD *thd, MODE newmode, bool *chk, bool *cras);
char *GetDBfromName(const char *name);
// Members // Members
static ulong num; // Tracable handler number static ulong num; // Tracable handler number
......
...@@ -2023,7 +2023,6 @@ bool ODBConn::GetDrivers(PQRYRES qrp) ...@@ -2023,7 +2023,6 @@ bool ODBConn::GetDrivers(PQRYRES qrp)
return rv; return rv;
} // end of GetDrivers } // end of GetDrivers
/***********************************************************************/ /***********************************************************************/
/* A helper class to split an optionally qualified table name into */ /* A helper class to split an optionally qualified table name into */
/* components. */ /* components. */
...@@ -2042,7 +2041,7 @@ class SQLQualifiedName ...@@ -2042,7 +2041,7 @@ class SQLQualifiedName
{ {
S->str= str; S->str= str;
S->length= length; S->length= length;
} // eend of lex_string_set } // end of lex_string_set
void lex_string_shorten_down(MYSQL_LEX_STRING *S, size_t offs) void lex_string_shorten_down(MYSQL_LEX_STRING *S, size_t offs)
{ {
......
...@@ -62,10 +62,10 @@ public: ...@@ -62,10 +62,10 @@ public:
static PCONNECT to_users; // To the chain of users static PCONNECT to_users; // To the chain of users
PCONNECT next; // Next user in chain PCONNECT next; // Next user in chain
PCONNECT previous; // Previous user in chain PCONNECT previous; // Previous user in chain
PGLOBAL g; // The common handle to CONNECT PGLOBAL g; // The common handle to CONNECT
//char dbname[32]; // The DBCONNECT database //char dbname[32]; // The DBCONNECT database
query_id_t last_query_id; // the latest user query id query_id_t last_query_id; // the latest user query id
int count; // if used by several handlers int count; // if used by several handlers
// Statistics // Statistics
ulong nrd, fnd, nfd; ulong nrd, fnd, nfd;
ulonglong tb1; ulonglong tb1;
......
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