[tpop3d-discuss]domain-separators config option

Daniel Tiefnig tpop3d at inode.at
Wed, 02 Aug 2006 13:41:04 +0200


This is a multi-part message in MIME format.
--------------020503060408060703080201
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

Hej,

attached is a patch that introduces a config option called
"domain-separators", that does exactly what you'll think it does. It
makes DOMAIN_SEPARATORS from util.h configurable via tpop3d.conf. (Why
has this been a global constant anyway?) This adds some calls to
config_get_string(), but these shouldn't hurt much.
Have a look at it if you like and tell me what dou you think about that.
Chris? I'll commit to CVS if no one objects.

I implemented this because - due to historical reasons - we have to
support logins with "user@domain" as well as "user#domain". But now this
raises a limitation of tpop3d's config file, I wasn't aware of: One may
not use '#' characters in config directions in any way. A look at
config.c shows we're really just cutting config lines at the first '#'
we find.
I've patched tpop3d to seek for a backslash character preceding the '#',
but that introduces two problems:
1) Comments that are directly preceded by a backslash character won't be
recognized as comments any more. (Not very likely, though)
2) This will not only add "#" but also a literal "\" into the config
values. Substituting "\#" by "#" raises further questions about
backwards compatibility and what to do with "\\#", "\\\#", "\\\\#", ...
What do people here think about that? Chris?

lg,
daniel

--------------020503060408060703080201
Content-Type: text/plain;
 name="tpop3d_domsep.cvsdiff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="tpop3d_domsep.cvsdiff"

Index: CHANGES
===================================================================
RCS file: /home/chris/vcvs/repos/tpop3d/CHANGES,v
retrieving revision 1.102
diff -u -r1.102 CHANGES
--- CHANGES	24 Jun 2006 17:47:39 -0000	1.102
+++ CHANGES	2 Aug 2006 11:08:15 -0000
@@ -27,6 +27,8 @@
 with poll(2), to fix `Bad file descriptor' error on very busy servers (thanks
 to Arkadiusz Miskiewicz for this patch). Added mailspool-no-dotfile-locking
 option to switch off dot-locks at runtime (useful for sites using quotas).
+Added domain-separators option to make former DOMAIN_SEPARATORS from util.h
+configurable.
 
 1.5.3
 
Index: authswitch.c
===================================================================
RCS file: /home/chris/vcvs/repos/tpop3d/authswitch.c,v
retrieving revision 1.46
diff -u -r1.46 authswitch.c
--- authswitch.c	25 Aug 2005 13:21:58 -0000	1.46
+++ authswitch.c	2 Aug 2006 11:08:15 -0000
@@ -236,14 +236,17 @@
  
     /* If no local-part has been explicitly supplied, then we try to construct
      * one by splitting up the username over one of the characters listed in
-     * DOMAIN_SEPARATORS. This is distinct from the append-domain
+     * domain-separators. This is distinct from the append-domain
      * functionality, which will attempt to use the user's supplied username
      * as a local-part, with the listener domain as the domain, and the
      * strip-domain functionality, which will suppress the domain supplied by
      * the user. */
     if (!local_part && domain) {
         int n;
-        n = strcspn(user, DOMAIN_SEPARATORS);
+        char *domsep;
+        if (!(domsep = config_get_string("domain-separators")))
+            domsep = DOMAIN_SEPARATORS;
+        n = strcspn(user, domsep);
         if (n > 0 && user[n]) {
             x = xstrdup(user);
             x[n] = 0;
@@ -292,7 +295,10 @@
     /* Maybe split local part and domain (see above). */
     if (!local_part && domain) {
         int n;
-        n = strcspn(user, DOMAIN_SEPARATORS);
+        char *domsep;
+        if (!(domsep = config_get_string("domain-separators")))
+            domsep = DOMAIN_SEPARATORS;
+        n = strcspn(user, domsep);
         if (n > 0 && user[n]) {
             x = xstrdup(user);
             x[n] = 0;
Index: cfgdirectives.c
===================================================================
RCS file: /home/chris/vcvs/repos/tpop3d/cfgdirectives.c,v
retrieving revision 1.35
diff -u -r1.35 cfgdirectives.c
--- cfgdirectives.c	24 Jun 2006 17:43:52 -0000	1.35
+++ cfgdirectives.c	2 Aug 2006 11:08:15 -0000
@@ -39,6 +39,7 @@
     "lowercase-user",
     "lowercase-mailbox",
     "uidl-style",
+    "domain-separators",
  
 #if defined(MBOX_BSD) && defined(MBOX_BSD_SAVE_INDICES)
     "mailspool-index",
Index: pop3.c
===================================================================
RCS file: /home/chris/vcvs/repos/tpop3d/pop3.c,v
retrieving revision 1.62
diff -u -r1.62 pop3.c
--- pop3.c	20 Dec 2005 21:41:19 -0000	1.62
+++ pop3.c	2 Aug 2006 11:08:15 -0000
@@ -166,8 +166,11 @@
     /* Maybe retry authentication with an added or removed domain name. */
     if (!c->a && (strip_domain || append_domain)) {
         int n, len;
+        char *domsep;
         len = strlen(name);
-        n = strcspn(name, DOMAIN_SEPARATORS);
+        if (!(domsep = config_get_string("domain-separators")))
+            domsep = DOMAIN_SEPARATORS;
+        n = strcspn(name, domsep);
         if (append_domain && c->domain && n == len)
             /* OK, if we have a domain name, try appending that. */
             c->a = authcontext_new_apop(name, name, c->domain, c->timestamp, digest, c->remote_ip, c->local_ip);
@@ -525,8 +528,11 @@
             /* Maybe retry authentication with an added or removed domain name. */
             if (!c->a && (append_domain || strip_domain)) {
                 int n, len;
+                char *domsep;
                 len = strlen(c->user);
-                n = strcspn(c->user, DOMAIN_SEPARATORS);
+                if (!(domsep = config_get_string("domain-separators")))
+                    domsep = DOMAIN_SEPARATORS;
+                n = strcspn(c->user, domsep);
                 if (append_domain && c->domain && n == len)
                     /* OK, if we have a domain name, try appending that. */
                     c->a = authcontext_new_user_pass(c->user, c->user, c->domain, c->pass, c->remote_ip, c->local_ip);
Index: tpop3d.conf.5
===================================================================
RCS file: /home/chris/vcvs/repos/tpop3d/tpop3d.conf.5,v
retrieving revision 1.58
diff -u -r1.58 tpop3d.conf.5
--- tpop3d.conf.5	24 Jun 2006 17:43:52 -0000	1.58
+++ tpop3d.conf.5	2 Aug 2006 11:08:15 -0000
@@ -113,8 +113,7 @@
 with the address on which the connection was received. This is intended to
 be used where multiple virtual domains are served from multiple IP addresses.
 This option only takes effect when \fIusername\fP does not contain a
-separator, which may be `@', `%', `:' or `!'. See below for a more detailed
-description.
+separator. See below for a more detailed description.
 .TP
 \fBstrip-domain\fP: (\fByes\fP|\fBtrue\fP)
 If authentication does not succeed for a given \fIusername\fP, and the
@@ -126,7 +125,11 @@
 \fIusername\fP@\fIdomain.com\fP and \fIusername\fP@\fIdomain.net\fP are
 equivalent and served from the same machine.
 This option only takes effect when \fIusername\fP contains a separator,
-which may be `@', `%' or `!'.
+which may be specified via the \fBdomain-separators\fP config option. (see below)
+.TP
+\fBdomain-separators\fP: \fIstring\fP
+Specify which characters may be used to separate local_parts from
+domains in POP3 usernames. The default is "@%!:".
 .TP
 \fBapop-only\fP: (\fByes\fP|\fBtrue\fP)
 Disconnect any client which attempts plaintext USER/PASS authentication. The
Index: tpop3d.conf.sample
===================================================================
RCS file: /home/chris/vcvs/repos/tpop3d/tpop3d.conf.sample,v
retrieving revision 1.7
diff -u -r1.7 tpop3d.conf.sample
--- tpop3d.conf.sample	20 Dec 2005 21:41:19 -0000	1.7
+++ tpop3d.conf.sample	2 Aug 2006 11:08:15 -0000
@@ -31,6 +31,11 @@
 # supplied and fails to authenticate. [default: no]
 #strip-domain: true
 
+# domain-separators: string
+# Specifies which characters can be used to separate local_parts from
+# domains in POP3 usernames. [default: @%!:]
+#domain-separators: @
+
 # apop-only: (yes|true)
 # Disconnect any client which sends a USER command. [default: no]
 #apop-only: true

--------------020503060408060703080201--