Mailing List Archive

Patch for address rewriting. Comments?
-----BEGIN PGP SIGNED MESSAGE-----

Hi,
Recently modified qmail-inject.c to perform address rewriting. This
allows to get all To:, From: etc. into our standard format. Thought others
may be interested. Anyone who knows qmail-inject inside out (Dan?) care to
comment on it? Cheers. (There's still some diagnostics in this version,
but you get the idea.) (Sorry about the comments, Dan :-)

- ------
diff -c qmail-1.00.orig/qmail-inject.c qmail-1.00/qmail-inject.c
*** qmail-1.00.orig/qmail-inject.c Thu Feb 20 07:07:24 1997
- --- qmail-1.00/qmail-inject.c Tue Mar 18 14:13:47 1997
***************
*** 21,26 ****
- --- 21,27 ----
#include "exit.h"
#include "quote.h"
#include "headerbody.h"
+ #include "cdb.h"

#define LINELEN 80

***************
*** 254,259 ****
- --- 255,309 ----
addr->t[i] = defaultdomain.t[shift - 1 - i];
}

+ stralloc tempsa = {0};
+ stralloc tempsabuf = {0};
+ token822_alloc tempaddr = {0};
+ int usersfd;
+
+ void salf_rw(addr)
+ token822_alloc *addr;
+ {
+ char buf[LINELEN + 2];
+ uint32 dlen, p;
+
+ /* reverse addr array */
+ token822_reverse(addr);
+
+ /* convert addr array back to string */
+ if (token822_unparse(&tempsa, addr, LINELEN) != 1) die_nomem();
+
+ /* lower-case the string */
+ for (p = 0; p < tempsa.len - 1; p++)
+ tempsa.s[p] = tolower(tempsa.s[p]);
+
+ strncpy(buf, tempsa.s, tempsa.len);
+ buf[tempsa.len] = '\0';
+ printf("%s", buf);
+
+ /* see if we can find it in the database */
+ if (tempsa.len >= 2 && cdb_seek(usersfd, tempsa.s, tempsa.len - 1, &dlen)) {
+
+ /* if so check we can read the value okay */
+ if (dlen <= sizeof buf && read(usersfd, buf, dlen) == dlen) {
+
+ buf[dlen] = '\0';
+ printf("Matched with : %s\n", buf);
+ /* resize the allocated space for string and copy new string over it */
+ if (stralloc_ready(&tempsa, dlen + 1)) {
+ strncpy(tempsa.s, buf, dlen);
+ tempsa.s[dlen] = '\n';
+ tempsa.len = dlen + 1;
+
+ /* parse string back into addr array */
+ token822_parse(addr, &tempsa, &tempsabuf);
+ }
+ }
+ }
+
+ /* reverse addr array */
+ token822_reverse(addr);
+ }
+
void rwplus(addr)
token822_alloc *addr;
{
***************
*** 293,298 ****
- --- 343,349 ----
rwnoat(addr);
rwplus(addr);
rwnodot(addr);
+ salf_rw(addr);
}

int setreturn(addr)
***************
*** 652,657 ****
- --- 703,710 ----
int recipstrategy;

signal_init();
+
+ usersfd = open_read("/var/qmail/rewrite/compiled");

starttime = now();

diff -c qmail-1.00.orig/Makefile qmail-1.00/Makefile
*** qmail-1.00.orig/Makefile Thu Feb 20 07:07:24 1997
- --- qmail-1.00/Makefile Tue Mar 11 10:42:12 1997
***************
*** 965,978 ****
qmail-inject.o hfield.o newfield.o datetime.o date822fmt.o now.o \
signal.o quote.o token822.o control.o libopen.a headerbody.o qqtalk.o \
libwait.a libenv.a libgetopt.a libgetline.a libsubstdio.a \
! libstralloc.a liballoc.a liberror.a libstr.a libfs.a libfd.a load
./load qmail-inject hfield.o newfield.o datetime.o \
date822fmt.o now.o signal.o quote.o token822.o control.o \
headerbody.o qqtalk.o libenv.a libgetopt.a libgetline.a \
libfd.a \
libwait.a \
libopen.a \
! libsubstdio.a libstralloc.a liballoc.a liberror.a libstr.a libfs.a

qmail-inject.0: \
qmail-inject.8
- --- 965,978 ----
qmail-inject.o hfield.o newfield.o datetime.o date822fmt.o now.o \
signal.o quote.o token822.o control.o libopen.a headerbody.o qqtalk.o \
libwait.a libenv.a libgetopt.a libgetline.a libsubstdio.a \
! libstralloc.a liballoc.a liberror.a libstr.a libfs.a libfd.a load libcdb.a
./load qmail-inject hfield.o newfield.o datetime.o \
date822fmt.o now.o signal.o quote.o token822.o control.o \
headerbody.o qqtalk.o libenv.a libgetopt.a libgetline.a \
libfd.a \
libwait.a \
libopen.a \
! libsubstdio.a libstralloc.a liballoc.a liberror.a libstr.a libfs.a libcdb.a

qmail-inject.0: \
qmail-inject.8
***************
*** 983,989 ****
error.h sgetopt.h stralloc.h now.h gen_alloc.h exit.h subfd.h \
newfield.h quote.h headerbody.h token822.h qqtalk.h alloc.h \
conf-home.h getline.h fmt.h str.h subgetopt.h gen_allocdefs.h \
! datetime.h
./compile qmail-inject.c

qmail-limits.0: \
- --- 983,989 ----
error.h sgetopt.h stralloc.h now.h gen_alloc.h exit.h subfd.h \
newfield.h quote.h headerbody.h token822.h qqtalk.h alloc.h \
conf-home.h getline.h fmt.h str.h subgetopt.h gen_allocdefs.h \
! datetime.h cdb.h uint32.h
./compile qmail-inject.c

qmail-limits.0: \
- ------

Mark Powell - Unix Information Officer - Clifford Whitworth Building
A.I.S., University of Salford, Salford, Manchester, UK.
Tel: +44 161 745 5936 Fax: +44 161 736 3596
Email: mark@salford.ac.uk finger mark@ucsalf.ac.uk (for PGP key)
<A HREF="http://www.ucsalf.ac.uk/~mark/">Home Page</A>

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv

iQCVAwUBMy6ls1M87iaKBL59AQGjggP+JpsseeY8uLt6WL/U0LStLvSp3GxOiO3Y
GUwApsjEu4+6f0zTRhvVt4ala/zc5N/7JqLhrJiK4E4+3+dS0NZJwyHH1UJa3I9t
e9393u3ygahzXYzhQqpueFe0DV8/m70eAXMH3Bry5KYTou7zuT2k2nSkPQOHCxLO
UckOGYz5qzc=
=Pyk6
-----END PGP SIGNATURE-----
Re: Patch for address rewriting. Comments? [ In reply to ]
Hi Mark,

Did you verify that your patch works if you have a list of addresses in a
field (like To: u@a, v@b)? Looking at your patch, I would think that it will
fail. I have a similar patch with rudimentary documentation. When I wrote it,
I had the problem that token822_parse uses the string space passed to hold the
text associated with some of the tokens w/o copying. You need an extra buffer
per address in a list of addresses in a header. I'll try to make my patches
avaialble RSN.

Cheers,
Lukas
-------------------------------------------------------------------------------
Dr. Lukas Nellen | Email: lukas@teorica0.ifisicacu.unam.mx
Depto. de Fisica Teorica, IFUNAM |
Apdo. Postal 20-364 | Tel.: +52 5 622 5014 ext. 218
01000 Mexico D.F., MEXICO | Fax: +52 5 622 5015
Re: Patch for address rewriting. Comments? [ In reply to ]
-----BEGIN PGP SIGNED MESSAGE-----

In article <5gmsan$4fa$1@io.salford.ac.uk>,
<lukas@teorica0.ifisicacu.unam.mx> wrote:
>Hi Mark,
>
>Did you verify that your patch works if you have a list of addresses in a
>field (like To: u@a, v@b)? Looking at your patch, I would think that it
will
>fail. I have a similar patch with rudimentary documentation. When I wrote
it,

It works fine for multiple addresses. The rw_generic function is called
for each 822 address not just once for the To:, From:, etc. lines.

>I had the problem that token822_parse uses the string space passed to
hold the
>text associated with some of the tokens w/o copying. You need an extra
buffer
>per address in a list of addresses in a header. I'll try to make my
patches
>avaialble RSN.

As I said. rw_generic is called for each address. Each time it is passed
the addr array which holds each token of the address. rw_generic performs
several "tidy ups" of the address, by modifing addr. My routine which
rw_generic calls last, modifies the addr array based on table lookup. No
different from the way rw_generic does it.

Mark Powell - Unix Information Officer - Clifford Whitworth Building
A.I.S., University of Salford, Salford, Manchester, UK.
Tel: +44 161 745 5936 Fax: +44 161 736 3596
Email: mark@salford.ac.uk finger mark@ucsalf.ac.uk (for PGP key)
<A HREF="http://www.ucsalf.ac.uk/~mark/">Home Page</A>

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv

iQCVAwUBMy/2j1M87iaKBL59AQGm/AP/UTdM2d00BnzAoP/f3h/OwpjzPKA51o94
2vjwcrUlhtst3vn6Ad4XhBPGtNb0mGicyfyh6w4rYqWqs++B9d2POZuE8TESkaO6
9XCvTRZCSzxvx8IUbThxC6z8VjnuexozyOj68mqm/1zO56pUu0imiZsnUJC77nBC
/MfXfpW/Q1Y=
=iDM1
-----END PGP SIGNATURE-----
Re: Patch for address rewriting. Comments? [ In reply to ]
i took a look at the web site describing the rewrite patch, and i guess
i understand what it does -- but i'm not sure why i'd want what it does.
i've had some small rewriting needs in the past, and i don't think this
would help, but maybe i'm missing something. can you give some examples
of how you're using it, or how you'd expect it to be useful?

paul
---------------------
paul fox, pgf@foxharp.boston.ma.us (arlington, ma)
Re: Patch for address rewriting. Comments? [ In reply to ]
> It works fine for multiple addresses. The rw_generic function is called
> for each 822 address not just once for the To:, From:, etc. lines.
>

I'm afraid you're wrong. The problem is exactly the same one I had. Look at the following test case, tried with your patch, looking at the output of qmail-inject -n:

-------------------- original mail ----------------
Return-Path: <user@a.dom.ain>
Date: 23 Dec 1996 18:04:01 -0000
From: Leonard User <user@a.dom.ain>
To: u1@dom.ain, u2@dom.ain
To: u2@dom.ain
To: u1@dom.ain

end
-------------------- qmail-inject -n output ---------
Return-Path: <user@a.dom.ain>
Message-ID: <19970319174030.7966.qmail@snork.ifisicacu.unam.mx>
Date: 23 Dec 1996 18:04:01 -0000
From: Leonard User <user@a.dom.ain>
To: Number.One@Dom.Ain, Number.One@Dom.Ain
To: Number.Two@Dom.Ain
To: Number.One@Dom.Ain

end
--------------------- cdb input ---------------------
+6,16:user@a->L.User@A.Dom.Ain
+6,16:user@b->L.User@B.Dom.Ain
+10,18:u1@dom.ain->Number.One@Dom.Ain
+10,18:u2@dom.ain->Number.Two@Dom.Ain

The first To:-line is rewritten incorrectly. You get even wierder results if the resulting addresses are of different length... The reason is that the header after rewriting is kept in memory until _all_ addresses in that line (including contiunuation lines) are rewritten. So you have to provide a separate buffer to token822_parse for each address in a header line. You can recycle buffers once you get to the next header line. It took me a while looking at the tokenisation code (and in a debugger) to figure out that one.

Cheers,
Lukas
-------------------------------------------------------------------------------
Dr. Lukas Nellen | Email: lukas@teorica0.ifisicacu.unam.mx
Depto. de Fisica Teorica, IFUNAM |
Apdo. Postal 20-364 | Tel.: +52 5 622 5014 ext. 218
01000 Mexico D.F., MEXICO | Fax: +52 5 622 5015
Re: Patch for address rewriting. Comments? [ In reply to ]
-----BEGIN PGP SIGNED MESSAGE-----

In article <5gou4q$8hp$1@io.salford.ac.uk>,
Paul Fox <pgf@foxharp.boston.ma.us> wrote:
>i took a look at the web site describing the rewrite patch, and i guess
>i understand what it does -- but i'm not sure why i'd want what it does.
>i've had some small rewriting needs in the past, and i don't think this
>would help, but maybe i'm missing something. can you give some examples
>of how you're using it, or how you'd expect it to be useful?

We have lots of users ~25000. We have too many name clashes to allow
email addresses of the form:

A.N.Other@salford.ac.uk

So we use department names in the full email address, creating virtual
hosts. e.g.

A.N.Other@dept1.salford.ac.uk
A.N.Other@dept2.salford.ac.uk

We'd like to configure clients to use this form, but some just won't do
it.
Thus, we need to rewrite whatever the client is using as the address, into
the correct form for the user.


Mark Powell - Unix Information Officer - Clifford Whitworth Building
A.I.S., University of Salford, Salford, Manchester, UK.
Tel: +44 161 745 5936 Fax: +44 161 736 3596
Email: mark@salford.ac.uk finger mark@ucsalf.ac.uk (for PGP key)
<A HREF="http://www.ucsalf.ac.uk/~mark/">Home Page</A>

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv

iQCVAwUBMzEEV1M87iaKBL59AQHi8AQAjDfDaNCgHgI/cfNZUwZZRKOJFlIkeNdS
FUYJ11uUyxMOfJGDio7sOyhBPKx+0YR4G1noTwkRgGgoBzwcMhV3+y2a0Dw605hc
r1HOaxDjY7g/91ZR10IEiPmTxvQm+YI3UZqeFSTgAYXN7oPaGZ8jikPSYFgmuYxR
JbXS00vhZ6Y=
=tQPX
-----END PGP SIGNATURE-----