1 /* $NetBSD: postconf_unused.c,v 1.1.1.2 2014/07/06 19:27:53 tron Exp $ */
2
3 /*++
4 /* NAME
5 /* postconf_unused 3
6 /* SUMMARY
7 /* report unused parameters
8 /* SYNOPSIS
9 /* #include <postconf.h>
10 /*
11 /* void pcf_flag_unused_main_parameters()
12 /*
13 /* void pcf_flag_unused_master_parameters()
14 /* DESCRIPTION
15 /* These functions must be called after all parameter information
16 /* is initialized: built-ins, service-defined and user-defined.
17 /* In other words, don't call these functions with "postconf
18 /* -d" which ignores user-defined main.cf settings.
19 /*
20 /* pcf_flag_unused_main_parameters() reports unused "name=value"
21 /* entries in main.cf.
22 /*
23 /* pcf_flag_unused_master_parameters() reports unused "-o
24 /* name=value" entries in master.cf.
25 /* DIAGNOSTICS
26 /* Problems are reported to the standard error stream.
27 /* LICENSE
28 /* .ad
29 /* .fi
30 /* The Secure Mailer license must be distributed with this software.
31 /* AUTHOR(S)
32 /* Wietse Venema
33 /* IBM T.J. Watson Research
34 /* P.O. Box 704
35 /* Yorktown Heights, NY 10598, USA
36 /*--*/
37
38 /* System library. */
39
40 #include <sys_defs.h>
41
42 /* Utility library. */
43
44 #include <msg.h>
45 #include <dict.h>
46 #include <vstream.h>
47
48 /* Global library. */
49
50 #include <mail_params.h>
51 #include <mail_conf.h>
52
53 /* Application-specific. */
54
55 #include <postconf.h>
56
57 /* pcf_flag_unused_parameters - warn about unused parameters */
58
pcf_flag_unused_parameters(DICT * dict,const char * conf_name,PCF_MASTER_ENT * local_scope)59 static void pcf_flag_unused_parameters(DICT *dict, const char *conf_name,
60 PCF_MASTER_ENT *local_scope)
61 {
62 const char *myname = "pcf_flag_unused_parameters";
63 const char *param_name;
64 const char *param_value;
65 int how;
66
67 /*
68 * Sanity checks.
69 */
70 if (pcf_param_table == 0)
71 msg_panic("%s: global parameter table is not initialized", myname);
72
73 /*
74 * Iterate over all entries, and flag parameter names that aren't used
75 * anywhere. Show the warning message at the end of the output.
76 */
77 if (dict->sequence == 0)
78 msg_panic("%s: parameter dictionary %s has no iterator",
79 myname, conf_name);
80 for (how = DICT_SEQ_FUN_FIRST;
81 dict->sequence(dict, how, ¶m_name, ¶m_value) == 0;
82 how = DICT_SEQ_FUN_NEXT) {
83 if (PCF_PARAM_TABLE_LOCATE(pcf_param_table, param_name) == 0
84 && (local_scope == 0
85 || PCF_PARAM_TABLE_LOCATE(local_scope->valid_names, param_name) == 0)) {
86 vstream_fflush(VSTREAM_OUT);
87 msg_warn("%s/%s: unused parameter: %s=%s",
88 var_config_dir, conf_name, param_name, param_value);
89 }
90 }
91 }
92
93 /* pcf_flag_unused_main_parameters - warn about unused parameters */
94
pcf_flag_unused_main_parameters(void)95 void pcf_flag_unused_main_parameters(void)
96 {
97 const char *myname = "pcf_flag_unused_main_parameters";
98 DICT *dict;
99
100 /*
101 * Iterate over all main.cf entries, and flag parameter names that aren't
102 * used anywhere.
103 */
104 if ((dict = dict_handle(CONFIG_DICT)) == 0)
105 msg_panic("%s: parameter dictionary %s not found",
106 myname, CONFIG_DICT);
107 pcf_flag_unused_parameters(dict, MAIN_CONF_FILE, (PCF_MASTER_ENT *) 0);
108 }
109
110 /* pcf_flag_unused_master_parameters - warn about unused parameters */
111
pcf_flag_unused_master_parameters(void)112 void pcf_flag_unused_master_parameters(void)
113 {
114 const char *myname = "pcf_flag_unused_master_parameters";
115 PCF_MASTER_ENT *masterp;
116 DICT *dict;
117
118 /*
119 * Sanity checks.
120 */
121 if (pcf_master_table == 0)
122 msg_panic("%s: master table is not initialized", myname);
123
124 /*
125 * Iterate over all master.cf entries, and flag parameter names that
126 * aren't used anywhere.
127 */
128 for (masterp = pcf_master_table; masterp->argv != 0; masterp++)
129 if ((dict = masterp->all_params) != 0)
130 pcf_flag_unused_parameters(dict, MASTER_CONF_FILE, masterp);
131 }
132