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

« back to all changes in this revision

Viewing changes to src/global/mail_conf_nint.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
/*      mail_conf_nint 3
 
4
/* SUMMARY
 
5
/*      integer-valued configuration parameter support
 
6
/* SYNOPSIS
 
7
/*      #include <mail_conf.h>
 
8
/*
 
9
/*      int     get_mail_conf_nint(name, defval, min, max);
 
10
/*      const char *name;
 
11
/*      const char *defval;
 
12
/*      int     min;
 
13
/*      int     max;
 
14
/*
 
15
/*      int     get_mail_conf_nint_fn(name, defval, min, max);
 
16
/*      const char *name;
 
17
/*      char    *(*defval)();
 
18
/*      int     min;
 
19
/*      int     max;
 
20
/*
 
21
/*      void    set_mail_conf_nint(name, value)
 
22
/*      const char *name;
 
23
/*      const char *value;
 
24
/*
 
25
/*      void    set_mail_conf_nint_int(name, value)
 
26
/*      const char *name;
 
27
/*      int     value;
 
28
/*
 
29
/*      void    get_mail_conf_nint_table(table)
 
30
/*      const CONFIG_NINT_TABLE *table;
 
31
/*
 
32
/*      void    get_mail_conf_nint_fn_table(table)
 
33
/*      const CONFIG_NINT_TABLE *table;
 
34
/* AUXILIARY FUNCTIONS
 
35
/*      int     get_mail_conf_nint2(name1, name2, defval, min, max);
 
36
/*      const char *name1;
 
37
/*      const char *name2;
 
38
/*      int     defval;
 
39
/*      int     min;
 
40
/*      int     max;
 
41
/* DESCRIPTION
 
42
/*      This module implements configuration parameter support
 
43
/*      for integer values. The default value can be a macro
 
44
/*      expression ($name, ${name?value} and ${name:value}).
 
45
/*
 
46
/*      get_mail_conf_nint() looks up the named entry in the global
 
47
/*      configuration dictionary. The default value is returned
 
48
/*      when no value was found.
 
49
/*      \fImin\fR is zero or specifies a lower limit on the integer
 
50
/*      value or string length; \fImax\fR is zero or specifies an
 
51
/*      upper limit on the integer value or string length.
 
52
/*
 
53
/*      get_mail_conf_nint_fn() is similar but specifies a function that
 
54
/*      provides the default value. The function is called only
 
55
/*      when the default value is needed.
 
56
/*
 
57
/*      set_mail_conf_nint() updates the named entry in the global
 
58
/*      configuration dictionary. This has no effect on values that
 
59
/*      have been looked up earlier via the get_mail_conf_XXX() routines.
 
60
/*
 
61
/*      get_mail_conf_nint_table() and get_mail_conf_nint_fn_table() initialize
 
62
/*      lists of variables, as directed by their table arguments. A table
 
63
/*      must be terminated by a null entry.
 
64
/*
 
65
/*      get_mail_conf_nint2() concatenates the two names and is otherwise
 
66
/*      identical to get_mail_conf_nint().
 
67
/* DIAGNOSTICS
 
68
/*      Fatal errors: malformed numerical value.
 
69
/* SEE ALSO
 
70
/*      config(3) general configuration
 
71
/*      mail_conf_str(3) string-valued configuration parameters
 
72
/* LICENSE
 
73
/* .ad
 
74
/* .fi
 
75
/*      The Secure Mailer license must be distributed with this software.
 
76
/* AUTHOR(S)
 
77
/*      Wietse Venema
 
78
/*      IBM T.J. Watson Research
 
79
/*      P.O. Box 704
 
80
/*      Yorktown Heights, NY 10598, USA
 
81
/*--*/
 
82
 
 
83
/* System library. */
 
84
 
 
85
#include <sys_defs.h>
 
86
#include <stdlib.h>
 
87
#include <stdio.h>                      /* sscanf() */
 
88
 
 
89
/* Utility library. */
 
90
 
 
91
#include <msg.h>
 
92
#include <mymalloc.h>
 
93
#include <dict.h>
 
94
#include <stringops.h>
 
95
 
 
96
/* Global library. */
 
97
 
 
98
#include "mail_conf.h"
 
99
 
 
100
/* convert_mail_conf_nint - look up and convert integer parameter value */
 
101
 
 
102
static int convert_mail_conf_nint(const char *name, int *intval)
 
103
{
 
104
    const char *strval;
 
105
    char    junk;
 
106
 
 
107
    if ((strval = mail_conf_lookup_eval(name)) != 0) {
 
108
        if (sscanf(strval, "%d%c", intval, &junk) != 1)
 
109
            msg_fatal("bad numerical configuration: %s = %s", name, strval);
 
110
        return (1);
 
111
    }
 
112
    return (0);
 
113
}
 
114
 
 
115
/* check_mail_conf_nint - validate integer value */
 
116
 
 
117
static void check_mail_conf_nint(const char *name, int intval, int min, int max)
 
118
{
 
119
    if (min && intval < min)
 
120
        msg_fatal("invalid %s parameter value %d < %d", name, intval, min);
 
121
    if (max && intval > max)
 
122
        msg_fatal("invalid %s parameter value %d > %d", name, intval, max);
 
123
}
 
124
 
 
125
/* get_mail_conf_nint - evaluate integer-valued configuration variable */
 
126
 
 
127
int     get_mail_conf_nint(const char *name, const char *defval, int min, int max)
 
128
{
 
129
    int     intval;
 
130
 
 
131
    if (convert_mail_conf_nint(name, &intval) == 0)
 
132
        set_mail_conf_nint(name, defval);
 
133
    if (convert_mail_conf_nint(name, &intval) == 0)
 
134
        msg_panic("get_mail_conf_nint: parameter not found: %s", name);
 
135
    check_mail_conf_nint(name, intval, min, max);
 
136
    return (intval);
 
137
}
 
138
 
 
139
/* get_mail_conf_nint2 - evaluate integer-valued configuration variable */
 
140
 
 
141
int     get_mail_conf_nint2(const char *name1, const char *name2, int defval,
 
142
                                    int min, int max)
 
143
{
 
144
    int     intval;
 
145
    char   *name;
 
146
 
 
147
    name = concatenate(name1, name2, (char *) 0);
 
148
    if (convert_mail_conf_nint(name, &intval) == 0)
 
149
        set_mail_conf_nint_int(name, defval);
 
150
    if (convert_mail_conf_nint(name, &intval) == 0)
 
151
        msg_panic("get_mail_conf_nint2: parameter not found: %s", name);
 
152
    check_mail_conf_nint(name, intval, min, max);
 
153
    myfree(name);
 
154
    return (intval);
 
155
}
 
156
 
 
157
/* get_mail_conf_nint_fn - evaluate integer-valued configuration variable */
 
158
 
 
159
typedef const char *(*stupid_indent_int) (void);
 
160
 
 
161
int     get_mail_conf_nint_fn(const char *name, stupid_indent_int defval,
 
162
                                      int min, int max)
 
163
{
 
164
    int     intval;
 
165
 
 
166
    if (convert_mail_conf_nint(name, &intval) == 0)
 
167
        set_mail_conf_nint(name, defval());
 
168
    if (convert_mail_conf_nint(name, &intval) == 0)
 
169
        msg_panic("get_mail_conf_nint_fn: parameter not found: %s", name);
 
170
    check_mail_conf_nint(name, intval, min, max);
 
171
    return (intval);
 
172
}
 
173
 
 
174
/* set_mail_conf_nint - update integer-valued configuration dictionary entry */
 
175
 
 
176
void    set_mail_conf_nint(const char *name, const char *value)
 
177
{
 
178
    mail_conf_update(name, value);
 
179
}
 
180
 
 
181
/* set_mail_conf_nint_int - update integer-valued configuration dictionary entry */
 
182
 
 
183
void    set_mail_conf_nint_int(const char *name, int value)
 
184
{
 
185
    char    buf[BUFSIZ];                /* yeah! crappy code! */
 
186
 
 
187
    sprintf(buf, "%d", value);                  /* yeah! more crappy code! */
 
188
    mail_conf_update(name, buf);
 
189
}
 
190
 
 
191
/* get_mail_conf_nint_table - look up table of integers */
 
192
 
 
193
void    get_mail_conf_nint_table(const CONFIG_NINT_TABLE *table)
 
194
{
 
195
    while (table->name) {
 
196
        table->target[0] = get_mail_conf_nint(table->name, table->defval,
 
197
                                              table->min, table->max);
 
198
        table++;
 
199
    }
 
200
}
 
201
 
 
202
/* get_mail_conf_nint_fn_table - look up integers, defaults are functions */
 
203
 
 
204
void    get_mail_conf_nint_fn_table(const CONFIG_NINT_FN_TABLE *table)
 
205
{
 
206
    while (table->name) {
 
207
        table->target[0] = get_mail_conf_nint_fn(table->name, table->defval,
 
208
                                                 table->min, table->max);
 
209
        table++;
 
210
    }
 
211
}