# HG changeset patch # User meillo@marmaro.de # Date 1303665278 -7200 # Node ID f10a56dc74811e9cbf74c1ad448c0b3e62c0f4a0 # Parent 273f6c9eb6a2b533454bb404cf873f6a0b7dd416 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. diff -r 273f6c9eb6a2 -r f10a56dc7481 admin/config-transition --- a/admin/config-transition Sun Apr 24 19:02:09 2011 +0200 +++ b/admin/config-transition Sun Apr 24 19:14:38 2011 +0200 @@ -67,6 +67,18 @@ It is now called 'caseless_matching' instead. \ " +check["online_detect"] = "conf" SUBSEP "Removed in 0.3.2" SUBSEP "\ +Destilled to online_query. \ +" + +check["online_file"] = "conf" SUBSEP "Removed in 0.3.2" SUBSEP "\ +Use online_query=\"/bin/cat /path/to/file\" instead. \ +" + +check["online_pipe"] = "conf" SUBSEP "Renamed in 0.3.2" SUBSEP "\ +Now known as online_query. online_detect=pipe is not needed anymore. \ +" + # route files check["pop3_login"] = "route" SUBSEP "Removed in 0.3.0" SUBSEP "\ diff -r 273f6c9eb6a2 -r f10a56dc7481 docs/ppp-setup --- a/docs/ppp-setup Sun Apr 24 19:02:09 2011 +0200 +++ b/docs/ppp-setup Sun Apr 24 19:14:38 2011 +0200 @@ -29,8 +29,8 @@ delivered immediately using the route configuration, you have two possibilities: -* if you are using the masqdialer system, you just have to set the - variables online_detect to pipe and online_pipe to something like +* if you are using the masqdialer system, you just have to set + online_query to something like /usr/bin/mservdetect localhost 224 if mserver is running on localhost and listens on port 224. See the man page to mservdetect(1). @@ -41,8 +41,8 @@ and you have to remove the file /var/run/masqmail/masqmail-route in your ip-down script: rm /var/run/masqmail/masqmail-route - Then you have to set online_detect to file and online_file to - /var/run/masqmail/masqmail-route + Then you have to set online_query to + /bin/cat /var/run/masqmail/masqmail-route See the route documentation for more. diff -r 273f6c9eb6a2 -r f10a56dc7481 docs/simple-relay-setup --- a/docs/simple-relay-setup Sun Apr 24 19:02:09 2011 +0200 +++ b/docs/simple-relay-setup Sun Apr 24 19:14:38 2011 +0200 @@ -106,8 +106,7 @@ Add this to masqmail.conf: - online_detect = "pipe" - online_pipe = "/bin/echo default" + online_query = "/bin/echo default" Now masqmail will send online mail automatically through the default route, each time it does a queue run (every ten minutes). diff -r 273f6c9eb6a2 -r f10a56dc7481 examples/masqmail.conf --- a/examples/masqmail.conf Sun Apr 24 19:02:09 2011 +0200 +++ b/examples/masqmail.conf Sun Apr 24 19:14:38 2011 +0200 @@ -23,8 +23,7 @@ # online detection: # # for 'file' uncomment next 2 lines -#online_detect = file -#online_file = "/var/run/masqmail/masqmail-route" +#online_query = "/bin/cat /var/run/masqmail/masqmail-route" # example for local delivery to an mda: diff -r 273f6c9eb6a2 -r f10a56dc7481 man/masqmail.8 --- a/man/masqmail.8 Sun Apr 24 19:02:09 2011 +0200 +++ b/man/masqmail.8 Sun Apr 24 19:14:38 2011 +0200 @@ -91,7 +91,7 @@ and to remote ones, if available online routes permit. That means, masqmail sends all queued mail it can. Online detection is done with the configured -method (see \fBonline_detect\fR in \fBmasqmail.conf(5)\fR). +method (see \fBonline_query\fR in \fBmasqmail.conf(5)\fR). .TP .B Single queue run (only named route) diff -r 273f6c9eb6a2 -r f10a56dc7481 man/masqmail.conf.5 --- a/man/masqmail.conf.5 Sun Apr 24 19:02:09 2011 +0200 +++ b/man/masqmail.conf.5 Sun Apr 24 19:14:38 2011 +0200 @@ -347,69 +347,43 @@ Default is false. .TP -\fBonline_detect = \fIstring\fR +\fBonline_query = \fIcommand line\fR -Defines the method masqmail uses to detect whether there is currently an online connection. -It can have the values \fIfile\fR or \fIpipe\fR. +Defines the method masqmail uses to detect whether there exists an online connection currently. -When it is set to \fIfile\fR, masqmail first checks for the existence of \fBonline_file\fR -(see below) and if it exists, it reads it. -The content of the file should be the name of the current connection as defined -with \fBconnect_route.\fIname\fR (trailing whitespace is removed). +Masqmail executes the command given and reads from its standard output. +The command should just print a route name, as defined +with \fBonline_routes.\fIname\fR, to standard output and return a zero status code. +Masqmail assumes it is offline if the script returns with a non-zero status. +Leading and trailing whitespace is removed from the output. -When it is set to \fIpipe\fR, masqmail calls the executable given by the -\fBonline_pipe\fR option (see below) and reads the current online status from its standard output. +Simple example: + +.nf +#!/bin/sh +test \-e /var/run/masqmail/masqmail-route || exit 1 +cat /var/run/masqmail/masqmail-route +exit 0 +.fi No matter how masqmail detects the online status, only messages that are accepted at online time will be delivered using the connection. -The spool still has to be emptied with masqmail \fB\-qo\fIconnection\fR. +The mail spool still needs to be emptied manually +(\fB\-qo\fIconnection\fR). -.TP -\fBonline_file = \fIfile\fR - -This is the name of the file checked for when masqmail determines whether it is online. -The file should only exist when there is currently a connection. -Create it in your ip-up script with e.g. - -echo "connection-name" >/var/run/masqmail/masqmail-route - -chmod 0644 /var/run/masqmail/masqmail-route - -Do not forget to delete it in your ip-down script. - -.TP -\fBonline_pipe = \fIfile\fR - -This is the name of the executable which will be called to determine the online status. -This executable should just print the name of the current connection to -the standard output and return a zero status code. -masqmail assumes it is offline if the script returns with a non zero status. -Simple example: - -#!/bin/sh - -[ \-e /var/run/masqmail/masqmail-route ] || exit 1 - -cat /var/run/masqmail/masqmail-route - -exit 0 - -Of course, instead of the example above you could as well use \fIfile\fR as -the online detection method, but you can do something more sophisticated. - -\fIfile\fR must contain an absolute path to an executable program. +\fIcommand line\fR must start with an absolute path to an executable program. It can contain optional arguments. -Example: \fI/bin/echo foo\fR -(This tells masqmail to be always online with connection `foo'.) +To simulate the old online_method=file, use: +\fI/bin/cat /path/to/file\fP -For querying a masqdialer server -(= asking it whether a connection exists and what its name is) +To be always online with connection `foo', use: +\fI/bin/echo foo\fP + +To query a masqdialer server +(i.e. asking it whether a connection exists and what its name is) use: - -online_method=pipe - -online_pipe="/usr/bin/mservdetect localhost 224" +\fI/usr/bin/mservdetect localhost 224\fP .TP diff -r 273f6c9eb6a2 -r f10a56dc7481 man/mservdetect.1 --- a/man/mservdetect.1 Sun Apr 24 19:02:09 2011 +0200 +++ b/man/mservdetect.1 Sun Apr 24 19:14:38 2011 +0200 @@ -14,8 +14,7 @@ if the modem server masqdialer is used. It connects to the\fIhost\fR at \fIport\fR and prints the connection name to stdout. -If you want to use it, set \fBonline_detect\fR=\fIpipe\fR and -\fBonline_pipe\fR=\fI"/usr/bin/mservdetect host port"\fR in +If you want to use it, set \fBonline_query\fR=\fI"/usr/bin/mservdetect host port"\fR in masqmail.conf. .SH OPTIONS diff -r 273f6c9eb6a2 -r f10a56dc7481 src/conf.c --- a/src/conf.c Sun Apr 24 19:02:09 2011 +0200 +++ b/src/conf.c Sun Apr 24 19:14:38 2011 +0200 @@ -542,12 +542,8 @@ conf.connect_routes = g_list_append(conf.connect_routes, pair); } else if (strcmp(lval, "local_net_route") == 0) { conf.local_net_routes = parse_list(rval, FALSE); - } else if (strcmp(lval, "online_detect") == 0) - conf.online_detect = g_strdup(rval); - else if (strcmp(lval, "online_file") == 0) - conf.online_file = g_strdup(rval); - else if (strcmp(lval, "online_pipe") == 0) - conf.online_pipe = g_strdup(rval); + } else if (strcmp(lval, "online_query") == 0) + conf.online_query = g_strdup(rval); else if (strcmp(lval, "do_queue") == 0) conf.do_queue = parse_boolean(rval); else if (strcmp(lval, "errmsg_file") == 0) diff -r 273f6c9eb6a2 -r f10a56dc7481 src/deliver.c --- a/src/deliver.c Sun Apr 24 19:02:09 2011 +0200 +++ b/src/deliver.c Sun Apr 24 19:14:38 2011 +0200 @@ -694,7 +694,7 @@ gchar *connect_name = NULL; gboolean ok = FALSE; - connect_name = detect_online(); + connect_name = online_query(); if (!connect_name) { return FALSE; } diff -r 273f6c9eb6a2 -r f10a56dc7481 src/masqmail.c --- a/src/masqmail.c Sun Apr 24 19:02:09 2011 +0200 +++ b/src/masqmail.c Sun Apr 24 19:14:38 2011 +0200 @@ -385,8 +385,7 @@ if (do_runq_online) { if (route_name) { - conf.online_detect = g_strdup("argument"); - set_online_name(route_name); + conf.online_query = g_strdup_printf("/bin/echo %s", route_name); } /* TODO: change behavior of `-qo without argument'? Because that behavior is included in -q. */ diff -r 273f6c9eb6a2 -r f10a56dc7481 src/masqmail.h --- a/src/masqmail.h Sun Apr 24 19:02:09 2011 +0200 +++ b/src/masqmail.h Sun Apr 24 19:14:38 2011 +0200 @@ -183,9 +183,7 @@ GList *local_net_routes; GList *connect_routes; /* list of pairs which point to lists */ - gchar *online_detect; - gchar *online_file; - gchar *online_pipe; + gchar *online_query; gchar *errmsg_file; gchar *warnmsg_file; @@ -478,8 +476,7 @@ gboolean queue_delete(gchar * uid); /* online.c */ -gchar *detect_online(); -void set_online_name(gchar * name); +gchar *online_query(); /* permissions.c */ gboolean is_ingroup(uid_t uid, gid_t gid); diff -r 273f6c9eb6a2 -r f10a56dc7481 src/online.c --- a/src/online.c Sun Apr 24 19:02:09 2011 +0200 +++ b/src/online.c Sun Apr 24 19:14:38 2011 +0200 @@ -17,71 +17,31 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include #include #include "masqmail.h" #include "peopen.h" -gchar *connection_name; -void -set_online_name(gchar * name) +gchar* +online_query() { - connection_name = g_strdup(name); -} - -static gchar* -detect_online_file(const gchar* file) -{ - struct stat st; - int err; - FILE *fptr; - char buf[256]; - - err = stat(conf.online_file, &st); - - if (err) { - if (errno==ENOENT) { - logwrite(LOG_NOTICE, "not online.\n"); - return NULL; - } - logwrite(LOG_ALERT, "stat of %s failed: %s\n", conf.online_file, strerror(errno)); - return NULL; - } - - fptr = fopen(conf.online_file, "r"); - if (!fptr) { - logwrite(LOG_ALERT, "opening of %s failed: %s\n", conf.online_file, strerror(errno)); - return NULL; - } - if (fgets(buf, 256, fptr) == NULL) { - logwrite(LOG_ALERT, "empty online file %s\n", conf.online_file); - fclose(fptr); - return NULL; - } - g_strstrip(buf); /* strip whitespace */ - fclose(fptr); - if (strlen(buf) == 0) { - logwrite(LOG_ALERT, "only whitespace connection name in %s\n", conf.online_file); - return NULL; - } - return g_strdup(buf); -} - -static gchar* -detect_online_pipe(const gchar * pipe) -{ + gchar* pipe = conf.online_query; pid_t pid; void (*old_signal) (int); int status; FILE *in; gchar *name = NULL; + if (!conf.online_query) { + return NULL; + } + DEBUG(3) debugf("online query `%s'\n", pipe); + old_signal = signal(SIGCHLD, SIG_DFL); in = peopen(pipe, "r", environ, &pid); - if (in == NULL) { + if (!in) { logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", pipe, strerror(errno)); signal(SIGCHLD, old_signal); return NULL; @@ -111,37 +71,3 @@ return name; } - -gchar* -detect_online() -{ - if (!conf.online_detect) { - return NULL; - } - - if (strcmp(conf.online_detect, "file") == 0) { - DEBUG(3) debugf("online detection method 'file'\n"); - if (!conf.online_file) { - logwrite(LOG_ALERT, "online detection mode is 'file', but online_file is undefined\n"); - return NULL; - } - return detect_online_file(conf.online_file); - - } else if (strcmp(conf.online_detect, "pipe") == 0) { - DEBUG(3) debugf("connection method 'pipe'\n"); - if (!conf.online_pipe) { - logwrite(LOG_ALERT, "online detection mode is 'pipe', but online_pipe is undefined\n"); - return NULL; - } - return detect_online_pipe(conf.online_pipe); - - } else if (strcmp(conf.online_detect, "argument") == 0) { - DEBUG(3) debugf("online route literally defined\n"); - /* use the name set with set_online_name() */ - return connection_name; - - } - - DEBUG(3) debugf("unknown online detection method `%s'\n", conf.online_detect); - return NULL; -} diff -r 273f6c9eb6a2 -r f10a56dc7481 tests/relay-to-hostname-mta/test.conf.tpl --- a/tests/relay-to-hostname-mta/test.conf.tpl Sun Apr 24 19:02:09 2011 +0200 +++ b/tests/relay-to-hostname-mta/test.conf.tpl Sun Apr 24 19:14:38 2011 +0200 @@ -15,8 +15,7 @@ # we want to deliver through a route named `test' to a local MTA # thus we do not define any hosts or nets as local # all mail should go through the `test' route. -online_detect = "file" -online_file = "PWD/online" +online_query = "/bin/cat PWD/online" online_routes.test = "PWD/test.route" # spool files in the current directory diff -r 273f6c9eb6a2 -r f10a56dc7481 tests/relay-to-localhost-mta/test.conf.tpl --- a/tests/relay-to-localhost-mta/test.conf.tpl Sun Apr 24 19:02:09 2011 +0200 +++ b/tests/relay-to-localhost-mta/test.conf.tpl Sun Apr 24 19:14:38 2011 +0200 @@ -15,8 +15,7 @@ # we want to deliver through a route named `test' to a local MTA # thus we do not define any hosts or nets as local # all mail should go through the `test' route. -online_detect = "file" -online_file = "PWD/online" +online_query = "/bin/cat PWD/online" online_routes.test = "PWD/test.route" # spool files in the current directory