mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-06 10:46:21 +08:00
improved error reporting
This commit is contained in:
parent
7389cb27ed
commit
00c7cf396b
@ -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,
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user