Some bugs that user has properly recognized in user management

system.
parent 141e7a55
...@@ -652,7 +652,12 @@ static void acl_update_user(const char *user, const char *host, ...@@ -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->host.hostname && !strcmp(host,acl_user->host.hostname))
{ {
acl_user->access=privileges; 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 #ifdef HAVE_OPENSSL
acl_user->ssl_type=ssl_type; acl_user->ssl_type=ssl_type;
acl_user->ssl_cipher=ssl_cipher; acl_user->ssl_cipher=ssl_cipher;
......
...@@ -349,63 +349,60 @@ static bool check_mqh(THD *thd, uint check_command) ...@@ -349,63 +349,60 @@ static bool check_mqh(THD *thd, uint check_command)
USER_CONN *uc=thd->user_connect; USER_CONN *uc=thd->user_connect;
DBUG_ASSERT(uc != 0); 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 (check_command < (uint) SQLCOM_END)
{ {
if (uc->user_resources.updates && uc_update_queries[check_command] && if (uc->user_resources.updates && uc_update_queries[check_command] &&
++(uc->updates) > uc->user_resources.updates) ++(uc->updates) > uc->user_resources.updates)
{ {
net_printf(&thd->net, ER_USER_LIMIT_REACHED, uc->user, "max_updates", net_printf(&thd->net, ER_USER_LIMIT_REACHED, uc->user, "max_updates",
(long) uc->user_resources.updates); (long) uc->user_resources.updates);
error=1; error=1;
goto end; 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;
}
} }
end: end:
DBUG_RETURN(error); 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); (void) pthread_mutex_lock(&LOCK_user_conn);
if (lu) // for GRANT if (lu) // for GRANT
{ {
USER_CONN *uc; 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]; char temp_user[USERNAME_LENGTH+HOSTNAME_LENGTH+2];
memcpy(temp_user,lu->user.str,lu->user.length); memcpy(temp_user,lu->user.str,lu->user.length);
memcpy(temp_user+lu->user.length+1,lu->host.str,lu->host.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; temp_user[lu->user.length]='\0'; temp_user[temp_len-1]=0;
if ((uc = (struct user_conn *) hash_search(&hash_user_connections, 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->questions=0;
uc->user_resources=*mqh; get_mqh(temp_user,&temp_user[lu->user.length+1],uc);
uc->updates=0; uc->updates=0;
uc->conn_per_hour=0; uc->conn_per_hour=0;
} }
...@@ -2351,13 +2348,12 @@ mysql_execute_command(void) ...@@ -2351,13 +2348,12 @@ mysql_execute_command(void)
Query_log_event qinfo(thd, thd->query); Query_log_event qinfo(thd, thd->query);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
if (mqh_used && lex->sql_command == SQLCOM_GRANT && if (mqh_used && lex->sql_command == SQLCOM_GRANT)
(lex->mqh.questions || lex->mqh.updates || lex->mqh.connections))
{ {
List_iterator <LEX_USER> str_list(lex->users_list); List_iterator <LEX_USER> str_list(lex->users_list);
LEX_USER *user; LEX_USER *user;
while ((user=str_list++)) 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) ...@@ -3334,7 +3330,7 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables)
acl_reload(); acl_reload();
grant_reload(); grant_reload();
if (mqh_used) if (mqh_used)
reset_mqh(thd,(LEX_USER *) NULL, 0, true); reset_mqh(thd,(LEX_USER *) NULL,true);
} }
if (options & REFRESH_LOG) if (options & REFRESH_LOG)
{ {
...@@ -3389,7 +3385,7 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables) ...@@ -3389,7 +3385,7 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables)
UNLOCK_ACTIVE_MI; UNLOCK_ACTIVE_MI;
} }
if (options & REFRESH_USER_RESOURCES) if (options & REFRESH_USER_RESOURCES)
reset_mqh(thd,(LEX_USER *) NULL, 0); reset_mqh(thd,(LEX_USER *) NULL);
return result; return result;
} }
......
...@@ -2723,11 +2723,12 @@ flush_option: ...@@ -2723,11 +2723,12 @@ flush_option:
| STATUS_SYM { Lex->type|= REFRESH_STATUS; } | STATUS_SYM { Lex->type|= REFRESH_STATUS; }
| SLAVE { Lex->type|= REFRESH_SLAVE; } | SLAVE { Lex->type|= REFRESH_SLAVE; }
| MASTER_SYM { Lex->type|= REFRESH_MASTER; } | 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: opt_table_list:
/* empty */ {} /* empty */ {;}
| table_list {}; | table_list {;};
reset: reset:
RESET_SYM RESET_SYM
...@@ -3676,14 +3677,14 @@ grant_option: ...@@ -3676,14 +3677,14 @@ grant_option:
| MAX_CONNECTIONS_PER_HOUR ULONG_NUM | MAX_CONNECTIONS_PER_HOUR ULONG_NUM
{ {
Lex->mqh.connections=$2; Lex->mqh.connections=$2;
} };
begin: begin:
BEGIN_SYM { Lex->sql_command = SQLCOM_BEGIN;} opt_work; BEGIN_SYM { Lex->sql_command = SQLCOM_BEGIN;} opt_work;
opt_work: opt_work:
/* empty */ {} /* empty */ {}
| WORK_SYM {}; | WORK_SYM {;};
commit: commit:
COMMIT_SYM { Lex->sql_command = SQLCOM_COMMIT;}; COMMIT_SYM { Lex->sql_command = SQLCOM_COMMIT;};
......
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