Mod aaa-12 修改auth_parameters.c文件代码review的问题
RCA: SOL: 修改人:chenling 检视人:
This commit is contained in:
parent
6def2e16c2
commit
f2f1fc5ede
|
@ -40,8 +40,8 @@ int authparInit()
|
||||||
/*下发用户老化时间配置到内核态 */
|
/*下发用户老化时间配置到内核态 */
|
||||||
int set_agingtimecfg_waitack(int *agingtime)
|
int set_agingtimecfg_waitack(int *agingtime)
|
||||||
{
|
{
|
||||||
int agingtime_len = 0;
|
int agingtime_len = 0;
|
||||||
struct nlmsghdr *ack = NULL;
|
struct nlmsghdr *ack = NULL;
|
||||||
struct nlmsghdr **answer = &ack;
|
struct nlmsghdr **answer = &ack;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
@ -50,12 +50,12 @@ int set_agingtimecfg_waitack(int *agingtime)
|
||||||
} req = {
|
} req = {
|
||||||
.n.nlmsg_len = NLMSG_LENGTH(0),
|
.n.nlmsg_len = NLMSG_LENGTH(0),
|
||||||
#ifdef CFG_AGINGTIME_ACK_COOKIES
|
#ifdef CFG_AGINGTIME_ACK_COOKIES
|
||||||
.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,/*set NLM_F_ACK:use kernel auto ack*/
|
.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK, /*set NLM_F_ACK:use kernel auto ack*/
|
||||||
#else
|
#else
|
||||||
.n.nlmsg_flags = NLM_F_REQUEST, /*not use kernel auto ack */
|
.n.nlmsg_flags = NLM_F_REQUEST, /*not use kernel auto ack */
|
||||||
#endif
|
#endif
|
||||||
.n.nlmsg_type = AGINGTIME_CFG, /*用户态发送给内核态的用户老化时间消息 */
|
.n.nlmsg_type = AGINGTIME_CFG, /*用户态发送给内核态的用户老化时间消息 */
|
||||||
.n.nlmsg_pid = getpid(),
|
.n.nlmsg_pid = getpid(),
|
||||||
};
|
};
|
||||||
|
|
||||||
/*判断要发送的数据是否为NULL,不为NULL,打印出来 */
|
/*判断要发送的数据是否为NULL,不为NULL,打印出来 */
|
||||||
|
@ -110,39 +110,34 @@ int set_agingtimecfg_waitack(int *agingtime)
|
||||||
/*检查IP地址是否有效,端口号是否被占用 */
|
/*检查IP地址是否有效,端口号是否被占用 */
|
||||||
int _valid_port(int port)
|
int _valid_port(int port)
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
int fd;
|
int fd;
|
||||||
int i;
|
int i;
|
||||||
volatile int local_errno;
|
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
fd = socket(AF_INET, SOCK_STREAM, 0); /*初始化*/
|
fd = socket(AF_INET, SOCK_STREAM, 0); /*初始化*/
|
||||||
|
|
||||||
if(fd == -1) { /*检查是否正常初始化socket */
|
if(fd == -1) { /*检查是否正常初始化socket */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr.sin_family = AF_INET; /*地址结构的协议簇 */
|
addr.sin_family = AF_INET; /*地址结构的协议簇 */
|
||||||
addr.sin_port = htons(port); /*地址结构的端口地址,网络字节序 */
|
addr.sin_port = htons(port); /*地址结构的端口地址,网络字节序 */
|
||||||
|
|
||||||
i = (bind(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr)));
|
i = (bind(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr)));
|
||||||
printf("the value of i:%d\n", i);
|
printf("the value of i:%d\n", i);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
if(i < 0) {
|
if(i < 0) {
|
||||||
printf("port %d has been used. \n", port);
|
printf("port %d has been used. \n", port);
|
||||||
close(fd);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* iuput格式:{"type": 0, "data": {"port": 1010,"timehorizon": 10,"failcount": 20,"locktime":30, "aging_time":10}}*/
|
/* iuput格式:{"type": 0, "data": {"port": 1010,"timehorizon": 10,"failcount": 20,"locktime":30, "aging_time":10}}*/
|
||||||
ret_code authpara_config_json_parse(pointer input, uint *conf_type, auth_parameters_t *authpara_buff)
|
ret_code authpara_config_json_parse(pointer input, uint *conf_type, auth_parameters_t *authpara_buff)
|
||||||
{
|
{
|
||||||
char *pString = (char *)input;
|
char *pString = (char *)input;
|
||||||
ret_code ret = RET_OK;
|
|
||||||
cJSON *cjson, *type, *data;
|
cJSON *cjson, *type, *data;
|
||||||
|
|
||||||
printf("json:[%s]\n", pString);
|
printf("json:[%s]\n", pString);
|
||||||
|
@ -150,29 +145,27 @@ ret_code authpara_config_json_parse(pointer input, uint *conf_type, auth_paramet
|
||||||
cjson = cJSON_Parse(pString);
|
cjson = cJSON_Parse(pString);
|
||||||
|
|
||||||
if(!cjson) {
|
if(!cjson) {
|
||||||
ret = RET_INPUTERR;
|
return RET_INPUTERR;
|
||||||
ASSERT_RET(ret);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*获取操作类型 add、mod、del */
|
/*获取操作类型 add、mod、del */
|
||||||
type = cJSON_GetObjectItem(cjson, "type");
|
type = cJSON_GetObjectItem(cjson, "type");
|
||||||
|
|
||||||
if(!type) {
|
if(!type) {
|
||||||
ret = RET_INPUTERR;
|
|
||||||
cJSON_Delete(cjson);
|
cJSON_Delete(cjson);
|
||||||
return ret;
|
return RET_INPUTERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
*conf_type = type->valueint;
|
if(conf_type) {
|
||||||
|
*conf_type = type->valueint;
|
||||||
|
}
|
||||||
|
|
||||||
/*获取免认证规则的data部分 */
|
/*获取免认证规则的data部分 */
|
||||||
data = cJSON_GetObjectItem(cjson, "data");
|
data = cJSON_GetObjectItem(cjson, "data");
|
||||||
|
|
||||||
if(!data) {
|
if(!data) {
|
||||||
ret = RET_INPUTERR;
|
|
||||||
cJSON_Delete(cjson);
|
cJSON_Delete(cjson);
|
||||||
return ret;
|
return RET_INPUTERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*创建freeauth_configure_t结构体对象 */
|
/*创建freeauth_configure_t结构体对象 */
|
||||||
|
@ -190,19 +183,20 @@ ret_code authpara_config_json_parse(pointer input, uint *conf_type, auth_paramet
|
||||||
s2j_struct_get_basic_element(auth_parameters, data, int, locktime);
|
s2j_struct_get_basic_element(auth_parameters, data, int, locktime);
|
||||||
s2j_struct_get_basic_element(auth_parameters, data, int, aging_time);
|
s2j_struct_get_basic_element(auth_parameters, data, int, aging_time);
|
||||||
|
|
||||||
authpara_buff->port = auth_parameters->port;
|
if(authpara_buff) {
|
||||||
authpara_buff->timehorizon = auth_parameters->timehorizon;
|
authpara_buff->port = auth_parameters->port;
|
||||||
authpara_buff->failcount = auth_parameters->failcount;
|
authpara_buff->timehorizon = auth_parameters->timehorizon;
|
||||||
authpara_buff->locktime = auth_parameters->locktime;
|
authpara_buff->failcount = auth_parameters->failcount;
|
||||||
authpara_buff->aging_time = auth_parameters->aging_time;
|
authpara_buff->locktime = auth_parameters->locktime;
|
||||||
|
authpara_buff->aging_time = auth_parameters->aging_time;
|
||||||
|
}
|
||||||
|
|
||||||
//s2j_delete_struct_obj(auth_parameters);
|
s2j_delete_struct_obj(auth_parameters);
|
||||||
cJSON_Delete(cjson);
|
cJSON_Delete(cjson);
|
||||||
|
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* 发布配置的本地Portal server 的port*/
|
/* 发布配置的本地Portal server 的port*/
|
||||||
void local_portal_port(char *port)
|
void local_portal_port(char *port)
|
||||||
{
|
{
|
||||||
|
@ -242,23 +236,20 @@ ret_code authpara_config_proc(uint source, uint config_type,
|
||||||
pointer input, int input_len,
|
pointer input, int input_len,
|
||||||
pointer output, int *output_len)
|
pointer output, int *output_len)
|
||||||
{
|
{
|
||||||
ret_code ret = RET_OK;
|
|
||||||
auth_parameters_t auth_parameters = {0};
|
|
||||||
int config_len = sizeof(auth_parameters_t);
|
|
||||||
uint conf_type = AUTHPARA_CONFIG_MOD;
|
|
||||||
int code = 0;
|
|
||||||
cJSON *res;
|
|
||||||
char *ret_char = NULL;
|
|
||||||
unsigned int ret_int = 0;
|
|
||||||
configure_result_t *configure_result;
|
configure_result_t *configure_result;
|
||||||
int r = -1;
|
cJSON *res;
|
||||||
int portresult = 0;
|
char auth_port[20];
|
||||||
|
ret_code ret = RET_OK;
|
||||||
|
auth_parameters_t auth_parameters = {0};
|
||||||
|
uint conf_type = AUTHPARA_CONFIG_MOD;
|
||||||
|
char *ret_char = NULL;
|
||||||
|
unsigned int ret_int = 0;
|
||||||
|
int portresult = 0;
|
||||||
|
|
||||||
authpara_config_json_parse(input, &conf_type, &auth_parameters);
|
authpara_config_json_parse(input, &conf_type, &auth_parameters);
|
||||||
|
|
||||||
if((input_len < sizeof(auth_parameters_t)) || (input_len > sizeof(auth_parameters_t))) {
|
if(input_len != sizeof(auth_parameters_t)) {
|
||||||
ret = RET_INPUTERR;
|
return RET_INPUTERR;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
portresult = _valid_port(auth_parameters.port);
|
portresult = _valid_port(auth_parameters.port);
|
||||||
|
@ -284,6 +275,7 @@ ret_code authpara_config_proc(uint source, uint config_type,
|
||||||
#if 0
|
#if 0
|
||||||
|
|
||||||
/*存数据库成功,则下发到内核态auth_hook*/
|
/*存数据库成功,则下发到内核态auth_hook*/
|
||||||
|
int r = -1;
|
||||||
if(0 == configure_result->resultcode) {
|
if(0 == configure_result->resultcode) {
|
||||||
/*用户态下发到内核态auth_hook */
|
/*用户态下发到内核态auth_hook */
|
||||||
printf("cfgchannel main begin:\r\n");
|
printf("cfgchannel main begin:\r\n");
|
||||||
|
@ -312,7 +304,7 @@ ret_code authpara_config_proc(uint source, uint config_type,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*Portal server的port通过redis消息队列接口发布给web server*/
|
/*Portal server的port通过redis消息队列接口发布给web server*/
|
||||||
char auth_port[20];
|
memset(auth_port, 0, 20);
|
||||||
sprintf(auth_port, "%d ", auth_parameters.port);
|
sprintf(auth_port, "%d ", auth_parameters.port);
|
||||||
printf("The number 'port' is %d and the string 'port' is %s. \n", auth_parameters.port, auth_port);
|
printf("The number 'port' is %d and the string 'port' is %s. \n", auth_parameters.port, auth_port);
|
||||||
local_portal_port(auth_port);
|
local_portal_port(auth_port);
|
||||||
|
@ -321,6 +313,7 @@ ret_code authpara_config_proc(uint source, uint config_type,
|
||||||
res = cJSON_CreateObject();
|
res = cJSON_CreateObject();
|
||||||
|
|
||||||
if(!res) {
|
if(!res) {
|
||||||
|
free(configure_result);
|
||||||
ret = RET_ERR;
|
ret = RET_ERR;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -329,7 +322,7 @@ ret_code authpara_config_proc(uint source, uint config_type,
|
||||||
cJSON_AddNumberToObject(res, "resultcode", configure_result->resultcode);
|
cJSON_AddNumberToObject(res, "resultcode", configure_result->resultcode);
|
||||||
cJSON_AddStringToObject(res, "message", configure_result->message);
|
cJSON_AddStringToObject(res, "message", configure_result->message);
|
||||||
ret_char = cJSON_PrintUnformatted(res);
|
ret_char = cJSON_PrintUnformatted(res);
|
||||||
ret_int = strlen(ret_char);
|
ret_int = strlen(ret_char);
|
||||||
|
|
||||||
if(output_len) {
|
if(output_len) {
|
||||||
*output_len = ret_int;
|
*output_len = ret_int;
|
||||||
|
@ -337,6 +330,7 @@ ret_code authpara_config_proc(uint source, uint config_type,
|
||||||
|
|
||||||
/*超出2k的内存,报错 */
|
/*超出2k的内存,报错 */
|
||||||
if(ret_int >= 1024 * 2) {
|
if(ret_int >= 1024 * 2) {
|
||||||
|
free(configure_result);
|
||||||
free(ret_char);
|
free(ret_char);
|
||||||
cJSON_Delete(res);
|
cJSON_Delete(res);
|
||||||
return RET_NOMEM;
|
return RET_NOMEM;
|
||||||
|
@ -346,5 +340,7 @@ ret_code authpara_config_proc(uint source, uint config_type,
|
||||||
|
|
||||||
free(ret_char);
|
free(ret_char);
|
||||||
cJSON_Delete(res);
|
cJSON_Delete(res);
|
||||||
|
free(configure_result);
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue