summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sql/sql_acl.cc7
-rw-r--r--sql/sql_parse.cc72
-rw-r--r--sql/sql_yacc.yy11
3 files changed, 46 insertions, 44 deletions
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index 4b3a20b0014..cdfe2f2e5b3 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -652,7 +652,12 @@ static void acl_update_user(const char *user, const char *host,
acl_user->host.hostname && !strcmp(host,acl_user->host.hostname))
{
acl_user->access=privileges;
- acl_user->user_resource=*mqh;
+ if (mqh->questions)
+ acl_user->user_resource.questions=mqh->questions;
+ if (mqh->updates)
+ acl_user->user_resource.updates=mqh->updates;
+ if (mqh->connections)
+ acl_user->user_resource.connections=mqh->connections;
#ifdef HAVE_OPENSSL
acl_user->ssl_type=ssl_type;
acl_user->ssl_cipher=ssl_cipher;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index a29e1e6930f..f3b5f45ae6b 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -349,63 +349,60 @@ static bool check_mqh(THD *thd, uint check_command)
USER_CONN *uc=thd->user_connect;
DBUG_ASSERT(uc != 0);
+ bool my_start = thd->start_time != 0;
+ time_t check_time = (my_start) ? thd->start_time : time(NULL);
+
+ if (check_time - uc->intime >= 3600)
+ {
+ (void) pthread_mutex_lock(&LOCK_user_conn);
+ uc->questions=1;
+ uc->updates=0;
+ uc->conn_per_hour=0;
+ uc->intime=check_time;
+ (void) pthread_mutex_unlock(&LOCK_user_conn);
+ }
+ if (uc->user_resources.questions &&
+ uc->questions++ >= uc->user_resources.questions)
+ {
+ net_printf(&thd->net, ER_USER_LIMIT_REACHED, uc->user, "max_questions",
+ (long) uc->user_resources.questions);
+ error=1;
+ goto end;
+ }
if (check_command < (uint) SQLCOM_END)
{
if (uc->user_resources.updates && uc_update_queries[check_command] &&
++(uc->updates) > uc->user_resources.updates)
- {
- net_printf(&thd->net, ER_USER_LIMIT_REACHED, uc->user, "max_updates",
- (long) uc->user_resources.updates);
- error=1;
- goto end;
- }
- }
- else
- {
- bool my_start = thd->start_time != 0;
- time_t check_time = (my_start) ? thd->start_time : time(NULL);
-
- if (check_time - uc->intime >= 3600)
- {
- (void) pthread_mutex_lock(&LOCK_user_conn);
- uc->questions=1;
- uc->updates=0;
- uc->conn_per_hour=0;
- uc->intime=check_time;
- (void) pthread_mutex_unlock(&LOCK_user_conn);
- }
- else if (uc->user_resources.questions &&
- uc->questions++ >= uc->user_resources.questions)
- {
- net_printf(&thd->net, ER_USER_LIMIT_REACHED, uc->user, "max_questions",
- (long) uc->user_resources.questions);
- error=1;
- goto end;
- }
+ {
+ net_printf(&thd->net, ER_USER_LIMIT_REACHED, uc->user, "max_updates",
+ (long) uc->user_resources.updates);
+ error=1;
+ goto end;
+ }
}
end:
DBUG_RETURN(error);
}
-static void reset_mqh(THD *thd, LEX_USER *lu, USER_RESOURCES *mqh, bool get_them=false)
+static void reset_mqh(THD *thd, LEX_USER *lu, bool get_them=false)
{
(void) pthread_mutex_lock(&LOCK_user_conn);
if (lu) // for GRANT
{
USER_CONN *uc;
- uint temp_len=lu->user.length+lu->host.length+2;
+ volatile uint temp_len=lu->user.length+lu->host.length+2;
char temp_user[USERNAME_LENGTH+HOSTNAME_LENGTH+2];
memcpy(temp_user,lu->user.str,lu->user.length);
memcpy(temp_user+lu->user.length+1,lu->host.str,lu->host.length);
temp_user[lu->user.length]='\0'; temp_user[temp_len-1]=0;
if ((uc = (struct user_conn *) hash_search(&hash_user_connections,
- (byte*) temp_user, temp_len-1)))
+ (byte*) temp_user, temp_len)))
{
uc->questions=0;
- uc->user_resources=*mqh;
+ get_mqh(temp_user,&temp_user[lu->user.length+1],uc);
uc->updates=0;
uc->conn_per_hour=0;
}
@@ -2351,13 +2348,12 @@ mysql_execute_command(void)
Query_log_event qinfo(thd, thd->query);
mysql_bin_log.write(&qinfo);
}
- if (mqh_used && lex->sql_command == SQLCOM_GRANT &&
- (lex->mqh.questions || lex->mqh.updates || lex->mqh.connections))
+ if (mqh_used && lex->sql_command == SQLCOM_GRANT)
{
List_iterator <LEX_USER> str_list(lex->users_list);
LEX_USER *user;
while ((user=str_list++))
- reset_mqh(thd,user,&(lex->mqh));
+ reset_mqh(thd,user);
}
}
}
@@ -3334,7 +3330,7 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables)
acl_reload();
grant_reload();
if (mqh_used)
- reset_mqh(thd,(LEX_USER *) NULL, 0, true);
+ reset_mqh(thd,(LEX_USER *) NULL,true);
}
if (options & REFRESH_LOG)
{
@@ -3389,7 +3385,7 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables)
UNLOCK_ACTIVE_MI;
}
if (options & REFRESH_USER_RESOURCES)
- reset_mqh(thd,(LEX_USER *) NULL, 0);
+ reset_mqh(thd,(LEX_USER *) NULL);
return result;
}
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 53724c3656b..dcb5f680357 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -2723,11 +2723,12 @@ flush_option:
| STATUS_SYM { Lex->type|= REFRESH_STATUS; }
| SLAVE { Lex->type|= REFRESH_SLAVE; }
| MASTER_SYM { Lex->type|= REFRESH_MASTER; }
- | DES_KEY_FILE { Lex->type|= REFRESH_DES_KEY_FILE; };
+ | DES_KEY_FILE { Lex->type|= REFRESH_DES_KEY_FILE; }
+ | RESOURCES { Lex->type|= REFRESH_USER_RESOURCES; };
opt_table_list:
- /* empty */ {}
- | table_list {};
+ /* empty */ {;}
+ | table_list {;};
reset:
RESET_SYM
@@ -3676,14 +3677,14 @@ grant_option:
| MAX_CONNECTIONS_PER_HOUR ULONG_NUM
{
Lex->mqh.connections=$2;
- }
+ };
begin:
BEGIN_SYM { Lex->sql_command = SQLCOM_BEGIN;} opt_work;
opt_work:
/* empty */ {}
- | WORK_SYM {};
+ | WORK_SYM {;};
commit:
COMMIT_SYM { Lex->sql_command = SQLCOM_COMMIT;};