From: Ralf Haferkamp Date: Wed, 20 Apr 2005 12:57:51 +0000 (+0000) Subject: improved error reporting X-Git-Tag: OPENLDAP_AC_BP~867 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=00c7cf396ba33378f15b33976d4e9482827e608d;p=openldap improved error reporting --- diff --git a/contrib/ldapc++/src/LDAPAsynConnection.cpp b/contrib/ldapc++/src/LDAPAsynConnection.cpp index 74011169f5..58b6056576 100644 --- a/contrib/ldapc++/src/LDAPAsynConnection.cpp +++ b/contrib/ldapc++/src/LDAPAsynConnection.cpp @@ -56,8 +56,11 @@ void LDAPAsynConnection::init(const string& hostname, int port){ ldap_set_option(cur_session, LDAP_OPT_PROTOCOL_VERSION, &opt); } -int LDAPAsynConnection::start_tls(){ - return ldap_start_tls_s( cur_session, NULL, NULL ); +void LDAPAsynConnection::start_tls(){ + int resCode; + if( ldap_start_tls_s( cur_session, NULL, NULL ) != LDAP_SUCCESS ) { + throw LDAPException(this); + } } LDAPMessageQueue* LDAPAsynConnection::bind(const string& dn, diff --git a/contrib/ldapc++/src/LDAPAsynConnection.h b/contrib/ldapc++/src/LDAPAsynConnection.h index ed217d01cd..acd8151483 100644 --- a/contrib/ldapc++/src/LDAPAsynConnection.h +++ b/contrib/ldapc++/src/LDAPAsynConnection.h @@ -92,10 +92,11 @@ class LDAPAsynConnection{ /** * Start TLS on this connection. This isn't in the constructor, * because it could fail (i.e. server doesn't have SSL cert, client - * api wasn't compiled against OpenSSL, etc.). If you need TLS, - * then you should error if this call fails with an error code. + * api wasn't compiled against OpenSSL, etc.). + * @throws LDAPException if the TLS Layer could not be setup + * correctly */ - int start_tls(); + void start_tls(); /** Simple authentication to a LDAP-Server * diff --git a/contrib/ldapc++/src/LDAPConnection.cpp b/contrib/ldapc++/src/LDAPConnection.cpp index 3dde845890..5facda9b6f 100644 --- a/contrib/ldapc++/src/LDAPConnection.cpp +++ b/contrib/ldapc++/src/LDAPConnection.cpp @@ -25,8 +25,8 @@ LDAPConnection::LDAPConnection(const string& hostname, int port, LDAPConnection::~LDAPConnection(){ } -int LDAPConnection::start_tls(){ - return LDAPAsynConnection::start_tls(); +void LDAPConnection::start_tls(){ + LDAPAsynConnection::start_tls(); } void LDAPConnection::bind(const string& dn, const string& passwd, @@ -50,9 +50,10 @@ void LDAPConnection::bind(const string& dn, const string& passwd, delete msg; throw LDAPReferralException(urls); }else{ + string srvMsg = res->getErrMsg(); delete res; delete msg; - throw LDAPException(resCode); + throw LDAPException(resCode, srvMsg); } } delete res; @@ -97,9 +98,10 @@ bool LDAPConnection::compare(const string& dn, const LDAPAttribute& attr, } break; default : + string srvMsg = res->getErrMsg(); delete res; delete msg; - throw LDAPException(resCode); + throw LDAPException(resCode, srvMsg); } } @@ -130,9 +132,10 @@ void LDAPConnection::del(const string& dn, const LDAPConstraints* cons){ } break; default : + string srvMsg = res->getErrMsg(); delete res; delete msg; - throw LDAPException(resCode); + throw LDAPException(resCode, srvMsg); } } @@ -164,9 +167,10 @@ void LDAPConnection::add(const LDAPEntry* le, const LDAPConstraints* cons){ } break; default : + string srvMsg = res->getErrMsg(); delete res; delete msg; - throw LDAPException(resCode); + throw LDAPException(resCode, srvMsg); } } @@ -201,7 +205,7 @@ void LDAPConnection::modify(const string& dn, const LDAPModList* mods, string srvMsg = res->getErrMsg(); delete res; delete msg; - throw LDAPException(resCode,srvMsg); + throw LDAPException(resCode, srvMsg); } } @@ -236,9 +240,10 @@ void LDAPConnection::rename(const string& dn, const string& newRDN, } break; default : + string srvMsg = res->getErrMsg(); delete res; delete msg; - throw LDAPException(resCode); + throw LDAPException(resCode, srvMsg); } } @@ -278,10 +283,11 @@ LDAPSearchResults* LDAPConnection::search(const string& base, int scope, } break; default : + string srvMsg = res->getErrMsg(); delete results; // memcheck delete res; delete msgq; - throw LDAPException(resCode); + throw LDAPException(resCode, srvMsg); } } return 0; @@ -314,9 +320,10 @@ LDAPExtResult* LDAPConnection::extOperation(const string& oid, } break; default : + string srvMsg = res->getErrMsg(); delete res; delete msg; - throw LDAPException(resCode); + throw LDAPException(resCode, srvMsg); } } diff --git a/contrib/ldapc++/src/LDAPConnection.h b/contrib/ldapc++/src/LDAPConnection.h index b18842d88e..3f4d6f4a52 100644 --- a/contrib/ldapc++/src/LDAPConnection.h +++ b/contrib/ldapc++/src/LDAPConnection.h @@ -71,10 +71,11 @@ class LDAPConnection : private LDAPAsynConnection { /** * Start TLS on this connection. This isn't in the constructor, * because it could fail (i.e. server doesn't have SSL cert, client - * api wasn't compiled against OpenSSL, etc.). If you need TLS, - * then you should error if this call fails with an error code. + * api wasn't compiled against OpenSSL, etc.). + * @throws LDAPException if the TLS Layer could not be setup + * correctly */ - int start_tls(); + void start_tls(); /** * Performs a simple authentication with the server diff --git a/contrib/ldapc++/src/LDAPException.cpp b/contrib/ldapc++/src/LDAPException.cpp index 26dcbe47ff..5038df613b 100644 --- a/contrib/ldapc++/src/LDAPException.cpp +++ b/contrib/ldapc++/src/LDAPException.cpp @@ -15,19 +15,19 @@ using namespace std; LDAPException::LDAPException(int res_code, const string& err_string){ - m_res_code=res_code; - m_res_string=string(ldap_err2string(res_code)); + m_res_code=res_code; + m_res_string=string(ldap_err2string(res_code)); m_err_string=err_string; } LDAPException::LDAPException(const LDAPAsynConnection *lc){ - m_err_string=string(); - m_res_string=string(); - LDAP *l = lc->getSessionHandle(); - ldap_get_option(l,LDAP_OPT_ERROR_NUMBER,&m_res_code); - m_res_string=string(ldap_err2string(m_res_code)); + m_err_string=string(); + m_res_string=string(); + LDAP *l = lc->getSessionHandle(); + ldap_get_option(l,LDAP_OPT_ERROR_NUMBER,&m_res_code); + m_res_string=string(ldap_err2string(m_res_code)); char* err_string; - ldap_get_option(l,LDAP_OPT_ERROR_STRING,&err_string); + ldap_get_option(l,LDAP_OPT_ERROR_STRING,&err_string); m_err_string=string(err_string); } @@ -35,11 +35,11 @@ LDAPException::~LDAPException(){ } int LDAPException::getResultCode() const{ - return m_res_code; + return m_res_code; } const string& LDAPException::getResultMsg() const{ - return m_res_string; + return m_res_string; } const string& LDAPException::getServerMsg() const{