Hi,
I was trying to debug a "Naming violation" error I was getting while trying to save a new user from drupal to active directory 2013 and 2008
This is the exception in watchdog

SimpleLdapException: Naming violation in SimpleLdap::ldap_add() (line 316 of .../SimpleLdap.class.php).

Turns out that the dn value of the SimpleLdapUser class was false (from watchdog)

ldap_add($link_identifier = Resource id #443, $dn = OU=TESTOU,DC=TESTCDC,DC=local, $entry = Array ( [samaccountname] => Array ( [0] => test_test.com ) [mail] => Array ( [0] => test@test.com ) [objectclass] => Array ( [0] => user ) ) )

I noticed that the dn variable of the SimpleLdapUser class is declared as false in the contructor

protected $dn = FALSE;

I couldn't figure out where it's supposed to get set. So I did from hook_simple_ldap_user_to_ldap_alter

function MYMODULE_simple_ldap_user_to_ldap_alter($ldap_user, $drupal_user) {
  $dn = $ldap_user->__get('dn');
  if (empty($dn)){
    $base_dn = simple_ldap_user_variable_get('simple_ldap_user_basedn');
    $ldap_user->__set('dn', $base_dn);
  }
}

I'm not to sure if this is the right way or why the object did not have a dn.
Thank you.

Comments

iamjon’s picture

Issue summary: View changes
iamjon’s picture

Issue summary: View changes
iamjon’s picture

Ok I got it to work by changing the alter a bit:

function MYMODULE_simple_ldap_user_to_ldap_alter($ldap_user, $drupal_user) {
  $dn = $ldap_user->__get('dn');
  if (empty($dn)){    
    if (!empty($drupal_user->field_custom_name_field[LANGUAGE_NONE])){
      $full_name = $drupal_user->field_custom_name_field[LANGUAGE_NONE][0]['value'];
    }
    else {
      $full_name = 'User id ' . $drupal_user->uid . ' from drupal';
    }
    $new_dn = 'cn=' . $full_name . ',' . simple_ldap_user_variable_get('simple_ldap_user_basedn');    
    $ldap_user->__set('dn', $new_dn);
  }
}

I still have no idea why the dn is empty in the first place.