From ccdd043ab309ca382dc949612d7efe3562adf5c5 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Thu, 18 Aug 2011 10:30:29 -0700 Subject: (#8662) Break circular feature dependency The root feature was being evaluated prior to the microsoft_windows feature being defined. On Windows, this had the side-effect of calling Process.uid prior to the win32 sys/admin gem being loaded. And the default ruby implementation of Process.uid always returns 0, which caused Puppet.features.root? to always return true. This commit reorders the syslog, posix, microsoft_windows, and root features due to dependencies among them. This ensures the microsoft_windows feature is defined prior to evaluating the root feature. As a result of this commit, the SUIDManager now calls the win32 sys/admin version of the Process.uid method, which returns the RID component of the user's SID. As this is not 0, Puppet.features.root? will now always return false on Windows. A future commit will fix this, so that Puppet.feature.root? only returns true when running as the Windows-equivalent of root. --- lib/puppet/feature/base.rb | 54 ++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/lib/puppet/feature/base.rb b/lib/puppet/feature/base.rb index 2eddadb7a..cecc1b9ad 100644 --- a/lib/puppet/feature/base.rb +++ b/lib/puppet/feature/base.rb @@ -2,6 +2,34 @@ require 'puppet/util/feature' # Add the simple features, all in one file. +# Order is important as some features depend on others + +# We have a syslog implementation +Puppet.features.add(:syslog, :libs => ["syslog"]) + +# We can use POSIX user functions +Puppet.features.add(:posix) do + require 'etc' + Etc.getpwuid(0) != nil && Puppet.features.syslog? +end + +# We can use Microsoft Windows functions +Puppet.features.add(:microsoft_windows) do + begin + require 'sys/admin' + require 'win32/process' + require 'win32/dir' + require 'win32/service' + require 'win32ole' + require 'win32/api' + true + rescue LoadError => err + warn "Cannot run on Microsoft Windows without the sys-admin, win32-process, win32-dir & win32-service gems: #{err}" unless Puppet.features.posix? + end +end + +raise Puppet::Error,"Cannot determine basic system flavour" unless Puppet.features.posix? or Puppet.features.microsoft_windows? + # We've got LDAP available. Puppet.features.add(:ldap, :libs => ["ldap"]) @@ -30,32 +58,6 @@ Puppet.features.add(:rrd, :libs => ["RRD"]) # We have OpenSSL Puppet.features.add(:openssl, :libs => ["openssl"]) -# We have a syslog implementation -Puppet.features.add(:syslog, :libs => ["syslog"]) - -# We can use POSIX user functions -Puppet.features.add(:posix) do - require 'etc' - Etc.getpwuid(0) != nil && Puppet.features.syslog? -end - -# We can use Microsoft Windows functions -Puppet.features.add(:microsoft_windows) do - begin - require 'sys/admin' - require 'win32/process' - require 'win32/dir' - require 'win32/service' - require 'win32ole' - require 'win32/api' - true - rescue LoadError => err - warn "Cannot run on Microsoft Windows without the sys-admin, win32-process, win32-dir & win32-service gems: #{err}" unless Puppet.features.posix? - end -end - -raise Puppet::Error,"Cannot determine basic system flavour" unless Puppet.features.posix? or Puppet.features.microsoft_windows? - # We have CouchDB Puppet.features.add(:couchdb, :libs => ["couchrest"]) -- cgit