--- smbldap-migrate-pwdump-accounts	2011-02-22 09:08:33.000000000 -0600
+++ /usr/share/doc/smbldap-tools-0.9.6/migration_scripts/smbldap-migrate-pwdump-accounts	2014-03-26 11:23:38.000000000 -0500
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# $Id: smbldap-migrate-pwdump-accounts 11 2010-10-21 13:13:53Z mm1 $
+# $Id: smbldap-migrate-pwdump-accounts 26 2010-11-15 14:28:01Z mm1 $
 #
 #  This code was developped by IDEALX (http://IDEALX.org/) and
 #  contributors (their names can be found in the CONTRIBUTORS file).
@@ -39,22 +39,11 @@
 # in pwdump format to stdout.
 # Errors, debug and stats are output to stderr.
 
-sub modify_account
-  {
-    my ($login, $basedn, $lmpwd, $ntpwd, $gecos, $homedir) = @_;
-    my $modify = $ldap_master->modify ("uid=$login,$basedn",
-				       changes => [
-						   replace => [sambaLMPassword => "$lmpwd"],
-						   replace => [sambaNTPassword => "$ntpwd"],
-						   replace => [gecos => "$gecos"],
-						   replace => [sambaHomePath => "$homedir"]
-						  ]
-				      );
-    $modify->code && die "failed to modify entry: ", $modify->error ;
-  }
 
 #####################
 
+sub modify_account;
+sub has_user_entry;
 
 my %Options;
 
@@ -129,7 +118,8 @@
     $gecos = $config{userGecos};
   }
 
-  my $user_exists = is_samba_user($login);
+  #my $user_exists = is_samba_user($login);
+  my $user_exists = has_user_entry($ldap_master,$login);
  
   if (!$user_exists) {
     if (!defined($Options{'C'})) {
@@ -185,6 +175,35 @@
 
 print STDERR "special users skipped: $specialskipped\n";
 
+sub modify_account
+  {
+    my ($login, $basedn, $lmpwd, $ntpwd, $gecos, $homedir) = @_;
+    my $modify = $ldap_master->modify ("uid=$login,$basedn",
+				       changes => [
+						   replace => [sambaLMPassword => "$lmpwd"],
+						   replace => [sambaNTPassword => "$ntpwd"],
+						   replace => [gecos => "$gecos"],
+						   replace => [sambaHomePath => "$homedir"]
+						  ]
+				      );
+    $modify->code && die "failed to modify entry: ", $modify->error ;
+  }
+
+sub has_user_entry
+  {
+    my($ldap_master,$user) = @_;
+    # do not use read_user_entry()
+    my $mesg = $ldap_master->search( base => $config{usersdn},
+				     scope => 'one',
+				     filter => "(uid=$user)"
+				   );
+    if ($mesg->count() == 1 ) {
+        return 1;
+    } else {
+        return 0;
+    }
+  }
+
 
 ########################################
 
