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