--- lualdap-1.1.0/src/lualdap.c.orig 2012-05-31 03:32:44.337987490 +0200 +++ lualdap-1.1.0/src/lualdap.c 2012-05-31 03:33:35.515987505 +0200 @@ -461,7 +461,11 @@ luaL_argcheck(L, conn!=NULL, 1, LUALDAP_PREFIX"LDAP connection expected"); if (conn->ld == NULL) /* already closed */ return 0; +#if defined(LDAP_API_FEATURE_X_OPENLDAP) && LDAP_API_FEATURE_X_OPENLDAP >= 20300 + ldap_unbind_ext (conn->ld, NULL, NULL); +#else ldap_unbind (conn->ld); +#endif conn->ld = NULL; lua_pushnumber (L, 1); return 1; @@ -939,13 +947,27 @@ const char *password = luaL_optstring (L, 3, NULL); int use_tls = lua_toboolean (L, 4); conn_data *conn = (conn_data *)lua_newuserdata (L, sizeof(conn_data)); +#if defined(LDAP_API_FEATURE_X_OPENLDAP) && LDAP_API_FEATURE_X_OPENLDAP >= 20300 + struct berval cred = { 0, NULL }; + char *host_with_schema = NULL; +#endif int err; /* Initialize */ lualdap_setmeta (L, LUALDAP_CONNECTION_METATABLE); conn->version = 0; +#if defined(LDAP_API_FEATURE_X_OPENLDAP) && LDAP_API_FEATURE_X_OPENLDAP >= 20300 + host_with_schema = malloc(strlen(host) + 8); + strcpy(host_with_schema, "ldap://"); + strcat(host_with_schema, host); + err = ldap_initialize(&conn->ld, host_with_schema); + free(host_with_schema); + host_with_schema = NULL; + if (err != LDAP_SUCCESS) +#else conn->ld = ldap_init (host, LDAP_PORT); if (conn->ld == NULL) +#endif return faildirect(L,LUALDAP_PREFIX"Error connecting to server"); /* Set protocol version */ conn->version = LDAP_VERSION3; @@ -959,7 +981,16 @@ return faildirect (L, ldap_err2string (rc)); } /* Bind to a server */ +#if defined(LDAP_API_FEATURE_X_OPENLDAP) && LDAP_API_FEATURE_X_OPENLDAP >= 20300 + cred.bv_len = strlen(password); + cred.bv_val = strdup(password); + err = ldap_sasl_bind_s (conn->ld, who, LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL); + free(cred.bv_val); + cred.bv_len = 0; + cred.bv_val = NULL; +#else err = ldap_bind_s (conn->ld, who, password, LDAP_AUTH_SIMPLE); +#endif if (err != LDAP_SUCCESS) return faildirect (L, ldap_err2string (err));