(#13204) Workaround duplicate Augeas save events

Bug #264 in Augeas causes duplicate save events to be returned when editing
under /boot in newfile mode.  Because we loop around these events, diffing and
unlinking the files, this causes an ENOENT error when we process the same event
twice.

This commit checks that the file we intend to operate on exists.
Quote strings containing hex numbers when generating ZAML

When generating ZAML, we prefer to write bare strings when possible. To
that end, we have rules about which sorts of strings are not safe to
write bare. One of those rules is strings containing numbers (for if we
wrote those bare, they would be revived as numbers). However, ZAML
wasn't properly considering hex digits when identifying a string
containing a number, resulting in those strings being written unquoted,
and revived incorrectly as numbers.

That is, YAML.load(ZAML.dump("0xffff")) would return 65535, when it ought
to be "0xffff".
(#12466) unset X-Forwarded-For header

Without this patch the handling of
X-Forwarded-For headers is insecure in a
default apache conf supplied with puppet.
This patch ensures X-Forwarded-For headers
are dropped.

Signed-off-by: Moses Mendoza <moses@puppetlabs.com>
(#12101) Add shared context for specs to imitate windows or posix

Add "windows" and "posix" shared contexts to rspec. If you give :as_platform
=> :posix or :as_platform => :windows as argument to a describe block, it will
automatically stub the relevant facts and path behavior to imitate windows or
posix.
(#12101) Make Puppet::Util::absolute_path? usable in autoloader

This makes Puppet::Util::absolute_path? check File::ALT_SEPARATOR to determine
path behavior of the local system instead of Puppet.features, which required
having an Autoload instance already. File::ALT_SEPARATOR is only defined on
systems with Windows path behavior, and the Ruby standard library uses this
frequently to distinguish systems.
(#13397) fix gem provider ensure=>latest bug

As of 2.7.12, if you had "ensure=>latest" for any gem package
resource, puppet would not correctly detect that the gem
was already installed and would attempt to install it on
every run.  (This was because the "latest" method on the
gem provider was always returning an array, when it should
always be returning a single value.)
(#3581) Stop forking around: Add fork helper method

Without this patch we are forking all over the place. All this forking
around is problematic when it comes to things like ActiveRecord and
database connections. It turns out that forking has a nasty side effect
of aggressively closing database connections and spewing errors all over
the place.

This patch introduces a new `Puppet::Util#safe_posix_fork` method that
does forking the right way (closing file descriptors, and resetting
stdin, stdout, and stderr). Tagmail, Puppet kick, and
`Puppet::Util#execute_posix` have been updated to make use of this new
functionality.

In the future, `Puppet::Util#safe_posix_fork` should be used in-place of
direct calls to `Kernel#fork`.

This patch includes related spec tests.
Removed text/marshal support

Removing text/marshal support in order to close the security
vulnerability described in Bug #13552.
Fix for bucket_path security vulnerability

This is a fix for Bugs #13553, #13418, #13511. The bucket_path parameter
allowed control over where the filebucket will try to read and write to.
The only place available to stop this parameter is in the resolution
from a URI to an indirectory terminus. The bucket_path is used
internally for local filebuckets and so cannot be removed completely
without a larger change to the design.
Remove telnet Output_log parameter

The puppet telnet util opened an output log by default with a predictable name.
This left the log open to a write-through symlink attack as the puppet user.
This fix addresses that by removing the Output_log parameter from the
Net::Telnet::new call. Without the parameter, Net::Telnet defaults to no output
logging. The same is true for the dump_log parameter. The spec test for telnet
has been updated to test and ensure that no files are opened during connect. It
also stubs the TCPSocket for the telnet connection so that no connection is
attempted if @transport.connect isn't stubbed.
Refactor pkgdmg specs

Refactor to a more current spec style. Several of these specs didn't actually
test anything. They have either been deleted or made more specific.
(#13260) Use mktmpdir when downloading packages

This fixes a security vulnerability in the appdmg and pkgdmg providers where
they would curl packages directly into /tmp and the install them, allowing an
attacker to craft a symlink and overwrite arbitrary files or install arbitrary
packages.
(#12392) Created Windows eventlog message resource dll

This commit adds the ability to build a message resource dll used to
display localized eventlog messages on Windows. Windows eventlog expects
that each log event has a unique id, which can then be localized in a
resource dll, one for each locale. However, puppet does not yet support
this, see #11076. So this commit defines three puppet event ids
corresponding to the three levels of Windows events that we support
(info, warn, and error).

In order to build the dll, you need the Windows SDK installed that
contains the mc, rc, and link utilities.
(#13260) Spec test to verify that mktmpdir is used
Stub mktmpdir and remove_entry_secure in os x package providers
(#13638) Add SemVer#pre function

Before this patch the `SemVer#[]` method uses a `proc` to pre-process
version strings, which seems a bit unnecessary when a method would do.

This patch replaces the `proc` with the `SemVer#pre` method and updates
the related specs.
(#13642) Move search notice message

Currently the PMT search action assumes the searcher implementation will
connect to the HTTP server defined by
`Puppet.settings[:module_repository]` when searching for modules on the
Forge. The server defined by `Puppet.settings[:module_repository]` is then
used in a message printed on the console: `Searching #{server} …`. This
is a little too close to the implementation and the notice has been
moved closer to where the search is actually taking place.
(#13643) Make the use of FileUtils.rm_rf secure

Use the `:secure` option with the `FileUtils.rm_rf` method to
avoid a TOCTTOU (time-of-check-to-time-of-use) local security
vulnerability.
(#13649) Restrict module name matching

Before this patch the regex used to match valid module names in
`Puppet::Node::Environment#modules_by_path` matches invalid module
names.

This patch replaces the current regex pattern with one more accurate.
This patch also includes updated specs to cover this change in behavior.
(#12392) Add eventlog destination and log to it by default on Windows

Previously, puppet logged by default to syslog or a file.

This commit changes puppet to log to syslog, the eventlog, or a file, in
that order. Puppet uses `Puppet.features.eventlog?` to determine if the
Windows eventlog is available on the current platform (which requires
the win32-eventlog gem). If the feature is false, then the eventlog
destination is not created, and the next suitable destination is used.