Blame SOURCES/MigrationTools-47-hosts.patch

e96fd1
916623 - migrate_all_offline.sh fails on duplicity
e96fd1
e96fd1
1) We should skip all hosts, which are already inserted into the database,
e96fd1
hostname is the primary key there.
e96fd1
e96fd1
2) When a service in /etc/services has different port for TCP and UPD,
e96fd1
we must use different dn: for them - let's add '+udp' and '+tcp' prefix
e96fd1
to them 
e96fd1
e96fd1
3) LDAP is case insensitive, while /etc/services is case sensitive.
e96fd1
Therefore skip all services, which would clash in LDAP.
e96fd1
e96fd1
diff -up MigrationTools-47/migrate_hosts.pl.orig MigrationTools-47/migrate_hosts.pl
e96fd1
--- MigrationTools-47/migrate_hosts.pl.orig	2013-08-08 11:33:36.098638903 +0200
e96fd1
+++ MigrationTools-47/migrate_hosts.pl	2013-08-08 11:33:47.250619710 +0200
e96fd1
@@ -51,34 +53,56 @@ while(<INFILE>)
e96fd1
 	next if /^#/;
e96fd1
 	s/#(.*)$//;
e96fd1
 	local($hostaddr, $hostname, @aliases) = split(/\s+/);
e96fd1
-	
e96fd1
-	if ($use_stdout) {
e96fd1
-		&dump_host(STDOUT, $hostaddr, $hostname, @aliases);
e96fd1
-	} else {
e96fd1
-		&dump_host(OUTFILE, $hostaddr, $hostname, @aliases);
e96fd1
-	}
e96fd1
+	&add_host($hostaddr, $hostname, @aliases)
e96fd1
 }
e96fd1
 
e96fd1
+if ($use_stdout) {
e96fd1
+	&dump_hosts(STDOUT);
e96fd1
+} else {
e96fd1
+	&dump_hosts(OUTFILE);
e96fd1
+}
e96fd1
+
e96fd1
+# hash hostname -> IPaddresses
e96fd1
+%hosts={};
e96fd1
 
e96fd1
-sub dump_host
e96fd1
+sub add_host
e96fd1
 {
e96fd1
-	local($HANDLE, $hostaddr, $hostname, @aliases) = @_;
e96fd1
-	local($dn);
e96fd1
+	local($hostaddr, $hostname, @aliases) = @_;
e96fd1
 	return if (!$hostaddr);
e96fd1
+	
e96fd1
+	if ($hosts{$hostname}) {
e96fd1
+		@addrs = @{$hosts{$hostname}};
e96fd1
+		push(@addrs, $hostaddr);
e96fd1
+		$hosts{$hostname} = [@addrs];
e96fd1
+	} else {
e96fd1
+		$hosts{$hostname} = [$hostaddr];
e96fd1
+	}
e96fd1
 
e96fd1
-	print $HANDLE "dn: cn=$hostname,$NAMINGCONTEXT\n";
e96fd1
-	print $HANDLE "objectClass: top\n";
e96fd1
-	print $HANDLE "objectClass: ipHost\n";
e96fd1
-	print $HANDLE "objectClass: device\n";
e96fd1
-	print $HANDLE "ipHostNumber: $hostaddr\n";
e96fd1
-	print $HANDLE "cn: $hostname\n";
e96fd1
-	@aliases = uniq($hostname, @aliases);
e96fd1
-	foreach $_ (@aliases) {
e96fd1
-		if ($_ ne $hostname) {
e96fd1
-			print $HANDLE "cn: $_\n";
e96fd1
+	foreach (@aliases) {
e96fd1
+		if ($hosts{$_}) {
e96fd1
+			@addrs = @{$hosts{$_}};
e96fd1
+			push(@addrs, $hostaddr);
e96fd1
+		} else {
e96fd1
+			@hosts{$_} = [$hostaddr];
e96fd1
+		}
e96fd1
+	}
e96fd1
+}
e96fd1
+
e96fd1
+sub dump_hosts
e96fd1
+{
e96fd1
+	my $HANDLE = shift;
e96fd1
+	for my $hostname ( keys %hosts ) {
e96fd1
+		print $HANDLE "dn: cn=$hostname,$NAMINGCONTEXT\n";
e96fd1
+		print $HANDLE "cn: $hostname\n";
e96fd1
+		print $HANDLE "objectClass: top\n";
e96fd1
+		print $HANDLE "objectClass: ipHost\n";
e96fd1
+		print $HANDLE "objectClass: device\n";
e96fd1
+		@addrs = @{$hosts{$hostname}};
e96fd1
+		for my $hostaddr (@addrs) {
e96fd1
+			print $HANDLE "ipHostNumber: $hostaddr\n";
e96fd1
 		}
e96fd1
+		print $HANDLE "\n";
e96fd1
 	}
e96fd1
-	print $HANDLE "\n";
e96fd1
 }
e96fd1
 
e96fd1
 close(INFILE);
e96fd1
diff -up MigrationTools-47/migrate_services.pl.orig MigrationTools-47/migrate_services.pl
e96fd1
--- MigrationTools-47/migrate_services.pl.orig	2013-08-08 13:14:48.404960042 +0200
e96fd1
+++ MigrationTools-47/migrate_services.pl	2013-08-08 13:14:26.000000000 +0200
e96fd1
@@ -186,6 +187,17 @@ sub build_service_records
e96fd1
 					$suffix = "+ipServicePort=" . &escape_metacharacters($port);
e96fd1
 				}
e96fd1
 
e96fd1
+                                # Add suffix also when UDP and TCP port differ, but the service name is the same
e96fd1
+                                if (exists $Rh_portmap->{$servicename}{"udp"} 
e96fd1
+                                                and exists $Rh_portmap->{$servicename}{"tcp"}) {
e96fd1
+                                        my @udpport = keys(%{$Rh_portmap->{$servicename}{'udp'}});
e96fd1
+                                        my @tcpport = keys(%{$Rh_portmap->{$servicename}{'tcp'}});
e96fd1
+
e96fd1
+                                        if (!(@udpport ~~ @tcpport)) {
e96fd1
+                                                $suffix = "-" . $proto;
e96fd1
+                                        }
e96fd1
+                                }
e96fd1
+
e96fd1
 				# Normalize aliases across protocols. Yet
e96fd1
 				# another uncomfortable compromise.
e96fd1
 				foreach (keys %{$Rh_services->{$port}{$servicename}{$proto}{'aliases'}}) {
e96fd1
diff -up MigrationTools-47/migrate_services.pl.orig MigrationTools-47/migrate_services.pl
e96fd1
--- MigrationTools-47/migrate_services.pl.orig	2013-08-08 13:21:16.191273547 +0200
e96fd1
+++ MigrationTools-47/migrate_services.pl	2013-08-08 13:42:14.497330286 +0200
e96fd1
@@ -93,6 +93,8 @@ sub parse_services
e96fd1
 	my %protocols_found = ();
e96fd1
 
e96fd1
 	my $card = '';
e96fd1
+	my %loservices = (); # lower-case service names
e96fd1
+	my %services = (); # service names
e96fd1
 	readloop:
e96fd1
 	while(defined($card = <INFILE>))
e96fd1
 	{
e96fd1
@@ -104,10 +106,15 @@ sub parse_services
e96fd1
 
e96fd1
 		# do not generate ddp services - it's AppleTalk, not IP
e96fd1
                 if ($proto eq "ddp") { 
e96fd1
-                    print STDERR "Skipping non-IP service '$servicename $portproto'\n";
e96fd1
+                    print STDERR "Skipping non-IP service '$servicename $portproto'.\n";
e96fd1
                     next; 
e96fd1
                 }
e96fd1
-
e96fd1
+                if (exists $loservices{lc($servicename)} and !exists $services{$servicename}) {
e96fd1
+                    print STDERR "Skipping service '$servicename', it clashes with services '".$loservices{lc($servicename)}."' because LDAP is case-insensitive.\n";
e96fd1
+                    next;
e96fd1
+                }
e96fd1
+                $services{$servicename} = $servicename;
e96fd1
+                $loservices{lc($servicename)} = $servicename;
e96fd1
 		# Find services specifying a port range (e.g. X11.)
e96fd1
 		my $loport = '';
e96fd1
 		my $hiport = '';