Skip to content

Commit

Permalink
Add column comment in mysql_users table #1633
Browse files Browse the repository at this point in the history
Added online migration from previous table definition (1.3.0 and 1.4.0).
LOAD MYSQL USERS TO RUNTIME and SAVE MYSQL USERS TO MEMORY handle the new field
comment can be read also from config file
ProxySQL Cluster reads comment from remote node
  • Loading branch information
renecannao committed Aug 8, 2018
1 parent 7202338 commit 73f73b6
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 44 deletions.
3 changes: 2 additions & 1 deletion include/MySQL_Authentication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef struct _account_details_t {
bool __frontend; // this is used only during the dump
bool __backend; // this is used only during the dump
bool __active;
char *comment;
} account_details_t;

typedef std::map<uint64_t, account_details_t *> umap_auth;
Expand Down Expand Up @@ -60,7 +61,7 @@ class MySQL_Authentication {
public:
MySQL_Authentication();
~MySQL_Authentication();
bool add(char *username, char *password, enum cred_username_type usertype, bool use_ssl, int default_hostgroup, char *default_schema, bool schema_locked, bool transaction_persistent, bool fast_forward, int max_connections);
bool add(char *username, char *password, enum cred_username_type usertype, bool use_ssl, int default_hostgroup, char *default_schema, bool schema_locked, bool transaction_persistent, bool fast_forward, int max_connections, char *comment);
bool del(char *username, enum cred_username_type usertype, bool set_lock=true);
bool reset();
void print_version();
Expand Down
21 changes: 18 additions & 3 deletions lib/MySQL_Authentication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void MySQL_Authentication::remove_inactives(enum cred_username_type usertype) {
#endif
}

bool MySQL_Authentication::add(char * username, char * password, enum cred_username_type usertype, bool use_ssl, int default_hostgroup, char *default_schema, bool schema_locked, bool transaction_persistent, bool fast_forward, int max_connections) {
bool MySQL_Authentication::add(char * username, char * password, enum cred_username_type usertype, bool use_ssl, int default_hostgroup, char *default_schema, bool schema_locked, bool transaction_persistent, bool fast_forward, int max_connections, char *comment) {
uint64_t hash1, hash2;
SpookyHash myhash;
myhash.Init(1,2);
Expand Down Expand Up @@ -109,10 +109,15 @@ bool MySQL_Authentication::add(char * username, char * password, enum cred_usern
free(ad->default_schema);
ad->default_schema=strdup(default_schema);
}
if (strcmp(ad->comment,comment)) {
free(ad->comment);
ad->comment=strdup(comment);
}
} else {
ad=(account_details_t *)malloc(sizeof(account_details_t));
ad->username=strdup(username);
ad->default_schema=strdup(default_schema);
ad->comment=strdup(comment);
ad->password=strdup(password);
new_ad=true;
ad->sha1_pass=NULL;
Expand Down Expand Up @@ -156,6 +161,7 @@ unsigned int MySQL_Authentication::memory_usage() {
if (ado->password) ret += strlen(ado->password) + 1;
if (ado->sha1_pass) ret += SHA_DIGEST_LENGTH;
if (ado->default_schema) ret += strlen(ado->default_schema) + 1;
if (ado->comment) ret += strlen(ado->comment) + 1;
}
ret += sizeof(creds_group_t);
ret += sizeof(PtrArray);
Expand All @@ -167,6 +173,7 @@ unsigned int MySQL_Authentication::memory_usage() {
if (ado->password) ret += strlen(ado->password) + 1;
if (ado->sha1_pass) ret += SHA_DIGEST_LENGTH;
if (ado->default_schema) ret += strlen(ado->default_schema) + 1;
if (ado->comment) ret += strlen(ado->comment) + 1;
}
ret += sizeof(creds_group_t);
ret += sizeof(PtrArray);
Expand Down Expand Up @@ -208,6 +215,7 @@ int MySQL_Authentication::dump_all_users(account_details_t ***ads, bool _complet
if (_complete==false) {
ad->password=NULL;
ad->default_schema=NULL;
ad->comment=NULL;
ad->num_connections_used=ado->num_connections_used;
} else {
ad->num_connections_used=ado->num_connections_used;
Expand All @@ -216,6 +224,7 @@ int MySQL_Authentication::dump_all_users(account_details_t ***ads, bool _complet
ad->sha1_pass=NULL;
ad->use_ssl=ado->use_ssl;
ad->default_schema=strdup(ado->default_schema);
ad->comment=strdup(ado->comment);
ad->schema_locked=ado->schema_locked;
ad->transaction_persistent=ado->transaction_persistent;
ad->fast_forward=ado->fast_forward;
Expand All @@ -236,6 +245,7 @@ int MySQL_Authentication::dump_all_users(account_details_t ***ads, bool _complet
ad->use_ssl=ado->use_ssl;
ad->default_hostgroup=ado->default_hostgroup;
ad->default_schema=strdup(ado->default_schema);
ad->comment=strdup(ado->comment);
ad->schema_locked=ado->schema_locked;
ad->transaction_persistent=ado->transaction_persistent;
ad->fast_forward=ado->fast_forward;
Expand Down Expand Up @@ -348,6 +358,7 @@ bool MySQL_Authentication::del(char * username, enum cred_username_type usertype
free(ad->password);
if (ad->sha1_pass) { free(ad->sha1_pass); ad->sha1_pass=NULL; }
free(ad->default_schema);
free(ad->comment);
free(ad);
ret=true;
}
Expand Down Expand Up @@ -452,11 +463,12 @@ bool MySQL_Authentication::_reset(enum cred_username_type usertype) {
lookup = cg.bt_map.begin();
if ( lookup != cg.bt_map.end() ) {
account_details_t *ad=lookup->second;
cg.bt_map.erase(lookup);
cg.bt_map.erase(lookup);
free(ad->username);
free(ad->password);
if (ad->sha1_pass) { free(ad->sha1_pass); ad->sha1_pass=NULL; }
free(ad->default_schema);
free(ad->comment);
free(ad);
}
}
Expand Down Expand Up @@ -499,7 +511,10 @@ uint64_t MySQL_Authentication::_get_runtime_checksum(enum cred_username_type use
myhash.Update(&ad->max_connections,sizeof(ad->max_connections));
myhash.Update(ad->username,strlen(ad->username));
myhash.Update(ad->password,strlen(ad->password));
myhash.Update(ad->default_schema,strlen(ad->default_schema));
if (ad->default_schema)
myhash.Update(ad->default_schema,strlen(ad->default_schema));
if (ad->comment)
myhash.Update(ad->comment,strlen(ad->comment));
}
it++;
}
Expand Down
Loading

0 comments on commit 73f73b6

Please sign in to comment.