| 10635 | */ |
| 10636 | |
| 10637 | static int handle_grant_struct(enum enum_acl_lists struct_no, bool drop, |
| 10638 | LEX_USER *user_from, LEX_USER *user_to) |
| 10639 | { |
| 10640 | int result= 0; |
| 10641 | int elements; |
| 10642 | bool restart; |
| 10643 | const char *UNINIT_VAR(user); |
| 10644 | const char *UNINIT_VAR(host); |
| 10645 | ACL_USER *acl_user= NULL; |
| 10646 | ACL_ROLE *acl_role= NULL; |
| 10647 | ACL_DB *acl_db= NULL; |
| 10648 | ACL_PROXY_USER *acl_proxy_user= NULL; |
| 10649 | GRANT_NAME *grant_name= NULL; |
| 10650 | ROLE_GRANT_PAIR *UNINIT_VAR(role_grant_pair); |
| 10651 | HASH *grant_name_hash= NULL; |
| 10652 | HASH *roles_mappings_hash= NULL; |
| 10653 | DBUG_ENTER("handle_grant_struct"); |
| 10654 | DBUG_PRINT("info",("scan struct: %u search: '%s'@'%s'", |
| 10655 | struct_no, user_from->user.str, user_from->host.str)); |
| 10656 | |
| 10657 | mysql_mutex_assert_owner(&acl_cache->lock); |
| 10658 | |
| 10659 | /* No point in querying ROLE ACL if user_from is not a role */ |
| 10660 | if (struct_no == ROLE_ACL && user_from->host.length) |
| 10661 | DBUG_RETURN(0); |
| 10662 | |
| 10663 | /* same. no roles in PROXY_USERS_ACL */ |
| 10664 | if (struct_no == PROXY_USERS_ACL && user_from->is_role()) |
| 10665 | DBUG_RETURN(0); |
| 10666 | |
| 10667 | if (struct_no == ROLE_ACL) //no need to scan the structures in this case |
| 10668 | { |
| 10669 | acl_role= find_acl_role(user_from->user, true); |
| 10670 | if (!acl_role) |
| 10671 | DBUG_RETURN(0); |
| 10672 | |
| 10673 | if (!drop && !user_to) //role was found |
| 10674 | DBUG_RETURN(1); |
| 10675 | |
| 10676 | /* this calls for a role update */ |
| 10677 | const char *old_key= acl_role->user.str; |
| 10678 | size_t old_key_length= acl_role->user.length; |
| 10679 | if (drop) |
| 10680 | { |
| 10681 | // delete the role from cross-reference arrays |
| 10682 | for (size_t i=0; i < acl_role->role_grants.elements; i++) |
| 10683 | { |
| 10684 | ACL_ROLE *grant= *dynamic_element(&acl_role->role_grants, |
| 10685 | i, ACL_ROLE**); |
| 10686 | remove_ptr_from_dynarray(&grant->parent_grantee, acl_role); |
| 10687 | } |
| 10688 | |
| 10689 | for (size_t i=0; i < acl_role->parent_grantee.elements; i++) |
| 10690 | { |
| 10691 | ACL_USER_BASE *grantee= *dynamic_element(&acl_role->parent_grantee, |
| 10692 | i, ACL_USER_BASE**); |
| 10693 | remove_ptr_from_dynarray(&grantee->role_grants, acl_role); |
| 10694 | } |
no test coverage detected