diff --git a/rust/suricatasc/src/unix/commands.rs b/rust/suricatasc/src/unix/commands.rs index 707e934c8f68..9f36b6320839 100644 --- a/rust/suricatasc/src/unix/commands.rs +++ b/rust/suricatasc/src/unix/commands.rs @@ -71,12 +71,11 @@ impl<'a> CommandParser<'a> { } pub fn parse(&self, input: &str) -> Result { - let parts: Vec<&str> = input.split(' ').map(|s| s.trim()).collect(); + let mut parts: Vec<&str> = input.split(' ').map(|s| s.trim()).collect(); if parts.is_empty() { return Err(CommandParseError::Other("No command provided".to_string())); } let command = parts[0]; - let args = &parts[1..]; let spec = self .commands @@ -91,6 +90,13 @@ impl<'a> CommandParser<'a> { // Calculate the number of required arguments for better error reporting. let required = spec.iter().filter(|e| e.required).count(); + let optional = spec.iter().filter(|e| !e.required).count(); + // Handle the case where the command has only required arguments and allow + // last one to contain spaces. + if optional == 0 { + parts = input.splitn(required + 1, ' ').map(|s| s).collect(); + } + let args = &parts[1..]; let mut json_args = HashMap::new(); @@ -386,6 +392,45 @@ fn command_defs() -> Result>, serde_json::Error> { "type": "string", }, ], + "datajson-add": [ + { + "name": "setname", + "required": true, + "type": "string", + }, + { + "name": "settype", + "required": true, + "type": "string", + }, + { + "name": "datavalue", + "required": true, + "type": "string", + }, + { + "name": "datajson", + "required": true, + "type": "string", + }, + ], + "datajson-remove": [ + { + "name": "setname", + "required": true, + "type": "string", + }, + { + "name": "settype", + "required": true, + "type": "string", + }, + { + "name": "datavalue", + "required": true, + "type": "string", + }, + ], "get-flow-stats-by-id": [ { "name": "flow_id",