Skip to content

Commit

Permalink
filed: ldap - improve path handling on restore
Browse files Browse the repository at this point in the history
Previously the destination dn when restoring an ldap object was
generated in a way that made it really hard to restore do a different
location.
This patch replaces the parser with a much more relaxed approach that
accepts different syntaxes. The new behaviour uses every path component
that contains an equals-sign (=) and builds a DN out of these.

(backport of commit 35451a0)
  • Loading branch information
arogge committed Sep 16, 2020
1 parent 948fcca commit 61d5360
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions core/src/plugins/filed/BareosFdPluginLDAP.py
Expand Up @@ -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
Expand Down

0 comments on commit 61d5360

Please sign in to comment.