~ubuntu-branches/debian/sid/postfix/sid

« back to all changes in this revision

Viewing changes to src/postscreen/postscreen_tests.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones, LaMont Jones, localization folks
  • Date: 2014-02-11 07:44:30 UTC
  • mfrom: (1.1.41)
  • Revision ID: package-import@ubuntu.com-20140211074430-91tdwgjriazawdz4
Tags: 2.11.0-1
[LaMont Jones]

* New upstream release: 2.11.0

[localization folks]

* l10n: Updated German translations.  Closes: #734893 (Helge Kreutzmann)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
/*      const char *helo;
28
28
/*      const char *sender;
29
29
/*      const char *rcpt;
 
30
/*
 
31
/*      const char *psc_test_name(tindx)
 
32
/*      int     tindx;
30
33
/* DESCRIPTION
31
34
/*      The functions in this module overwrite the per-test expiration
32
35
/*      time stamps and all flags bits.  Some functions are implemented
54
57
/*      This may modify the time stamps for disabled tests.
55
58
/*
56
59
/*      psc_print_grey_key() prints a greylist lookup key.
 
60
/*
 
61
/*      psc_test_name() returns the name for the specified text
 
62
/*      index.
57
63
/* LICENSE
58
64
/* .ad
59
65
/* .fi
69
75
 
70
76
#include <sys_defs.h>
71
77
#include <stdio.h>                      /* sscanf */
 
78
#include <stdlib.h>                     /* strtoul */
72
79
 
73
80
/* Utility library. */
74
81
 
75
82
#include <msg.h>
 
83
#include <name_code.h>
76
84
 
77
85
/* Global library. */
78
86
 
132
140
    state->pipel_stamp = PSC_TIME_STAMP_NEW;
133
141
    state->nsmtp_stamp = PSC_TIME_STAMP_NEW;
134
142
    state->barlf_stamp = PSC_TIME_STAMP_NEW;
135
 
    state->penal_stamp = PSC_TIME_STAMP_NEW;
136
143
 
137
144
    /*
138
145
     * Don't flag disabled tests as "todo", because there would be no way to
156
163
                                const char *stamp_str,
157
164
                                time_t time_value)
158
165
{
159
 
    unsigned long pregr_stamp;
160
 
    unsigned long dnsbl_stamp;
161
 
    unsigned long pipel_stamp;
162
 
    unsigned long nsmtp_stamp;
163
 
    unsigned long barlf_stamp;
164
 
    unsigned long penal_stamp;
165
 
 
166
 
#ifdef NONPROD
167
 
    time_t  penalty_left;
168
 
 
169
 
#endif
 
166
    const char *start = stamp_str;
 
167
    char   *cp;
 
168
    time_t *time_stamps = state->expire_time;
 
169
    time_t *sp;
170
170
 
171
171
    /*
172
172
     * We don't know what tests have expired or have never passed.
182
182
     * enabled tests, but the remote SMTP client has not yet passed all those
183
183
     * tests.
184
184
     */
185
 
    switch (sscanf(stamp_str, "%lu;%lu;%lu;%lu;%lu;%lu",
186
 
                   &pregr_stamp, &dnsbl_stamp, &pipel_stamp, &nsmtp_stamp,
187
 
                   &barlf_stamp, &penal_stamp)) {
188
 
    case 0:
189
 
        pregr_stamp = PSC_TIME_STAMP_DISABLED;
190
 
    case 1:
191
 
        dnsbl_stamp = PSC_TIME_STAMP_DISABLED;
192
 
    case 2:
193
 
        pipel_stamp = PSC_TIME_STAMP_DISABLED;
194
 
    case 3:
195
 
        nsmtp_stamp = PSC_TIME_STAMP_DISABLED;
196
 
    case 4:
197
 
        barlf_stamp = PSC_TIME_STAMP_DISABLED;
198
 
    case 5:
199
 
        penal_stamp = PSC_TIME_STAMP_DISABLED;
200
 
    default:
201
 
        break;
 
185
    for (sp = time_stamps; sp < time_stamps + PSC_TINDX_COUNT; sp++) {
 
186
        *sp = strtoul(start, &cp, 10);
 
187
        if (*start == 0 || (*cp != '\0' && *cp != ';') || errno == ERANGE)
 
188
            *sp = PSC_TIME_STAMP_DISABLED;
 
189
        if (*sp == PSC_TIME_STAMP_NEW)
 
190
            state->flags |= PSC_STATE_FLAG_NEW;
 
191
        if (msg_verbose)
 
192
            msg_info("%s -> %lu", start, (unsigned long) *sp);
 
193
        if (*cp == ';')
 
194
            start = cp + 1;
 
195
        else
 
196
            start = cp;
202
197
    }
203
 
    state->pregr_stamp = pregr_stamp;
204
 
    state->dnsbl_stamp = dnsbl_stamp;
205
 
    state->pipel_stamp = pipel_stamp;
206
 
    state->nsmtp_stamp = nsmtp_stamp;
207
 
    state->barlf_stamp = barlf_stamp;
208
 
    state->penal_stamp = penal_stamp;
209
 
 
210
 
    if (pregr_stamp == PSC_TIME_STAMP_NEW
211
 
        || dnsbl_stamp == PSC_TIME_STAMP_NEW
212
 
        || pipel_stamp == PSC_TIME_STAMP_NEW
213
 
        || nsmtp_stamp == PSC_TIME_STAMP_NEW
214
 
        || barlf_stamp == PSC_TIME_STAMP_NEW)
215
 
        state->flags |= PSC_STATE_FLAG_NEW;
216
198
 
217
199
    /*
218
200
     * Don't flag disabled tests as "todo", because there would be no way to
270
252
            state->flags |= PSC_STATE_FLAG_DNSBL_TODO;
271
253
    }
272
254
#endif
273
 
 
274
 
    /*
275
 
     * Apply unexpired penalty for past behavior.
276
 
     * 
277
 
     * XXX Before we can drop connections, change this function to return
278
 
     * success/fail, to inform the caller that the state object no longer
279
 
     * exists.
280
 
     */
281
 
#ifdef NONPROD
282
 
    if ((penalty_left = state->penal_stamp - event_time()) > 0) {
283
 
        msg_info("PENALTY %ld for %s",
284
 
                 (long) penalty_left, state->smtp_client_addr);
285
 
        PSC_FAIL_SESSION_STATE(state, PSC_STATE_FLAG_PENAL_FAIL);
286
 
#if 0
287
 
        switch (psc_penal_action) {
288
 
        case PSC_ACT_DROP:
289
 
            PSC_DROP_SESSION_STATE(state,
290
 
                             "421 4.3.2 Service currently unavailable\r\n");
291
 
            break;
292
 
        case PSC_ACT_ENFORCE:
293
 
#endif
294
 
            PSC_ENFORCE_SESSION_STATE(state,
295
 
                             "450 4.3.2 Service currently unavailable\r\n");
296
 
#if 0
297
 
            break;
298
 
        case PSC_ACT_IGNORE:
299
 
            PSC_UNFAIL_SESSION_STATE(state, PSC_STATE_FLAG_PENAL_FAIL);
300
 
            break;
301
 
        default:
302
 
            msg_panic("%s: unknown penalty action value %d",
303
 
                      myname, psc_penal_action);
304
 
        }
305
 
#endif
306
 
    }
307
 
#endif                                          /* NONPROD */
308
255
}
309
256
 
310
257
/* psc_print_tests - print postscreen cache record */
320
267
        msg_panic("%s: attempt to save a no-update record", myname);
321
268
 
322
269
    /*
323
 
     * Don't record a client as "passed" while subject to penalty. Be sure to
324
 
     * produce correct PASS OLD/NEW logging.
325
 
     * 
326
 
     * XXX This needs to be refined - we should not reset the result of tests
327
 
     * that were passed in previous sessions, otherwise a client may never
328
 
     * pass a multi-stage test such as greylisting. One solution is to keep
329
 
     * the original and updated time stamps around, and to save an updated
330
 
     * time stamp only when the corresponding "pass" flag is raised.
331
 
     */
332
 
#ifdef NONPROD
333
 
    if (state->flags & PSC_STATE_FLAG_PENAL_FAIL) {
334
 
        state->pregr_stamp = state->dnsbl_stamp = state->pipel_stamp =
335
 
            state->nsmtp_stamp = state->barlf_stamp =
336
 
            ((state->flags & PSC_STATE_FLAG_NEW) ?
337
 
             PSC_TIME_STAMP_NEW : PSC_TIME_STAMP_DISABLED);
338
 
    }
339
 
#endif
340
 
 
341
 
    /*
342
270
     * Give disabled tests a dummy time stamp so that we don't log a client
343
271
     * with "pass new" when some disabled test becomes enabled at some later
344
272
     * time.
354
282
    if (var_psc_barlf_enable == 0 && state->barlf_stamp == PSC_TIME_STAMP_NEW)
355
283
        state->barlf_stamp = PSC_TIME_STAMP_DISABLED;
356
284
 
357
 
    vstring_sprintf(buf, "%lu;%lu;%lu;%lu;%lu;%lu",
 
285
    vstring_sprintf(buf, "%lu;%lu;%lu;%lu;%lu",
358
286
                    (unsigned long) state->pregr_stamp,
359
287
                    (unsigned long) state->dnsbl_stamp,
360
288
                    (unsigned long) state->pipel_stamp,
361
289
                    (unsigned long) state->nsmtp_stamp,
362
 
                    (unsigned long) state->barlf_stamp,
363
 
                    (unsigned long) state->penal_stamp);
 
290
                    (unsigned long) state->barlf_stamp);
364
291
    return (STR(buf));
365
292
}
366
293
 
373
300
    return (STR(vstring_sprintf(buf, "%s/%s/%s/%s",
374
301
                                client, helo, sender, rcpt)));
375
302
}
 
303
 
 
304
/* psc_test_name - map test index to symbolic name */
 
305
 
 
306
const char *psc_test_name(int tindx)
 
307
{
 
308
    const char *myname = "psc_test_name";
 
309
    const NAME_CODE test_name_map[] = {
 
310
        PSC_TNAME_PREGR, PSC_TINDX_PREGR,
 
311
        PSC_TNAME_DNSBL, PSC_TINDX_DNSBL,
 
312
        PSC_TNAME_PIPEL, PSC_TINDX_PIPEL,
 
313
        PSC_TNAME_NSMTP, PSC_TINDX_NSMTP,
 
314
        PSC_TNAME_BARLF, PSC_TINDX_BARLF,
 
315
        0, -1,
 
316
    };
 
317
    const char *result;
 
318
 
 
319
    if ((result = str_name_code(test_name_map, tindx)) == 0)
 
320
        msg_panic("%s: bad index %d", myname, tindx);
 
321
    return (result);
 
322
}