@@ -73,6 +73,7 @@ network_backends_t *network_backends_new(guint event_thread_count, gchar *defaul
7373 bs -> global_wrr = g_wrr_poll_new ();
7474 bs -> event_thread_count = event_thread_count ;
7575 bs -> default_file = g_strdup (default_file );
76+ bs -> raw_pwds = g_hash_table_new_full (g_str_hash , g_str_equal , g_free , g_free );
7677
7778 return bs ;
7879}
@@ -112,6 +113,9 @@ void network_backends_free(network_backends_t *bs) {
112113 g_wrr_poll_free (bs -> global_wrr );
113114 g_free (bs -> default_file );
114115
116+ g_hash_table_remove_all (bs -> raw_pwds );
117+ g_hash_table_destroy (bs -> raw_pwds );
118+
115119 g_free (bs );
116120}
117121
@@ -182,6 +186,8 @@ int network_backends_addpwd(network_backends_t *bs, gchar *address) {
182186 g_hash_table_insert (new_table , g_strdup (user ), hashed_password );
183187 g_atomic_int_set (bs -> pwd_table_index , 1 - index );
184188
189+ g_hash_table_insert (bs -> raw_pwds , g_strdup (user ), g_strdup (pwd ));
190+
185191 return 0 ;
186192}
187193
@@ -212,6 +218,7 @@ int network_backends_removepwd(network_backends_t *bs, gchar *address) {
212218 g_hash_table_foreach (old_table , copy_pwd , new_table );
213219 g_hash_table_remove (new_table , address );
214220 g_atomic_int_set (bs -> pwd_table_index , 1 - index );
221+ g_hash_table_remove (bs -> raw_pwds , address );
215222
216223 return 0 ;
217224}
@@ -286,6 +293,23 @@ int network_backends_save(network_backends_t *bs) {
286293
287294 g_string_free (client_ips , TRUE);
288295
296+ GHashTableIter iter ;
297+ g_hash_table_iter_init (& iter , bs -> raw_pwds );
298+ gchar * user = NULL , * pwd = NULL ;
299+
300+ GString * pwds = g_string_new (NULL );
301+ while (g_hash_table_iter_next (& iter , & user , & pwd )) {
302+ g_string_append_printf (pwds , ",%s:%s" , user , pwd );
303+ }
304+
305+ if (pwds -> len != 0 ) {
306+ g_key_file_set_value (keyfile , "mysql-proxy" , "pwds" , pwds -> str + 1 );
307+ } else {
308+ g_key_file_set_value (keyfile , "mysql-proxy" , "pwds" , "" );
309+ }
310+
311+ g_string_free (pwds , TRUE);
312+
289313 gsize file_size = 0 ;
290314 gchar * file_buf = g_key_file_to_data (keyfile , & file_size , NULL );
291315 if (FALSE == g_file_set_contents (bs -> default_file , file_buf , file_size , & gerr )) {
0 commit comments