From 8c72b349db3ee39cbaf481b938a3913c8891dc0d Mon Sep 17 00:00:00 2001 From: alakatos Date: Mon, 12 Dec 2022 11:59:28 +0100 Subject: [PATCH 1/2] Add "--version" option to the usbguard CLI Running usbguard --version should help us handle fixes and issues more easily in the future. By doing so, it's easier to track down which options have been enabled during build time. Fixes #570 --- Makefile.am | 4 +- scripts/bash_completion/usbguard | 2 +- src/CLI/usbguard-print-version.cpp | 83 ++++++++++++++++++++++++++++++ src/CLI/usbguard-print-version.hpp | 29 +++++++++++ src/CLI/usbguard.cpp | 4 +- 5 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 src/CLI/usbguard-print-version.cpp create mode 100644 src/CLI/usbguard-print-version.hpp diff --git a/Makefile.am b/Makefile.am index 2d1ded8e..7dc6849d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -433,7 +433,9 @@ usbguard_SOURCES=\ src/CLI/usbguard-add-user.cpp \ src/CLI/usbguard-add-user.hpp \ src/CLI/usbguard-remove-user.cpp \ - src/CLI/usbguard-remove-user.hpp + src/CLI/usbguard-remove-user.hpp \ + src/CLI/usbguard-print-version.cpp \ + src/CLI/usbguard-print-version.hpp usbguard_CXXFLAGS=\ $(PTHREAD_CFLAGS) diff --git a/scripts/bash_completion/usbguard b/scripts/bash_completion/usbguard index 312e912d..97c21ab5 100644 --- a/scripts/bash_completion/usbguard +++ b/scripts/bash_completion/usbguard @@ -251,7 +251,7 @@ _usbguard() { # If there was no positional argument provided yet, complete commands if [[ $args -eq 1 ]]; then opts="get-parameter set-parameter list-devices allow-device block-device reject-device list-rules append-rule" - opts="${opts} remove-rule generate-policy watch read-descriptor add-user remove-user" + opts="${opts} remove-rule generate-policy watch read-descriptor add-user remove-user --version" else opts='-h --help' diff --git a/src/CLI/usbguard-print-version.cpp b/src/CLI/usbguard-print-version.cpp new file mode 100644 index 00000000..30dc09c1 --- /dev/null +++ b/src/CLI/usbguard-print-version.cpp @@ -0,0 +1,83 @@ +// +// Copyright (C) 2022 Red Hat, Inc. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// Authors: Attila Lakatos +// +#ifdef HAVE_BUILD_CONFIG_H + #include +#endif + +#include "usbguard.hpp" +#include "usbguard-print-version.hpp" + +#include "usbguard/IPCClient.hpp" + +#include +#include +#include + + +namespace usbguard +{ + static std::string toHumanReadable(const int enabled) + { + return enabled ? "enabled" : "disabled"; + } + + int usbguard_print_version(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[]) + { + if (argc != 1) { + return EXIT_FAILURE; + } + + int audit = 0, libcapng = 0, seccomp = 0, systemd = 0, umockdev = 0; + std::string crypto; +#ifdef HAVE_LINUX_AUDIT + audit = 1; +#endif +#ifdef HAVE_LIBCAPNG + libcapng = 1; +#endif +#ifdef HAVE_SECCOMP + seccomp = 1; +#endif +#ifdef SYSTEMD_SUPPORT_ENABLED + systemd = 1; +#endif +#ifdef HAVE_UMOCKDEV + umockdev = 1; +#endif +#ifdef USBGUARD_USE_LIBGCRYPT + crypto = "libgcrypt"; +#elif USBGUARD_USE_LIBSODIUM + crypto = "libsodium"; +#elif USBGUARD_USE_OPENSSL + crypto = "openssl"; +#else + crypto = "unknown"; +#endif + std::cout << "usbguard " << PACKAGE_VERSION << " compiled with:" << std::endl; + std::cout << " Linux audit support: " << toHumanReadable(audit) << std::endl; + std::cout << " Libcapng support: " << toHumanReadable(libcapng) << std::endl; + std::cout << " Seccomp support: " << toHumanReadable(seccomp) << std::endl; + std::cout << " Systemd support: " << toHumanReadable(systemd) << std::endl; + std::cout << " Umockdev support: " << toHumanReadable(umockdev) << std::endl; + std::cout << " Crypto backend library: " << crypto << std::endl; + return EXIT_SUCCESS; + } +} /* namespace usbguard */ + +/* vim: set ts=2 sw=2 et */ diff --git a/src/CLI/usbguard-print-version.hpp b/src/CLI/usbguard-print-version.hpp new file mode 100644 index 00000000..c33efcd3 --- /dev/null +++ b/src/CLI/usbguard-print-version.hpp @@ -0,0 +1,29 @@ +// +// Copyright (C) 2022 Red Hat, Inc. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// Authors: Attila Lakatos +// +#pragma once +#ifdef HAVE_BUILD_CONFIG_H + #include +#endif + +namespace usbguard +{ + int usbguard_print_version(int argc, char** argv); +} /* namespace usbguard */ + +/* vim: set ts=2 sw=2 et */ diff --git a/src/CLI/usbguard.cpp b/src/CLI/usbguard.cpp index 2fc9758b..82b30f61 100644 --- a/src/CLI/usbguard.cpp +++ b/src/CLI/usbguard.cpp @@ -52,6 +52,7 @@ #include "usbguard-read-descriptor.hpp" #include "usbguard-add-user.hpp" #include "usbguard-remove-user.hpp" +#include "usbguard-print-version.hpp" namespace usbguard { @@ -71,7 +72,8 @@ namespace usbguard { "watch", &usbguard_watch }, { "read-descriptor", &usbguard_read_descriptor }, { "add-user", &usbguard_add_user }, - { "remove-user", &usbguard_remove_user } + { "remove-user", &usbguard_remove_user }, + { "--version", &usbguard_print_version } }; static void showTopLevelHelp(std::ostream& stream = std::cout) From b4eabbf1351778f9f651a788c5015ad5475b6110 Mon Sep 17 00:00:00 2001 From: alakatos Date: Thu, 30 May 2024 11:39:32 +0200 Subject: [PATCH 2/2] CI: replace deprecated include module in favor of include_tasks --- .../ansible/roles/bennojoy.openldap_server/tasks/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tests/LDAP/ansible/roles/bennojoy.openldap_server/tasks/main.yml b/src/Tests/LDAP/ansible/roles/bennojoy.openldap_server/tasks/main.yml index 9e96d404..54260df2 100644 --- a/src/Tests/LDAP/ansible/roles/bennojoy.openldap_server/tasks/main.yml +++ b/src/Tests/LDAP/ansible/roles/bennojoy.openldap_server/tasks/main.yml @@ -1,3 +1,3 @@ --- -- include: install_ldap.yml -- include: configure_ldap.yml +- include_tasks: install_ldap.yml +- include_tasks: configure_ldap.yml