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 "suricata.h"
27#include "conf.h"
28#include "runmodes.h"
29#include "util-conf.h"
30#include "util-debug.h"
31#include "util-path.h"
32
34{
35 return SCConfSetFinal("default-log-dir", name) ? TM_ECODE_OK : TM_ECODE_FAILED;
36}
37
38const char *SCConfigGetLogDirectory(void)
39{
40 const char *log_dir = NULL;
41
42 if (SCConfGet("default-log-dir", &log_dir) != 1) {
43#ifdef OS_WIN32
44 log_dir = _getcwd(NULL, 0);
45 if (log_dir == NULL) {
46 log_dir = DEFAULT_LOG_DIR;
47 }
48#else
49 log_dir = DEFAULT_LOG_DIR;
50#endif /* OS_WIN32 */
51 }
52
53 return log_dir;
54}
55
57{
58 SCEnter();
59 SCStat buf;
60 if (SCStatFn(log_dir, &buf) != 0) {
62 }
64}
65
67{
68 if (strlen(name) == 0)
69 return TM_ECODE_OK;
70
71 size_t size = strlen(name) + 1;
72 char tmp[size];
73 strlcpy(tmp, name, size);
74 if (size > 2 && tmp[size - 2] == '/') // > 2 to allow just /
75 tmp[size - 2] = '\0';
76
77 return SCConfSetFinal("default-data-dir", tmp) ? TM_ECODE_OK : TM_ECODE_FAILED;
78}
79
80const char *ConfigGetDataDirectory(void)
81{
82 const char *data_dir = NULL;
83
84 if (SCConfGet("default-data-dir", &data_dir) != 1) {
85#ifdef OS_WIN32
86 data_dir = _getcwd(NULL, 0);
87 if (data_dir == NULL) {
88 data_dir = DEFAULT_DATA_DIR;
89 }
90#else
91 data_dir = DEFAULT_DATA_DIR;
92#endif /* OS_WIN32 */
93 }
94
95 SCLogDebug("returning '%s'", data_dir);
96 return data_dir;
97}
98
99TmEcode ConfigCheckDataDirectory(const char *data_dir)
100{
101 SCEnter();
102 SCStat buf;
103 if (SCStatFn(data_dir, &buf) != 0) {
105 }
107}
108
109/**
110 * \brief Find the configuration node for a specific device.
111
112 * Basically hunts through the list of maps for the first one with a
113 * key of "interface", and a value of the provided interface.
114 *
115 * \param node The node to start looking for the device
116 * configuration. Typically this would be something like the af-packet
117 * or pf-ring node.
118 *
119 * \param iface The name of the interface to find the config for.
120 */
122{
123 SCConfNode *if_node, *item;
124 TAILQ_FOREACH(if_node, &node->head, next) {
125 TAILQ_FOREACH(item, &if_node->head, next) {
126 if (strcmp(item->name, "interface") == 0 &&
127 strcmp(item->val, iface) == 0) {
128 return if_node;
129 }
130 }
131 }
132
133 return NULL;
134}
135
137{
138 const char *value;
139
140 if (SCConfGet("unix-command.enabled", &value) != 1) {
141 return 0;
142 }
143
144 if (value == NULL) {
145 SCLogError("malformed value for unix-command.enabled: NULL");
146 return 0;
147 }
148
149 if (!strcmp(value, "auto")) {
150#ifdef OS_WIN32
151 return 0;
152#else
154 SCLogInfo("Running in live mode, activating unix socket");
155 return 1;
156 } else {
157 return 0;
158 }
159#endif
160 }
161
162 return SCConfValIsTrue(value);
163}
struct HtpBodyChunk_ * next
int SCConfValIsTrue(const char *val)
Check if a value is true.
Definition conf.c:551
int SCConfSetFinal(const char *name, const char *val)
Set a final configuration value.
Definition conf.c:318
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
Definition conf.c:350
#define DEFAULT_DATA_DIR
Definition conf.h:59
#define DEFAULT_LOG_DIR
Definition conf.h:58
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:252
bool IsRunModeOffline(enum SCRunModes run_mode_to_check)
Definition runmodes.c:561
char * name
Definition conf.h:38
char * val
Definition conf.h:39
size_t strlcpy(char *dst, const char *src, size_t siz)
SCRunMode SCRunmodeGet(void)
Get the current run mode.
Definition suricata.c:279
@ TM_ECODE_FAILED
@ TM_ECODE_OK
const char * name
TmEcode ConfigSetDataDirectory(char *name)
Definition util-conf.c:66
TmEcode ConfigCheckDataDirectory(const char *data_dir)
Definition util-conf.c:99
const char * SCConfigGetLogDirectory(void)
Definition util-conf.c:38
TmEcode ConfigSetLogDirectory(const char *name)
Definition util-conf.c:33
TmEcode ConfigCheckLogDirectoryExists(const char *log_dir)
Definition util-conf.c:56
SCConfNode * ConfFindDeviceConfig(SCConfNode *node, const char *iface)
Find the configuration node for a specific device.
Definition util-conf.c:121
const char * ConfigGetDataDirectory(void)
Definition util-conf.c:80
int ConfUnixSocketIsEnable(void)
Definition util-conf.c:136
#define SCEnter(...)
Definition util-debug.h:277
#define SCLogDebug(...)
Definition util-debug.h:275
#define SCReturnInt(x)
Definition util-debug.h:281
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition util-debug.h:225
#define SCLogError(...)
Macro used to log ERROR messages.
Definition util-debug.h:267
#define SCStatFn(pathname, statbuf)
Definition util-path.h:35
struct stat SCStat
Definition util-path.h:33