~ubuntu-branches/ubuntu/vivid/postfix/vivid-proposed

« back to all changes in this revision

Viewing changes to src/postconf/postconf_unused.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2012-03-20 13:47:16 UTC
  • mfrom: (1.1.33)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: package-import@ubuntu.com-20120320134716-v7ab94fmor2z9pvp
Tags: upstream-2.9.1
ImportĀ upstreamĀ versionĀ 2.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*++
 
2
/* NAME
 
3
/*      postconf_unused 3
 
4
/* SUMMARY
 
5
/*      report unused parameters
 
6
/* SYNOPSIS
 
7
/*      #include <postconf.h>
 
8
/*
 
9
/*      void    flag_unused_main_parameters()
 
10
/*
 
11
/*      void    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 -d"
 
16
/*      which ignores user-defined main.cf settings.
 
17
/*
 
18
/*      flag_unused_main_parameters() reports unused "name=value"
 
19
/*      entries in main.cf.
 
20
/*
 
21
/*      flag_unused_master_parameters() reports unused "-o name=value"
 
22
/*      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
/* flag_unused_parameters - warn about unused parameters */
 
56
 
 
57
static void flag_unused_parameters(DICT *dict, const char *conf_name,
 
58
                                           PC_MASTER_ENT *local_scope)
 
59
{
 
60
    const char *myname = "flag_unused_parameters";
 
61
    const char *param_name;
 
62
    const char *param_value;
 
63
    int     how;
 
64
 
 
65
    /*
 
66
     * Sanity checks.
 
67
     */
 
68
    if (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 (PC_PARAM_TABLE_LOCATE(param_table, param_name) == 0
 
82
            && (local_scope == 0
 
83
                || PC_PARAM_TABLE_LOCATE(local_scope->valid_names, param_name) == 0)) {
 
84
            vstream_fflush(VSTREAM_OUT);
 
85
            msg_warn("%s/%s: unused parameter: %s=%s",
 
86
                     var_config_dir, conf_name, param_name, param_value);
 
87
        }
 
88
    }
 
89
}
 
90
 
 
91
/* flag_unused_main_parameters - warn about unused parameters */
 
92
 
 
93
void    flag_unused_main_parameters(void)
 
94
{
 
95
    const char *myname = "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
    flag_unused_parameters(dict, MAIN_CONF_FILE, (PC_MASTER_ENT *) 0);
 
106
}
 
107
 
 
108
/* flag_unused_master_parameters - warn about unused parameters */
 
109
 
 
110
void    flag_unused_master_parameters(void)
 
111
{
 
112
    const char *myname = "flag_unused_master_parameters";
 
113
    PC_MASTER_ENT *masterp;
 
114
    DICT   *dict;
 
115
 
 
116
    /*
 
117
     * Sanity checks.
 
118
     */
 
119
    if (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 = master_table; masterp->argv != 0; masterp++)
 
127
        if ((dict = masterp->all_params) != 0)
 
128
            flag_unused_parameters(dict, MASTER_CONF_FILE, masterp);
 
129
}