(#19271) Proper check for which cert to use in ssl error

Don't assume the puppet ca subject name starts with 'puppet ca'
Explicitly cast Pathname in Puppet::Util#replace_file

Puppet::Util#replace_file contains a call to File#rename
where one of the arguments is of type `Pathname`.  The
actual method signature requires two String arguments,
and JRuby does not appear to implicitly cast in this
situation--so all calls to `replace_file` were failing
on JRuby.  This commit simply makes the cast explicit.
(#18781) Be more tolerant of old clients in WEBrick server

In #18781 and #6117 there are cases of relatively simplistic puppet
setups failing between old versions of the puppet client (which
always use HTTP GET) and new versions of the puppet WEBrick server
(which has a relatively low limit on the size of a valid GET: 2083
bytes).

While there are other non-WEBrick server options available, WEBrick
has the advantage of simplicity, so it would be nice to keep it working.

Here we patch the WEBrick constant which specifies the maximum size of
a HTTP GET request, increasing it to a value that should work for common
setups.
(#19323) ext/systemd: adding a way to specify cmd line options

This patch adds a way to easily specify extra command line options for
both puppetagent and puppetmaster services when starting them with
systemd.

It removes ExecPre command as the directory creation is now handled by
the RPM install.

Previously there was no way to pass in valid puppet agent/master command
line parameters like '--config=/etc/puppet/puppetmaster.conf', etc. A
lot of people use separate config files for the agent and the master
services.

To make it somewhat consistent I added a systemd supported way to read
environment variables from a file '/etc/sysconfig/<servicename>', so
people who use extra cmd line options already will be able to do that with
systemd as well.

When services are started by systemd, systemd will read the files which
contain the below variables and will pass their values when starting
puppet services (I used the same variable names as it's been used in
redhat-like distros already):

PUPPET_EXTRA_OPTS in /etc/sysconfig/puppetagent
PUPPETMASTER_EXTRA_OPTS in /etc/sysconfig/puppetmaster
Merge pull request #1483 from cprice-puppet/bug/master/replace_file_jruby_fix

Explicitly cast Pathname in Puppet::Util#replace_file
Merge pull request #1487 from vaijab/fix/master/cmd_line_opts_with_systemd

(#19323) ext/systemd: adding a way to specify cmd line options
Merge pull request #1478 from dsd/fix/master/18781-webrick-old-client-compat

(#18781) Be more tolerant of old clients in WEBrick server
Merge pull request #1477 from dalen/ssl_error

(#19271) Proper check for which cert to use in ssl error
(maint) Use MatchData object over ruby global vars

The implementation for native file headers for the ParsedFile providers
made use of the Perl style global variables like $`, $', and $&. These
are difficult to understand at first glance and equivalent behavior is
provided by MatchData objects. This commit removes the global variables
with a MatchData object for clarity.
(#19393) Safely load YAML from the network

When using Psych (only available in Ruby 1.9), YAML.load may in certain
cases (!map: and !ruby/hash: tags) use the initialize and []= methods to
create objects. These methods could potentially allow arbitrary code to
be executed. We now add a safely_load method which parses the input
first, checks it for dangerous tags, and fails if they are found. If the
input is clean, we transform the result (as YAML.load would have done)
and go on our merry way.

This change is only applied to YAML coming in either HTTP requests or
responses. YAML from the local system is trusted, as anyone who can
write that YAML could do damage some other way.
(#19393) Safely load YAML from the network

When using Psych (only available in Ruby 1.9), YAML.load may in certain
cases (!map: and !ruby/hash: tags) use the initialize and []= methods to
create objects. These methods could potentially allow arbitrary code to
be executed. We now add a safely_load method which parses the input
first, checks it for dangerous tags, and fails if they are found. If the
input is clean, we transform the result (as YAML.load would have done)
and go on our merry way.

This change is only applied to YAML coming in either HTTP requests or
responses. YAML from the local system is trusted, as anyone who can
write that YAML could do damage some other way.
Merge remote-tracking branch 'puppet-cve-test/safely-yaml-3.1.0' into security/3.1.0/february_code_orange

* puppet-cve-test/safely-yaml-3.1.0:
  (#19393) Safely load YAML from the network
Merge pull request #1489 from adrienthebo/maint/master/parsedfile-human-readable-match-variables

(maint) Use MatchData object over ruby global vars
(#14093) Cleanup tests for template functionality

Some of the previous tests were unneeded (check for simple existance) or
mis-named. This cleans those up. A few other tests were trying to
indirectly test many things at once (the ones about access to instance
variables). Instead of the indirect test this splits it into much more
specific tests and statement of behavior.
(#14093) Remove unsafe attributes from TemplateWrapper

The attribute accessor for the :string attribute in the TemplateWrapper
conflicted with a variable being in scope that is named string. The
variable would take precedence and because of the way the
TemplateWrapper accessed the value of the attribute, the variable's
value would be used as the template.

This changes the TemplateWrapper to completely remove :string as an
attribute and only use local variables. This also removes the :file
attribute in favor of a "private"-style naming of the instance variable.
There are no collisions with @__file__ that would cause problems, but
this should reduce the likelihood of them happening in the first place.
(Maint) Remove special handling for symbols in scope

The Puppet::Parser::Scope no longer allows variable names that are not
String objects, so the extra code to handle non-string variable names is
no longer needed.
(#14093) Restore access to the filename in the template

The change to fix certain variables interfering with template evaluation
also removed the accessor method for file. It appears that this is a
mechanism that had been used by others for identifying the name of the
template being evaluated so that they can trace back from a file on a
node to the module and template that created it. This restores that
functionality.
(Maint) Add YARD to TemplateWrapper

This tries to document the methods that should be available to template
authors. Not all methods are listed, since there may be some things that
are mixed in somehow and there are all of the variable accesses provided
via method_missing.
(maint) Kill Puppet::Parser::TemplateWrapper#scope=

This is dead code that is never called based on `ack` and replacing the
method body with an thrown exception.  The scope instance var is stored
in @__scope__ not @scope.
Merge branch 'zaphod42-issue/master/14093-string-overrides-all-template-output'

* zaphod42-issue/master/14093-string-overrides-all-template-output:
  (maint) Kill Puppet::Parser::TemplateWrapper#scope=
  (Maint) Add YARD to TemplateWrapper
  (#14093) Restore access to the filename in the template
  (Maint) Remove special handling for symbols in scope
  (#14093) Remove unsafe attributes from TemplateWrapper
  (#14093) Cleanup tests for template functionality