libi2ncommon
6 days agoRelease libi2ncommon 2.13 master v2.13
Thomas Jarosch [Wed, 31 Dec 2025 11:20:28 +0000]
Release libi2ncommon 2.13

Issue a new release due to all the fixes.

No .so version bump needed, ABI stayed the same.

6 days agoMerge branch 'fix-compile-warnings'
Thomas Jarosch [Wed, 31 Dec 2025 11:14:34 +0000]
Merge branch 'fix-compile-warnings'

This solves compile warnings for C++11 and later. Tested up to C++20.

We did go the extra mile and for now it's still compatible with C++98 / gcc 4.4.
The ABI does not change when using the old compiler (compared the mangled symbols).

6 days agoFix ignored-qualifiers warning
Thomas Jarosch [Tue, 30 Dec 2025 09:13:52 +0000]
Fix ignored-qualifiers warning

Original warning:
src/timefunc.hxx:418:30: error: type qualifiers ignored on function return type [-Werror=ignored-qualifiers]

The function 'get_msec' was declared to return 'const long' but the const on
return by value is meaningless (the return value is a prvalue, not an lvalue).
Changed to 'long get_msec()' and also changed implementation to access
value.tv_nsec directly to avoid calling non-const get_nsec from const method.

6 days agoconfiglib: Remove deprecated std::binary_function inheritance
Thomas Jarosch [Tue, 30 Dec 2025 20:32:14 +0000]
configlib: Remove deprecated std::binary_function inheritance

Original warnings:
configlib/i2n_global_config.hpp:261:15: error: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Werror=deprecated-declarations]
configlib/i2n_global_config.hpp:278:15: error: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Werror=deprecated-declarations]
configlib/i2n_global_config.hpp:299:15: error: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Werror=deprecated-declarations]
configlib/i2n_global_config.hpp:350:18: error: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Werror=deprecated-declarations]

Keep std::binary_function inheritance for GCC < 4.8 only.

GCC 4.8.1 was the first version with feature-complete C++11 support.

Require C++11 when using GCC >= 4.8 to avoid ABI mismatch between the
deprecated std::binary_function and modern C++ standard library.

Applied to:
- DefaultConverter<ValueType>
- DefaultConverter<std::string>
- AutoIntConverter<ValueType>

Also added conditional BOOST_STATIC_ASSERT in Var class to check
binary_function inheritance only for GCC < 4.8.

6 days agoFix missing initializer for timespec
Thomas Jarosch [Tue, 30 Dec 2025 09:11:43 +0000]
Fix missing initializer for timespec

Original warning:
src/timefunc.cpp:50:30: error: missing initializer for member 'timespec::tv_nsec' [-Werror=missing-field-initializers]

Fixed by initializing both members: struct timespec ts = { 0, 0 };

6 days agoFix catch-value warning
Thomas Jarosch [Tue, 30 Dec 2025 09:10:07 +0000]
Fix catch-value warning

Original warning:
src/pointer_func.hpp:74:27: error: catching polymorphic type 'class boost::bad_weak_ptr' by value [-Werror=catch-value=]

Changed both catch statements to catch by reference (const&) instead of by value.

6 days agopipestream: Fix unused parameter warning
Thomas Jarosch [Tue, 30 Dec 2025 09:08:21 +0000]
pipestream: Fix unused parameter warning

Original warning:
src/pipestream.cpp:493:32: error: unused parameter '_ignored_flags' [-Werror=unused-parameter]

Fixed by adding (void)_ignored_flags; cast to suppress the warning.

6 days agologfunc: Fix deprecated std::auto_ptr for GCC 4.8.1+
Thomas Jarosch [Tue, 30 Dec 2025 09:00:54 +0000]
logfunc: Fix deprecated std::auto_ptr for GCC 4.8.1+

Original warning:
src/logfunc.hpp:147:30: error: 'template<class> class std::auto_ptr' is deprecated: use 'std::unique_ptr' instead [-Werror=deprecated-declarations]

Use std::auto_ptr for GCC <= 4.7.x and std::unique_ptr for GCC >= 4.8.1.
GCC 4.8.1 was the first version with feature-complete C++11 support.

This still enables compilation on g++ 4.4.4.

6 days agotest: Add unit tests for chown() with User and Group parameters
Thomas Jarosch [Tue, 30 Dec 2025 13:44:21 +0000]
test: Add unit tests for chown() with User and Group parameters

Test the sentinel value handling for uid_t and gid_t types that
was fixed in the previous commit.

Added tests:
- TestChownWithInvalidUid: Verify chown fails when User has invalid uid
- TestChownWithValidUidAndInvalidGid: Verify chown succeeds when gid falls back to valid user.Gid
- TestChownWithUserAndGroupObjects: Verify chown works with valid User and Group objects

6 days agoFix unsigned comparison warnings in chown()
Thomas Jarosch [Tue, 30 Dec 2025 08:58:00 +0000]
Fix unsigned comparison warnings in chown()

Original warnings:
src/filefunc.cpp:756:12: error: comparison of unsigned expression in '< 0' is always false [-Werror=type-limits]
src/filefunc.cpp:758:12: error: comparison of unsigned expression in '< 0' is always false [-Werror=type-limits]
src/filefunc.cpp:759:12: error: comparison of unsigned expression in '< 0' is always false [-Werror=type-limits]

The uid_t and gid_t types are unsigned, so comparisons like 'uid < 0' are always false.
Changed to use static_cast<uid_t>(-1) and static_cast<gid_t>(-1) to check for sentinel values.

6 days agoReplace deprecated readdir_r() with readdir()
Thomas Jarosch [Tue, 30 Dec 2025 08:54:15 +0000]
Replace deprecated readdir_r() with readdir()

Original warnings:
src/filefunc.cpp:318:21: error: 'int readdir_r(DIR*, dirent*, dirent**)' is deprecated [-Werror=deprecated-declarations]
src/filefunc.cpp:360:21: error: 'int readdir_r(DIR*, dirent*, dirent**)' is deprecated [-Werror=deprecated-declarations]
src/filefunc.cpp:362:27: error: the address of 'dirent::d_name' will never be NULL [-Werror=address]

The readdir_r() function is deprecated in favor of readdir(), which is
thread-safe on Linux with glibc since many years. I checked the glibc 2.17 source code
and it uses a lock internally (and also traced it back to at least 2012).

Also removed the unnecessary NULL check for d_name since it is never NULL per POSIX.

6 days agoMerge branch 'cmake-modernize-boost'
Thomas Jarosch [Wed, 31 Dec 2025 11:09:56 +0000]
Merge branch 'cmake-modernize-boost'

6 days agoModernize Boost module finding for CMake 3.30+
Thomas Jarosch [Wed, 31 Dec 2025 10:36:59 +0000]
Modernize Boost module finding for CMake 3.30+

Add CMP0167 policy to suppress FindBoost deprecation warning on CMake 3.30+

Use modern Boost imported targets (Boost::iostreams, Boost::thread,
Boost::unit_test_framework) when available (CMAKE_VERSION >= 3.30)

Fallback to old-style variables for CMake 3.28.

Split target_link_libraries calls: Boost libraries + non-Boost libraries.

"include_directories" for Boost handled in root CMakeLists.txt.

Fixes: CMake warning about deprecated FindBoost module on CMake 3.30+:
*******************************************
CMake Warning (dev) at CMakeLists.txt:137 (find_package):
  Policy CMP0167 is not set: The FindBoost module is removed.  Run "cmake
  --help-policy CMP0167" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.
*******************************************

6 days agoAdd missing Boost include directory
Thomas Jarosch [Wed, 31 Dec 2025 10:36:53 +0000]
Add missing Boost include directory

Otherwise it defaults to /usr/include. During upgrades,
we want it to pick it up from /opt/boost/include.

6 days agoFix Boost bind deprecation warning
Thomas Jarosch [Tue, 30 Dec 2025 20:32:14 +0000]
Fix Boost bind deprecation warning

Original warning:
boost/bind.hpp:36:1: note: ‘#pragma message: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.’

Use <boost/bind/bind.hpp> with boost::placeholders for Boost 1.46+.
Fall back to <boost/bind.hpp> for Boost 1.44 (no deprecation warning in that version).

6 days agoconfigfile: Fix passing along the "decoder" in load_ini_config_file()
Thomas Jarosch [Tue, 30 Dec 2025 08:59:25 +0000]
configfile: Fix passing along the "decoder" in load_ini_config_file()

Original warning:
src/i2n_configfile.cpp:66:25: error: unused parameter 'decoder' [-Werror=unused-parameter]

6 days agoFix broken error check for iconv_open() result in iso_to_utf8()
Thomas Jarosch [Wed, 31 Dec 2025 10:37:07 +0000]
Fix broken error check for iconv_open() result in iso_to_utf8()

The variable 'i2utf8' was misspelled as the function name 'iso_to_utf8'
in the error check. This would cause the error condition to always be false,
preventing proper detection of iconv_open() failures.

Luckily ISO-8859-1 to UTF-8 should always be available.

6 days agoMake TestPidOf1 unit test more robust
Thomas Jarosch [Tue, 30 Dec 2025 10:58:20 +0000]
Make TestPidOf1 unit test more robust

The test expects to find PID 1 by searching for "init" or "systemd".

While some LXC container is running:
- PID 1 runs systemd (not traditional init)
- Another process (e.g., PID 41150) may have "init" in its cmdline

This causes pid_of("init") to return PID 41150 instead of PID 1,
and the test would fail because PID 1 is not in the result.

The fix checks if PID 1 is found after the "init" search, and if not,
falls back to searching for "systemd" to find PID 1.

14 months agoReplace inet_aton() with inet_pton() to parse IPs correctly (#8825)
Kejdi Domi [Wed, 16 Oct 2024 13:29:01 +0000]
Replace inet_aton() with inet_pton() to parse IPs correctly (#8825)

inet_aton() modifies IPs in an unwanted manner (1.2 -> 1.0.0.2), so
for proper handling of IPs and for future support of IPv6 addresses,
it was changed to inet_pton() and tested accordingly.

17 months agoRelease libi2ncommon 2.12 v2.12
Thomas Jarosch [Thu, 1 Aug 2024 12:48:44 +0000]
Release libi2ncommon 2.12

Issue a new release due to the .so version bump.

17 months agoSet minimum cmake version to 3.28
Thomas Jarosch [Thu, 1 Aug 2024 12:47:26 +0000]
Set minimum cmake version to 3.28

Probably a lower version would do but it's the
current version we have on the Intra2net system.

Solves one deprecation warning from Cmake.

17 months agoBump soversion to 8 since ABI of the tmpfstream changed
Thomas Jarosch [Thu, 1 Aug 2024 12:44:55 +0000]
Bump soversion to 8 since ABI of the tmpfstream changed

17 months agoAdd CLion dirs to gitignore
Christian Herdtweck [Mon, 29 Apr 2024 09:27:25 +0000]
Add CLion dirs to gitignore

17 months agoMerge branch 'timefunc-fixes'
Thomas Jarosch [Thu, 1 Aug 2024 12:57:39 +0000]
Merge branch 'timefunc-fixes'

17 months agounit test Time::operator<<
Philipp Gesang [Fri, 26 Apr 2019 15:00:12 +0000]
unit test Time::operator<<

17 months agotest robustness against DST transition
Philipp Gesang [Fri, 26 Apr 2019 13:42:35 +0000]
test robustness against DST transition

17 months agoadd precautions for old glibc
Philipp Gesang [Fri, 26 Apr 2019 08:44:02 +0000]
add precautions for old glibc

The glibc 2.17 currently being used on the Intranator lacks two
commits from 2015 which implement correct handling of ISO8601
timezone specifications. This causes timestamp parsing to fail
where the `Z' suffix is used to indicate UTC, so comment out
the respective tests.

17 months agoapply UTC offset during timestamp conversion
Philipp Gesang [Fri, 26 Apr 2019 07:47:30 +0000]
apply UTC offset during timestamp conversion

Glibc strptime(3) does not automatically apply the UTC offset
when present but stores it in the member tm_gmtoff. (Probably
because the standard mandates different, insufficient means
of timezone handling that need to be supported for portability.)

Thus we do that right in the constructor immediately after we
have obtained a valid struct tm.

17 months agofix formatting of timezone in iso timestamps
Philipp Gesang [Fri, 26 Apr 2019 07:40:39 +0000]
fix formatting of timezone in iso timestamps

The `Z' indicates UTC and has no place in timestamps with an
explicit offset.

17 months agoexplicitly set timezone for tests that depend on it
Philipp Gesang [Thu, 25 Apr 2019 14:20:36 +0000]
explicitly set timezone for tests that depend on it

Some timefunc tests rely on the time zone to be CE[S]T and will
fail otherwise. Not a good thing for a correctness test to do, so
set the zone explicitly in those cases. Example:

    $ ./test/test_i2ncommon --run_test=TestTimeFunc/FormatFullTime
    Running 1 test case...

    *** No errors detected
    $ TZ=UTC ./test/test_i2ncommon --run_test=TestTimeFunc/FormatFullTime
    Running 1 test case...
    /home/philipp/src/i2ncommon/libi2ncommon-git/test/test_timefunc.cpp(480): error: in "TestTimeFunc/FormatFullTime": check "17.10.2011 11:33" == format_full_time(seconds) has failed [17.10.2011 11:33 != 17.10.2011 09:33]

17 months agoReplace outdated (std::ios_base::)open_mode with openmode
Thomas Jarosch [Mon, 20 May 2024 10:54:29 +0000]
Replace outdated (std::ios_base::)open_mode with openmode

Otherwise we'll get a compile error on C++17.

17 months agoInclude 'algorithm' header for std::sort()
Thomas Jarosch [Mon, 20 May 2024 10:47:25 +0000]
Include 'algorithm' header for std::sort()

gcc 8.3+ errored out about missing std::sort() when including "timefunc.hxx".

17 months agoconvert_hex_to_binary(): Remove exception specification
Thomas Jarosch [Mon, 20 May 2024 10:43:46 +0000]
convert_hex_to_binary(): Remove exception specification

gcc complained:
"ISO C++17 does not allow dynamic exception specifications"

Also remove it in ensure_indent_level() static function.

3 years agoMerge branch 'daemon-ext'
Thomas Jarosch [Mon, 10 Jan 2022 15:26:00 +0000]
Merge branch 'daemon-ext'

3 years agoadd handling of stdio descriptors
Philipp Gesang [Fri, 7 Jan 2022 10:07:19 +0000]
add handling of stdio descriptors

This completes the daemonization API by adding a function that
reassigns the stdio descriptors to /dev/null to prevent the
process from being tied IO wise to the terminal it was started
on.

A ``daemonize_full()`` helper combines all the daemonization
steps into a single call.

3 years agodon't leak iconv context on OOM
Philipp Gesang [Mon, 10 Jan 2022 14:27:12 +0000]
don't leak iconv context on OOM

4 years agoadd session handling
Philipp Gesang [Wed, 5 Jan 2022 15:38:15 +0000]
add session handling

The ``daemonize()`` API does not establish a new session so
processes that use it end up being controlled by the tty of the
process they were launched under, which too often happens to be
some system console.

4 years agoMerge branch 'html_entities_iso'
Thomas Jarosch [Mon, 29 Nov 2021 13:37:02 +0000]
Merge branch 'html_entities_iso'

4 years agofix typo
Philipp Gesang [Mon, 29 Nov 2021 13:25:01 +0000]
fix typo

4 years agoadd latin-1 wrapper for html_entities
Philipp Gesang [Mon, 29 Nov 2021 13:24:10 +0000]
add latin-1 wrapper for html_entities

Still a bit underwhelming as we can't express the encoding
difference in the type system.

4 years agoaccount for deletion marker in /proc/pid/exe
Philipp Gesang [Tue, 16 Nov 2021 09:45:28 +0000]
account for deletion marker in /proc/pid/exe

The kernel appends a `` (deleted)`` suffix to the executable path
if the original binary has been unlinked since the process was
started. The ``pid_of()`` API needs to account for this when
matching process names.

5 years agoFix 'occurred' typo
Thomas Jarosch [Sat, 23 May 2020 10:33:35 +0000]
Fix 'occurred' typo

5 years agoremove unused constants
Philipp Gesang [Mon, 3 Feb 2020 14:40:37 +0000]
remove unused constants

These have been provided by glibc for ages and are no longer
needed.

5 years agoreplace obsolete call to ftime(3)
Philipp Gesang [Mon, 3 Feb 2020 14:35:38 +0000]
replace obsolete call to ftime(3)

ftime() and timeb.h have been deprecated since POSIX 2008 and
will be removed in future versions of glibc [0]. Replace them
with (probably faster) calls to clock_gettime(2).

[0] https://sourceware.org/ml/libc-announce/2020/msg00001.html

6 years agodrop reference to obsolete symbol from unit test
Philipp Gesang [Thu, 25 Apr 2019 13:58:55 +0000]
drop reference to obsolete symbol from unit test

The revert

    commit 49ee03b8f8540d2f09ebd416d2f3e09350300573 (origin/master, origin/HEAD)
    Author: Christian Herdtweck <christian.herdtweck@intra2net.com>
    Date:   Thu Apr 18 17:35:21 2019 +0200

        Revert "Add another convenience function allowing i18n_noops("foo")+"bar""

failed to revert one use of i18n_noops() from the unit tests
which breaks the build. Fix it by removing the call.

6 years agoRevert "Add another convenience function allowing i18n_noops("foo")+"bar""
Christian Herdtweck [Thu, 18 Apr 2019 15:35:21 +0000]
Revert "Add another convenience function allowing i18n_noops("foo")+"bar""

Such string-return aliases for i18n functions encourage creation of texts
using concatenation (+). However, such strings might not be translateable
in the future (e.g. into languages with very different word order).

To encourage using i18n_get_string() which is a translation-friendly way
to dynamically assemble strings, we remove this

This reverts commit 0562a0f617437d45d9e344da14980598d7c6c93d.

6 years agoRelease libi2ncommon 2.11 v2.11
Thomas Jarosch [Fri, 5 Apr 2019 14:30:01 +0000]
Release libi2ncommon 2.11

No increase in SOVERSION needed as far as I can tell.

6 years agoMerge branch 'timefunc-new'
Thomas Jarosch [Fri, 5 Apr 2019 14:23:44 +0000]
Merge branch 'timefunc-new'

6 years agodocument some more timefunc member functions
Philipp Gesang [Fri, 5 Apr 2019 09:48:44 +0000]
document some more timefunc member functions

6 years agoadd constructor tests for all Time::Clock ids and variants
Philipp Gesang [Fri, 5 Apr 2019 07:08:07 +0000]
add constructor tests for all Time::Clock ids and variants

Go through the supported combinations of clock modes in the
constructor tests.

6 years agostop leaking TZ between unit tests
Philipp Gesang [Fri, 5 Apr 2019 06:51:25 +0000]
stop leaking TZ between unit tests

So apparently boost/unit_test does not restore the original
environment for each test. Do that ourselves then for the TZ
variable which is needed for certain tests.

Also enable UTC in more helpers that leave it unspecified in
formatting. Till now those were relying on the UTC set in a
previous test. Ew!

6 years agodocument timefunc api
Philipp Gesang [Thu, 4 Apr 2019 15:23:08 +0000]
document timefunc api

6 years agodocument clockid_t helper
Philipp Gesang [Thu, 4 Apr 2019 15:06:25 +0000]
document clockid_t helper

6 years agoremove bogus clock variant check
Philipp Gesang [Thu, 4 Apr 2019 14:35:47 +0000]
remove bogus clock variant check

Spotted by Tom: There are no variants to CLOCK_BOOTTIME so
this would fall back on the default monotonic clock.

6 years agohandle strftime() more defensively
Philipp Gesang [Thu, 4 Apr 2019 14:26:09 +0000]
handle strftime() more defensively

Null terminating the result is not necessary under the assumption
that the function works as advertised since we start out with a
zeroed buffer. Thus drop the calculation based on its return
value and null terminate the final byte instead -- after all if
the function should be borked we have no idea where the
terminator should go.

Also error out if it returns zero since the ISO time format cannot
result in the empty string.

6 years agoFix output unit for Time::operator<<
Thomas Jarosch [Wed, 27 Mar 2019 15:49:44 +0000]
Fix output unit for Time::operator<<

It's seconds instead of milliseconds.

6 years agoFix compile warning
Thomas Jarosch [Wed, 27 Mar 2019 09:38:41 +0000]
Fix compile warning

timefunc.cpp: In function ‘boost::optional<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > format_min_sec_msec(const timespec&)’:
timefunc.cpp:1000: warning: '0' flag ignored with precision and ‘%d’ gnu_printf format

Also fix small typos.

6 years agoadd more struct timespec/Time formatters
Philipp Gesang [Mon, 5 Feb 2018 13:49:28 +0000]
add more struct timespec/Time formatters

Add formatters for durations:

* format_sec_msec: ``1s 337ms'', and
* format_min_sec_msec: ``1m3.370s'' (following time(1)).

Also only use string option types when there is actually an error
path under our control (e. g. with snprintf(3)). (NB the
omnipresent to_string() does not propagate formatting errors
upward so the wrappers we have for it return a plain string.)

6 years agotake precautions for 32bit time_t/long
Philipp Gesang [Thu, 1 Feb 2018 09:50:02 +0000]
take precautions for 32bit time_t/long

Direct handling of time_t or conversions to it from other
representations will cause failures on 32 bit systems. Introduce
an exception ``conversion_error'' to communicate these conditions
from constructors.

6 years agouse separate directives for time formatting and scanning
Philipp Gesang [Wed, 31 Jan 2018 13:32:59 +0000]
use separate directives for time formatting and scanning

Glibc 2.17 has trouble with length modifiers in format directives
which prevents us from using the same strings both ways. This is
fixed in later versions (by 2.25 definitely, maybe earlier) but
for the time being we have to use different format strings
depending on the action.

6 years agoimplement division by scalar for Time and container ops
Philipp Gesang [Tue, 30 Jan 2018 16:00:07 +0000]
implement division by scalar for Time and container ops

Add division by integer plus related operations over containers.

As per C++ convention the division functions themselves will not
attempt to handle the case when zero is passed as the divisor.
The functions operating on containers will simply return a zero-
initialized Time object if the argument container is empty.

6 years agoallow creating Time objects from formatted timestamps
Philipp Gesang [Tue, 30 Jan 2018 14:52:25 +0000]
allow creating Time objects from formatted timestamps

Read ISO-8601 formatted strings to construct timestamps from.

The format strings already defined for formatting timestamps are
reused. Since years can be negative but the sign handling in
glibc is flawed with the %Y specifier, we need to handle negative
year numbers manually.

6 years agoextend Time class with string formatters
Philipp Gesang [Tue, 30 Jan 2018 09:24:03 +0000]
extend Time class with string formatters

Add convenience member functions for the existing formatters.
Note that the make_*() group of functions all use
``localtime_r()`` internally so unit tests must be guarded by an
explicit time zone change to UTC.

6 years agoadd ISO-8601 formatters to timefunc
Philipp Gesang [Tue, 9 Jan 2018 10:52:53 +0000]
add ISO-8601 formatters to timefunc

Adds format_iso8601() to create conforming timestamps from
broken-down time. Includes overload wrappers for time_t and
struct timespec.

6 years agoimplement basic operations over class Time
Philipp Gesang [Mon, 29 Jan 2018 13:02:18 +0000]
implement basic operations over class Time

This adds members and overloads for

    * addition, subtraction / difference, multiplication by
      time_t,
    * comparison, less-than / greater-than, equality,
    * trivial formatting (needed in boost unittest)

operations involving *class Time* objects.

6 years agoimplement a basic time/clock datastructure
Philipp Gesang [Mon, 29 Jan 2018 10:06:13 +0000]
implement a basic time/clock datastructure

Add a class ``Time'' to the timefunc part of the library. The
goal is to provide a generalist handle around struct timespec to
supersede the current ones that had been built on now deprecated
APIs (e. g. ``timeb.h'').

7 years agostop leaking FILE* objects when hashing
Philipp Gesang [Tue, 27 Nov 2018 15:30:41 +0000]
stop leaking FILE* objects when hashing

In hash_file(), the input FILE* needs freeing when no error
occurred. Do this as soon as it is not needed anymore.

7 years agomake crypto code compile with openssl 1.1.x
Philipp Gesang [Tue, 27 Nov 2018 15:14:20 +0000]
make crypto code compile with openssl 1.1.x

From EVP_DigestInit(3):

       EVP_MD_CTX_create() and EVP_MD_CTX_destroy() were renamed
       to EVP_MD_CTX_new() and EVP_MD_CTX_free() in OpenSSL 1.1.

7 years agodrop unused includes from userfunc
Philipp Gesang [Tue, 27 Nov 2018 15:06:22 +0000]
drop unused includes from userfunc

Ironically, despite the duplicate include the userfunc routines
never even check errno at all.

7 years agoMerge branch 'redirect-urlauth'
Thomas Jarosch [Tue, 2 Oct 2018 12:16:08 +0000]
Merge branch 'redirect-urlauth'

7 years agoRemove default hash algorithm from the new hash functions
Thomas Jarosch [Fri, 28 Sep 2018 12:43:45 +0000]
Remove default hash algorithm from the new hash functions

Rationale: SHA1 is outdated, we would need to switch
to something like SHA256 nowadays. If the algorithm
is given explicitly, we can grep for the identifier.

When we do the migration from the libgcrypt-intranator API,
it's better to explicitly adapt the call sites.

7 years agoRedirectHash class created in restricted_html file
Túlio Cavalcanti [Tue, 18 Sep 2018 13:12:10 +0000]
RedirectHash class created in restricted_html file

class used to find all redirect urls in a html text and add a query
parameter "urlauth" with a hash as value to them.

7 years agoHashing functions based upon openssl created
Tulio Cavalcanti [Mon, 17 Sep 2018 12:47:26 +0000]
Hashing functions based upon openssl created

The following functions were implemented:
string hash_data(string data, algorithm algo=SHA1); // output: hex encoded hash
string hash_data_raw(string data, algorithm algo=SHA1); // output: raw binary hash
string hash_file(string filename, algorithm algo=SHA1); // hash data in 64kb blocks

Unit test also included.

7 years agoAdd openssl-devel to build requirements
Thomas Jarosch [Tue, 4 Sep 2018 15:39:05 +0000]
Add openssl-devel to build requirements

7 years agoRevert "restore join_string() symbols in library"
Thomas Jarosch [Wed, 15 Aug 2018 15:14:58 +0000]
Revert "restore join_string() symbols in library"

We bump the SOVERSION of the library, so no compat functions needed anymore.

This reverts commit f3b61bd6816546a39a072a5b8be56d78cf775683.

7 years agoBump soversion to 7 since the pipestream interface changed v2.10
Thomas Jarosch [Wed, 15 Aug 2018 14:54:30 +0000]
Bump soversion to 7 since the pipestream interface changed

7 years agoMerge branch 'pipeexec'
Thomas Jarosch [Tue, 14 Aug 2018 15:24:14 +0000]
Merge branch 'pipeexec'

Thanks Philipp!

7 years agoadd support for guarding pipestream with NO_NEW_PRIVS
Philipp Gesang [Tue, 26 Jun 2018 07:38:56 +0000]
add support for guarding pipestream with NO_NEW_PRIVS

Add an option to the pipestream and related APIs to drop the
right to obtain further privileges before exec()ing the binary
(off by default). This may be used as an additional measure to
guard invocations of untrusted binaries or trusted ones that
operate on untrusted inputs.

Target audience: arnied scheduler, everywhere file(1) or
imagemagick tools are called.

Defects: it will be tricky to properly unit test this.

[0] https://www.kernel.org/doc/Documentation/prctl/no_new_privs.txt

7 years agodo not indent boost unittest structurals
Philipp Gesang [Tue, 14 Aug 2018 13:38:50 +0000]
do not indent boost unittest structurals

As per request. Does not contain functional changes.

7 years agopass pipestream flags as bitset
Philipp Gesang [Mon, 13 Aug 2018 15:25:58 +0000]
pass pipestream flags as bitset

Avoid cluttering the API with long lists of booleans by using
symbolic names instead.

7 years agoadd option to forward environment to pipestream
Philipp Gesang [Tue, 17 Apr 2018 09:32:20 +0000]
add option to forward environment to pipestream

Add an argument to all execve-based pipestream APIs to control
whether *environ* should be passed through to the executed
command. Till now this used to depend on whether path lookup was
requested which is rather undesirable.

Unit tests included.

7 years agoskip unit tests for handling child errors in pipestream with ancient boost
Philipp Gesang [Mon, 12 Feb 2018 14:32:36 +0000]
skip unit tests for handling child errors in pipestream with ancient boost

7 years agodistinguish child errors from failing to exec
Philipp Gesang [Mon, 12 Feb 2018 10:52:23 +0000]
distinguish child errors from failing to exec

Use the old pipe/cloexec trick to separate errors from the spawned
program from such that occur before execv[p]e(). Only errors on
the far side of exec() may be handled by the user.

7 years agoprotect pipe fd with O_CLOEXEC
Philipp Gesang [Mon, 12 Feb 2018 09:48:07 +0000]
protect pipe fd with O_CLOEXEC

On the parent, prevent other exec()s than the one in our child
from carrying over the fd. The pipe wrapper may be long lived
for this to become a problem.

7 years agoblock signals before fork()ing the pipestream child
Philipp Gesang [Mon, 12 Feb 2018 08:19:53 +0000]
block signals before fork()ing the pipestream child

Block all signals until we are ready to handle them again.

In particular, this saves us checking for close(2) being
interrupted.

7 years agoredirect unused fds to /dev/null in pipestream
Philipp Gesang [Thu, 4 Jan 2018 16:35:48 +0000]
redirect unused fds to /dev/null in pipestream

Closing an fd like stdout and stderr will cause EBADF on access
which may not be handled in a child process. Thus redirect them
to /dev/null if the user requests that their output be ignored.

7 years agoallow path lookup for pipestream
Philipp Gesang [Wed, 3 Jan 2018 17:08:44 +0000]
allow path lookup for pipestream

Add a flag ``path'' which, if set, causes the specified program
to be executed with execvpe(); also, the environment is passed
on so in this case (to propagate $PATH) so it is up to the caller
to sanitize envp beforehand.

7 years agoadd printing helper to pipestream status specification
Philipp Gesang [Thu, 4 Jan 2018 08:17:10 +0000]
add printing helper to pipestream status specification

7 years agohandle pipe termination separately depending on whether a shell is present
Philipp Gesang [Wed, 3 Jan 2018 16:16:43 +0000]
handle pipe termination separately depending on whether a shell is present

Keep the child's pid around and wait() for it to perish in the
dtor of inpipestream. Return the error from closing the pipe or
terminating the process in the shell-free version. The mechanism
for retrieving the status does not allow to distinguish between
the two, so always prefer the latter.

7 years agoadd pipestream unit tests for execution failure
Philipp Gesang [Wed, 3 Jan 2018 13:50:50 +0000]
add pipestream unit tests for execution failure

Note that on the Intranator as of 6.4.13, the argument
--catch_system_errors=no must be passed to the unit test
executable on account of ancient Boost being oversensitive to
child process termination.

7 years agoallow selecting stdout and stderr with inpipestream
Philipp Gesang [Tue, 2 Jan 2018 16:55:28 +0000]
allow selecting stdout and stderr with inpipestream

Only handle the user-requested fd in the forked command and
discard the other.

7 years agobump release version 2.9 -> 2.10
Philipp Gesang [Tue, 2 Jan 2018 16:12:47 +0000]
bump release version 2.9 -> 2.10

7 years agoadd pipestream ctor overload for vectors of string
Philipp Gesang [Tue, 2 Jan 2018 16:10:13 +0000]
add pipestream ctor overload for vectors of string

Add definitions that make passing a vector<string> equivalent to
passing a char**, i. e. take the execve() path.

7 years agoadd unit test series for pipestream
Philipp Gesang [Tue, 2 Jan 2018 15:13:30 +0000]
add unit test series for pipestream

Setup skeleton unit test file with some simple functionality
tests and include it in a normal run. There haven't been any
pipestream tests so far.

7 years agoadd shell-free pipestream
Philipp Gesang [Fri, 9 Feb 2018 13:21:41 +0000]
add shell-free pipestream

Overload the pipestream ctor with a variant that avoids shelling
out with *popen(3)* that is chosen by passing an argument list
in lieu of a command.

7 years agoImplement percent url encoder and decoder
Juliana Rodrigueiro [Wed, 8 Aug 2018 12:40:24 +0000]
Implement percent url encoder and decoder

7 years agoAdd basic restricted_html structure
Juliana Rodrigueiro [Wed, 8 Aug 2018 12:13:39 +0000]
Add basic restricted_html structure

7 years agouse glibc syscall wrapper for clock_gettime
Philipp Gesang [Mon, 29 Jan 2018 08:03:38 +0000]
use glibc syscall wrapper for clock_gettime

These are available on any non-ancient system by now so it’s safe
to drop them.

7 years agoMerge branch 'scopetracker-nothrow'
Thomas Jarosch [Wed, 8 Aug 2018 09:31:39 +0000]
Merge branch 'scopetracker-nothrow'

The nothrow() modification of SourceLocation has been dropped
since std::string might throw std::bad_alloc.
Fixing this would require more work for little gain.

7 years agoWrap Scopetracker constructor/destructor in big try-catch
Christian Herdtweck [Mon, 6 Aug 2018 10:43:33 +0000]
Wrap Scopetracker constructor/destructor in big try-catch