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