modernize: Use nullptr
[quassel.git] / src / core / ldapauthenticator.cpp
index b420440..76db681 100644 (file)
 
 LdapAuthenticator::LdapAuthenticator(QObject *parent)
     : Authenticator(parent),
-    _connection(0)
+    _connection(nullptr)
 {
 }
 
 
 LdapAuthenticator::~LdapAuthenticator()
 {
-    if (_connection != 0) {
-        ldap_unbind_ext(_connection, 0, 0);
+    if (_connection != nullptr) {
+        ldap_unbind_ext(_connection, nullptr, nullptr);
     }
 }
 
@@ -183,7 +183,7 @@ Authenticator::State LdapAuthenticator::init(const QVariantMap &settings,
 // Method based on abustany LDAP quassel patch.
 bool LdapAuthenticator::ldapConnect()
 {
-    if (_connection != 0) {
+    if (_connection != nullptr) {
         ldapDisconnect();
     }
 
@@ -208,8 +208,8 @@ bool LdapAuthenticator::ldapConnect()
 
     if (res != LDAP_SUCCESS) {
         qWarning() << "Could not set LDAP protocol version to v3:" << ldap_err2string(res);
-        ldap_unbind_ext(_connection, 0, 0);
-        _connection = 0;
+        ldap_unbind_ext(_connection, nullptr, nullptr);
+        _connection = nullptr;
         return false;
     }
 
@@ -219,12 +219,12 @@ bool LdapAuthenticator::ldapConnect()
 
 void LdapAuthenticator::ldapDisconnect()
 {
-    if (_connection == 0) {
+    if (_connection == nullptr) {
         return;
     }
 
-    ldap_unbind_ext(_connection, 0, 0);
-    _connection = 0;
+    ldap_unbind_ext(_connection, nullptr, nullptr);
+    _connection = nullptr;
 }
 
 
@@ -237,7 +237,7 @@ bool LdapAuthenticator::ldapAuth(const QString &username, const QString &passwor
     int res;
 
     // Attempt to establish a connection.
-    if (_connection == 0) {
+    if (_connection == nullptr) {
         if (!ldapConnect()) {
             return false;
         }
@@ -251,10 +251,10 @@ bool LdapAuthenticator::ldapAuth(const QString &username, const QString &passwor
     QByteArray baseDN = _baseDN.toLocal8Bit();
     QByteArray uidAttribute = _uidAttribute.toLocal8Bit();
 
-    cred.bv_val = (bindPassword.size() > 0 ? bindPassword.data() : NULL);
+    cred.bv_val = (bindPassword.size() > 0 ? bindPassword.data() : nullptr);
     cred.bv_len = bindPassword.size();
 
-    res = ldap_sasl_bind_s(_connection, bindDN.size() > 0 ? bindDN.constData() : 0, LDAP_SASL_SIMPLE, &cred, 0, 0, 0);
+    res = ldap_sasl_bind_s(_connection, bindDN.size() > 0 ? bindDN.constData() : nullptr, LDAP_SASL_SIMPLE, &cred, nullptr, nullptr, nullptr);
 
     if (res != LDAP_SUCCESS) {
         qWarning() << "Refusing connection from" << username << "(LDAP bind failed:" << ldap_err2string(res) << ")";
@@ -262,11 +262,11 @@ bool LdapAuthenticator::ldapAuth(const QString &username, const QString &passwor
         return false;
     }
 
-    LDAPMessage *msg = NULL, *entry = NULL;
+    LDAPMessage *msg = nullptr, *entry = nullptr;
 
     const QByteArray ldapQuery = "(&(" + uidAttribute + '=' + username.toLocal8Bit() + ")" + _filter.toLocal8Bit() + ")";
 
-    res = ldap_search_ext_s(_connection, baseDN.constData(), LDAP_SCOPE_SUBTREE, ldapQuery.constData(), 0, 0, 0, 0, 0, 0, &msg);
+    res = ldap_search_ext_s(_connection, baseDN.constData(), LDAP_SCOPE_SUBTREE, ldapQuery.constData(), nullptr, 0, nullptr, nullptr, nullptr, 0, &msg);
 
     if (res != LDAP_SUCCESS) {
         qWarning() << "Refusing connection from" << username << "(LDAP search failed:" << ldap_err2string(res) << ")";
@@ -281,7 +281,7 @@ bool LdapAuthenticator::ldapAuth(const QString &username, const QString &passwor
 
     entry = ldap_first_entry(_connection, msg);
 
-    if (entry == 0) {
+    if (entry == nullptr) {
         qWarning() << "Refusing connection from" << username << "(LDAP search returned no results)";
         ldap_msgfree(msg);
         return false;
@@ -293,7 +293,7 @@ bool LdapAuthenticator::ldapAuth(const QString &username, const QString &passwor
 
     char *userDN = ldap_get_dn(_connection, entry);
 
-    res = ldap_sasl_bind_s(_connection, userDN, LDAP_SASL_SIMPLE, &cred, 0, 0, 0);
+    res = ldap_sasl_bind_s(_connection, userDN, LDAP_SASL_SIMPLE, &cred, nullptr, nullptr, nullptr);
 
     if (res != LDAP_SUCCESS) {
         qWarning() << "Refusing connection from" << username << "(LDAP authentication failed)";