e3ffab
From 761257efc18f9f5efedae110ba8cfa5feeb9f8f7 Mon Sep 17 00:00:00 2001
e3ffab
From: Jan Cholasta <jcholast@redhat.com>
e3ffab
Date: Mon, 12 Jan 2015 15:37:33 +0000
e3ffab
Subject: [PATCH] Remove RUV from LDIF files before using them in ipa-restore
e3ffab
e3ffab
https://fedorahosted.org/freeipa/ticket/4822
e3ffab
e3ffab
Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
e3ffab
---
e3ffab
 ipaserver/install/ipa_restore.py | 36 +++++++++++++++++++++++++++++++++++-
e3ffab
 1 file changed, 35 insertions(+), 1 deletion(-)
e3ffab
e3ffab
diff --git a/ipaserver/install/ipa_restore.py b/ipaserver/install/ipa_restore.py
e3ffab
index f3a60fcc7a60c38c0d2ae1e52fc4fe7712411ec1..cd98d07f5f7c7b2ea1b1fef9a272229475efcdc9 100644
e3ffab
--- a/ipaserver/install/ipa_restore.py
e3ffab
+++ b/ipaserver/install/ipa_restore.py
e3ffab
@@ -24,6 +24,7 @@ import tempfile
e3ffab
 import time
e3ffab
 import pwd
e3ffab
 from ConfigParser import SafeConfigParser
e3ffab
+import ldif
e3ffab
 
e3ffab
 from ipalib import api, errors
e3ffab
 from ipapython import version, ipautil, certdb, dogtag
e3ffab
@@ -94,6 +95,32 @@ def decrypt_file(tmpdir, filename, keyring):
e3ffab
     return dest
e3ffab
 
e3ffab
 
e3ffab
+class RemoveRUVParser(ldif.LDIFParser):
e3ffab
+    def __init__(self, input_file, writer, logger):
e3ffab
+        ldif.LDIFParser.__init__(self, input_file)
e3ffab
+        self.writer = writer
e3ffab
+        self.log = logger
e3ffab
+
e3ffab
+    def handle(self, dn, entry):
e3ffab
+        objectclass = None
e3ffab
+        nsuniqueid = None
e3ffab
+
e3ffab
+        for name, value in entry.iteritems():
e3ffab
+            name = name.lower()
e3ffab
+            if name == 'objectclass':
e3ffab
+                objectclass = [x.lower() for x in value]
e3ffab
+            elif name == 'nsuniqueid':
e3ffab
+                nsuniqueid = [x.lower() for x in value]
e3ffab
+
e3ffab
+        if (objectclass and nsuniqueid and
e3ffab
+            'nstombstone' in objectclass and
e3ffab
+            'ffffffff-ffffffff-ffffffff-ffffffff' in nsuniqueid):
e3ffab
+            self.log.debug("Removing RUV entry %s", dn)
e3ffab
+            return
e3ffab
+
e3ffab
+        self.writer.unparse(dn, entry)
e3ffab
+
e3ffab
+
e3ffab
 class Restore(admintool.AdminTool):
e3ffab
     command_name = 'ipa-restore'
e3ffab
     log_file_name = paths.IPARESTORE_LOG
e3ffab
@@ -447,7 +474,14 @@ class Restore(admintool.AdminTool):
e3ffab
         dn = DN(('cn', cn), ('cn', 'import'), ('cn', 'tasks'), ('cn', 'config'))
e3ffab
 
e3ffab
         ldifname = '%s-%s.ldif' % (instance, backend)
e3ffab
-        ldiffile = os.path.join(self.dir, ldifname)
e3ffab
+        srcldiffile = os.path.join(self.dir, ldifname)
e3ffab
+        ldiffile = '%s.noruv' % srcldiffile
e3ffab
+
e3ffab
+        with open(ldiffile, 'wb') as out_file:
e3ffab
+            ldif_writer = ldif.LDIFWriter(out_file)
e3ffab
+            with open(srcldiffile, 'rb') as in_file:
e3ffab
+                ldif_parser = RemoveRUVParser(in_file, ldif_writer, self.log)
e3ffab
+                ldif_parser.parse()
e3ffab
 
e3ffab
         if online:
e3ffab
             conn = self.get_connection()
e3ffab
-- 
e3ffab
2.1.0
e3ffab