**  If local delivery, just return a constant.
**  If local delivery (and not remote), just return a constant.
hostsignature(m, host)	register MAILER *m;	char *host;{	register char *p;	register STAB *s;#if NAMED_BIND	char sep = ':';	char prevsep = ':';	int i;	int len;	int nmx;	int hl;	time_t now;	char *hp;	char *endp;	int oldoptions = _res.options;	char *mxhosts[MAXMXHOSTS + 1];	u_short mxprefs[MAXMXHOSTS + 1];#endif /* NAMED_BIND */	if (tTd(17, 3))		dprintf("hostsignature(%s)\n", host);	/*	**  If local delivery, just return a constant.	*/	if (bitnset(M_LOCALMAILER, m->m_flags))		return "localhost";	/*	**  Check to see if this uses IPC -- if not, it can't have MX records.	*/	p = m->m_mailer;	if (strcmp(p, "[IPC]") != 0 &&	    strcmp(p, "[TCP]") != 0)	{		/* just an ordinary mailer */		return host;	}#if NETUNIX	else if (m->m_argv[0] != NULL &&		 strcmp(m->m_argv[0], "FILE") == 0)	{		/* rendezvous in the file system, no MX records */		return host;	}#endif /* NETUNIX */	/*	**  Look it up in the symbol table.	*/	s = stab(host, ST_HOSTSIG, ST_ENTER);	if (s->s_hostsig != NULL)	{		if (tTd(17, 3))			dprintf("hostsignature(): stab(%s) found %s\n", host,				s->s_hostsig);		return s->s_hostsig;	}	/*	**  Not already there -- create a signature.	*/#if NAMED_BIND	if (ConfigLevel < 2)		_res.options &= ~(RES_DEFNAMES | RES_DNSRCH);	/* XXX */	now = curtime();	for (hp = host; hp != NULL; hp = endp)	{#if NETINET6		if (*hp == '[')		{			endp = strchr(hp + 1, ']');			if (endp != NULL)				endp = strpbrk(endp + 1, ":,");		}		else			endp = strpbrk(hp, ":,");#else /* NETINET6 */		endp = strpbrk(hp, ":,");#endif /* NETINET6 */		if (endp != NULL)		{			sep = *endp;			*endp = '\0';		}		if (bitnset(M_NOMX, m->m_flags))		{			/* skip MX lookups */			nmx = 1;			mxhosts[0] = hp;		}		else		{			auto int rcode;			nmx = getmxrr(hp, mxhosts, mxprefs, TRUE, &rcode);			if (nmx <= 0)			{				register MCI *mci;				/* update the connection info for this host */				mci = mci_get(hp, m);				mci->mci_errno = errno;				mci->mci_herrno = h_errno;				mci->mci_lastuse = now;				if (rcode == EX_NOHOST)					mci_setstat(mci, rcode, "5.1.2",						"550 Host unknown");				else					mci_setstat(mci, rcode, NULL, NULL);				/* use the original host name as signature */				nmx = 1;				mxhosts[0] = hp;			}			if (tTd(17, 3))				dprintf("hostsignature(): getmxrr() returned %d, mxhosts[0]=%s\n",					nmx, mxhosts[0]);		}		len = 0;		for (i = 0; i < nmx; i++)			len += strlen(mxhosts[i]) + 1;		if (s->s_hostsig != NULL)			len += strlen(s->s_hostsig) + 1;		if (len >= MAXHOSTSIGNATURE)		{			sm_syslog(LOG_WARNING, NOQID, "hostsignature for host '%s' exceeds maxlen (%d): %d",				  host, MAXHOSTSIGNATURE, len);			len = MAXHOSTSIGNATURE;		}		p = xalloc(len);		if (s->s_hostsig != NULL)		{			(void) strlcpy(p, s->s_hostsig, len);			free(s->s_hostsig);			s->s_hostsig = p;			hl = strlen(p);			p += hl;			*p++ = prevsep;			len -= hl + 1;		}		else			s->s_hostsig = p;		for (i = 0; i < nmx; i++)		{			hl = strlen(mxhosts[i]);			if (len - 1 < hl || len <= 1)			{				/* force to drop out of outer loop */				len = -1;				break;			}			if (i != 0)			{				if (mxprefs[i] == mxprefs[i - 1])					*p++ = ',';				else					*p++ = ':';				len--;			}			(void) strlcpy(p, mxhosts[i], len);			p += hl;			len -= hl;		}		/*		**  break out of loop if len exceeded MAXHOSTSIGNATURE		**  because we won't have more space for further hosts		**  anyway (separated by : in the .cf file).		*/		if (len < 0)			break;		if (endp != NULL)			*endp++ = sep;		prevsep = sep;	}	makelower(s->s_hostsig);	if (ConfigLevel < 2)		_res.options = oldoptions;#else /* NAMED_BIND */	/* not using BIND -- the signature is just the host name */	s->s_hostsig = host;#endif /* NAMED_BIND */	if (tTd(17, 1))		dprintf("hostsignature(%s) = %s\n", host, s->s_hostsig);	return s->s_hostsig;}