(#20302) Windows ruby 1.8 workarounds are not necessary in 1.9

Previously, the sprintf spec failed, because ruby outputted the
exponent with a leading zero, despite a precision of 2. The zaml spec
failed, because ruby didn't recognize the Europe/London timezone.

Ruby 1.9 fixes these issues, so the workaround in sprintf_spec is no
longer necessary, and the zaml_spec issue is no longer pending.
(#20302) Append .exe to spec "executables" on Windows

When running the tests on Windows and Ruby 1.8.7, File.executable?
returns true on regardless of the file extension. On Ruby 1.9, it only
returns true if the extension is .exe or similar.

This commit ensures the "executable" ends with .exe.
(#20302) Handle nested include filters

Nested rspec include filters don't work the way I expect. Given:

  describe "A", :if => rdoc1? do
    before :all do
      require 'rdoc/tokenstream'
    end

    describe "B", :if => windows? do
    end
  end

If rdoc1? is false, but windows? is true, the before :all/:each blocks
will still be executed, and the tests in B will be executed.

As a result, the spec tests fail on Windows and ruby 1.9, because our rdoc
parser is not compatible with newer versions of rdoc. For example,
rdoc/tokenstream.rb was moved to token_stream.rb, etc.

This commit adds the rdoc1? predicate to the example group B, so that
it is not executed when rdoc1? is false.
(#20302) File.expand_file('~') fails differently in Ruby19

In ruby 1.8, calling File.expand_path('~') when HOME is undefined
would raise ArgumentError on both Unix and Windows.

The same test in ruby 1.9 does not raise on Windows, because ruby
also looks at HOMEDRIVE and USERPROFILE. Only if all three are
undefined does ruby raise ArgumentError as expected.

This commit ensures all 3 environment variables are undefined in util_spec. It
also only tests the platform specific RunMode functionality on the appropriate
platforms, and adds tests that were missing on the Windows side.
Docs: Improve documentation of "duration" settings

A user pointed out that "as a duration" was not a helpful way to describe the
formats used by duration settings; although the formats are explained at the top
of the config reference, scrolling shouldn't be necessary, and most readers
wouldn't think to check the top of the file.

This commit puts a small list of the formats in each duration setting, as well
as marking the activerecord storeconfigs settings as deprecated.
Revert "Merge branch 'cprice-puppet-bug/3.0rc/15187-log-fatal-errors-to-console'"

This reverts commit 8d99bcbe6ebe6ca15868334bb52349911b58598c, reversing
changes made to 7d6515f076715c1feab0addc99312c42fb8b578c.

This change had two unintended side effects:

1) 20900 tagmail from 'puppet agent --onetime' run as a cron job begins
sending additional emails of verbose logs.

2) 20919 cron job of 'puppet agent --onetime --no-daemonize' produces
additional verbose logs to both console and syslog.

Issue #1 occured because the 15187 patch caused agent log level to
switch to info by default.

Issue #2 was due to the above log level issue, and the fact that by
default a console logger was also opened for all agents, which does not
get closed if --no-daemonize is specified.

Reverting fixes both of these unintended logging issues by returning to
the logging behavior seen in 3.1.1.
Docs: Fix a persistent formatting glitch in the file type's ensure parameter docs
Maint: Don't execute facter during spec tests

Previously, the test was trying to test that the 'facts' application
could be invoked and return exit code 0 with meaningful output. However,
it causes the 'facter' terminus to be invoked, which actually runs
facter.

Since we don't care what facts are returned, this commit adds an
expection to make sure the indirection#save method is called and returns
successfully.

This was discovered on win2003 due to local facts being present, which
when evaluated, wrote errors into the log.
Merge branch 'ticket/stable/20900-revert-agent-console-logging' into stable

* ticket/stable/20900-revert-agent-console-logging:
  Revert "Merge branch 'cprice-puppet-bug/3.0rc/15187-log-fatal-errors-to-console'"
Maint: Fix typo in deprecation warning

The deprecation warning said to use a method that doesn't exist.
Merge pull request #1674 from nfagerlund/maint/duration_settings

Docs: Improve documentation of "duration" settings
Merge pull request #1675 from nfagerlund/maint/file_typo

Docs: Fix a persistent formatting glitch in the file type's ensure parameter docs
Merge pull request #1677 from joshcooper/ticket/stable/20302-ruby19-windows-specs

Update specs for Windows on Ruby 1.9
(#20768) Don't confuse WMI and IADsUser automation objects

To enumerate local users (and groups), we execute a WMI query. The query
returns an array of generic WIN32OLE objects, each of which wraps an OLE
automation object. The WIN32OLE object uses method_missing to dispatch
method calls to the underlying automation object.

In the case of a WMI query for users, the underlying automation object
provides the methods and properties defined by the Win32_UserAccount
class[1], e.g.  AccountType, Caption, etc.

Previously, we were creating instances of Puppet::Util::ADSI::User and
passing in a WIN32OLE object wrapping the WMI automation object, when it
expects a WIN32OLE object wrapping an IADsUser[2] object.

This never caused a problem, because the windows ADSI user provider's
instances method only enumerates the user names on the systems and
creates new Puppet::Util::ADSI::User objects from them.

However, if you had ever called Puppet::Util::ADSI::User.each
programmatically, and then called a method that used the WIN32OLE
object, e.g. native_user.Get('HomeDirectory'), it would fail since the
WMI based automation object doesn't implement the 'Get' method.

This commit changes the 'User.each' method to not pass in a native_user
object. Instead, we create the correct native_user object lazily.

The same issue existed for 'Puppet::Util::ADSI::Group.each' as well.

[1] http://msdn.microsoft.com/en-us/library/windows/desktop/aa394507(v=vs.85).aspx
[2] http://msdn.microsoft.com/en-us/library/windows/desktop/aa746340(v=vs.85).aspx
(#20768) Only query on the name field

Previously, we loaded entire WMI objects from the query, assuming they
were needed by the ADSI objects. But this was incorrect and never
worked.

Since we only need the User and Group names, we can select only those
fields.
(#20768) Use the correct Win32API method signatures

In ruby 1.8, we could call CloseHandle passing it the handle (an opaque
unsigned integer value), and due to the 'P' in the method signature,
automatically arrayify and pack the handle. This wasn't done intentionally,
it just happened to work.

But ruby 1.9 no longer automatically coerces the parameter, instead
the CloseHandle method (implemented by the windows-pr gem) tries to pack
the handle, generating an error `can't convert Fixnum into String`. This
prevents puppet from managing a user's password and home directory.

The proper fix is to define the CloseHandle method signature correctly, so
that the windows-pr layer doesn't attempt to coerce the handle value.

The UnloadUserProfile API had a similar problem, it takes the handle as an
'L' input paramter (instead of a pointer).
(#20768) Enable managehome acceptance test on Windows

This commit enables the acceptance test on windows. On 2003, the default
home directory is C:\Documents and Settings\username. On Vista and
later, it is C:\Users\username. In the 2003 case, the home directory
needs to be quoted, e.g. when passed on the command line.
(#20768) Refactor base profile logic

This commit refactors the logic for figuring out the base profile
directory, e.g. C:\Users or C:\Documents and Settings, and updates the
acceptance test to use it. The `--helper` option must be used in the
systest harness so that the LOAD_PATH is setup correctly to find the
windows_utils.rb helper, but this should already be the case for
temp_file_utils.rb, etc.
(#20768) Windows can now create the home directory (again)

The previously pending_test method was used, because puppet couldn't
create the home directory when creating the user in ruby 1.9 on windows.
Now that that is resolved, we can remove the windows-specific
pending_test. Note, that the test will still be pending later, since
neither the windows nor useradd providers correctly move the user's home
directory.
Merge pull request #1680 'joshcooper/ticket/stable/20768-windows-managehome-redux' into stable

* joshcooper/ticket/stable/20768-windows-managehome-redux:
  (#20768) Windows can now create the home directory (again)
  (#20768) Refactor base profile logic
  (#20768) Enable managehome acceptance test on Windows
  (#20768) Use the correct Win32API method signatures
  (#20768) Only query on the name field
  (#20768) Don't confuse WMI and IADsUser automation objects
  Maint: Fix typo in deprecation warning

closes #1680