Skip to content

Commit

Permalink
filed: ldap - support backup/restore large objects
Browse files Browse the repository at this point in the history
Previously the plugin would not back up large objects (>64k ldif data).
This patch now adds support for these larger objects.
  • Loading branch information
arogge committed Sep 11, 2020
1 parent e9b60b1 commit 7ee398a
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions core/src/plugins/filed/python/ldap/BareosFdPluginLDAP.py
Expand Up @@ -30,6 +30,7 @@
import BareosFdPluginBaseclass
from StringIO import StringIO
from stat import S_IFREG, S_IFDIR, S_IRWXU
import io
import ldif
import ldap
import ldap.resiter
Expand All @@ -51,6 +52,7 @@ def __init__(self, plugindef):
)
super(BareosFdPluginLDAP, self).__init__(plugindef, ["uri", "basedn"])
self.ldap = BareosLDAPWrapper()
self.data_stream = None

def parse_plugin_definition(self, plugindef):
"""
Expand Down Expand Up @@ -140,7 +142,8 @@ def plugin_io(self, IOP):
if self.last_op == bareosfd.bIOPS["IO_OPEN"]:
bareosfd.JobMessage(
bareosfd.bJobMessageType["M_WARNING"],
"Missing data for DN %s\n" % self.ldap.dn)
"Missing data for DN %s\n" % self.ldap.dn,
)
self.last_op = IOP.func
return bareosfd.bRC_OK

Expand All @@ -149,21 +152,24 @@ def plugin_io(self, IOP):
return bareosfd.bRC_OK

elif IOP.func == bareosfd.bIOPS["IO_READ"]:
if self.ldap.ldif:
IOP.buf = bytearray(self.ldap.ldif)
IOP.status = self.ldap.ldif_len
if not self.data_stream:
self.data_stream = io.BytesIO(self.ldap.ldif)
IOP.buf = bytearray(IOP.count)
IOP.status = self.data_stream.readinto(IOP.buf)

if IOP.status == 0:
self.data_stream = None
self.ldap.ldif = None
else:
IOP.status = 0
IOP.io_errno = 0

IOP.io_errno = 0
self.last_op = IOP.func
return bareosfd.bRC_OK

elif IOP.func == bareosfd.bIOPS["IO_WRITE"]:
self.ldap.ldif = str(IOP.buf)
self.ldap.ldif_len = IOP.count
IOP.status = IOP.count
if not self.data_stream:
self.data_stream = io.BytesIO()

IOP.status = self.data_stream.write(IOP.buf)
IOP.io_errno = 0

self.last_op = IOP.func
Expand All @@ -177,6 +183,11 @@ def end_backup_file(self):
def end_restore_file(self):
bareosfd.DebugMessage(100, "BareosFdPluginLDAP:end_restore_file() called\n")

if self.data_stream is not None:
self.ldap.ldif = self.data_stream.getvalue().decode("ascii")
self.ldap.ldif_len = len(self.ldap.ldif)
self.data_stream = None

return self.ldap.restore_entry()


Expand Down Expand Up @@ -420,12 +431,7 @@ def set_new_dn(self, fname):
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("/")),
)
)
self.dn = ",".join(filter(lambda x: "=" in x, reversed(fname.split("/"))))

def has_next_file(self):
# See if we are currently handling the LDIF file or
Expand Down

0 comments on commit 7ee398a

Please sign in to comment.