190792Sgshapiro/*
2261194Sgshapiro * Copyright (c) 2000-2002 Proofpoint, Inc. and its suppliers.
390792Sgshapiro *	All rights reserved.
490792Sgshapiro *
590792Sgshapiro * By using this file, you agree to the terms and conditions set
690792Sgshapiro * forth in the LICENSE file which can be found at the top level of
790792Sgshapiro * the sendmail distribution.
890792Sgshapiro *
990792Sgshapiro */
1090792Sgshapiro
1190792Sgshapiro#include <sendmail.h>
12266527SgshapiroSM_RCSID("@(#)$Id: cf.c,v 8.20 2013-11-22 20:51:50 ca Exp $")
1390792Sgshapiro#include <sendmail/pathnames.h>
1490792Sgshapiro
1590792Sgshapiro/*
1690792Sgshapiro**  GETCFNAME -- return the name of the .cf file to use.
1790792Sgshapiro**
1890792Sgshapiro**	Some systems (e.g., NeXT) determine this dynamically.
1990792Sgshapiro**
2090792Sgshapiro**	For others: returns submit.cf or sendmail.cf depending
2190792Sgshapiro**		on the modes.
2290792Sgshapiro**
2390792Sgshapiro**	Parameters:
2490792Sgshapiro**		opmode -- operation mode.
2590792Sgshapiro**		submitmode -- submit mode.
2690792Sgshapiro**		cftype -- may request a certain cf file.
2790792Sgshapiro**		conffile -- if set, return it.
2890792Sgshapiro**
2990792Sgshapiro**	Returns:
3090792Sgshapiro**		name of .cf file.
3190792Sgshapiro*/
3290792Sgshapiro
3390792Sgshapirochar *
3490792Sgshapirogetcfname(opmode, submitmode, cftype, conffile)
3590792Sgshapiro	int opmode;
3690792Sgshapiro	int submitmode;
3790792Sgshapiro	int cftype;
3890792Sgshapiro	char *conffile;
3990792Sgshapiro{
40110560Sgshapiro#if NETINFO
41110560Sgshapiro	char *cflocation;
42363466Sgshapiro#endif
4390792Sgshapiro
4490792Sgshapiro	if (conffile != NULL)
4590792Sgshapiro		return conffile;
4690792Sgshapiro
4790792Sgshapiro	if (cftype == SM_GET_SUBMIT_CF ||
4890792Sgshapiro	    ((submitmode != SUBMIT_UNKNOWN ||
4990792Sgshapiro	      opmode == MD_DELIVER ||
5090792Sgshapiro	      opmode == MD_ARPAFTP ||
5190792Sgshapiro	      opmode == MD_SMTP) &&
5290792Sgshapiro	     cftype != SM_GET_SENDMAIL_CF))
5390792Sgshapiro	{
5490792Sgshapiro		struct stat sbuf;
5598121Sgshapiro		static char cf[MAXPATHLEN];
5690792Sgshapiro
57110560Sgshapiro#if NETINFO
58110560Sgshapiro		cflocation = ni_propval("/locations", NULL, "sendmail",
59110560Sgshapiro					"submit.cf", '\0');
60110560Sgshapiro		if (cflocation != NULL)
61110560Sgshapiro			(void) sm_strlcpy(cf, cflocation, sizeof cf);
62110560Sgshapiro		else
63110560Sgshapiro#endif /* NETINFO */
64110560Sgshapiro			(void) sm_strlcpyn(cf, sizeof cf, 2, _DIR_SENDMAILCF,
65110560Sgshapiro					   "submit.cf");
6690792Sgshapiro		if (cftype == SM_GET_SUBMIT_CF || stat(cf, &sbuf) == 0)
6790792Sgshapiro			return cf;
6890792Sgshapiro	}
69110560Sgshapiro#if NETINFO
70110560Sgshapiro	cflocation = ni_propval("/locations", NULL, "sendmail",
71110560Sgshapiro				"sendmail.cf", '\0');
72110560Sgshapiro	if (cflocation != NULL)
73110560Sgshapiro		return cflocation;
74363466Sgshapiro#endif
7590792Sgshapiro	return _PATH_SENDMAILCF;
7690792Sgshapiro}
77