parent
9f183b4708
commit
9c8f3e51b0
|
@ -29,8 +29,8 @@ auth_parameters_t *auth_para;
|
||||||
int authparInit()
|
int authparInit()
|
||||||
{
|
{
|
||||||
auth_para = (auth_parameters_t *)malloc(sizeof(auth_parameters_t));
|
auth_para = (auth_parameters_t *)malloc(sizeof(auth_parameters_t));
|
||||||
if (NULL == auth_para)
|
|
||||||
{
|
if(NULL == auth_para) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,12 +59,10 @@ int set_agingtimecfg_waitack(int *agingtime)
|
||||||
};
|
};
|
||||||
|
|
||||||
/*判断要发送的数据是否为NULL,不为NULL,打印出来 */
|
/*判断要发送的数据是否为NULL,不为NULL,打印出来 */
|
||||||
if (agingtime == NULL)
|
if(agingtime == NULL) {
|
||||||
{
|
|
||||||
printf("set_agingtimecfg_waitack is error: input struct_agingtime is NULL.\r\n");
|
printf("set_agingtimecfg_waitack is error: input struct_agingtime is NULL.\r\n");
|
||||||
return -1;
|
return -1;
|
||||||
}else
|
} else {
|
||||||
{
|
|
||||||
printf("set_freeauthcfg_waitack :agingtime %d\n", *agingtime);
|
printf("set_freeauthcfg_waitack :agingtime %d\n", *agingtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,36 +74,34 @@ if (agingtime == NULL)
|
||||||
commnl_addattr_l(&req.n, sizeof(req), 1, agingtime, agingtime_len);
|
commnl_addattr_l(&req.n, sizeof(req), 1, agingtime, agingtime_len);
|
||||||
|
|
||||||
/*发送组装好的netlink消息 */
|
/*发送组装好的netlink消息 */
|
||||||
if(pdeliv_talk(1, &req.n, answer) < 0)
|
if(pdeliv_talk(1, &req.n, answer) < 0) {
|
||||||
{
|
|
||||||
printf("set_user_agingtime_waitack rcv ack msg faild.\r\n");
|
printf("set_user_agingtime_waitack rcv ack msg faild.\r\n");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("set_user_agingtime_waitack rcv ack msg success.\r\n");
|
printf("set_user_agingtime_waitack rcv ack msg success.\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(*answer != NULL)
|
if(*answer != NULL) {
|
||||||
{
|
|
||||||
printf("set_user_agingtime_waitack rcv answer.\r\n");
|
printf("set_user_agingtime_waitack rcv answer.\r\n");
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
printf("set_user_agingtime_waitack rcv answer error.\r\n");
|
printf("set_user_agingtime_waitack rcv answer error.\r\n");
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CFG_AGINGTIME_ACK_COOKIES
|
#ifdef CFG_AGINGTIME_ACK_COOKIES
|
||||||
|
|
||||||
/*recv answer*/
|
/*recv answer*/
|
||||||
if((*answer)->nlmsg_type == NLMSG_ERROR) {
|
if((*answer)->nlmsg_type == NLMSG_ERROR) {
|
||||||
nl_debugfs_extack(*answer);
|
nl_debugfs_extack(*answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/*recv answer*/
|
/*recv answer*/
|
||||||
if((*answer)->nlmsg_type == AGINGTIME_CFG)
|
if((*answer)->nlmsg_type == AGINGTIME_CFG) {
|
||||||
{
|
|
||||||
nl_debugfs(*answer);
|
nl_debugfs(*answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -121,8 +117,7 @@ int _valid_port(int port)
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,8 +127,7 @@ int _valid_port(int 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);
|
||||||
|
|
||||||
if( i < 0)
|
if(i < 0) {
|
||||||
{
|
|
||||||
printf("port %d has been used. \n", port);
|
printf("port %d has been used. \n", port);
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -154,8 +148,8 @@ ret_code authpara_config_json_parse(pointer input, uint *conf_type, auth_paramet
|
||||||
printf("json:[%s]\n", pString);
|
printf("json:[%s]\n", pString);
|
||||||
/*JSON字符串到JSON格式 */
|
/*JSON字符串到JSON格式 */
|
||||||
cjson = cJSON_Parse(pString);
|
cjson = cJSON_Parse(pString);
|
||||||
if(!cjson)
|
|
||||||
{
|
if(!cjson) {
|
||||||
ret = RET_INPUTERR;
|
ret = RET_INPUTERR;
|
||||||
ASSERT_RET(ret);
|
ASSERT_RET(ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -163,8 +157,8 @@ ret_code authpara_config_json_parse(pointer input, uint *conf_type, auth_paramet
|
||||||
|
|
||||||
/*获取操作类型 add、mod、del */
|
/*获取操作类型 add、mod、del */
|
||||||
type = cJSON_GetObjectItem(cjson, "type");
|
type = cJSON_GetObjectItem(cjson, "type");
|
||||||
if(!type)
|
|
||||||
{
|
if(!type) {
|
||||||
ret = RET_INPUTERR;
|
ret = RET_INPUTERR;
|
||||||
cJSON_Delete(cjson);
|
cJSON_Delete(cjson);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -174,8 +168,8 @@ ret_code authpara_config_json_parse(pointer input, uint *conf_type, auth_paramet
|
||||||
|
|
||||||
/*获取免认证规则的data部分 */
|
/*获取免认证规则的data部分 */
|
||||||
data = cJSON_GetObjectItem(cjson, "data");
|
data = cJSON_GetObjectItem(cjson, "data");
|
||||||
if(!data)
|
|
||||||
{
|
if(!data) {
|
||||||
ret = RET_INPUTERR;
|
ret = RET_INPUTERR;
|
||||||
cJSON_Delete(cjson);
|
cJSON_Delete(cjson);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -183,8 +177,8 @@ ret_code authpara_config_json_parse(pointer input, uint *conf_type, auth_paramet
|
||||||
|
|
||||||
/*创建freeauth_configure_t结构体对象 */
|
/*创建freeauth_configure_t结构体对象 */
|
||||||
s2j_create_struct_obj(auth_parameters, auth_parameters_t);
|
s2j_create_struct_obj(auth_parameters, auth_parameters_t);
|
||||||
if(auth_parameters == NULL)
|
|
||||||
{
|
if(auth_parameters == NULL) {
|
||||||
cJSON_Delete(cjson);
|
cJSON_Delete(cjson);
|
||||||
return RET_NOMEM;
|
return RET_NOMEM;
|
||||||
}
|
}
|
||||||
|
@ -214,15 +208,15 @@ void local_portal_port(char *port)
|
||||||
{
|
{
|
||||||
printf("port of local portal server:%s\n", port);
|
printf("port of local portal server:%s\n", port);
|
||||||
bool ret = redisPubInit();
|
bool ret = redisPubInit();
|
||||||
if (!ret)
|
|
||||||
{
|
if(!ret) {
|
||||||
printf("Init failed.\n");
|
printf("Init failed.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = redisPubConnect();
|
ret = redisPubConnect();
|
||||||
if (!ret)
|
|
||||||
{
|
if(!ret) {
|
||||||
printf("connect failed.");
|
printf("connect failed.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -262,24 +256,23 @@ ret_code authpara_config_proc(uint source, uint config_type,
|
||||||
|
|
||||||
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)) || (input_len > sizeof(auth_parameters_t))) {
|
||||||
{
|
|
||||||
ret = RET_INPUTERR;
|
ret = RET_INPUTERR;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
portresult = _valid_port(auth_parameters.port);
|
portresult = _valid_port(auth_parameters.port);
|
||||||
printf("portresult:%d\n", portresult);
|
printf("portresult:%d\n", portresult);
|
||||||
if(portresult == 1)
|
|
||||||
{
|
if(portresult == 1) {
|
||||||
return RET_CHKERR;
|
return RET_CHKERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*数据库修改 存入全局变量*/
|
/*数据库修改 存入全局变量*/
|
||||||
configure_result = (configure_result_t *)malloc(sizeof(configure_result_t));
|
configure_result = (configure_result_t *)malloc(sizeof(configure_result_t));
|
||||||
if (NULL == configure_result)
|
|
||||||
{
|
if(NULL == configure_result) {
|
||||||
return RET_NOMEM;
|
return RET_NOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,24 +282,24 @@ ret_code authpara_config_proc(uint source, uint config_type,
|
||||||
/*共享内存 传送用户态和内核态之间的配置信息*/
|
/*共享内存 传送用户态和内核态之间的配置信息*/
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
||||||
/*存数据库成功,则下发到内核态auth_hook*/
|
/*存数据库成功,则下发到内核态auth_hook*/
|
||||||
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");
|
||||||
|
|
||||||
/*创建通道 */
|
/*创建通道 */
|
||||||
r = commcfgnl_open();
|
r = commcfgnl_open();
|
||||||
if(r < 0)
|
|
||||||
{
|
if(r < 0) {
|
||||||
printf(" pdlivnl_open fail, exit.\r\n");
|
printf(" pdlivnl_open fail, exit.\r\n");
|
||||||
return RET_ERR;
|
return RET_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*下发配置到内核态 */
|
/*下发配置到内核态 */
|
||||||
r = set_agingtimecfg_waitack(&(auth_parameters.aging_time));
|
r = set_agingtimecfg_waitack(&(auth_parameters.aging_time));
|
||||||
if(r < 0)
|
|
||||||
{
|
if(r < 0) {
|
||||||
printf("set_cfg_debug_waitack failed.\r\n");
|
printf("set_cfg_debug_waitack failed.\r\n");
|
||||||
return RET_ERR;
|
return RET_ERR;
|
||||||
}
|
}
|
||||||
|
@ -315,6 +308,7 @@ ret_code authpara_config_proc(uint source, uint config_type,
|
||||||
commcfgnl_close();
|
commcfgnl_close();
|
||||||
printf("cfgchannel main exit!\r\n");
|
printf("cfgchannel main exit!\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*Portal server的port通过redis消息队列接口发布给web server*/
|
/*Portal server的port通过redis消息队列接口发布给web server*/
|
||||||
|
@ -325,8 +319,8 @@ ret_code authpara_config_proc(uint source, uint config_type,
|
||||||
|
|
||||||
/*创建json对象 */
|
/*创建json对象 */
|
||||||
res = cJSON_CreateObject();
|
res = cJSON_CreateObject();
|
||||||
if(!res)
|
|
||||||
{
|
if(!res) {
|
||||||
ret = RET_ERR;
|
ret = RET_ERR;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -336,14 +330,13 @@ ret_code authpara_config_proc(uint source, uint config_type,
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*超出2k的内存,报错 */
|
/*超出2k的内存,报错 */
|
||||||
if(ret_int >= 1024 * 2)
|
if(ret_int >= 1024 * 2) {
|
||||||
{
|
|
||||||
free(ret_char);
|
free(ret_char);
|
||||||
cJSON_Delete(res);
|
cJSON_Delete(res);
|
||||||
return RET_NOMEM;
|
return RET_NOMEM;
|
||||||
|
|
Loading…
Reference in New Issue