suricata
util-conf.c
Go to the documentation of this file.
1 /* Copyright (C) 2013 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Eric Leblond <eric@regit.org>
22  *
23  */
24 
25 #include "suricata-common.h"
26 #include "config.h"
27 #include "conf.h"
28 #include "runmodes.h"
29 #include "util-conf.h"
30 
32 {
33  return ConfSetFinal("default-log-dir", name) ? TM_ECODE_OK : TM_ECODE_FAILED;
34 }
35 
36 const char *ConfigGetLogDirectory()
37 {
38  const char *log_dir = NULL;
39 
40  if (ConfGet("default-log-dir", &log_dir) != 1) {
41 #ifdef OS_WIN32
42  log_dir = _getcwd(NULL, 0);
43  if (log_dir == NULL) {
44  log_dir = DEFAULT_LOG_DIR;
45  }
46 #else
47  log_dir = DEFAULT_LOG_DIR;
48 #endif /* OS_WIN32 */
49  }
50 
51  return log_dir;
52 }
53 
54 TmEcode ConfigCheckLogDirectory(const char *log_dir)
55 {
56  SCEnter();
57 #ifdef OS_WIN32
58  struct _stat buf;
59  if (_stat(log_dir, &buf) != 0) {
60 #else
61  struct stat buf;
62  if (stat(log_dir, &buf) != 0) {
63 #endif /* OS_WIN32 */
65  }
67 }
68 
69 /**
70  * \brief Find the configuration node for a specific device.
71 
72  * Basically hunts through the list of maps for the first one with a
73  * key of "interface", and a value of the provided interface.
74  *
75  * \param node The node to start looking for the device
76  * configuration. Typically this would be something like the af-packet
77  * or pf-ring node.
78  *
79  * \param iface The name of the interface to find the config for.
80  */
81 ConfNode *ConfFindDeviceConfig(ConfNode *node, const char *iface)
82 {
83  ConfNode *if_node, *item;
84  TAILQ_FOREACH(if_node, &node->head, next) {
85  TAILQ_FOREACH(item, &if_node->head, next) {
86  if (strcmp(item->name, "interface") == 0 &&
87  strcmp(item->val, iface) == 0) {
88  return if_node;
89  }
90  }
91  }
92 
93  return NULL;
94 }
95 
97 {
98  const char *value;
99 
100  if (ConfGet("unix-command.enabled", &value) != 1) {
101  return 0;
102  }
103 
104  if (value == NULL) {
105  SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY, "malformed value for unix-command.enabled: NULL");
106  return 0;
107  }
108 
109  if (!strcmp(value, "auto")) {
110 #ifdef HAVE_LIBJANSSON
111 #ifdef OS_WIN32
112  return 0;
113 #else
115  SCLogInfo("Running in live mode, activating unix socket");
116  return 1;
117  } else {
118  return 0;
119  }
120 #endif
121 #else
122  return 0;
123 #endif
124  }
125 
126  return ConfValIsTrue(value);
127 }
TmEcode ConfigSetLogDirectory(char *name)
Definition: util-conf.c:31
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:350
struct HtpBodyChunk_ * next
#define DEFAULT_LOG_DIR
Definition: conf.h:53
int ConfUnixSocketIsEnable(void)
Definition: util-conf.c:96
char * val
Definition: conf.h:34
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
Definition: conf.c:331
ConfNode * ConfFindDeviceConfig(ConfNode *node, const char *iface)
Find the configuration node for a specific device.
Definition: util-conf.c:81
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:294
#define SCEnter(...)
Definition: util-debug.h:337
int ConfSetFinal(const char *name, const char *val)
Set a final configuration value.
Definition: conf.c:299
TmEcode ConfigCheckLogDirectory(const char *log_dir)
Definition: util-conf.c:54
#define SCReturnInt(x)
Definition: util-debug.h:341
int ConfValIsTrue(const char *val)
Check if a value is true.
Definition: conf.c:566
Definition: conf.h:32
const char * ConfigGetLogDirectory()
Definition: util-conf.c:36
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:254
bool IsRunModeOffline(int run_mode_to_check)
Definition: runmodes.c:508
char * name
Definition: conf.h:33
int RunmodeGetCurrent(void)
Definition: suricata.c:269