From 4165e996d54ef0144b6cf207dc60c2cfe75bbb39 Mon Sep 17 00:00:00 2001 From: Sebastian Lederer Date: Fri, 28 Jul 2023 19:23:20 +0200 Subject: [PATCH 1/3] create systemtest for python 3 ldap plugin --- systemtests/tests/CMakeLists.txt | 2 +- .../bareos-dir.d/fileset/Catalog.conf.in | 11 -- .../client/FileDaemon-local.conf.in | 5 - .../director/Director-local.conf | 4 - .../storage/StorageDaemon-local.conf.in | 5 - .../CMakeLists.txt | 19 +- .../README.md | 6 +- .../bareos-dir.d/catalog/MyCatalog.conf.in | 0 .../bareos-dir.d/client/bareos-fd.conf.in | 0 .../bareos-dir.d/director/bareos-dir.conf.in | 0 .../bareos-dir.d/fileset/PluginTest.conf.in | 0 .../bareos-dir.d/fileset/SelfTest.conf.in | 1 - .../bareos-dir.d/job/RestoreFiles.conf.in | 0 .../bareos-dir.d/job/backup-bareos-fd.conf | 0 .../bareos-dir.d/jobdefs/DefaultJob.conf.in | 0 .../bareos-dir.d/messages/Daemon.conf.in | 0 .../bareos-dir.d/messages/Standard.conf.in | 0 .../bareos-dir.d/pool/Differential.conf | 0 .../etc/bareos/bareos-dir.d/pool/Full.conf | 0 .../bareos/bareos-dir.d/pool/Incremental.conf | 0 .../etc/bareos/bareos-dir.d/pool/Scratch.conf | 0 .../bareos/bareos-dir.d/profile/operator.conf | 0 .../bareos/bareos-dir.d/storage/File.conf.in | 0 .../bareos/bareos-fd.d/client/myself.conf.in | 0 .../bareos-fd.d/director/bareos-dir.conf.in | 0 .../bareos/bareos-fd.d/messages/Standard.conf | 0 .../bareos-sd.d/device/FileStorage.conf.in | 0 .../bareos-sd.d/director/bareos-dir.conf.in | 0 .../bareos/bareos-sd.d/messages/Standard.conf | 0 .../bareos-sd.d/storage/bareos-sd.conf.in | 0 .../etc/bareos/bconsole.conf.in | 0 .../testdata.py | 174 ++++++++---------- .../testrunner | 9 +- 33 files changed, 94 insertions(+), 142 deletions(-) delete mode 100644 systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in delete mode 100644 systemtests/tests/py2plug-fd-ldap/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in delete mode 100644 systemtests/tests/py2plug-fd-ldap/etc/bareos/tray-monitor.d/director/Director-local.conf delete mode 100644 systemtests/tests/py2plug-fd-ldap/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/CMakeLists.txt (80%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/README.md (88%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in (89%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-dir.d/messages/Daemon.conf.in (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-dir.d/messages/Standard.conf.in (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-dir.d/pool/Differential.conf (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-dir.d/pool/Full.conf (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-dir.d/pool/Incremental.conf (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-dir.d/pool/Scratch.conf (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-dir.d/profile/operator.conf (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-dir.d/storage/File.conf.in (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-fd.d/client/myself.conf.in (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-fd.d/messages/Standard.conf (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-sd.d/device/FileStorage.conf.in (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-sd.d/messages/Standard.conf (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/etc/bareos/bconsole.conf.in (100%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/testdata.py (60%) rename systemtests/tests/{py2plug-fd-ldap => py3plug-fd-ldap}/testrunner (83%) diff --git a/systemtests/tests/CMakeLists.txt b/systemtests/tests/CMakeLists.txt index b20ebd6a786..fd8ad8d7f65 100644 --- a/systemtests/tests/CMakeLists.txt +++ b/systemtests/tests/CMakeLists.txt @@ -58,7 +58,6 @@ add_subdirectory(passive) add_subdirectory(pruning) add_subdirectory(py2plug-dir) add_subdirectory(py2plug-fd-contrib-bareos_tasks_mysql) -add_subdirectory(py2plug-fd-ldap) add_subdirectory(py2plug-fd-libcloud) add_subdirectory(py2plug-fd-local-fileset-restoreobject) add_subdirectory(py2plug-fd-mariabackup) @@ -67,6 +66,7 @@ add_subdirectory(py2plug-fd-percona-xtrabackup) add_subdirectory(py2plug-fd-vmware) add_subdirectory(py2plug-sd) add_subdirectory(py2plug-fd-local-fileset-basic) +add_subdirectory(py3plug-fd-ldap) add_subdirectory(py3plug-fd-local-fileset-basic) add_subdirectory(py3plug-fd-basic) add_subdirectory(py3plug-fd-contrib-mysql_dump) diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in b/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in deleted file mode 100644 index 1dbd17581cf..00000000000 --- a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in +++ /dev/null @@ -1,11 +0,0 @@ -FileSet { - Name = "Catalog" - Description = "Backup the catalog dump and Bareos configuration files." - Include { - Options { - Signature = XXH128 - } - File = "@working_dir@/@db_name@.sql" # database dump - File = "@confdir@" # configuration - } -} diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in b/systemtests/tests/py2plug-fd-ldap/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in deleted file mode 100644 index dd00dd9f103..00000000000 --- a/systemtests/tests/py2plug-fd-ldap/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in +++ /dev/null @@ -1,5 +0,0 @@ -Client { - Name = @basename@-fd - Address = localhost - Password = "@mon_fd_password@" # password for FileDaemon -} diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/tray-monitor.d/director/Director-local.conf b/systemtests/tests/py2plug-fd-ldap/etc/bareos/tray-monitor.d/director/Director-local.conf deleted file mode 100644 index 55dae492250..00000000000 --- a/systemtests/tests/py2plug-fd-ldap/etc/bareos/tray-monitor.d/director/Director-local.conf +++ /dev/null @@ -1,4 +0,0 @@ -Director { - Name = bareos-dir - Address = localhost -} diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in b/systemtests/tests/py2plug-fd-ldap/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in deleted file mode 100644 index 6538f4fd248..00000000000 --- a/systemtests/tests/py2plug-fd-ldap/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in +++ /dev/null @@ -1,5 +0,0 @@ -Storage { - Name = bareos-sd - Address = localhost - Password = "@mon_sd_password@" # password for StorageDaemon -} diff --git a/systemtests/tests/py2plug-fd-ldap/CMakeLists.txt b/systemtests/tests/py3plug-fd-ldap/CMakeLists.txt similarity index 80% rename from systemtests/tests/py2plug-fd-ldap/CMakeLists.txt rename to systemtests/tests/py3plug-fd-ldap/CMakeLists.txt index 14440908a26..3c7bcf2ad68 100644 --- a/systemtests/tests/py2plug-fd-ldap/CMakeLists.txt +++ b/systemtests/tests/py3plug-fd-ldap/CMakeLists.txt @@ -1,6 +1,6 @@ # BAREOS® - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2021-2021 Bareos GmbH & Co. KG +# Copyright (C) 2021-2023 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -35,13 +35,12 @@ set(SYSTEMTEST_LDAP_PASSWORD "admin" CACHE STRING "LDAP bind password for plugin test" ) -check_pymodule_available(2 ldap) -if(TARGET python-fd - AND PYMODULE_2_LDAP_FOUND - AND Python2_EXECUTABLE - AND SYSTEMTEST_LDAP_ADDRESS -) - create_systemtest(${SYSTEMTEST_PREFIX} ${BASENAME}) -else() - create_systemtest(${SYSTEMTEST_PREFIX} ${BASENAME} DISABLED) + +if(TARGET python3-fd) + check_pymodule_available(3 ldap) + if(PYMODULE_3_LDAP_FOUND AND SYSTEMTEST_LDAP_ADDRESS) + create_systemtest(${SYSTEMTEST_PREFIX} ${BASENAME}) + else() + create_systemtest(${SYSTEMTEST_PREFIX} ${BASENAME} DISABLED) + endif() endif() diff --git a/systemtests/tests/py2plug-fd-ldap/README.md b/systemtests/tests/py3plug-fd-ldap/README.md similarity index 88% rename from systemtests/tests/py2plug-fd-ldap/README.md rename to systemtests/tests/py3plug-fd-ldap/README.md index 9b2c634e2f7..304d26d30d7 100644 --- a/systemtests/tests/py2plug-fd-ldap/README.md +++ b/systemtests/tests/py3plug-fd-ldap/README.md @@ -8,7 +8,7 @@ Finally both subtrees will be compared. Besides simple DNs we also test DNs with special characters (i.e. quotes, backslashes, newlines, etc.) and UTF-8 characters. ## Requirements to run -For this to work you will have to build Bareos with the Python 2 plugin for the Bareos FD. +For this to work you will have to build Bareos with the Python 3 plugin for the Bareos FD. The python code itself requires the python-ldap library. To run a backup and a restore this test requires a working LDAP server. @@ -22,6 +22,4 @@ You should configure the following CMake settings to point the test at your serv * `SYSTEMTEST_LDAP_BINDDN` * `SYSTEMTEST_LDAP_PASSWORD` -Everything besides `SYSTEMTEST_LDAP_ADDRESS` defaults to the valies for the above container. - -AFAICT this test will not work with Python 3. +Everything besides `SYSTEMTEST_LDAP_ADDRESS` defaults to the values for the above container. diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in similarity index 89% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in index e2acb53b583..b875bf23fd3 100644 --- a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in +++ b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in @@ -5,7 +5,6 @@ FileSet { Options { Signature = XXH128 } - #File = "@sbindir@" File=<@tmpdir@/file-list } } diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/messages/Daemon.conf.in b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/messages/Daemon.conf.in similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/messages/Daemon.conf.in rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/messages/Daemon.conf.in diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/messages/Standard.conf.in b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/messages/Standard.conf.in similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/messages/Standard.conf.in rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/messages/Standard.conf.in diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/pool/Differential.conf b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/pool/Differential.conf similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/pool/Differential.conf rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/pool/Differential.conf diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/pool/Full.conf b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/pool/Full.conf similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/pool/Full.conf rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/pool/Full.conf diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/pool/Incremental.conf b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/pool/Incremental.conf similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/pool/Incremental.conf rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/pool/Incremental.conf diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/pool/Scratch.conf b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/pool/Scratch.conf similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/pool/Scratch.conf rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/pool/Scratch.conf diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/profile/operator.conf b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/profile/operator.conf similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/profile/operator.conf rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/profile/operator.conf diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/storage/File.conf.in b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/storage/File.conf.in similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-dir.d/storage/File.conf.in rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-dir.d/storage/File.conf.in diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-fd.d/client/myself.conf.in similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-fd.d/client/myself.conf.in rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-fd.d/client/myself.conf.in diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-fd.d/messages/Standard.conf b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-fd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-fd.d/messages/Standard.conf rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-fd.d/messages/Standard.conf diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-sd.d/device/FileStorage.conf.in b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-sd.d/device/FileStorage.conf.in similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-sd.d/device/FileStorage.conf.in rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-sd.d/device/FileStorage.conf.in diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-sd.d/messages/Standard.conf b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-sd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-sd.d/messages/Standard.conf rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-sd.d/messages/Standard.conf diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in diff --git a/systemtests/tests/py2plug-fd-ldap/etc/bareos/bconsole.conf.in b/systemtests/tests/py3plug-fd-ldap/etc/bareos/bconsole.conf.in similarity index 100% rename from systemtests/tests/py2plug-fd-ldap/etc/bareos/bconsole.conf.in rename to systemtests/tests/py3plug-fd-ldap/etc/bareos/bconsole.conf.in diff --git a/systemtests/tests/py2plug-fd-ldap/testdata.py b/systemtests/tests/py3plug-fd-ldap/testdata.py similarity index 60% rename from systemtests/tests/py2plug-fd-ldap/testdata.py rename to systemtests/tests/py3plug-fd-ldap/testdata.py index cbe3c45598f..84bab29140c 100755 --- a/systemtests/tests/py2plug-fd-ldap/testdata.py +++ b/systemtests/tests/py3plug-fd-ldap/testdata.py @@ -1,8 +1,8 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # BAREOS - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2020-2020 Bareos GmbH & Co. KG +# Copyright (C) 2020-2023 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -31,25 +31,13 @@ def _safe_encode(data): - if isinstance(data, unicode): + if isinstance(data, str): return data.encode("utf-8") return data -class BytesLDIFRecordList(ldif.LDIFRecordList): - """Simple encoding wrapper for LDIFRecordList that converts keys to UTF-8""" - - def _next_key_and_value(self): - # we do not descend from object, so we cannot use super() - k, v = ldif.LDIFRecordList._next_key_and_value(self) - return k.encode("utf-8"), v - - def ldap_connect(address, binddn, password): - try: - conn = ldap.initialize("ldap://%s" % address, bytes_mode=True) - except TypeError: - conn = ldap.initialize("ldap://%s" % address) + conn = ldap.initialize("ldap://%s" % address) conn.set_option(ldap.OPT_REFERRALS, 0) conn.simple_bind_s(binddn, password) @@ -76,7 +64,7 @@ def action_clean(conn, basedn): longest to shortest dn, so we remove parent objects later """ - for subtree_dn in [b"ou=backup,%s" % basedn, b"ou=restore,%s" % basedn]: + for subtree_dn in ["ou=backup,%s" % basedn, "ou=restore,%s" % basedn]: try: for dn in sorted( map( @@ -96,91 +84,97 @@ def action_populate(conn, basedn): """Populate our backup data""" ldap_create_or_fail( conn, - b"ou=backup,%s" % basedn, - {b"objectClass": [b"organizationalUnit"], b"ou": [b"restore"]}, + "ou=backup,%s" % basedn, + {"objectClass": [b"organizationalUnit"], "ou": [b"restore"]}, ) ldap_create_or_fail( conn, - b"cn=No JPEG,ou=backup,%s" % basedn, + "cn=No JPEG,ou=backup,%s" % basedn, { - b"objectClass": [b"inetOrgPerson", b"posixAccount", b"shadowAccount"], - b"uid": [b"njpeg"], - b"sn": [b"JPEG"], - b"givenName": [b"No"], - b"cn": [b"No JPEG"], - b"displayName": [b"No JPEG"], - b"uidNumber": [b"1000"], - b"gidNumber": [b"1000"], - b"loginShell": [b"/bin/bash"], - b"homeDirectory": [b"/home/njpeg"], + "objectClass": [b"inetOrgPerson", b"posixAccount", b"shadowAccount"], + "uid": [b"njpeg"], + "sn": [b"JPEG"], + "givenName": [b"No"], + "cn": [b"No JPEG"], + "displayName": [b"No JPEG"], + "uidNumber": [b"1000"], + "gidNumber": [b"1000"], + "loginShell": [b"/bin/bash"], + "homeDirectory": [b"/home/njpeg"], }, ) + photo = open("image-small.jpg", "rb").read() + ldap_create_or_fail( conn, - b"cn=Small JPEG,ou=backup,%s" % basedn, + "cn=Small JPEG,ou=backup,%s" % basedn, { - b"objectClass": [b"inetOrgPerson", b"posixAccount", b"shadowAccount"], - b"uid": [b"sjpeg"], - b"sn": [b"JPEG"], - b"givenName": [b"Small"], - b"cn": [b"Small JPEG"], - b"displayName": [b"Small JPEG"], - b"uidNumber": [b"1001"], - b"gidNumber": [b"1000"], - b"loginShell": [b"/bin/bash"], - b"homeDirectory": [b"/home/sjpeg"], - b"jpegPhoto": open("image-small.jpg", "rb").read(), + "objectClass": [b"inetOrgPerson", b"posixAccount", b"shadowAccount"], + "uid": [b"sjpeg"], + "sn": [b"JPEG"], + "givenName": [b"Small"], + "cn": [b"Small JPEG"], + "displayName": [b"Small JPEG"], + "uidNumber": [b"1001"], + "gidNumber": [b"1000"], + "loginShell": [b"/bin/bash"], + "homeDirectory": [b"/home/sjpeg"], + "jpegPhoto": photo, }, ) + photo = open("image-medium.jpg", "rb").read() + ldap_create_or_fail( conn, - b"cn=Medium JPEG,ou=backup,%s" % basedn, + "cn=Medium JPEG,ou=backup,%s" % basedn, { - b"objectClass": [b"inetOrgPerson", b"posixAccount", b"shadowAccount"], - b"uid": [b"mjpeg"], - b"sn": [b"JPEG"], - b"givenName": [b"Medium"], - b"cn": [b"Medium JPEG"], - b"displayName": [b"Medium JPEG"], - b"uidNumber": [b"1002"], - b"gidNumber": [b"1000"], - b"loginShell": [b"/bin/bash"], - b"homeDirectory": [b"/home/mjpeg"], - b"jpegPhoto": open("image-medium.jpg", "rb").read(), + "objectClass": [b"inetOrgPerson", b"posixAccount", b"shadowAccount"], + "uid": [b"mjpeg"], + "sn": [b"JPEG"], + "givenName": [b"Medium"], + "cn": [b"Medium JPEG"], + "displayName": [b"Medium JPEG"], + "uidNumber": [b"1002"], + "gidNumber": [b"1000"], + "loginShell": [b"/bin/bash"], + "homeDirectory": [b"/home/mjpeg"], + "jpegPhoto": photo, }, ) + photo = open("image-large.jpg", "rb").read() + ldap_create_or_fail( conn, - b"cn=Large JPEG,ou=backup,%s" % basedn, + "cn=Large JPEG,ou=backup,%s" % basedn, { - b"objectClass": [b"inetOrgPerson", b"posixAccount", b"shadowAccount"], - b"uid": [b"ljpeg"], - b"sn": [b"JPEG"], - b"givenName": [b"Large"], - b"cn": [b"Large JPEG"], - b"displayName": [b"Large JPEG"], - b"uidNumber": [b"1003"], - b"gidNumber": [b"1000"], - b"loginShell": [b"/bin/bash"], - b"homeDirectory": [b"/home/ljpeg"], - b"jpegPhoto": open("image-large.jpg", "rb").read(), + "objectClass": [b"inetOrgPerson", b"posixAccount", b"shadowAccount"], + "uid": [b"ljpeg"], + "sn": [b"JPEG"], + "givenName": [b"Large"], + "cn": [b"Large JPEG"], + "displayName": [b"Large JPEG"], + "uidNumber": [b"1003"], + "gidNumber": [b"1000"], + "loginShell": [b"/bin/bash"], + "homeDirectory": [b"/home/ljpeg"], + "jpegPhoto": photo, }, ) ldap_create_or_fail( conn, - b"o=Bareos GmbH & Co. KG,ou=backup,%s" % basedn, - {b"objectClass": [b"top", b"organization"], b"o": [b"Bareos GmbH & Co. KG"]}, + "o=Bareos GmbH & Co. KG,ou=backup,%s" % basedn, + {"objectClass": [b"top", b"organization"], "o": [b"Bareos GmbH & Co. KG"]}, ) ldap_create_or_fail( conn, - b"ou=automount,ou=backup,%s" % basedn, - {b"objectClass": [b"top", b"organizationalUnit"], b"ou": [b"automount"]}, + "ou=automount,ou=backup,%s" % basedn, + {"objectClass": [b"top", b"organizationalUnit"], "ou": [b"automount"]}, ) # # Objects with / in the DN are currently not supported @@ -196,8 +190,8 @@ def action_populate(conn, basedn): ldap_create_or_fail( conn, - b"ou=weird-names,ou=backup,%s" % basedn, - {b"objectClass": [b"top", b"organizationalUnit"], b"ou": [b"weird-names"]}, + "ou=weird-names,ou=backup,%s" % basedn, + {"objectClass": [b"top", b"organizationalUnit"], "ou": [b"weird-names"]}, ) for ou in [ @@ -218,27 +212,28 @@ def action_populate(conn, basedn): ]: ldap_create_or_fail( conn, - b"ou=%s,ou=weird-names,ou=backup,%s" - % (ldap.dn.escape_dn_chars(ou), basedn), - {b"objectClass": [b"top", b"organizationalUnit"], b"ou": [ou]}, + "ou=%s,ou=weird-names,ou=backup,%s" + % (ldap.dn.escape_dn_chars(ou.decode("utf8")), basedn), + {"objectClass": [b"top", b"organizationalUnit"], "ou": [ou]}, ) # creating the DN using the normal method wouldn't work, so we create a # temporary LDIF and parse that. ldif_data = io.BytesIO() - ldif_data.write(b"dn: ou=böses encoding,ou=weird-names,ou=backup,") - ldif_data.write(b"%s\n" % basedn.encode("ascii")) + ldif_data.write("dn: ou=böses encoding,ou=weird-names,ou=backup,".encode("utf8")) + ldif_data.write(b"%s\n" % basedn.encode("utf8")) ldif_data.write(b"objectClass: top\n") ldif_data.write(b"objectClass: organizationalUnit\n") - ldif_data.write(b"ou: böses encoding\n") + ldif_data.write("ou: böses encoding\n".encode("utf8")) ldif_data.seek(0) - ldif_parser = BytesLDIFRecordList(ldif_data, max_entries=1) + ldif_parser = ldif.LDIFRecordList(ldif_data, max_entries=1) ldif_parser.parse() + dn, entry = ldif_parser.all_records[0] ldif_data.close() - ldap_create_or_fail(conn, _safe_encode(dn), entry) + ldap_create_or_fail(conn, dn, entry) def abbrev_value(v): @@ -246,7 +241,7 @@ def abbrev_value(v): length = len(v) if length > 80: digest = hashlib.sha1(v).hexdigest() - return "BLOB len:%d sha1:%s" % (length, digest) + return ("BLOB len:%d sha1:%s" % (length, digest)).encode("utf8") return v @@ -255,19 +250,12 @@ def action_dump(conn, basedn, shorten=True, rewrite_dn=True): try: for dn, attrs in conn.search_s(basedn, ldap.SCOPE_SUBTREE): if rewrite_dn: - dn = ( - dn.decode("utf-8") - .replace(basedn, "dc=unified,dc=base,dc=dn") - .encode("utf-8") - ) + dn = dn.replace(basedn, "dc=unified,dc=base,dc=dn") if shorten: attrs = { - k: [abbrev_value(v) for v in vals] for k, vals in attrs.iteritems() + k: [abbrev_value(v) for v in vals] for k, vals in attrs.items() } - try: - writer.unparse(dn, attrs) - except UnicodeDecodeError: - writer.unparse(dn.decode("utf-8"), attrs) + writer.unparse(dn, attrs) except ldap.NO_SUCH_OBJECT: print("No object '%s' in directory." % basedn, file=sys.stderr) sys.exit(1) @@ -329,14 +317,14 @@ def action_dump(conn, basedn, shorten=True, rewrite_dn=True): if args.dump_backup: action_dump( conn, - b"ou=backup,%s" % args.basedn, + "ou=backup,%s" % args.basedn, shorten=not args.full_value, rewrite_dn=not args.real_dn, ) if args.dump_restore: action_dump( conn, - b"ou=restore,%s" % args.basedn, + "ou=restore,%s" % args.basedn, shorten=not args.full_value, rewrite_dn=not args.real_dn, ) diff --git a/systemtests/tests/py2plug-fd-ldap/testrunner b/systemtests/tests/py3plug-fd-ldap/testrunner similarity index 83% rename from systemtests/tests/py2plug-fd-ldap/testrunner rename to systemtests/tests/py3plug-fd-ldap/testrunner index 375df4c5b7d..a8e2b7b32ed 100755 --- a/systemtests/tests/py2plug-fd-ldap/testrunner +++ b/systemtests/tests/py3plug-fd-ldap/testrunner @@ -4,14 +4,7 @@ set -o pipefail set -u # # This systemtest tests the plugin functionality -# of the Bareos FD by using the supplied module -# bareos-fd-local-fileset.py -# -# The module will backup some files. -# This plugin is not intended for production, -# but is only a minimal example that shows -# how to use the python plugin interface. -# File attributes like uses and times will not be saved. +# of the Bareos FD with the Python LDAP plugin. # TestName="$(basename "$(pwd)")" export TestName From 36524be28478bbb6f555952c0ea255089b157cc0 Mon Sep 17 00:00:00 2001 From: Sebastian Lederer Date: Thu, 10 Aug 2023 16:20:45 +0200 Subject: [PATCH 2/3] python-plugin-ldap: changes for Python 3 Adjust to different behaviour of python-ldap in Python 3, cleanup constants, remove unused code. --- .../filed/python/ldap/BareosFdPluginLDAP.py | 104 +++++++----------- 1 file changed, 42 insertions(+), 62 deletions(-) diff --git a/core/src/plugins/filed/python/ldap/BareosFdPluginLDAP.py b/core/src/plugins/filed/python/ldap/BareosFdPluginLDAP.py index ae81384cfd7..9e5add6ec23 100644 --- a/core/src/plugins/filed/python/ldap/BareosFdPluginLDAP.py +++ b/core/src/plugins/filed/python/ldap/BareosFdPluginLDAP.py @@ -28,7 +28,6 @@ import bareosfd import BareosFdPluginBaseclass -from StringIO import StringIO from stat import S_IFREG, S_IFDIR, S_IRWXU import io import ldif @@ -41,23 +40,11 @@ def _safe_encode(data): - if isinstance(data, unicode): + if isinstance(data, str): return data.encode("utf-8") return data -class BytesLDIFRecordList(ldif.LDIFRecordList): - """Simple encoding wrapper for LDIFRecordList that converts keys to UTF-8""" - - def _next_key_and_value(self): - # we do not descend from object, so we cannot use super() - k, v = ldif.LDIFRecordList._next_key_and_value(self) - try: - return _safe_encode(k), v - except: - return k, v - - class BareosFdPluginLDAP(BareosFdPluginBaseclass.BareosFdPluginBaseclass): """ LDAP related backup and restore stuff @@ -134,14 +121,14 @@ def create_file(self, restorepkt): bareosfd.DebugMessage( 100, "BareosFdPluginLDAP:create_file() called with %s\n" % (restorepkt) ) - if restorepkt.type == bareosfd.bFileType["FT_DIREND"]: - restorepkt.create_status = bareosfd.bCFs["CF_SKIP"] - elif restorepkt.type == bareosfd.bFileType["FT_REG"]: + if restorepkt.type == bareosfd.FT_DIREND: + restorepkt.create_status = bareosfd.CF_SKIP + elif restorepkt.type == bareosfd.FT_REG: self.ldap.set_new_dn(restorepkt.ofname) - restorepkt.create_status = bareosfd.bCFs["CF_EXTRACT"] + restorepkt.create_status = bareosfd.CF_EXTRACT else: bareosfd.JobMessage( - bareosfd.bJobMessageType["M_FATAL"], + bareosfd.M_FATAL, "Request to restore illegal filetype %s\n" % (restorepkt.type), ) return bareosfd.bRC_Error @@ -153,24 +140,24 @@ def plugin_io(self, IOP): 100, "BareosFdPluginLDAP:plugin_io() called with function %s\n" % (IOP.func) ) - if IOP.func == bareosfd.bIOPS["IO_OPEN"]: + if IOP.func == bareosfd.IO_OPEN: self.last_op = IOP.func return bareosfd.bRC_OK - elif IOP.func == bareosfd.bIOPS["IO_CLOSE"]: - if self.last_op == bareosfd.bIOPS["IO_OPEN"]: + elif IOP.func == bareosfd.IO_CLOSE: + if self.last_op == bareosfd.IO_OPEN: bareosfd.JobMessage( - bareosfd.bJobMessageType["M_WARNING"], + bareosfd.M_WARNING, "Missing data for DN %s\n" % self.ldap.dn, ) self.last_op = IOP.func return bareosfd.bRC_OK - elif IOP.func == bareosfd.bIOPS["IO_SEEK"]: + elif IOP.func == bareosfd.IO_SEEK: self.last_op = IOP.func return bareosfd.bRC_OK - elif IOP.func == bareosfd.bIOPS["IO_READ"]: + elif IOP.func == bareosfd.IO_READ: if not self.data_stream: self.data_stream = io.BytesIO(_safe_encode(self.ldap.ldif)) IOP.buf = bytearray(IOP.count) @@ -184,7 +171,7 @@ def plugin_io(self, IOP): self.last_op = IOP.func return bareosfd.bRC_OK - elif IOP.func == bareosfd.bIOPS["IO_WRITE"]: + elif IOP.func == bareosfd.IO_WRITE: if not self.data_stream: self.data_stream = io.BytesIO() @@ -238,15 +225,9 @@ def connect_and_bind(self, options, bulk=False): Bind to LDAP URI using the given authentication tokens """ if bulk: - try: - self.ld = BulkLDAP(options["uri"], bytes_mode=True) - except TypeError: - self.ld = BulkLDAP(options["uri"]) + self.ld = BulkLDAP(options["uri"]) else: - try: - self.ld = ldap.initialize(options["uri"], bytes_mode=True) - except TypeError: - self.ld = ldap.initialize(options["uri"]) + self.ld = ldap.initialize(options["uri"]) try: self.ld.protocol_version = ldap.VERSION3 @@ -256,7 +237,7 @@ def connect_and_bind(self, options, bulk=False): self.ld.simple_bind_s("", "") except ldap.INVALID_CREDENTIALS: bareosfd.JobMessage( - bareosfd.bJobMessageType["M_FATAL"], + bareosfd.M_FATAL, "Failed to bind to LDAP uri due to invalid credentials %s\n" % (options["uri"]), ) @@ -265,13 +246,13 @@ def connect_and_bind(self, options, bulk=False): except ldap.LDAPError as e: if type(e.message) == dict and "desc" in e.message: bareosfd.JobMessage( - bareosfd.bJobMessageType["M_FATAL"], + bareosfd.M_FATAL, "Failed to bind to LDAP uri %s: %s %s\n" % (options["uri"], e.message["desc"], e.message["info"]), ) else: bareosfd.JobMessage( - bareosfd.bJobMessageType["M_FATAL"], + bareosfd.M_FATAL, "Failed to bind to LDAP uri %s: %s\n" % (options["uri"], e), ) @@ -313,13 +294,13 @@ def prepare_backup(self, options): except ldap.LDAPError as e: if type(e.message) == dict and "desc" in e.message: bareosfd.JobMessage( - bareosfd.bJobMessageType["M_FATAL"], + bareosfd.M_FATAL, "Failed to execute LDAP search on LDAP uri %s: %s\n" % (options["uri"], e.message["desc"]), ) else: bareosfd.JobMessage( - bareosfd.bJobMessageType["M_FATAL"], + bareosfd.M_FATAL, "Failed to execute LDAP search on LDAP uri %s: %s\n" % (options["uri"], e), ) @@ -358,18 +339,15 @@ def get_next_file_to_backup(self, savepkt): # Remove some attributes from entry before creating the LDIF. ignore_attribute = ["createTimestamp", "modifyTimestamp"] - keys = self.entry.keys() + keys = list(self.entry.keys()) for value in keys: if value in ignore_attribute: del self.entry[value] # Dump the content of the LDAP entry as LDIF text - ldif_dump = StringIO() + ldif_dump = io.StringIO() ldif_out = ldif.LDIFWriter(ldif_dump) - try: - ldif_out.unparse(self.dn, self.entry) - except UnicodeDecodeError: - ldif_out.unparse(self.dn.decode("utf-8"), self.entry) + ldif_out.unparse(self.dn, self.entry) self.ldif = ldif_dump.getvalue() self.ldif_len = len(self.ldif) @@ -384,7 +362,7 @@ def get_next_file_to_backup(self, savepkt): statp.st_mtime = self.unix_modify_time savepkt.statp = statp - savepkt.type = bareosfd.bFileType["FT_REG"] + savepkt.type = bareosfd.FT_REG savepkt.fname = self.file_to_backup + "/data.ldif" # Read the content of a file savepkt.no_read = False @@ -398,7 +376,7 @@ def get_next_file_to_backup(self, savepkt): # Try to get the first result set from the query, # if there is nothing return an error. try: - res_type, res_data, res_msgid, res_controls = self.resultset.next() + res_type, res_data, res_msgid, res_controls = next(self.resultset) self.ldap_entries = collections.deque(res_data) except ldap.NO_SUCH_OBJECT: return bareosfd.bRC_Error @@ -414,7 +392,9 @@ def get_next_file_to_backup(self, savepkt): # convert it to an UNIX timestamp self.unix_create_time = None try: - createTimestamp = self.entry["createTimestamp"][0] + createTimestamp = self.entry["createTimestamp"][0].decode( + "ascii" + ) except KeyError: pass else: @@ -422,7 +402,9 @@ def get_next_file_to_backup(self, savepkt): self.unix_modify_time = None try: - modifyTimestamp = self.entry["modifyTimestamp"][0] + modifyTimestamp = self.entry["modifyTimestamp"][0].decode( + "ascii" + ) except KeyError: pass else: @@ -442,7 +424,8 @@ def get_next_file_to_backup(self, savepkt): statp.st_mtime = self.unix_modify_time savepkt.statp = statp - savepkt.type = bareosfd.bFileType["FT_DIREND"] + + savepkt.type = bareosfd.FT_DIREND savepkt.fname = self.file_to_backup # A directory has a link field which contains # the fname + a trailing '/' @@ -452,7 +435,7 @@ def get_next_file_to_backup(self, savepkt): if "/" in self.dn: bareosfd.JobMessage( - bareosfd.bJobMessageType["M_ERROR"], + bareosfd.M_ERROR, "Slashes (/) in DN not supported. Skipping %s" % self.dn, ) # set to none, so the object will not be picket up @@ -469,9 +452,7 @@ def set_new_dn(self, fname): 3. filter out anything without an equals sign("=") 4. join components into comma-separated string """ - self.dn = _safe_encode( - ",".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 @@ -484,7 +465,7 @@ def has_next_file(self): if self.resultset: try: # Get the next result set - res_type, res_data, res_msgid, res_controls = self.resultset.next() + res_type, res_data, res_msgid, res_controls = next(self.resultset) self.ldap_entries = collections.deque(res_data) # We expect something to be in the result set but better check @@ -502,16 +483,15 @@ def restore_entry(self): # Restore the entry if self.ldif: # Parse the LDIF back to an attribute list - ldif_dump = StringIO(str(self.ldif)) - ldif_parser = BytesLDIFRecordList(ldif_dump, max_entries=1) + ldif_dump = io.StringIO(self.ldif) + ldif_parser = ldif.LDIFRecordList(ldif_dump, max_entries=1) ldif_parser.parse() dn, entry = ldif_parser.all_records[0] - dn = _safe_encode(dn) ldif_dump.close() if self.dn != dn: bareosfd.JobMessage( - bareosfd.bJobMessageType["M_INFO"], + bareosfd.M_INFO, "Restoring original DN %s as %s\n" % (dn, self.dn), ) @@ -529,20 +509,20 @@ def restore_entry(self): except ldap.LDAPError as e: if type(e.message) == dict and "desc" in e.message: bareosfd.JobMessage( - bareosfd.bJobMessageType["M_ERROR"], + bareosfd.M_ERROR, "Failed to restore LDAP DN %s: %s\n" % (self.dn, e.message["desc"]), ) else: bareosfd.JobMessage( - bareosfd.bJobMessageType["M_ERROR"], + bareosfd.M_ERROR, "Failed to restore LDAP DN %s: %s\n" % (self.dn, e), ) self.ldif = None return bareosfd.bRC_Error else: bareosfd.JobMessage( - bareosfd.bJobMessageType["M_ERROR"], + bareosfd.M_ERROR, "Failed to restore LDAP DN %s no writable binding to LDAP exists\n" % (self.dn), ) From a01c934358536de6f9b543d7e184b142d8bc081c Mon Sep 17 00:00:00 2001 From: Bareos Bot Date: Thu, 10 Aug 2023 20:36:41 +0000 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3631a19f7bb..bd3e175b3f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https: - dird: add prev and new jobid variables [PR #1499] - improve default configuration [PR #1508] - stored: add AccessMode SD->Device directive to reserve devices exclusively for reading or writing [PR #1464] +- plugins: switch python-ldap plugin to python3 [PR #1522] ### Removed - remove no longer used pkglists [PR #1335] @@ -224,4 +225,5 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https: [PR #1508]: https://github.com/bareos/bareos/pull/1508 [PR #1511]: https://github.com/bareos/bareos/pull/1511 [PR #1512]: https://github.com/bareos/bareos/pull/1512 +[PR #1522]: https://github.com/bareos/bareos/pull/1522 [unreleased]: https://github.com/bareos/bareos/tree/master