From 8943ad79131e99aaa1103e6fd8f56b70aeb0fade Mon Sep 17 00:00:00 2001 From: Tristan Lelong Date: Mon, 26 May 2025 13:38:17 +0200 Subject: [PATCH] Consolidate dependency on OpenSSH headers. Create a new openssh/ folder and add a wrapper to OpenSSH includes. This allows the code to: * Rely on includes.h from OpenSSH for better compatibility (see github.com/google/hiba/commit/642d64ffec5719178644078867bcd4ff88298621). * Fix pre-processor conflicts on config.h symbols that are used in both projects. This also remove uneeded includes in some source files. --- Makefile.am | 2 +- certificates.c | 2 ++ checks.c | 3 ++- configure.ac | 24 ++++++++++++++++-------- errors.c | 1 - hiba-chk.c | 2 ++ hiba-gen.c | 2 ++ hiba-grl.c | 2 ++ openssh/includes.h | 26 ++++++++++++++++++++++++++ revocations.c | 4 +++- util.c | 6 +++++- 11 files changed, 61 insertions(+), 13 deletions(-) create mode 100644 openssh/includes.h diff --git a/Makefile.am b/Makefile.am index 09017f0..d719588 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,7 +8,7 @@ ACLOCAL_AMFLAGS = -I m4 ARFLAGS = cr AM_LIBTOOLFLAGS = "--preserve-dup-deps" -include_HEADERS = hiba.h extensions.h errors.h checks.h certificates.h revocations.h +include_HEADERS = hiba.h extensions.h errors.h checks.h certificates.h revocations.h openssh/includes.h lib_LTLIBRARIES = libhiba.la libhiba_la_SOURCES = extensions.c errors.c checks.c certificates.c revocations.c diff --git a/certificates.c b/certificates.c index b8952ad..ccad6be 100644 --- a/certificates.c +++ b/certificates.c @@ -9,6 +9,8 @@ #include #include +#include "config.h" + #include "extensions.h" #include "certificates.h" #include "errors.h" diff --git a/checks.c b/checks.c index 49e8530..29d77f0 100644 --- a/checks.c +++ b/checks.c @@ -14,8 +14,9 @@ #include #include -#include "checks.h" #include "config.h" + +#include "checks.h" #include "errors.h" #include "extensions.h" #include "log.h" diff --git a/configure.ac b/configure.ac index 3cd7c2a..4b333c4 100644 --- a/configure.ac +++ b/configure.ac @@ -5,13 +5,19 @@ m4_define([MAJOR], 1) m4_define([MINOR], 4) AC_PREREQ([2.69]) -AC_INIT([HIBA], [MAJOR.MINOR], [hibassh@google.com]) +AC_INIT([HIBA], [MAJOR.MINOR], [hibassh@google.com], [], [https://github.com/google/hiba]) AC_CONFIG_SRCDIR([hiba.h]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIRS([m4]) AC_LANG([C]) AC_PROG_CC([cc gcc clang]) +AH_TOP([#ifndef HIBA_CONFIG_H_ +#define HIBA_CONFIG_H_ + +#include "openssh/includes.h"]) +AH_BOTTOM([#endif /* HIBA_CONFIG_H_ */]) + LT_INIT AM_INIT_AUTOMAKE([foreign no-dependencies]) @@ -122,13 +128,6 @@ AC_LINK_IFELSE( ) LDFLAGS="$save_LDFLAGS" -# Check for definition of max hostname length -AC_CHECK_DECL( - [HOST_NAME_MAX], [], [AC_DEFINE([HOST_NAME_MAX], [64], [ - Maximum supported hostname size if not already defined by OS. - ])], [#include ], -) - # Update flags. CFLAGS="$CFLAGS $extra_CFLAGS" CPPFLAGS="$CPPFLAGS $extra_CPPFLAGS" @@ -296,6 +295,15 @@ AC_SEARCH_LIBS([sshbuf_new], [ssh], [], [ AC_SUBST([extra_LIBS], [$LIBS]) LIBS="$save_LIBS" +# Check for definition of max hostname length +# If undefined, it could still be provided by OpenSSH headers. +AC_CHECK_DECL([HOST_NAME_MAX], [], AH_VERBATIM([HOST_NAME_MAX], + [/* Maximum supported hostname size if not already defined. */ +#ifndef HOST_NAME_MAX +#define HOST_NAME_MAX 64 +#endif]), [#include ], +) + # Checks for header files. AC_CHECK_HEADERS([inttypes.h limits.h stdint.h stdlib.h string.h sys/types.h unistd.h]) diff --git a/errors.c b/errors.c index 75592dc..0e6fb3f 100644 --- a/errors.c +++ b/errors.c @@ -6,7 +6,6 @@ * https://developers.google.com/open-source/licenses/bsd */ #include "errors.h" -#include "ssherr.h" const char *hiba_err(int err) { if (err == HIBA_OK) diff --git a/hiba-chk.c b/hiba-chk.c index 7cb1f5f..de0d33d 100644 --- a/hiba-chk.c +++ b/hiba-chk.c @@ -14,6 +14,8 @@ #define HIBA_INTERNAL +#include "config.h" + #include "log.h" #include "hiba.h" #include "misc.h" diff --git a/hiba-gen.c b/hiba-gen.c index ba857dd..b933d10 100644 --- a/hiba-gen.c +++ b/hiba-gen.c @@ -12,6 +12,8 @@ #include #include +#include "config.h" + #include "log.h" #include "hiba.h" #include "misc.h" diff --git a/hiba-grl.c b/hiba-grl.c index d22c254..d105188 100644 --- a/hiba-grl.c +++ b/hiba-grl.c @@ -15,6 +15,8 @@ #define HIBA_INTERNAL +#include "config.h" + #include "log.h" #include "hiba.h" #include "misc.h" diff --git a/openssh/includes.h b/openssh/includes.h new file mode 100644 index 0000000..918e430 --- /dev/null +++ b/openssh/includes.h @@ -0,0 +1,26 @@ +/* + * Copyright 2021 The HIBA Authors + * + * Wrapper to openssh headers. + * + * Use of this source code is governed by a BSD-style + * license that can be found in the LICENSE file or at + * https://developers.google.com/open-source/licenses/bsd + */ +#ifndef _OPENSSH_WRAPPER_INCLUDES_H +#define _OPENSSH_WRAPPER_INCLUDES_H + +#include + +/* + * The includes header indirectly includes the config.h file from the OpenSSH + * project which conflicts/overrides HIBA's config.h + */ +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_URL +#undef PACKAGE_VERSION + +#endif /* _OPENSSH_WRAPPER_INCLUDES_H */ diff --git a/revocations.c b/revocations.c index c0a41a0..2859191 100644 --- a/revocations.c +++ b/revocations.c @@ -12,8 +12,10 @@ #include #include -#include "errors.h" +#include "config.h" + #include "log.h" +#include "errors.h" #include "revocations.h" #define HIBA_CURRENT_GRL_VERSION 0x1 diff --git a/util.c b/util.c index 0b55538..05c944e 100644 --- a/util.c +++ b/util.c @@ -14,8 +14,12 @@ #include #include +#include "config.h" + +#include "certificates.h" +#include "errors.h" +#include "extensions.h" #include "log.h" -#include "hiba.h" #include "misc.h" #include "openbsd-compat/bsd-misc.h" #include "ssherr.h"