summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2008-12-18 20:31:21 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2008-12-18 20:31:21 +0300
commit5f0da61541dd368961694b26766b12d051227844 (patch)
tree98f069f3db91ed38e7044ef022149e6bb6576121
parent9e9ced325226942bbfb6c4aa307f388044e29b23 (diff)
downloadrspamd-5f0da61541dd368961694b26766b12d051227844.tar.gz
rspamd-5f0da61541dd368961694b26766b12d051227844.zip
* Make sample config more complete
* Fix bugs with config file parsing * Fix bugs with creating sockets and reading commands
-rw-r--r--rspamd.conf.sample63
-rw-r--r--src/cfg_file.y12
-rw-r--r--src/cfg_utils.c8
-rw-r--r--src/controller.c12
-rw-r--r--src/main.c2
-rw-r--r--src/util.c48
-rw-r--r--src/util.h2
7 files changed, 103 insertions, 44 deletions
diff --git a/rspamd.conf.sample b/rspamd.conf.sample
index c146ce629..dec751baa 100644
--- a/rspamd.conf.sample
+++ b/rspamd.conf.sample
@@ -5,9 +5,70 @@
# pidfile - path to pid file
# Default: pidfile = /var/run/rspamd.pid
-
pidfile = "./rspamd.pid";
+# Number of workers to process connections
+# Default: 1
workers = 1;
+# Socket for accepting mail to filter, can be unix socket if begin with '/'
+# (bind_socket=/var/run/rspamd.sock for example)
bind_socket = localhost:11333;
+
+# Settings for controller interface
+control {
+ # Bind socket for control interface
+ bind_socket = localhost:11334;
+ # Password for privilleged commands
+ password = "q1";
+};
+
+# Sample metric definition
+metric {
+ # Name of metric
+ name = "testmetric";
+ # Score to count message as spam by this metric
+ required_score = 10.1;
+};
+
+# Logging settings
+logging {
+ # Log type can be: console, syslog and file
+ log_type = console;
+ # Log level can be: DEBUG, INFO, WARN and ERROR
+ log_level = DEBUG;
+ # Log facility specifies facility for syslog logging, see syslog (3) for details
+ # log_facility = "LOG_MAIL";
+
+ # Log file is used with log type "file"
+ # log_file = /var/log/rspamd.log
+};
+
+# Limit for statfile pool size
+# Default: 100M
+statfile_pool_size = 10M;
+
+
+# Sample statfile definition
+statfile {
+ # Alias is used for learning and is used as symbol
+ alias = "test.spam";
+ # Pattern is path to file, can include %r - recipient name and %f - mail from value
+ pattern = "./test.spam";
+ # Weight in spam/ham classifier
+ weight = 1.0;
+ # Size of this statfile class
+ size = 10M;
+ # Tokenizer for this statfile
+ # Deafault: osb-text
+ tokenizer = "osb-text";
+ # Classifier for this statfile
+ # Default: winnow
+ classifier = "winnow";
+};
+statfile {
+ alias = "test.ham";
+ pattern = "./test.ham";
+ weight = -1.0;
+ size = 10M;
+};
diff --git a/src/cfg_file.y b/src/cfg_file.y
index 59d70b160..641220870 100644
--- a/src/cfg_file.y
+++ b/src/cfg_file.y
@@ -464,10 +464,10 @@ loggingtype:
LOG_TYPE EQSIGN LOG_TYPE_CONSOLE {
cfg->log_type = RSPAMD_LOG_CONSOLE;
}
- LOG_TYPE EQSIGN LOG_TYPE_SYSLOG {
+ | LOG_TYPE EQSIGN LOG_TYPE_SYSLOG {
cfg->log_type = RSPAMD_LOG_SYSLOG;
}
- LOG_TYPE EQSIGN LOG_TYPE_FILE {
+ | LOG_TYPE EQSIGN LOG_TYPE_FILE {
cfg->log_type = RSPAMD_LOG_FILE;
}
;
@@ -476,13 +476,13 @@ logginglevel:
LOG_LEVEL EQSIGN LOG_LEVEL_DEBUG {
cfg->log_level = G_LOG_LEVEL_DEBUG;
}
- LOG_LEVEL EQSIGN LOG_LEVEL_INFO {
+ | LOG_LEVEL EQSIGN LOG_LEVEL_INFO {
cfg->log_level = G_LOG_LEVEL_INFO | G_LOG_LEVEL_MESSAGE;
}
- LOG_LEVEL EQSIGN LOG_LEVEL_WARNING {
+ | LOG_LEVEL EQSIGN LOG_LEVEL_WARNING {
cfg->log_level = G_LOG_LEVEL_WARNING;
}
- LOG_LEVEL EQSIGN LOG_LEVEL_ERROR {
+ | LOG_LEVEL EQSIGN LOG_LEVEL_ERROR {
cfg->log_level = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL;
}
;
@@ -621,7 +621,7 @@ statfilesize:
}
cur_statfile->size = $3;
}
- | WEIGHT EQSIGN SIZELIMIT {
+ | SIZE EQSIGN SIZELIMIT {
if (cur_statfile == NULL) {
cur_statfile = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct statfile));
}
diff --git a/src/cfg_utils.c b/src/cfg_utils.c
index 72ae97517..fd3f4503f 100644
--- a/src/cfg_utils.c
+++ b/src/cfg_utils.c
@@ -123,11 +123,14 @@ parse_bind_line (struct config_file *cf, char *str, char is_control)
return 0;
}
else {
- cf->bind_host = memory_pool_strdup (cf->cfg_pool, cur_tok);
+ cf->control_host = memory_pool_strdup (cf->cfg_pool, cur_tok);
memcpy((char *)&cf->control_addr, hent->h_addr, sizeof(struct in_addr));
s = strlen (cur_tok) + 1;
}
}
+ else {
+ cf->control_host = memory_pool_strdup (cf->cfg_pool, cur_tok);
+ }
cf->control_family = AF_INET;
}
@@ -144,6 +147,9 @@ parse_bind_line (struct config_file *cf, char *str, char is_control)
s = strlen (cur_tok) + 1;
}
}
+ else {
+ cf->bind_host = memory_pool_strdup (cf->cfg_pool, cur_tok);
+ }
cf->bind_family = AF_INET;
}
diff --git a/src/controller.c b/src/controller.c
index 4369f7d7f..42e790e8a 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -94,6 +94,7 @@ static void
free_session (struct controller_session *session)
{
bufferevent_disable (session->bev, EV_READ | EV_WRITE);
+ bufferevent_free (session->bev);
memory_pool_delete (session->session_pool);
g_free (session);
}
@@ -306,6 +307,7 @@ read_socket (struct bufferevent *bev, void *arg)
switch (session->state) {
case STATE_COMMAND:
s = evbuffer_readline (EVBUFFER_INPUT (bev));
+ msg_debug ("read_socket: got '%s' string from user", s);
if (s != NULL && *s != 0) {
len = strlen (s);
/* Remove end of line characters from string */
@@ -325,10 +327,12 @@ read_socket (struct bufferevent *bev, void *arg)
process_command ((struct controller_command *)comp_list->data, &params[1], session);
break;
case 0:
+ msg_debug ("Unknown command: '%s'", cmd);
i = snprintf (out_buf, sizeof (out_buf), "Unknown command" CRLF);
bufferevent_write (bev, out_buf, i);
break;
default:
+ msg_debug ("Ambigious command: '%s'", cmd);
i = snprintf (out_buf, sizeof (out_buf), "Ambigious command" CRLF);
bufferevent_write (bev, out_buf, i);
break;
@@ -419,7 +423,6 @@ accept_socket (int fd, short what, void *arg)
new_session->cfg = worker->srv->cfg;
new_session->state = STATE_COMMAND;
new_session->session_pool = memory_pool_new (memory_pool_get_size () - 1);
- memory_pool_add_destructor (new_session->session_pool, (pool_destruct_func)bufferevent_free, new_session->bev);
worker->srv->stat->control_connections_count ++;
/* Read event */
@@ -448,7 +451,7 @@ start_controller (struct rspamd_worker *worker)
signal_add (&worker->sig_ev, NULL);
if (worker->srv->cfg->control_family == AF_INET) {
- if ((listen_sock = make_socket (worker->srv->cfg->control_host, worker->srv->cfg->control_port)) == -1) {
+ if ((listen_sock = make_socket (&worker->srv->cfg->control_addr, worker->srv->cfg->control_port)) == -1) {
msg_err ("start_controller: cannot create tcp listen socket. %m");
exit(-errno);
}
@@ -462,6 +465,11 @@ start_controller (struct rspamd_worker *worker)
}
start_time = time (NULL);
+
+ if (listen (listen_sock, -1) == -1) {
+ msg_err ("start_controller: cannot listen on socket. %m");
+ exit(-errno);
+ }
/* Init command completion */
for (i = 0; i < sizeof (commands) / sizeof (commands[0]) - 1; i ++) {
diff --git a/src/main.c b/src/main.c
index 64ac455a7..e2649e911 100644
--- a/src/main.c
+++ b/src/main.c
@@ -297,7 +297,7 @@ main (int argc, char **argv, char **env)
sigprocmask(SIG_BLOCK, &signals.sa_mask, NULL);
if (rspamd->cfg->bind_family == AF_INET) {
- if ((listen_sock = make_socket (rspamd->cfg->bind_host, rspamd->cfg->bind_port)) == -1) {
+ if ((listen_sock = make_socket (&rspamd->cfg->bind_addr, rspamd->cfg->bind_port)) == -1) {
msg_err ("main: cannot create tcp listen socket. %m");
exit(-errno);
}
diff --git a/src/util.c b/src/util.c
index 1399e76c7..6794d7bb7 100644
--- a/src/util.c
+++ b/src/util.c
@@ -31,33 +31,41 @@ event_make_socket_nonblocking (int fd)
return 0;
}
-static int
-make_socket_ai (struct addrinfo *ai)
+int
+make_socket (struct in_addr *addr, u_short port)
{
struct linger linger;
int fd, on = 1, r;
int serrno;
+ struct sockaddr_in sin;
- /* Create listen socket */
- fd = socket(AF_INET, SOCK_STREAM, 0);
+ /* Create socket */
+ fd = socket (AF_INET, SOCK_STREAM, 0);
if (fd == -1) {
- return (-1);
+ return -1;
}
- if (event_make_socket_nonblocking(fd) < 0)
+ if (event_make_socket_nonblocking(fd) < 0) {
goto out;
+ }
if (fcntl(fd, F_SETFD, 1) == -1) {
goto out;
}
-
+
+ /* Socket options */
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on));
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on));
linger.l_onoff = 1;
linger.l_linger = 5;
setsockopt(fd, SOL_SOCKET, SO_LINGER, (void *)&linger, sizeof(linger));
+
+ /* Bind options */
+ sin.sin_family = AF_INET;
+ sin.sin_port = htons (port);
+ sin.sin_addr.s_addr = addr->s_addr;
- r = bind(fd, ai->ai_addr, ai->ai_addrlen);
+ r = bind(fd, (struct sockaddr *)&sin, sizeof (struct sockaddr_in));
if (r == -1) {
if (errno != EINPROGRESS) {
@@ -75,30 +83,6 @@ make_socket_ai (struct addrinfo *ai)
}
int
-make_socket (const char *address, u_short port)
-{
- int fd;
- struct addrinfo ai, *aitop = NULL;
- char strport[NI_MAXSERV];
- int ai_result;
-
- memset (&ai, 0, sizeof (ai));
- ai.ai_family = AF_INET;
- ai.ai_socktype = SOCK_STREAM;
- ai.ai_flags = AI_PASSIVE;
- snprintf (strport, sizeof (strport), "%d", port);
- if ((ai_result = getaddrinfo (address, strport, &ai, &aitop)) != 0) {
- return (-1);
- }
-
- fd = make_socket_ai (aitop);
-
- freeaddrinfo (aitop);
-
- return (fd);
-}
-
-int
make_unix_socket (const char *path, struct sockaddr_un *addr)
{
size_t len = strlen (path);
diff --git a/src/util.h b/src/util.h
index 5d4590c4c..c0fb77eeb 100644
--- a/src/util.h
+++ b/src/util.h
@@ -18,7 +18,7 @@
struct config_file;
/* Create socket and bind it to specified address and port */
-int make_socket(const char *, u_short );
+int make_socket(struct in_addr *, u_short );
/* Create and bind unix socket */
int make_unix_socket (const char *, struct sockaddr_un *);
/* Parse command line arguments using getopt (3) */