Using C code I am trying to bind to an LDAP server using GSSAPI/SASL on a Debian stretch server.
I initialize a kerberos credentials cache and then make the location of that cache known to the LDAP calls using the environment variable KRB5CCNAME
. Here is the code:
#include <ldap.h>
#include <krb5.h>
#define CACHE_NAME "MEMORY:ldapconnect"
/* Set up Kerberos credentials cache in CACHE_NAME */
[... omitted to save space ...]
/* Create LDAP object */
char *ldapuri = "ldap://ldap.example.com";
LDAP *ld = NULL;
code = ldap_initialize(&ld, ldapuri);
/* Make the LDAP object be version 3 */
int option = LDAP_VERSION3;
code = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &option);
/* Set the environment variable KRB5CCNAME to CACHE_NAME */
putenv((char *) "KRB5CCNAME=" CACHE_NAME);
/* Do the LDAP bind using SASL */
code = ldap_sasl_interactive_bind_s(ld, NULL, "GSSAPI", NULL, NULL,
LDAP_SASL_QUIET, ad_interact_sasl,
NULL);
If I change CACHE_NAME
to FILE:/tmp/ldapconnect
it works. It is only when CACHE_NAME
uses MEMORY:
that it fails.
For reasons including security and simplicity I want to use a MEMORY:
cache type, but I can't get the above to work except with a FILE:
cache type.
The relevant libraries I am using:
# debian stretch
libldap-2.4-2 2.4.44+dfsg-5+deb9u2
libsasl2-2 2.1.27~101-g0780600+dfsg-3
libkrb5-26-heimdal 7.5.0+dfsg-2.1