32 m_command(Command::RCPT) ,
35 m_result(
GSmtp::VerifierStatus::invalid({})) ,
36 m_range(G::Range::range(1000,32767))
42 m_range = G::Range::range( t() ) ;
43 else if( ( t().size() <= 3U && t().find(
'l') != std::string::npos ) || t() ==
"lowercase"_sv )
45 else if( ( t().size() <= 3U && t().find(
'r') != std::string::npos ) || t() ==
"remote"_sv )
46 m_config_remote = true ;
47 else if( ( t().size() <= 3U && t().find(
'c') != std::string::npos ) || t() ==
"check"_sv )
48 m_config_check = true ;
50 G_DEBUG(
"GVerifiers::UserVerifier: uid range " << G::Range::str(m_range) ) ;
53void GVerifiers::UserVerifier::verify( Command command ,
const std::string & rcpt_to_parameter ,
59 std::string user = dequote(
G::Str::head( dequote(rcpt_to_parameter) ,
"@" ,
false ) ) ;
60 std::string domain =
G::Str::tail( dequote(rcpt_to_parameter) ,
"@" ) ;
64 if( user ==
"postmaster" && domain.empty() )
66 else if( lookup(user,domain,&reason,&mailbox) )
70 GSmtp::VerifierStatus::local( rcpt_to_parameter , {} , m_config_lc?
G::Str::lower(mailbox):mailbox ) ;
71 else if( m_config_check )
76 m_timer.startTimer( 0U ) ;
79bool GVerifiers::UserVerifier::lookup(
const std::string & user ,
const std::string & domain ,
80 std::string * reason_p , std::string * mailbox_p )
const
83 std::ostringstream ss ;
86 ss <<
"[" << domain <<
"] does not match [" << m_config.domain <<
"]" ;
97 ss <<
"[" << user <<
"] is not a valid account name" ;
99 else if( !pair.first.match( m_range ) )
101 ss <<
"uid " << pair.first.userid() <<
" is not in the range " << G::Range::str(m_range) ;
106 *mailbox_p = pair.second ;
110 if( !result && reason_p ) *reason_p = ss.str() ;
116 return m_done_signal ;
119void GVerifiers::UserVerifier::cancel()
121 m_timer.cancelTimer() ;
124void GVerifiers::UserVerifier::onTimeout()
126 m_done_signal.emit( m_command , m_result ) ;
129std::string GVerifiers::UserVerifier::dequote(
const std::string & s )
131 if( s.size() >= 2U && s.at(0) ==
'"' && s.at(s.size()-1U) ==
'"' )
132 return s.substr( 1U , s.size()-2U ) ;
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
static VerifierStatus local(const std::string &recipient, const std::string &full_name, const std::string &mbox)
Constructor for a valid local mailbox.
static VerifierStatus invalid(const std::string &recipient, bool temporary=false, const std::string &response={}, const std::string &reason={})
Factory function for an invalid address.
static VerifierStatus remote(const std::string &recipient, const std::string &address={})
Constructor for a valid remote mailbox.
A concrete Verifier class that verifies against the password database (ie.
UserVerifier(GNet::ExceptionSink es, const GSmtp::Verifier::Config &config, const std::string &spec)
Constructor.
static Identity invalid() noexcept
Returns an invalid identity.
static std::pair< Identity, std::string > lookup(const std::string &user)
Does a username lookup returning the identity and the canonical name.
static bool isPrintableAscii(string_view s) noexcept
Returns true if every character is a 7-bit, non-control character (ie.
static bool isNumeric(string_view s, bool allow_minus_sign=false) noexcept
Returns true if every character is a decimal digit.
static bool imatch(char, char) noexcept
Returns true if the two characters are the same, ignoring seven-bit case.
static std::string lower(string_view)
Returns a copy of 's' in which all seven-bit upper-case characters have been replaced by lower-case c...
static std::string tail(string_view in, std::size_t pos, string_view default_={})
Returns the last part of the string after the given position.
static std::string head(string_view in, std::size_t pos, string_view default_={})
Returns the first part of the string up to just before the given position.
A zero-copy string token iterator where the token separators are runs of whitespace characters,...
A class like c++17's std::string_view.
Utility functions for pair-of-integer ranges.
Configuration passed to address verifier constructors.
Extra information passed to GSmtp::Verifier::verify().