alias.c

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 786 行 · 第 1/2 页

C
786
字号
#ifndef lintstatic	char	*sccsid = "@(#)alias.c	4.1	(ULTRIX)	7/2/90";#endif lint/************************************************************************ *									* *			Copyright (c) 1987 by				* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any  other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived  from  software  received  from  the	* *   University    of   California,   Berkeley,   and   from   Bell	* *   Laboratories.  Use, duplication, or disclosure is  subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or  reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************/# include <pwd.h># include <sys/types.h># include <sys/stat.h># include <signal.h># include <errno.h># include "sendmail.h"# ifdef FLOCK# include <sys/file.h># endif FLOCK#include <sys/svcinfo.h>#include <hesiod.h># ifndef DBM# ifndef lintstatic char	SccsId[] = "@(#)alias.c @(#)alias.c	1.2 (ULTRIX) 7/20/87 (no DBM)";# endif not lint# else DBM# ifndef lintstatic char	SccsId[] = "@(#)alias.c @(#)alias.c	1.2 (ULTRIX) 7/20/87 (with DBM)";# endif not lint# endif not DBM/***  ALIAS -- Compute aliases.****	Scans the alias file for an alias for the given address.**	If found, it arranges to deliver to the alias list instead.**	Uses libdbm database if -DDBM.****	Parameters:**		a -- address to alias.**		sendq -- a pointer to the head of the send queue**			to put the aliases in.****	Returns:**		none****	Side Effects:**		Aliases found are expanded.****	Notes:**		If NoAlias (the "-n" flag) is set, no aliasing is**			done.****	Deficiencies:**		It should complain about names that are aliased to**			nothing.*/#ifdef DBMtypedef struct{	char	*dptr;	int	dsize;} DATUM;extern DATUM fetch();#endif DBMalias(a, sendq)	register ADDRESS *a;	ADDRESS **sendq;{	register char *p;	extern char *aliaslookup();# ifdef DEBUG	if (tTd(27, 1))		printf("alias(%s)\n", a->q_paddr);# endif	/* don't realias already aliased names */	if (bitset(QDONTSEND, a->q_flags))		return;	CurEnv->e_to = a->q_paddr;	/*	**  Look up this name	*/	if (NoAlias)		p = NULL;	else		p = aliaslookup(a->q_user);	if (p == NULL)		return;	/*	**  Match on Alias.	**	Deliver to the target list.	*/# ifdef DEBUG	if (tTd(27, 1))		printf("%s (%s, %s) aliased to %s\n",		    a->q_paddr, a->q_host, a->q_user, p);# endif	message(Arpa_Info, "aliased to %s", p);	AliasLevel++;	sendtolist(p, a, sendq);	AliasLevel--;}/***  ALIASLOOKUP -- look up a name in the alias file.****	Parameters:**		name -- the name to look up.****	Returns:**		the value of name.**		NULL if unknown.****	Side Effects:**		none.****	Warnings:**		The return value will be trashed across calls.*/char * aliaslookup_local();char * aliaslookup_yp();char * aliaslookup_bind();char * (*aliaslookups []) ()={		aliaslookup_local,		aliaslookup_yp,		aliaslookup_bind};/* * generic alias service routines */char *aliaslookup (name)	register char *name;{	register char *p=NULL;	register i;	struct svcinfo *svcinfo;	if ((svcinfo = getsvc()) != NULL)		for (i=0; (svc_lastlookup = svcinfo->svcpath[SVC_ALIASES][i]) != SVC_LAST; i++)			if (p = ((*(aliaslookups [svcinfo->svcpath[SVC_ALIASES][i]])) (name) ))				break;	return (p);}/* * specific alias service routines */char *aliaslookup_local(name)	char *name;{# ifdef DBM	DATUM rhs, lhs;#ifdef DEBUG	printf("aliaslookup_local(%s)\n", name);#endif DEBUG	/*	 * Create a key for fetch	 */	lhs.dptr = name;	lhs.dsize = strlen(name) + 1;	rhs = fetch(lhs);	if (rhs.dptr == NULL)		return(NULL);	return (rhs.dptr);# else DBM	register STAB *s;#ifdef DEBUG	printf("aliaslookup_local(%s)\n", name);#endif DEBUG	s = stab(name, ST_ALIAS, ST_FIND);	if (s == NULL)		return(NULL);	return (s->s_alias);# endif DBM}char *aliaslookup_bind(name)	char *name;{	char **pp;	#ifdef DEBUG	printf("aliaslookup_bind(%s)\n", name);#endif DEBUG	setent_bind(0);	pp = hes_resolve(name, "aliases");	endent_bind();	if (pp == NULL)		return(NULL);	return(*pp);}char *aliaslookup_yp(name)	char *name;{# ifdef DBM	DATUM rhs;	int err = 0;	if (!YPdomain)		return(NULL);# ifdef DEBUG	printf("aliaslookup_yp(%s)\n", name);	/* Note: The only time you can see the following message	 *	 is via a  "telnet host 25"   command   AND  the	 *	 DEBUG code has been compiled in.	 *	 mail -v user  would show on terminal IF we wanted	 *	 to put in a  "message(Arpa_Info...)"  statement..	 */	if (tTd(27, 1))		printf("cking YP mail.aliases map for  %s\n",name);# endif DEBUG	err = yp_match(YPdomain,"mail.aliases",name,strlen(name),&rhs.dptr,&rhs.dsize);	if (err == YPERR_KEY) {		err = yp_match(YPdomain,"mail.aliases",name,strlen(name) + 1 ,&rhs.dptr,&rhs.dsize);		if (err) {			/* Assume end of alias chain.			 */			return(NULL);		}	}# ifdef DEBUG	if (tTd(27, 1))		printf("YP map aliases %s to %s\n",name,rhs.dptr);# endif DEBUG	/* The end of an alias from YP comes back with a	 * newline. This disrupts the syslog entries and	 * the qfAAnnnnnn entries for recipients. Therefore,	 * squash them off.	 */	if (rhs.dptr[rhs.dsize] == '\n')		rhs.dptr[rhs.dsize--] = NULL;		/*	 * rhs.dptr will be null if the object is not found	 * in the YP map. Therefore, no need to ck "err".	 */	return (rhs.dptr);# else DBM	register STAB *s;	if (!YPdomain)		return(NULL);	else {		err = yp_match(YPdomain,"mail.aliases",name,strlen(name),&s->s_alias,&size);		if (err == YPERR_KEY) {			err = yp_match(YPdomain,"mail.aliases",name,strlen(name) + 1 ,&s->s_alias,&size);			if (err) {				/* Assume end of alias chain.				 */				return(NULL);			}		}	}	return (s->s_alias);# endif DBM}/***  INITALIASES -- initialize for aliasing****	Very different depending on whether we are running DBM or not.****	Parameters:**		aliasfile -- location of aliases.**		init -- if set and if DBM, initialize the DBM files.****	Returns:**		none.****	Side Effects:**		initializes aliases:**		if DBM:  opens the database.**		if ~DBM: reads the aliases into the symbol table.*/# define DBMMODE	0666initaliases(aliasfile, init)	char *aliasfile;	bool init;{#ifdef DBM	int atcnt;	time_t modtime;	bool automatic = FALSE;	char buf[MAXNAME];#endif DBM	struct stat stb;	static bool initialized = FALSE;	if (initialized)		return;	initialized = TRUE;	if (aliasfile == NULL || stat(aliasfile, &stb) < 0)	{		if (aliasfile != NULL && init)			syserr("Cannot open %s", aliasfile);		NoAlias = TRUE;		errno = 0;		return;	}# ifdef DBM	/*	**  Check to see that the alias file is complete.	**	If not, we will assume that someone died, and it is up	**	to us to rebuild it.	*/	if (!init)		dbminit(aliasfile);	atcnt = SafeAlias * 2;	if (atcnt > 0)	{		while (!init && atcnt-- >= 0 && aliaslookup("@") == NULL)		{			/*			**  Reinitialize alias file in case the new			**  one is mv'ed in instead of cp'ed in.			**			**	Only works with new DBM -- old one will			**	just consume file descriptors forever.			**	If you have a dbmclose() it can be			**	added before the sleep(30).			*/			sleep(30);# ifdef NDBM			dbminit(aliasfile);# endif NDBM		}	}	else		atcnt = 1;	/*	**  See if the DBM version of the file is out of date with	**  the text version.  If so, go into 'init' mode automatically.	**	This only happens if our effective userid owns the DBM	**	version or if the mode of the database is 666 -- this	**	is an attempt to avoid protection problems.  Note the	**	unpalatable hack to see if the stat succeeded.	*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?