42 Commits
Author SHA1 Message Date
Thomas Vincent 898d8c692c fix(privileges): drop root before input and retain owned ICMP sockets (#639)
Open and own the required ICMP sockets before permanently dropping
setuid root, then parse input without elevated identity. Close-on-exec
socket ownership, shared IPv4/IPv6 dispatch and fault-injected
identity/capability calls are covered. The owned fixture tests check
deny/allow behavior without contacting external devices.

Step 2/14 of the complete C17/native-correctness series. Base: the
preceding series branch; merge/review in order so this PR shows only its
own step.

Earlier validation, before this review follow-up, in isolated copied
snapshots on Linux arm64:

- Clean GCC build and make check: 13 passed, 1 existing prerequisite
skips, 0 failures.
- ASan/UBSan: 12 passed, 2 existing privilege/allocator-interposition
prerequisite skips, 0 failures; no sanitizer findings.
- Production source/profile integrity verification against disposable
MariaDB and loopback SNMP fixtures passed.
- Release archive extracted into a separate source tree and built/tested
out of tree; fuzz checks passed.

Earlier local profiles retain source hashes for the copied validation
tree; GitHub checks validate the published commit. No production
database/device, host installation or live privilege change is part of
validation. Existing prerequisite skips were retained; no test or
finding was suppressed to obtain a pass.


Series navigation: [Series
index](https://github.com/Cacti/spine/pull/638); [previous
step](https://github.com/Cacti/spine/pull/638). [Next
step](https://github.com/Cacti/spine/pull/640).

Review follow-up (2026-10-09): Restacked on the corrected preceding
branches. The SNMP status fix is introduced in #638, the
reindex/completion fixes in #640, and focused regression coverage in
#650.

Restacked tip validation: isolated Linux arm64 build and make check
passed (18 passed, 1 setuid prerequisite skip, no failures).
GitHub checks validate the updated published commits; earlier
profile/archive/sanitizer evidence above belongs to the previous
revisions.

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
2026-10-10 21:08:52 -04:00
Thomas Vincent 3065c6fc23 refactor(core): add bounded native interfaces and polling contracts (#638)
Introduce bounded native interfaces and grouped runtime state, then link
regression and fault contracts against the real poller implementations.
The contracts capture CLI/configuration input, availability
combinations, SNMP request/response ownership, script framing,
reindexing, output persistence, worker completion and shutdown. This
foundational change is larger because the shared interfaces and their
existing production contracts must move together; later changes have
separate review boundaries.

Step 1/14 of the complete C17/native-correctness series. Base: develop.

Earlier validation, before this review follow-up, in isolated copied
snapshots on Linux arm64:

- Clean GCC build and make check: 13 passed, 0 existing prerequisite
skips, 0 failures.
- ASan/UBSan: 12 passed, 1 existing privilege/allocator-interposition
prerequisite skips, 0 failures; no sanitizer findings.
- Production source/profile integrity verification against disposable
MariaDB and loopback SNMP fixtures passed.
- Release archive extracted into a separate source tree and built/tested
out of tree; fuzz checks passed.

Earlier local profiles retain source hashes for the copied validation
tree; GitHub checks validate the published commit. No production
database/device, host installation or live privilege change is part of
validation. Existing prerequisite skips were retained; no test or
finding was suppressed to obtain a pass.


The worker contracts publish owned heap state and release it only after
joining workers and restoring the runtime table. Coverage counters use
atomic updates; cppcheck receives an explicit model of the fatal exit
contract. Fixture images use public mirrors to avoid shared Docker Hub
pull limits.


Series navigation: review and merge in order. Every PR targets the
preceding branch so its diff contains one step.

1. [refactor(core): add bounded native interfaces and polling
contracts](https://github.com/Cacti/spine/pull/638)
2. [fix(privileges): drop root before input and retain owned ICMP
sockets](https://github.com/Cacti/spine/pull/639)
3. [fix(poller): isolate worker failures and bound database
reconnects](https://github.com/Cacti/spine/pull/640)
4. [fix(results): normalize output and unify SNMP batch
persistence](https://github.com/Cacti/spine/pull/641)
5. [fix(runtime): bound probe retries and validate CLI and
configuration](https://github.com/Cacti/spine/pull/642)
6. [build: select GNU C17 explicitly and probe hardening
support](https://github.com/Cacti/spine/pull/643)
7. [fix(threads): size worker stacks and guard size
arithmetic](https://github.com/Cacti/spine/pull/644)
8. [refactor(c17): simplify ownership guards and share test
support](https://github.com/Cacti/spine/pull/645)
9. [refactor(core): extract configuration polling and runtime
modules](https://github.com/Cacti/spine/pull/646)
10. [fix(boundaries): validate script slots and make cleanup
portable](https://github.com/Cacti/spine/pull/647)
11. [refactor(layout): organize responsibilities and separate main from
runtime](https://github.com/Cacti/spine/pull/648)
12. [docs(license): adopt SPDX notices and retain contributor
credits](https://github.com/Cacti/spine/pull/649)
13. [test(runtime): measure all suites and cover protocol
boundaries](https://github.com/Cacti/spine/pull/650)
14. [build(ci): validate connectors time width and native C17
modules](https://github.com/Cacti/spine/pull/651)

Review follow-up (2026-10-09): Publish the decoded GET/GETNEXT status
back to the host so availability checks observe exception and
missing-response failures, while preserving the legacy transport-success
behavior for agent PDU errors.

Updated step 1 snapshot: isolated Linux arm64 build and make check
passed (13 passed, no skips or failures).
The restacked tip passes all five clang-tidy gate regression tests and
real clang-tidy analysis (26 reviewed baseline findings, no new
findings). Actionlint and matching DCO trailers pass. The setuid test
also passes when run in the separate disposable root container.
GitHub checks validate the updated published commits; earlier
profile/archive/sanitizer evidence above belongs to the previous
revisions.

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
2026-10-10 20:03:21 -04:00
478d330985 fix(ping): make IPv4 and IPv6 ICMP polling safe (#619)
## Summary

Consolidates the overlapping ICMP work from #555 and #619 into one
review of the complete socket and resolver state machine.

- add ICMPv6 echo polling and dispatch IPv6 devices to it
- prefer unprivileged datagram ICMP sockets when the kernel permits them
- retain bounded raw-socket fallback for IPv4 and IPv6
- give packet and socket resources one cleanup owner
- leave caller-owned resolver state untouched on lookup failure
- keep every retry inside one cached capability and privilege-transition
decision
- prevent LOCK_SETEUID retry deadlocks
- validate raw and datagram reply layouts, source, sequence,
identifiers, and payload
- retain fuzz and unprivileged-socket integration coverage

The consolidation also fixed an integration defect found locally: the
controlled successful-reply test constructed only a raw IPv4 packet even
when the production path selected SOCK_DGRAM. It now models the selected
socket format, and IPv6 raw retries use the same privilege-safety
invariant as IPv4.

## Verification

- warning-enabled local build completed with MariaDB Connector/C,
Net-SNMP, OpenSSL 3, and cmocka
- make check: 5/5 test binaries passed
- focused ping_icmp suite: 9/9 cases passed
- actionlint and git diff --check passed
- all commits are signed
- GitHub CI is authoritative for Linux capability, sanitizer, fuzz, and
unprivileged-network coverage

Closes #127.
Closes #250.
Closes #593.
Closes #611.
Supersedes #555.
Refs #597 and #618.

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: TheWitness <copilot@users.noreply.github.com>
Co-authored-by: TheWitness <thewitness@cacti.net>
Co-authored-by: TheWitness <copilot@users.noreply.github.com>
2026-09-23 09:34:15 -04:00
Thomas Vincent e8a4b9aac9 fix: poller correctness bugs, with fuzz and integration coverage (#542)
Poller correctness and memory-safety fixes, with the ICMP hardening from
#543 folded in.

Verified in a clean `ubuntu:24.04` container: builds at **38 warnings**
against develop's 39, and the unit tests build and pass on Linux (39
assertions across three binaries).

**Fixes**
- `php_readpipe` off-by-one — the old bound let `bptr` reach
`result_string + 2048` and then wrote the terminator one byte past a
2048-byte allocation.
- `get_namebyhost` used `strtok`, which keeps one process-wide save
pointer, and runs unlocked on every poller thread. Two devices could be
polled at each other's addresses. Now `strtok_r`.
- The log date format was read from `default_dateformat`; Cacti's key is
`default_date_format`, so the lookup never matched and the format was
never loaded.
- `db_query` returns `mysql_store_result()` directly, which is NULL on
store failure. The NULL check ran *after* `mysql_fetch_row`, so the
crash happened one line before the guard.
- `snmp_count` logged a Net-SNMP `errstat` without setting either loop
flag, rebuilding the identical GETNEXT forever and pinning a thread
until the poll interval ended.
- `php_close` skipped the `close()` when the quit write failed with
EPIPE, leaking a descriptor per script-server restart.
- The reap loop's delay was compiled out on `SOLAR_THREAD` builds, so
both phases burned twenty `WNOHANG` polls in nanoseconds and the child
was never reaped.
- ICMP replies are validated for length and matched on id/sequence; on
Cygwin the peeked datagram is now drained, which previously busy-spun
until host timeout.
- The fatal signal handler no longer calls
`malloc`/`localtime_r`/`fprintf` before `_exit` — on a SIGSEGV caused by
heap corruption that deadlocked on the allocator's lock instead of
dying.
- The unit test Makefile was hardcoded to `/opt/homebrew` paths and
`-std=gnu23`, so it could not build on Linux at all. Now pkg-config
driven.

Supersedes #543.

**Added since the first revision**
- `snmp_get_multi()` now checks the varbind type before formatting.
Under v2c an agent reports a per-OID failure as an inline exception
varbind while the PDU `errstat` stays `NOERROR`, so `snprint_value()`
rendered the exception as literal text and stored it as a value.
- Two warning sources removed: a dangling line continuation ending
`sql.h`, and `strncopy()` now using `memcpy` where the byte count is
already exact. Warnings drop from **39 to 7**.

Closes #551
Closes #232
- `read_config_options()` issued 23 separate `SELECT ... FROM settings
WHERE name = ?` round trips at startup; they are now one bulk read
served from memory. Call sites are unchanged.

Closes #330

**Test infrastructure**
- The SNMPv3 integration fixture was broken: the image shipped a binary
that could not start (`libmysqlclient.so.21: cannot open shared object
file`). The build context carried `*.o`, `spine`, `Makefile` and
`config.status`, so `make` treated them as current, skipped compiling,
and packaged a binary linked against libraries the runtime image does
not have. `.dockerignore` now excludes build output. The fixture runs
end to end: spine polls the SNMPv3 device, reads `uptime`, writes to
`poller_output` and exits 0.
- Two libFuzzer targets, run per PR and weekly: the host string parser
and the ICMP reply parser. The second drives
`spine_icmp_classify_reply()`, extracted from `ping_icmp` so the bounds
walk over a shared raw socket is reachable by a test. 15M executions
under ASan/UBSan, no crashes.


**Added in this revision**
- `output_regex` was applied only in the in-loop OID drain, not the pass
after the loop that handles whatever did not fill a `MAX_OIDS` batch, so
a device whose OID count missed a boundary stored raw values. A single
data source is always the leftover case.
`tests/integration/test_output_regex.sh` now asserts on the value: it
fails on the parent commit with the raw reading and passes here with the
filtered one. Addresses #210; the feature stays dormant until Cacti
populates `poller_item.output_regex`.

Merge before #555, which needs the `get_namebyhost` fix above to resolve
a device hostname at all.

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
2026-08-31 10:03:55 +01:00
TheWitness ef783a0ff4 Copyrights (#396) 2026-02-15 22:39:58 -05:00
Linegod 169210b03c typos 2025-02-10 22:22:21 -06:00
TheWitness cea199ec6c Update all copyrights 2024-10-30 18:28:27 -04:00
Mark Brugnoli-Vinten b3303d3e16 Update copyright year for 2023 2023-01-04 10:21:05 +00:00
netniV 9c6e198295 Parse hostnames from tcp[6]:hostname:port (#181)
This is partially implemented as the hostname is now correctly extracted and a port is set against the ping_port field.  However, I don't think this goes far enough as I didn't have time to adjust udp/tcp over default methods.
2021-05-20 10:41:51 +00:00
TheWitness 95c7350679 Updating copyright, preparing for release 2021-01-01 20:31:36 -05:00
TheWitness bdfc997b8a Prep for 1.2.11 Release 2020-03-29 12:06:30 -04:00
TheWitness 5644db7732 Fixing Issue #149
Segmentation fault in spine 1.2.10 due to IPv6 address using IPv4 ICMP ping
2020-03-21 11:42:44 -04:00
cigamit 8fc523829a Update configure.ac for 1.2.3 release
Additionally update copright years.
2019-03-29 18:24:34 -05:00
Tony Roman 02c5a4615f Update copyright to 2018 2018-01-06 09:15:06 -05:00
Tony Roman eaa981b70e Update copyright to current year 2017-01-01 14:25:45 -05:00
Tony Roman 9ea2b5d348 Update copyright 2015-06-08 14:16:52 -04:00
Tony Roman a1e4e4b8fc Update copyright date to 2014
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.8@7495 860744bd-22fc-0310-8c96-e9fe5004b5ca
2014-11-12 02:38:23 +00:00
Tony Roman 168474be8c - Update spine copyright
- Fix up documenation


git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.8@7398 860744bd-22fc-0310-8c96-e9fe5004b5ca
2013-08-04 20:32:56 +00:00
Tony Roman 7128b774e5 Update spine copyrights to 2012
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@7020 860744bd-22fc-0310-8c96-e9fe5004b5ca
2012-02-27 07:18:50 +00:00
Tony Roman f76a465dcf Update spine copyright dates
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@6235 860744bd-22fc-0310-8c96-e9fe5004b5ca
2011-01-27 03:54:19 +00:00
Larry Adams 32bbae5007 QA: More copyright years.
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@6000 860744bd-22fc-0310-8c96-e9fe5004b5ca
2010-06-12 19:34:44 +00:00
Larry Adams d76efdcb8b -QA: compatibility issues with new code on Cygwin/Windows
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@5182 860744bd-22fc-0310-8c96-e9fe5004b5ca
2009-08-12 13:54:09 +00:00
Larry Adams 2acf4f0a88 -bug: ICMP fails on some platforms.
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@5181 860744bd-22fc-0310-8c96-e9fe5004b5ca
2009-08-12 13:22:18 +00:00
Larry Adams 1a81f5aee6 -QA: a few patches based on QA from Jimmy.
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@4707 860744bd-22fc-0310-8c96-e9fe5004b5ca
2008-09-10 03:44:32 +00:00
Larry Adams 720f666d52 -bug#0001231: Compiling Spine on Solaris 10
-feature: Use threadsafe gethostbyname_r
-feature: Improve mysql logging


git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@4676 860744bd-22fc-0310-8c96-e9fe5004b5ca
2008-08-31 16:41:56 +00:00
Larry Adams 55cb955d2e QA: Update copyrights
QA: Oops removing snmp_init broke snmpv3
Feature: don't complain on wrong snmp types, just roll with it

git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@4551 860744bd-22fc-0310-8c96-e9fe5004b5ca
2008-03-06 02:44:08 +00:00
Larry Adams 2b8a8c606b QA: Crossing fingers. Ok on CentOS anyway.
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@4546 860744bd-22fc-0310-8c96-e9fe5004b5ca
2008-03-02 21:08:59 +00:00
Larry Adams 93e26a31ff QA: Reworking string functions
QA: Reworking icmp ping logic a bit.

git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@4541 860744bd-22fc-0310-8c96-e9fe5004b5ca
2008-03-02 13:29:24 +00:00
Larry Adams 4bc02cf584 QA: Various build issue on various platforms.
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@4333 860744bd-22fc-0310-8c96-e9fe5004b5ca
2007-11-11 19:58:15 +00:00
Larry Adams 5c9f3715e6 Compatibility fixes for Windows build.
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/main@4272 860744bd-22fc-0310-8c96-e9fe5004b5ca
2007-10-23 00:40:56 +00:00
Larry Adams b4c9889899 Fixing implied definition of ping_tcp.
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/main@4220 860744bd-22fc-0310-8c96-e9fe5004b5ca
2007-10-09 18:02:38 +00:00
Larry Adams b099e3d543 Initial rename, Add tabs stops and autoindent, fix copyright
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/main@4142 860744bd-22fc-0310-8c96-e9fe5004b5ca
2007-09-10 12:28:22 +00:00
Larry Adams 47300c2932 1) Update Copyright information
2) -feature: add Net-SNMP Library vs. Header check prior to execution.
3) More clearly indicated script servers being shut down during debug
4) Optimize some of the latest code based upon what would appear to be common sense.

git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid@3567 860744bd-22fc-0310-8c96-e9fe5004b5ca
2006-03-12 15:28:34 +00:00
Larry Adams 7b3e4ad1c8 -bug: Allow ICMP or UDP ping to work if host begins with either "TCP:" or "UDP:"
-bug#0000682: Allow storing of each hosts polling start time
-bug#0000716: Don't attempt to save output for a host if there is none.
-bug#0000717: Allow numeric double results to start with '+', '-', '.'


git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid@3564 860744bd-22fc-0310-8c96-e9fe5004b5ca
2006-03-11 20:44:40 +00:00
Larry Adams 961bacbe20 additional portability patches from the unixwiz.
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid@3452 860744bd-22fc-0310-8c96-e9fe5004b5ca
2005-12-30 00:33:34 +00:00
Larry Adams 02db0c564a major changes thanks to the a contrib from http://www.unixwiz.net Thanks Steve!
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid@3442 860744bd-22fc-0310-8c96-e9fe5004b5ca
2005-12-24 01:28:16 +00:00
Larry Adams 4a456ce805 preping rc6 of cactid-086f
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid@3148 860744bd-22fc-0310-8c96-e9fe5004b5ca
2005-08-26 00:48:55 +00:00
Larry Adams 4f6c0e1f60 change licensing to LGPL
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid_unix@2953 860744bd-22fc-0310-8c96-e9fe5004b5ca
2005-06-11 03:58:59 +00:00
Larry Adams 7e95af3875 copyright information change for OpenSSL compliance
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid_unix@2947 860744bd-22fc-0310-8c96-e9fe5004b5ca
2005-06-10 04:04:09 +00:00
Larry Adams ac3b7890c1 rc16 changes
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid_unix@2914 860744bd-22fc-0310-8c96-e9fe5004b5ca
2005-06-07 02:09:44 +00:00
Larry Adams 9a6ae7abd9 repaired some string handling issues with multi part script server results.
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid_unix@2910 860744bd-22fc-0310-8c96-e9fe5004b5ca
2005-06-03 22:45:40 +00:00
Larry Adams dbfde20dbf cactid 0.8.6e-rc8
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid_unix@2868 860744bd-22fc-0310-8c96-e9fe5004b5ca
2005-05-27 18:05:55 +00:00