]> source.dussan.org Git - rspamd.git/commitdiff
* Make sample config more complete
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 18 Dec 2008 17:31:21 +0000 (20:31 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 18 Dec 2008 17:31:21 +0000 (20:31 +0300)
* Fix bugs with config file parsing
* Fix bugs with creating sockets and reading commands

rspamd.conf.sample
src/cfg_file.y
src/cfg_utils.c
src/controller.c
src/main.c
src/util.c
src/util.h

index c146ce629147ce4b6d1b683d97548e1aa7a7f61d..dec751baae4d9ac021ff536cf5a4efbc4b26b794 100644 (file)
@@ -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;
+};
index 59d70b160b6d81189e16016db468ccdc75b783ca..64122087099f2659624c8346b59fb8ed4a46976c 100644 (file)
@@ -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));
                }
index 72ae975172cf838dac58a3c8cf7b5bd2883f3145..fd3f4503f6a2081be2f840a608b0ec57cd48db43 100644 (file)
@@ -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;
                }
index 4369f7d7fa5e28fd5142d81e7f8d94f1897aac8d..42e790e8aad395733573286783d253f8e329dbcc 100644 (file)
@@ -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 ++) {
index 64ac455a7975e179c55daff1aba56d59db7938a2..e2649e911284895e1477e6164db86191130205f3 100644 (file)
@@ -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);
                }
index 1399e76c730e9fb1b2255a6daa53234bd3c27024..6794d7bb75ddabd1a75b5a9caf704d51c9a78e8e 100644 (file)
@@ -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) {
@@ -74,30 +82,6 @@ make_socket_ai (struct addrinfo *ai)
        return (-1);
 }
 
-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)
 {
index 5d4590c4c987fde05db4530347f56a2188f63f9f..c0fb77eeb31d6b5e11f2901f74dc79aa0a2b1ad6 100644 (file)
@@ -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) */