diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-10-06 17:00:49 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-10-06 17:00:49 +0400 |
commit | 2c7e49f97e737af5ac40bef8bf2b33fa9331736f (patch) | |
tree | 4c6efc5c9d21aa1720b5c8a014227f0dd72c3e06 | |
parent | d162849fae30115e87ce4f745208f55bd72a22cd (diff) | |
download | rspamd-2c7e49f97e737af5ac40bef8bf2b33fa9331736f.tar.gz rspamd-2c7e49f97e737af5ac40bef8bf2b33fa9331736f.zip |
Try to check spf domain before adding it to LRU hash.
Make libutil functions ported from BSD compatible with libbsd in linux.
-rw-r--r-- | src/main.c | 14 | ||||
-rw-r--r-- | src/main.h | 2 | ||||
-rw-r--r-- | src/plugins/spf.c | 2 | ||||
-rw-r--r-- | src/util.c | 40 | ||||
-rw-r--r-- | src/util.h | 18 |
5 files changed, 41 insertions, 35 deletions
diff --git a/src/main.c b/src/main.c index c6055e2de..25e9dd562 100644 --- a/src/main.c +++ b/src/main.c @@ -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: diff --git a/src/main.h b/src/main.h index 812877d15..f979bf69a 100644 --- a/src/main.h +++ b/src/main.h @@ -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 */ diff --git a/src/plugins/spf.c b/src/plugins/spf.c index 5b4d7aa3a..4372f94b9 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -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); diff --git a/src/util.c b/src/util.c index 5ff70c9fd..277806721 100644 --- a/src/util.c +++ b/src/util.c @@ -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 diff --git a/src/util.h b/src/util.h index 2fb083eba..3e5985d1b 100644 --- a/src/util.h +++ b/src/util.h @@ -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 /* |