diff --git a/core/src/plugins/filed/BareosFdPluginLDAP.py b/core/src/plugins/filed/BareosFdPluginLDAP.py index 5cb6651a443..cf3960a476b 100644 --- a/core/src/plugins/filed/BareosFdPluginLDAP.py +++ b/core/src/plugins/filed/BareosFdPluginLDAP.py @@ -430,12 +430,20 @@ def get_next_file_to_backup(self, context, savepkt): return bRCs["bRC_OK"] def set_new_dn(self, fname): - path = fname[: -len("/ldif.data")] - # Convert the PATH into a DN e.g. reverse the elements. - path_sliced = path.split("/") - new_dn = "".join([element + "," for element in reversed(path_sliced)]) - # Remove the ',@LDAP,' in the DN which is an internal placeholder - self.dn = new_dn.replace(",@LDAP,", "") + """ + Generate a LDAP DN based on provided filename and path. + + 1. split filename into path components + 2. reverse the list + 3. filter out anything without an equals sign("=") + 4. join components into comma-separated string + """ + self.dn = ",".join( + filter( + lambda x: "=" in x, + reversed(fname.split("/")), + ) + ) def has_next_file(self, context): # See if we are currently handling the LDIF file or