Skip to content

Commit

Permalink
Add "--version" option to the usbguard CLI
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Cropi committed Dec 12, 2022
1 parent 32713be commit b2a3ef3
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ AC_CONFIG_SRCDIR([src/])
AC_CONFIG_HEADERS([src/build-config.h.in])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([config])
AC_CANONICAL_HOST

AM_INIT_AUTOMAKE([subdir-objects foreign tar-pax])

Expand Down Expand Up @@ -104,6 +105,11 @@ AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
AC_SUBST(LT_AGE)

AC_DEFINE_UNQUOTED([PLATFORM_ID], ["${host}"], [platform id for display purposes])
# we don't mind if we don't have the lsb_release utility. But if we have, it's
# nice to have the extra information.
AC_DEFINE_UNQUOTED([PLATFORM_ID_LSB], ["`lsb_release -d`"], [platform id for display purposes])

AC_ARG_ENABLE([coverage],
[AS_HELP_STRING([--enable-coverage], [enable instrumented compilation for code coverage testing (default=no)])],
[case "${enableval}" in
Expand Down
73 changes: 73 additions & 0 deletions src/CLI/usbguard-print-version.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// 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 <http://www.gnu.org/licenses/>.
//
// Authors: Attila Lakatos <[email protected]>
//
#ifdef HAVE_BUILD_CONFIG_H
#include <build-config.h>
#endif

#include "usbguard.hpp"
#include "usbguard-print-version.hpp"

#include "usbguard/IPCClient.hpp"

#include <iostream>
#include <map>
#include <vector>

namespace usbguard
{
int usbguard_print_version(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
{
if (argc != 1) {
return EXIT_FAILURE;
}

std::cout << "usbguard " << PACKAGE_VERSION << " compiled with:" << std::endl;
std::cout << "\t" << "Platform: \t\t\t" << PLATFORM_ID << std::endl;
std::cout << "\t" << "Platform (lsb_release -d)" << "\t" << PLATFORM_ID_LSB << std::endl;
#ifdef HAVE_LINUX_AUDIT
std::cout << "\t" << "Linux audit support:\t\t" << HAVE_LINUX_AUDIT << std::endl;
#endif
#ifdef HAVE_LIBCAPNG
std::cout << "\t" << "Libcapng support:\t\t" << HAVE_LIBCAPNG << std::endl;
#endif
#ifdef HAVE_SECCOMP
std::cout << "\t" << "Seccomp support:\t\t" << HAVE_SECCOMP << std::endl;
#endif
#ifdef SYSTEMD_SUPPORT_ENABLED
std::cout << "\t" << "Systemd support:\t\t" << SYSTEMD_SUPPORT_ENABLED << std::endl;
#endif
#ifdef HAVE_UMOCKDEV
std::cout << "\t" << "Umockdev support:\t\t" << HAVE_UMOCKDEV << std::endl;
#endif
std::string crypto;
#ifdef USBGUARD_USE_LIBGCRYPT
crypto = "libgcrypt";
#elif USBGUARD_USE_LIBSODIUM
crypto = "libsodium";
#elif USBGUARD_USE_OPENSSL
crypto = "openssl";
#else
crypto = "unknown";
#endif
std::cout << "\t" << "Crypto backend library:\t\t" << crypto << std::endl;
return EXIT_SUCCESS;
}
} /* namespace usbguard */

/* vim: set ts=2 sw=2 et */
29 changes: 29 additions & 0 deletions src/CLI/usbguard-print-version.hpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
//
// Authors: Attila Lakatos <[email protected]>
//
#pragma once
#ifdef HAVE_BUILD_CONFIG_H
#include <build-config.h>
#endif

namespace usbguard
{
int usbguard_print_version(int argc, char** argv);
} /* namespace usbguard */

/* vim: set ts=2 sw=2 et */
4 changes: 3 additions & 1 deletion src/CLI/usbguard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
Expand Down

0 comments on commit b2a3ef3

Please sign in to comment.