From: hno <> Date: Wed, 2 May 2001 19:19:10 +0000 (+0000) Subject: Added glue for OpenLDAP 2.x / Current Internet Draft API. The new API X-Git-Tag: SQUID_3_0_PRE1~1520 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=87f6d1e1a4ce53cb7ca0240ff25a94da867c116d;p=thirdparty%2Fsquid.git Added glue for OpenLDAP 2.x / Current Internet Draft API. The new API is unfortunately not backwards compatible with the old RFC1823 API. --- diff --git a/helpers/basic_auth/LDAP/squid_ldap_auth.c b/helpers/basic_auth/LDAP/squid_ldap_auth.c index 014f707a9c..971e6af9cc 100644 --- a/helpers/basic_auth/LDAP/squid_ldap_auth.c +++ b/helpers/basic_auth/LDAP/squid_ldap_auth.c @@ -23,6 +23,10 @@ * or (at your option) any later version. * * Changes: + * 2001-05-02: Henrik Nordstrom + * - Support newer OpenLDAP 2.x libraries using the + * revised Internet Draft API which unfortunately + * is not backwards compatible with RFC1823.. * 2001-04-15: Henrik Nordstrom * - Added command line option for basedn * - Added the ability to search for the user DN @@ -57,6 +61,42 @@ static int aliasderef = LDAP_DEREF_NEVER; static int checkLDAP(LDAP * ld, char *userid, char *password); +/* Yuck.. we need to glue to different versions of the API */ + +#if defined(LDAP_API_VERSION) && LDAP_API_VERSION > 1823 +int squid_ldap_errno(LDAP *ld) +{ + int err = 0; + ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &err); + return err; +} +void squid_ldap_set_aliasderef(LDAP *ld, int deref) +{ + ldap_set_option(ld, LDAP_OPT_DEREF, &deref); +} +void squid_ldap_set_referrals(LDAP *ld, int referrals) +{ + int *value = referrals ? LDAP_OPT_ON : LDAP_OPT_OFF; + ldap_set_option(ld, LDAP_OPT_REFERRALS, value); +} +#else +int squid_ldap_errno(LDAP *ld) +{ + return ld->ld_errno; +} +void squid_ldap_set_aliasderef(LDAP *ld, int deref) +{ + ld->ld_deref = deref; +} +void squid_ldap_set_referrals(LDAP *ld, int referrals) +{ + if (referrals) + ld->ld_options |= ~LDAP_OPT_REFERRALS; + else + ld->ld_options &= ~LDAP_OPT_REFERRALS; +} +#endif + int main(int argc, char **argv) { @@ -179,12 +219,11 @@ recover: ldapServer, LDAP_PORT); exit(1); } - if (noreferrals) - ld->ld_options &= ~LDAP_OPT_REFERRALS; - ld->ld_deref = aliasderef; + squid_ldap_set_referrals(ld, !noreferrals); + squid_ldap_set_aliasderef(ld, aliasderef); } if (checkLDAP(ld, user, passwd) != 0) { - if (tryagain && ld->ld_errno != LDAP_INVALID_CREDENTIALS) { + if (tryagain && squid_ldap_errno(ld) != LDAP_INVALID_CREDENTIALS) { tryagain = 0; ldap_unbind(ld); ld = NULL; @@ -194,7 +233,7 @@ recover: } else { printf("OK\n"); } - if (!persistent || (ld->ld_errno != LDAP_SUCCESS && ld->ld_errno != LDAP_INVALID_CREDENTIALS)) { + if (!persistent || (squid_ldap_errno(ld) != LDAP_SUCCESS && squid_ldap_errno(ld) != LDAP_INVALID_CREDENTIALS)) { ldap_unbind(ld); ld = NULL; }