diff --git a/Common/config_manager.h b/Common/config_manager.h index dcbf0869e..c07b5c42f 100755 --- a/Common/config_manager.h +++ b/Common/config_manager.h @@ -45,8 +45,9 @@ #define USER_MANAGER_CONFIG_USER (uint64)((uint64)USER_MANAGER_CONFIG_MODULE<<32|2) #define USER_MANAGER_CONFIG_RECOVER (uint64)((uint64)USER_MANAGER_CONFIG_MODULE<<32|3) -#define AUTHFREE_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|1) -#define FREEPARAMETERS_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|2) +#define AUTHFREE_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|1) +#define FREEPARAMETERS_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|2) +#define AUTH_CONFIG_RECOVER (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|3) #define LOG_CONFIG_CONSOLE (uint64)((uint64)LOG_CONFIG_MODULE<<32|1) diff --git a/Platform/build/user.configm.Makefile b/Platform/build/user.configm.Makefile index b38b6a0f8..cea8c2a28 100755 --- a/Platform/build/user.configm.Makefile +++ b/Platform/build/user.configm.Makefile @@ -33,7 +33,7 @@ COMMON_SRCS = configserver.c \ netconfig/bridge/libbridge/libbridge_if.c netconfig/bridge/libbridge/libbridge_init.c netconfig/bridge/libbridge/libbridge_devif.c\ web_config/config-adm/user_authpara.c \ web_config/config-adm/user_authfree.c \ - web_config/authfree.c web_config/auth_parameters.c\ + web_config/authfree.c web_config/auth_parameters.c web_config/auth_recover_config.c \ user_manager_config/user_recover_config.c user_manager_config/user_group_config.c user_manager_config/user_account_config.c user_manager_config/usermanager-server/array_index.c \ user_manager_config/usermanager-server/user_group.c user_manager_config/usermanager-server/user_mod.c user_manager_config/usermanager-server/user.c \ log_config/log_config_console.c log_config/log_config_init.c log_config/log_config_cm.c log_config/log_config_monitor.c log_config/log_config_remote.c log_config/log_config_file.c \ diff --git a/Platform/user/configm/config-server/include/configm.h b/Platform/user/configm/config-server/include/configm.h index 49c3913ac..e6c97eac7 100755 --- a/Platform/user/configm/config-server/include/configm.h +++ b/Platform/user/configm/config-server/include/configm.h @@ -1,262 +1,272 @@ -#ifndef CONFIGM_H_ -#define CONFIGM_H_ -#include "config_manager.h" -#include "s2j/s2j.h" -#include "../../../../common/rpc/rpc_common.h" -#include "../../../../../Common/commuapinl.h" -#include "../user_manager_config/user_group_config.h" -#include "../user_manager_config/user_account_config.h" -#include "../user_manager_config/user_recover_config.h" -#include "netconfig.h" -#include "log_config.h" -#include "../web_config/authfree.h" -#include "../web_config/auth_parameters.h" -#include "natconfig.h" -#include "vlan_config.h" - -#define RET_CODE_LEN 16 -#define RET_MSG_LEN 128 - -#define CONFIG_INIT_ARRAY \ -{\ - { \ - NETCONFIG_MODULE, \ - net_main \ - }, \ - { \ - LOG_CONFIG_MODULE, \ - log_config_init \ - }, \ - { \ - VLAN_CONFIG_MODULE, \ - vlan_config_init \ - } \ -} - -/* - 1、配置ID,全局唯一,用于寻找对应的配置业务 - 2、配置源检查,全局唯一,用于寻找对应的配置业务, - 从低位到高位,第一位表示WEB,后续配置扩展 - 3、是否配置恢复 - 4、是否是多实例 - 5、配置校验回调函数 - 6、配置处理接口 - 7、配置获取接口 - 8、配置全部获取接口 -*/ -#define CONFIG_SERVICE_ARRAY \ -{ \ - {\ - IPCONFIG_V4, \ - CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ - FALSE, \ - ip_config_chk, \ - ip_config_proc, \ - ip_config_get, \ - ip_config_get_all \ - },\ - {\ - BR_CONFIG, \ - CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ - FALSE, \ - br_config_chk, \ - br_config_proc, \ - NULL, \ - NULL \ - },\ - {\ - BRIF_CONFIG, \ - CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ - FALSE, \ - br_if_config_chk, \ - br_if_config_proc, \ - br_if_config_get, \ - br_if_config_get_all \ - },\ - {\ - BRFDB_CONFIG, \ - CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ - FALSE, \ - br_fdb_config_chk, \ - NULL, \ - br_fdb_config_get, \ - NULL \ - },\ - {\ - USER_MANAGER_CONFIG_GROUP, \ - CONFIG_FROM_WEB, \ - FALSE, \ - usergroup_config_chk, \ - usergroup_config_proc, \ - usergroup_config_get, \ - usergroup_config_get_all \ - },\ - {\ - USER_MANAGER_CONFIG_RECOVER, \ - CONFIG_FROM_RECOVER1, \ - TRUE, \ - userecover_config_chk, \ - userecover_config_proc, \ - userecover_config_get, \ - userecover_config_get_all \ - },\ - { \ - AUTHFREE_CONFIG, \ - CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ - FALSE, \ - freeauth_config_chk, \ - freeauth_config_proc, \ - NULL, \ - NULL \ - },\ - {\ - FREEPARAMETERS_CONFIG, \ - CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ - FALSE, \ - authpara_config_chk, \ - authpara_config_proc, \ - NULL, \ - NULL \ - },\ - {\ - USER_MANAGER_CONFIG_USER, \ - CONFIG_FROM_WEB, \ - FALSE, \ - user_config_chk, \ - user_config_proc, \ - user_config_get, \ - user_config_get_all \ - },\ - {\ - LOG_CONFIG_CONSOLE, \ - CONFIG_FROM_WEB, \ - FALSE, \ - log_console_config_chk, \ - log_console_config_proc, \ - log_console_config_get, \ - log_console_config_getall \ - },\ - {\ - LOG_CONFIG_MONITOR, \ - CONFIG_FROM_WEB, \ - FALSE, \ - log_monitor_config_chk, \ - log_monitor_config_proc, \ - log_monitor_config_get, \ - log_monitor_config_getall \ - },\ - {\ - LOG_CONFIG_REMOTE_ADD_HOST, \ - CONFIG_FROM_WEB, \ - FALSE, \ - log_remote_host_config_chk, \ - log_remote_add_host_config_proc, \ - NULL, \ - NULL \ - },\ - {\ - LOG_CONFIG_REMOTE_DEL_HOST, \ - CONFIG_FROM_WEB, \ - FALSE, \ - log_remote_host_config_chk, \ - log_remote_del_host_config_proc, \ - NULL, \ - NULL \ - },\ - {\ - LOG_CONFIG_REMOTE_LEVEL, \ - CONFIG_FROM_WEB, \ - FALSE, \ - log_remote_level_config_chk, \ - log_remote_level_config_proc, \ - log_remote_level_config_get, \ - log_remote_level_config_getall \ - },\ - {\ - LOG_CONFIG_FILE, \ - CONFIG_FROM_WEB, \ - FALSE, \ - log_file_config_chk, \ - log_file_config_proc, \ - log_file_config_get, \ - log_file_config_getall \ - },\ - {\ - LOG_CONFIG_REMOTE_GET_HOST, \ - CONFIG_FROM_WEB, \ - FALSE, \ - log_remote_host_x_config_chk, \ - NULL, \ - log_remote_host_x_config_get, \ - log_remote_host_x_config_getall \ - },\ - {\ - NAT4_CONFIG, \ - CONFIG_FROM_WEB, \ - FALSE, \ - nat_config_chk, \ - nat_config_proc, \ - NULL, \ - nat_config_get_all \ - },\ - {\ - VLAN_CONFIG, \ - CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ - FALSE, \ - vlan_config_chk, \ - vlan_config_proc, \ - vlan_config_get, \ - vlan_config_get_all \ - }\ -} - -typedef ret_code (*cm_config_init)(); - -typedef ret_code (*cm_config_chk)(uint source, uint *config_type, - pointer input, int *input_len, - pointer output, int *output_len); - -typedef ret_code (*cm_config_proc)(uint source, uint config_type, - pointer input, int input_len, - pointer output, int *output_len); - -typedef ret_code (*cm_config_get)(uint source, - pointer input, int input_len, - pointer output, int *output_len); - -typedef ret_code (*cm_config_get_all)(uint source, - pointer output, int *output_len); - -/* 配置注册 */ -struct _config_init { - uint config_mudlue; - cm_config_init init_callback; -}; -typedef struct _config_init config_init_t; - - -/* 配置注册 */ -struct _config_service { - uint64 config_id; /* 配置ID,全局唯一,用于寻找对应的配置业务*/ - uint config_src; /* 配置源检查,全局唯一,用于寻找对应的配置业务,从低位到高位,第一位表示web,后续配置扩展 */ - boolean recovery; /* 配置恢复处理函数,如果为FALSE则不进行配置恢复 */ - cm_config_chk chk_callback; /* 配置校验回调函数 */ - cm_config_proc proc_callback; /* 配置接口 */ - cm_config_get get_callback; /* 获取配置接口 */ - cm_config_get_all getall_callback; /* 获取所有配置接口 */ -}; - -typedef struct _config_service config_service_t; - -struct _config_result { - char resultCode[RET_CODE_LEN]; - char *message; - char *data; -}; - -typedef struct _config_result config_result_t; - -int cm_format_data(ret_code ret_code, cJSON *json_obj, char *output); - -#endif /* RPC_COMMON_H_ */ - +#ifndef CONFIGM_H_ +#define CONFIGM_H_ +#include "config_manager.h" +#include "s2j/s2j.h" +#include "../../../../common/rpc/rpc_common.h" +#include "../../../../../Common/commuapinl.h" +#include "../user_manager_config/user_group_config.h" +#include "../user_manager_config/user_account_config.h" +#include "../user_manager_config/user_recover_config.h" +#include "netconfig.h" +#include "log_config.h" +#include "../web_config/authfree.h" +#include "../web_config/auth_parameters.h" +#include "../web_config/auth_recover_config.h" +#include "natconfig.h" +#include "vlan_config.h" + +#define RET_CODE_LEN 16 +#define RET_MSG_LEN 128 + +#define CONFIG_INIT_ARRAY \ +{\ + { \ + NETCONFIG_MODULE, \ + net_main \ + }, \ + { \ + LOG_CONFIG_MODULE, \ + log_config_init \ + }, \ + { \ + VLAN_CONFIG_MODULE, \ + vlan_config_init \ + } \ +} + +/* + 1、配置ID,全局唯一,用于寻找对应的配置业务 + 2、配置源检查,全局唯一,用于寻找对应的配置业务, + 从低位到高位,第一位表示WEB,后续配置扩展 + 3、是否配置恢复 + 4、是否是多实例 + 5、配置校验回调函数 + 6、配置处理接口 + 7、配置获取接口 + 8、配置全部获取接口 +*/ +#define CONFIG_SERVICE_ARRAY \ +{ \ + {\ + IPCONFIG_V4, \ + CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ + FALSE, \ + ip_config_chk, \ + ip_config_proc, \ + ip_config_get, \ + ip_config_get_all \ + },\ + {\ + BR_CONFIG, \ + CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ + FALSE, \ + br_config_chk, \ + br_config_proc, \ + NULL, \ + NULL \ + },\ + {\ + BRIF_CONFIG, \ + CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ + FALSE, \ + br_if_config_chk, \ + br_if_config_proc, \ + br_if_config_get, \ + br_if_config_get_all \ + },\ + {\ + BRFDB_CONFIG, \ + CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ + FALSE, \ + br_fdb_config_chk, \ + NULL, \ + br_fdb_config_get, \ + NULL \ + },\ + {\ + USER_MANAGER_CONFIG_GROUP, \ + CONFIG_FROM_WEB, \ + FALSE, \ + usergroup_config_chk, \ + usergroup_config_proc, \ + usergroup_config_get, \ + usergroup_config_get_all \ + },\ + {\ + USER_MANAGER_CONFIG_RECOVER, \ + CONFIG_FROM_RECOVER1, \ + TRUE, \ + userecover_config_chk, \ + userecover_config_proc, \ + userecover_config_get, \ + userecover_config_get_all \ + },\ + { \ + AUTHFREE_CONFIG, \ + CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ + FALSE, \ + freeauth_config_chk, \ + freeauth_config_proc, \ + NULL, \ + NULL \ + },\ + {\ + FREEPARAMETERS_CONFIG, \ + CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ + FALSE, \ + authpara_config_chk, \ + authpara_config_proc, \ + NULL, \ + NULL \ + },\ + {\ + AUTH_CONFIG_RECOVER, \ + CONFIG_FROM_RECOVER1, \ + TRUE, \ + auth_recover_chk, \ + auth_recover_proc, \ + auth_recover_get, \ + auth_recover_get_all \ + },\ + {\ + USER_MANAGER_CONFIG_USER, \ + CONFIG_FROM_WEB, \ + FALSE, \ + user_config_chk, \ + user_config_proc, \ + user_config_get, \ + user_config_get_all \ + },\ + {\ + LOG_CONFIG_CONSOLE, \ + CONFIG_FROM_WEB, \ + FALSE, \ + log_console_config_chk, \ + log_console_config_proc, \ + log_console_config_get, \ + log_console_config_getall \ + },\ + {\ + LOG_CONFIG_MONITOR, \ + CONFIG_FROM_WEB, \ + FALSE, \ + log_monitor_config_chk, \ + log_monitor_config_proc, \ + log_monitor_config_get, \ + log_monitor_config_getall \ + },\ + {\ + LOG_CONFIG_REMOTE_ADD_HOST, \ + CONFIG_FROM_WEB, \ + FALSE, \ + log_remote_host_config_chk, \ + log_remote_add_host_config_proc, \ + NULL, \ + NULL \ + },\ + {\ + LOG_CONFIG_REMOTE_DEL_HOST, \ + CONFIG_FROM_WEB, \ + FALSE, \ + log_remote_host_config_chk, \ + log_remote_del_host_config_proc, \ + NULL, \ + NULL \ + },\ + {\ + LOG_CONFIG_REMOTE_LEVEL, \ + CONFIG_FROM_WEB, \ + FALSE, \ + log_remote_level_config_chk, \ + log_remote_level_config_proc, \ + log_remote_level_config_get, \ + log_remote_level_config_getall \ + },\ + {\ + LOG_CONFIG_FILE, \ + CONFIG_FROM_WEB, \ + FALSE, \ + log_file_config_chk, \ + log_file_config_proc, \ + log_file_config_get, \ + log_file_config_getall \ + },\ + {\ + LOG_CONFIG_REMOTE_GET_HOST, \ + CONFIG_FROM_WEB, \ + FALSE, \ + log_remote_host_x_config_chk, \ + NULL, \ + log_remote_host_x_config_get, \ + log_remote_host_x_config_getall \ + },\ + {\ + NAT4_CONFIG, \ + CONFIG_FROM_WEB, \ + FALSE, \ + nat_config_chk, \ + nat_config_proc, \ + NULL, \ + nat_config_get_all \ + },\ + {\ + VLAN_CONFIG, \ + CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ + FALSE, \ + vlan_config_chk, \ + vlan_config_proc, \ + vlan_config_get, \ + vlan_config_get_all \ + }\ +} + +typedef ret_code (*cm_config_init)(); + +typedef ret_code (*cm_config_chk)(uint source, uint *config_type, + pointer input, int *input_len, + pointer output, int *output_len); + +typedef ret_code (*cm_config_proc)(uint source, uint config_type, + pointer input, int input_len, + pointer output, int *output_len); + +typedef ret_code (*cm_config_get)(uint source, + pointer input, int input_len, + pointer output, int *output_len); + +typedef ret_code (*cm_config_get_all)(uint source, + pointer output, int *output_len); + +/* 配置注册 */ +struct _config_init { + uint config_mudlue; + cm_config_init init_callback; +}; +typedef struct _config_init config_init_t; + + +/* 配置注册 */ +struct _config_service { + uint64 config_id; /* 配置ID,全局唯一,用于寻找对应的配置业务*/ + uint config_src; /* 配置源检查,全局唯一,用于寻找对应的配置业务,从低位到高位,第一位表示web,后续配置扩展 */ + boolean recovery; /* 配置恢复处理函数,如果为FALSE则不进行配置恢复 */ + cm_config_chk chk_callback; /* 配置校验回调函数 */ + cm_config_proc proc_callback; /* 配置接口 */ + cm_config_get get_callback; /* 获取配置接口 */ + cm_config_get_all getall_callback; /* 获取所有配置接口 */ +}; + +typedef struct _config_service config_service_t; + +struct _config_result { + char resultCode[RET_CODE_LEN]; + char *message; + char *data; +}; + +typedef struct _config_result config_result_t; + +int cm_format_data(ret_code ret_code, cJSON *json_obj, char *output); + +#endif /* RPC_COMMON_H_ */ + diff --git a/Platform/user/configm/config-server/web_config/auth_recover_config.c b/Platform/user/configm/config-server/web_config/auth_recover_config.c new file mode 100644 index 000000000..53f147647 --- /dev/null +++ b/Platform/user/configm/config-server/web_config/auth_recover_config.c @@ -0,0 +1,321 @@ +#include "auth_recover_config.h" +#include +#include "../include/parsefile.h" +#include "../include/configm.h" +#include "rpc.h" +#include "s2j/s2j.h" +#include "commuapinl.h" +#include "../Platform/common/database/database.h" +#include "config_manager.h" +#include "authfree.h" +#include "auth_parameters.h" +#include "include/user_authfree.h" +#include "include/user_authpara.h" +#include "include/auth_common.h" + +void * auth_hdbc = NULL; //认证数据库连接句柄 +extern freeauth_configure_t freeauth_array[]; +extern auth_parameters_t *auth_para; + + +/*数据库重连*/ +void db_connect() +{ + if(NULL == auth_hdbc) + { + auth_hdbc = connect_database(AUTHRECOVER_DATABASE_ID); + } +} + + +/* 查询未认证权限恢复 */ +void auth_getrule_db(char ** rule_db) +{ + int num = 0; + int size = 0; + char *ret_authrule = NULL; + + /*数据库重连*/ + db_connect(); + if(NULL == auth_hdbc) + { + return; + } + + char *select_sql = "SELECT rule_priority, name, sip, dip, dport, flag FROM `authfree`"; + ret_authrule = select_datebase_by_number(AUTHRECOVER_DATABASE_ID, auth_hdbc, "authfree", select_sql, 1, 0, &num, 0); + + if(0 == num || NULL == ret_authrule) + { + return; + } + + size = strlen(ret_authrule)+1; + char * point = (char*)malloc(size); + if(NULL == point) + { + return; + } + memset(point, 0, size); + memcpy(point, ret_authrule, size); + *rule_db = point; //在函数外面释放 + + return; +} + +/* 查询认证参数恢复 */ +void auth_getpara_db(char ** parameters_db) +{ + int num = 0; + int size = 0; + char *ret_parameters = NULL; + + /*数据库重连*/ + db_connect(); + if(NULL == auth_hdbc) + { + return; + } + + char *select_sql = "SELECT port, timehorizon, failcount, dip, locktime, aging_time FROM `authparas`"; + ret_parameters = select_datebase_by_number(AUTHRECOVER_DATABASE_ID, auth_hdbc, "authparas", select_sql, 1, 0, &num, 0); + + if(0 == num || NULL == ret_parameters) + { + return; + } + + size = strlen(ret_parameters)+1; + char * point = (char*)malloc(size); + if(NULL == point) + { + return; + } + memset(point, 0, size); + memcpy(point, ret_parameters, size); + *parameters_db = point; //在函数外面释放 + + return; +} + + +ret_code auth_recover_chk(uint source, uint *config_type, + pointer input, int *input_len, + pointer output, int *output_len) +{ + ret_code ret = RET_OK; + return ret; +} + +ret_code auth_recover_proc(uint source, uint config_type, + pointer input, int input_len, + pointer output, int *output_len) +{ + ret_code ret = RET_OK; + return ret; +} + +ret_code auth_recover_get(uint source, + pointer input, int input_len, + pointer output, int *output_len) +{ + ret_code ret = RET_OK; + return ret; +} + +/*配置恢复未认证权限、认证参数*/ +ret_code auth_recover_get_all(uint source, + pointer output, int *output_len) +{ + ret_code ret = RET_OK; + char *rule_db = NULL; + char *parameters_db = NULL; + + if(CONFIG_FROM_RECOVER1 != source) + { + return ret; + } + + auth_hdbc = connect_database(AUTHRECOVER_DATABASE_ID); + + if(NULL == auth_hdbc) + { + return RET_SYSERR; + } + + /*初始化认证参数结构体指针*/ + authparInit(); + + auth_getrule_db(&rule_db); + if(NULL != rule_db) + { + /*输出参数为json字符串*/ + cJSON * cjson = cJSON_Parse(rule_db); + if(NULL == cjson) + { + free(rule_db); + ret = RET_ERR; + return ret; + } + + cJSON * data = cJSON_GetObjectItem(cjson, "data"); + if(NULL == data) + { + free(rule_db); + cJSON_Delete(cjson); + return RET_ERR; + } + + int mun_rule = cJSON_GetArraySize(data); + if(0 == mun_rule) + { + free(rule_db); + cJSON_Delete(cjson); + return RET_ERR; + } + + /*创建freeauth_configure_t结构体对象 */ + s2j_create_struct_obj(freeauth_buff, freeauth_configure_t); + + if(freeauth_buff == NULL) { + cJSON_Delete(cjson); + return RET_NOMEM; + } + + for (int i = 0; i < mun_rule; i++) + { + cJSON *pArrayItem = cJSON_GetArrayItem(data, i); + + if(pArrayItem) { + /*获取未认证权限优先级键值对*/ + cJSON *rule_priority = cJSON_GetObjectItem(pArrayItem, "rule_priority"); + + if(rule_priority) { + freeauth_buff->rule_priority = rule_priority->valueint; + } + + /*未认证权限名称*/ + cJSON *name = cJSON_GetObjectItem(pArrayItem, "name"); + + if(name) { + strncpy(freeauth_buff->name, name->valuestring, 31); + } + + /*源IP地址*/ + cJSON *sip = cJSON_GetObjectItem(pArrayItem, "sip"); + + if(sip) { + freeauth_buff->sip = sip->valueint; + } + + /*目的IP地址*/ + cJSON *dip = cJSON_GetObjectItem(pArrayItem, "dip"); + + if(dip) { + freeauth_buff->dip = dip->valueint; + } + + /*目的端口号*/ + cJSON *dport = cJSON_GetObjectItem(pArrayItem, "dport"); + + if(dport) { + freeauth_buff->dport = dport->valueint; + } + + /*状态标志位*/ + cJSON *flag = cJSON_GetObjectItem(pArrayItem, "flag"); + + if(flag) { + freeauth_buff->flag = flag->valueint; + } + + printf("freeauth_buff->name = %p %s\n", &freeauth_buff->name, freeauth_buff->name); + + /*把数据库的内容读出来 然后加到全局变量里边去*/ + for(i = 0; i < RULE_MAX_NUM; i++) { + printf("the name is :%s\n", freeauth_array[i].name); + /*两个字符串相等 strcmp值为0*/ + int a = strlen(freeauth_array[i].name); + printf("%d\n", a); + + if(0 == strlen(freeauth_array[i].name)) { + printf("%s(%d) freeauth_array[%d] = %p\n", __FUNCTION__, __LINE__, i, &freeauth_array[i]); + memset(&freeauth_array[i], 0, sizeof(freeauth_configure_t)); + freeauth_array[i].rule_priority = freeauth_buff->rule_priority; + strncpy(freeauth_array[i].name, freeauth_buff->name, 32); + freeauth_array[i].sip = freeauth_buff->sip; + freeauth_array[i].dip = freeauth_buff->dip; + freeauth_array[i].dport = freeauth_buff->dport; + freeauth_array[i].flag = freeauth_buff->flag; + printf("[%d %s %d %d %d %d %d]\n", freeauth_array[i].rule_priority, freeauth_array[i].name, freeauth_array[i].sip, + freeauth_array[i].dip, freeauth_array[i].dport, freeauth_array[i].dport, i); + break; + } + + } + + freeauth_buff++; + } + } + + s2j_delete_struct_obj(freeauth_buff); + free(rule_db); + + return RET_OK; + } + + + auth_getpara_db(¶meters_db); + if(NULL != parameters_db) + { + /*输出参数为json字符串*/ + cJSON * cjson_para = cJSON_Parse(parameters_db); + if(NULL == cjson_para) + { + free(parameters_db); + ret = RET_ERR; + return ret; + } + + cJSON * data_para = cJSON_GetObjectItem(cjson_para, "data"); + if(NULL == data_para) + { + free(parameters_db); + cJSON_Delete(cjson_para); + return RET_ERR; + } + + /*创建freeauth_configure_t结构体对象 */ + s2j_create_struct_obj(auth_parameters, auth_parameters_t); + + if(auth_parameters == NULL) { + cJSON_Delete(cjson_para); + return RET_NOMEM; + } + + /*反序列化数据到freeauth_configure_t结构体对象 */ + s2j_struct_get_basic_element(auth_parameters, data_para, int, port); + s2j_struct_get_basic_element(auth_parameters, data_para, int, timehorizon); + s2j_struct_get_basic_element(auth_parameters, data_para, int, failcount); + s2j_struct_get_basic_element(auth_parameters, data_para, int, locktime); + s2j_struct_get_basic_element(auth_parameters, data_para, int, aging_time); + + /*将数据存入全局结构体指针*/ + if(auth_para) { + auth_para->port = auth_parameters->port; + auth_para->timehorizon = auth_parameters->timehorizon; + auth_para->failcount = auth_parameters->failcount; + auth_para->locktime = auth_parameters->locktime; + auth_para->aging_time = auth_parameters->aging_time; + } + + s2j_delete_struct_obj(auth_parameters); + cJSON_Delete(cjson_para); + } + + return RET_OK; +} + + + + diff --git a/Platform/user/configm/config-server/web_config/auth_recover_config.h b/Platform/user/configm/config-server/web_config/auth_recover_config.h new file mode 100644 index 000000000..abef11537 --- /dev/null +++ b/Platform/user/configm/config-server/web_config/auth_recover_config.h @@ -0,0 +1,41 @@ +#ifndef AUTH_RECOVER_H_ +#define AUTH_RECOVER_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "rpc_common.h" + +/*数据库重连*/ +void db_connect(); + +/* 查询未认证权限恢复 */ +void auth_getrule_db(char ** rule_db); + +/* 查询认证参数恢复 */ +void auth_getpara_db(char ** parameters_db); + +ret_code auth_recover_chk(uint source, uint *config_type, + pointer input, int *input_len, + pointer output, int *output_len); + +ret_code auth_recover_proc(uint source, uint config_type, + pointer input, int input_len, + pointer output, int *output_len); + +ret_code auth_recover_get(uint source, + pointer input, int input_len, + pointer output, int *output_len); + +/*配置恢复未认证权限、认证参数*/ +ret_code auth_recover_get_all(uint source, + pointer output, int *output_len); + + + +#endif \ No newline at end of file diff --git a/Platform/user/configm/config-server/web_config/config-adm/user_authfree.c b/Platform/user/configm/config-server/web_config/config-adm/user_authfree.c index 4ce0b9fed..dbc0e6842 100644 --- a/Platform/user/configm/config-server/web_config/config-adm/user_authfree.c +++ b/Platform/user/configm/config-server/web_config/config-adm/user_authfree.c @@ -3,11 +3,10 @@ #include "../Platform/common/database/database.h" #include "../include/user_authfree.h" #include "string.h" - -#define AUTHFREE_DATABASE_ID (16) -#define AUTHFREE_TABLE "authfree" +#include "../include/auth_common.h" extern freeauth_configure_t freeauth_array[]; +extern void * auth_hdbc; static char *authfreemes[] = {"addrule success", "addrule fail", "rule existed", "modrule success", "modrule failure", "rule not found", "delrule success", "delrule fail", "rulenum exceed maxnum", @@ -37,7 +36,7 @@ static int is_rule_full(void) /*增加未认证权限规则*/ void add_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int dport, int flag, authfree_result_t *authfree_result) { - void *authfree_hdbc; + //void *authfree_hdbc; char *ret_sql = NULL; int ret_add; int ret; @@ -54,10 +53,9 @@ void add_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int authfree_result->message = get_sql_ret_message(authfree_result->resultcode); return; } - - printf("开始连接数据库\n"); /* 连接数据库 */ + #if 0 authfree_hdbc = connect_database(AUTHFREE_DATABASE_ID); if(NULL == authfree_hdbc) { @@ -67,7 +65,10 @@ void add_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int /*长整型bigint 浮点型double 字符串character(10)*/ printf("authfree_hdbc = %p\n", authfree_hdbc); - ret = create_database_table(AUTHFREE_DATABASE_ID, authfree_hdbc, "authfree", "create table authfree(rule_priority bigint, name character(32), sip bigint, dip bigint, dport bigint, flag bigint)"); + #endif + + /*建表*/ + ret = create_database_table(AUTHRECOVER_DATABASE_ID, auth_hdbc, "authfree", "create table authfree(rule_priority bigint, name character(32), sip bigint, dip bigint, dport bigint, flag bigint)"); printf("%d \n", ret); #if 0 @@ -89,7 +90,7 @@ void add_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int /* 根据指定信息查询数据库的获取的结果的条目数 条目数大于10 则不能再添加 */ char *select_num = "SELECT rule_priority, name, sip, dip, dport, flag FROM `authfree`"; - ret = get_select_datebase_number(AUTHFREE_DATABASE_ID, authfree_hdbc, "authfree", select_num, &num_sql, 6, + ret = get_select_datebase_number(AUTHRECOVER_DATABASE_ID, auth_hdbc, "authfree", select_num, &num_sql, 6, DB_DATA_INT_TYPE, sizeof(rule_priority), rule_priority, DB_DATA_STRING_TYPE, strlen(name) + 1, name, DB_DATA_INT_TYPE, sizeof(sip), sip, @@ -109,7 +110,7 @@ void add_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int /* 向authfree表中添加:未认证权限名称、内部源IP地址、目的IP地址、目的端口号 */ char *addfree_sql = "INSERT INTO `authfree` SET rule_priority = ?, name = ?, sip = ?, dip = ?, dport = ?, flag = ?"; - ret_add = update_database(AUTHFREE_DATABASE_ID, authfree_hdbc, DB_OP_INSERT, AUTHFREE_TABLE, addfree_sql, 6, + ret_add = update_database(AUTHRECOVER_DATABASE_ID, auth_hdbc, DB_OP_INSERT, AUTHFREE_TABLE, addfree_sql, 6, DB_DATA_INT_TYPE, sizeof(rule_priority), rule_priority, DB_DATA_STRING_TYPE, strlen(name) + 1, name, DB_DATA_INT_TYPE, sizeof(sip), sip, @@ -167,7 +168,7 @@ void add_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int /*修改未认证权限*/ void mod_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int dport, int flag, authfree_result_t *authfree_result) { - void *authfree_hdbc; + //void *authfree_hdbc; char *ret_sql = NULL; int ret_mod; int ret; @@ -179,9 +180,10 @@ void mod_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int } printf("开始连接数据库\n"); - + + #if 0 /* 连接数据库 */ - authfree_hdbc = connect_database(AUTHFREE_DATABASE_ID); + authfree_hdbc = connect_database(AUTHRECOVER_DATABASE_ID); if(NULL == authfree_hdbc) { printf("connetc failure\n"); @@ -190,7 +192,10 @@ void mod_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int /*长整型bigint 浮点型double 字符串character(10)*/ printf("authfree_hdbc = %p\n", authfree_hdbc); - ret = create_database_table(AUTHFREE_DATABASE_ID, authfree_hdbc, "authfree", "create table authfree(name character(32), sip bigint, dip bigint, dport bigint)"); + #endif + + /*建表*/ + ret = create_database_table(AUTHRECOVER_DATABASE_ID, auth_hdbc, "authfree", "create table authfree(name character(32), sip bigint, dip bigint, dport bigint)"); printf("%d \n", ret); #if 0 @@ -211,7 +216,7 @@ void mod_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int /*修改authfree表中内部源IP地址、目的IP地址、目的端口号 未认证权限名称不能修改 */ char *modfree_sql = "UPDATE `authfree` SET rule_priority = ?, sip = ?, dip = ?, dport = ? ,flag = ? WHERE name = ?"; - ret_mod = update_database(AUTHFREE_DATABASE_ID, authfree_hdbc, DB_OP_UPDATE, AUTHFREE_TABLE, modfree_sql, 6, + ret_mod = update_database(AUTHRECOVER_DATABASE_ID, auth_hdbc, DB_OP_UPDATE, AUTHFREE_TABLE, modfree_sql, 6, DB_DATA_INT_TYPE, sizeof(rule_priority), rule_priority, DB_DATA_INT_TYPE, sizeof(sip), sip, DB_DATA_INT_TYPE, sizeof(dip), dip, @@ -262,7 +267,7 @@ void mod_authfree(int rule_priority, char *name, uint32_t sip, uint32_t dip, int /*删除未认证权限*/ void del_authfree(char *name, authfree_result_t *authfree_result) { - void *authfree_hdbc; + //void *authfree_hdbc; char *ret_sql = NULL; int ret_del; int ret; @@ -272,9 +277,8 @@ void del_authfree(char *name, authfree_result_t *authfree_result) if(NULL == authfree_result) { return; } - - printf("开始连接数据库\n"); - + + #if 0 /* 连接数据库 */ authfree_hdbc = connect_database(AUTHFREE_DATABASE_ID); @@ -285,7 +289,10 @@ void del_authfree(char *name, authfree_result_t *authfree_result) /*长整型bigint 浮点型double 字符串character(10)*/ printf("authfree_hdbc = %p\n", authfree_hdbc); - ret = create_database_table(AUTHFREE_DATABASE_ID, authfree_hdbc, "authfree", "create table authfree(name character(32), sip bigint, dip bigint, dport bigint)"); + #endif + + /*建表*/ + ret = create_database_table(AUTHRECOVER_DATABASE_ID, auth_hdbc, "authfree", "create table authfree(name character(32), sip bigint, dip bigint, dport bigint)"); printf("%d \n", ret); @@ -308,7 +315,7 @@ void del_authfree(char *name, authfree_result_t *authfree_result) /*删除authfree表中未认证权限名称、内部源IP地址、目的IP地址、目的端口号 */ char *delfree_sql = "DELETE FROM authfree WHERE name = ?"; - ret_del = update_database(AUTHFREE_DATABASE_ID, authfree_hdbc, DB_OP_DEL, AUTHFREE_TABLE, delfree_sql, 1, + ret_del = update_database(AUTHRECOVER_DATABASE_ID, auth_hdbc, DB_OP_DEL, AUTHFREE_TABLE, delfree_sql, 1, DB_DATA_STRING_TYPE, strlen(name) + 1, name); printf("the value of ret:%d\n", ret_del); diff --git a/Platform/user/configm/config-server/web_config/config-adm/user_authpara.c b/Platform/user/configm/config-server/web_config/config-adm/user_authpara.c index be2138df9..86e0ebb2b 100644 --- a/Platform/user/configm/config-server/web_config/config-adm/user_authpara.c +++ b/Platform/user/configm/config-server/web_config/config-adm/user_authpara.c @@ -8,11 +8,11 @@ #include "../../../../../Common/commuapinl.h" #include "../auth_parameters.h" #include "../Platform/common/database/database.h" - -#define AUTHPARA_DATABASE_ID 15 -#define AUTHPARA_TABLE "authparas" +#include "../include/user_authpara.h" +#include "../include/auth_common.h" extern auth_parameters_t *auth_para; +extern void * auth_hdbc; char * mes[]={"mod success", "mod failure"}; @@ -20,7 +20,7 @@ char * mes[]={"mod success", "mod failure"}; void mod_authpara(int port, int timehorizon, int failcount, int locktime, int aging_time, configure_result_t *configure_result) { authparInit(); - void * authpara_hdbc; + //void * authpara_hdbc; char * ret_sql = NULL; int ret; int num; @@ -31,6 +31,7 @@ void mod_authpara(int port, int timehorizon, int failcount, int locktime, int ag return; } + #if 0 printf("开始连接数据库\n"); /* 连接数据库 */ @@ -43,15 +44,18 @@ void mod_authpara(int port, int timehorizon, int failcount, int locktime, int ag /*长整型bigint 浮点型double 字符串character(10)*/ printf("authpara_hdbc = %p\n", authpara_hdbc); - ret = create_database_table(AUTHPARA_DATABASE_ID, authpara_hdbc, "authparas", "create table authparas(port bigint, timehorizon bigint, failcount bigint, locktime bigint, aging_time bigint)"); + #endif + + /*建表*/ + ret = create_database_table(AUTHRECOVER_DATABASE_ID, auth_hdbc, "authparas", "create table authparas(port bigint, timehorizon bigint, failcount bigint, locktime bigint, aging_time bigint)"); printf("%d \n",ret); /* 存authpara表 默认值 */ char *user1_authpara = "INSERT INTO `authparas` SET port = 8080, timehorizon = 1, failcount = 5, locktime = 10, aging_time = 10"; - int ret_addauthpara = update_database(AUTHPARA_DATABASE_ID, authpara_hdbc, DB_OP_INSERT, AUTHPARA_TABLE, user1_authpara, 0); + int ret_addauthpara = update_database(AUTHRECOVER_DATABASE_ID, auth_hdbc, DB_OP_INSERT, AUTHPARA_TABLE, user1_authpara, 0); if(0 != ret_addauthpara) { - disconnect_database(AUTHPARA_DATABASE_ID , authpara_hdbc); // ret_release记录日志 + disconnect_database(AUTHRECOVER_DATABASE_ID , auth_hdbc); // ret_release记录日志 configure_result->resultcode = 1; configure_result->message = mes[configure_result->resultcode]; return; @@ -59,7 +63,7 @@ void mod_authpara(int port, int timehorizon, int failcount, int locktime, int ag char *user_authpara = "UPDATE `authparas` SET port = ?, timehorizon = ?, failcount = ?, locktime = ?, aging_time = ?"; - ret = update_database(AUTHPARA_DATABASE_ID, authpara_hdbc, DB_OP_UPDATE, AUTHPARA_TABLE, user_authpara, 5, + ret = update_database(AUTHRECOVER_DATABASE_ID, auth_hdbc, DB_OP_UPDATE, AUTHPARA_TABLE, user_authpara, 5, DB_DATA_INT_TYPE, sizeof(port), port, DB_DATA_INT_TYPE, sizeof(timehorizon), timehorizon, DB_DATA_INT_TYPE, sizeof(failcount), failcount, diff --git a/Platform/user/configm/config-server/web_config/include/auth_common.h b/Platform/user/configm/config-server/web_config/include/auth_common.h new file mode 100644 index 000000000..2587b3656 --- /dev/null +++ b/Platform/user/configm/config-server/web_config/include/auth_common.h @@ -0,0 +1,9 @@ +#ifndef AUTH_COMMON_H_ +#define AUTH_COMMON_H_ + +#define AUTHPARA_TABLE "authparas" +#define AUTHFREE_TABLE "authfree" + +#define AUTHRECOVER_DATABASE_ID (15) + +#endif \ No newline at end of file diff --git a/Platform/user/configm/config-server/web_config/include/user_authfree.h b/Platform/user/configm/config-server/web_config/include/user_authfree.h index 4c3496268..a62356a9e 100644 --- a/Platform/user/configm/config-server/web_config/include/user_authfree.h +++ b/Platform/user/configm/config-server/web_config/include/user_authfree.h @@ -11,7 +11,6 @@ #define DELAUTHFREE_FAIL_DATABASE (7) //删除未认证权限失败 #define RULENUM_EXCEED (8) //未认证权限数量超过最大值 - typedef enum { ADD_RULE_OK = 0, ADD_RULE_ERR = 1, diff --git a/Platform/user/configm/config-server/web_config/include/user_authpara.h b/Platform/user/configm/config-server/web_config/include/user_authpara.h index c5df56948..4fc142033 100644 --- a/Platform/user/configm/config-server/web_config/include/user_authpara.h +++ b/Platform/user/configm/config-server/web_config/include/user_authpara.h @@ -4,7 +4,6 @@ #include #include "../Platform/user/configm/config-server/web_config/auth_parameters.h" - #define ADDUSER_FAIL_NAMEDUP 4 //用户名重名 #define MODAUTHPARA_SUCCESS 0 //修改认证信息成功