xref: /illumos-gate/usr/src/cmd/sendmail/libsmutil/cf.c (revision 2a8bcb4e)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers.
3*7c478bd9Sstevel@tonic-gate  *	All rights reserved.
4*7c478bd9Sstevel@tonic-gate  *
5*7c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
6*7c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
7*7c478bd9Sstevel@tonic-gate  * the sendmail distribution.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  */
10*7c478bd9Sstevel@tonic-gate 
11*7c478bd9Sstevel@tonic-gate #include <sendmail.h>
12*7c478bd9Sstevel@tonic-gate SM_RCSID("@(#)$Id: cf.c,v 8.18.2.1 2002/09/24 21:48:23 ca Exp $")
13*7c478bd9Sstevel@tonic-gate #include <sendmail/pathnames.h>
14*7c478bd9Sstevel@tonic-gate 
15*7c478bd9Sstevel@tonic-gate /*
16*7c478bd9Sstevel@tonic-gate **  GETCFNAME -- return the name of the .cf file to use.
17*7c478bd9Sstevel@tonic-gate **
18*7c478bd9Sstevel@tonic-gate **	Some systems (e.g., NeXT) determine this dynamically.
19*7c478bd9Sstevel@tonic-gate **
20*7c478bd9Sstevel@tonic-gate **	For others: returns submit.cf or sendmail.cf depending
21*7c478bd9Sstevel@tonic-gate **		on the modes.
22*7c478bd9Sstevel@tonic-gate **
23*7c478bd9Sstevel@tonic-gate **	Parameters:
24*7c478bd9Sstevel@tonic-gate **		opmode -- operation mode.
25*7c478bd9Sstevel@tonic-gate **		submitmode -- submit mode.
26*7c478bd9Sstevel@tonic-gate **		cftype -- may request a certain cf file.
27*7c478bd9Sstevel@tonic-gate **		conffile -- if set, return it.
28*7c478bd9Sstevel@tonic-gate **
29*7c478bd9Sstevel@tonic-gate **	Returns:
30*7c478bd9Sstevel@tonic-gate **		name of .cf file.
31*7c478bd9Sstevel@tonic-gate */
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate char *
34*7c478bd9Sstevel@tonic-gate getcfname(opmode, submitmode, cftype, conffile)
35*7c478bd9Sstevel@tonic-gate 	int opmode;
36*7c478bd9Sstevel@tonic-gate 	int submitmode;
37*7c478bd9Sstevel@tonic-gate 	int cftype;
38*7c478bd9Sstevel@tonic-gate 	char *conffile;
39*7c478bd9Sstevel@tonic-gate {
40*7c478bd9Sstevel@tonic-gate #if NETINFO
41*7c478bd9Sstevel@tonic-gate 	char *cflocation;
42*7c478bd9Sstevel@tonic-gate #endif /* NETINFO */
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate 	if (conffile != NULL)
45*7c478bd9Sstevel@tonic-gate 		return conffile;
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate 	if (cftype == SM_GET_SUBMIT_CF ||
48*7c478bd9Sstevel@tonic-gate 	    ((submitmode != SUBMIT_UNKNOWN ||
49*7c478bd9Sstevel@tonic-gate 	      opmode == MD_DELIVER ||
50*7c478bd9Sstevel@tonic-gate 	      opmode == MD_ARPAFTP ||
51*7c478bd9Sstevel@tonic-gate 	      opmode == MD_SMTP) &&
52*7c478bd9Sstevel@tonic-gate 	     cftype != SM_GET_SENDMAIL_CF))
53*7c478bd9Sstevel@tonic-gate 	{
54*7c478bd9Sstevel@tonic-gate 		struct stat sbuf;
55*7c478bd9Sstevel@tonic-gate 		static char cf[MAXPATHLEN];
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate #if NETINFO
58*7c478bd9Sstevel@tonic-gate 		cflocation = ni_propval("/locations", NULL, "sendmail",
59*7c478bd9Sstevel@tonic-gate 					"submit.cf", '\0');
60*7c478bd9Sstevel@tonic-gate 		if (cflocation != NULL)
61*7c478bd9Sstevel@tonic-gate 			(void) sm_strlcpy(cf, cflocation, sizeof cf);
62*7c478bd9Sstevel@tonic-gate 		else
63*7c478bd9Sstevel@tonic-gate #endif /* NETINFO */
64*7c478bd9Sstevel@tonic-gate 			(void) sm_strlcpyn(cf, sizeof cf, 2, _DIR_SENDMAILCF,
65*7c478bd9Sstevel@tonic-gate 					   "submit.cf");
66*7c478bd9Sstevel@tonic-gate 		if (cftype == SM_GET_SUBMIT_CF || stat(cf, &sbuf) == 0)
67*7c478bd9Sstevel@tonic-gate 			return cf;
68*7c478bd9Sstevel@tonic-gate 	}
69*7c478bd9Sstevel@tonic-gate #if NETINFO
70*7c478bd9Sstevel@tonic-gate 	cflocation = ni_propval("/locations", NULL, "sendmail",
71*7c478bd9Sstevel@tonic-gate 				"sendmail.cf", '\0');
72*7c478bd9Sstevel@tonic-gate 	if (cflocation != NULL)
73*7c478bd9Sstevel@tonic-gate 		return cflocation;
74*7c478bd9Sstevel@tonic-gate #endif /* NETINFO */
75*7c478bd9Sstevel@tonic-gate 	return _PATH_SENDMAILCF;
76*7c478bd9Sstevel@tonic-gate }
77