|
|
|
@ -831,6 +831,16 @@ TmEcode UnixSocketDatasetLookup(json_t *cmd, json_t *answer, void *data)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool JsonU32Value(json_t *jarg, uint32_t *ret)
|
|
|
|
|
{
|
|
|
|
|
int64_t r = json_integer_value(jarg);
|
|
|
|
|
if (r < 0 || r > UINT32_MAX) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
*ret = (uint32_t)r;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Command to add a tenant handler
|
|
|
|
|
*
|
|
|
|
@ -856,7 +866,12 @@ TmEcode UnixSocketRegisterTenantHandler(json_t *cmd, json_t* answer, void *data)
|
|
|
|
|
json_object_set_new(answer, "message", json_string("id is not an integer"));
|
|
|
|
|
return TM_ECODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
uint32_t tenant_id = json_integer_value(jarg);
|
|
|
|
|
uint32_t tenant_id;
|
|
|
|
|
if (!JsonU32Value(jarg, &tenant_id)) {
|
|
|
|
|
SCLogInfo("tenant_id is not a uint32");
|
|
|
|
|
json_object_set_new(answer, "message", json_string("tenant_id is not a uint32"));
|
|
|
|
|
return TM_ECODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 2 get tenant handler type */
|
|
|
|
|
jarg = json_object_get(cmd, "htype");
|
|
|
|
@ -937,7 +952,12 @@ TmEcode UnixSocketUnregisterTenantHandler(json_t *cmd, json_t* answer, void *dat
|
|
|
|
|
json_object_set_new(answer, "message", json_string("id is not an integer"));
|
|
|
|
|
return TM_ECODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
uint32_t tenant_id = json_integer_value(jarg);
|
|
|
|
|
uint32_t tenant_id;
|
|
|
|
|
if (!JsonU32Value(jarg, &tenant_id)) {
|
|
|
|
|
SCLogInfo("tenant_id is not a uint32");
|
|
|
|
|
json_object_set_new(answer, "message", json_string("tenant_id is not a uint32"));
|
|
|
|
|
return TM_ECODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 2 get tenant handler type */
|
|
|
|
|
jarg = json_object_get(cmd, "htype");
|
|
|
|
@ -1018,7 +1038,12 @@ TmEcode UnixSocketRegisterTenant(json_t *cmd, json_t* answer, void *data)
|
|
|
|
|
json_object_set_new(answer, "message", json_string("id is not an integer"));
|
|
|
|
|
return TM_ECODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
uint32_t tenant_id = json_integer_value(jarg);
|
|
|
|
|
uint32_t tenant_id;
|
|
|
|
|
if (!JsonU32Value(jarg, &tenant_id)) {
|
|
|
|
|
SCLogInfo("tenant_id is not a uint32");
|
|
|
|
|
json_object_set_new(answer, "message", json_string("tenant_id is not a uint32"));
|
|
|
|
|
return TM_ECODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 2 get tenant yaml */
|
|
|
|
|
jarg = json_object_get(cmd, "filename");
|
|
|
|
@ -1086,7 +1111,12 @@ TmEcode UnixSocketReloadTenant(json_t *cmd, json_t* answer, void *data)
|
|
|
|
|
json_object_set_new(answer, "message", json_string("id is not an integer"));
|
|
|
|
|
return TM_ECODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
uint32_t tenant_id = json_integer_value(jarg);
|
|
|
|
|
uint32_t tenant_id;
|
|
|
|
|
if (!JsonU32Value(jarg, &tenant_id)) {
|
|
|
|
|
SCLogInfo("tenant_id is not a uint32");
|
|
|
|
|
json_object_set_new(answer, "message", json_string("tenant_id is not a uint32"));
|
|
|
|
|
return TM_ECODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 2 get tenant yaml */
|
|
|
|
|
jarg = json_object_get(cmd, "filename");
|
|
|
|
@ -1180,7 +1210,12 @@ TmEcode UnixSocketUnregisterTenant(json_t *cmd, json_t* answer, void *data)
|
|
|
|
|
json_object_set_new(answer, "message", json_string("id is not an integer"));
|
|
|
|
|
return TM_ECODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
uint32_t tenant_id = json_integer_value(jarg);
|
|
|
|
|
uint32_t tenant_id;
|
|
|
|
|
if (!JsonU32Value(jarg, &tenant_id)) {
|
|
|
|
|
SCLogInfo("tenant_id is not a uint32");
|
|
|
|
|
json_object_set_new(answer, "message", json_string("tenant_id is not a uint32"));
|
|
|
|
|
return TM_ECODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCLogInfo("remove-tenant: removing tenant %d", tenant_id);
|
|
|
|
|
|
|
|
|
@ -1271,14 +1306,24 @@ TmEcode UnixSocketHostbitAdd(json_t *cmd, json_t* answer, void *data_usused)
|
|
|
|
|
json_object_set_new(answer, "message", json_string("expire is not an integer"));
|
|
|
|
|
return TM_ECODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
uint32_t expire = json_integer_value(jarg);
|
|
|
|
|
uint32_t expire;
|
|
|
|
|
if (!JsonU32Value(jarg, &expire)) {
|
|
|
|
|
SCLogInfo("expire is not a uint32");
|
|
|
|
|
json_object_set_new(answer, "message", json_string("expire is not a uint32"));
|
|
|
|
|
return TM_ECODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCLogInfo("add-hostbit: ip %s hostbit %s expire %us", ipaddress, hostbit, expire);
|
|
|
|
|
|
|
|
|
|
SCTime_t current_time = TimeGet();
|
|
|
|
|
Host *host = HostGetHostFromHash(&a);
|
|
|
|
|
if (host) {
|
|
|
|
|
HostBitSet(host, idx, SCTIME_SECS(current_time) + expire);
|
|
|
|
|
if (SCTIME_SECS(current_time) + expire > UINT32_MAX) {
|
|
|
|
|
json_object_set_new(answer, "message", json_string("couldn't set host expire"));
|
|
|
|
|
HostRelease(host);
|
|
|
|
|
return TM_ECODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
HostBitSet(host, idx, (uint32_t)(SCTIME_SECS(current_time) + expire));
|
|
|
|
|
HostRelease(host);
|
|
|
|
|
|
|
|
|
|
json_object_set_new(answer, "message", json_string("hostbit added"));
|
|
|
|
|