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)
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)
Merge pull request #1902 from ediosyncratic/cherries-36x

[3.6.x] Cherries from master for 3.6.x
Simplify if/#if-ery to avoid confusing emacs indentation.

(cherry picked from commit 2e3a00af1faeb78d05a331f5ae019eaadc701679)
redmine 5893: scalar variables in unexpanded array references

Fix parsing, add acceptance test.

(cherry picked from commit 8596c8af5ca5a94a685b7ceb5e396f5cf4362d6e)
Patch for parsing of arrays of lists

(cherry picked from commit 0f80c3cc99f3be36d90aa60ea17a9172ded44c54)

Conflicts:
	libpromises/cf3.defs.h
	libpromises/mod_common.c
Add: Acceptance test for rendering quotes in mustache

Ref: https://dev.cfengine.com/issues/6516
(cherry picked from commit 51ca2ac5964d8a2966f728c96e15d654ab13c514)
Fix for test of mustache's rendering of quotes.

The test expected variable expansion to be unescaped, but it's escaped
by default; it needs an & at the start of the variable name to
suppress escaping.  I've duly expanded the test to test both escaped
and unescaped variable expansion.

(cherry picked from commit b2e5b9b1abf6291cb5da5fef16c1047476b8f7d1)
Assorted clean-up in processes_select.c

Casting the paramater of isspace to int is dumb; even without the
overt cast, that would happen.  As it happens, isspace wants to be
given an int whose value is either that of an unsigned char or EOF
(which is -1).  So, when passing a char to it (which is what we're
doing) we *do* need to cast it - to unsigned char - after all.
Likewise for isalnum().

Various loops were needlessly complicated by mishandling the 0 case,
leading to kludges to not end up with the wrong answer.  Use the right
test, avoid the dumb kludges.

Prefer memcpy (with explicit termination) over strncpy and kill the
wanton memset(,0,)s implicit in an initializer that assured the
strncpy() would have a trailing '\0'.

Kill a spurious continue (in an if, whose else was the rest of the
loop anyway).

Removed misleading " INFO - " from the front of a LOG_LEVEL_VERBOSE.
Chop() was being called with the wrong size for its buffer.
A loop variable could be made more local and const.
Turn some untidy while loops into for loops.
Split some lines to make them more readable.
Made diverse other locals more local.
Fewer parentheses.

(cherry picked from commit 4d8404417605e41687d1d76a9a5f1700d2114750)
Rework SplitProcLine(): smarter growing of fields outside columns.

GetProcessColumnNames() records the start and end columns of the
headings for ps-output.  SplitProcLine() uses these in its second
heuristic for parsing the columns from data lines.  (The first
heuristic simply splits on spaces, aside from a minor kludge for
STIME.  If the two heuristics disagree, we Log() a warning.)  It used
to grow the field outwards, to a space on each side, but limiting
growth to the right to (arbitrarily) ten characters.  This might
extend beyond the next column to either side.  We see Solaris ps can
have fields that abut, which would lead several fields to use the same
text, this way.

Having now studied actual ps output (details documented in a comment
at the start of the heuristic), I've changed this so that:
 * for numeric fields, it grows left, potentially into the previous
   column but never to its start;
 * for text columns it grows right but never overlaps the next column
   header.
Other columns are limited to the width of their header.

It also now strips all leading and trailing space (it used to neglect
this for the last column, even after I fixed assorted off-by-one
errors), which eliminates the need for Chop().

I've also eliminated the assumption that CMD/COMMAND is the last
column - it's easier, safer and correct to test for last column, for
all that this always just happens, for good reason, to be CMD.

(cherry picked from commit cbf52201b0c202140380b08f78944066a2fadeb0)
Rewrite SplitProcLine() without temp buffers.

Rather than scanning the line twice, filling two arrays with fragments
obtained by two heuristics, so as to be able to compare them, do the
two scans in parallel.  This removes the needs for arrays to hold the
fragments, hence the need to clip a long field if we hit one (it'll be
COMMAND, if it happens), and saves a lot of copying.  We only need to
copy the contents (and clip them) when warning and as part of the
xstrndup(), replacing xstrdup() of a copy, needed to allocate the
fragment saved.

(cherry picked from commit 2dc3be355f846bbca47693da4eaf26b5322b74c9)
Include {admit,deny}_{ips,hostnames} in the relevant legacy lists.

Entries provided by admit are delivered both to the legacy ACL list
and to the new ACL system's relevant list for admit_ips or
admit_hostnames; likewise for deny.  However, entries given with these
new controls were only added to the new system's lists, not to the
legacy lists, so parts of the code that still use the legacy lists
were not honouring ACLs set using the new keywords.  Add also to the
legacy lists to fix this, until we're finally rid of the legacy code.

(cherry picked from commit 49258153202cfa131ef40d687ca08bc97f26f4aa)
Bug in makerule - and make it compatible with if/ifvarclass.

Function was declared incorrectly and would not match in
if/ifvarclass. Also it must return false in order to be compatible
with these cases, not merely fail as previously argued. This is the
only way to make class functions consistent

Downgrade the level of a Log() message.

(cherry picked from commit e3f11abf91a07a78439594ab32819c0d0514b3ee)
Refine old-ACL representation of new-ACL hostnames.

The old-style ACLs used regex matching on hostnames, alongside exact
matching; new-style uses only sub-domain and exact matching.  So map
sub-domain matches to regexes in the natural way.

(cherry picked from commit 52c72ceb900785353a1345be4d18ddf84571f634)
Fix fence-post error in my re-write of SplitProcLine().

I was leaving ep pointing at the last character of the space-delimited
field, not at the character after it.  How did that even work on the
systems where it did ?

(cherry picked from commit 74eb756c2e3363254ef7fb5b798157d9f8c258ad)