diff --git a/contrib/bin/fusiondirectory-setup b/contrib/bin/fusiondirectory-setup index 65f49cc62765fd2b160d3e618f4fed8fcf5b02f8..fea4f7fd34a13e746d840df608b448161381466d 100644 --- a/contrib/bin/fusiondirectory-setup +++ b/contrib/bin/fusiondirectory-setup @@ -7,7 +7,7 @@ # Manage fusiondirectory installs from the command line # # This code is part of FusionDirectory (http://www.fusiondirectory.org/) -# Copyright (C) 2011-2016 FusionDirectory +# Copyright (C) 2011-2017 FusionDirectory # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -94,6 +94,7 @@ my $grouprdn = "ou=groups"; my $systemrdn = "ou=systems"; my $dnsrdn = "ou=dns"; my $dhcprdn = "ou=dhcp"; +my $workstationrdn = "ou=workstations,ou=systems"; ################################################################################################################################################# @@ -1449,6 +1450,68 @@ sub migrate_systems { $unbind->code && warn "! Unable to unbind from LDAP server: ", $unbind->error."\n"; } +# function that migrates winstations from FD<1.1 to FD>=1.1 +sub migrate_winstations +{ + # initiate the LDAP connexion + my %hash_ldap_param = get_ldap_connexion(); + + # LDAP's connection's parameters + my $base = $hash_ldap_param{base}; + my $ldap = $hash_ldap_param{ldap}; + + my $mesg = $ldap->search( + filter => "(&(!(objectClass=fdWorkstation))(objectClass=sambaSamAccount))", + base => $base + ); + $mesg->code && die $mesg->error; + + if ($mesg->count > 0) { + print ("The following winstations are not using the new fdWorkstation objectClass:\n"); + + my @entries = $mesg->entries; + + foreach my $entry (@entries) { + print $entry->dn()."\n"; + } + + if (ask_yn_question("Migrate these entries to fdWorkstation objectClass?")) { + foreach my $entry (@entries) { + my $cn = $entry->get_value('cn'); + $cn =~ s/\$$//; + $entry->replace('cn' => $cn); + my $newrdn = "cn=".$cn; + my $dn_old = $entry->dn(); + my $dn_new = $entry->dn(); + $dn_new =~ s/^[^,]+,[^,]+,[^,]+,/$newrdn,$workstationrdn/; + $entry->dn($dn_new); + my @replace = ('fdWorkstation'); + my @classes = $entry->get_value('objectClass'); + foreach my $class (@classes) { + if ($class ne 'account') { + push(@replace, "$class"); + } + } + $entry->replace("objectClass" => \@replace); + $entry->add('fdMode' => 'unlocked'); + $mesg = $ldap->add($entry); + if ($mesg->code) { + print $entry->dn().": ".$mesg->error."\n"; + next; + } + undef @replace; + $mesg = $ldap->delete($dn_old); + if ($mesg->code) { + print $entry->dn().": ".$mesg->error."\n"; + next; + } + } + } + } else { + print "Found no winstation to migrate\n"; + } +} + # function that migrates phones from FD<1.1 to FD>=1.1 sub migrate_phones { # initiate the LDAP connexion @@ -1656,6 +1719,9 @@ sub read_ldap_config { if (($mesg->entries)[0]->exists('fdDhcpRDN')) { $dhcprdn = ($mesg->entries)[0]->get_value('fdDhcpRDN'); } + if (($mesg->entries)[0]->exists('fdWorkstationRDN')) { + $workstationrdn = ($mesg->entries)[0]->get_value('fdWorkstationRDN'); + } } return ($mesg->entries)[0]; @@ -1747,6 +1813,7 @@ die ("! You have to run this script as root\n") if ($<!=0); $commands{"--migrate-users"} = ["Migrating your users", \&migrate_users]; $commands{"--migrate-phones"} = ["Migrating your phones from FD < 1.1", \&migrate_phones]; $commands{"--migrate-systems"} = ["Migrating your systems from FD < 1.1", \&migrate_systems]; + $commands{"--migrate-winstations"} = ["Migrating your winstations from FD < 1.1", \&migrate_winstations]; $commands{"--migrate-dhcp"} = ["Migrating DHCP configurations for FD >= 1.0.17",\&migrate_dhcp]; $commands{"--delete-gosa-locks"} = ["Delete lock tokens using old gosaLockEntry class", \&delete_gosa_locks]; $commands{"--install-plugins"} = ["Installing FusionDirectory's plugins", \&install_plugins]; @@ -1853,6 +1920,10 @@ This option removes device objectClass for phones as fdPhones is now structural This option replace old systems objectClasses by new objectClasses from FD 1.1. +=item --migrate-winstations + +This option replace old winstations objectClasses by new objectClasses from FD 1.1. + =item --migrate-dhcp This option moves DHCP configurations from systems branch to DHCP branch, which is necessary for FusionDirectory 1.0.17 and above.