From afd6ad80a49bff9e5ecd99e8f4003dcd7cbe46f3 Mon Sep 17 00:00:00 2001
From: baeumma <none@none>
Date: Mon, 16 Jul 2012 16:53:27 +0200
Subject: [PATCH] fix adduser synchro(maybe)

---
 ldap_NS.pl | 48 +++++++++++++++++++++++++++++++++++-------------
 1 file changed, 35 insertions(+), 13 deletions(-)

diff --git a/ldap_NS.pl b/ldap_NS.pl
index e95bfbe..45ae2d3 100755
--- a/ldap_NS.pl
+++ b/ldap_NS.pl
@@ -43,6 +43,8 @@ LDAP_PP_ACCOUNT_LOCKED
 LDAP_PP_CHANGE_AFTER_RESET
 );
 
+use SNET::Magic::MagicHash;
+
 my $ldap_snmc;
 
 my $homepage='/cgi-bin/auth/ldap_NS.pl';
@@ -348,18 +350,31 @@ sub synchronize_add_users($$) {
       (ref($entry) eq 'HASH')
     );
 
+    my %nocasehash;
+    tie %nocasehash, 'MagicHash', {
+      'KEY' => sub { return lc($_[0]) },
+    };
+
     while (my ($k, $v) = each %{$entry}) {
 
-      delete($v->{'auditinformation'});
-      delete($v->{'pwdreset'});
+      die 'entry uid undefined' unless (
+        (ref($v) eq 'HASH') && (defined($v->{'uid'}))
+      );
 
-      die 'entry uid undefined' unless defined($v->{'uid'});
+      my %nocasehash_v;
+      tie %nocasehash_v, 'MagicHash', {
+        'KEY' => sub { return lc($_[0]) },
+      };
+      while (my ($kk, $vv) = each %{$v}) {
+        $nocasehash_v{$kk} = $vv;
+      }
+      $nocasehash{$k} = \%nocasehash_v;
 
-      $v->{'homeDirectory'} = ['/home/'.${$v->{'uid'}}[0]] unless (defined($v->{'homeDirectory'}));
-      $v->{'shadowLastChange'} = ['11640'];
-      $v->{'shadowFlag'} = [0];
-      $v->{'loginShell'} = ['/bin/ksh'];
-      $v->{'cn'} = [${$v->{'uid'}}[0]];
+      $nocasehash{$k}->{'homeDirectory'} = ['/home/'.${$v->{'uid'}}[0]];
+      $nocasehash{$k}->{'shadowLastChange'} = ['11640'];
+      $nocasehash{$k}->{'shadowFlag'} = [0];
+      $nocasehash{$k}->{'loginShell'} = ['/bin/ksh'];
+      $nocasehash{$k}->{'cn'} = [${$v->{'uid'}}[0]];
 
     }
 
@@ -383,10 +398,7 @@ sub synchronize_add_users($$) {
         
       my $connection = SNET::LdapNS::get_connection($host);
 
-      while (my ($k, $v) = each %{$entry}) {
-
-        delete($v->{'objectclass'});
-        $v->{'objectClass'} = [qw(top posixAccount shadowAccount account), $class];
+      while (my ($k, $v) = each %nocasehash) {
 
         my $uid = $connection->clean_dn(${$v->{'uid'}}[0]);
         my $res;
@@ -409,6 +421,12 @@ sub synchronize_add_users($$) {
 
         print STDERR "synchronize_add_users: synchronizing user `$uid'\n";
 
+        delete($v->{'objectclass'});
+        delete($v->{'auditinformation'});
+        delete($v->{'pwdreset'});
+
+        $v->{'objectClass'} = [qw(top posixAccount shadowAccount account), $class];
+
         my $dn = 'uid='.$uid.',ou=People,'.$base;
 
         eval {
@@ -419,6 +437,8 @@ sub synchronize_add_users($$) {
           }
           $entry->changetype('add');
 
+          #print STDERR 'uid='.$uid.',ou=People,'.$base.' => '.Dumper($entry)."\n";
+
           my $result = $entry->update($connection->{'connection'});
           die "[uid=$uid]: ".(
             defined($result->error_desc) ? $result->error_desc : $result->error()
@@ -1441,6 +1461,7 @@ EOJS
         }
       }
       else {
+        print STDERR "looking good, fetched userInfos for `$dn'\n";
         foreach my $attr (@attributes) {
           next unless (
             ($attr =~ m/userPassword/i)
@@ -2889,9 +2910,9 @@ sub display_passwd {
         eq 
         $form->field(name => 'repeat')
       );
+
       reconnect_ldap_snmc();
       SNET::LdapNS::passwd(
-        defined($form->field(name => 'synchronize')),
         $ldap_snmc->{'label'},
         $form->field(name => 'old'),
         $form->field(name => 'new')
@@ -2900,6 +2921,7 @@ sub display_passwd {
       $session->clear(['action', 'error']);
 
       synchronize_passwords(
+        defined($form->field(name => 'synchronize')),
         $ldap_snmc->{'label'},
         $form->field(name => 'new'),
         undef,
-- 
GitLab