From smail3-users-request@cs.athabascau.ca Fri Jul  3 03:47:19 1998
Return-Path: <smail3-users-request@cs.athabascau.ca>
Received: by qiclab.scn.rain.com (Smail-3.2.0.91 1997-Jan-14 #1)
	id <m0ys3N8-000cJIC@qiclab.scn.rain.com>; Fri, 3 Jul 1998 03:47:18 -0700 (PDT)
Received: from aurora.cs.athabascau.ca(131.232.10.2)
 via SMTP by qiclab.scn.rain.com, id smtpdAAAa16066; Fri Jul  3 03:47:16 1998
Received: from aupair.cs.athabascau.ca([131.232.10.8]) (17855 bytes) by aurora.cs.athabascau.ca
	via smtpd with P:smtp/R:bind/T:smtp
	(sender: <smail3-users-request@cs.athabascau.ca>) 
	id <m0ys2nX-001IJ1C@aurora.cs.athabascau.ca>
	for <neighorn@qiclab.scn.rain.com>; Fri, 3 Jul 1998 04:10:31 -0600 (MDT)
	(Smail-3.2.0.101 1997-Dec-17 #3 built 1998-Mar-11)
Received: (11846 bytes) by aupair.cs.athabascau.ca
	via sendmail with P:stdio/D:aliasinclude/R:smart_host/T:smtp
	(sender: <smail3-users-request@cs.athabascau.ca>) 
	id <m0ys1Vf-000iYnC@aupair.cs.athabascau.ca>
	for smail3-users-dist@cs.athabascau.ca; Fri, 3 Jul 1998 02:47:59 -0600 (MDT)
	(Smail-3.2.0.101 1997-Dec-17 #1 built 1998-Mar-3)
Resent-Date: Fri, 3 Jul 1998 02:47:59 -0600 (MDT)
Old-Return-Path: <charmer@punchdown.org>
Message-Id: <m0ys1De-000GwTC@fugazi.punchdown.org>
From: charmer@punchdown.org (Craig Harmer)
Subject: Re: non-local aliases
To: marzen@mgi.de (Marzen Holger)
Date: Fri, 3 Jul 1998 01:29:21 -0700 (PDT)
Cc: woods@most.weird.com, smail3-users@cs.athabascau.ca
In-Reply-To: <Pine.LNX.3.96.980703092827.12862A-100000@sally.alz.mgi.de> from "Marzen Holger" at Jul 3, 98 09:35:05 am
X-Mailer: ELM [version 2.4 PL24 PGP3 *ALPHA*]
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Length:      10840
Resent-Message-ID: <"Ltz_9C.A.0lD._qJn1"@aupair.cs.athabascau.ca>
Resent-From: smail3-users@cs.athabascau.ca
X-Mailing-List: <smail3-users@cs.athabascau.ca> archive/latest/2655
X-Loop: smail3-users@cs.athabascau.ca
Precedence: list
Resent-Sender: smail3-users-request@cs.athabascau.ca
Status: OR

> Date: Fri, 3 Jul 1998 09:35:05 +0100 (GMT+0100)
> From: Marzen Holger <marzen@mgi.de>
> X-Sender: hm@sally.alz.mgi.de
> To: "Greg A. Woods" <woods@most.weird.com>
> cc: smail3-users@cs.athabascau.ca
> Subject: Re: non-local aliases

hey,


> On Fri, 3 Jul 1998, Greg A. Woods wrote:
>
> > Date: Fri, 3 Jul 1998 00:18:59 -0400 (EDT)
> > From: "Greg A. Woods" <woods@most.weird.com>
> > Reply-To: "Greg A. Woods" <woods@weird.com>
> > To: smail3-users@cs.athabascau.ca
> > Subject: Re: non-local aliases
> > 
> > [ On Thu, July 2, 1998 at 16:21:36 (-0700), Craig Harmer wrote: ]
> > > Subject: Re: non-local aliases
> > >
> > > i have a fix for this, which i'll submit via a `smailbug' report.
> > 
> > Please do!  ;-)
> > 
> > > meanwhile, looking at the source code for routers/rewrite.c, it suggests
> > > the use of:
> > > 
> > > gemel.com.er            +       ${lookup:user:lsearch{gemel-aliases} \
> > >                                 then {$value} else {$input_addr}}
> > > 
> > > which seems to work fine.  that should be an adequate work around
> > > for both of us ...
...
> > Using "$user@$host" instead of the recommended "$input_addr" is not a
> > good idea in this situation, though I'm not sure I can explain exactly
> > why.   ;-)

> No, it doesn't work correctly.
>
> There is the same bug as with $user@$host: If the user is not in the
> alias-file then smail -bv '<user@this.domain>' returns nothing and mail
> will be bounced:

oh!  you're right!

looking at the code, i guess i understand why that would be the case.
hmmm ... i wonder why this hasn't been hit more often?

> Please gimme tha magic power masta fix :)

i just submitted bug smail/368.  here's the unified diff (wrapped in a
shar archive) of my proposed fix.  you can actually skip the changes
to src/addr.c if you want to; they only affect the DEBUG output it
generates.

i should mention that this patch is for smail 3.2.0.101.

let me know how this works for you.

cheers,

craig.

#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1998-07-03 01:43 PDT by <charmer@ns.punchdown.org>.
# Source directory was `/local/src/cmd/smail'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#   5995 -rw-r--r-- rewrite.fix
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
  if test "$gettext_dir" = FAILED && test -f $dir/gettext \
     && ($dir/gettext --version >/dev/null 2>&1)
  then
    set `$dir/gettext --version 2>&1`
    if test "$3" = GNU
    then
      gettext_dir=$dir
    fi
  fi
  if test "$locale_dir" = FAILED && test -f $dir/shar \
     && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
  then
    locale_dir=`$dir/shar --print-text-domain-dir`
  fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
  echo=echo
else
  TEXTDOMAINDIR=$locale_dir
  export TEXTDOMAINDIR
  TEXTDOMAIN=sharutils
  export TEXTDOMAIN
  echo="$gettext_dir/gettext -s"
fi
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo
  $echo 'WARNING: not restoring timestamps.  Consider getting and'
  $echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 1231235999 $$.touch
#
if mkdir _sh25571; then
  $echo 'x -' 'creating lock directory'
else
  $echo 'failed to create lock directory'
  exit 1
fi
# ============= rewrite.fix ==============
if test -f 'rewrite.fix' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'rewrite.fix' '(file already exists)'
else
  $echo 'x -' extracting 'rewrite.fix' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'rewrite.fix' &&
Index: src/addr.c
===================================================================
RCS file: /local/src/cmd/smail/ARCHIVE/smail/src/addr.c,v
retrieving revision 1.1.1.21
retrieving revision 1.1.1.21.4.1
diff -u -r1.1.1.21 -r1.1.1.21.4.1
--- addr.c	1998/01/16 02:59:14	1.1.1.21
+++ addr.c	1998/07/03 05:45:21	1.1.1.21.4.1
@@ -327,9 +327,12 @@
X 		if (check_target_and_remainder(target, remainder) == FAIL) {
X 		    return FAIL;
X 		}
-		DEBUG2(DBG_ADDR_HI,
-		       "parse_address: RFC_ROUTE: target=%s, remainder=%s\n",
+		DEBUG3(DBG_ADDR_HI,
+		       "parse_address: %s: target=%s, remainder=%s\n",
+		       retval == RFC_ROUTE ? "RFC_ROUTE" : "RFC_ENDROUTE",
X 		       *target, *remainder);
+	    } else {
+		DEBUG(DBG_ADDR_HI, "parse_address: RFC_ROUTE\n");
X 	    }
X 	    return retval;
X 	}
@@ -371,6 +374,8 @@
X 	    DEBUG2(DBG_ADDR_HI,
X 		   "parse_address: MAILBOX: target=%s, remainder=%s\n",
X 		   *target, *remainder);
+	} else {
+	    DEBUG(DBG_ADDR_HI, "parse_address: MAILBOX\n");
X 	}
X 	return MAILBOX;
X     }
@@ -401,6 +406,8 @@
X 	    DEBUG2(DBG_ADDR_HI,
X 		   "parse_address: UUCP_ROUTE: target=%s, remainder=%s\n",
X 		   *target, *remainder);
+	} else {
+	    DEBUG(DBG_ADDR_HI, "parse_address: UUCP_ROUTE\n");
X 	}
X 	return UUCP_ROUTE;
X     }
@@ -423,6 +430,8 @@
X 		DEBUG2(DBG_ADDR_HI,
X 		       "parse_address: DECNET: target=%s, remainder=%s\n",
X 		       *target, *remainder);
+	    } else {
+		DEBUG(DBG_ADDR_HI, "parse_address: DECNET\n");
X 	    }
X 	    return DECNET;
X 	}
@@ -439,6 +448,8 @@
X 	    DEBUG2(DBG_ADDR_HI,
X 		   "parse_address: BERKENET: target=%s, remainder=%s\n",
X 		   *target, *remainder);
+	} else {
+	    DEBUG(DBG_ADDR_HI, "parse_address: BERKENET\n");
X 	}
X 	return BERKENET;
X # endif /* USE_BERKENET */
@@ -465,6 +476,8 @@
X 	    DEBUG2(DBG_ADDR_HI,
X 		   "parse_address: PCT_MAILBOX: target=%s, remainder=%s\n",
X 		   *target, *remainder);
+	} else {
+	    DEBUG(DBG_ADDR_HI, "parse_address: PCT_MAILBOX\n");
X 	}
X 	return PCT_MAILBOX;
X     }
@@ -485,6 +498,8 @@
X 	DEBUG2(DBG_ADDR_HI, "parse_address: LOCAL: target=%s, remainder=%s\n",
X 	       *target ? *target : "(no-domain)", *remainder);
X #endif
+    } else {
+	DEBUG(DBG_ADDR_HI, "parse_address: LOCAL\n");
X     }
X     return LOCAL;
X }
Index: src/routers/rewrite.c
===================================================================
RCS file: /local/src/cmd/smail/ARCHIVE/smail/src/routers/rewrite.c,v
retrieving revision 1.1.1.19
retrieving revision 1.1.1.19.4.1
diff -u -r1.1.1.19 -r1.1.1.19.4.1
--- rewrite.c	1998/01/16 02:59:29	1.1.1.19
+++ rewrite.c	1998/07/03 05:46:26	1.1.1.19.4.1
@@ -397,6 +397,8 @@
X     int form;		/* form of remainder */
X     char *error;	/* error from some lower-level functions */
X     char *new_address;	/* rewritten address */
+    char *new_target;	/* target of rewritten address */
+    char *new_remainder; /* remainder of rewritten address */
X 
X     /* is the target in the database? */
X     result = find_domain(rp, addr, &raw_data, &match, error_p);
@@ -445,7 +447,13 @@
X 		}
X     default:	*error_p = bad_entry(rp, raw_data);
X 		return DB_AGAIN;
-    };
+    }
+
+    /*
+     * raw_data points to a static area which is overwritten by calls
+     * to other lookup routines.  preserve it for error messages.
+     */
+    format = COPY_STRING(format);
X 
X     /* is the remainder a simple user name? */
X     form = parse_address(addr->remainder, (char **)0, &error, (int *)0);
@@ -463,18 +471,20 @@
X 		temp_addr.next_addr = addr->remainder;	/* for ${user} */
X 		temp_addr.next_host = addr->target;	/* for ${host} */
X 
-		new_address = expand_string(format,
-					    &temp_addr, (char *)NULL, addr->remainder);
+		new_address = expand_string(COPY_STRING(format),
+					    &temp_addr, (char *)NULL,
+					    addr->remainder);
X 	    }
X 	    if (new_address == NULL) {
-		*error_p = expand_error(rp, format);
+		*error_p = expand_error(rp, format, NULL);
X 		return DB_AGAIN;
X 	    }
X 
-	    /* preparse to strip comments etc. */
+	    /* preparse to canonicalize, strip comments, etc. */
X 	    p = preparse_address(new_address, &error);
X 	    if (p == NULL) {
-		*error_p = expand_error(rp, format);
+		*error_p = expand_error(rp, format,
+				      xprintf("%s \"%s\"", error, new_address));
X 		return DB_AGAIN;
X 	    }
X 	    new_address = p;
@@ -484,13 +494,27 @@
X 	    /* rewrite otherstuff@target to just otherstuff */
X 	    new_address = COPY_STRING(addr->remainder);
X 	    break;
+
X     }
X 
X     /* is rewritten address the same as before rewriting? */
-    if (EQIC(new_address, addr->in_addr)) {
-	DEBUG2(DBG_DRIVER_HI, "rewrite_lookup: not rewriting %s --> %s\n",
+
+    if (parse_address(COPY_STRING(new_address),
+		      &new_target, &new_remainder, (int *)0) == FAIL) {
+	/*
+	 * don't return DB_AGAIN; the fault is probably in the
+	 * original address and will be handled elsewhere.
+	 */
+	DEBUG2(DBG_DRIVER_LO,
+	       "rewrite_lookup: rewritten address %s --> %s not parsable\n",
X 	       addr->in_addr, new_address);
-	return DB_NOMATCH;
+    } else {
+	if (EQIC(new_target, addr->target)
+	    && EQIC(new_remainder, addr->remainder)) {
+	    DEBUG2(DBG_DRIVER_HI, "rewrite_lookup: not rewriting %s --> %s\n",
+		   addr->in_addr, new_address);
+	    return DB_NOMATCH;
+	}
X     }
X 
X     /*
@@ -865,9 +889,10 @@
X }
X 
X static struct error *
-expand_error(rp, format)
+expand_error(rp, format, infop)
X     struct router *rp;
X     char *format;
+    char *infop;
X {
X     char *error_text;
X 
@@ -885,8 +910,13 @@
X      *      The postmaster should fix the entry in the
X      *	    rewrite database.
X      */
-    error_text = xprintf("router %s: expansion of \"%s\" failed",
-			 rp->name, format);
+    if (!infop) {
+	error_text = xprintf("router %s: expansion of \"%s\" failed",
+			     rp->name, format);
+    } else {
+	error_text = xprintf("router %s: expansion of \"%s\" failed: %s",
+			     rp->name, format, infop);
+    }
X     DEBUG1(DBG_DRIVER_LO, "%s\n", error_text);
X     return note_error(ERR_CONFERR|ERR_1204, error_text);
X }
SHAR_EOF
  $shar_touch -am 0702230398 'rewrite.fix' &&
  chmod 0644 'rewrite.fix' ||
  $echo 'restore of' 'rewrite.fix' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'rewrite.fix:' 'MD5 check failed'
65e28fdd244493e3a199b6b5f234c869  rewrite.fix
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'rewrite.fix'`"
    test 5995 -eq "$shar_count" ||
    $echo 'rewrite.fix:' 'original size' '5995,' 'current size' "$shar_count!"
  fi
fi
rm -fr _sh25571
exit 0
-- 
craig harmer			               PGP public key available:
charmer@punchdown.org                          finger charmer@ns.punchdown.org
(415) 668-3564 (h)

