util action api returns error code if it encounters wrong values parsing wrong action conf

remotes/origin/HEAD
Anoop Saldanha 13 years ago committed by Victor Julien
parent f2dd61868d
commit f5af4c9ceb

@ -1650,7 +1650,9 @@ int main(int argc, char **argv)
SCClassConfLoadClassficationConfigFile(de_ctx); SCClassConfLoadClassficationConfigFile(de_ctx);
SCRConfLoadReferenceConfigFile(de_ctx); SCRConfLoadReferenceConfigFile(de_ctx);
ActionInitConfig(); if (ActionInitConfig() < 0) {
exit(EXIT_FAILURE);
}
if (MagicInit() != 0) if (MagicInit() != 0)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

@ -90,9 +90,10 @@ uint8_t ActionAsciiToFlag(char *action) {
* \brief Load the action order from config. If none is provided, * \brief Load the action order from config. If none is provided,
* it will be default to ACTION_PASS, ACTION_DROP, * it will be default to ACTION_PASS, ACTION_DROP,
* ACTION_REJECT, ACTION_ALERT (pass has the highest prio) * ACTION_REJECT, ACTION_ALERT (pass has the highest prio)
* \retval none *
* \retval 0 on success; -1 on fatal error;
*/ */
void ActionInitConfig() { int ActionInitConfig() {
uint8_t actions_used = 0; uint8_t actions_used = 0;
uint8_t action_flag = 0; uint8_t action_flag = 0;
uint8_t actions_config[4] = {0, 0, 0, 0}; uint8_t actions_config[4] = {0, 0, 0, 0};
@ -112,7 +113,7 @@ void ActionInitConfig() {
" \"pass\",\"drop\",\"alert\",\"reject\". You have" " \"pass\",\"drop\",\"alert\",\"reject\". You have"
" to specify all of them, without quotes and without" " to specify all of them, without quotes and without"
" capital letters", action->val); " capital letters", action->val);
return; goto error;
} }
if (actions_used & action_flag) { if (actions_used & action_flag) {
@ -120,7 +121,7 @@ void ActionInitConfig() {
" use \"pass\",\"drop\",\"alert\",\"reject\". You" " use \"pass\",\"drop\",\"alert\",\"reject\". You"
" have to specify all of them, without quotes and" " have to specify all of them, without quotes and"
" without capital letters", action->val); " without capital letters", action->val);
return; goto error;
} }
if (order >= 4) { if (order >= 4) {
@ -129,7 +130,7 @@ void ActionInitConfig() {
"\"drop\",\"alert\",\"reject\". You have to specify" "\"drop\",\"alert\",\"reject\". You have to specify"
" all of them, without quotes and without capital" " all of them, without quotes and without capital"
" letters", action->val); " letters", action->val);
return; goto error;
} }
actions_used |= action_flag; actions_used |= action_flag;
actions_config[order++] = action_flag; actions_config[order++] = action_flag;
@ -140,13 +141,18 @@ void ActionInitConfig() {
"actions. Please, use \"pass\",\"drop\",\"alert\"," "actions. Please, use \"pass\",\"drop\",\"alert\","
"\"reject\". You have to specify all of them, without" "\"reject\". You have to specify all of them, without"
" quotes and without capital letters"); " quotes and without capital letters");
return; goto error;
} }
/* Now, it's a valid config. Override the default preset */ /* Now, it's a valid config. Override the default preset */
for (order = 0; order < 4; order++) { for (order = 0; order < 4; order++) {
action_order_sigs[order] = actions_config[order]; action_order_sigs[order] = actions_config[order];
} }
return 0;
error:
return -1;
} }
#ifdef UNITTESTS #ifdef UNITTESTS

@ -24,7 +24,7 @@
#ifndef __ACTION_ORDER_H__ #ifndef __ACTION_ORDER_H__
#define __ACTION_ORDER_H__ #define __ACTION_ORDER_H__
#include "suricata-common.h" #include "suricata-common.h"
void ActionInitConfig(); int ActionInitConfig();
uint8_t ActionOrderVal(uint8_t); uint8_t ActionOrderVal(uint8_t);
void UtilActionRegisterTests(void); void UtilActionRegisterTests(void);

Loading…
Cancel
Save