Commit 3b60458e authored by Sam Varshavchik's avatar Sam Varshavchik

libfilter initialization update.

Use argv[0] to determine socket name. ratefilter, verifyfilter, dupfilter,
and perlfilter provide their argv[0] to lf_init().
parent e302ea42
......@@ -5,6 +5,7 @@
/config.guess
/config.sub
/configure.args
/courier.config.cache
/courier.service
/courier.spec
/courier.sysvinit
......
2018-06-10 Sam Varshavchik <mrsam@courier-mta.com>
* courier/filters/libfilter/libfilter.c: Use argv[0] to determine
socket name. ratefilter, verifyfilter, dupfilter, and perlfilter
provide their argv[0] to lf_init().
2018-05-22 Sam Varshavchik <mrsam@courier-mta.com>
* libs/makedat/makedat.in (cidr): Fix smtpaccess syntax parsing
for IPv6 address ranges.
2018-04-26 Sam Varshavchik <mrsam@courier-mta.com>
* Update for Fedora 28 RPM.
......
......@@ -5,7 +5,7 @@ dnl distribution information.
AC_PREREQ(2.59)
AC_INIT(courier, 0.78.2.20180428, [courier-users@lists.sourceforge.net])
AC_INIT(courier, 0.78.2.20180610, [courier-users@lists.sourceforge.net])
version=$PACKAGE_VERSION
AC_CONFIG_SRCDIR(courier/courier.c)
AM_INIT_AUTOMAKE
......
......@@ -13,7 +13,6 @@
#include "msghash.h"
#include "duphash.h"
#include "comctlfile.h"
#include "filtersocketdir.h"
#include "threadlib/threadlib.h"
#include <sys/types.h>
......@@ -196,17 +195,13 @@ static void initdupinfo(struct dupinfo *a, struct dupinfo *b)
a->cancelfunc=b->cancelfunc;
}
static int realmode(unsigned nthreads)
static int realmode(unsigned nthreads, const char *argv0)
{
int listensock;
struct cthreadinfo *threads;
struct dupinfo di;
int listensock;
struct cthreadinfo *threads;
struct dupinfo di;
listensock=lf_init("filters/dupfilter-mode",
ALLFILTERSOCKETDIR "/dupfilter",
ALLFILTERSOCKETDIR "/.dupfilter",
FILTERSOCKETDIR "/dupfilter",
FILTERSOCKETDIR "/.dupfilter");
listensock=lf_init("filters/dupfilter-mode", argv0);
if (listensock < 0)
return (1);
......@@ -310,6 +305,6 @@ int main(int argc, char **argv)
duphash_init(&top_hash, hashsize, duplevel);
duphash_init(&bottom_hash, hashsize, duplevel);
return (realmode(nthreads));
return (realmode(nthreads, argv[0]));
}
}
/*
** Copyright 2000-2006 Double Precision, Inc.
** Copyright 2000-2018 Double Precision, Inc.
** See COPYING for distribution information.
*/
......@@ -32,14 +32,14 @@
#include <sys/un.h>
#include "libfilter.h"
#include "filtersocketdir.h"
static int do_lf_init(const char *modfile,
const char *allname,
const char *alltmpname,
int lf_init(const char *modfile,
const char *allname,
const char *alltmpname,
const char *notallname,
const char *notalltmpname)
const char *notallname,
const char *notalltmpname)
{
int all=0;
const char *sockname, *tmpsockname;
......@@ -147,3 +147,41 @@ socklen_t sunlen;
}
return (fd);
}
int lf_init(const char *modfile,
const char *argv0)
{
char *allname;
char *alltmpname;
char *notallname;
char *notalltmpname;
size_t l;
int rc;
const char *p=strrchr(argv0, '/');
if (p)
argv0=p+1;
l=strlen(argv0);
allname=courier_malloc(sizeof(ALLFILTERSOCKETDIR "/") + l);
alltmpname=courier_malloc(sizeof(ALLFILTERSOCKETDIR "/.") + l);
notallname=courier_malloc(sizeof(FILTERSOCKETDIR "/") + l);
notalltmpname=courier_malloc(sizeof(FILTERSOCKETDIR "/.") + l);
strcat(strcpy(allname, ALLFILTERSOCKETDIR "/"), argv0);
strcat(strcpy(alltmpname, ALLFILTERSOCKETDIR "/."), argv0);
strcat(strcpy(notallname, FILTERSOCKETDIR "/"), argv0);
strcat(strcpy(notalltmpname, FILTERSOCKETDIR "/."), argv0);
rc=do_lf_init(modfile, allname, alltmpname, notallname, notalltmpname);
free(allname);
free(alltmpname);
free(notallname);
free(notalltmpname);
return rc;
}
......@@ -13,16 +13,15 @@ extern "C" {
/*
chdir() to Courier's root directory.
Create and initialize the filesystem socket used to accept filtering requests.
Typically we have a configuration file (modfile), then specifies whether
everything or just the selected mail sources are filtered.
lf_init reads modfile, then creates either "allname", which should be a
complete pathname to $(allfiltersocketdir), or "notallname", which should be a
complete pathname to $(filtersocketdir).
alltmpname and notalltmpname are temporary names, in the corresponding
directories (beginning with a .), that are used to create the socket.
lf_init reads modfile, then creates either the socket either in
$(allfiltersocketdir) or $(filtersocketdir), based on the passed-in
argv0, which should be the filter's argv[0].
lf_init() returns a non-zero file descriptor, or -1 for error.
......@@ -31,10 +30,8 @@ See dupfilter.c for example usage.
*/
int lf_init(const char *modfile,
const char *allname,
const char *alltmpname,
const char *notallname,
const char *notalltmpname);
const char *argv);
/*
** Checks if this process is started by courierfilter. Returns true
......
......@@ -21,7 +21,6 @@
#endif
#endif
#include "libfilter/libfilter.h"
#include "filtersocketdir.h"
#include "waitlib/waitlib.h"
#include "wrapperpl.h"
......@@ -40,7 +39,7 @@ pid_t *children;
#undef VERSION
#include "xsinit.c"
static void perlfilter()
{
char *embedding[] = { "", WRAPPERPL };
......@@ -48,16 +47,16 @@ char *args[] = { "", "0", NULL, NULL, NULL};
int exitstatus = 0;
int sock;
PerlInterpreter *my_perl;
if((my_perl = perl_alloc()) == NULL)
{
fprintf(stderr, "no memory!");
exit(1);
}
perl_construct(my_perl);
exitstatus = perl_parse(my_perl, xs_init, 2, embedding, NULL);
if (exitstatus || (exitstatus=perl_run(my_perl)) != 0)
{
fprintf(stderr, "Cannot parse " WRAPPERPL "\n");
......@@ -204,11 +203,7 @@ struct stat stat_buf;
exit(1);
}
listen_sock=lf_init("filters/perlfilter-mode",
ALLFILTERSOCKETDIR "/perlfilter",
ALLFILTERSOCKETDIR "/.perlfilter",
FILTERSOCKETDIR "/perlfilter",
FILTERSOCKETDIR "/.perlfilter");
listen_sock=lf_init("filters/perlfilter-mode", argv[0]);
if (listen_sock < 0)
{
......
......@@ -16,7 +16,6 @@
#include <fstream>
#include <map>
#include "comctlfile.h"
#include "filtersocketdir.h"
#include "afx/afx.h"
#include <sys/types.h>
#if HAVE_SYS_STAT_H
......@@ -24,7 +23,8 @@
#endif
#include "libfilter/libfilter.h"
static int ratefilter(size_t interval, size_t maxrcpts, size_t minuid)
static int ratefilter(size_t interval, size_t maxrcpts, size_t minuid,
const char *argv0)
{
int listensock;
std::string line;
......@@ -44,11 +44,7 @@ static int ratefilter(size_t interval, size_t maxrcpts, size_t minuid)
time_t lasttimestamp=0;
interval /= 2;
listensock=lf_init("filters/ratefilter-mode",
ALLFILTERSOCKETDIR "/ratefilter",
ALLFILTERSOCKETDIR "/.ratefilter",
FILTERSOCKETDIR "/ratefilter",
FILTERSOCKETDIR "/.ratefilter");
listensock=lf_init("filters/ratefilter-mode", argv0);
if (listensock < 0)
return (1);
......@@ -192,7 +188,8 @@ int main(int argc, char **argv)
clog_open_stderr(0);
ratefilter(getconfig("filters/ratefilter-interval", 60),
getconfig("filters/ratefilter-maxrcpts", 100),
getconfig("filters/ratefilter-minuid", 100));
getconfig("filters/ratefilter-minuid", 100),
argv[0]);
exit(0);
return 0;
}
......@@ -15,7 +15,6 @@
#endif
#include "comctlfile.h"
#include "comtrack.h"
#include "filtersocketdir.h"
#include "threadlib/threadlib.h"
#include <sys/types.h>
......@@ -633,7 +632,7 @@ static void verifyfinish(struct verify_thread_info *ignored)
{
}
int verifyfilter(unsigned nthreads)
int verifyfilter(unsigned nthreads, const char *argv0)
{
int listensock;
struct cthreadinfo *threads;
......@@ -651,11 +650,7 @@ int verifyfilter(unsigned nthreads)
if (logmode)
free(logmode);
listensock=lf_init("filters/verifyfilter-mode",
ALLFILTERSOCKETDIR "/verifyfilter",
ALLFILTERSOCKETDIR "/.verifyfilter",
FILTERSOCKETDIR "/verifyfilter",
FILTERSOCKETDIR "/.verifyfilter");
listensock=lf_init("filters/verifyfilter-mode", argv0);
if (listensock < 0)
return (1);
......@@ -716,5 +711,5 @@ int main(int argc, char **argv)
}
free(fn);
verifyfilter(nthreads);
verifyfilter(nthreads, argv[0]);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment