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

« back to all changes in this revision

Viewing changes to src/cleanup/cleanup_addr.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
/*      cleanup_addr 3
 
4
/* SUMMARY
 
5
/*      process envelope addresses
 
6
/* SYNOPSIS
 
7
/*      #include <cleanup.h>
 
8
/*
 
9
/*      void    cleanup_addr_sender(state, addr)
 
10
/*      CLEANUP_STATE *state;
 
11
/*      const char *addr;
 
12
/*
 
13
/*      void    cleanup_addr_recipient(state, addr)
 
14
/*      CLEANUP_STATE *state;
 
15
/*      const char *addr;
 
16
/*
 
17
/*      void    cleanup_addr_bcc(state, addr)
 
18
/*      CLEANUP_STATE *state;
 
19
/*      const char *addr;
 
20
/* DESCRIPTION
 
21
/*      This module processes envelope address records and writes the result
 
22
/*      to the queue file. Processing includes address rewriting and
 
23
/*      sender/recipient auto bcc address generation.
 
24
/*
 
25
/*      cleanup_addr_sender() processes sender envelope information and updates
 
26
/*      state->sender.
 
27
/*
 
28
/*      cleanup_addr_recipient() processes recipient envelope information
 
29
/*      and updates state->recip.
 
30
/*
 
31
/*      cleanup_addr_bcc() processes recipient envelope information. This
 
32
/*      is a separate function to avoid invoking cleanup_addr_recipient()
 
33
/*      recursively.
 
34
/*
 
35
/*      Arguments:
 
36
/* .IP state
 
37
/*      Queue file and message processing state. This state is updated
 
38
/*      as records are processed and as errors happen.
 
39
/* .IP buf
 
40
/*      Record content.
 
41
/* LICENSE
 
42
/* .ad
 
43
/* .fi
 
44
/*      The Secure Mailer license must be distributed with this software.
 
45
/* AUTHOR(S)
 
46
/*      Wietse Venema
 
47
/*      IBM T.J. Watson Research
 
48
/*      P.O. Box 704
 
49
/*      Yorktown Heights, NY 10598, USA
 
50
/*--*/
 
51
 
 
52
/* System library. */
 
53
 
 
54
#include <sys_defs.h>
 
55
#include <string.h>
 
56
#include <stdlib.h>
 
57
 
 
58
#ifdef STRCASECMP_IN_STRINGS_H
 
59
#include <strings.h>
 
60
#endif
 
61
 
 
62
/* Utility library. */
 
63
 
 
64
#include <msg.h>
 
65
#include <vstring.h>
 
66
#include <vstream.h>
 
67
#include <mymalloc.h>
 
68
#include <stringops.h>
 
69
 
 
70
/* Global library. */
 
71
 
 
72
#include <rec_type.h>
 
73
#include <cleanup_user.h>
 
74
#include <mail_params.h>
 
75
#include <ext_prop.h>
 
76
#include <mail_addr.h>
 
77
#include <canon_addr.h>
 
78
#include <mail_addr_find.h>
 
79
 
 
80
/* Application-specific. */
 
81
 
 
82
#include "cleanup.h"
 
83
 
 
84
#define STR                     vstring_str
 
85
#define IGNORE_EXTENSION        (char **) 0
 
86
 
 
87
/* cleanup_addr_sender - process envelope sender record */
 
88
 
 
89
void    cleanup_addr_sender(CLEANUP_STATE *state, const char *buf)
 
90
{
 
91
    VSTRING *clean_addr = vstring_alloc(100);
 
92
    const char *bcc;
 
93
 
 
94
    cleanup_rewrite_internal(clean_addr, buf);
 
95
    if (strncasecmp(STR(clean_addr), MAIL_ADDR_MAIL_DAEMON "@",
 
96
                    sizeof(MAIL_ADDR_MAIL_DAEMON)) == 0) {
 
97
        canon_addr_internal(state->temp1, MAIL_ADDR_MAIL_DAEMON);
 
98
        if (strcasecmp(STR(clean_addr), STR(state->temp1)) == 0)
 
99
            vstring_strcpy(clean_addr, "");
 
100
    }
 
101
    if (state->flags & CLEANUP_FLAG_MAP_OK) {
 
102
        if (cleanup_send_canon_maps)
 
103
            cleanup_map11_internal(state, clean_addr, cleanup_send_canon_maps,
 
104
                                cleanup_ext_prop_mask & EXT_PROP_CANONICAL);
 
105
        if (cleanup_comm_canon_maps)
 
106
            cleanup_map11_internal(state, clean_addr, cleanup_comm_canon_maps,
 
107
                                cleanup_ext_prop_mask & EXT_PROP_CANONICAL);
 
108
        if (cleanup_masq_domains
 
109
            && (cleanup_masq_flags & CLEANUP_MASQ_FLAG_ENV_FROM))
 
110
            cleanup_masquerade_internal(clean_addr, cleanup_masq_domains);
 
111
    }
 
112
    CLEANUP_OUT_BUF(state, REC_TYPE_FROM, clean_addr);
 
113
    if (state->sender == 0)
 
114
        state->sender = mystrdup(STR(clean_addr));
 
115
    if ((state->flags & CLEANUP_FLAG_BCC_OK)
 
116
        && *STR(clean_addr)
 
117
        && cleanup_send_bcc_maps
 
118
        && (bcc = mail_addr_find(cleanup_send_bcc_maps, STR(clean_addr),
 
119
                                 IGNORE_EXTENSION)) != 0)
 
120
        cleanup_addr_bcc(state, bcc);
 
121
    vstring_free(clean_addr);
 
122
}
 
123
 
 
124
/* cleanup_addr_recipient - process envelope recipient */
 
125
 
 
126
void    cleanup_addr_recipient(CLEANUP_STATE *state, const char *buf)
 
127
{
 
128
    VSTRING *clean_addr = vstring_alloc(100);
 
129
    const char *bcc;
 
130
 
 
131
    cleanup_rewrite_internal(clean_addr, *buf ? buf : var_empty_addr);
 
132
    if (state->flags & CLEANUP_FLAG_MAP_OK) {
 
133
        if (cleanup_rcpt_canon_maps)
 
134
            cleanup_map11_internal(state, clean_addr, cleanup_rcpt_canon_maps,
 
135
                                cleanup_ext_prop_mask & EXT_PROP_CANONICAL);
 
136
        if (cleanup_comm_canon_maps)
 
137
            cleanup_map11_internal(state, clean_addr, cleanup_comm_canon_maps,
 
138
                                cleanup_ext_prop_mask & EXT_PROP_CANONICAL);
 
139
        if (cleanup_masq_domains
 
140
            && (cleanup_masq_flags & CLEANUP_MASQ_FLAG_ENV_RCPT))
 
141
            cleanup_masquerade_internal(clean_addr, cleanup_masq_domains);
 
142
    }
 
143
    cleanup_out_recipient(state, state->orig_rcpt, STR(clean_addr));
 
144
    if (state->recip == 0)
 
145
        state->recip = mystrdup(STR(clean_addr));
 
146
    if ((state->flags & CLEANUP_FLAG_BCC_OK)
 
147
        && *STR(clean_addr)
 
148
        && cleanup_rcpt_bcc_maps
 
149
        && (bcc = mail_addr_find(cleanup_rcpt_bcc_maps, STR(clean_addr),
 
150
                                 IGNORE_EXTENSION)) != 0)
 
151
        cleanup_addr_bcc(state, bcc);
 
152
    vstring_free(clean_addr);
 
153
}
 
154
 
 
155
/* cleanup_addr_bcc - process automatic BCC recipient */
 
156
 
 
157
void    cleanup_addr_bcc(CLEANUP_STATE *state, const char *bcc)
 
158
{
 
159
    VSTRING *clean_addr = vstring_alloc(100);
 
160
 
 
161
    cleanup_rewrite_internal(clean_addr, bcc);
 
162
    if (state->flags & CLEANUP_FLAG_MAP_OK) {
 
163
        if (cleanup_rcpt_canon_maps)
 
164
            cleanup_map11_internal(state, clean_addr, cleanup_rcpt_canon_maps,
 
165
                                cleanup_ext_prop_mask & EXT_PROP_CANONICAL);
 
166
        if (cleanup_comm_canon_maps)
 
167
            cleanup_map11_internal(state, clean_addr, cleanup_comm_canon_maps,
 
168
                                cleanup_ext_prop_mask & EXT_PROP_CANONICAL);
 
169
        if (cleanup_masq_domains
 
170
            && (cleanup_masq_flags & CLEANUP_MASQ_FLAG_ENV_RCPT))
 
171
            cleanup_masquerade_internal(clean_addr, cleanup_masq_domains);
 
172
    }
 
173
    cleanup_out_recipient(state, STR(clean_addr), STR(clean_addr));
 
174
    vstring_free(clean_addr);
 
175
}