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.

(backport of commit 7ee398a)
  • Loading branch information
arogge committed Sep 16, 2020
1 parent 2048ef9 commit 279c229
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions core/src/plugins/filed/BareosFdPluginLDAP.py
Expand Up @@ -31,6 +31,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 @@ -53,6 +54,7 @@ def __init__(self, context, plugindef):
)
super(BareosFdPluginLDAP, self).__init__(context, plugindef, ["uri", "basedn"])
self.ldap = BareosLDAPWrapper()
self.data_stream = None

def parse_plugin_definition(self, context, plugindef):
"""
Expand Down Expand Up @@ -163,21 +165,24 @@ def plugin_io(self, context, IOP):
return bRCs["bRC_OK"]

elif IOP.func == 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 bRCs["bRC_OK"]

elif IOP.func == 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 @@ -195,6 +200,11 @@ def end_restore_file(self, context):
context, 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(context)


Expand Down Expand Up @@ -448,12 +458,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, context):
# See if we are currently handling the LDIF file or
Expand Down

0 comments on commit 279c229

Please sign in to comment.