|
|
|
@ -281,27 +281,27 @@ int UnixCommandAccept(UnixCommand *this)
|
|
|
|
ret = recv(client, buffer, sizeof(buffer)-1, 0);
|
|
|
|
ret = recv(client, buffer, sizeof(buffer)-1, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
if (ret < 0) {
|
|
|
|
SCLogInfo("Command server: client doesn't send version");
|
|
|
|
SCLogInfo("Command server: client doesn't send version");
|
|
|
|
UnixCommandClose(this, client);
|
|
|
|
close(client);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret >= (int)(sizeof(buffer)-1)) {
|
|
|
|
if (ret >= (int)(sizeof(buffer)-1)) {
|
|
|
|
SCLogInfo("Command server: client message is too long, "
|
|
|
|
SCLogInfo("Command server: client message is too long, "
|
|
|
|
"disconnect him.");
|
|
|
|
"disconnect him.");
|
|
|
|
UnixCommandClose(this, client);
|
|
|
|
close(client);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buffer[ret] = 0;
|
|
|
|
buffer[ret] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
client_msg = json_loads(buffer, 0, &jerror);
|
|
|
|
client_msg = json_loads(buffer, 0, &jerror);
|
|
|
|
if (client_msg == NULL) {
|
|
|
|
if (client_msg == NULL) {
|
|
|
|
SCLogInfo("Invalid command, error on line %d: %s\n", jerror.line, jerror.text);
|
|
|
|
SCLogInfo("Invalid command, error on line %d: %s\n", jerror.line, jerror.text);
|
|
|
|
UnixCommandClose(this, client);
|
|
|
|
close(client);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
version = json_object_get(client_msg, "version");
|
|
|
|
version = json_object_get(client_msg, "version");
|
|
|
|
if(!json_is_string(version)) {
|
|
|
|
if(!json_is_string(version)) {
|
|
|
|
SCLogInfo("error: version is not a string");
|
|
|
|
SCLogInfo("error: version is not a string");
|
|
|
|
UnixCommandClose(this, client);
|
|
|
|
close(client);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -309,7 +309,7 @@ int UnixCommandAccept(UnixCommand *this)
|
|
|
|
if (strcmp(json_string_value(version), UNIX_PROTO_VERSION) != 0) {
|
|
|
|
if (strcmp(json_string_value(version), UNIX_PROTO_VERSION) != 0) {
|
|
|
|
SCLogInfo("Unix socket: invalid client version: \"%s\"",
|
|
|
|
SCLogInfo("Unix socket: invalid client version: \"%s\"",
|
|
|
|
json_string_value(version));
|
|
|
|
json_string_value(version));
|
|
|
|
UnixCommandClose(this, client);
|
|
|
|
close(client);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
SCLogInfo("Unix socket: client version: \"%s\"",
|
|
|
|
SCLogInfo("Unix socket: client version: \"%s\"",
|
|
|
|
@ -319,16 +319,18 @@ int UnixCommandAccept(UnixCommand *this)
|
|
|
|
/* send answer */
|
|
|
|
/* send answer */
|
|
|
|
server_msg = json_object();
|
|
|
|
server_msg = json_object();
|
|
|
|
if (server_msg == NULL) {
|
|
|
|
if (server_msg == NULL) {
|
|
|
|
UnixCommandClose(this, client);
|
|
|
|
close(client);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
json_object_set_new(server_msg, "return", json_string("OK"));
|
|
|
|
json_object_set_new(server_msg, "return", json_string("OK"));
|
|
|
|
|
|
|
|
|
|
|
|
if (json_dump_callback(server_msg, UnixCommandSendCallback, &client, 0) == -1) {
|
|
|
|
if (json_dump_callback(server_msg, UnixCommandSendCallback, &client, 0) == -1) {
|
|
|
|
SCLogWarning(SC_ERR_SOCKET, "Unable to send command");
|
|
|
|
SCLogWarning(SC_ERR_SOCKET, "Unable to send command");
|
|
|
|
UnixCommandClose(this, client);
|
|
|
|
json_decref(server_msg);
|
|
|
|
|
|
|
|
close(client);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
json_decref(server_msg);
|
|
|
|
|
|
|
|
|
|
|
|
/* client connected */
|
|
|
|
/* client connected */
|
|
|
|
SCLogInfo("Unix socket: client connected");
|
|
|
|
SCLogInfo("Unix socket: client connected");
|
|
|
|
@ -518,7 +520,7 @@ int UnixMain(UnixCommand * this)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (FD_ISSET(this->socket, &select_set)) {
|
|
|
|
if (FD_ISSET(this->socket, &select_set)) {
|
|
|
|
if (!UnixCommandAccept(this))
|
|
|
|
if (!UnixCommandAccept(this))
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
|