[comp.mail.sendmail] sendmail computes alias sizes incorrectly

paul@uxc.cso.uiuc.edu (Paul Pomes - UofIllinois CSO) (08/03/90)

DBM requires that the sum of the sizes of a key/content pair must not exceed
the internal block size (1024 or 4096 depending on dbm version).  Sendmail,
however, reports only the size of the longest RHS (content) when re-building
the alias file.  This can lead to the situation where the reported alias
size is OK, if close to the edge, but is really too long when the size of
the alias name is added in.

The following patch to alias.c (V5.64+IDA, your numbers may vary) reports
the corrected size plus the name of the longest alias.  In addition, the
success of the dbm_store()/store() call is checked and a error message is
printed if it fails.

/pbp

======
*** /tmp/,RCSt1014207	Thu Aug  2 14:37:01 1990
--- alias.c	Thu Aug  2 14:36:50 1990
***************
*** 328,333 ****
--- 328,334 ----
  	ADDRESS al, bl;
  	register STAB *s;
  	char line[BUFSIZ];
+ 	char longest_lhs[BUFSIZ];
  
  # ifdef YPMARK
  	if (AliasFile[0] == YPMARK) {
***************
*** 532,542 ****
  			key.dptr = al.q_user;
  			content.dsize = rhssize;
  			content.dptr = rhs;
  # if defined(NDBM) || defined(SDBM)
! 			(void) dbm_store(AliasDbm, key, content, DBM_REPLACE);
  # else /* !NDBM && !SDBM */
! 			store(key, content);
  # endif /* NDBM || SDBM */
  		}
  		else
  # endif /* DBM */
--- 533,546 ----
  			key.dptr = al.q_user;
  			content.dsize = rhssize;
  			content.dptr = rhs;
+ 			if (
  # if defined(NDBM) || defined(SDBM)
! 			    dbm_store(AliasDbm, key, content, DBM_REPLACE)
  # else /* !NDBM && !SDBM */
! 			    store(key, content)
  # endif /* NDBM || SDBM */
+ 			    < 0)
+ 				syserr("DBM store of %s (size %d) failed", al.q_user, (lhssize+rhssize));
  		}
  		else
  # endif /* DBM */
***************
*** 548,555 ****
  		/* statistics */
  		naliases++;
  		bytes += lhssize + rhssize;
! 		if (rhssize > longest)
! 			longest = rhssize;
  	}
  
  # ifdef DBM
--- 552,561 ----
  		/* statistics */
  		naliases++;
  		bytes += lhssize + rhssize;
! 		if ((rhssize + lhssize) > longest) {
! 			longest = rhssize + lhssize;
! 			(void) strcpy(longest_lhs, al.q_user);
! 		}
  	}
  
  # ifdef DBM
***************
*** 601,612 ****
  	(void) fclose(af);
  	CurEnv->e_to = NULL;
  	FileName = NULL;
! 	message(Arpa_Info, "%d aliases, longest %d bytes, %d bytes total",
! 			naliases, longest, bytes);
  # ifdef LOG
  	if (LogLevel >= 8)
! 		syslog(LOG_INFO, "%d aliases, longest %d bytes, %d bytes total",
! 			naliases, longest, bytes);
  # endif /* LOG */
  }
  /*
--- 607,618 ----
  	(void) fclose(af);
  	CurEnv->e_to = NULL;
  	FileName = NULL;
! 	message(Arpa_Info, "%d aliases, longest (%s) %d bytes, %d bytes total",
! 			naliases, longest_lhs, longest, bytes);
  # ifdef LOG
  	if (LogLevel >= 8)
! 		syslog(LOG_INFO, "%d aliases, longest (%s) %d bytes, %d bytes total",
! 			naliases, longest_lhs, longest, bytes);
  # endif /* LOG */
  }
  /*
--
         Paul Pomes

UUCP: {att,iuvax,uunet}!uiucuxc!paul   Internet, BITNET: paul@uxc.cso.uiuc.edu
US Mail:  UofIllinois, CSO, 1304 W Springfield Ave, Urbana, IL  61801-2987