[tpop3d-discuss] Mass virtual hosting regex problem

Chris Lightfoot chris at ex-parrot.com
Wed, 5 Nov 2003 12:37:32 +0000


On Tue, Nov 04, 2003 at 11:44:40AM -0800, Tech Support wrote:
> According to the information in the man page, I've been trying to use the mass
> virtual hosting feature. The regex doesn't seem to be working right, though.
> 
> I have the following in my config file (pasted right from the man page with
> 'pop3' changed to 'mail'):
> listen-address: 0.0.0.0/^mail\.(.*)$/
> append-domain: yes

Yep, I'd done something dumb here. I'd forgotten that the
matches returned from regexec include, as their first
element, the entire regex which matches. I'm guessing you
must be the first person to use this feature!

(Regrettably, I'd tested it with regexps like /^(..)/,
which don't show this problem....)

Here is the patch (also now in CVS):

diff -u -r1.17 listener.c
--- listener.c  7 Sep 2003 15:41:24 -0000       1.17
+++ listener.c  5 Nov 2003 12:34:34 -0000
@@ -197,7 +197,7 @@
     struct sockaddr_in sin;
     size_t l = sizeof sin;
     struct hostent *he;
-    regmatch_t match;
+    regmatch_t match[2];
     int err;
 
     if (!L->have_re)
@@ -216,20 +216,20 @@
 
     /* OK, we have a name; we need to run the regular expression against it and
      * check that we get one match exactly. */
-    if ((err = regexec(&L->re, he->h_name, 1, &match, 0)) == REG_NOMATCH) {
+    if ((err = regexec(&L->re, he->h_name, 2, match, 0)) == REG_NOMATCH) {
         log_print(LOG_WARNING, _("listener_obtain_domain: /%s/: %s: no regex match"), L->regex, he->h_name);
         return NULL;
-    } else if (match.rm_so == -1) {
+    } else if (match[1].rm_so == -1) {
         log_print(LOG_WARNING, _("listener_obtain_domain: /%s/: %s: regex failed to match any subexpression"), L->regex, he->h_name);
         return NULL;
-    } else if (match.rm_so == match.rm_eo) {
+    } else if (match[1].rm_so == match[1].rm_eo) {
         log_print(LOG_WARNING, _("listener_obtain_domain: /%s/: %s: zero-length subexpression"), L->regex, he->h_name);
         return NULL;
     } else {
         char *x;
         int l;
-        x = xcalloc((l = match.rm_eo - match.rm_so) + 1, 1);
-        memcpy(x, he->h_name + match.rm_so, l);
+        x = xcalloc((l = match[1].rm_eo - match[1].rm_so) + 1, 1);
+        memcpy(x, he->h_name + match[1].rm_so, l);
         return x;
     }
 }


-- 
``I've noticed that drivers often have trouble distinguishing
  [green and orange]. Presumably Northern Ireland drivers are
  much better with traffic lights.'' (Ben Hutchings)