masqmail

changeset 310:f10a56dc7481

reworked online_detect to the simpler online_query Only pipe is supported now. Use online_query="/bin/cat /path/to/file" instead of online_detect=file online_file=/path/to/file and online_query="/path/to/some/script foo" instead of online_detect=pipe online_pipe="/path/to/some/script foo" See man page masqmail.conf(5) and admin/config-transition.
author meillo@marmaro.de
date Sun, 24 Apr 2011 19:14:38 +0200
parents 273f6c9eb6a2
children e230bcd0f1c6
files admin/config-transition docs/ppp-setup docs/simple-relay-setup examples/masqmail.conf man/masqmail.8 man/masqmail.conf.5 man/mservdetect.1 src/conf.c src/deliver.c src/masqmail.c src/masqmail.h src/online.c tests/relay-to-hostname-mta/test.conf.tpl tests/relay-to-localhost-mta/test.conf.tpl
diffstat 14 files changed, 63 insertions(+), 164 deletions(-) [+]
line diff
     1.1 --- a/admin/config-transition	Sun Apr 24 19:02:09 2011 +0200
     1.2 +++ b/admin/config-transition	Sun Apr 24 19:14:38 2011 +0200
     1.3 @@ -67,6 +67,18 @@
     1.4  It is now called 'caseless_matching' instead. \
     1.5  "
     1.6  
     1.7 +check["online_detect"] = "conf" SUBSEP "Removed in 0.3.2" SUBSEP "\
     1.8 +Destilled to online_query. \
     1.9 +"
    1.10 +
    1.11 +check["online_file"] = "conf" SUBSEP "Removed in 0.3.2" SUBSEP "\
    1.12 +Use online_query=\"/bin/cat /path/to/file\" instead. \
    1.13 +"
    1.14 +
    1.15 +check["online_pipe"] = "conf" SUBSEP "Renamed in 0.3.2" SUBSEP "\
    1.16 +Now known as online_query. online_detect=pipe is not needed anymore. \
    1.17 +"
    1.18 +
    1.19  # route files
    1.20  
    1.21  check["pop3_login"] = "route" SUBSEP "Removed in 0.3.0" SUBSEP "\
     2.1 --- a/docs/ppp-setup	Sun Apr 24 19:02:09 2011 +0200
     2.2 +++ b/docs/ppp-setup	Sun Apr 24 19:14:38 2011 +0200
     2.3 @@ -29,8 +29,8 @@
     2.4  delivered immediately using the route configuration, you have two
     2.5  possibilities:
     2.6  
     2.7 -* if you are using the masqdialer system, you just have to set the
     2.8 -  variables online_detect to pipe and online_pipe to something like
     2.9 +* if you are using the masqdialer system, you just have to set
    2.10 +  online_query to something like
    2.11  	/usr/bin/mservdetect localhost 224
    2.12    if mserver is running on localhost and listens on port 224. See the
    2.13    man page to mservdetect(1).
    2.14 @@ -41,8 +41,8 @@
    2.15    and you have to remove the file /var/run/masqmail/masqmail-route in
    2.16    your ip-down script:
    2.17  	rm /var/run/masqmail/masqmail-route
    2.18 -  Then you have to set online_detect to file and online_file to
    2.19 -  /var/run/masqmail/masqmail-route
    2.20 +  Then you have to set online_query to
    2.21 +	/bin/cat /var/run/masqmail/masqmail-route
    2.22  
    2.23  See the route documentation for more.
    2.24  
     3.1 --- a/docs/simple-relay-setup	Sun Apr 24 19:02:09 2011 +0200
     3.2 +++ b/docs/simple-relay-setup	Sun Apr 24 19:14:38 2011 +0200
     3.3 @@ -106,8 +106,7 @@
     3.4  
     3.5  Add this to masqmail.conf:
     3.6  
     3.7 -    online_detect = "pipe"
     3.8 -    online_pipe = "/bin/echo default"
     3.9 +    online_query = "/bin/echo default"
    3.10  
    3.11  Now masqmail will send online mail automatically through the default
    3.12  route, each time it does a queue run (every ten minutes).
     4.1 --- a/examples/masqmail.conf	Sun Apr 24 19:02:09 2011 +0200
     4.2 +++ b/examples/masqmail.conf	Sun Apr 24 19:14:38 2011 +0200
     4.3 @@ -23,8 +23,7 @@
     4.4  # online detection:
     4.5  #
     4.6  # for 'file' uncomment next 2 lines
     4.7 -#online_detect = file
     4.8 -#online_file = "/var/run/masqmail/masqmail-route"
     4.9 +#online_query = "/bin/cat /var/run/masqmail/masqmail-route"
    4.10  
    4.11  
    4.12  # example for local delivery to an mda:
     5.1 --- a/man/masqmail.8	Sun Apr 24 19:02:09 2011 +0200
     5.2 +++ b/man/masqmail.8	Sun Apr 24 19:14:38 2011 +0200
     5.3 @@ -91,7 +91,7 @@
     5.4  and to remote ones, if available online routes permit.
     5.5  That means, masqmail sends all queued mail it can.
     5.6  Online detection is done with the configured
     5.7 -method (see \fBonline_detect\fR in \fBmasqmail.conf(5)\fR).
     5.8 +method (see \fBonline_query\fR in \fBmasqmail.conf(5)\fR).
     5.9  
    5.10  .TP
    5.11  .B Single queue run (only named route)
     6.1 --- a/man/masqmail.conf.5	Sun Apr 24 19:02:09 2011 +0200
     6.2 +++ b/man/masqmail.conf.5	Sun Apr 24 19:14:38 2011 +0200
     6.3 @@ -347,69 +347,43 @@
     6.4  Default is false.
     6.5  
     6.6  .TP
     6.7 -\fBonline_detect = \fIstring\fR
     6.8 +\fBonline_query = \fIcommand line\fR
     6.9  
    6.10 -Defines the method masqmail uses to detect whether there is currently an online connection.
    6.11 -It can have the values \fIfile\fR or \fIpipe\fR.
    6.12 +Defines the method masqmail uses to detect whether there exists an online connection currently.
    6.13  
    6.14 -When it is set to \fIfile\fR, masqmail first checks for the existence of \fBonline_file\fR
    6.15 -(see below) and if it exists, it reads it.
    6.16 -The content of the file should be the name of the current connection as defined
    6.17 -with \fBconnect_route.\fIname\fR (trailing whitespace is removed).
    6.18 +Masqmail executes the command given and reads from its standard output.
    6.19 +The command should just print a route name, as defined
    6.20 +with \fBonline_routes.\fIname\fR, to standard output and return a zero status code.
    6.21 +Masqmail assumes it is offline if the script returns with a non-zero status.
    6.22 +Leading and trailing whitespace is removed from the output.
    6.23  
    6.24 -When it is set to \fIpipe\fR, masqmail calls the executable given by the
    6.25 -\fBonline_pipe\fR option (see below) and reads the current online status from its standard output.
    6.26 +Simple example:
    6.27 +
    6.28 +.nf
    6.29 +#!/bin/sh
    6.30 +test \-e /var/run/masqmail/masqmail-route || exit 1
    6.31 +cat /var/run/masqmail/masqmail-route
    6.32 +exit 0
    6.33 +.fi
    6.34  
    6.35  No matter how masqmail detects the online status,
    6.36  only messages that are accepted at online time will be delivered using the connection.
    6.37 -The spool still has to be emptied with masqmail \fB\-qo\fIconnection\fR.
    6.38 +The mail spool still needs to be emptied manually
    6.39 +(\fB\-qo\fIconnection\fR).
    6.40  
    6.41 -.TP
    6.42 -\fBonline_file = \fIfile\fR
    6.43 -
    6.44 -This is the name of the file checked for when masqmail determines whether it is online.
    6.45 -The file should only exist when there is currently a connection.
    6.46 -Create it in your ip-up script with e.g.
    6.47 -
    6.48 -echo "connection-name" >/var/run/masqmail/masqmail-route
    6.49 -
    6.50 -chmod 0644 /var/run/masqmail/masqmail-route
    6.51 -
    6.52 -Do not forget to delete it in your ip-down script.
    6.53 -
    6.54 -.TP
    6.55 -\fBonline_pipe = \fIfile\fR
    6.56 -
    6.57 -This is the name of the executable which will be called to determine the online status.
    6.58 -This executable should just print the name of the current connection to
    6.59 -the standard output and return a zero status code.
    6.60 -masqmail assumes it is offline if the script returns with a non zero status.
    6.61 -Simple example:
    6.62 -
    6.63 -#!/bin/sh
    6.64 -
    6.65 -[ \-e /var/run/masqmail/masqmail-route ] || exit 1
    6.66 -
    6.67 -cat /var/run/masqmail/masqmail-route
    6.68 -
    6.69 -exit 0
    6.70 -
    6.71 -Of course, instead of the example above you could as well use \fIfile\fR as
    6.72 -the online detection method, but you can do something more sophisticated.
    6.73 -
    6.74 -\fIfile\fR must contain an absolute path to an executable program.
    6.75 +\fIcommand line\fR must start with an absolute path to an executable program.
    6.76  It can contain optional arguments.
    6.77  
    6.78 -Example: \fI/bin/echo foo\fR
    6.79 -(This tells masqmail to be always online with connection `foo'.)
    6.80 +To simulate the old online_method=file, use:
    6.81 +\fI/bin/cat /path/to/file\fP
    6.82  
    6.83 -For querying a masqdialer server
    6.84 -(= asking it whether a connection exists and what its name is)
    6.85 +To be always online with connection `foo', use:
    6.86 +\fI/bin/echo foo\fP
    6.87 +
    6.88 +To query a masqdialer server
    6.89 +(i.e. asking it whether a connection exists and what its name is)
    6.90  use:
    6.91 -
    6.92 -online_method=pipe
    6.93 -
    6.94 -online_pipe="/usr/bin/mservdetect localhost 224"
    6.95 +\fI/usr/bin/mservdetect localhost 224\fP
    6.96  
    6.97  
    6.98  .TP
     7.1 --- a/man/mservdetect.1	Sun Apr 24 19:02:09 2011 +0200
     7.2 +++ b/man/mservdetect.1	Sun Apr 24 19:14:38 2011 +0200
     7.3 @@ -14,8 +14,7 @@
     7.4  if the modem server masqdialer is used.
     7.5  It connects to the\fIhost\fR at \fIport\fR and prints the connection name to stdout.
     7.6  
     7.7 -If you want to use it, set \fBonline_detect\fR=\fIpipe\fR and
     7.8 -\fBonline_pipe\fR=\fI"/usr/bin/mservdetect host port"\fR in
     7.9 +If you want to use it, set \fBonline_query\fR=\fI"/usr/bin/mservdetect host port"\fR in
    7.10  masqmail.conf.
    7.11  
    7.12  .SH OPTIONS
     8.1 --- a/src/conf.c	Sun Apr 24 19:02:09 2011 +0200
     8.2 +++ b/src/conf.c	Sun Apr 24 19:14:38 2011 +0200
     8.3 @@ -542,12 +542,8 @@
     8.4  			conf.connect_routes = g_list_append(conf.connect_routes, pair);
     8.5  		} else if (strcmp(lval, "local_net_route") == 0) {
     8.6  			conf.local_net_routes = parse_list(rval, FALSE);
     8.7 -		} else if (strcmp(lval, "online_detect") == 0)
     8.8 -			conf.online_detect = g_strdup(rval);
     8.9 -		else if (strcmp(lval, "online_file") == 0)
    8.10 -			conf.online_file = g_strdup(rval);
    8.11 -		else if (strcmp(lval, "online_pipe") == 0)
    8.12 -			conf.online_pipe = g_strdup(rval);
    8.13 +		} else if (strcmp(lval, "online_query") == 0)
    8.14 +			conf.online_query = g_strdup(rval);
    8.15  		else if (strcmp(lval, "do_queue") == 0)
    8.16  			conf.do_queue = parse_boolean(rval);
    8.17  		else if (strcmp(lval, "errmsg_file") == 0)
     9.1 --- a/src/deliver.c	Sun Apr 24 19:02:09 2011 +0200
     9.2 +++ b/src/deliver.c	Sun Apr 24 19:14:38 2011 +0200
     9.3 @@ -694,7 +694,7 @@
     9.4  	gchar *connect_name = NULL;
     9.5  	gboolean ok = FALSE;
     9.6  
     9.7 -	connect_name = detect_online();
     9.8 +	connect_name = online_query();
     9.9  	if (!connect_name) {
    9.10  		return FALSE;
    9.11  	}
    10.1 --- a/src/masqmail.c	Sun Apr 24 19:02:09 2011 +0200
    10.2 +++ b/src/masqmail.c	Sun Apr 24 19:14:38 2011 +0200
    10.3 @@ -385,8 +385,7 @@
    10.4  
    10.5  	if (do_runq_online) {
    10.6  		if (route_name) {
    10.7 -			conf.online_detect = g_strdup("argument");
    10.8 -			set_online_name(route_name);
    10.9 +			conf.online_query = g_strdup_printf("/bin/echo %s", route_name);
   10.10  		}
   10.11  		/* TODO: change behavior of `-qo without argument'?
   10.12  		         Because that behavior is included in -q. */
    11.1 --- a/src/masqmail.h	Sun Apr 24 19:02:09 2011 +0200
    11.2 +++ b/src/masqmail.h	Sun Apr 24 19:14:38 2011 +0200
    11.3 @@ -183,9 +183,7 @@
    11.4  	GList *local_net_routes;
    11.5  	GList *connect_routes;  /* list of pairs which point to lists */
    11.6  
    11.7 -	gchar *online_detect;
    11.8 -	gchar *online_file;
    11.9 -	gchar *online_pipe;
   11.10 +	gchar *online_query;
   11.11  
   11.12  	gchar *errmsg_file;
   11.13  	gchar *warnmsg_file;
   11.14 @@ -478,8 +476,7 @@
   11.15  gboolean queue_delete(gchar * uid);
   11.16  
   11.17  /* online.c */
   11.18 -gchar *detect_online();
   11.19 -void set_online_name(gchar * name);
   11.20 +gchar *online_query();
   11.21  
   11.22  /* permissions.c */
   11.23  gboolean is_ingroup(uid_t uid, gid_t gid);
    12.1 --- a/src/online.c	Sun Apr 24 19:02:09 2011 +0200
    12.2 +++ b/src/online.c	Sun Apr 24 19:14:38 2011 +0200
    12.3 @@ -17,71 +17,31 @@
    12.4      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    12.5  */
    12.6  
    12.7 -#include <sys/stat.h>
    12.8  #include <sys/wait.h>
    12.9  
   12.10  #include "masqmail.h"
   12.11  #include "peopen.h"
   12.12  
   12.13 -gchar *connection_name;
   12.14  
   12.15 -void
   12.16 -set_online_name(gchar * name)
   12.17 +gchar*
   12.18 +online_query()
   12.19  {
   12.20 -	connection_name = g_strdup(name);
   12.21 -}
   12.22 -
   12.23 -static gchar*
   12.24 -detect_online_file(const gchar* file)
   12.25 -{
   12.26 -	struct stat st;
   12.27 -	int err;
   12.28 -	FILE *fptr;
   12.29 -	char buf[256];
   12.30 -
   12.31 -	err = stat(conf.online_file, &st);
   12.32 -
   12.33 -	if (err) {
   12.34 -		if (errno==ENOENT) {
   12.35 -			logwrite(LOG_NOTICE, "not online.\n");
   12.36 -			return NULL;
   12.37 -		}
   12.38 -		logwrite(LOG_ALERT, "stat of %s failed: %s\n", conf.online_file, strerror(errno));
   12.39 -		return NULL;
   12.40 -	}
   12.41 -
   12.42 -	fptr = fopen(conf.online_file, "r");
   12.43 -	if (!fptr) {
   12.44 -		logwrite(LOG_ALERT, "opening of %s failed: %s\n", conf.online_file, strerror(errno));
   12.45 -		return NULL;
   12.46 -	}
   12.47 -	if (fgets(buf, 256, fptr) == NULL) {
   12.48 -		logwrite(LOG_ALERT, "empty online file %s\n", conf.online_file);
   12.49 -		fclose(fptr);
   12.50 -		return NULL;
   12.51 -	}
   12.52 -	g_strstrip(buf);  /* strip whitespace */
   12.53 -	fclose(fptr);
   12.54 -	if (strlen(buf) == 0) {
   12.55 -		logwrite(LOG_ALERT, "only whitespace connection name in %s\n", conf.online_file);
   12.56 -		return NULL;
   12.57 -	}
   12.58 -	return g_strdup(buf);
   12.59 -}
   12.60 -
   12.61 -static gchar*
   12.62 -detect_online_pipe(const gchar * pipe)
   12.63 -{
   12.64 +	gchar* pipe = conf.online_query;
   12.65  	pid_t pid;
   12.66  	void (*old_signal) (int);
   12.67  	int status;
   12.68  	FILE *in;
   12.69  	gchar *name = NULL;
   12.70  
   12.71 +	if (!conf.online_query) {
   12.72 +		return NULL;
   12.73 +	}
   12.74 +	DEBUG(3) debugf("online query `%s'\n", pipe);
   12.75 +
   12.76  	old_signal = signal(SIGCHLD, SIG_DFL);
   12.77  
   12.78  	in = peopen(pipe, "r", environ, &pid);
   12.79 -	if (in == NULL) {
   12.80 +	if (!in) {
   12.81  		logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", pipe, strerror(errno));
   12.82  		signal(SIGCHLD, old_signal);
   12.83  		return NULL;
   12.84 @@ -111,37 +71,3 @@
   12.85  
   12.86  	return name;
   12.87  }
   12.88 -
   12.89 -gchar*
   12.90 -detect_online()
   12.91 -{
   12.92 -	if (!conf.online_detect) {
   12.93 -		return NULL;
   12.94 -	}
   12.95 -
   12.96 -	if (strcmp(conf.online_detect, "file") == 0) {
   12.97 -		DEBUG(3) debugf("online detection method 'file'\n");
   12.98 -		if (!conf.online_file) {
   12.99 -			logwrite(LOG_ALERT, "online detection mode is 'file', but online_file is undefined\n");
  12.100 -			return NULL;
  12.101 -		}
  12.102 -		return detect_online_file(conf.online_file);
  12.103 -
  12.104 -	} else if (strcmp(conf.online_detect, "pipe") == 0) {
  12.105 -		DEBUG(3) debugf("connection method 'pipe'\n");
  12.106 -		if (!conf.online_pipe) {
  12.107 -			logwrite(LOG_ALERT, "online detection mode is 'pipe', but online_pipe is undefined\n");
  12.108 -			return NULL;
  12.109 -		}
  12.110 -		return detect_online_pipe(conf.online_pipe);
  12.111 -
  12.112 -	} else if (strcmp(conf.online_detect, "argument") == 0) {
  12.113 -		DEBUG(3) debugf("online route literally defined\n");
  12.114 -		/* use the name set with set_online_name() */
  12.115 -		return connection_name;
  12.116 -
  12.117 -	}
  12.118 -
  12.119 -	DEBUG(3) debugf("unknown online detection method `%s'\n", conf.online_detect);
  12.120 -	return NULL;
  12.121 -}
    13.1 --- a/tests/relay-to-hostname-mta/test.conf.tpl	Sun Apr 24 19:02:09 2011 +0200
    13.2 +++ b/tests/relay-to-hostname-mta/test.conf.tpl	Sun Apr 24 19:14:38 2011 +0200
    13.3 @@ -15,8 +15,7 @@
    13.4  # we want to deliver through a route named `test' to a local MTA
    13.5  # thus we do not define any hosts or nets as local
    13.6  # all mail should go through the `test' route.
    13.7 -online_detect = "file"
    13.8 -online_file = "PWD/online"
    13.9 +online_query = "/bin/cat PWD/online"
   13.10  online_routes.test = "PWD/test.route"
   13.11  
   13.12  # spool files in the current directory
    14.1 --- a/tests/relay-to-localhost-mta/test.conf.tpl	Sun Apr 24 19:02:09 2011 +0200
    14.2 +++ b/tests/relay-to-localhost-mta/test.conf.tpl	Sun Apr 24 19:14:38 2011 +0200
    14.3 @@ -15,8 +15,7 @@
    14.4  # we want to deliver through a route named `test' to a local MTA
    14.5  # thus we do not define any hosts or nets as local
    14.6  # all mail should go through the `test' route.
    14.7 -online_detect = "file"
    14.8 -online_file = "PWD/online"
    14.9 +online_query = "/bin/cat PWD/online"
   14.10  online_routes.test = "PWD/test.route"
   14.11  
   14.12  # spool files in the current directory