Skip to content

Commit 7e9c6f3

Browse files
authored
Merge pull request networkupstools#3330 from jimklimov/nit-ssl
Identify SSL support in upsd and libupsclient, add NIT tests for OpenSSL and Mozilla NSS
2 parents d90af21 + 412c7b5 commit 7e9c6f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1259
-135
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ all-libs-local/common: all-libs-local/include @dotMAKE@
268268
### Delivers: libupsclient.la libnutclient.la libnutclientstub.la
269269
### Delivers: libupsclient-version.h
270270
### LIB-Requires-ext: common/libcommonclient.la
271+
### Requires-ext: include/nut_version.h
271272
### Requires-ext: common/libcommon.la common/libcommonclient.la
272273
### Requires-ext: common/libcommonversion.la
273274
### Requires-ext: common/libparseconf.la

NEWS.adoc

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ NUT Release Notes
33
=================
44
endif::txt[]
55

6-
If you're upgrading from an earlier version, see the link:UPGRADING.adoc[] file.
6+
This document summarizes the practical side of changes coming with each
7+
newer release development, as compared to the preceding release.
8+
9+
If you're upgrading from an earlier version, or are a package maintainer,
10+
please see also the link:UPGRADING.adoc[] file about anticipated impacts
11+
of ongoing development on existing deployments and third-party consumers.
712

813
Please note that web and source document links, product and service names
914
listed in historic entries of past releases may no longer be relevant.
@@ -104,6 +109,16 @@ https://github.com/networkupstools/nut/milestone/12
104109
characters. Now it is evaluated at `configure` time (to check that the
105110
characters may be used), and if not -- during `nut_stdint.h` parsing to
106111
fit known `int`/`long`/`long long` types. [#3300]
112+
* Added new API methods and defined bitmap values for `libupsclient`
113+
C binding to query and report SSL capabilities of the current library
114+
build (none, OpenSSL, Mozilla NSS): `upscli_ssl_caps_descr()` and
115+
`upscli_ssl_caps()`. Updated common NUT clients to report this info
116+
in their detailed help banners. Done similarly for `upsd`. The NIT
117+
(NUT Integration Test) suite piggy-backs on this to add run-time
118+
dependent tests of SSL capability. Added `upscli_set_debug_level()`
119+
and `upscli_set_debug_level()` methods to facilitate NUT debugging
120+
for clients built with shared NUT private libraries. [issues #3328,
121+
#1771, #2800, PR #3330]
107122

108123
- NUT for Windows specific updates:
109124
* Revised detection of (relative) paths to program and configuration files
@@ -305,6 +320,11 @@ https://github.com/networkupstools/nut/milestone/12
305320
or Windows `HANDLE`'s at a time, and moving on to another chunk.
306321
The system-provided value can be further limited by `NUT_SYSMAXCONN_LIMIT`
307322
environment variable (e.g. in tests). [#3302]
323+
* Extended processing of `CERTREQUEST` setting to handle numeric or specific
324+
string values, to match both ways of reading ambiguous documentation.
325+
Added `configure --with-ssl-client-validation` toggle to expose the
326+
macro previously meant to be passed via `make` command line. [PR #3330,
327+
but beware issue #3329]
308328

309329
- `upsdrvctl` tool updates:
310330
* Make use of `setproctag()` and `getproctag()` to report parent/child
@@ -533,6 +553,10 @@ several `FSD` notifications into one executed action. [PR #3097]
533553
* Dropped the `compile` script from Git sources. It originates from automake
534554
and is added to work area (if missing) during `autogen.sh` rituals anyway.
535555
It is still distributed as part of `make dist` tarball. [#1209]
556+
* Extended `ci_build.sh` and `build-mingw-nut.sh` so that certain values
557+
of `NUT_SSL_VARIANTS=[yes, no, auto, ssl, nss, openssl]` can be used
558+
with generic builds to test a specific code path and not only the
559+
auto-detected one. [#1711]
536560

537561
- Upstreamed reference packaging recipes (DEB, RPM) from the 42ITy project
538562
which can be used with OBS (Open Build Service by SUSE), both to support

UPGRADING.adoc

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ Upgrading notes
44
endif::txt[]
55

66
This file lists changes that affect users who installed older versions
7-
of this software. When upgrading from an older version, be sure to
8-
check this file to see if you need to make changes to your system.
7+
of this software, or third-party integrations and library or data consumers.
8+
When upgrading from an older NUT version, be sure to check this file to
9+
see if you need to make changes to your system.
10+
11+
We welcome feedback from package maintainers -- if you had to patch something
12+
out, or work around something in NUT code or recipes, please let us know in
13+
the issue tracker. Chances are, other distributions feel your pain, and some
14+
generalized solution belongs in the upstream project as an easy to use build
15+
configuration toggle to be shared by all interested downstream projects.
916

1017
[NOTE]
1118
======
@@ -35,6 +42,10 @@ Changes from 2.8.4 to 2.8.5
3542
library files to deliver with the packages (formally versioned and
3643
named by NUT release semantic version triplet). [issue #2800]
3744
45+
- Related to the above, `libupsclient` will remove the exported symbol for
46+
`nut_debug_level` variable in a later NUT release, and now introduces the
47+
`upscli_set_debug_level()` and `upscli_get_debug_level()` methods. [PR #3330]
48+
3849
- For ages, most recipes for building NUT had customized the `sysconfdir` to
3950
be `/etc/nut`, which is not exactly the *system* configuration directory.
4051
This is finally deprecated, with new `--with-confdir` configuration option
@@ -99,6 +110,10 @@ Changes from 2.8.4 to 2.8.5
99110
use `upsdrvquery_NOSIGPIPE=0` to disable neutering of the signal inside
100111
the API itself. [PR #3277]
101112
113+
- Added new API methods and defined bitmap values for `libupsclient` C binding
114+
to query and report SSL capabilities of the library build (none, OpenSSL,
115+
Mozilla NSS): `upscli_ssl_caps_descr()` and `upscli_ssl_caps()`. [PR #33xx]
116+
102117
- Fixed man page naming for `nutdrv_siemens-sitop(.8)` (dash vs. underscore)
103118
to match the driver program name. Packaging recipes may have to be updated.
104119
Follow-up from slightly botched renaming in original contribution. [PR #545]

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ install:
6363
# versions of packages.
6464
- cmd: |
6565
REM Prerequisites for NUT per https://github.com/networkupstools/nut/blob/master/docs/config-prereqs.txt :
66-
C:\msys64\usr\bin\bash -lc "date -u; pacman --noconfirm -S --needed base-devel mingw-w64-x86_64-toolchain autoconf-wrapper automake-wrapper libtool mingw-w64-x86_64-libltdl gcc ccache mingw-w64-x86_64-ccache git aspell aspell-en python mingw-w64-x86_64-python-pygments mingw-w64-x86_64-winpthreads-git mingw-w64-x86_64-libusb mingw-w64-x86_64-libusb-compat-git mingw-w64-x86_64-neon libneon-devel mingw-w64-x86_64-libgd mingw-w64-x86_64-cppunit"
66+
C:\msys64\usr\bin\bash -lc "date -u; pacman --noconfirm -S --needed base-devel mingw-w64-x86_64-toolchain autoconf-wrapper automake-wrapper libtool mingw-w64-x86_64-libltdl gcc ccache mingw-w64-x86_64-ccache git aspell aspell-en python mingw-w64-x86_64-python-pygments mingw-w64-x86_64-winpthreads-git mingw-w64-x86_64-libusb mingw-w64-x86_64-libusb-compat-git mingw-w64-x86_64-neon libneon-devel mingw-w64-x86_64-libgd mingw-w64-x86_64-cppunit mingw-w64-x86_64-nss mingw-w64-x86_64-openssl"
6767
REM SKIP mingw-w64-x86_64-libmodbus-git : we custom-build one with USB support
6868
REM SKIP for now NUT-Monitor prereqs (runtime Python would require somilar modules; need to fix localization builds like "fr.po"): gettext mingw-w64-x86_64-python-pyqt6
6969
@@ -115,7 +115,7 @@ build_script:
115115
REM to find "nearby" program or configuration files (see common.c
116116
REM for current implementation). Hard-coded fallback strings may
117117
REM end up getting used in those cases.
118-
C:\msys64\usr\bin\bash -lc 'date -u; PATH="/mingw64/bin:$PATH" CI_SKIP_CHECK=true CANBUILD_WITH_LIBMODBUS_USB=yes WITH_LIBNUTPRIVATE=true ./ci_build.sh --with-docs=no'
118+
C:\msys64\usr\bin\bash -lc 'date -u; PATH="/mingw64/bin:$PATH" CI_SKIP_CHECK=true CANBUILD_WITH_LIBMODBUS_USB=yes WITH_LIBNUTPRIVATE=true NUT_SSL_VARIANTS=nss ./ci_build.sh --with-docs=no'
119119
120120
121121
after_build:

ci_build.sh

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ SCRIPT_ARGS=("$@")
3535
# in a different directory and then it would be used with a warning. This may
3636
# require that you `make distclean` the original source checkout first:
3737
# CI_BUILDDIR=obj BUILD_TYPE=default-all-errors ./ci_build.sh
38+
#
39+
# The NUT_SSL_VARIANTS=[yes, no, auto, ssl, nss, openssl] values can be used
40+
# with generic builds (not only iteration of a default-all-errors* matrix)
41+
# to set specific SSL options in tested NUT builds.
42+
#
3843
case "$BUILD_TYPE" in
3944
fightwarn) ;; # for default compiler
4045
fightwarn-all)
@@ -1947,7 +1952,20 @@ default|default-alldrv|default-alldrv:no-distcheck|default-all-errors|default-al
19471952
19481953
case "$BUILD_TYPE" in
19491954
"default-all-errors"*) ;; # Treated below
1950-
*) configure_nut ;;
1955+
*) # Final choices that can conflict with the matrix
1956+
# tried in default-all-errors* builds
1957+
case "${NUT_SSL_VARIANTS}" in
1958+
ssl|nss|openssl)
1959+
CONFIG_OPTS+=("--with-${NUT_SSL_VARIANTS}")
1960+
;;
1961+
yes) CONFIG_OPTS+=("--with-ssl") ;;
1962+
no) CONFIG_OPTS+=("--without-ssl") ;;
1963+
auto) CONFIG_OPTS+=("--with-ssl=auto") ;;
1964+
"") ;;
1965+
*) echo "WARNING: Unrecognized NUT_SSL_VARIANTS='${NUT_SSL_VARIANTS}' for a general deterministic build, ignored" >&2 ;;
1966+
esac
1967+
configure_nut
1968+
;;
19511969
esac
19521970
19531971
# NOTE: There is also a case "$BUILD_TYPE" above for setting CONFIG_OPTS
@@ -2842,6 +2860,17 @@ bindings)
28422860
CONFIG_OPTS+=("--enable-shared-private-libs")
28432861
fi
28442862
2863+
case "${NUT_SSL_VARIANTS}" in
2864+
ssl|nss|openssl)
2865+
CONFIG_OPTS+=("--with-${NUT_SSL_VARIANTS}")
2866+
;;
2867+
yes) CONFIG_OPTS+=("--with-ssl") ;;
2868+
no) CONFIG_OPTS+=("--without-ssl") ;;
2869+
auto) CONFIG_OPTS+=("--with-ssl=auto") ;;
2870+
"") ;;
2871+
*) echo "WARNING: Unrecognized NUT_SSL_VARIANTS='${NUT_SSL_VARIANTS}' for a general deterministic build, ignored" >&2 ;;
2872+
esac
2873+
28452874
if [ -n "${BUILD_DEBUGINFO-}" ]; then
28462875
CONFIG_OPTS+=("--with-debuginfo=${BUILD_DEBUGINFO}")
28472876
else
@@ -2987,6 +3016,8 @@ cross-windows-mingw*)
29873016
fi # else we have some value from caller
29883017
export WITH_LIBNUTPRIVATE
29893018
3019+
export NUT_SSL_VARIANTS
3020+
29903021
SOURCEMODE="out-of-tree" \
29913022
MAKEFLAGS="$PARMAKE_FLAGS" \
29923023
KEEP_NUT_REPORT_FEATURE="true" \

clients/Makefile.am

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,37 @@ upsstats_cgi_LDADD = $(LDADD_CLIENT) $(top_builddir)/common/libcommonstrjson.la
163163

164164
################################## Plain C client library (libupsclient) :
165165

166-
# not LDADD... why?
167-
libupsclient_la_SOURCES = upsclient.c upsclient.h
168166
# NOTE: The library does not require libcommonversion.la
167+
# but it needs nut_version.h made before the rest of build,
168+
# to include it into upsclient.c (without an explicit link,
169+
# this target is sometimes missed in parallel builds):
170+
libupsclient_la_SOURCES = upsclient.c upsclient.h
171+
172+
# See comments for similar trick in common/Makefile.am for common-nut_version.c
173+
if BUILDING_IN_TREE
174+
upsclient.c: $(top_builddir)/include/nut_version.h
175+
else !BUILDING_IN_TREE
176+
upsclient.c: $(top_builddir)/include/nut_version.h $(srcdir)/upsclient.c
177+
@if [ x"$(abs_top_srcdir)" = x"$(abs_top_builddir)" ] || test -s "$@" ; then \
178+
exit 0 ; \
179+
else \
180+
echo " LN $(top_srcdir)/clients/upsclient.c => $@ (relative to `pwd`)" ; \
181+
ln -s -f "$(top_srcdir)/clients/upsclient.c" "$@" ; \
182+
fi
183+
184+
CLEANFILES += $(top_builddir)/clients/upsclient.c
185+
BUILT_SOURCES = upsclient.c
186+
endif !BUILDING_IN_TREE
187+
188+
189+
# not LDADD... why?
190+
if ENABLE_SHARED_PRIVATE_LIBS
191+
libupsclient_la_LIBADD = \
192+
$(top_builddir)/common/libnutprivate-@NUT_SOURCE_GITREV_SEMVER_UNDERSCORES@-common-client.la
193+
else !ENABLE_SHARED_PRIVATE_LIBS
169194
libupsclient_la_LIBADD = \
170195
$(top_builddir)/common/libcommonclient.la
196+
endif !ENABLE_SHARED_PRIVATE_LIBS
171197
if HAVE_WINDOWS_SOCKETS
172198
libupsclient_la_LIBADD += -lws2_32
173199
endif HAVE_WINDOWS_SOCKETS
@@ -181,6 +207,15 @@ endif WITH_SSL
181207
# object .so names would differ)
182208

183209
# libupsclient version information
210+
# NOTE: with libnutprivate*common* builds dynamically linked into the same
211+
# program (a typical in-tree NUT client, not typical for out-of-tree third
212+
# party clients) we can end up with two copies of libcommon symbols present
213+
# in each library. It's recommended to explicitly call upscli_set_debug_level()
214+
# instead of ambiguously manipulating the nut_debug_level variable by name.
215+
# TOTHINK: Un-export nut_debug_level from this library to avoid ambiguity
216+
# for the run-time dynamic linker resolution? For now the shared-library
217+
# builds are "exotic", but it makes sense to deprecate this export in a
218+
# future release.
184219
libupsclient_la_LDFLAGS = -version-info 7:0:0
185220
libupsclient_la_LDFLAGS += -export-symbols-regex '^(upscli_|nut_debug_level)'
186221
#|s_upsdebug|fatalx|fatal_with_errno|xcalloc|xbasename|print_banner_once)'
@@ -207,6 +242,7 @@ endif HAVE_WINDOWS
207242
# ways to skip this rebuild noise for common NUT parallel `make -j N all` runs.
208243
CLEANFILES += libupsclient-version.h libupsclient-version.h.tmp*
209244
libupsclient-version.h: libupsclient.la
245+
@test -s '$?' || { echo "[Error] Missing or empty input file: $?" >&2 ; exit 1; }
210246
@if [ -s '$@' -a -s '$?' ] ; then \
211247
if test -n "`find '$@' -newer '$?' 2>/dev/null`" ; then \
212248
if [ x"$(MAINTAINER_GENERATE_HEADER_DEBUG)" = xyes ] ; then \

clients/upsc.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
Copyright (C) 1999 Russell Kroll <rkroll@exploits.org>
44
Copyright (C) 2012 Arnaud Quette <arnaud.quette@free.fr>
5-
Copyright (C) 2020-2025 Jim Klimov <jimklimov+nut@gmail.com>
5+
Copyright (C) 2020-2026 Jim Klimov <jimklimov+nut@gmail.com>
66
77
This program is free software; you can redistribute it and/or modify
88
it under the terms of the GNU General Public License as published by
@@ -48,14 +48,14 @@ static void fatalx_error_json_simple(int msg_is_simple, const char *msg) {
4848
if (output_json) {
4949
if (msg_is_simple) {
5050
/* Caller knows there is nothing to escape here, pass through */
51-
printf("{\"error\": \"%s\"}\n", msg);
51+
printf("{\"error\": \"%s\"}\n", NUT_STRARG(msg));
5252
} else {
5353
printf("{\"error\": \"");
5454
json_print_esc(msg);
5555
printf("\"}\n");
5656
}
5757
}
58-
fatalx(EXIT_FAILURE, "Error: %s", msg);
58+
fatalx(EXIT_FAILURE, "Error: %s", NUT_STRARG(msg));
5959
}
6060

6161
static void usage(const char *prog)
@@ -91,6 +91,7 @@ static void usage(const char *prog)
9191
printf(" -h - display this help text\n");
9292

9393
nut_report_config_flags();
94+
upscli_report_build_details();
9495

9596
printf("\n%s", suggest_doc_links(prog, NULL));
9697
}
@@ -168,6 +169,8 @@ static void list_vars(void)
168169
int msg_is_simple = 1;
169170

170171
/* check for an old upsd */
172+
upsdebugx(1, "%s: got code %d, upserror %d",
173+
__func__, ret, upscli_upserror(ups));
171174
if (upscli_upserror(ups) == UPSCLI_ERR_UNKCOMMAND) {
172175
msg = "upsd is too old to support this query";
173176
} else {
@@ -177,14 +180,14 @@ static void list_vars(void)
177180

178181
if (output_json) {
179182
if (msg_is_simple) {
180-
printf(" \"error\": \"%s\"\n}\n", msg);
183+
printf(" \"error\": \"%s\"\n}\n", NUT_STRARG(msg));
181184
} else {
182185
printf(" \"error\": \"");
183186
json_print_esc(msg);
184187
printf("\"\n}\n");
185188
}
186189
}
187-
fatalx(EXIT_FAILURE, "Error: %s", msg);
190+
fatalx(EXIT_FAILURE, "Error: %s", NUT_STRARG(msg));
188191
}
189192

190193
while (upscli_list_next(ups, numq, query, &numa, &answer) == 1) {
@@ -237,6 +240,8 @@ static void list_upses(int verbose)
237240
int msg_is_simple = 1;
238241

239242
/* check for an old upsd */
243+
upsdebugx(1, "%s: got code %d, upserror %d",
244+
__func__, ret, upscli_upserror(ups));
240245
if (upscli_upserror(ups) == UPSCLI_ERR_UNKCOMMAND) {
241246
msg = "upsd is too old to support this query";
242247
} else {
@@ -394,6 +399,7 @@ int main(int argc, char **argv)
394399
s = getenv("NUT_DEBUG_LEVEL");
395400
if (s && str_to_int(s, &i, 10) && i > 0) {
396401
nut_debug_level = i;
402+
upscli_set_debug_level(nut_debug_level);
397403
}
398404
upsdebugx(1, "Starting NUT client: %s", prog);
399405

0 commit comments

Comments
 (0)