No empty .Rs/.Re
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / smtpd / smtpd_state.c
blob537b9b76cf94da0b08248ff1d431325f2c51ac68
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* smtpd_state 3
6 /* SUMMARY
7 /* Postfix SMTP server
8 /* SYNOPSIS
9 /* #include "smtpd.h"
11 /* void smtpd_state_init(state, stream, service)
12 /* SMTPD_STATE *state;
13 /* VSTREAM *stream;
14 /* const char *service;
16 /* void smtpd_state_reset(state)
17 /* SMTPD_STATE *state;
18 /* DESCRIPTION
19 /* smtpd_state_init() initializes session context.
21 /* smtpd_state_reset() cleans up session context.
23 /* Arguments:
24 /* .IP state
25 /* Session context.
26 /* .IP stream
27 /* Stream connected to peer. The stream is not copied.
28 /* DIAGNOSTICS
29 /* All errors are fatal.
30 /* LICENSE
31 /* .ad
32 /* .fi
33 /* The Secure Mailer license must be distributed with this software.
34 /* AUTHOR(S)
35 /* Wietse Venema
36 /* IBM T.J. Watson Research
37 /* P.O. Box 704
38 /* Yorktown Heights, NY 10598, USA
40 /* TLS support originally by:
41 /* Lutz Jaenicke
42 /* BTU Cottbus
43 /* Allgemeine Elektrotechnik
44 /* Universitaetsplatz 3-4
45 /* D-03044 Cottbus, Germany
46 /*--*/
48 /* System library. */
50 #include <sys_defs.h>
52 /* Utility library. */
54 #include <events.h>
55 #include <mymalloc.h>
56 #include <vstream.h>
57 #include <name_mask.h>
58 #include <msg.h>
60 /* Global library. */
62 #include <cleanup_user.h>
63 #include <mail_params.h>
64 #include <mail_error.h>
65 #include <mail_proto.h>
67 /* Application-specific. */
69 #include "smtpd.h"
70 #include "smtpd_chat.h"
71 #include "smtpd_sasl_glue.h"
73 /* smtpd_state_init - initialize after connection establishment */
75 void smtpd_state_init(SMTPD_STATE *state, VSTREAM *stream,
76 const char *service)
80 * Initialize the state information for this connection, and fill in the
81 * connection-specific fields.
83 state->flags = 0;
84 state->err = CLEANUP_STAT_OK;
85 state->client = stream;
86 state->service = mystrdup(service);
87 state->buffer = vstring_alloc(100);
88 state->addr_buf = vstring_alloc(100);
89 state->error_count = 0;
90 state->error_mask = 0;
91 state->notify_mask = name_mask(VAR_NOTIFY_CLASSES, mail_error_masks,
92 var_notify_classes);
93 state->helo_name = 0;
94 state->queue_id = 0;
95 state->cleanup = 0;
96 state->dest = 0;
97 state->rcpt_count = 0;
98 state->access_denied = 0;
99 state->history = 0;
100 state->reason = 0;
101 state->sender = 0;
102 state->verp_delims = 0;
103 state->recipient = 0;
104 state->etrn_name = 0;
105 state->protocol = mystrdup(MAIL_PROTO_SMTP);
106 state->where = SMTPD_AFTER_CONNECT;
107 state->recursion = 0;
108 state->msg_size = 0;
109 state->act_size = 0;
110 state->junk_cmds = 0;
111 state->rcpt_overshoot = 0;
112 state->defer_if_permit_client = 0;
113 state->defer_if_permit_helo = 0;
114 state->defer_if_permit_sender = 0;
115 state->defer_if_reject.dsn = 0;
116 state->defer_if_reject.reason = 0;
117 state->defer_if_permit.dsn = 0;
118 state->defer_if_permit.reason = 0;
119 state->discard = 0;
120 state->expand_buf = 0;
121 state->prepend = 0;
122 state->proxy = 0;
123 state->proxy_buffer = 0;
124 state->proxy_mail = 0;
125 state->proxy_xforward_features = 0;
126 state->saved_filter = 0;
127 state->saved_redirect = 0;
128 state->saved_bcc = 0;
129 state->saved_flags = 0;
130 #ifdef DELAY_ACTION
131 state->saved_delay = 0;
132 #endif
133 state->instance = vstring_alloc(10);
134 state->seqno = 0;
135 state->rewrite_context = 0;
136 #if 0
137 state->ehlo_discard_mask = ~0;
138 #else
139 state->ehlo_discard_mask = 0;
140 #endif
141 state->dsn_envid = 0;
142 state->dsn_buf = vstring_alloc(100);
143 state->dsn_orcpt_buf = vstring_alloc(100);
144 #ifdef USE_TLS
145 state->tls_use_tls = 0;
146 state->tls_enforce_tls = 0;
147 state->tls_auth_only = 0;
148 state->tls_context = 0;
149 #endif
151 #ifdef USE_SASL_AUTH
152 if (SMTPD_STAND_ALONE(state))
153 var_smtpd_sasl_enable = 0;
154 smtpd_sasl_set_inactive(state);
155 #endif
157 state->milter_argv = 0;
158 state->milter_argc = 0;
161 * Initialize peer information.
163 smtpd_peer_init(state);
166 * Initialize xforward information.
168 smtpd_xforward_init(state);
171 * Initialize the conversation history.
173 smtpd_chat_reset(state);
176 /* smtpd_state_reset - cleanup after disconnect */
178 void smtpd_state_reset(SMTPD_STATE *state)
182 * When cleaning up, touch only those fields that smtpd_state_init()
183 * filled in. The other fields are taken care of by their own
184 * "destructor" functions.
186 if (state->service)
187 myfree(state->service);
188 if (state->buffer)
189 vstring_free(state->buffer);
190 if (state->addr_buf)
191 vstring_free(state->addr_buf);
192 if (state->access_denied)
193 myfree(state->access_denied);
194 if (state->protocol)
195 myfree(state->protocol);
196 smtpd_peer_reset(state);
199 * Buffers that are created on the fly and that may be shared among mail
200 * deliveries within the same SMTP session.
202 if (state->defer_if_permit.dsn)
203 vstring_free(state->defer_if_permit.dsn);
204 if (state->defer_if_permit.reason)
205 vstring_free(state->defer_if_permit.reason);
206 if (state->defer_if_reject.dsn)
207 vstring_free(state->defer_if_reject.dsn);
208 if (state->defer_if_reject.reason)
209 vstring_free(state->defer_if_reject.reason);
210 if (state->expand_buf)
211 vstring_free(state->expand_buf);
212 if (state->proxy_buffer)
213 vstring_free(state->proxy_buffer);
214 if (state->instance)
215 vstring_free(state->instance);
216 if (state->dsn_buf)
217 vstring_free(state->dsn_buf);
218 if (state->dsn_orcpt_buf)
219 vstring_free(state->dsn_orcpt_buf);