1875 Commits

Author SHA1 Message Date
Alexander A. Klimov
34e0a978bf On Windows, don't create C:\Program Files\Icinga2\var during MSI build 2025-01-16 12:07:44 +01:00
Julian Brost
4cdcaeaa65
Merge commit from fork
Icinga 2.13.10
2024-11-12 15:01:57 +01:00
Julian Brost
3504fc7ed6 Security: fix TLS certificate validation bypass
The previous validation in set_verify_callback() could be bypassed, tricking
Icinga 2 into treating invalid certificates as valid. To fix this, the
validation checks were moved into the IsVerifyOK() function.

This is tracked as CVE-2024-49369, more details will be published at a later time.
2024-10-22 10:42:15 +02:00
Julian Brost
396ce871ec Utility::FormatDateTime(): provide an overload for tm*
This allows the function to be used both with a double timestamp or a pointer
to a tm struct. With this, a similar implementation inside the tests can simply
use our regular function.
2024-09-23 10:54:26 +02:00
Julian Brost
8eaab27bd0 Utility::FormatDateTime(): handle invalid format strings on Windows
On Windows, the strftime() function family invokes an invalid parameter handler
when the format string is invalid (see the "Remarks" section in their
documentation). std::put_time() shows the same behavior as it uses
_wcsftime_l() internally. The default invalid parameter handler may terminate
the process, which can be a problem given that the format string can be
specified by the user from the Icinga DSL.

Thus, temporarily set a thread-local no-op handler to disable the default one
allowing the program to continue. This then simply results in the function
returning an error which then results in an exception as we ask the stream to
throw one.

See also:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsftime-l?view=msvc-170
https://learn.microsoft.com/en-us/cpp/c-runtime-library/parameter-validation?view=msvc-170
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/set-invalid-parameter-handler-set-thread-local-invalid-parameter-handler?view=msvc-170
2024-09-23 10:47:20 +02:00
Julian Brost
e65827cd58 Utility::FormatDateTime(): handle errors from strftime()
So far, the return value of strftime() was simply ignored and the output buffer
passed to the icinga::String constructor. However, there are error conditions
where strftime() returns 0 to signal an error, like if the buffer was too small
for the output. In that case, there's no guarantee on the buffer contents and
reading it can result in undefined behavior. Unfortunately, returning 0 can
also indicate success and strftime() doesn't set errno, so there's no reliable
way to distinguish both situations. Thus, the implementation now returns the
empty string in both cases.

I attempted to use std::put_time() at first as that allows for better error
handling, however, there were problems with the implementation on Windows (see
inline comment), so I put that plan on hold at left strftime() there for the
time being.
2024-09-23 10:47:20 +02:00
Julian Brost
9d6b3f3305 Utility::FormatDateTime(): use localtime_s() on Windows
localtime() is not thread-safe as it returns a pointer to a shared tm struct.
Everywhere except on Windows, localtime_r() is used already which avoids the
problem by using a struct allocated by the caller for the output.

Windows actually has a similar function called localtime_s() which has the same
properties, just with a different name and order of arguments.
2024-09-23 10:47:19 +02:00
Julian Brost
5339c72403 Utility::FormatDateTime(): use boost::numeric_cast<>()
The previous implementation actually had undefined behavior when called with a
double that can't be represented as time_t. With boost::numeric_cast, there's a
convenient cast available that avoids this and throws an exceptions on
overflow.

It's undefined behavior ([0], where the implicit conversion rule comes into
play because the C-style cast uses static_cast [1] which in turn uses the
imlicit conversion as per rule 5 of [2]):

> A prvalue of floating-point type can be converted to a prvalue of any integer
> type. The fractional part is truncated, that is, the fractional part is
> discarded.
>
> * If the truncated value cannot fit into the destination type, the behavior
>   is undefined (even when the destination type is unsigned, modulo arithmetic
>   does not apply).

Note that on Linux amd64, the undefined behavior typically manifests itself in
the result being the minimal value of time_t which then results in localtime_r
failing with EOVERFLOW.

[0]: https://en.cppreference.com/w/cpp/language/implicit_conversion#Floating.E2.80.93integral_conversions
[1]: https://en.cppreference.com/w/cpp/language/explicit_cast
[2]: https://en.cppreference.com/w/cpp/language/static_cast
2024-09-23 10:47:19 +02:00
Alexander Aleksandrovič Klimov
600e631a4d
Merge pull request #9945 from Icinga/2139backport
Disable TLS renegotiation, bump Windows deps and fix Icinga DB crashes
2023-12-20 12:14:30 +01:00
Alexander A. Klimov
89c54ca5e5 Disable TLS renegotiation
The API doesn't need it and a customer's security scanner
is afraid of a potential DoS attack vector.
2023-12-20 10:05:35 +01:00
Alexander A. Klimov
5bf8db41ef CertificateToString(): allow raw pointer input 2023-12-18 17:07:44 +01:00
Alexander A. Klimov
d1098dc959 CreateCertIcingaCA(EVP_PKEY*, X509_NAME*): enable optional CA creation 2023-12-18 17:07:44 +01:00
Alexander A. Klimov
35317f14e7 Introduce IsCaUptodate() by splitting IsCertUptodate() 2023-12-18 17:07:44 +01:00
Alexander Aleksandrovič Klimov
eacf5f27cf
Merge pull request #9816 from Icinga/2.13.8/vendor
Update vendored libs
2023-07-07 16:29:20 +02:00
Alexander A. Klimov
b3d90f5418 Update third-party/nlohmann_json to v3.9.1
the latest version w/o Apache 2.0 licensed code which conflicts with GPL 2.
2023-07-03 17:40:53 +02:00
Alexander A. Klimov
243b8aa7a8 Connect(): don't try next DNS record if operation is canceled
Instead return immediately to meet the caller's expectations.
2023-07-03 17:16:26 +02:00
Alexander Aleksandrovič Klimov
c0bd0936f9
Merge pull request #9682 from Icinga/9631-213
Setup all signal handlers with SA_RESTART flag
2023-02-16 16:24:26 +01:00
Alexander Aleksandrovič Klimov
fe2fed4817
Merge pull request #9680 from Icinga/9488-213
Fix compile error on Solaris 11.4
2023-02-16 16:24:05 +01:00
Alexander Aleksandrovič Klimov
6dfc21f9bd
Merge pull request #9678 from Icinga/181b213
Bump Boost to v1.81
2023-02-16 16:23:50 +01:00
Alexander A. Klimov
d2e3a094c1 Introduce AtomicFile#GetTempFilename() 2023-02-15 17:20:35 +01:00
Alexander A. Klimov
69b3c81ea1 Remove unused Utility::CreateTempFile() 2023-02-15 17:20:02 +01:00
Alexander A. Klimov
34844c146d Deduplicate and stabilize fragile filesystem transactions
by using AtomicFile so they ensure all or nothing of a file gets replaced.
2023-02-15 17:19:57 +01:00
Alexander A. Klimov
f0c1764adc Introduce AtomicFile::Write() 2023-02-15 16:25:39 +01:00
Alexander A. Klimov
a497645127 Setup all signal handlers with SA_RESTART flag
so interrupted syscalls get auto-restarted and callers
don't get or have to handle the EINTR error.
2023-02-15 11:08:29 +01:00
Alexander A. Klimov
a1bda3300e Fix compile error on Solaris 11.4
by not using LOG_FTP which is not defined there.
2023-02-15 10:48:05 +01:00
Alexander A. Klimov
68198f2ef9 Handle boost::beast::http::basic_fields#set() signature change (v1.81)
Make String convertible to boost::beast::string_view (always working),
not boost::string_view (broken).
2023-02-15 10:41:31 +01:00
Alexander A. Klimov
3d2a6bbfb1 Allow hashmaps of String 2022-11-04 12:47:41 +01:00
Alexander A. Klimov
de60eb445b Logger: don't render log messages which will be disposed anyway
by caching the total minimum log severity of all loggers in a
"global variable" and whether a message's severity is large enough for any of
the loggers in a per-message no-op flag.
2022-10-26 11:55:10 +02:00
Alexander A. Klimov
865c5b8365 Utility::ValidateUTF8(): move a string instead of copying a vector
less malloc() = more speed

Especially as JsonEncode() validates every single input string.
2022-10-26 11:55:10 +02:00
Julian Brost
1a2ee1241a
Merge pull request #9467 from Icinga/flush-state-file-213
Dump state file atomically not to corrupt it
2022-08-02 09:21:07 +02:00
Alexander A. Klimov
92a01a748d Dump state file atomically not to corrupt it
by using fsync(2) before close(2) and rename(2).
2022-08-01 17:56:37 +02:00
Alexander A. Klimov
53af4f2dd4 Introduce AtomicFile 2022-08-01 17:56:37 +02:00
Julian Brost
cc1e9c05ec Windows: output useful error message for syscall errors 2022-08-01 17:56:37 +02:00
Julian Brost
67fb24cc11 Windows: only include critical messages in early log messages
The point of logging to the Windows Event Log was to catch errors that happen
before the full logging configuration has been loaded and enabled. Messages
like the number of loaded objects per type just cause noise in the log and
provide little benefit. Therefore raise the required log level at this stage.

Note that this commit removes the (never documented) ability to use the -x flag
to change the level. But doing so would require patching the command line of
the service in the registry anyways.
2022-07-26 18:33:22 +02:00
Julian Brost
184548f4fe Replace EventuallyAtomic with AtomicOrLocked which falls back to a mutex
Apparently there was a reason for making the members of generated classes
atomic. However, this was only done for some types, others were still accessed
using non-atomic operations. For members of type T::Ptr (i.e.  intrusive_ptr<T>),
this can result in a double free when multiple threads access the same variable
and at least one of them writes to the variable.

This commit makes use of std::atomic<T> for more T (it removes the additional
constraint sizeof(T) <= sizeof(void*)) and uses a type including a mutex for
load and store operations as a fallback.
2022-06-14 13:46:40 +02:00
Julian Brost
e289ec689e
Merge pull request #9337 from Icinga/Al2Klimov-patch-3-213
Let new cluster certificates expire after 397 days, not 15 years
2022-04-11 21:20:39 +02:00
Alexander A. Klimov
f63b364d91 Renew certificates also periodically 2022-04-11 12:43:54 +02:00
Alexander A. Klimov
83911d0e05 Introduce IsCertUptodate() 2022-04-11 12:43:54 +02:00
Alexander A. Klimov
85f8496017 Let new cluster certificates expire after 397 days, not 15 years
https://cabforum.org/wp-content/uploads/CA-Browser-Forum-BR-1.7.3.pdf, section 6.3.2:

"Subscriber Certificates issued on or after 1 September 2020 SHOULD NOT have a Validity Period greater than 397 days and MUST NOT have a Validity Period greater than 398 days."
2022-04-11 12:43:53 +02:00
Julian Brost
9d566e0138
Merge pull request #9328 from Icinga/bugfix/parallel-api-package-calls-do-not-finish-while-reload-213
Worker process doesn't let parallel API package stage updates to complete when terminated
2022-04-07 17:09:52 +02:00
Yonas Habteab
236a888c1b Defer: Allow to cancel the callback before going out of scope 2022-04-07 11:58:04 +02:00
Yonas Habteab
36c75218e4 ConfigObject: Initialize local static var at declaration to ensure thread safety 2022-03-29 16:38:09 +02:00
Alexander A. Klimov
1d1e2b2888 Introduce IoEngine::YieldCurrentCoroutine() 2022-03-03 09:57:03 +01:00
Alexander A. Klimov
3cc82069cd Icinga DB: log amount of history kept in memory every 10s 2022-03-03 09:57:03 +01:00
Alexander A. Klimov
0137713d15 Icinga DB: keep history in memory until written to Redis
by putting the messages into a Bulker and retrying each chunk.
2022-03-03 09:57:03 +01:00
Alexander A. Klimov
8538ba97aa Introduce Bulker 2022-03-03 09:57:03 +01:00
Noah Hilverling
6ddac83d81 Dictionary: Make sure underlaying map is ordered 2021-11-12 17:55:47 +01:00
Julian Brost
1dcba7d127 tlsutility: move hex encoding into a separate function BinaryToHex 2021-11-11 16:58:16 +01:00
Julian Brost
6080538223 Enable hostname verification in UnbufferedAsioTlsStream 2021-08-19 11:06:19 +02:00
Julian Brost
ec73b417f2 ApiListener: Choose bind host default based on OS IPv6 support 2021-08-06 12:19:08 +02:00