[comp.mail.sendmail] LHS map lookup. Missing feature in IDA sendmail?

sjg@melb.bull.oz.au (Simon J. Gerraty) (06/03/91)

In the process of building/testing sendmail-5.65+IDA, I seem to
have come accross a need for a new feature.

The $(x key $@ arg $: default $) feature is _just_ what I have
always wanted on the RHS of a re-write rule.

However I am used to having Sun's $%x and $!x features for
checking a key in a map in the LHS of the rules.

Ie.  I want to be able to have a rule match iff a key is present
in a map, or iff a key is NOT present in a map.  Then I'd like
to be able to make use of the lookup feature.

This seems such a fundamental requirement - that obviously I'm
not thinking right.  Could some one please:
1/ mail me an example of how the current IDA features can be
   used to replace something like:

R$*<@$%Y>$*	$#ether $@$2 $:$1<@$2>$3	user@etherhost

2/ let me know whether someone else has already done this.
   
3/ set me straight :-)

Its been a busy few weeks, so please flame > /dev/null if I'm
obviously not thinking properly :-)

Thanks!

-- 
Simon J. Gerraty        <sjg@sun0.melb.bull.oz.au>      (work)
                        <sjg@zen.void.oz.au>            (home)

#include <disclaimer>   /* imagine something *very* witty here */

sjg@melb.bull.oz.au (Simon J Gerraty) (06/04/91)

In <1991Jun3.090222.13897@melb.bull.oz.au> sjg@melb.bull.oz.au (Simon J. Gerraty) writes:
>In the process of building/testing sendmail-5.65+IDA, I seem to
>have come accross a need for a new feature.

>The $(x key $@ arg $: default $) feature is _just_ what I have
>always wanted on the RHS of a re-write rule.

>However I am used to having Sun's $%x and $!x features for
>checking a key in a map in the LHS of the rules.

Well the more I thought about it the more it seemed like a
GoodThing[TM].  We have several hosts on our network that use
only YP to lookup hosts.  This reduces the load on our name
servers. 

The following diffs represent my first pass at this lot.
The aim was to painlessly drop sendmail-5.65+ into our net in
place of Sun's sendmail (and Bull's) on our various systems.
There are basically two changes.
1/ Implement $%x and $!x on LHS
   Unfortunately $!x is used on the RHS by the QUOTE822
   facility.  Since one only appears on LHS and the other only
   on RHS they don't actually conflict, but it is unfortunate.
   I don't actually use $!x on the LHS, so I have arranged to
   add $%x without $!x.

   For those unfamiliar but curious a LHS pattern like:

   R$*<@$%Y>$*	

   Matches if the tokens within `<>' can be found as a key in
   the DBM map Y.  If the map is declared with OKY%map vs
   OKYmap, then Yellow Pages (NIS) is used.

2/ Recognize [TCP] as well as [IPC] for the name of the smtp
   mailer.

If you find any bugs in this I am sorry and would appreciate
hearing about it.

*** ChangeLog.old	Tue Jun  4 14:54:50 1991
--- ChangeLog	Tue Jun  4 14:53:14 1991
***************
*** 0 ****
--- 1,17 ----
+ Tue Jun  4 14:41:24 1991  Simon J. Gerraty  (sjg at sun0)
+ 
+ 	* sendmail.h,main.c,parseaddr.c:
+ 	Added new LHS meta-macro's MATCHMAP and MATCHNMAP.
+ 	These are used to implement $%x and $!x compatible with Sun's YP
+ 	lookup stuff.  This allows Sun sendmail.cf's to be used with only
+ 	the declaration of YP maps changed to OKY%hosts.byname for
+ 	example.
+ 	NOTE: MATCHNMAP ($!x) conflicts with QUOTE822 ($!x) (I think).
+ 	In anycase it is not (yet) needed, and has not been tested!
+ 	MATCHMAP ($%x) appears to work fine and is all that is needed for
+ 	compatibility. 
+ 
+ 	* deliver.c:
+ 	Recognize [TCP] as well as [IPC] as mailer name for smtp mailer.
+ 
+ 
*** sendmail.h.old	Tue Jun  4 15:06:39 1991
--- sendmail.h	Tue Jun  4 14:57:25 1991
***************
*** 338,343 ****
--- 338,361 ----
  # define MATCHCLASS	'\023'	/* match one token in a class */
  # define MATCHNCLASS	'\024'	/* match anything not in class */
  # define MATCHREPL	'\025'	/* replacement on RHS for above */
+ #ifdef DBM
+ /*
+  * 91-06-04 <sjg@melb.bull.oz.au>
+  * These are to add $%x and $!x on LHS
+  * to be more compatible with Sun's sendmail.cf's
+  * The lhs pattern matches if the token is/is_not in the dbm map.
+  * NOTE that `!' use here for MATCHNMAP conflicts with
+  * its use for QUOTE822, though MATCHNMAP only appears on LHS
+  * and QUOTE822 on the RHS.
+  * At this stage I don't use MATCHNMAP anyway :-)
+  * MATCHMAP works as expected, but the token's may need their values
+  * changed...
+  */
+ # define MATCHMAP	'\013'	/* found in dbm/map */
+ # ifdef USE_MATCHNMAP
+ #   define MATCHNMAP	'\014'	/* not found in dbm/map */
+ # endif
+ #endif /* DBM */
  
  /* right hand side items */
  # define CANONNET	'\026'	/* canonical net, next token */
*** main.c.old	Tue Jun  4 15:06:42 1991
--- main.c	Tue Jun  4 14:57:22 1991
***************
*** 871,877 ****
  	/* LHS pattern matching characters */
  	'*', MATCHZANY,	'+', MATCHANY,	'-', MATCHONE,	'=', MATCHCLASS,
  	'~', MATCHNCLASS,
! 
  	/* these are RHS metasymbols */
  	'#', CANONNET,	'@', CANONHOST,	':', CANONUSER,	'>', CALLSUBR,
  
--- 871,889 ----
  	/* LHS pattern matching characters */
  	'*', MATCHZANY,	'+', MATCHANY,	'-', MATCHONE,	'=', MATCHCLASS,
  	'~', MATCHNCLASS,
! #ifdef DBM
! 	/*
! 	 * 91-06-04 <sjg@melb.bull.oz.au>
! 	 * These are to add $%x and $!x on lhs
! 	 * see sendmail.h
! 	 */
! # ifdef MATCHMAP
! 	'%', MATCHMAP, 
! # endif
! # ifdef MATCHNMAP
! 	'!', MATCHNMAP,		/* conflicts with QUOTE822 `!' */
! # endif
! #endif /* DBM */
  	/* these are RHS metasymbols */
  	'#', CANONNET,	'@', CANONHOST,	':', CANONUSER,	'>', CALLSUBR,
  
*** parseaddr.c.old	Tue Jun  4 15:06:44 1991
--- parseaddr.c	Tue Jun  4 14:57:24 1991
***************
*** 443,449 ****
  		expand("\001o", buf, &buf[sizeof buf - 1], CurEnv);
  		(void) strcat(buf, DELIMCHARS);
  	}
! 	if (c == MATCHCLASS || c == MATCHREPL || c == MATCHNCLASS)
  		return (ONE);
  #ifdef MACVALUE
  	if (c == MACVALUE)
--- 443,456 ----
  		expand("\001o", buf, &buf[sizeof buf - 1], CurEnv);
  		(void) strcat(buf, DELIMCHARS);
  	}
! 	if (c == MATCHCLASS || c == MATCHREPL ||
! #ifdef MATCHMAP
! 	    c == MATCHMAP || 
! #endif
! #ifdef MATCHNMAP
! 	    c == MATCHNMAP || 
! #endif
! 	    c == MATCHNCLASS)
  		return (ONE);
  #ifdef MACVALUE
  	if (c == MACVALUE)
***************
*** 623,629 ****
--- 630,675 ----
  				mlp->last = avp-1;
  				mlp++;
  				break;
+ #ifdef MATCHMAP
+ 				/*
+ 				 * 91-06-04 <sjg@melb.bull.oz.au>
+ 				 * These are to add $%x and $!x on lhs
+ 				 * see sendmail.h
+ 				 */
+ 			  case MATCHMAP:
+ 				/* match any token in a DBM map */
+ 				/* handles multi-token class matches */
+ 				oldavp = avp;
+ 				*tokbuf = NULL;
+ 				do {
+ 					if (*avp == NULL) {
+ 						avp = oldavp;
+ 					goto backup;
+ 					}
+ 					strcat(tokbuf, *avp++);
+ 				} while (mapkey(rp[1], tokbuf,
+ 						sizeof(tokbuf) - 1, NULL)
+ 					 == NULL);
+ 				mlp->first = oldavp;
+ 				mlp->last = avp-1;
+ 				mlp++;
+ 				break;
  
+ #endif	/* MATCHMAP */
+ #ifdef MATCHNMAP
+ 			  case MATCHNMAP:
+ 				/* match any token not in a DBM map */
+ 				if ((rp = mapkey(rp[1], ap, 0, NULL)) != NULL)
+ 				{
+ 				  free(rp);
+ 				  goto backup;
+ 				}
+ 				/* match exactly one token */
+ 				mlp->first = avp;
+ 				mlp->last = avp++;
+ 				mlp++;
+ 				break;
+ #endif /* MATCHNMAP */
  			  case MATCHONE:
  			  case MATCHANY:
  				/* match exactly one token */
*** deliver.c.old	Tue Jun  4 15:06:48 1991
--- deliver.c	Tue Jun  4 14:39:25 1991
***************
*** 835,841 ****
  		return (0);
  	}
  
! 	if (strcmp(m->m_mailer, "[IPC]") == 0)
  	{
  #ifdef HOSTINFO
  		register STAB *st;
--- 835,847 ----
  		return (0);
  	}
  
! 	/*
! 	 * 91-06-04 <sjg@melb.bull.oz.au>
! 	 * To make this sendmail compatible with our old .cf
! 	 * files, we must recognize [TCP] as mailer name.
! 	 */
! 	if (strcmp(m->m_mailer, "[IPC]") == 0 ||
! 	    strcmp(m->m_mailer, "[TCP]") == 0) 
  	{
  #ifdef HOSTINFO
  		register STAB *st;

-- 
Simon J. Gerraty		<sjg@melb.bull.oz.au>

#include <disclaimer,_witty_comment>