|
|
@ -166,7 +166,7 @@ struct dynsec__group *dynsec_groups__find(const char *groupname)
|
|
|
|
|
|
|
|
|
|
|
|
int dynsec_groups__process_add_role(cJSON *j_responses, struct mosquitto *context, cJSON *command, char *correlation_data)
|
|
|
|
int dynsec_groups__process_add_role(cJSON *j_responses, struct mosquitto *context, cJSON *command, char *correlation_data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char *groupname, *role_name;
|
|
|
|
char *groupname, *rolename;
|
|
|
|
struct dynsec__group *group;
|
|
|
|
struct dynsec__group *group;
|
|
|
|
struct dynsec__role *role;
|
|
|
|
struct dynsec__role *role;
|
|
|
|
int priority;
|
|
|
|
int priority;
|
|
|
@ -175,11 +175,19 @@ int dynsec_groups__process_add_role(cJSON *j_responses, struct mosquitto *contex
|
|
|
|
dynsec__command_reply(j_responses, context, "addGroupRole", "Invalid/missing groupname", correlation_data);
|
|
|
|
dynsec__command_reply(j_responses, context, "addGroupRole", "Invalid/missing groupname", correlation_data);
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mosquitto_validate_utf8(groupname, (int)strlen(groupname)) != MOSQ_ERR_SUCCESS){
|
|
|
|
|
|
|
|
dynsec__command_reply(j_responses, context, "addGroupRole", "Group name not valid UTF-8", correlation_data);
|
|
|
|
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(json_get_string(command, "roleName", &role_name, false) != MOSQ_ERR_SUCCESS){
|
|
|
|
if(json_get_string(command, "roleName", &rolename, false) != MOSQ_ERR_SUCCESS){
|
|
|
|
dynsec__command_reply(j_responses, context, "addGroupRole", "Invalid/missing roleName", correlation_data);
|
|
|
|
dynsec__command_reply(j_responses, context, "addGroupRole", "Invalid/missing roleName", correlation_data);
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mosquitto_validate_utf8(rolename, (int)strlen(rolename)) != MOSQ_ERR_SUCCESS){
|
|
|
|
|
|
|
|
dynsec__command_reply(j_responses, context, "addGroupRole", "Role name not valid UTF-8", correlation_data);
|
|
|
|
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
json_get_int(command, "priority", &priority, true, -1);
|
|
|
|
json_get_int(command, "priority", &priority, true, -1);
|
|
|
|
|
|
|
|
|
|
|
|
group = dynsec_groups__find(groupname);
|
|
|
|
group = dynsec_groups__find(groupname);
|
|
|
@ -188,7 +196,7 @@ int dynsec_groups__process_add_role(cJSON *j_responses, struct mosquitto *contex
|
|
|
|
return MOSQ_ERR_SUCCESS;
|
|
|
|
return MOSQ_ERR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
role = dynsec_roles__find(role_name);
|
|
|
|
role = dynsec_roles__find(rolename);
|
|
|
|
if(role == NULL){
|
|
|
|
if(role == NULL){
|
|
|
|
dynsec__command_reply(j_responses, context, "addGroupRole", "Role not found", correlation_data);
|
|
|
|
dynsec__command_reply(j_responses, context, "addGroupRole", "Role not found", correlation_data);
|
|
|
|
return MOSQ_ERR_SUCCESS;
|
|
|
|
return MOSQ_ERR_SUCCESS;
|
|
|
@ -404,6 +412,10 @@ int dynsec_groups__process_create(cJSON *j_responses, struct mosquitto *context,
|
|
|
|
dynsec__command_reply(j_responses, context, "createGroup", "Invalid/missing groupname", correlation_data);
|
|
|
|
dynsec__command_reply(j_responses, context, "createGroup", "Invalid/missing groupname", correlation_data);
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mosquitto_validate_utf8(groupname, (int)strlen(groupname)) != MOSQ_ERR_SUCCESS){
|
|
|
|
|
|
|
|
dynsec__command_reply(j_responses, context, "createGroup", "Group name not valid UTF-8", correlation_data);
|
|
|
|
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(json_get_string(command, "textname", &text_name, true) != MOSQ_ERR_SUCCESS){
|
|
|
|
if(json_get_string(command, "textname", &text_name, true) != MOSQ_ERR_SUCCESS){
|
|
|
|
dynsec__command_reply(j_responses, context, "createGroup", "Invalid/missing textname", correlation_data);
|
|
|
|
dynsec__command_reply(j_responses, context, "createGroup", "Invalid/missing textname", correlation_data);
|
|
|
@ -478,6 +490,10 @@ int dynsec_groups__process_delete(cJSON *j_responses, struct mosquitto *context,
|
|
|
|
dynsec__command_reply(j_responses, context, "deleteGroup", "Invalid/missing groupname", correlation_data);
|
|
|
|
dynsec__command_reply(j_responses, context, "deleteGroup", "Invalid/missing groupname", correlation_data);
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mosquitto_validate_utf8(groupname, (int)strlen(groupname)) != MOSQ_ERR_SUCCESS){
|
|
|
|
|
|
|
|
dynsec__command_reply(j_responses, context, "deleteGroup", "Group name not valid UTF-8", correlation_data);
|
|
|
|
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
group = dynsec_groups__find(groupname);
|
|
|
|
group = dynsec_groups__find(groupname);
|
|
|
|
if(group){
|
|
|
|
if(group){
|
|
|
@ -558,11 +574,20 @@ int dynsec_groups__process_add_client(cJSON *j_responses, struct mosquitto *cont
|
|
|
|
dynsec__command_reply(j_responses, context, "addGroupClient", "Invalid/missing username", correlation_data);
|
|
|
|
dynsec__command_reply(j_responses, context, "addGroupClient", "Invalid/missing username", correlation_data);
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mosquitto_validate_utf8(username, (int)strlen(username)) != MOSQ_ERR_SUCCESS){
|
|
|
|
|
|
|
|
dynsec__command_reply(j_responses, context, "addGroupClient", "Username not valid UTF-8", correlation_data);
|
|
|
|
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(json_get_string(command, "groupname", &groupname, false) != MOSQ_ERR_SUCCESS){
|
|
|
|
if(json_get_string(command, "groupname", &groupname, false) != MOSQ_ERR_SUCCESS){
|
|
|
|
dynsec__command_reply(j_responses, context, "addGroupClient", "Invalid/missing groupname", correlation_data);
|
|
|
|
dynsec__command_reply(j_responses, context, "addGroupClient", "Invalid/missing groupname", correlation_data);
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mosquitto_validate_utf8(groupname, (int)strlen(groupname)) != MOSQ_ERR_SUCCESS){
|
|
|
|
|
|
|
|
dynsec__command_reply(j_responses, context, "addGroupClient", "Group name not valid UTF-8", correlation_data);
|
|
|
|
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
json_get_int(command, "priority", &priority, true, -1);
|
|
|
|
json_get_int(command, "priority", &priority, true, -1);
|
|
|
|
|
|
|
|
|
|
|
|
rc = dynsec_groups__add_client(username, groupname, priority, true);
|
|
|
|
rc = dynsec_groups__add_client(username, groupname, priority, true);
|
|
|
@ -653,11 +678,19 @@ int dynsec_groups__process_remove_client(cJSON *j_responses, struct mosquitto *c
|
|
|
|
dynsec__command_reply(j_responses, context, "removeGroupClient", "Invalid/missing username", correlation_data);
|
|
|
|
dynsec__command_reply(j_responses, context, "removeGroupClient", "Invalid/missing username", correlation_data);
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mosquitto_validate_utf8(username, (int)strlen(username)) != MOSQ_ERR_SUCCESS){
|
|
|
|
|
|
|
|
dynsec__command_reply(j_responses, context, "removeGroupClient", "Username not valid UTF-8", correlation_data);
|
|
|
|
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(json_get_string(command, "groupname", &groupname, false) != MOSQ_ERR_SUCCESS){
|
|
|
|
if(json_get_string(command, "groupname", &groupname, false) != MOSQ_ERR_SUCCESS){
|
|
|
|
dynsec__command_reply(j_responses, context, "removeGroupClient", "Invalid/missing groupname", correlation_data);
|
|
|
|
dynsec__command_reply(j_responses, context, "removeGroupClient", "Invalid/missing groupname", correlation_data);
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mosquitto_validate_utf8(groupname, (int)strlen(groupname)) != MOSQ_ERR_SUCCESS){
|
|
|
|
|
|
|
|
dynsec__command_reply(j_responses, context, "removeGroupClient", "Group name not valid UTF-8", correlation_data);
|
|
|
|
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rc = dynsec_groups__remove_client(username, groupname, true);
|
|
|
|
rc = dynsec_groups__remove_client(username, groupname, true);
|
|
|
|
if(rc == MOSQ_ERR_SUCCESS){
|
|
|
|
if(rc == MOSQ_ERR_SUCCESS){
|
|
|
@ -825,6 +858,10 @@ int dynsec_groups__process_get(cJSON *j_responses, struct mosquitto *context, cJ
|
|
|
|
dynsec__command_reply(j_responses, context, "getGroup", "Invalid/missing groupname", correlation_data);
|
|
|
|
dynsec__command_reply(j_responses, context, "getGroup", "Invalid/missing groupname", correlation_data);
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mosquitto_validate_utf8(groupname, (int)strlen(groupname)) != MOSQ_ERR_SUCCESS){
|
|
|
|
|
|
|
|
dynsec__command_reply(j_responses, context, "getGroup", "Group name not valid UTF-8", correlation_data);
|
|
|
|
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tree = cJSON_CreateObject();
|
|
|
|
tree = cJSON_CreateObject();
|
|
|
|
if(tree == NULL){
|
|
|
|
if(tree == NULL){
|
|
|
@ -884,11 +921,19 @@ int dynsec_groups__process_remove_role(cJSON *j_responses, struct mosquitto *con
|
|
|
|
dynsec__command_reply(j_responses, context, "removeGroupRole", "Invalid/missing groupname", correlation_data);
|
|
|
|
dynsec__command_reply(j_responses, context, "removeGroupRole", "Invalid/missing groupname", correlation_data);
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mosquitto_validate_utf8(groupname, (int)strlen(groupname)) != MOSQ_ERR_SUCCESS){
|
|
|
|
|
|
|
|
dynsec__command_reply(j_responses, context, "removeGroupRole", "Group name not valid UTF-8", correlation_data);
|
|
|
|
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(json_get_string(command, "roleName", &rolename, false) != MOSQ_ERR_SUCCESS){
|
|
|
|
if(json_get_string(command, "roleName", &rolename, false) != MOSQ_ERR_SUCCESS){
|
|
|
|
dynsec__command_reply(j_responses, context, "removeGroupRole", "Invalid/missing roleName", correlation_data);
|
|
|
|
dynsec__command_reply(j_responses, context, "removeGroupRole", "Invalid/missing roleName", correlation_data);
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mosquitto_validate_utf8(rolename, (int)strlen(rolename)) != MOSQ_ERR_SUCCESS){
|
|
|
|
|
|
|
|
dynsec__command_reply(j_responses, context, "removeGroupRole", "Role name not valid UTF-8", correlation_data);
|
|
|
|
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
group = dynsec_groups__find(groupname);
|
|
|
|
group = dynsec_groups__find(groupname);
|
|
|
|
if(group == NULL){
|
|
|
|
if(group == NULL){
|
|
|
@ -930,6 +975,10 @@ int dynsec_groups__process_modify(cJSON *j_responses, struct mosquitto *context,
|
|
|
|
dynsec__command_reply(j_responses, context, "modifyGroup", "Invalid/missing groupname", correlation_data);
|
|
|
|
dynsec__command_reply(j_responses, context, "modifyGroup", "Invalid/missing groupname", correlation_data);
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mosquitto_validate_utf8(groupname, (int)strlen(groupname)) != MOSQ_ERR_SUCCESS){
|
|
|
|
|
|
|
|
dynsec__command_reply(j_responses, context, "modifyGroup", "Group name not valid UTF-8", correlation_data);
|
|
|
|
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
group = dynsec_groups__find(groupname);
|
|
|
|
group = dynsec_groups__find(groupname);
|
|
|
|
if(group == NULL){
|
|
|
|
if(group == NULL){
|
|
|
@ -1010,6 +1059,10 @@ int dynsec_groups__process_set_anonymous_group(cJSON *j_responses, struct mosqui
|
|
|
|
dynsec__command_reply(j_responses, context, "setAnonymousGroup", "Invalid/missing groupname", correlation_data);
|
|
|
|
dynsec__command_reply(j_responses, context, "setAnonymousGroup", "Invalid/missing groupname", correlation_data);
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mosquitto_validate_utf8(groupname, (int)strlen(groupname)) != MOSQ_ERR_SUCCESS){
|
|
|
|
|
|
|
|
dynsec__command_reply(j_responses, context, "setAnonymousGroup", "Group name not valid UTF-8", correlation_data);
|
|
|
|
|
|
|
|
return MOSQ_ERR_INVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
group = dynsec_groups__find(groupname);
|
|
|
|
group = dynsec_groups__find(groupname);
|
|
|
|
if(group == NULL){
|
|
|
|
if(group == NULL){
|
|
|
|