]> source.dussan.org Git - rspamd.git/commitdiff
Try to check spf domain before adding it to LRU hash.
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 6 Oct 2011 13:00:49 +0000 (17:00 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 6 Oct 2011 13:00:49 +0000 (17:00 +0400)
Make libutil functions ported from BSD compatible with libbsd in linux.

src/main.c
src/main.h
src/plugins/spf.c
src/util.c
src/util.h

index c6055e2deafef16354c3705f236d0ae53a85a448..25e9dd5628fa1de16b5d17891ecdf21f3dfed095 100644 (file)
@@ -351,38 +351,38 @@ fork_worker (struct rspamd_main *rspamd, struct worker_conf *cf)
                        switch (cf->type) {
                        case TYPE_CONTROLLER:
                                setproctitle ("controller process");
-                               pidfile_close (rspamd->pfh);
+                               rspamd_pidfile_close (rspamd->pfh);
                                msg_info ("starting controller process %P", getpid ());
                                start_controller (cur);
                                break;
                        case TYPE_LMTP:
                                setproctitle ("lmtp process");
-                               pidfile_close (rspamd->pfh);
+                               rspamd_pidfile_close (rspamd->pfh);
                                msg_info ("starting lmtp process %P", getpid ());
                                start_lmtp_worker (cur);
                                break;
                        case TYPE_SMTP:
                                setproctitle ("smtp process");
-                               pidfile_close (rspamd->pfh);
+                               rspamd_pidfile_close (rspamd->pfh);
                                msg_info ("starting smtp process %P", getpid ());
                                start_smtp_worker (cur);
                                break;
                        case TYPE_FUZZY:
                                setproctitle ("fuzzy storage");
-                               pidfile_close (rspamd->pfh);
+                               rspamd_pidfile_close (rspamd->pfh);
                                msg_info ("starting fuzzy storage process %P", getpid ());
                                start_fuzzy_storage (cur);
                                break;
                        case TYPE_GREYLIST:
                                setproctitle ("greylist storage");
-                               pidfile_close (rspamd->pfh);
+                               rspamd_pidfile_close (rspamd->pfh);
                                msg_info ("starting greylist storage process %P", getpid ());
                                start_greylist_storage (cur);
                                break;
                        case TYPE_WORKER:
                        default:
                                setproctitle ("worker process");
-                               pidfile_close (rspamd->pfh);
+                               rspamd_pidfile_close (rspamd->pfh);
                                msg_info ("starting worker process %P", getpid ());
                                start_worker (cur);
                                break;
@@ -390,7 +390,7 @@ fork_worker (struct rspamd_main *rspamd, struct worker_conf *cf)
                        break;
                case -1:
                        msg_err ("cannot fork main process. %s", strerror (errno));
-                       pidfile_remove (rspamd->pfh);
+                       rspamd_pidfile_remove (rspamd->pfh);
                        exit (-errno);
                        break;
                default:
index 812877d15e972b930c7f6d23f80ab87243640025..f979bf69a8b95d6c4568284b930faf4ac18c1e55 100644 (file)
@@ -87,7 +87,7 @@ struct rspamd_main {
        struct config_file *cfg;                                                                        /**< pointer to config structure                                        */
        pid_t pid;                                                                                                      /**< main pid                                                                           */
        /* Pid file structure */
-       struct pidfh *pfh;                                                                                      /**< struct pidfh for pidfile                                           */
+       rspamd_pidfh_t *pfh;                                                                                    /**< struct pidfh for pidfile                                           */
        enum process_type type;                                                                         /**< process type                                                                       */
        guint ev_initialized;                                                                           /**< is event system is initialized                                     */
        struct rspamd_stat *stat;                                                                       /**< pointer to statistics                                                      */
index 5b4d7aa3afae7926917d1969cd8e6124c3b7918a..4372f94b946f785f33967a82eb35c7dc89ca8291 100644 (file)
@@ -218,7 +218,7 @@ spf_plugin_callback (struct spf_record *record, struct worker_task *task)
 {
        GList                           *l;
 
-       if (record && record->addrs) {
+       if (record && record->addrs && record->sender_domain) {
 
                if ((l = rspamd_lru_hash_lookup (spf_module_ctx->spf_hash, record->sender_domain, task->tv.tv_sec)) == NULL) {
                        l = spf_record_copy (record->addrs);
index 5ff70c9fd05327bf7610294ab98b10b7fb19e79a..277806721a7030434cca1ad6d72fc709bf267656 100644 (file)
@@ -287,13 +287,13 @@ write_pid (struct rspamd_main *main)
        if (main->cfg->pid_file == NULL) {
                return -1;
        }
-       main->pfh = pidfile_open (main->cfg->pid_file, 0644, &pid);
+       main->pfh = rspamd_pidfile_open (main->cfg->pid_file, 0644, &pid);
 
        if (main->pfh == NULL) {
                return -1;
        }
 
-       pidfile_write (main->pfh);
+       rspamd_pidfile_write (main->pfh);
 
        return 0;
 }
@@ -490,10 +490,10 @@ init_title (gint argc, gchar *argv[], gchar *envp[])
 
 #ifndef HAVE_PIDFILE
 extern gchar                    *__progname;
-static gint                      _pidfile_remove (struct pidfh *pfh, gint freeit);
+static gint                      _rspamd_pidfile_remove (rspamd_pidfh_t *pfh, gint freeit);
 
 static gint
-pidfile_verify (struct pidfh *pfh)
+rspamd_pidfile_verify (rspamd_pidfh_t *pfh)
 {
        struct stat                     sb;
 
@@ -510,7 +510,7 @@ pidfile_verify (struct pidfh *pfh)
 }
 
 static gint
-pidfile_read (const gchar *path, pid_t * pidptr)
+rspamd_pidfile_read (const gchar *path, pid_t * pidptr)
 {
        gchar                           buf[16], *endptr;
        gint                            error, fd, i;
@@ -535,10 +535,10 @@ pidfile_read (const gchar *path, pid_t * pidptr)
        return 0;
 }
 
-struct pidfh                   *
-pidfile_open (const gchar *path, mode_t mode, pid_t * pidptr)
+rspamd_pidfh_t                   *
+rspamd_pidfile_open (const gchar *path, mode_t mode, pid_t * pidptr)
 {
-       struct pidfh                   *pfh;
+       rspamd_pidfh_t                 *pfh;
        struct stat                     sb;
        gint                            error, fd, len, count;
        struct timespec                 rqtp;
@@ -571,7 +571,7 @@ pidfile_open (const gchar *path, mode_t mode, pid_t * pidptr)
                rqtp.tv_nsec = 5000000;
                if (errno == EWOULDBLOCK && pidptr != NULL) {
                  again:
-                       errno = pidfile_read (pfh->pf_path, pidptr);
+                       errno = rspamd_pidfile_read (pfh->pf_path, pidptr);
                        if (errno == 0)
                                errno = EEXIST;
                        else if (errno == EAGAIN) {
@@ -605,7 +605,7 @@ pidfile_open (const gchar *path, mode_t mode, pid_t * pidptr)
 }
 
 gint
-pidfile_write (struct pidfh *pfh)
+rspamd_pidfile_write (rspamd_pidfh_t *pfh)
 {
        gchar                           pidstr[16];
        gint                            error, fd;
@@ -614,7 +614,7 @@ pidfile_write (struct pidfh *pfh)
         * Check remembered descriptor, so we don't overwrite some other
         * file if pidfile was closed and descriptor reused.
         */
-       errno = pidfile_verify (pfh);
+       errno = rspamd_pidfile_verify (pfh);
        if (errno != 0) {
                /*
                 * Don't close descriptor, because we are not sure if it's ours.
@@ -628,7 +628,7 @@ pidfile_write (struct pidfh *pfh)
         */
        if (ftruncate (fd, 0) == -1) {
                error = errno;
-               _pidfile_remove (pfh, 0);
+               _rspamd_pidfile_remove (pfh, 0);
                errno = error;
                return -1;
        }
@@ -636,7 +636,7 @@ pidfile_write (struct pidfh *pfh)
        rspamd_snprintf (pidstr, sizeof (pidstr), "%P", getpid ());
        if (pwrite (fd, pidstr, strlen (pidstr), 0) != (ssize_t) strlen (pidstr)) {
                error = errno;
-               _pidfile_remove (pfh, 0);
+               _rspamd_pidfile_remove (pfh, 0);
                errno = error;
                return -1;
        }
@@ -645,11 +645,11 @@ pidfile_write (struct pidfh *pfh)
 }
 
 gint
-pidfile_close (struct pidfh *pfh)
+rspamd_pidfile_close (rspamd_pidfh_t *pfh)
 {
        gint                            error;
 
-       error = pidfile_verify (pfh);
+       error = rspamd_pidfile_verify (pfh);
        if (error != 0) {
                errno = error;
                return -1;
@@ -666,11 +666,11 @@ pidfile_close (struct pidfh *pfh)
 }
 
 static gint
-_pidfile_remove (struct pidfh *pfh, gint freeit)
+_rspamd_pidfile_remove (rspamd_pidfh_t *pfh, gint freeit)
 {
        gint                            error;
 
-       error = pidfile_verify (pfh);
+       error = rspamd_pidfile_verify (pfh);
        if (error != 0) {
                errno = error;
                return -1;
@@ -678,7 +678,7 @@ _pidfile_remove (struct pidfh *pfh, gint freeit)
 
        if (unlink (pfh->pf_path) == -1)
                error = errno;
-       if (! unlock_file (pfh->pf_fd, FALSE)) {
+       if (!unlock_file (pfh->pf_fd, FALSE)) {
                if (error == 0)
                        error = errno;
        }
@@ -698,10 +698,10 @@ _pidfile_remove (struct pidfh *pfh, gint freeit)
 }
 
 gint
-pidfile_remove (struct pidfh *pfh)
+rspamd_pidfile_remove (rspamd_pidfh_t *pfh)
 {
 
-       return (_pidfile_remove (pfh, 1));
+       return (_rspamd_pidfile_remove (pfh, 1));
 }
 #endif
 
index 2fb083ebaa8e283042dc0604cb05b3d2c1b9ae28..3e5985d1bfc9e42645ce94665a415c2f66b3b591 100644 (file)
@@ -95,7 +95,7 @@ gint setproctitle(const gchar *fmt, ...);
 /*
  * Pidfile functions from FreeBSD libutil code
  */
-struct pidfh {
+typedef struct rspamd_pidfh_s {
        gint pf_fd;
 #ifdef HAVE_PATH_MAX
        gchar    pf_path[PATH_MAX + 1];
@@ -106,11 +106,17 @@ struct pidfh {
 #endif
        dev_t pf_dev;
        ino_t   pf_ino;
-};
-struct pidfh *pidfile_open(const gchar *path, mode_t mode, pid_t *pidptr);
-gint pidfile_write(struct pidfh *pfh);
-gint pidfile_close(struct pidfh *pfh);
-gint pidfile_remove(struct pidfh *pfh);
+} rspamd_pidfh_t;
+rspamd_pidfh_t *rspamd_pidfile_open(const gchar *path, mode_t mode, pid_t *pidptr);
+gint rspamd_pidfile_write(rspamd_pidfh_t *pfh);
+gint rspamd_pidfile_close(rspamd_pidfh_t *pfh);
+gint rspamd_pidfile_remove(rspamd_pidfh_t *pfh);
+#else
+typedef struct pidfh rspamd_pidfh_t;
+#define rspamd_pidfile_open pidfile_open
+#define rspamd_pidfile_write pidfile_write
+#define rspamd_pidfile_close pidfile_close
+#define rspamd_pidfile_remove pidfile_remove
 #endif
 
 /*