Ticket #28: patch-ldap-referral.patch

File patch-ldap-referral.patch, 1.2 KB (added by smoku, 20 months ago)

Patch by Stephen Marquard <scm@…>

  • c2s/authreg_ldap.c

    old new  
    7070    return ld_errno; 
    7171} 
    7272 
     73/** entry-point function for following referrals, required in some cases by Active Directory */ 
     74static int rebindProc(LDAP *ld, LDAP_CONST char *url, ber_tag_t request, ber_int_t msgid, void *mdata) 
     75{ 
     76    moddata_t data = mdata; 
     77    data->ld = ld; 
     78    if(ldap_simple_bind_s(data->ld, data->binddn, data->bindpw)) { 
     79        log_write(data->ar->c2s->log, LOG_ERR, "ldap: bind failed (to %s): %s", url, ldap_err2string(_ldap_get_lderrno(data->ld))); 
     80        ldap_unbind_s(data->ld); 
     81        data->ld = NULL; 
     82        return NULL; 
     83    } 
     84 
     85    return LDAP_SUCCESS; 
     86} 
     87 
    7388/** connect to the ldap host */ 
    7489static int _ldap_connect(moddata_t data) 
    7590{ 
     
    151166    } 
    152167 
    153168    snprintf(filter, 1024, "(%s=%s)", data->uidattr, username); 
     169 
     170    if(ldap_set_rebind_proc(data->ld, &rebindProc,data)) { 
     171        log_write(data->ar->c2s->log, LOG_ERR, "ldap: set_rebind_proc failed: %s", ldap_err2string(_ldap_get_lderrno(data->ld))); 
     172        ldap_unbind_s(data->ld); 
     173        data->ld = NULL; 
     174        return NULL; 
     175    } 
    154176 
    155177    if(ldap_search_s(data->ld, basedn, LDAP_SCOPE_SUBTREE, filter, no_attrs, 0, &result)) 
    156178    {