31 class SaslServerPamImp ;
43 bool init(
const std::string & mechanism ) ;
44 std::string apply(
const std::string & pwd ,
bool & done ) ;
45 std::string id()
const ;
46 bool authenticated()
const ;
55 unique_ptr<PamImp> m_pam ;
66 typedef GAuth::PamImp::ItemArray ItemArray ;
67 G_EXCEPTION_CLASS( NoPrompt ,
"no password prompt received from pam module" ) ;
69 PamImp(
const std::string & app ,
const std::string &
id ) ;
72 void apply(
const std::string & ) ;
73 std::string id()
const ;
76 virtual void converse( ItemArray & )
override ;
77 virtual void delay(
unsigned int usec )
override ;
81 void operator=(
const PamImp & ) ;
89 GAuth::PamImp::PamImp(
const std::string & app ,
const std::string &
id ) :
94 G_DEBUG(
"GAuth::PamImp::ctor: [" << app <<
"] [" <<
id <<
"]" ) ;
97 GAuth::PamImp::~PamImp()
101 std::string GAuth::PamImp::id()
const
109 for( ItemArray::iterator p = items.begin() ; p != items.end() ; ++p )
111 if( (*p).in_type ==
"password" )
114 (*p).out_defined = true ;
124 void GAuth::PamImp::apply(
const std::string & pwd )
127 authenticate(
true ) ;
140 GAuth::SaslServerPamImp::SaslServerPamImp(
bool active ,
bool allow_apop ) :
142 m_allow_apop(allow_apop)
146 GAuth::SaslServerPamImp::~SaslServerPamImp()
150 bool GAuth::SaslServerPamImp::active()
const
155 bool GAuth::SaslServerPamImp::init(
const std::string & mechanism )
162 std::string GAuth::SaslServerPamImp::id()
const
164 return m_pam.get() ? m_pam->id() : std::string() ;
167 std::string GAuth::SaslServerPamImp::apply(
const std::string & response ,
bool & done )
170 std::string sep( 1U ,
'\0' ) ;
171 std::string s =
G::Str::tail( response , response.find(sep) , std::string() ) ;
172 std::string
id =
G::Str::head( s , s.find(sep) , std::string() ) ;
173 std::string pwd =
G::Str::tail( s , s.find(sep) , std::string() ) ;
175 m_pam.reset(
new PamImp(
"emailrelay" ,
id ) ) ;
179 m_pam->apply( pwd ) ;
183 G_WARNING(
"GAuth::SaslServer::apply: " << e.
what() ) ;
186 catch( PamImp::NoPrompt & e )
188 G_WARNING(
"GAuth::SaslServer::apply: pam error: " << e.what() ) ;
193 return std::string() ;
225 return m_imp->active() ;
235 return m_imp->init( mechanism ) ;
240 return std::string() ;
245 return m_imp->apply( response , done ) ;
250 return !m_imp->id().empty() ;
virtual const char * what() const g__noexcept override
Override from std::exception.
static std::string tail(const std::string &in, size_type pos, const std::string &default_=std::string())
Returns the last part of the string after the given position.
virtual std::string initialChallenge() const override
Override from GAuth::SaslServer.
virtual std::string id() const override
Override from GAuth::SaslServer.
virtual bool init(const std::string &mechanism) override
Override from GAuth::SaslServer.
static std::string head(const std::string &in, size_type pos, const std::string &default_=std::string())
Returns the first part of the string up to just before the given position.
The GNet::Address class encapsulates a TCP/UDP transport address.
virtual bool requiresEncryption() const override
Override from GAuth::SaslServer.
virtual bool authenticated() const override
Override from GAuth::SaslServer.
virtual bool active() const override
Override from GAuth::SaslServer.
An interface used by GAuth::SaslServer to obtain authentication secrets.
virtual ~SaslServerPam()
Destructor.
virtual void delay(unsigned int usec) override
Called when the pam library wants the application to introduce a delay to prevent brute-force attacks...
virtual std::string mechanism() const override
Override from GAuth::SaslServer.
virtual void converse(ItemArray &) override
Called to pass a message to the user, or request a password etc.
A private implementation class used by GAuth::SaslServerPam.
static std::string upper(const std::string &s)
Returns a copy of 's' in which all Latin-1 lowercase characters have been replaced by uppercase chara...
virtual std::string apply(const std::string &response, bool &done) override
Override from GAuth::SaslServer.
A private implementation of the G::Pam interface used by GAuth::SaslServerPamImp, which is itself a p...
SaslServerPam(const SaslServerSecrets &, bool allow_apop)
Constructor.
An exception class used by G::Pam.
virtual bool trusted(const GNet::Address &) const override
Override from GAuth::SaslServer.
virtual bool mustChallenge() const override
Override from GAuth::SaslServer.
virtual std::string mechanisms(char sep= ' ') const override
Override from GAuth::SaslServer.
SASL authentication classes.
A thin interface to the system PAM library, with two pure virtual methods that derived classes should...