dbproxy-user/pwd

Posted taek

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dbproxy-user/pwd相关的知识,希望对你有一定的参考价值。

dbproxy 的账号是统一的, 即连接dbproxy,连接主mysql ,连接从mysql 的账号必须一样, 为了隔离 即使用dbproxy的人感知不到mysql, 需要分离

配置文件

#dbproxy账号密码与real 主mysql 和 从mysql 隔离
dbproxy-user=test
dbproxy-pwd=7O7YJJEK
master-user = master
master-pwd = 7O7YJJEK
slave-user = slave
slave-pwd = 7O7YJJEK

 

struct chassis_plugin_config
位置plugins/proxy/proxy-plugin.h

struct chassis_plugin_config {
    ...
    gchar* id_generate;
    gchar* dbproxy_user;
    gchar* dbproxy_pwd;
    gchar* master_user;
    gchar* master_pwd;
    gchar* slave_user;
    gchar* slave_pwd;
    ...
}

 

 

network_mysqld_proxy_plugin_new
位置:/plugins/proxy/proxy-plugin.c

 

chassis_plugin_config * network_mysqld_proxy_plugin_new(void) {
    ...
    config = g_new0(chassis_plugin_config, 1);
    config->id_generate    = NULL;
    config->dbproxy_user = NULL;
    config->dbproxy_pwd = NULL;
    config->master_user  = NULL;
    config->master_pwd  = NULL;
    config->slave_user    = NULL;
    config->slave_pwd    = NULL;
    ...
}

 

network_mysqld_proxy_plugin_free
位置:/plugins/proxy/proxy-plugin.c

void network_mysqld_proxy_plugin_free(chassis_plugin_config *oldconfig) {
    ...
    if (config->id_generate) g_free(config->id_generate);
    if (config->dbproxy_user) g_free(config->dbproxy_user);
    if (config->dbproxy_pwd) g_free(config->dbproxy_pwd);
    if (config->master_user) g_free(config->master_user);
    if (config->master_pwd) g_free(config->master_pwd);
    if (config->slave_user) g_free(config->slave_user);
    if (config->slave_pwd) g_free(config->slave_pwd);
    ...
}

 

 

network_mysqld_proxy_plugin_get_options
位置:/plugins/proxy/proxy-plugin.c

static chassis_options_t * network_mysqld_proxy_plugin_get_options(chassis_plugin_config *oldconfig) {
    if (config->opts == NULL) {
        chassis_options_t *opts = chassis_options_new();
        chassis_options_add(opts, "id-generate", 0, 0, G_OPTION_ARG_STRING, &(config->id_generate), "id-generate", NULL, NULL, NULL, 0);

        chassis_options_add(opts, "dbproxy-user", 0, 0, G_OPTION_ARG_STRING, &(config->dbproxy_user), "dbproxy-user", NULL, NULL, NULL, 0);

        chassis_options_add(opts, "dbproxy-pwd", 0, 0, G_OPTION_ARG_STRING, &(config->dbproxy_pwd), "dbproxy-pwd", NULL, NULL, NULL, 0);

        chassis_options_add(opts, "master-user", 0, 0, G_OPTION_ARG_STRING, &(config->master_user), "master-user", NULL, NULL, NULL, 0);

        chassis_options_add(opts, "master-pwd", 0, 0, G_OPTION_ARG_STRING, &(config->master_pwd), "master-pwd", NULL, NULL, NULL, 0);

        chassis_options_add(opts, "slave-user", 0, 0, G_OPTION_ARG_STRING, &(config->slave_user), "slave-user", NULL, NULL, NULL, 0);

        chassis_options_add(opts, "slave-pwd", 0, 0, G_OPTION_ARG_STRING, &(config->slave_pwd), "slave-pwd", NULL, NULL, NULL, 0);

        config->opts = opts;
    }
    return config->opts;
}

 

 

network_mysqld_proxy_plugin_apply_config
位置:/plugins/proxy/proxy-plugin.c

int network_mysqld_proxy_plugin_apply_config(chassis *chas, chassis_plugin_config *oldconfig) {
    gchar *user = NULL, *pwd = NULL, *user_master = NULL, *pwd_master = NULL, *user_slave = NULL, *pwd_slave = NULL;
    user = config->dbproxy_user;
    pwd = config->dbproxy_pwd;
    user_master = config->master_user;
    pwd_master = config->master_pwd;
    user_slave = config->slave_user;
    pwd_slave = config->slave_pwd;

    char* raw_pwd = decrypt(pwd);
    char* raw_pwd_master = decrypt(pwd_master);
    char* raw_pwd_slave = decrypt(pwd_slave);

    if (raw_pwd && raw_pwd_master && raw_pwd_slave) {
        GString* hashed_password = g_string_new(NULL);
        network_mysqld_proto_password_hash(hashed_password, raw_pwd, strlen(raw_pwd));
        
        /*
        主库 设置密码
        */
        GString* hashed_password_master = g_string_new(NULL);
        network_mysqld_proto_password_hash(hashed_password_master, raw_pwd_master, strlen(raw_pwd_master));
                
        /*
        从库 设置密码
        */
        GString* hashed_password_slave = g_string_new(NULL);
        network_mysqld_proto_password_hash(hashed_password_slave, raw_pwd_slave, strlen(raw_pwd_slave));
            


        user_info_hval *hval = user_info_hval_new(hashed_password, hashed_password_master, user_master, hashed_password_slave, user_slave);

        // g_log_dbproxy(g_critical, "hashed_password_slave is %s ,len is %d", hval->hashed_password_slave->str, hval->hashed_password_slave->len);
        raw_user_info *rwi = raw_user_info_new(user, pwd, NULL, NULL, user_master, pwd_master, user_slave, pwd_slave);


        g_rw_lock_writer_lock(&bs->user_mgr_lock);
        if (g_hash_table_lookup(bs->pwd_table, user) == NULL) {
            g_hash_table_insert(bs->pwd_table, g_strdup(user), hval);
            g_ptr_array_add(bs->raw_pwds, rwi);
        }
        g_rw_lock_writer_unlock(&bs->user_mgr_lock);

        //g_free(tmp_for_free);
        g_free(raw_pwd);
}

 

 

 

 

 

 

 

 

 

 

以上是关于dbproxy-user/pwd的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段——CSS选择器

谷歌浏览器调试jsp 引入代码片段,如何调试代码片段中的js

片段和活动之间的核心区别是啥?哪些代码可以写成片段?

VSCode自定义代码片段——.vue文件的模板

VSCode自定义代码片段6——CSS选择器

VSCode自定义代码片段——声明函数