~ubuntu-branches/ubuntu/hoary/postfix/hoary-security

« back to all changes in this revision

Viewing changes to src/local/delivered.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-10-06 11:50:33 UTC
  • Revision ID: james.westby@ubuntu.com-20041006115033-ooo6yfg6kmoteu04
Tags: upstream-2.1.3
ImportĀ upstreamĀ versionĀ 2.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*++
 
2
/* NAME
 
3
/*      delivered 3
 
4
/* SUMMARY
 
5
/*      process Delivered-To: headers
 
6
/* SYNOPSIS
 
7
/*      #include "local.h"
 
8
/*
 
9
/*      HTABLE  *delivered_init(attr)
 
10
/*      DELIVER_ATTR attr;
 
11
/*
 
12
/*      int     delivered_find(table, address)
 
13
/*      HTABLE  *table;
 
14
/*      char    *address;
 
15
/*
 
16
/*      void    delivered_free(table)
 
17
/*      HTABLE  *table;
 
18
/* DESCRIPTION
 
19
/*      This module processes addresses in Delivered-To: headers.
 
20
/*      These headers are added by some mail delivery systems, for the
 
21
/*      purpose of breaking mail forwarding loops. N.B. This solves
 
22
/*      a different problem than the Received: hop count limit. Hop
 
23
/*      counts are used to limit the impact of mail routing problems.
 
24
/*
 
25
/*      delivered_init() extracts Delivered-To: header addresses
 
26
/*      from the specified message, and returns a table with the
 
27
/*      result.
 
28
/*
 
29
/*      delivered_find() looks up the address in the lookup table,
 
30
/*      and returns non-zero when the address was found. The
 
31
/*      address argument must be in internalized form.
 
32
/*
 
33
/*      delivered_free() releases storage that was allocated by
 
34
/*      delivered_init().
 
35
/*
 
36
/*      Arguments:
 
37
/* .IP state
 
38
/*      The attributes that specify the message, recipient and more.
 
39
/* .IP table
 
40
/*      A table with extracted Delivered-To: addresses.
 
41
/* .IP address
 
42
/*      A recipient address, internal form.
 
43
/* DIAGNOSTICS
 
44
/*      Fatal errors: out of memory.
 
45
/* SEE ALSO
 
46
/* LICENSE
 
47
/* .ad
 
48
/* .fi
 
49
/*      The Secure Mailer license must be distributed with this software.
 
50
/* AUTHOR(S)
 
51
/*      Wietse Venema
 
52
/*      IBM T.J. Watson Research
 
53
/*      P.O. Box 704
 
54
/*      Yorktown Heights, NY 10598, USA
 
55
/*--*/
 
56
 
 
57
/* System library. */
 
58
 
 
59
#include <sys_defs.h>
 
60
#include <unistd.h>
 
61
#include <string.h>
 
62
#include <ctype.h>
 
63
 
 
64
/* Utility library. */
 
65
 
 
66
#include <msg.h>
 
67
#include <htable.h>
 
68
#include <vstring.h>
 
69
#include <vstream.h>
 
70
#include <vstring_vstream.h>
 
71
#include <stringops.h>
 
72
 
 
73
/* Global library. */
 
74
 
 
75
#include <record.h>
 
76
#include <rec_type.h>
 
77
#include <is_header.h>
 
78
#include <quote_822_local.h>
 
79
#include <header_opts.h>
 
80
 
 
81
/* Application-specific. */
 
82
 
 
83
#include "local.h"
 
84
 
 
85
static VSTRING *buf;
 
86
 
 
87
#define STR vstring_str
 
88
 
 
89
/* delivered_init - extract delivered-to information from the message */
 
90
 
 
91
HTABLE *delivered_init(DELIVER_ATTR attr)
 
92
{
 
93
    char   *cp;
 
94
    HTABLE *table = htable_create(0);
 
95
    HEADER_OPTS *hdr;
 
96
 
 
97
    if (buf == 0)
 
98
        buf = vstring_alloc(10);
 
99
 
 
100
    if (vstream_fseek(attr.fp, attr.offset, SEEK_SET) < 0)
 
101
        msg_fatal("seek queue file %s: %m", VSTREAM_PATH(attr.fp));
 
102
 
 
103
    /*
 
104
     * XXX Assume that normal mail systems produce headers that fit in a
 
105
     * REC_TYPE_NORM record. Lowercase the delivered-to addresses for
 
106
     * consistency.
 
107
     */
 
108
    while (rec_get(attr.fp, buf, 0) == REC_TYPE_NORM) {
 
109
        if (is_header(STR(buf))) {
 
110
            if ((hdr = header_opts_find(STR(buf))) != 0
 
111
                && hdr->type == HDR_DELIVERED_TO) {
 
112
                cp = STR(buf) + strlen(hdr->name) + 1;
 
113
                while (ISSPACE(*cp))
 
114
                    cp++;
 
115
                lowercase(cp);
 
116
                if (msg_verbose)
 
117
                    msg_info("delivered_init: %s", cp);
 
118
                htable_enter(table, cp, (char *) 0);
 
119
            }
 
120
        } else if (ISSPACE(STR(buf)[0])) {
 
121
            continue;
 
122
        } else {
 
123
            break;
 
124
        }
 
125
    }
 
126
    return (table);
 
127
}
 
128
 
 
129
/* delivered_find - look up recipient in delivered table */
 
130
 
 
131
int     delivered_find(HTABLE *table, char *address)
 
132
{
 
133
    HTABLE_INFO *ht;
 
134
 
 
135
    /*
 
136
     * mail_copy() uses quote_822_local() when writing the Delivered-To:
 
137
     * header. We must therefore apply the same transformation when looking
 
138
     * up the recipient. Lowercase the delivered-to address for consistency.
 
139
     */
 
140
    quote_822_local(buf, address);
 
141
    lowercase(STR(buf));
 
142
    ht = htable_locate(table, STR(buf));
 
143
    return (ht != 0);
 
144
}