Fix memory leak in IsProcessNameRunning().

When it finds a matching row, it breaks out of the loop over rows;
otherwise, it free()s the fragments into which it parsed the line that
just failed.  The matching line's fragments need free()d just as much.

(cherry picked from commit 54f1e64a5c284da152e71b7edbcc552de085e5a7)
Redmine #6370: Discard call collect connection.

Instead of sending "BAD: Unspecified server refusal
(see verbose server output)" message to the call collected client
which is not having access to call collect simply refuse connection.

Message sent to the client is interpreted as a call collect queue
length and client assumes that connection is valid.

(cherry picked from commit 9a5e8c5b1cc65a3f681d6acfced407612673be95)
Redmine #6434: Fix AIX missing a lot of log output.

It happens because we list a static library as a dependency for
libpromises, and then we list the same static library as a dependency
for a binary that depends on libpromises. Then the symbol will be
included both in the library and in the binary.

Exactly how the symbols are resolved appears to be platform dependent,
but what can happen is this: At any point, when you call a duplicate
symbol, depending on where you call it from, you will either call the
version in the binary or in the library. This is fine, since they both
contain exactly the same code. However, they do not refer to the same
global symbols. They each have their own set. This means that
something that was initialized in the binary may not be initialized in
the library, even though the symbol name is the same. This has weird
effects, like a symbol suddenly switching from a valid value to zero
when the stack trace crosses a library boundary.

The problem was observed on AIX, where the log level randomly switches
between verbose and non-verbose, depending on where the Log() function
was called from.

(cherry picked from commit da7d7457b8f14f11f71fb4ea345688b311418742)
Redmine #4716: Lots of fixes to dirname(), esp. on Windows.

These problems were fixed:
* AddSlash() always adds Unix slash when argument is empty.
* DeleteSlash() removes root slash.
* DeleteSlash() does not handle repeated path separators.
* FirstFileSeparator() returns NULL on all relative Unix paths, even
  if it has a file separator.
* ChopLastNode() gives empty string when removing last directory
  component of a relative path. It should give '.'.
* ChopLastNode() does not handle Windows drive letters.
* ChopLastNode() does not handle repeated path separators.
* IsAbsoluteFileName() does not handle absolute paths on Windows that
  don't start with a drive letter. Both types are considered absolute
  paths.

This also fixes a Windows issue where creating a directory in policy
would lead to an error message about not being able to chdir into a
directory with the name ''. This was due to the final root slash not
being preserved.

(cherry picked from commit 1b6ac94a576b13dfc5dd5b2e5b12ccce655101f6)
Revert "Remove uninitialized buffers as source of entropy."

This reverts commit 570724e752cf131132bb88e65a031f700b0ac424.

The reason is that in a chroot testing environment, there isn't enough
entropy available to satisfy OpenSSL, so it will bail out. Reverting
is not the correct fix for the problem, but right now we need tests to
pass, so postponing this for later.

Conflicts:

	libpromises/crypto.c

(cherry picked from commit f0865c7682036ef78bb4b3ac27ea0d6a898b7958)
the detection of the package manager was wrong

(cherry picked from commit b68b49fe53540c1d9b9edebdd1d205bb8094b921)
the cache file is now valid, so we only have one package match

(cherry picked from commit 71af0b96568db065be5e7caa667f891aeddebd6f)
re-enable acceptance tests which now pass on solaris

(cherry picked from commit b2dc9eb028ced32ff350d60e7f80034876f2cd26)
redmine6476: Aborting on low entropy is too drastic.

Rather than reverting the whole commit involved, keep what we can of
it and Log() instead of UnexpectedError(), at least until Jimis can
invent some better way to respond to this.

(cherry picked from commit e7f0dc7983ff1242df8c9b602a0db08190097ae3)
Pass the path to pcre.h to the compiler

(cherry picked from commit a8d82ab6d737100dea7992f1fcd9fe759cd14adc)
Correct return from BusyWith functions after ReceiveCollectCall().

Forwarding its return to our caller wasn't smart: we should return
false either way, because cf-serverd's side of the connection got
closed whether it succeeded (handed off to cf-hub) or failed
(abandoned).  Returning true was leading the caller to call the
BusyWith function again, producing a distracting TLS_Read failure.

In addition, on failure, BusyWithClassicConnection() would - due to a
misguided fall-through - wrongly report an unexpected command, if we
ever let it support call-collect.  Now it returns false.

(cherry picked from commit b1735f77faf3936230580b2b842a2cd99e3422db)
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)
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)
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)