xref: /titanic_52/usr/src/cmd/sendmail/libsmutil/cf.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
12*7c478bd9Sstevel@tonic-gate 
13*7c478bd9Sstevel@tonic-gate #include <sendmail.h>
14*7c478bd9Sstevel@tonic-gate SM_RCSID("@(#)$Id: cf.c,v 8.18.2.1 2002/09/24 21:48:23 ca Exp $")
15*7c478bd9Sstevel@tonic-gate #include <sendmail/pathnames.h>
16*7c478bd9Sstevel@tonic-gate 
17*7c478bd9Sstevel@tonic-gate /*
18*7c478bd9Sstevel@tonic-gate **  GETCFNAME -- return the name of the .cf file to use.
19*7c478bd9Sstevel@tonic-gate **
20*7c478bd9Sstevel@tonic-gate **	Some systems (e.g., NeXT) determine this dynamically.
21*7c478bd9Sstevel@tonic-gate **
22*7c478bd9Sstevel@tonic-gate **	For others: returns submit.cf or sendmail.cf depending
23*7c478bd9Sstevel@tonic-gate **		on the modes.
24*7c478bd9Sstevel@tonic-gate **
25*7c478bd9Sstevel@tonic-gate **	Parameters:
26*7c478bd9Sstevel@tonic-gate **		opmode -- operation mode.
27*7c478bd9Sstevel@tonic-gate **		submitmode -- submit mode.
28*7c478bd9Sstevel@tonic-gate **		cftype -- may request a certain cf file.
29*7c478bd9Sstevel@tonic-gate **		conffile -- if set, return it.
30*7c478bd9Sstevel@tonic-gate **
31*7c478bd9Sstevel@tonic-gate **	Returns:
32*7c478bd9Sstevel@tonic-gate **		name of .cf file.
33*7c478bd9Sstevel@tonic-gate */
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate char *
36*7c478bd9Sstevel@tonic-gate getcfname(opmode, submitmode, cftype, conffile)
37*7c478bd9Sstevel@tonic-gate 	int opmode;
38*7c478bd9Sstevel@tonic-gate 	int submitmode;
39*7c478bd9Sstevel@tonic-gate 	int cftype;
40*7c478bd9Sstevel@tonic-gate 	char *conffile;
41*7c478bd9Sstevel@tonic-gate {
42*7c478bd9Sstevel@tonic-gate #if NETINFO
43*7c478bd9Sstevel@tonic-gate 	char *cflocation;
44*7c478bd9Sstevel@tonic-gate #endif /* NETINFO */
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate 	if (conffile != NULL)
47*7c478bd9Sstevel@tonic-gate 		return conffile;
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate 	if (cftype == SM_GET_SUBMIT_CF ||
50*7c478bd9Sstevel@tonic-gate 	    ((submitmode != SUBMIT_UNKNOWN ||
51*7c478bd9Sstevel@tonic-gate 	      opmode == MD_DELIVER ||
52*7c478bd9Sstevel@tonic-gate 	      opmode == MD_ARPAFTP ||
53*7c478bd9Sstevel@tonic-gate 	      opmode == MD_SMTP) &&
54*7c478bd9Sstevel@tonic-gate 	     cftype != SM_GET_SENDMAIL_CF))
55*7c478bd9Sstevel@tonic-gate 	{
56*7c478bd9Sstevel@tonic-gate 		struct stat sbuf;
57*7c478bd9Sstevel@tonic-gate 		static char cf[MAXPATHLEN];
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate #if NETINFO
60*7c478bd9Sstevel@tonic-gate 		cflocation = ni_propval("/locations", NULL, "sendmail",
61*7c478bd9Sstevel@tonic-gate 					"submit.cf", '\0');
62*7c478bd9Sstevel@tonic-gate 		if (cflocation != NULL)
63*7c478bd9Sstevel@tonic-gate 			(void) sm_strlcpy(cf, cflocation, sizeof cf);
64*7c478bd9Sstevel@tonic-gate 		else
65*7c478bd9Sstevel@tonic-gate #endif /* NETINFO */
66*7c478bd9Sstevel@tonic-gate 			(void) sm_strlcpyn(cf, sizeof cf, 2, _DIR_SENDMAILCF,
67*7c478bd9Sstevel@tonic-gate 					   "submit.cf");
68*7c478bd9Sstevel@tonic-gate 		if (cftype == SM_GET_SUBMIT_CF || stat(cf, &sbuf) == 0)
69*7c478bd9Sstevel@tonic-gate 			return cf;
70*7c478bd9Sstevel@tonic-gate 	}
71*7c478bd9Sstevel@tonic-gate #if NETINFO
72*7c478bd9Sstevel@tonic-gate 	cflocation = ni_propval("/locations", NULL, "sendmail",
73*7c478bd9Sstevel@tonic-gate 				"sendmail.cf", '\0');
74*7c478bd9Sstevel@tonic-gate 	if (cflocation != NULL)
75*7c478bd9Sstevel@tonic-gate 		return cflocation;
76*7c478bd9Sstevel@tonic-gate #endif /* NETINFO */
77*7c478bd9Sstevel@tonic-gate 	return _PATH_SENDMAILCF;
78*7c478bd9Sstevel@tonic-gate }
79