Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to lowercase usernames?

543 views
Skip to first unread message

Tornoci Laszlo

unread,
Jan 4, 2003, 4:04:16 PM1/4/03
to
Hello,

I run postfix-1.1.11-20021015, with cyrus-imapd 2.1.11. All my users
have lowercase login names (authenticated from a mysql db). My problem
is, that many of my users get mail with mixed case or all uppercase
addresses, which currently get bounced with 550 error. How can I
rewrite all incoming addresses into all lowercase strings?
I guess it can be done with regexps or pcre.

Here is my postconf -n :

alias_database = hash:/etc/postfix/aliases
alias_maps = mysql:/etc/postfix/mysql-aliases.cf
broken_sasl_auth_clients = yes
command_directory = /usr/sbin
config_directory = /etc/postfix
content_filter = smtp-amavis:[127.0.0.1]:10024
daemon_directory = /usr/libexec/postfix
debug_peer_level = 2
mail_owner = postfix
mailbox_transport = lmtp:unix:/var/lib/imap/socket/lmtp
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /etc/postfix/readme
sample_directory = /etc/postfix/samples
sender_canonical_maps = mysql:/etc/postfix/mysql-sender-canonical.cf
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_recipient_restrictions = permit_sasl_authenticated,
permit_mynetworks,
check_relay_domains
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain =
smtpd_sasl_security_options = noanonymous
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /etc/httpd/conf/ssl.crt/server.crt
smtpd_tls_key_file = /etc/httpd/conf/ssl.key/server.key
smtpd_tls_loglevel = 3
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
smtpd_use_tls = yes
tls_random_source = dev:/dev/urandom
virtual_maps = mysql:/etc/postfix/mysql-virtual.cf

Yours: Laszlo

--

----------------------------------------------------------------------
Laszlo L Tornoci Inst Pathophysiology
E-mail: tor...@xenia.sote.hu Semmelweis Univ Med School
tor...@net.sote.hu Nagyvarad ter 4.
fax: (36-1)-210-4409 Budapest, H-1089, Hungary
----------------------------------------------------------------------

Wietse Venema

unread,
Jan 4, 2003, 5:10:17 PM1/4/03
to
Hmm. People complained that the Postfix LMTP client lower-cased
all the recipient addresses so I took out that code.

You're right, Postfix regexp tables fold case. They do so by default,
because an address is case folded before lookup. All you need is
a case folding regexp before your real virtual table.

/etc/postfix/main.cf:
virtual_maps =
regexp:/etc/postfix/virtual_regexp
mysql:/etc/postfix/mysql-virtual.cf

/etc/postfix/virtual_regexp:
/^(.*[A-Z].*)$/ $1

It's a little disgusting, but I expect that it would work.

Wietse

Tornoci Laszlo:

Henrique de Moraes Holschuh

unread,
Jan 4, 2003, 10:34:36 PM1/4/03
to

--AqsLC8rIMeq19msA
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Sat, 04 Jan 2003, Wietse Venema wrote:
> Hmm. People complained that the Postfix LMTP client lower-cased
> all the recipient addresses so I took out that code.

Well, I just went and fixed it in Cyrus, since it CAN be argued that it is
Cyrus' job to do case folding, anyway. And it is trivial to do there.

Experimental patch (seems stable in my production systems) attached. This
patch has also been sent to Cyrus upstream, and it is also in the Debian
Cyrus21 packages.

> You're right, Postfix regexp tables fold case. They do so by default,
> because an address is case folded before lookup. All you need is
> a case folding regexp before your real virtual table.
>
> /etc/postfix/main.cf:
> virtual_maps =
> regexp:/etc/postfix/virtual_regexp
> mysql:/etc/postfix/mysql-virtual.cf
>
> /etc/postfix/virtual_regexp:
> /^(.*[A-Z].*)$/ $1
>
> It's a little disgusting, but I expect that it would work.

Will it skip the +plusaddressing part of an address, or will it fold the
entire address to lowercase?

For Cyrus, you _really_ don't want to fold the +plusaddressing part if your
setup did not use to do that before (because your users will have mixed-case
subfolders according to Murphy's law, and Cyrus is 100% case-sensitive).

> > I run postfix-1.1.11-20021015, with cyrus-imapd 2.1.11. All my users

The patch should apply to Cyrus 2.1 CVS, maybe it will apply cleanly to
2.1.11 release as well.

--
"One disk to rule them all, One disk to find them. One disk to bring
them all and in the darkness grind them. In the Land of Redmond
where the shadows lie." -- The Silicon Valley Tarot
Henrique Holschuh

--AqsLC8rIMeq19msA
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=foo

diff -ru cyrus-imapd.orig/imap/lmtpengine.c cyrus-imapd/imap/lmtpengine.c
--- cyrus-imapd.orig/imap/lmtpengine.c 2002-11-03 12:33:59.000000000 -0200
+++ cyrus-imapd/imap/lmtpengine.c 2002-12-25 10:57:30.000000000 -0200
@@ -1114,9 +1114,12 @@
char *user;
int r, sl;
address_data_t *ret = (address_data_t *) xmalloc(sizeof(address_data_t));
+ int forcedowncase;

assert(addr != NULL && msg != NULL);

+ forcedowncase = config_getswitch("lmtp_downcase_rcpt", 0);
+
if (*addr == '<') addr++;
dest = user = addr;

@@ -1147,13 +1150,18 @@
}
}
else {
+ while (*addr != '@' && *addr != '>' && *addr != '+') {
+ if (*addr == '\\') addr++;
+ if (! forcedowncase) *dest++ = *addr++;
+ else *dest++ = TOLOWER(*addr++);
+ }
while (*addr != '@' && *addr != '>') {
if (*addr == '\\') addr++;
*dest++ = *addr++;
}
}
*dest = '\0';
-
+
r = verify_user(user, ignorequota ? -1 : msg->size, msg->authstate);
if (r) {
/* we lost */
diff -ru cyrus-imapd.orig/man/imapd.conf.5 cyrus-imapd/man/imapd.conf.5
--- cyrus-imapd.orig/man/imapd.conf.5 2002-11-21 09:11:37.000000000 -0200
+++ cyrus-imapd/man/imapd.conf.5 2002-12-25 10:56:13.000000000 -0200
@@ -232,6 +232,8 @@
mailbox is over quota. By default, the failure is temporary.
.IP "\fBlmtp_allowplaintext:\fR <setting of \fIallowplaintext\fR>" 5
Allow the use of the SASL PLAIN mechanism for LMTP.
+.IP "\fBlmtp_downcase_rcpt:\fR no" 5
+If enabled, lmtpd will convert the recipient address to lowercase.
.IP "\fBpostuser:\fR <none>" 5
Userid used to deliver messages to shared folders. For example, if
set to "bb", email sent to "bb+shared.blah" would be delivered to the

--AqsLC8rIMeq19msA--

Wietse Venema

unread,
Jan 5, 2003, 12:05:05 AM1/5/03
to
Postfix case folds the entire address before (regexp) table lookup.

People who depend on case-sensitive addresses deserve the problems
that they get by doing so.

Wietse

Henrique de Moraes Holschuh:

[ Attachment, skipping... ]

Tornoci Laszlo

unread,
Jan 5, 2003, 4:46:10 AM1/5/03
to
On Sun, 5 Jan 2003, Henrique de Moraes Holschuh wrote:

> On Sat, 04 Jan 2003, Wietse Venema wrote:
> > Hmm. People complained that the Postfix LMTP client lower-cased
> > all the recipient addresses so I took out that code.
>
> Well, I just went and fixed it in Cyrus, since it CAN be argued that it is
> Cyrus' job to do case folding, anyway. And it is trivial to do there.
>
> Experimental patch (seems stable in my production systems) attached. This
> patch has also been sent to Cyrus upstream, and it is also in the Debian
> Cyrus21 packages.

Thank you both (Wietse & Henrique) for your help. The postfix regexp
solved my immediate problems. We have very recently migrated to Cyrus
imapd, my users don't have an idea about how to use address extensions,
so lowercasing the address after the + is not a problem yet.
On the long run, however, I think I will use Henrique's approach.

Tornoci Laszlo

unread,
Jan 5, 2003, 8:37:23 AM1/5/03
to
On Sat, 4 Jan 2003, Wietse Venema wrote:

> You're right, Postfix regexp tables fold case. They do so by default,
> because an address is case folded before lookup. All you need is
> a case folding regexp before your real virtual table.
>
> /etc/postfix/main.cf:
> virtual_maps =
> regexp:/etc/postfix/virtual_regexp
> mysql:/etc/postfix/mysql-virtual.cf
>
> /etc/postfix/virtual_regexp:
> /^(.*[A-Z].*)$/ $1
>
> It's a little disgusting, but I expect that it would work.

It works indeed. However, I get the following warning:
Jan 5 11:02:52 net postfix/smtpd[538]: warning: list domain net.sote.hu
in only one of $mydestination and $virtual_maps

(net.sote.hu is my machine's domain)

What's more, alias expansion gets broken to external domains:

e.g. if foo@extdomain1 writes to us...@net.sote.hu and 'user'
has this in the aliases sql table:
user user, bar@extdomain2

this is what happens:
Jan 5 11:02:53 net postfix/nqmgr[32641]: 558AAEE28E: from=<foo@extdomain1>,
size=1846, nrcpt=1 (queue active)
Jan 5 11:02:54 net postfix/lmtp[552]: 558AAEE28E: to=<us...@net.sote.hu>,
relay=/var/lib/imap/socket/lmtp[/var/lib/imap/socket/lmtp], delay=1,
status=sent (250 2.1.5 Ok)
Jan 5 11:02:54 net postfix/cleanup[539]: 29C8EEE28C:
message-id=<Pine.LNX.4.44.0301051102270.4292-100000@extdomain1>
Jan 5 11:02:54 net postfix/local[550]: 558AAEE28E: to=<us...@net.sote.hu>,
relay=local, delay=1, status=sent (forwarded as 29C8EEE28C)
Jan 5 11:02:54 net postfix/nqmgr[32641]: 29C8EEE28C: from=<foo@extdomain1>,
size=1972, nrcpt=1 (queue active)
Jan 5 11:02:54 net postfix/nqmgr[32641]: 29C8EEE28C: to=<bar@extdomain2>,
relay=none, delay=0, status=bounced (unknown user: "bar@extdomain2")
Jan 5 11:02:54 net postfix/cleanup[539]: 6C160EE28F:
message-id=<200301051002...@net.sote.hu>
Jan 5 11:02:54 net postfix/nqmgr[32641]: 6C160EE28F: from=<>, size=3506,
nrcpt=1 (queue active)
Jan 5 11:02:54 net postfix/nqmgr[32641]: 6C160EE28F: to=<foo@extdomain1>,
relay=none, delay=0, status=bounced (unknown user: "foo@extdomain1")

that is, the message gets delivered to 'us...@net.sote.hu' but will not
be forwarded to bar@extdomain2 and the sender will never get a bounce
message.

I have recently changed to postfix (and will NEVER go back to sendmail :)
and I know too little yet to find out what's wrong.
My sql virtal_map table is actually empty, but I might need it in the
future.

Yours: Laszlo

> Tornoci Laszlo:
> > Hello,


> >
> > I run postfix-1.1.11-20021015, with cyrus-imapd 2.1.11. All my users

--

Wietse Venema

unread,
Jan 5, 2003, 12:13:29 PM1/5/03
to
Tornoci Laszlo:

> On Sat, 4 Jan 2003, Wietse Venema wrote:
>
> > You're right, Postfix regexp tables fold case. They do so by default,
> > because an address is case folded before lookup. All you need is
> > a case folding regexp before your real virtual table.
> >
> > /etc/postfix/main.cf:
> > virtual_maps =
> > regexp:/etc/postfix/virtual_regexp
> > mysql:/etc/postfix/mysql-virtual.cf
> >
> > /etc/postfix/virtual_regexp:
> > /^(.*[A-Z].*)$/ $1
> >
> > It's a little disgusting, but I expect that it would work.
>
> It works indeed. However, I get the following warning:
> Jan 5 11:02:52 net postfix/smtpd[538]: warning: list domain net.sote.hu
> in only one of $mydestination and $virtual_maps

That's easily fixed - throw a @ somewhere in there:

/etc/postfix/virtual_regexp:
/^(.*[A-Z].*@.*)$/ $1

and it will no longer match the bare domain name.

Yes it will: see the line that says:

Jan 5 11:02:54 net postfix/nqmgr[32641]: 6C160EE28F: to=<foo@extdomain1>,
relay=none, delay=0, status=bounced (unknown user: "foo@extdomain1")

You are welcome to provide a more accurate problem description,
such as: how is your aliases sql table invoked from Postfix.
As it is now I cannot make head nor tail from it.

> I have recently changed to postfix (and will NEVER go back to sendmail :)
> and I know too little yet to find out what's wrong.
> My sql virtal_map table is actually empty, but I might need it in the
> future.

Wietse

Tornoci Laszlo

unread,
Jan 5, 2003, 12:49:52 PM1/5/03
to
On Sun, 5 Jan 2003, Wietse Venema wrote:

> > > /etc/postfix/main.cf:
> > > virtual_maps =
> > > regexp:/etc/postfix/virtual_regexp
> > > mysql:/etc/postfix/mysql-virtual.cf
> > >
> > > /etc/postfix/virtual_regexp:
> > > /^(.*[A-Z].*)$/ $1
> > >
> > > It's a little disgusting, but I expect that it would work.
> >
> > It works indeed. However, I get the following warning:
> > Jan 5 11:02:52 net postfix/smtpd[538]: warning: list domain net.sote.hu
> > in only one of $mydestination and $virtual_maps
>
> That's easily fixed - throw a @ somewhere in there:
>
> /etc/postfix/virtual_regexp:
> /^(.*[A-Z].*@.*)$/ $1
>
> and it will no longer match the bare domain name.

That fixed also my problem with alias expansion to external
domains. Now everything works as expected. Thanks a lot!

Yours: Laszlo

0 new messages