|
62 | 62 | bool mysql_user_table_is_in_short_password_format= false;
|
63 | 63 | bool using_global_priv_table= true;
|
64 | 64 |
|
| 65 | +// set that from field length in acl_load? |
| 66 | +const uint max_hostname_length= 60; |
| 67 | +const uint max_dbname_length= 64; |
| 68 | + |
| 69 | +#include "sql_acl_getsort.ic" |
| 70 | + |
65 | 71 | static LEX_CSTRING native_password_plugin_name= {
|
66 | 72 | STRING_WITH_LEN("mysql_native_password")
|
67 | 73 | };
|
@@ -117,7 +123,7 @@ static bool compare_hostname(const acl_host_and_ip *, const char *, const char *
|
117 | 123 |
|
118 | 124 | class ACL_ACCESS {
|
119 | 125 | public:
|
120 |
| - ulong sort; |
| 126 | + ulonglong sort; |
121 | 127 | ulong access;
|
122 | 128 | ACL_ACCESS()
|
123 | 129 | :sort(0), access(0)
|
@@ -284,7 +290,6 @@ ulong role_global_merges= 0, role_db_merges= 0, role_table_merges= 0,
|
284 | 290 |
|
285 | 291 | #ifndef NO_EMBEDDED_ACCESS_CHECKS
|
286 | 292 | static void update_hostname(acl_host_and_ip *host, const char *hostname);
|
287 |
| -static ulong get_sort(uint count,...); |
288 | 293 | static bool show_proxy_grants (THD *, const char *, const char *,
|
289 | 294 | char *, size_t);
|
290 | 295 | static bool show_role_grants(THD *, const char *, const char *,
|
@@ -332,7 +337,8 @@ class ACL_PROXY_USER :public ACL_ACCESS
|
332 | 337 | (proxied_host_arg && *proxied_host_arg) ?
|
333 | 338 | proxied_host_arg : NULL);
|
334 | 339 | with_grant= with_grant_arg;
|
335 |
| - sort= get_sort(4, host.hostname, user, proxied_host.hostname, proxied_user); |
| 340 | + sort= get_magic_sort("huhu", host.hostname, user, proxied_host.hostname, |
| 341 | + proxied_user); |
336 | 342 | }
|
337 | 343 |
|
338 | 344 | void init(MEM_ROOT *mem, const char *host_arg, const char *user_arg,
|
@@ -2344,7 +2350,7 @@ static bool acl_load(THD *thd, const Grant_tables& tables)
|
2344 | 2350 | }
|
2345 | 2351 | host.access= host_table.get_access();
|
2346 | 2352 | host.access= fix_rights_for_db(host.access);
|
2347 |
| - host.sort= get_sort(2, host.host.hostname, host.db); |
| 2353 | + host.sort= get_magic_sort("hd", host.host.hostname, host.db); |
2348 | 2354 | if (check_no_resolve && hostname_requires_resolving(host.host.hostname))
|
2349 | 2355 | {
|
2350 | 2356 | sql_print_warning("'host' entry '%s|%s' "
|
@@ -2386,7 +2392,7 @@ static bool acl_load(THD *thd, const Grant_tables& tables)
|
2386 | 2392 |
|
2387 | 2393 | user.access= user_table.get_access();
|
2388 | 2394 |
|
2389 |
| - user.sort= get_sort(2, user.host.hostname, user.user.str); |
| 2395 | + user.sort= get_magic_sort("hu", user.host.hostname, user.user.str); |
2390 | 2396 | user.hostname_length= safe_strlen(user.host.hostname);
|
2391 | 2397 |
|
2392 | 2398 | my_init_dynamic_array(&user.role_grants, sizeof(ACL_ROLE *), 0, 8, MYF(0));
|
@@ -2505,7 +2511,7 @@ static bool acl_load(THD *thd, const Grant_tables& tables)
|
2505 | 2511 | db.db, db.user, safe_str(db.host.hostname));
|
2506 | 2512 | }
|
2507 | 2513 | }
|
2508 |
| - db.sort=get_sort(3,db.host.hostname,db.db,db.user); |
| 2514 | + db.sort=get_magic_sort("hdu", db.host.hostname, db.db, db.user); |
2509 | 2515 | #ifndef TO_BE_REMOVED
|
2510 | 2516 | if (db_table.num_fields() <= 9)
|
2511 | 2517 | { // Without grant
|
@@ -2753,49 +2759,6 @@ static ulong get_access(TABLE *form, uint fieldnr, uint *next_field)
|
2753 | 2759 | }
|
2754 | 2760 |
|
2755 | 2761 |
|
2756 |
| -/* |
2757 |
| - Return a number which, if sorted 'desc', puts strings in this order: |
2758 |
| - no wildcards |
2759 |
| - wildcards |
2760 |
| - empty string |
2761 |
| -*/ |
2762 |
| - |
2763 |
| -static ulong get_sort(uint count,...) |
2764 |
| -{ |
2765 |
| - va_list args; |
2766 |
| - va_start(args,count); |
2767 |
| - ulong sort=0; |
2768 |
| - |
2769 |
| - /* Should not use this function with more than 4 arguments for compare. */ |
2770 |
| - DBUG_ASSERT(count <= 4); |
2771 |
| - |
2772 |
| - while (count--) |
2773 |
| - { |
2774 |
| - char *start, *str= va_arg(args,char*); |
2775 |
| - uint chars= 0; |
2776 |
| - uint wild_pos= 0; /* first wildcard position */ |
2777 |
| - |
2778 |
| - if ((start= str)) |
2779 |
| - { |
2780 |
| - for (; *str ; str++) |
2781 |
| - { |
2782 |
| - if (*str == wild_prefix && str[1]) |
2783 |
| - str++; |
2784 |
| - else if (*str == wild_many || *str == wild_one) |
2785 |
| - { |
2786 |
| - wild_pos= (uint) (str - start) + 1; |
2787 |
| - break; |
2788 |
| - } |
2789 |
| - chars= 128; // Marker that chars existed |
2790 |
| - } |
2791 |
| - } |
2792 |
| - sort= (sort << 8) + (wild_pos ? MY_MIN(wild_pos, 127U) : chars); |
2793 |
| - } |
2794 |
| - va_end(args); |
2795 |
| - return sort; |
2796 |
| -} |
2797 |
| - |
2798 |
| - |
2799 | 2762 | static int acl_compare(const ACL_ACCESS *a, const ACL_ACCESS *b)
|
2800 | 2763 | {
|
2801 | 2764 | if (a->sort > b->sort)
|
@@ -3157,7 +3120,7 @@ ACL_USER::ACL_USER(THD *thd, const LEX_USER &combo,
|
3157 | 3120 | user= safe_lexcstrdup_root(&acl_memroot, combo.user);
|
3158 | 3121 | update_hostname(&host, safe_strdup_root(&acl_memroot, combo.host.str));
|
3159 | 3122 | hostname_length= combo.host.length;
|
3160 |
| - sort= get_sort(2, host.hostname, user.str); |
| 3123 | + sort= get_magic_sort("hu", host.hostname, user.str); |
3161 | 3124 | password_last_changed= thd->query_start();
|
3162 | 3125 | password_lifetime= -1;
|
3163 | 3126 | my_init_dynamic_array(&role_grants, sizeof(ACL_USER *), 0, 8, MYF(0));
|
@@ -3314,7 +3277,7 @@ static void acl_insert_db(const char *user, const char *host, const char *db,
|
3314 | 3277 | update_hostname(&acl_db.host, safe_strdup_root(&acl_memroot, host));
|
3315 | 3278 | acl_db.db=strdup_root(&acl_memroot,db);
|
3316 | 3279 | acl_db.initial_access= acl_db.access= privileges;
|
3317 |
| - acl_db.sort=get_sort(3,acl_db.host.hostname,acl_db.db,acl_db.user); |
| 3280 | + acl_db.sort=get_magic_sort("hdu", acl_db.host.hostname, acl_db.db, acl_db.user); |
3318 | 3281 | acl_dbs.push(acl_db);
|
3319 | 3282 | rebuild_acl_dbs();
|
3320 | 3283 | }
|
@@ -5033,7 +4996,7 @@ class GRANT_NAME :public Sql_alloc
|
5033 | 4996 | char *db, *user, *tname, *hash_key;
|
5034 | 4997 | ulong privs;
|
5035 | 4998 | ulong init_privs; /* privileges found in physical table */
|
5036 |
| - ulong sort; |
| 4999 | + ulonglong sort; |
5037 | 5000 | size_t key_length;
|
5038 | 5001 | GRANT_NAME(const char *h, const char *d,const char *u,
|
5039 | 5002 | const char *t, ulong p, bool is_routine);
|
@@ -5079,7 +5042,7 @@ void GRANT_NAME::set_user_details(const char *h, const char *d,
|
5079 | 5042 | my_casedn_str(files_charset_info, db);
|
5080 | 5043 | }
|
5081 | 5044 | user = strdup_root(&grant_memroot,u);
|
5082 |
| - sort= get_sort(3,host.hostname,db,user); |
| 5045 | + sort= get_magic_sort("hdu", host.hostname, db, user); |
5083 | 5046 | if (tname != t)
|
5084 | 5047 | {
|
5085 | 5048 | tname= strdup_root(&grant_memroot, t);
|
@@ -5121,7 +5084,7 @@ GRANT_NAME::GRANT_NAME(TABLE *form, bool is_routine)
|
5121 | 5084 | update_hostname(&host, hostname);
|
5122 | 5085 |
|
5123 | 5086 | db= get_field(&grant_memroot,form->field[1]);
|
5124 |
| - sort= get_sort(3, host.hostname, db, user); |
| 5087 | + sort= get_magic_sort("hdu", host.hostname, db, user); |
5125 | 5088 | tname= get_field(&grant_memroot,form->field[3]);
|
5126 | 5089 | if (!db || !tname)
|
5127 | 5090 | {
|
@@ -6214,7 +6177,7 @@ static int update_role_db(int merged, int first, ulong access,
|
6214 | 6177 | acl_db.db= acl_dbs.at(first).db;
|
6215 | 6178 | acl_db.access= access;
|
6216 | 6179 | acl_db.initial_access= 0;
|
6217 |
| - acl_db.sort=get_sort(3, "", acl_db.db, role); |
| 6180 | + acl_db.sort= get_magic_sort("hdu", "", acl_db.db, role); |
6218 | 6181 | acl_dbs.push(acl_db);
|
6219 | 6182 | return 2;
|
6220 | 6183 | }
|
|
0 commit comments