简体   繁体   中英

LDAP SASL Binding C++

I'm currently implementing authorization mechanism on Linux against AD domain. I use for authorization the OpenLDAP library. Now I'm trying to perform the binding operation using ldap_sasl_bind_s function, and as the response from server my application is receiving the challenge but I'm not sure how to solve it. So I'm stuck with this:

berval creds;            // User creds
berval *srv = NULL;      // Server challenge
creds.bv_val = (char*)password.c_str();
creds.bv_len = password.length();

ret = ldap_sasl_bind_s(
        ldapConnection,
        username.c_str(),
        "DIGEST-MD5",
        &creds,
        NULL,
        NULL,
        &srv
        );

if((srv != NULL) && (ret == LDAP_SASL_BIND_IN_PROGRESS)) // If challenge has been received
{
    // Challenge solving mechanism goes there.
    ret = ldap_sasl_bind_s(
        ldapConnection,
        username.c_str(),
        "DIGEST-MD5",
        srv, // Not sure if it's the right place
        NULL,
        NULL,
        NULL
        );

    if(ret != LDAP_SUCCESS) // Here I get 0x31 (LDAP_INVALID_CREDENTIALS)
    {
        ldap_unbind_ext(ldapConnection, NULL, NULL);
        return false;
    }
}

Ok, thanks to IBM Knowledge Center I figured how to bind credentials. Using simple auth mechanism we can do this by calling

ret = ldap_sasl_bind_s(
        ldapConnection,
        "username@example.com",
        NULL, // Simple bind mechanism
        &creds,
        NULL,
        NULL,
        NULL
        );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM