Revert "Added resolving of wildcard database grants to multiple single database grants to mysql_client."
This reverts commit 2a416a8cbab5140595f4d2de73d76cefdf3667de.
This commit is contained in:
@ -50,7 +50,6 @@
|
|||||||
#include <secrets.h>
|
#include <secrets.h>
|
||||||
#include <mysql_client_server_protocol.h>
|
#include <mysql_client_server_protocol.h>
|
||||||
#include <mysqld_error.h>
|
#include <mysqld_error.h>
|
||||||
#include <regex.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define DEFAULT_CONNECT_TIMEOUT 3
|
#define DEFAULT_CONNECT_TIMEOUT 3
|
||||||
@ -111,16 +110,6 @@ void *resource_fetch(HASHTABLE *, char *);
|
|||||||
int resource_add(HASHTABLE *, char *, char *);
|
int resource_add(HASHTABLE *, char *, char *);
|
||||||
int resource_hash(char *);
|
int resource_hash(char *);
|
||||||
static int normalize_hostname(char *input_host, char *output_host);
|
static int normalize_hostname(char *input_host, char *output_host);
|
||||||
int wildcard_db_grant(char* str);
|
|
||||||
|
|
||||||
int add_wildcard_users(USERS *users,
|
|
||||||
char* name,
|
|
||||||
char* host,
|
|
||||||
char* password,
|
|
||||||
char* anydb,
|
|
||||||
char* db,
|
|
||||||
HASHTABLE* hash);
|
|
||||||
|
|
||||||
static int gw_mysql_set_timeouts(
|
static int gw_mysql_set_timeouts(
|
||||||
MYSQL* handle,
|
MYSQL* handle,
|
||||||
int read_timeout,
|
int read_timeout,
|
||||||
@ -908,16 +897,7 @@ getAllUsers(SERVICE *service, USERS *users)
|
|||||||
dbnm)));
|
dbnm)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
rc = add_mysql_users_with_host_ipv4(users, row[0], row[1], password, row[4],havedb ? dbnm : NULL);
|
||||||
if(havedb && wildcard_db_grant(dbnm))
|
|
||||||
{
|
|
||||||
rc = add_wildcard_users(users, row[0], row[1], password, row[4], dbnm, service->resources);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rc = add_mysql_users_with_host_ipv4(users, row[0], row[1], password, row[4], havedb ? dbnm : NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
skygw_log_write(LOGFILE_DEBUG,"%s: Adding user:%s host:%s anydb:%s db:%s.",
|
skygw_log_write(LOGFILE_DEBUG,"%s: Adding user:%s host:%s anydb:%s db:%s.",
|
||||||
service->name,row[0],row[1],row[4],
|
service->name,row[0],row[1],row[4],
|
||||||
havedb ? dbnm : NULL);
|
havedb ? dbnm : NULL);
|
||||||
@ -1391,16 +1371,7 @@ getUsers(SERVICE *service, USERS *users)
|
|||||||
|
|
||||||
if (db_grants) {
|
if (db_grants) {
|
||||||
/* we have dbgrants, store them */
|
/* we have dbgrants, store them */
|
||||||
|
|
||||||
if(wildcard_db_grant(row[5]))
|
|
||||||
{
|
|
||||||
rc = add_wildcard_users(users, row[0], row[1], password, row[4], row[5], service->resources);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rc = add_mysql_users_with_host_ipv4(users, row[0], row[1], password, row[4], row[5]);
|
rc = add_mysql_users_with_host_ipv4(users, row[0], row[1], password, row[4], row[5]);
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* we don't have dbgrants, simply set ANY DB for the user */
|
/* we don't have dbgrants, simply set ANY DB for the user */
|
||||||
rc = add_mysql_users_with_host_ipv4(users, row[0], row[1], password, "Y", NULL);
|
rc = add_mysql_users_with_host_ipv4(users, row[0], row[1], password, "Y", NULL);
|
||||||
@ -2092,82 +2063,3 @@ dbusers_load(USERS *users, char *filename)
|
|||||||
{
|
{
|
||||||
return hashtable_load(users->data, filename, dbusers_keyread, dbusers_valueread);
|
return hashtable_load(users->data, filename, dbusers_keyread, dbusers_valueread);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the database name contains a wildcard character
|
|
||||||
* @param str Database grant
|
|
||||||
* @return 1 if the name contains the '%' wildcard character, 0 if it does not
|
|
||||||
*/
|
|
||||||
int wildcard_db_grant(char* str)
|
|
||||||
{
|
|
||||||
char* ptr = str;
|
|
||||||
|
|
||||||
while(ptr && *ptr != '\0')
|
|
||||||
{
|
|
||||||
if(*ptr == '%')
|
|
||||||
return 1;
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int add_wildcard_users(USERS *users, char* name, char* host, char* password, char* anydb, char* db, HASHTABLE* hash)
|
|
||||||
{
|
|
||||||
HASHITERATOR* iter;
|
|
||||||
HASHTABLE* ht = hash;
|
|
||||||
char *restr,*ptr,*value;
|
|
||||||
int len,err,rval = 0;
|
|
||||||
char errbuf[1024];
|
|
||||||
regex_t re;
|
|
||||||
|
|
||||||
if(db == NULL || hash == NULL)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if((restr = malloc(sizeof(char)*strlen(db)*2)) == NULL)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
strcpy(restr,db);
|
|
||||||
|
|
||||||
len = strlen(restr);
|
|
||||||
ptr = strchr(restr,'%');
|
|
||||||
|
|
||||||
if(ptr == NULL)
|
|
||||||
{
|
|
||||||
free(restr);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(ptr)
|
|
||||||
{
|
|
||||||
memmove(ptr,ptr+1,(len - (ptr - restr)) + 1);
|
|
||||||
len = strlen(restr);
|
|
||||||
ptr = strchr(restr,'%');
|
|
||||||
}
|
|
||||||
|
|
||||||
if((err = regcomp(&re,restr,REG_ICASE|REG_NOSUB)))
|
|
||||||
{
|
|
||||||
regerror(err,&re,errbuf,1024);
|
|
||||||
skygw_log_write(LOGFILE_ERROR,"Error: Failed to compile regex "
|
|
||||||
"when resolving wildcard database grants: %s",
|
|
||||||
errbuf);
|
|
||||||
free(restr);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
iter = hashtable_iterator(ht);
|
|
||||||
|
|
||||||
while(iter && (value = hashtable_next(iter)))
|
|
||||||
{
|
|
||||||
if(regexec(&re,value,0,NULL,0) == 0)
|
|
||||||
{
|
|
||||||
rval = add_mysql_users_with_host_ipv4(users, name, host, password, anydb, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hashtable_iterator_free(iter);
|
|
||||||
regfree(&re);
|
|
||||||
free(restr);
|
|
||||||
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user