1 // Copyright Oryx Mail Systems GmbH. All enquiries to info@oryx.com, please.
3 #include "saslconnection.h"
15 /*! \class SaslConnection saslconnection.h
16 A connection that can engage in a SASL negotiation.
19 /*! Creates an Inactive \a type connection using \a fd. */
21 SaslConnection::SaslConnection( int fd, Type type )
22 : Connection( fd, type )
27 /*! Obligatory virtual destructor. */
29 SaslConnection::~SaslConnection()
34 /*! \fn virtual void SaslConnection::sendChallenge( const EString & s ) = 0
36 This virtual function must be defined by SaslConnection subclasses.
37 It is called by a SaslMechanism to send the challenge \a s, and is
38 responsible for enqueue()ing a correctly-encoded version of it.
42 /*! Returns a pointer to the authenticated User for this Connection, or
43 0 if a user has not yet been authenticated.
46 User * SaslConnection::user() const
52 /*! Informs this Connection that \a user has been authenticated using
53 the named \a mechanism. After a call to this function, user() will
54 return the specified \a user.
57 void SaslConnection::setUser( User * user, const EString & mechanism )
65 /*! This reimplementation logs the connection in the connections table
66 and cancels any other queries still running.
68 If the connection is closed as part of server shutdown, then it's
69 probably too late to execute a new Query. We're tolerant of that.
72 void SaslConnection::close()
74 if ( state() == Invalid )
77 Endpoint client = peer();
80 Database::cancelQueries( log() );
82 if ( !u || client.protocol() == Endpoint::Unix ||
83 !Configuration::toggle( Configuration::Security ) )
86 Query * q = new Query(
87 "insert into connections "
88 "(userid,address,port,mechanism,authfailures,"
89 "syntaxerrors,started_at,ended_at) "
90 "values ($1,$2,$3,$4,$5,$6,"
91 "$7::interval + 'epoch'::timestamptz,"
92 "$8::interval + 'epoch'::timestamptz)", 0
95 q->bind( 1, u->id() );
96 q->bind( 2, client.address() );
97 q->bind( 3, client.port() );
102 q->bind( 8, (uint)time( 0 ) );
107 /*! Used to count authentication failures for logging and
111 void SaslConnection::recordAuthenticationFailure()
117 /*! Used to count protocol syntax errors for logging and
121 void SaslConnection::recordSyntaxError()