I have been starting to work with the ldapauth module. After it authenticates a user, it calls user_save, sending $data a data argument array that includes 'authname_ldapauth' => name

This should cause the "ldapauth" module to be set as the authenticating module name in the user authmap, however it was not happening because my login already had a row in that table with the module name 'webserver_auth' and a unique constraint on authname prevents more than one row for the same authname. In the code below, this was causing the INSERT query to fail, but the error was not reported.

function user_set_authmaps($account, $authmaps) {
  foreach ($authmaps as $key => $value) {
    $module = explode('_', $key, 2);
    if ($value) {
      db_query("UPDATE {authmap} SET authname = '%s' WHERE uid = %d AND module = '%s'", $value, $account->uid, $module[1]);
      if (!db_affected_rows()) {
        @db_query("INSERT INTO {authmap} (authname, uid, module) VALUES ('%s', %d, '%s')", $value, $account->uid, $module[1]);
      }
    }
    else {
      db_query("DELETE FROM {authmap} WHERE uid = %d AND module = '%s'", $account->uid, $module[1]);
    }
  }
}

I resolved the problem by clearing the existing row from the authmap table, and I'm don't really understand how this is supposed to work, but it seems like there is a bug in here somewhere.

Thanks.

Comments

damien tournoud’s picture

Project: Drupal core » LDAP integration
Version: 6.19 » 6.x-1.x-dev
Component: user.module » Code

The bug is that LDAP has to name space its authnames. The general way of doing this is to postfix the authname with @ldap.

johnbarclay’s picture

Assigned: Unassigned » johnbarclay