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

« back to all changes in this revision

Viewing changes to src/global/verify.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
/*      verify 3
 
4
/* SUMMARY
 
5
/*      update verify database
 
6
/* SYNOPSIS
 
7
/*      #include <verify.h>
 
8
/*
 
9
/*      int     verify_append(queue_id, orig_rcpt, recipient,
 
10
/*                              relay, entry, status,
 
11
/*                              recipient_status, format, ...)
 
12
/*      const char *queue_id;
 
13
/*      const char *orig_rcpt;
 
14
/*      const char *recipient;
 
15
/*      const char *relay;
 
16
/*      time_t  entry;
 
17
/*      const char *status;
 
18
/*      int     recipient_status;
 
19
/*      const char *format;
 
20
/*
 
21
/*      int     vverify_append(queue_id, orig_rcpt, recipient,
 
22
/*                              relay, entry, status,
 
23
/*                              recipient_status, format, ap)
 
24
/*      int     recipient_status;
 
25
/*      const char *queue_id;
 
26
/*      const char *orig_rcpt;
 
27
/*      const char *recipient;
 
28
/*      const char *relay;
 
29
/*      time_t  entry;
 
30
/*      const char *status;
 
31
/*      int     recipient_status;
 
32
/*      const char *format;
 
33
/*      va_list ap;
 
34
/* DESCRIPTION
 
35
/*      This module implements an impedance adaptor between the
 
36
/*      verify_clnt interface and the interface expected by the
 
37
/*      bounce/defer/sent modules.
 
38
/*
 
39
/*      verify_append() updates the address verification database
 
40
/*      and logs the action to the mailer logfile.
 
41
/*
 
42
/*      vverify_append() implements an alternative interface.
 
43
/*
 
44
/*      Arguments:
 
45
/* .IP queue_id
 
46
/*      The message queue id.
 
47
/* .IP orig_rcpt
 
48
/*      The original envelope recipient address. If unavailable,
 
49
/*      specify a null string or a null pointer.
 
50
/* .IP recipient
 
51
/*      The recipient address.
 
52
/* .IP relay
 
53
/*      Name of the host we're talking to.
 
54
/* .IP entry
 
55
/*      Message arrival time.
 
56
/* .IP status
 
57
/*      "deliverable", "undeliverable", and so on.
 
58
/* .IP recipient_status
 
59
/*      One of the following recipient verification status codes:
 
60
/* .RS
 
61
/* .IP DEL_REQ_RCPT_STAT_OK
 
62
/*      Successful delivery.
 
63
/* .IP DEL_REQ_RCPT_STAT_DEFER
 
64
/*      Temporary delivery error.
 
65
/* .IP DEL_REQ_RCPT_STAT_BOUNCE
 
66
/*      Hard delivery error.
 
67
/* .RE
 
68
/* .IP format
 
69
/*      Optional additional information.
 
70
/* DIAGNOSTICS
 
71
/*      A non-zero result means the operation failed.
 
72
/*
 
73
/*      Fatal: out of memory.
 
74
/* BUGS
 
75
/*      Should be replaced by routines with an attribute-value based
 
76
/*      interface instead of an interface that uses a rigid argument list.
 
77
/* LICENSE
 
78
/* .ad
 
79
/* .fi
 
80
/*      The Secure Mailer license must be distributed with this software.
 
81
/* AUTHOR(S)
 
82
/*      Wietse Venema
 
83
/*      IBM T.J. Watson Research
 
84
/*      P.O. Box 704
 
85
/*      Yorktown Heights, NY 10598, USA
 
86
/*--*/
 
87
 
 
88
/* System library. */
 
89
 
 
90
#include <sys_defs.h>
 
91
#include <stdio.h>
 
92
#include <stdlib.h>                     /* 44BSD stdarg.h uses abort() */
 
93
#include <stdarg.h>
 
94
#include <string.h>
 
95
 
 
96
#ifdef STRCASECMP_IN_STRINGS_H
 
97
#include <strings.h>
 
98
#endif
 
99
 
 
100
/* Utility library. */
 
101
 
 
102
#include <msg.h>
 
103
#include <vstring.h>
 
104
 
 
105
/* Global library. */
 
106
 
 
107
#include <mail_params.h>
 
108
#include <mail_proto.h>
 
109
#include <verify_clnt.h>
 
110
#include <log_adhoc.h>
 
111
#include <verify.h>
 
112
 
 
113
/* verify_append - update address verification database */
 
114
 
 
115
int     verify_append(const char *queue_id, const char *orig_rcpt,
 
116
                             const char *recipient, const char *relay,
 
117
                             time_t entry, const char *status,
 
118
                             int rcpt_stat, const char *fmt,...)
 
119
{
 
120
    va_list ap;
 
121
    int     req_stat;
 
122
 
 
123
    va_start(ap, fmt);
 
124
    req_stat = vverify_append(queue_id, orig_rcpt, recipient, relay,
 
125
                             entry, status, rcpt_stat, fmt, ap);
 
126
    va_end(ap);
 
127
    return (req_stat);
 
128
}
 
129
 
 
130
/* vverify_append - update address verification database */
 
131
 
 
132
int     vverify_append(const char *queue_id, const char *orig_rcpt,
 
133
                              const char *recipient, const char *relay,
 
134
                              time_t entry, const char *status,
 
135
                              int rcpt_stat, const char *fmt, va_list ap)
 
136
{
 
137
    VSTRING *text = vstring_alloc(10);
 
138
    int     req_stat;
 
139
 
 
140
    /*
 
141
     * Impedance adaptor between bounce/defer/sent and verify_clnt.
 
142
     */
 
143
    vstring_vsprintf(text, fmt, ap);
 
144
    if (var_verify_neg_cache || rcpt_stat == DEL_RCPT_STAT_OK) {
 
145
        req_stat = verify_clnt_update(orig_rcpt, rcpt_stat,
 
146
                                      "%s", vstring_str(text));
 
147
        if (req_stat == VRFY_STAT_OK && strcasecmp(recipient, orig_rcpt) != 0)
 
148
            req_stat = verify_clnt_update(recipient, rcpt_stat,
 
149
                                          "%s", vstring_str(text));
 
150
    } else {
 
151
        status = "undeliverable-but-not-cached";
 
152
        req_stat = VRFY_STAT_OK;
 
153
    }
 
154
    if (req_stat == VRFY_STAT_OK) {
 
155
        log_adhoc(queue_id, orig_rcpt, recipient, relay,
 
156
                  entry, status, "%s", vstring_str(text));
 
157
        req_stat = 0;
 
158
    } else {
 
159
        msg_warn("%s: %s service failure", queue_id, var_verify_service);
 
160
        req_stat = -1;
 
161
    }
 
162
    vstring_free(text);
 
163
    return (req_stat);
 
164
}