~ubuntu-branches/ubuntu/maverick/postfix/maverick-security

« back to all changes in this revision

Viewing changes to src/master/master_watch.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones, Wietse Venema, LaMont Jones
  • Date: 2009-06-03 14:17:08 UTC
  • mfrom: (1.1.22 upstream)
  • Revision ID: james.westby@ubuntu.com-20090603141708-o9u59xlor7nmd2x1
[Wietse Venema]

* New upstream release: 2.6.2~rc1

[LaMont Jones]

* move postfix-add-{filter,policy} manpages to section 8, and deliver
* provide: default-mta on ubuntu

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*++
 
2
/* NAME
 
3
/*      master_watch 3
 
4
/* SUMMARY
 
5
/*      Postfix master - monitor main.cf changes
 
6
/* SYNOPSIS
 
7
/*      #include "master.h"
 
8
/*
 
9
/*      void    master_str_watch(str_watch_table)
 
10
/*      const MASTER_STR_WATCH *str_watch_table;
 
11
/*
 
12
/*      void    master_int_watch(int_watch_table)
 
13
/*      MASTER_INT_WATCH *int_watch_table;
 
14
/* DESCRIPTION
 
15
/*      The Postfix master daemon is a long-running process. After
 
16
/*      main.cf is changed, some parameter changes may require that
 
17
/*      master data structures be recomputed.
 
18
/*
 
19
/*      Unfortunately, some main.cf changes cannot be applied
 
20
/*      on-the-fly, either because they require killing off existing
 
21
/*      child processes and thus disrupt service, or because the
 
22
/*      necessary support for on-the-fly data structure update has
 
23
/*      not yet been implemented.  Such main.cf changes trigger a
 
24
/*      warning that they require that Postfix be stopped and
 
25
/*      restarted.
 
26
/*
 
27
/*      This module provides functions that monitor selected main.cf
 
28
/*      parameters for change. The operation of these functions is
 
29
/*      controlled by tables that specify the parameter name, the
 
30
/*      current parameter value, a historical parameter value,
 
31
/*      optional flags, and an optional notify call-back function.
 
32
/*
 
33
/*      master_str_watch() monitors string-valued parameters for
 
34
/*      change, and master_int_watch() does the same for integer-valued
 
35
/*      parameters. Note that master_int_watch() needs read-write
 
36
/*      access to its argument table, while master_str_watch() needs
 
37
/*      read-only access only.
 
38
/*
 
39
/*      The functions log a warning when a parameter value has
 
40
/*      changed after re-reading main.cf, but the parameter is not
 
41
/*      flagged in the MASTER_*_WATCH table as "updatable" with
 
42
/*      MASTER_WATCH_FLAG_UPDATABLE.
 
43
/*
 
44
/*      If the parameter has a notify call-back function, then the
 
45
/*      function is called after main.cf is read for the first time.
 
46
/*      If the parameter is flagged as "updatable", then the function
 
47
/*      is also called when the parameter value changes after
 
48
/*      re-reading main.cf.
 
49
/* LICENSE
 
50
/* .ad
 
51
/* .fi
 
52
/*      The Secure Mailer license must be distributed with this software.
 
53
/* AUTHOR(S)
 
54
/*      Wietse Venema
 
55
/*      IBM T.J. Watson Research
 
56
/*      P.O. Box 704
 
57
/*      Yorktown Heights, NY 10598, USA
 
58
/*--*/
 
59
 
 
60
/* System library. */
 
61
 
 
62
#include <sys_defs.h>
 
63
#include <string.h>
 
64
#include <unistd.h>
 
65
 
 
66
/* Utility library. */
 
67
 
 
68
#include <msg.h>
 
69
#include <mymalloc.h>
 
70
 
 
71
/* Application-specific. */
 
72
 
 
73
#include "master.h"
 
74
 
 
75
/* master_str_watch - watch string-valued parameters for change */
 
76
 
 
77
void    master_str_watch(const MASTER_STR_WATCH *str_watch_table)
 
78
{
 
79
    const MASTER_STR_WATCH *wp;
 
80
 
 
81
    for (wp = str_watch_table; wp->name != 0; wp++) {
 
82
 
 
83
        /*
 
84
         * Detect changes to monitored parameter values. If a change is
 
85
         * supported, we discard the backed up value and update it to the
 
86
         * current value later. Otherwise we complain.
 
87
         */
 
88
        if (wp->backup[0] != 0
 
89
            && strcmp(wp->backup[0], wp->value[0]) != 0) {
 
90
            if ((wp->flags & MASTER_WATCH_FLAG_UPDATABLE) == 0) {
 
91
                msg_warn("ignoring %s parameter value change", wp->name);
 
92
                msg_warn("old value: \"%s\", new value: \"%s\"",
 
93
                         wp->backup[0], wp->value[0]);
 
94
                msg_warn("to change %s, stop and start Postfix", wp->name);
 
95
            } else {
 
96
                myfree(wp->backup[0]);
 
97
                wp->backup[0] = 0;
 
98
            }
 
99
        }
 
100
 
 
101
        /*
 
102
         * Initialize the backed up parameter value, or update it if this
 
103
         * parameter supports updates after initialization. Optionally 
 
104
         * notify the application that this parameter has changed.
 
105
         */
 
106
        if (wp->backup[0] == 0) {
 
107
            if (wp->notify != 0)
 
108
                wp->notify();
 
109
            wp->backup[0] = mystrdup(wp->value[0]);
 
110
        }
 
111
    }
 
112
}
 
113
 
 
114
/* master_int_watch - watch integer-valued parameters for change */
 
115
 
 
116
void    master_int_watch(MASTER_INT_WATCH *int_watch_table)
 
117
{
 
118
    MASTER_INT_WATCH *wp;
 
119
 
 
120
    for (wp = int_watch_table; wp->name != 0; wp++) {
 
121
 
 
122
        /*
 
123
         * Detect changes to monitored parameter values. If a change is
 
124
         * supported, we discard the backed up value and update it to the
 
125
         * current value later. Otherwise we complain.
 
126
         */
 
127
        if ((wp->flags & MASTER_WATCH_FLAG_ISSET) != 0
 
128
            && wp->backup != wp->value[0]) {
 
129
            if ((wp->flags & MASTER_WATCH_FLAG_UPDATABLE) == 0) {
 
130
                msg_warn("ignoring %s parameter value change", wp->name);
 
131
                msg_warn("old value: \"%d\", new value: \"%d\"",
 
132
                         wp->backup, wp->value[0]);
 
133
                msg_warn("to change %s, stop and start Postfix", wp->name);
 
134
            } else {
 
135
                wp->flags &= ~MASTER_WATCH_FLAG_ISSET;
 
136
            }
 
137
        }
 
138
 
 
139
        /*
 
140
         * Initialize the backed up parameter value, or update if it this
 
141
         * parameter supports updates after initialization. Optionally 
 
142
         * notify the application that this parameter has changed.
 
143
         */
 
144
        if ((wp->flags & MASTER_WATCH_FLAG_ISSET) == 0) {
 
145
            if (wp->notify != 0)
 
146
                wp->notify();
 
147
            wp->flags |= MASTER_WATCH_FLAG_ISSET;
 
148
            wp->backup = wp->value[0];
 
149
        }
 
150
    }
 
151
}