Assert known constraints, log debug on any success.

ServerTLSPeek() would log the data it peeked, but only when deciding
it has TLS; I'd like to be able to see it also for classic.

As recv() definitely shouldn't return more than the buffer size it was
given, assert this, tweak the first check (any negative is failure,
not just -1, albeit only -1 should happen) and simplify the rest.  The
TLS case wasn't checking got == peek_size (as the CAUTH case did), but
can take this for granted (given the assertions) now.
(cherry picked from commit 0c10b9e0c00ac4a2db9f44d69bf4433abcc8e717)
Restructure ServerEntryPoint() to avoid duplication of tidy-up.

I'm about to complicate that tidy-up and I'd rather do it in one place
than five.
(cherry picked from commit c2be570c9fac109bc84d8b45f69f9addeeddb60c)
Don't mark call-collect as processed until it is.

In cf-serverd's StartServer, we were calling CollectCallMarkProcessed
right after the call to ServerEntryPoint; but that merely spawns a
thread to do the work, it doesn't wait for it to complete.  So mark
the connection info object and move the CollectCallMarkProcessed to
where that gets destroyed - when we've finished delivering our report,
or when we abandon the attempt for whatever reason.
(cherry picked from commit 07b76834628ed1dc99127a9dce5391fbdb8cf304)
Set policy_server everywhere we set am_policy_hub.

The recent change to replace am_policy_hub with policy_server broke
various things because cf-serverd wasn't seeing the new class defined.
So fix the places that set am_policy_hub without setting its
replacement also.  Also, various of those weren't using the right
metadata, so add a function that sets both classes, to be called by
all the places that used to set am_policy_hub, so that they all use
the right attributes and also set policy_server.
(cherry picked from commit ed7035e4b2459614f2a09f51686bbb7dfb410f45)
Rewrote RlistFromSplitString() to not limit fragment lengths.

It previously restricted the sizes of fragments to 1024 bytes,
CF_MAXVARSIZE; it now uses a dynamically-sized buffer.  Also, instead
of appending fragments to the Rlist, prepend them and reverse the list
just before returning it; this reduces an O(len^2) to an O(len).
(cherry picked from commit b796914262747321fbd9fca67da5f2983ffdf039)
redmine6466: preserve order in readstringarrayidx

Reading the file's contents via a Set is harmless for the other
read*array functions, since they use data from each line as the key,
so naturally discard duplicates and have no other ordering than that
of the keys themselves; however, for readstringarrayidx, the order of
lines actually matters and duplicates are meaningful.  So convert
BuildLineArray to use an Rlist instead of a StringSet (and iterator);
and add an acceptance test (which was actually the hard part).
(cherry picked from commit 6e11153492f13ff2057101cb2d5e9726dad41f93)
Un-suppress AIX, as it now works.

Builds of testing-enterprise-master were failing because
check_outputs.cf expected to fail and didn't ;-)
(cherry picked from commit 3411df88c8d7981b24d7cd8733d89f76de34dffa)
Make regex tests accept const-qualified parameters.

The string passed to IsRegex or IsPathRegex is not modified, so allow
these to be passed a const pointer; likewise for IsRegexItemIn's regex
and the list of entries that's used to check.
(cherry picked from commit 11053e88b5f05b5a633236e83dc78ba0e293e129)
Allow copy of dead symbolic links, see https://dev.cfengine.com/issues/6175
(cherry picked from commit ac65bfc2e2dc3a044b72ddf343081c05259d7106)
Implemented all suggestions from @ediosyncratic. Thanks for the review
(cherry picked from commit 6d47af76cb253ae67d7e8a1033ed5534fbbd8aec)
obey coding style and changed log message
(cherry picked from commit 1e431118f36facb041df42c7a101d6191622e86b)
the detection of dead symbolic links must also be ported to protocol_version 2 to my surprise
(cherry picked from commit cd0950473aaa9ba427a548b60229b263979fd75c)
Include type definitions when declaring functions that use them.

A header should not reference a type for which it doesn't provide a
declaration, ideally via the appropriate other header.  I wanted to
call cf_closesocket but pulling in the header that provides it gave me
compiler errors because of references to undefined types in functions
I wasn't interested in.
(cherry picked from commit c736ad146602bcb8ebd3c8fee9419ddf843add8e)
Only filter init out of process matches when we *are* signaling.

FindPidMatches() filters pid 1 (init) out of its result list because
we don't want to be sending it stray signals - we should only do this
when a.signals is set, though !  We special-case HUP and allow it; but
then a check on pid < 4 will exclude it anyway, regardless; so make
that an else clause of the pid == 1 check, so avoid subverting the HUP
exception.  Finally, combine these and the "don't shoot yourself"
exception for cfengine_pid into a single block conditioned on
a.signals instead of testing it separately for each of these cases.

(cherry picked from commit 8cdf3d733ed1d8a1e3fcc3eca002e575358254e6)