11 /* void smtpd_state_init(state, stream, service)
12 /* SMTPD_STATE *state;
14 /* const char *service;
16 /* void smtpd_state_reset(state)
17 /* SMTPD_STATE *state;
19 /* smtpd_state_init() initializes session context.
21 /* smtpd_state_reset() cleans up session context.
27 /* Stream connected to peer. The stream is not copied.
29 /* All errors are fatal.
33 /* The Secure Mailer license must be distributed with this software.
36 /* IBM T.J. Watson Research
38 /* Yorktown Heights, NY 10598, USA
40 /* TLS support originally by:
43 /* Allgemeine Elektrotechnik
44 /* Universitaetsplatz 3-4
45 /* D-03044 Cottbus, Germany
52 /* Utility library. */
57 #include <name_mask.h>
62 #include <cleanup_user.h>
63 #include <mail_params.h>
64 #include <mail_error.h>
65 #include <mail_proto.h>
67 /* Application-specific. */
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
,
80 * Initialize the state information for this connection, and fill in the
81 * connection-specific fields.
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
,
97 state
->rcpt_count
= 0;
98 state
->access_denied
= 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;
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;
120 state
->expand_buf
= 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;
131 state
->saved_delay
= 0;
133 state
->instance
= vstring_alloc(10);
135 state
->rewrite_context
= 0;
137 state
->ehlo_discard_mask
= ~0;
139 state
->ehlo_discard_mask
= 0;
141 state
->dsn_envid
= 0;
142 state
->dsn_buf
= vstring_alloc(100);
143 state
->dsn_orcpt_buf
= vstring_alloc(100);
145 state
->tls_use_tls
= 0;
146 state
->tls_enforce_tls
= 0;
147 state
->tls_auth_only
= 0;
148 state
->tls_context
= 0;
152 if (SMTPD_STAND_ALONE(state
))
153 var_smtpd_sasl_enable
= 0;
154 smtpd_sasl_set_inactive(state
);
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.
187 myfree(state
->service
);
189 vstring_free(state
->buffer
);
191 vstring_free(state
->addr_buf
);
192 if (state
->access_denied
)
193 myfree(state
->access_denied
);
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
);
215 vstring_free(state
->instance
);
217 vstring_free(state
->dsn_buf
);
218 if (state
->dsn_orcpt_buf
)
219 vstring_free(state
->dsn_orcpt_buf
);