21#ifndef G_SMTP_SERVER_PROTOCOL_H
22#define G_SMTP_SERVER_PROTOCOL_H
39 class ServerProtocol ;
40 class ServerProtocolText ;
58 G_EXCEPTION( ProtocolDone ,
"smtp protocol done" ) ;
63 virtual void protocolSend(
const std::string & s ,
bool go_secure ) = 0 ;
82 virtual std::string
hello(
const std::string & smtp_peer_name )
const = 0 ;
85 virtual std::string
received(
const std::string & smtp_peer_name ,
bool auth ,
bool secure ,
86 const std::string & protocol ,
const std::string & cipher )
const = 0 ;
95 bool with_vrfy{
false} ;
96 unsigned int filter_timeout{0U} ;
97 std::size_t max_size{0U} ;
98 bool authentication_requires_encryption{
false} ;
99 bool mail_requires_encryption{
false} ;
100 bool disconnect_on_max_size{
false} ;
101 bool tls_starttls{
false} ;
102 bool tls_connection{
false} ;
103 bool ignore_eager_quit{
false} ;
104 bool allow_pipelining{
false} ;
107 Config(
bool with_vrfy ,
unsigned int filter_timeout , std::size_t max_size ,
108 bool authentication_requires_encryption ,
109 bool mail_requires_encryption ,
111 bool tls_connection ) ;
112 Config & set_with_vrfy(
bool =
true ) ;
113 Config & set_filter_timeout(
unsigned int ) ;
114 Config & set_max_size( std::size_t ) ;
115 Config & set_authentication_requires_encryption(
bool =
true ) ;
116 Config & set_mail_requires_encryption(
bool =
true ) ;
117 Config & set_disconnect_on_max_size(
bool =
true ) ;
118 Config & set_tls_starttls(
bool =
true ) ;
119 Config & set_tls_connection(
bool =
true ) ;
120 Config & set_ignore_eager_quit(
bool =
true ) ;
121 Config & set_allow_pipelining(
bool =
true ) ;
172 bool apply(
const char * line_data , std::size_t line_size , std::size_t eolsize , std::size_t linesize ,
char c0 ) ;
179 void secure(
const std::string & certificate ,
const std::string & protocol ,
const std::string & cipher ) ;
232 std::size_t eolsize ;
233 std::size_t linesize ;
236 EventData(
const char * ptr , std::size_t size ) ;
237 EventData(
const char * ptr , std::size_t size , std::size_t eolsize , std::size_t linesize ,
char c0 ) ;
248 void send(
const char * ) ;
249 void send( std::string ,
bool =
false ) ;
250 Event commandEvent(
const std::string & )
const ;
251 std::string commandWord(
const std::string & line )
const ;
252 std::string commandLine(
const std::string & line )
const ;
253 static const std::string & crlf() ;
254 bool authenticationRequiresEncryption()
const ;
256 void badClientEvent() ;
257 void processDone(
bool ,
const MessageId & ,
const std::string & ,
const std::string & ) ;
258 void prepareDone(
bool ,
bool , std::string ) ;
259 bool isEndOfText(
const EventData & )
const ;
260 bool isEscaped(
const EventData & )
const ;
261 void doNoop( EventData ,
bool & ) ;
262 void doIgnore( EventData ,
bool & ) ;
263 void doNothing( EventData ,
bool & ) ;
264 void doDiscarded( EventData ,
bool & ) ;
265 void doDiscard( EventData ,
bool & ) ;
266 void doHelp( EventData ,
bool & ) ;
267 void doExpn( EventData ,
bool & ) ;
268 void doEagerQuit( EventData ,
bool & ) ;
269 void doQuit( EventData ,
bool & ) ;
270 void doEhlo( EventData ,
bool & ) ;
271 void doHelo( EventData ,
bool & ) ;
272 void sendReadyForTls() ;
273 void sendBadMechanism() ;
274 void doAuthInvalid( EventData ,
bool & ) ;
275 void doAuth( EventData ,
bool & ) ;
276 void doAuthData( EventData ,
bool & ) ;
277 void doMail( EventData ,
bool & ) ;
278 void doRcpt( EventData ,
bool & ) ;
279 void doUnknown( EventData ,
bool & ) ;
280 void doRset( EventData ,
bool & ) ;
281 void doData( EventData ,
bool & ) ;
282 void doContent( EventData ,
bool & ) ;
283 void doComplete( EventData ,
bool & ) ;
284 void doEot( EventData ,
bool & ) ;
285 void doVrfy( EventData ,
bool & ) ;
286 void doVrfyReply( EventData ,
bool & ) ;
287 void doVrfyToReply( EventData ,
bool & ) ;
288 void doNoRecipients( EventData ,
bool & ) ;
289 void doStartTls( EventData ,
bool & ) ;
290 void doSecure( EventData ,
bool & ) ;
291 void doSecureGreeting( EventData ,
bool & ) ;
292 void verifyDone(
const VerifierStatus & ) ;
293 void sendBadFrom(
const std::string & ) ;
294 void sendTooBig(
bool disconnecting =
false ) ;
295 void sendChallenge(
const std::string & ) ;
296 void sendBadTo(
const std::string & ,
bool ) ;
297 void sendOutOfSequence() ;
298 void sendGreeting(
const std::string & ) ;
301 void sendUnrecognised(
const std::string & ) ;
302 void sendNotImplemented() ;
303 void sendHeloReply() ;
304 void sendEhloReply() ;
305 void sendRsetReply() ;
306 void sendMailReply() ;
307 void sendRcptReply() ;
308 void sendDataReply() ;
309 void sendCompletionReply(
bool ok ,
const std::string & ) ;
310 void sendInvalidArgument() ;
311 void sendAuthenticationCancelled() ;
312 void sendAuthRequired() ;
313 void sendEncryptionRequired() ;
314 void sendNoRecipients() ;
315 void sendMissingParameter() ;
316 void sendVerified(
const std::string & ) ;
317 void sendNotVerified(
const std::string & ,
bool ) ;
318 void sendWillAccept(
const std::string & ) ;
319 void sendAuthDone(
bool ok ) ;
321 std::pair<std::string,std::string> parseAddress(
const std::string & )
const ;
322 std::pair<std::string,std::string> parseMailFrom(
const std::string & )
const ;
323 std::string parseMailParameter(
const std::string & ,
const std::string & )
const ;
324 std::size_t parseMailSize(
const std::string & )
const ;
325 std::string parseMailAuth(
const std::string & )
const ;
326 std::pair<std::string,std::string> parseRcptTo(
const std::string & )
const ;
327 std::string parseRcptParameter(
const std::string & )
const ;
328 std::string parsePeerName(
const std::string & )
const ;
329 void verify(
const std::string & ,
const std::string & ) ;
333 Verifier & m_verifier ;
335 ProtocolMessage & m_message ;
336 std::unique_ptr<GAuth::SaslServer> m_sasl ;
339 bool m_with_starttls ;
342 std::string m_certificate ;
343 std::string m_protocol ;
344 std::string m_cipher ;
345 unsigned int m_bad_client_count ;
346 unsigned int m_bad_client_limit ;
347 std::string m_session_peer_name ;
348 bool m_session_authenticated ;
349 std::string m_buffer ;
363 static std::string
receivedLine(
const std::string & smtp_peer_name_from_helo ,
364 const std::string & peer_address ,
const std::string & thishost ,
365 bool authenticated ,
bool secure ,
const std::string & secure_protocol ,
366 const std::string & secure_cipher ) ;
377 std::string greeting()
const override ;
378 std::string hello(
const std::string & smtp_peer_name_from_helo )
const override ;
379 std::string received(
const std::string & ,
bool ,
bool ,
const std::string & ,
const std::string & )
const override ;
382 std::string m_code_ident ;
383 std::string m_thishost ;
388inline GSmtp::ServerProtocol::Config & GSmtp::ServerProtocol::Config::set_filter_timeout(
unsigned int t ) { filter_timeout = t ;
return *this ; }
390inline GSmtp::ServerProtocol::Config & GSmtp::ServerProtocol::Config::set_authentication_requires_encryption(
bool b ) { authentication_requires_encryption = b ;
return *this ; }
391inline GSmtp::ServerProtocol::Config & GSmtp::ServerProtocol::Config::set_mail_requires_encryption(
bool b ) { mail_requires_encryption = b ;
return *this ; }
392inline GSmtp::ServerProtocol::Config & GSmtp::ServerProtocol::Config::set_disconnect_on_max_size(
bool b ) { disconnect_on_max_size = b ;
return *this ; }
395inline GSmtp::ServerProtocol::Config & GSmtp::ServerProtocol::Config::set_allow_pipelining(
bool b ) { allow_pipelining = b ;
return *this ; }
An interface used by GAuth::SaslServer to obtain authentication secrets.
The GNet::Address class encapsulates a TCP/UDP transport address.
An interface used by the ServerProtocol class to assemble and process an incoming message.
A default implementation for the ServerProtocol::Text interface.
ServerProtocolText(const std::string &code_ident, const std::string &thishost, const GNet::Address &peer_address)
Constructor.
static std::string receivedLine(const std::string &smtp_peer_name_from_helo, const std::string &peer_address, const std::string &thishost, bool authenticated, bool secure, const std::string &secure_protocol, const std::string &secure_cipher)
Returns a standard "Received:" line.
An interface used by ServerProtocol to send protocol replies.
virtual ~Sender()=default
Destructor.
virtual void protocolShutdown()=0
Called on receipt of a quit command after the quit response has been sent allowing the socket to be s...
virtual void protocolSend(const std::string &s, bool go_secure)=0
Called when the protocol class wants to send data down the socket.
An interface used by ServerProtocol to provide response text strings.
virtual std::string greeting() const =0
Returns a system identifier for the initial greeting.
virtual std::string received(const std::string &smtp_peer_name, bool auth, bool secure, const std::string &protocol, const std::string &cipher) const =0
Returns a complete 'Received' line.
virtual ~Text()=default
Destructor.
virtual std::string hello(const std::string &smtp_peer_name) const =0
Returns a hello response.
Implements the SMTP server-side protocol.
bool apply(const char *line_data, std::size_t line_size, std::size_t eolsize, std::size_t linesize, char c0)
Called on receipt of a line of text from the remote client.
void init()
Starts the protocol.
void secure(const std::string &certificate, const std::string &protocol, const std::string &cipher)
To be called when the transport protocol goes into secure mode.
bool inDataState() const
Returns true if currently in the data-transfer state.
ServerProtocol(Sender &, Verifier &, ProtocolMessage &, const GAuth::SaslServerSecrets &secrets, const std::string &sasl_server_config, Text &text, const GNet::Address &peer_address, const Config &config)
Constructor.
bool halfDuplexBusy() const
Returns true if the protocol has received a command but not yet sent a response.
virtual ~ServerProtocol()
Destructor.
An asynchronous interface that verifies recipient 'to' addresses.
SMTP and message-store classes.
A structure containing configuration parameters for ServerProtocol.