| 3430 | |
| 3431 | |
| 3432 | static int check_user_can_set_role(THD *thd, |
| 3433 | const LEX_CSTRING &user, |
| 3434 | const LEX_CSTRING &host, |
| 3435 | const LEX_CSTRING &ip, |
| 3436 | const LEX_CSTRING &rolename, |
| 3437 | privilege_t *access) |
| 3438 | { |
| 3439 | ACL_ROLE *role; |
| 3440 | ACL_USER_BASE *acl_user_base; |
| 3441 | ACL_USER *UNINIT_VAR(acl_user); |
| 3442 | bool is_granted= FALSE; |
| 3443 | int result= 0; |
| 3444 | |
| 3445 | /* clear role privileges */ |
| 3446 | mysql_mutex_lock(&acl_cache->lock); |
| 3447 | |
| 3448 | if (!strcasecmp(rolename.str, none.str)) |
| 3449 | { |
| 3450 | /* have to clear the privileges */ |
| 3451 | /* get the current user */ |
| 3452 | acl_user= find_user_wild(host, user, ip); |
| 3453 | if (acl_user == NULL) |
| 3454 | result= ER_INVALID_CURRENT_USER; |
| 3455 | else if (access) |
| 3456 | *access= acl_user->access; |
| 3457 | |
| 3458 | goto end; |
| 3459 | } |
| 3460 | |
| 3461 | role= find_acl_role(rolename, false); |
| 3462 | |
| 3463 | /* According to SQL standard, the same error message must be presented */ |
| 3464 | if (role == NULL) |
| 3465 | { |
| 3466 | result= ER_INVALID_ROLE; |
| 3467 | goto end; |
| 3468 | } |
| 3469 | |
| 3470 | for (uint i=0 ; i < role->parent_grantee.elements ; i++) |
| 3471 | { |
| 3472 | acl_user_base= *(dynamic_element(&role->parent_grantee, i, ACL_USER_BASE**)); |
| 3473 | if (acl_user_base->flags & IS_ROLE) |
| 3474 | continue; |
| 3475 | |
| 3476 | acl_user= (ACL_USER *)acl_user_base; |
| 3477 | if (acl_user->wild_eq(user.str, host.str, ip.str)) |
| 3478 | { |
| 3479 | is_granted= TRUE; |
| 3480 | break; |
| 3481 | } |
| 3482 | } |
| 3483 | |
| 3484 | /* According to SQL standard, the same error message must be presented */ |
| 3485 | if (!is_granted) |
| 3486 | { |
| 3487 | result= 1; |
| 3488 | goto end; |
| 3489 | } |
no test coverage detected