improved error reporting

This commit is contained in:
Ralf Haferkamp 2005-04-20 12:57:51 +00:00
parent 7389cb27ed
commit 00c7cf396b
5 changed files with 40 additions and 28 deletions

View File

@ -56,8 +56,11 @@ void LDAPAsynConnection::init(const string& hostname, int port){
ldap_set_option(cur_session, LDAP_OPT_PROTOCOL_VERSION, &opt); ldap_set_option(cur_session, LDAP_OPT_PROTOCOL_VERSION, &opt);
} }
int LDAPAsynConnection::start_tls(){ void LDAPAsynConnection::start_tls(){
return ldap_start_tls_s( cur_session, NULL, NULL ); int resCode;
if( ldap_start_tls_s( cur_session, NULL, NULL ) != LDAP_SUCCESS ) {
throw LDAPException(this);
}
} }
LDAPMessageQueue* LDAPAsynConnection::bind(const string& dn, LDAPMessageQueue* LDAPAsynConnection::bind(const string& dn,

View File

@ -92,10 +92,11 @@ class LDAPAsynConnection{
/** /**
* Start TLS on this connection. This isn't in the constructor, * Start TLS on this connection. This isn't in the constructor,
* because it could fail (i.e. server doesn't have SSL cert, client * because it could fail (i.e. server doesn't have SSL cert, client
* api wasn't compiled against OpenSSL, etc.). If you need TLS, * api wasn't compiled against OpenSSL, etc.).
* then you should error if this call fails with an error code. * @throws LDAPException if the TLS Layer could not be setup
* correctly
*/ */
int start_tls(); void start_tls();
/** Simple authentication to a LDAP-Server /** Simple authentication to a LDAP-Server
* *

View File

@ -25,8 +25,8 @@ LDAPConnection::LDAPConnection(const string& hostname, int port,
LDAPConnection::~LDAPConnection(){ LDAPConnection::~LDAPConnection(){
} }
int LDAPConnection::start_tls(){ void LDAPConnection::start_tls(){
return LDAPAsynConnection::start_tls(); LDAPAsynConnection::start_tls();
} }
void LDAPConnection::bind(const string& dn, const string& passwd, void LDAPConnection::bind(const string& dn, const string& passwd,
@ -50,9 +50,10 @@ void LDAPConnection::bind(const string& dn, const string& passwd,
delete msg; delete msg;
throw LDAPReferralException(urls); throw LDAPReferralException(urls);
}else{ }else{
string srvMsg = res->getErrMsg();
delete res; delete res;
delete msg; delete msg;
throw LDAPException(resCode); throw LDAPException(resCode, srvMsg);
} }
} }
delete res; delete res;
@ -97,9 +98,10 @@ bool LDAPConnection::compare(const string& dn, const LDAPAttribute& attr,
} }
break; break;
default : default :
string srvMsg = res->getErrMsg();
delete res; delete res;
delete msg; delete msg;
throw LDAPException(resCode); throw LDAPException(resCode, srvMsg);
} }
} }
@ -130,9 +132,10 @@ void LDAPConnection::del(const string& dn, const LDAPConstraints* cons){
} }
break; break;
default : default :
string srvMsg = res->getErrMsg();
delete res; delete res;
delete msg; delete msg;
throw LDAPException(resCode); throw LDAPException(resCode, srvMsg);
} }
} }
@ -164,9 +167,10 @@ void LDAPConnection::add(const LDAPEntry* le, const LDAPConstraints* cons){
} }
break; break;
default : default :
string srvMsg = res->getErrMsg();
delete res; delete res;
delete msg; 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(); string srvMsg = res->getErrMsg();
delete res; delete res;
delete msg; delete msg;
throw LDAPException(resCode,srvMsg); throw LDAPException(resCode, srvMsg);
} }
} }
@ -236,9 +240,10 @@ void LDAPConnection::rename(const string& dn, const string& newRDN,
} }
break; break;
default : default :
string srvMsg = res->getErrMsg();
delete res; delete res;
delete msg; delete msg;
throw LDAPException(resCode); throw LDAPException(resCode, srvMsg);
} }
} }
@ -278,10 +283,11 @@ LDAPSearchResults* LDAPConnection::search(const string& base, int scope,
} }
break; break;
default : default :
string srvMsg = res->getErrMsg();
delete results; // memcheck delete results; // memcheck
delete res; delete res;
delete msgq; delete msgq;
throw LDAPException(resCode); throw LDAPException(resCode, srvMsg);
} }
} }
return 0; return 0;
@ -314,9 +320,10 @@ LDAPExtResult* LDAPConnection::extOperation(const string& oid,
} }
break; break;
default : default :
string srvMsg = res->getErrMsg();
delete res; delete res;
delete msg; delete msg;
throw LDAPException(resCode); throw LDAPException(resCode, srvMsg);
} }
} }

View File

@ -71,10 +71,11 @@ class LDAPConnection : private LDAPAsynConnection {
/** /**
* Start TLS on this connection. This isn't in the constructor, * Start TLS on this connection. This isn't in the constructor,
* because it could fail (i.e. server doesn't have SSL cert, client * because it could fail (i.e. server doesn't have SSL cert, client
* api wasn't compiled against OpenSSL, etc.). If you need TLS, * api wasn't compiled against OpenSSL, etc.).
* then you should error if this call fails with an error code. * @throws LDAPException if the TLS Layer could not be setup
* correctly
*/ */
int start_tls(); void start_tls();
/** /**
* Performs a simple authentication with the server * Performs a simple authentication with the server