madscience 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.madscience_gem_location +0 -0
- data/Cheffile +9 -0
- data/Cheffile.lock +34 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +9 -0
- data/README.md +126 -0
- data/Rakefile +1 -0
- data/TODO +17 -0
- data/bin/madscience +90 -0
- data/cookbooks/apt/CHANGELOG.md +183 -0
- data/cookbooks/apt/README.md +255 -0
- data/cookbooks/apt/attributes/default.rb +29 -0
- data/cookbooks/apt/files/default/apt-proxy-v2.conf +50 -0
- data/cookbooks/apt/libraries/helpers.rb +49 -0
- data/cookbooks/apt/libraries/matchers.rb +17 -0
- data/cookbooks/apt/libraries/network.rb +31 -0
- data/cookbooks/apt/metadata.json +54 -0
- data/cookbooks/apt/metadata.rb +34 -0
- data/cookbooks/apt/providers/preference.rb +63 -0
- data/cookbooks/apt/providers/repository.rb +150 -0
- data/cookbooks/apt/recipes/cacher-client.rb +81 -0
- data/cookbooks/apt/recipes/cacher-ng.rb +43 -0
- data/cookbooks/apt/recipes/default.rb +91 -0
- data/cookbooks/apt/resources/preference.rb +32 -0
- data/cookbooks/apt/resources/repository.rb +43 -0
- data/cookbooks/apt/templates/debian-6.0/acng.conf.erb +173 -0
- data/cookbooks/apt/templates/default/01proxy.erb +5 -0
- data/cookbooks/apt/templates/default/acng.conf.erb +275 -0
- data/cookbooks/apt/templates/ubuntu-10.04/acng.conf.erb +269 -0
- data/cookbooks/chef_handler/CHANGELOG.md +44 -0
- data/cookbooks/chef_handler/README.md +103 -0
- data/cookbooks/chef_handler/attributes/default.rb +30 -0
- data/cookbooks/chef_handler/files/default/handlers/README +1 -0
- data/cookbooks/chef_handler/libraries/matchers.rb +29 -0
- data/cookbooks/chef_handler/metadata.json +29 -0
- data/cookbooks/chef_handler/metadata.rb +7 -0
- data/cookbooks/chef_handler/providers/default.rb +97 -0
- data/cookbooks/chef_handler/recipes/default.rb +33 -0
- data/cookbooks/chef_handler/recipes/json_file.rb +28 -0
- data/cookbooks/chef_handler/resources/default.rb +34 -0
- data/cookbooks/dmg/CHANGELOG.md +75 -0
- data/cookbooks/dmg/README.md +143 -0
- data/cookbooks/dmg/attributes/default.rb +20 -0
- data/cookbooks/dmg/metadata.json +30 -0
- data/cookbooks/dmg/metadata.rb +9 -0
- data/cookbooks/dmg/providers/package.rb +91 -0
- data/cookbooks/dmg/recipes/default.rb +18 -0
- data/cookbooks/dmg/resources/package.rb +37 -0
- data/cookbooks/vagrant/Berksfile +2 -0
- data/cookbooks/vagrant/CHANGELOG.md +7 -0
- data/cookbooks/vagrant/README.md +146 -0
- data/cookbooks/vagrant/TESTING.md +25 -0
- data/cookbooks/vagrant/attributes/default.rb +22 -0
- data/cookbooks/vagrant/metadata.rb +14 -0
- data/cookbooks/vagrant/providers/plugin.rb +50 -0
- data/cookbooks/vagrant/recipes/debian.rb +9 -0
- data/cookbooks/vagrant/recipes/default.rb +34 -0
- data/cookbooks/vagrant/recipes/fedora.rb +1 -0
- data/cookbooks/vagrant/recipes/mac_os_x.rb +7 -0
- data/cookbooks/vagrant/recipes/rhel.rb +9 -0
- data/cookbooks/vagrant/recipes/uninstall_gem.rb +7 -0
- data/cookbooks/vagrant/recipes/windows.rb +5 -0
- data/cookbooks/vagrant/resources/plugin.rb +8 -0
- data/cookbooks/virtualbox/README.md +167 -0
- data/cookbooks/virtualbox/attributes/default.rb +32 -0
- data/cookbooks/virtualbox/attributes/user.rb +22 -0
- data/cookbooks/virtualbox/attributes/webportal.rb +22 -0
- data/cookbooks/virtualbox/attributes/webservice.rb +24 -0
- data/cookbooks/virtualbox/files/ubuntu/machines_enabled +1 -0
- data/cookbooks/virtualbox/files/ubuntu/vboxcontrol +104 -0
- data/cookbooks/virtualbox/libraries/helpers.rb +30 -0
- data/cookbooks/virtualbox/metadata.rb +16 -0
- data/cookbooks/virtualbox/recipes/default.rb +70 -0
- data/cookbooks/virtualbox/recipes/systemservice.rb +56 -0
- data/cookbooks/virtualbox/recipes/user.rb +39 -0
- data/cookbooks/virtualbox/recipes/webportal.rb +58 -0
- data/cookbooks/virtualbox/recipes/webservice.rb +44 -0
- data/cookbooks/virtualbox/templates/ubuntu/config.erb +3 -0
- data/cookbooks/virtualbox/templates/ubuntu/config.php.erb +183 -0
- data/cookbooks/virtualbox/templates/ubuntu/vbox.cfg.erb +51 -0
- data/cookbooks/windows/CHANGELOG.md +268 -0
- data/cookbooks/windows/README.md +665 -0
- data/cookbooks/windows/attributes/default.rb +23 -0
- data/cookbooks/windows/files/default/handlers/windows_reboot_handler.rb +76 -0
- data/cookbooks/windows/libraries/feature_base.rb +59 -0
- data/cookbooks/windows/libraries/matchers.rb +450 -0
- data/cookbooks/windows/libraries/powershell_helper.rb +59 -0
- data/cookbooks/windows/libraries/powershell_out.rb +79 -0
- data/cookbooks/windows/libraries/registry_helper.rb +357 -0
- data/cookbooks/windows/libraries/version.rb +206 -0
- data/cookbooks/windows/libraries/windows_architecture_helper.rb +86 -0
- data/cookbooks/windows/libraries/windows_helper.rb +88 -0
- data/cookbooks/windows/libraries/windows_privileged.rb +94 -0
- data/cookbooks/windows/metadata.json +31 -0
- data/cookbooks/windows/metadata.rb +9 -0
- data/cookbooks/windows/providers/auto_run.rb +32 -0
- data/cookbooks/windows/providers/batch.rb +62 -0
- data/cookbooks/windows/providers/feature_dism.rb +64 -0
- data/cookbooks/windows/providers/feature_powershell.rb +38 -0
- data/cookbooks/windows/providers/feature_servermanagercmd.rb +47 -0
- data/cookbooks/windows/providers/package.rb +252 -0
- data/cookbooks/windows/providers/pagefile.rb +153 -0
- data/cookbooks/windows/providers/path.rb +35 -0
- data/cookbooks/windows/providers/printer.rb +100 -0
- data/cookbooks/windows/providers/printer_port.rb +102 -0
- data/cookbooks/windows/providers/reboot.rb +31 -0
- data/cookbooks/windows/providers/registry.rb +72 -0
- data/cookbooks/windows/providers/shortcut.rb +56 -0
- data/cookbooks/windows/providers/task.rb +128 -0
- data/cookbooks/windows/providers/zipfile.rb +91 -0
- data/cookbooks/windows/recipes/default.rb +34 -0
- data/cookbooks/windows/recipes/reboot_handler.rb +32 -0
- data/cookbooks/windows/resources/auto_run.rb +30 -0
- data/cookbooks/windows/resources/batch.rb +36 -0
- data/cookbooks/windows/resources/feature.rb +44 -0
- data/cookbooks/windows/resources/package.rb +46 -0
- data/cookbooks/windows/resources/pagefile.rb +29 -0
- data/cookbooks/windows/resources/path.rb +28 -0
- data/cookbooks/windows/resources/printer.rb +41 -0
- data/cookbooks/windows/resources/printer_port.rb +40 -0
- data/cookbooks/windows/resources/reboot.rb +29 -0
- data/cookbooks/windows/resources/registry.rb +34 -0
- data/cookbooks/windows/resources/shortcut.rb +35 -0
- data/cookbooks/windows/resources/task.rb +50 -0
- data/cookbooks/windows/resources/zipfile.rb +33 -0
- data/cookbooks/yum/CHANGELOG.md +212 -0
- data/cookbooks/yum/README.md +268 -0
- data/cookbooks/yum/attributes/main.rb +97 -0
- data/cookbooks/yum/libraries/matchers.rb +27 -0
- data/cookbooks/yum/metadata.json +34 -0
- data/cookbooks/yum/metadata.rb +13 -0
- data/cookbooks/yum/providers/globalconfig.rb +37 -0
- data/cookbooks/yum/providers/repository.rb +85 -0
- data/cookbooks/yum/recipes/default.rb +34 -0
- data/cookbooks/yum/resources/globalconfig.rb +105 -0
- data/cookbooks/yum/resources/repository.rb +63 -0
- data/cookbooks/yum/templates/default/main.erb +251 -0
- data/cookbooks/yum/templates/default/repo.erb +109 -0
- data/lib/madscience/version.rb +3 -0
- data/lib/madscience.rb +5 -0
- data/madscience.gemspec +44 -0
- data/new_gem_version.rb +6 -0
- data/node-data.json +3 -0
- data/site-cookbooks/madscience-vagrant-cookbook/CHANGELOG.md +13 -0
- data/site-cookbooks/madscience-vagrant-cookbook/README.md +53 -0
- data/site-cookbooks/madscience-vagrant-cookbook/metadata.rb +17 -0
- data/site-cookbooks/madscience-vagrant-cookbook/recipes/default.rb +87 -0
- data/solo.rb +6 -0
- metadata +337 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
class Chef
|
|
2
|
+
module Mixin
|
|
3
|
+
module PowershellOut
|
|
4
|
+
include Chef::Mixin::ShellOut
|
|
5
|
+
|
|
6
|
+
begin
|
|
7
|
+
include Chef::Mixin::WindowsArchitectureHelper
|
|
8
|
+
rescue
|
|
9
|
+
# nothing to do, as the include will happen when windows_architecture_helper.rb
|
|
10
|
+
# is loaded. This is for ease of removal of that library when either
|
|
11
|
+
# powershell_out is core chef or powershell cookbook depends upon version
|
|
12
|
+
# of chef that has Chef::Mixin::WindowsArchitectureHelper in core chef
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def powershell_out(*command_args)
|
|
16
|
+
script = command_args.first
|
|
17
|
+
options = command_args.last.is_a?(Hash) ? command_args.last : nil
|
|
18
|
+
|
|
19
|
+
run_command(script, options)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def powershell_out!(*command_args)
|
|
23
|
+
cmd = powershell_out(*command_args)
|
|
24
|
+
cmd.error!
|
|
25
|
+
cmd
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
def run_command(script, options)
|
|
30
|
+
if options && options[:architecture]
|
|
31
|
+
architecture = options[:architecture]
|
|
32
|
+
options.delete(:architecture)
|
|
33
|
+
else
|
|
34
|
+
architecture = node_windows_architecture(node)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
disable_redirection = wow64_architecture_override_required?(node, architecture)
|
|
38
|
+
|
|
39
|
+
if disable_redirection
|
|
40
|
+
original_redirection_state = disable_wow64_file_redirection(node)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
command = build_command(script)
|
|
44
|
+
|
|
45
|
+
if options
|
|
46
|
+
cmd = shell_out(command, options)
|
|
47
|
+
else
|
|
48
|
+
cmd = shell_out(command)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
if disable_redirection
|
|
52
|
+
restore_wow64_file_redirection(node, original_redirection_state)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
cmd
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def build_command(script)
|
|
59
|
+
flags = [
|
|
60
|
+
# Hides the copyright banner at startup.
|
|
61
|
+
"-NoLogo",
|
|
62
|
+
# Does not present an interactive prompt to the user.
|
|
63
|
+
"-NonInteractive",
|
|
64
|
+
# Does not load the Windows PowerShell profile.
|
|
65
|
+
"-NoProfile",
|
|
66
|
+
# always set the ExecutionPolicy flag
|
|
67
|
+
# see http://technet.microsoft.com/en-us/library/ee176961.aspx
|
|
68
|
+
"-ExecutionPolicy RemoteSigned",
|
|
69
|
+
# Powershell will hang if STDIN is redirected
|
|
70
|
+
# http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected
|
|
71
|
+
"-InputFormat None"
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
command = "powershell.exe #{flags.join(' ')} -Command \"#{script}\""
|
|
75
|
+
command
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Doug MacEachern (<dougm@vmware.com>)
|
|
3
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
|
4
|
+
# Author:: Paul Morton (<pmorton@biaprotect.com>)
|
|
5
|
+
# Cookbook Name:: windows
|
|
6
|
+
# Provider:: registry
|
|
7
|
+
#
|
|
8
|
+
# Copyright:: 2010, VMware, Inc.
|
|
9
|
+
# Copyright:: 2011, Opscode, Inc.
|
|
10
|
+
# Copyright:: 2011, Business Intelligence Associates, Inc
|
|
11
|
+
#
|
|
12
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
# you may not use this file except in compliance with the License.
|
|
14
|
+
# You may obtain a copy of the License at
|
|
15
|
+
#
|
|
16
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
#
|
|
18
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
# See the License for the specific language governing permissions and
|
|
22
|
+
# limitations under the License.
|
|
23
|
+
#
|
|
24
|
+
|
|
25
|
+
if RUBY_PLATFORM =~ /mswin|mingw32|windows/
|
|
26
|
+
require 'win32/registry'
|
|
27
|
+
require 'ruby-wmi'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
module Windows
|
|
31
|
+
module RegistryHelper
|
|
32
|
+
|
|
33
|
+
@@native_registry_constant = ENV['PROCESSOR_ARCHITEW6432'] == 'AMD64' ? 0x0100 : 0x0200
|
|
34
|
+
|
|
35
|
+
def get_hive_name(path)
|
|
36
|
+
Chef::Log.debug("Resolving registry shortcuts to full names")
|
|
37
|
+
|
|
38
|
+
reg_path = path.split("\\")
|
|
39
|
+
hive_name = reg_path.shift
|
|
40
|
+
|
|
41
|
+
hkey = {
|
|
42
|
+
"HKLM" => "HKEY_LOCAL_MACHINE",
|
|
43
|
+
"HKCU" => "HKEY_CURRENT_USER",
|
|
44
|
+
"HKU" => "HKEY_USERS"
|
|
45
|
+
}[hive_name] || hive_name
|
|
46
|
+
|
|
47
|
+
Chef::Log.debug("Hive resolved to #{hkey}")
|
|
48
|
+
return hkey
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def get_hive(path)
|
|
52
|
+
|
|
53
|
+
Chef::Log.debug("Getting hive for #{path}")
|
|
54
|
+
reg_path = path.split("\\")
|
|
55
|
+
hive_name = reg_path.shift
|
|
56
|
+
|
|
57
|
+
hkey = get_hive_name(path)
|
|
58
|
+
|
|
59
|
+
hive = {
|
|
60
|
+
"HKEY_LOCAL_MACHINE" => ::Win32::Registry::HKEY_LOCAL_MACHINE,
|
|
61
|
+
"HKEY_USERS" => ::Win32::Registry::HKEY_USERS,
|
|
62
|
+
"HKEY_CURRENT_USER" => ::Win32::Registry::HKEY_CURRENT_USER
|
|
63
|
+
}[hkey]
|
|
64
|
+
|
|
65
|
+
unless hive
|
|
66
|
+
Chef::Application.fatal!("Unsupported registry hive '#{hive_name}'")
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
Chef::Log.debug("Registry hive resolved to #{hkey}")
|
|
71
|
+
return hive
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def unload_hive(path)
|
|
75
|
+
hive = get_hive(path)
|
|
76
|
+
if hive == ::Win32::Registry::HKEY_USERS
|
|
77
|
+
reg_path = path.split("\\")
|
|
78
|
+
priv = Chef::WindowsPrivileged.new
|
|
79
|
+
begin
|
|
80
|
+
priv.reg_unload_key(reg_path[1])
|
|
81
|
+
rescue
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def set_value(mode,path,values,type=nil)
|
|
87
|
+
hive, reg_path, hive_name, root_key, hive_loaded = get_reg_path_info(path)
|
|
88
|
+
key_name = reg_path.join("\\")
|
|
89
|
+
|
|
90
|
+
Chef::Log.debug("Creating #{path}")
|
|
91
|
+
|
|
92
|
+
if !key_exists?(path,true)
|
|
93
|
+
create_key(path)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
hive.send(mode, key_name, ::Win32::Registry::KEY_ALL_ACCESS | @@native_registry_constant) do |reg|
|
|
97
|
+
changed_something = false
|
|
98
|
+
values.each do |k,val|
|
|
99
|
+
key = k.to_s #wtf. avoid "can't modify frozen string" in win32/registry.rb
|
|
100
|
+
cur_val = nil
|
|
101
|
+
begin
|
|
102
|
+
cur_val = reg[key]
|
|
103
|
+
rescue
|
|
104
|
+
#subkey does not exist (ok)
|
|
105
|
+
end
|
|
106
|
+
if cur_val != val
|
|
107
|
+
Chef::Log.debug("setting #{key}=#{val}")
|
|
108
|
+
|
|
109
|
+
if type.nil?
|
|
110
|
+
type = :string
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
reg_type = {
|
|
114
|
+
:binary => ::Win32::Registry::REG_BINARY,
|
|
115
|
+
:string => ::Win32::Registry::REG_SZ,
|
|
116
|
+
:multi_string => ::Win32::Registry::REG_MULTI_SZ,
|
|
117
|
+
:expand_string => ::Win32::Registry::REG_EXPAND_SZ,
|
|
118
|
+
:dword => ::Win32::Registry::REG_DWORD,
|
|
119
|
+
:dword_big_endian => ::Win32::Registry::REG_DWORD_BIG_ENDIAN,
|
|
120
|
+
:qword => ::Win32::Registry::REG_QWORD
|
|
121
|
+
}[type]
|
|
122
|
+
|
|
123
|
+
reg.write(key, reg_type, val)
|
|
124
|
+
|
|
125
|
+
ensure_hive_unloaded(hive_loaded)
|
|
126
|
+
|
|
127
|
+
changed_something = true
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
return changed_something
|
|
131
|
+
end
|
|
132
|
+
return false
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def get_value(path,value)
|
|
136
|
+
hive, reg_path, hive_name, root_key, hive_loaded = get_reg_path_info(path)
|
|
137
|
+
key = reg_path.join("\\")
|
|
138
|
+
|
|
139
|
+
hive.open(key, ::Win32::Registry::KEY_ALL_ACCESS | @@native_registry_constant) do | reg |
|
|
140
|
+
begin
|
|
141
|
+
return reg[value]
|
|
142
|
+
rescue
|
|
143
|
+
return nil
|
|
144
|
+
ensure
|
|
145
|
+
ensure_hive_unloaded(hive_loaded)
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def get_values(path)
|
|
151
|
+
hive, reg_path, hive_name, root_key, hive_loaded = get_reg_path_info(path)
|
|
152
|
+
key = reg_path.join("\\")
|
|
153
|
+
hive.open(key, ::Win32::Registry::KEY_ALL_ACCESS | @@native_registry_constant) do | reg |
|
|
154
|
+
values = []
|
|
155
|
+
begin
|
|
156
|
+
reg.each_value do |name, type, data|
|
|
157
|
+
values << [name, type, data]
|
|
158
|
+
end
|
|
159
|
+
rescue
|
|
160
|
+
ensure
|
|
161
|
+
ensure_hive_unloaded(hive_loaded)
|
|
162
|
+
end
|
|
163
|
+
values
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def delete_value(path,values)
|
|
168
|
+
hive, reg_path, hive_name, root_key, hive_loaded = get_reg_path_info(path)
|
|
169
|
+
key = reg_path.join("\\")
|
|
170
|
+
Chef::Log.debug("Deleting values in #{path}")
|
|
171
|
+
hive.open(key, ::Win32::Registry::KEY_ALL_ACCESS | @@native_registry_constant) do | reg |
|
|
172
|
+
values.each_key { |key|
|
|
173
|
+
name = key.to_s
|
|
174
|
+
# Ensure delete operation is idempotent.
|
|
175
|
+
if value_exists?(path, key)
|
|
176
|
+
Chef::Log.debug("Deleting value #{name} in #{path}")
|
|
177
|
+
reg.delete_value(name)
|
|
178
|
+
else
|
|
179
|
+
Chef::Log.debug("Value #{name} in #{path} does not exist, skipping.")
|
|
180
|
+
end
|
|
181
|
+
}
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def create_key(path)
|
|
187
|
+
hive, reg_path, hive_name, root_key, hive_loaded = get_reg_path_info(path)
|
|
188
|
+
key = reg_path.join("\\")
|
|
189
|
+
Chef::Log.debug("Creating registry key #{path}")
|
|
190
|
+
hive.create(key)
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def value_exists?(path,value)
|
|
194
|
+
if key_exists?(path,true)
|
|
195
|
+
|
|
196
|
+
hive, reg_path, hive_name, root_key , hive_loaded = get_reg_path_info(path)
|
|
197
|
+
key = reg_path.join("\\")
|
|
198
|
+
|
|
199
|
+
Chef::Log.debug("Attempting to open #{key}");
|
|
200
|
+
Chef::Log.debug("Native Constant #{@@native_registry_constant}")
|
|
201
|
+
Chef::Log.debug("Hive #{hive}")
|
|
202
|
+
|
|
203
|
+
hive.open(key, ::Win32::Registry::KEY_READ | @@native_registry_constant) do | reg |
|
|
204
|
+
begin
|
|
205
|
+
rtn_value = reg[value]
|
|
206
|
+
return true
|
|
207
|
+
rescue
|
|
208
|
+
return false
|
|
209
|
+
ensure
|
|
210
|
+
ensure_hive_unloaded(hive_loaded)
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
end
|
|
215
|
+
return false
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# TODO: Does not load user registry...
|
|
219
|
+
def key_exists?(path, load_hive = false)
|
|
220
|
+
if load_hive
|
|
221
|
+
hive, reg_path, hive_name, root_key , hive_loaded = get_reg_path_info(path)
|
|
222
|
+
key = reg_path.join("\\")
|
|
223
|
+
else
|
|
224
|
+
hive = get_hive(path)
|
|
225
|
+
reg_path = path.split("\\")
|
|
226
|
+
hive_name = reg_path.shift
|
|
227
|
+
root_key = reg_path[0]
|
|
228
|
+
key = reg_path.join("\\")
|
|
229
|
+
hive_loaded = false
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
begin
|
|
233
|
+
hive.open(key, ::Win32::Registry::Constants::KEY_READ | @@native_registry_constant )
|
|
234
|
+
return true
|
|
235
|
+
rescue
|
|
236
|
+
return false
|
|
237
|
+
ensure
|
|
238
|
+
ensure_hive_unloaded(hive_loaded)
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def get_user_hive_location(sid)
|
|
243
|
+
reg_key = "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\#{sid}"
|
|
244
|
+
Chef::Log.debug("Looking for profile at #{reg_key}")
|
|
245
|
+
if key_exists?(reg_key)
|
|
246
|
+
return get_value(reg_key,'ProfileImagePath')
|
|
247
|
+
else
|
|
248
|
+
return nil
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def resolve_user_to_sid(username)
|
|
254
|
+
begin
|
|
255
|
+
sid = WMI::Win32_UserAccount.find(:first, :conditions => {:name => username}).sid
|
|
256
|
+
Chef::Log.debug("Resolved user SID to #{sid}")
|
|
257
|
+
return sid
|
|
258
|
+
rescue
|
|
259
|
+
return nil
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def hive_loaded?(path)
|
|
264
|
+
hive = get_hive(path)
|
|
265
|
+
reg_path = path.split("\\")
|
|
266
|
+
hive_name = reg_path.shift
|
|
267
|
+
user_hive = path[0]
|
|
268
|
+
|
|
269
|
+
if is_user_hive?(hive)
|
|
270
|
+
return key_exists?("#{hive_name}\\#{user_hive}")
|
|
271
|
+
else
|
|
272
|
+
return true
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
def is_user_hive?(hive)
|
|
277
|
+
if hive == ::Win32::Registry::HKEY_USERS
|
|
278
|
+
return true
|
|
279
|
+
else
|
|
280
|
+
return true
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def get_reg_path_info(path)
|
|
285
|
+
hive = get_hive(path)
|
|
286
|
+
reg_path = path.split("\\")
|
|
287
|
+
hive_name = reg_path.shift
|
|
288
|
+
root_key = reg_path[0]
|
|
289
|
+
hive_loaded = false
|
|
290
|
+
|
|
291
|
+
if is_user_hive?(hive) && !key_exists?("#{hive_name}\\#{root_key}")
|
|
292
|
+
reg_path, hive_loaded = load_user_hive(hive,reg_path,root_key)
|
|
293
|
+
root_key = reg_path[0]
|
|
294
|
+
Chef::Log.debug("Resolved user (#{path}) to (#{reg_path.join('/')})")
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
return hive, reg_path, hive_name, root_key, hive_loaded
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def load_user_hive(hive,reg_path,user_hive)
|
|
301
|
+
Chef::Log.debug("Reg Path #{reg_path}")
|
|
302
|
+
# See if the hive is loaded. Logged in users will have a key that is named their SID
|
|
303
|
+
# if the user has specified the a path by SID and the user is logged in, this function
|
|
304
|
+
# should not be executed.
|
|
305
|
+
if is_user_hive?(hive) && !key_exists?("HKU\\#{user_hive}")
|
|
306
|
+
Chef::Log.debug("The user is not logged in and has not been specified by SID")
|
|
307
|
+
sid = resolve_user_to_sid(user_hive)
|
|
308
|
+
Chef::Log.debug("User SID resolved to (#{sid})")
|
|
309
|
+
# Now that the user has been resolved to a SID, check and see if the hive exists.
|
|
310
|
+
# If this exists by SID, the user is logged in and we should use that key.
|
|
311
|
+
# TODO: Replace the username with the sid and send it back because the username
|
|
312
|
+
# does not exist as the key location.
|
|
313
|
+
load_reg = false
|
|
314
|
+
if key_exists?("HKU\\#{sid}")
|
|
315
|
+
reg_path[0] = sid #use the active profile (user is logged on)
|
|
316
|
+
Chef::Log.debug("HKEY_USERS Mapped: #{user_hive} -> #{sid}")
|
|
317
|
+
else
|
|
318
|
+
Chef::Log.debug("User is not logged in")
|
|
319
|
+
load_reg = true
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# The user is not logged in, so we should load the registry from disk
|
|
323
|
+
if load_reg
|
|
324
|
+
profile_path = get_user_hive_location(sid)
|
|
325
|
+
if profile_path != nil
|
|
326
|
+
ntuser_dat = "#{profile_path}\\NTUSER.DAT"
|
|
327
|
+
if ::File.exists?(ntuser_dat)
|
|
328
|
+
priv = Chef::WindowsPrivileged.new
|
|
329
|
+
if priv.reg_load_key(sid,ntuser_dat)
|
|
330
|
+
Chef::Log.debug("RegLoadKey(#{sid}, #{user_hive}, #{ntuser_dat})")
|
|
331
|
+
reg_path[0] = sid
|
|
332
|
+
else
|
|
333
|
+
Chef::Log.debug("Failed RegLoadKey(#{sid}, #{user_hive}, #{ntuser_dat})")
|
|
334
|
+
end
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
end
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
return reg_path, load_reg
|
|
341
|
+
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
private
|
|
345
|
+
def ensure_hive_unloaded(hive_loaded=false)
|
|
346
|
+
if(hive_loaded)
|
|
347
|
+
Chef::Log.debug("Hive was loaded, we really should unload it")
|
|
348
|
+
unload_hive(path)
|
|
349
|
+
end
|
|
350
|
+
end
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
module Registry
|
|
355
|
+
module_function
|
|
356
|
+
extend Windows::RegistryHelper
|
|
357
|
+
end
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
|
3
|
+
# Cookbook Name:: windows
|
|
4
|
+
# Library:: version
|
|
5
|
+
#
|
|
6
|
+
# Copyright:: 2011, Opscode, Inc.
|
|
7
|
+
#
|
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
# you may not use this file except in compliance with the License.
|
|
10
|
+
# You may obtain a copy of the License at
|
|
11
|
+
#
|
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
#
|
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
# See the License for the specific language governing permissions and
|
|
18
|
+
# limitations under the License.
|
|
19
|
+
#
|
|
20
|
+
|
|
21
|
+
if RUBY_PLATFORM =~ /mswin|mingw32|windows/
|
|
22
|
+
require 'ruby-wmi'
|
|
23
|
+
require 'Win32API'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
module Windows
|
|
27
|
+
class Version
|
|
28
|
+
|
|
29
|
+
# http://msdn.microsoft.com/en-us/library/ms724833(v=vs.85).aspx
|
|
30
|
+
|
|
31
|
+
# Suite Masks
|
|
32
|
+
# Microsoft BackOffice components are installed.
|
|
33
|
+
VER_SUITE_BACKOFFICE = 0x00000004.freeze unless defined?(VER_SUITE_BACKOFFICE)
|
|
34
|
+
# Windows Server 2003, Web Edition is installed.
|
|
35
|
+
VER_SUITE_BLADE = 0x00000400.freeze unless defined?(VER_SUITE_BLADE)
|
|
36
|
+
# Windows Server 2003, Compute Cluster Edition is installed.
|
|
37
|
+
VER_SUITE_COMPUTE_SERVER = 0x00004000.freeze unless defined?(VER_SUITE_COMPUTE_SERVER)
|
|
38
|
+
# Windows Server 2008 Datacenter, Windows Server 2003, Datacenter Edition, or Windows 2000 Datacenter Server is installed.
|
|
39
|
+
VER_SUITE_DATACENTER = 0x00000080.freeze unless defined?(VER_SUITE_DATACENTER)
|
|
40
|
+
# Windows Server 2008 Enterprise, Windows Server 2003, Enterprise Edition, or Windows 2000 Advanced Server is installed. Refer to the Remarks section for more information about this bit flag.
|
|
41
|
+
VER_SUITE_ENTERPRISE = 0x00000002.freeze unless defined?(VER_SUITE_ENTERPRISE)
|
|
42
|
+
# Windows XP Embedded is installed.
|
|
43
|
+
VER_SUITE_EMBEDDEDNT = 0x00000040.freeze unless defined?(VER_SUITE_EMBEDDEDNT)
|
|
44
|
+
# Windows Vista Home Premium, Windows Vista Home Basic, or Windows XP Home Edition is installed.
|
|
45
|
+
VER_SUITE_PERSONAL = 0x00000200.freeze unless defined?(VER_SUITE_PERSONAL)
|
|
46
|
+
# Remote Desktop is supported, but only one interactive session is supported. This value is set unless the system is running in application server mode.
|
|
47
|
+
VER_SUITE_SINGLEUSERTS = 0x00000100.freeze unless defined?(VER_SUITE_SINGLEUSERTS)
|
|
48
|
+
# Microsoft Small Business Server was once installed on the system, but may have been upgraded to another version of Windows. Refer to the Remarks section for more information about this bit flag.
|
|
49
|
+
VER_SUITE_SMALLBUSINESS = 0x00000001.freeze unless defined?(VER_SUITE_SMALLBUSINESS)
|
|
50
|
+
# Microsoft Small Business Server is installed with the restrictive client license in force. Refer to the Remarks section for more information about this bit flag.
|
|
51
|
+
VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020.freeze unless defined?(VER_SUITE_SMALLBUSINESS_RESTRICTED)
|
|
52
|
+
# Windows Storage Server 2003 R2 or Windows Storage Server 2003is installed.
|
|
53
|
+
VER_SUITE_STORAGE_SERVER = 0x00002000.freeze unless defined?(VER_SUITE_STORAGE_SERVER)
|
|
54
|
+
# Terminal Services is installed. This value is always set.
|
|
55
|
+
# If VER_SUITE_TERMINAL is set but VER_SUITE_SINGLEUSERTS is not set, the system is running in application server mode.
|
|
56
|
+
VER_SUITE_TERMINAL = 0x00000010.freeze unless defined?(VER_SUITE_TERMINAL)
|
|
57
|
+
# Windows Home Server is installed.
|
|
58
|
+
VER_SUITE_WH_SERVER = 0x00008000.freeze unless defined?(VER_SUITE_WH_SERVER)
|
|
59
|
+
|
|
60
|
+
# Product Type
|
|
61
|
+
# The system is a domain controller and the operating system is Windows Server 2012, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
|
|
62
|
+
VER_NT_DOMAIN_CONTROLLER = 0x0000002.freeze unless defined?(VER_NT_DOMAIN_CONTROLLER)
|
|
63
|
+
# The operating system is Windows Server 2012, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
|
|
64
|
+
# Note that a server that is also a domain controller is reported as VER_NT_DOMAIN_CONTROLLER, not VER_NT_SERVER.
|
|
65
|
+
VER_NT_SERVER = 0x0000003.freeze unless defined?(VER_NT_SERVER)
|
|
66
|
+
# The operating system is Windows 7, Windows Vista, Windows XP Professional, Windows XP Home Edition, or Windows 2000 Professional.
|
|
67
|
+
VER_NT_WORKSTATION = 0x0000001.freeze unless defined?(VER_NT_WORKSTATION)
|
|
68
|
+
|
|
69
|
+
# GetSystemMetrics
|
|
70
|
+
# The build number if the system is Windows Server 2003 R2; otherwise, 0.
|
|
71
|
+
SM_SERVERR2 = 89.freeze unless defined?(SM_SERVERR2)
|
|
72
|
+
|
|
73
|
+
# http://msdn.microsoft.com/en-us/library/ms724358(v=vs.85).aspx
|
|
74
|
+
SKU = {
|
|
75
|
+
0x00000006 => {:ms_const => 'PRODUCT_BUSINESS', :name => 'Business'},
|
|
76
|
+
0x00000010 => {:ms_const => 'PRODUCT_BUSINESS_N', :name => 'Business N'},
|
|
77
|
+
0x00000012 => {:ms_const => 'PRODUCT_CLUSTER_SERVER', :name => 'HPC Edition'},
|
|
78
|
+
0x00000008 => {:ms_const => 'PRODUCT_DATACENTER_SERVER', :name => 'Server Datacenter (full installation)'},
|
|
79
|
+
0x0000000C => {:ms_const => 'PRODUCT_DATACENTER_SERVER_CORE', :name => 'Server Datacenter (core installation)'},
|
|
80
|
+
0x00000027 => {:ms_const => 'PRODUCT_DATACENTER_SERVER_CORE_V', :name => 'Server Datacenter without Hyper-V (core installation)'},
|
|
81
|
+
0x00000025 => {:ms_const => 'PRODUCT_DATACENTER_SERVER_V', :name => 'Server Datacenter without Hyper-V (full installation)'},
|
|
82
|
+
0x00000004 => {:ms_const => 'PRODUCT_ENTERPRISE', :name => 'Enterprise'},
|
|
83
|
+
0x00000046 => {:ms_const => 'PRODUCT_ENTERPRISE_E', :name => 'Not supported'},
|
|
84
|
+
0x0000001B => {:ms_const => 'PRODUCT_ENTERPRISE_N', :name => 'Enterprise N'},
|
|
85
|
+
0x0000000A => {:ms_const => 'PRODUCT_ENTERPRISE_SERVER', :name => 'Server Enterprise (full installation)'},
|
|
86
|
+
0x0000000E => {:ms_const => 'PRODUCT_ENTERPRISE_SERVER_CORE', :name => 'Server Enterprise (core installation)'},
|
|
87
|
+
0x00000029 => {:ms_const => 'PRODUCT_ENTERPRISE_SERVER_CORE_V', :name => 'Server Enterprise without Hyper-V (core installation)'},
|
|
88
|
+
0x0000000F => {:ms_const => 'PRODUCT_ENTERPRISE_SERVER_IA64', :name => 'Server Enterprise for Itanium-based Systems'},
|
|
89
|
+
0x00000026 => {:ms_const => 'PRODUCT_ENTERPRISE_SERVER_V', :name => 'Server Enterprise without Hyper-V (full installation)'},
|
|
90
|
+
0x00000002 => {:ms_const => 'PRODUCT_HOME_BASIC', :name => 'Home Basic'},
|
|
91
|
+
0x00000043 => {:ms_const => 'PRODUCT_HOME_BASIC_E', :name => 'Not supported'},
|
|
92
|
+
0x00000005 => {:ms_const => 'PRODUCT_HOME_BASIC_N', :name => 'Home Basic N'},
|
|
93
|
+
0x00000003 => {:ms_const => 'PRODUCT_HOME_PREMIUM', :name => 'Home Premium'},
|
|
94
|
+
0x00000044 => {:ms_const => 'PRODUCT_HOME_PREMIUM_E', :name => 'Not supported'},
|
|
95
|
+
0x0000001A => {:ms_const => 'PRODUCT_HOME_PREMIUM_N', :name => 'Home Premium N'},
|
|
96
|
+
0x0000002A => {:ms_const => 'PRODUCT_HYPERV', :name => 'Microsoft Hyper-V Server'},
|
|
97
|
+
0x0000001E => {:ms_const => 'PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT', :name => 'Windows Essential Business Server Management Server'},
|
|
98
|
+
0x00000020 => {:ms_const => 'PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING', :name => 'Windows Essential Business Server Messaging Server'},
|
|
99
|
+
0x0000001F => {:ms_const => 'PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY', :name => 'Windows Essential Business Server Security Server'},
|
|
100
|
+
0x00000030 => {:ms_const => 'PRODUCT_PROFESSIONAL', :name => 'Professional'},
|
|
101
|
+
0x00000045 => {:ms_const => 'PRODUCT_PROFESSIONAL_E', :name => 'Not supported'},
|
|
102
|
+
0x00000031 => {:ms_const => 'PRODUCT_PROFESSIONAL_N', :name => 'Professional N'},
|
|
103
|
+
0x00000018 => {:ms_const => 'PRODUCT_SERVER_FOR_SMALLBUSINESS', :name => 'Windows Server 2008 for Windows Essential Server Solutions'},
|
|
104
|
+
0x00000023 => {:ms_const => 'PRODUCT_SERVER_FOR_SMALLBUSINESS_V', :name => 'Windows Server 2008 without Hyper-V for Windows Essential Server Solutions'},
|
|
105
|
+
0x00000021 => {:ms_const => 'PRODUCT_SERVER_FOUNDATION', :name => 'Server Foundation'},
|
|
106
|
+
0x00000022 => {:ms_const => 'PRODUCT_HOME_PREMIUM_SERVER', :name => 'Windows Home Server 2011'},
|
|
107
|
+
0x00000032 => {:ms_const => 'PRODUCT_SB_SOLUTION_SERVER', :name => 'Windows Small Business Server 2011 Essentials'},
|
|
108
|
+
0x00000013 => {:ms_const => 'PRODUCT_HOME_SERVER', :name => 'Windows Storage Server 2008 R2 Essentials'},
|
|
109
|
+
0x00000009 => {:ms_const => 'PRODUCT_SMALLBUSINESS_SERVER', :name => 'Windows Small Business Server'},
|
|
110
|
+
0x00000038 => {:ms_const => 'PRODUCT_SOLUTION_EMBEDDEDSERVER', :name => 'Windows MultiPoint Server'},
|
|
111
|
+
0x00000007 => {:ms_const => 'PRODUCT_STANDARD_SERVER', :name => 'Server Standard (full installation)'},
|
|
112
|
+
0x0000000D => {:ms_const => 'PRODUCT_STANDARD_SERVER_CORE', :name => 'Server Standard (core installation)'},
|
|
113
|
+
0x00000028 => {:ms_const => 'PRODUCT_STANDARD_SERVER_CORE_V', :name => 'Server Standard without Hyper-V (core installation)'},
|
|
114
|
+
0x00000024 => {:ms_const => 'PRODUCT_STANDARD_SERVER_V', :name => 'Server Standard without Hyper-V (full installation)'},
|
|
115
|
+
0x0000000B => {:ms_const => 'PRODUCT_STARTER', :name => 'Starter'},
|
|
116
|
+
0x00000042 => {:ms_const => 'PRODUCT_STARTER_E', :name => 'Not supported'},
|
|
117
|
+
0x0000002F => {:ms_const => 'PRODUCT_STARTER_N', :name => 'Starter N'},
|
|
118
|
+
0x00000017 => {:ms_const => 'PRODUCT_STORAGE_ENTERPRISE_SERVER', :name => 'Storage Server Enterprise'},
|
|
119
|
+
0x00000014 => {:ms_const => 'PRODUCT_STORAGE_EXPRESS_SERVER', :name => 'Storage Server Express'},
|
|
120
|
+
0x00000015 => {:ms_const => 'PRODUCT_STORAGE_STANDARD_SERVER', :name => 'Storage Server Standard'},
|
|
121
|
+
0x00000016 => {:ms_const => 'PRODUCT_STORAGE_WORKGROUP_SERVER', :name => 'Storage Server Workgroup'},
|
|
122
|
+
0x00000000 => {:ms_const => 'PRODUCT_UNDEFINED', :name => 'An unknown product'},
|
|
123
|
+
0x00000001 => {:ms_const => 'PRODUCT_ULTIMATE', :name => 'Ultimate'},
|
|
124
|
+
0x00000047 => {:ms_const => 'PRODUCT_ULTIMATE_E', :name => 'Not supported'},
|
|
125
|
+
0x0000001C => {:ms_const => 'PRODUCT_ULTIMATE_N', :name => 'Ultimate N'},
|
|
126
|
+
0x00000011 => {:ms_const => 'PRODUCT_WEB_SERVER', :name => 'Web Server (full installation)'},
|
|
127
|
+
0x0000001D => {:ms_const => 'PRODUCT_WEB_SERVER_CORE', :name => 'Web Server (core installation)'}
|
|
128
|
+
}.freeze unless defined?(SKU)
|
|
129
|
+
|
|
130
|
+
attr_reader :major_version, :minor_version, :build_number, :service_pack_major_version, :service_pack_minor_version
|
|
131
|
+
attr_reader :version, :product_type, :product_suite, :sku
|
|
132
|
+
|
|
133
|
+
def initialize
|
|
134
|
+
unless RUBY_PLATFORM =~ /mswin|mingw32|windows/
|
|
135
|
+
raise NotImplementedError, 'only valid on Windows platform'
|
|
136
|
+
end
|
|
137
|
+
@version, @product_type, @product_suite, @sku, @service_pack_major_version, @service_pack_minor_version = get_os_info
|
|
138
|
+
@major_version, @minor_version, @build_number = version.split('.').map{|v| v.to_i }
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
WIN_VERSIONS = {
|
|
142
|
+
"Windows Server 2012 R2" => {:major => 6, :minor => 3, :callable => lambda{ @product_type != VER_NT_WORKSTATION }},
|
|
143
|
+
"Windows 8" => {:major => 6, :minor => 2, :callable => lambda{ @product_type == VER_NT_WORKSTATION }},
|
|
144
|
+
"Windows Server 2012" => {:major => 6, :minor => 2, :callable => lambda{ @product_type != VER_NT_WORKSTATION }},
|
|
145
|
+
"Windows 7" => {:major => 6, :minor => 1, :callable => lambda{ @product_type == VER_NT_WORKSTATION }},
|
|
146
|
+
"Windows Server 2008 R2" => {:major => 6, :minor => 1, :callable => lambda{ @product_type != VER_NT_WORKSTATION }},
|
|
147
|
+
"Windows Server 2008" => {:major => 6, :minor => 0, :callable => lambda{ @product_type != VER_NT_WORKSTATION }},
|
|
148
|
+
"Windows Vista" => {:major => 6, :minor => 0, :callable => lambda{ @product_type == VER_NT_WORKSTATION }},
|
|
149
|
+
"Windows Server 2003 R2" => {:major => 5, :minor => 2, :callable => lambda{ Win32API.new('user32', 'GetSystemMetrics', 'I', 'I').call(SM_SERVERR2) != 0 }},
|
|
150
|
+
"Windows Home Server" => {:major => 5, :minor => 2, :callable => lambda{ (@product_suite & VER_SUITE_WH_SERVER) == VER_SUITE_WH_SERVER }},
|
|
151
|
+
"Windows Server 2003" => {:major => 5, :minor => 2, :callable => lambda{ Win32API.new('user32', 'GetSystemMetrics', 'I', 'I').call(SM_SERVERR2) == 0 }},
|
|
152
|
+
"Windows XP" => {:major => 5, :minor => 1},
|
|
153
|
+
"Windows 2000" => {:major => 5, :minor => 0}
|
|
154
|
+
}.freeze unless defined?(WIN_VERSIONS)
|
|
155
|
+
|
|
156
|
+
marketing_names = Array.new
|
|
157
|
+
|
|
158
|
+
# General Windows checks
|
|
159
|
+
WIN_VERSIONS.each do |k,v|
|
|
160
|
+
method_name = "#{k.gsub(/\s/, '_').downcase}?"
|
|
161
|
+
define_method(method_name) do
|
|
162
|
+
(@major_version == v[:major]) &&
|
|
163
|
+
(@minor_version == v[:minor]) &&
|
|
164
|
+
(v[:callable] ? v[:callable].call : true)
|
|
165
|
+
end
|
|
166
|
+
marketing_names << [k, method_name]
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
define_method(:marketing_name) do
|
|
170
|
+
marketing_names.each do |mn|
|
|
171
|
+
break mn[0] if self.send(mn[1])
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# Server Type checks
|
|
176
|
+
%w{ core full datacenter }.each do |m|
|
|
177
|
+
define_method("server_#{m}?") do
|
|
178
|
+
if @sku
|
|
179
|
+
!(SKU[@sku][:name] =~ /#{m}/i).nil?
|
|
180
|
+
else
|
|
181
|
+
false
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
private
|
|
187
|
+
# Win32API call to GetSystemMetrics(SM_SERVERR2)
|
|
188
|
+
# returns: The build number if the system is Windows Server 2003 R2; otherwise, 0.
|
|
189
|
+
def sm_serverr2
|
|
190
|
+
@sm_serverr2 ||= Win32API.new('user32', 'GetSystemMetrics', 'I', 'I').call(SM_SERVERR2)
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# query WMI Win32_OperatingSystem for required OS info
|
|
194
|
+
def get_os_info
|
|
195
|
+
cols = %w{ Version ProductType OSProductSuite OperatingSystemSKU ServicePackMajorVersion ServicePackMinorVersion }
|
|
196
|
+
os_info = WMI::Win32_OperatingSystem.find(:first)
|
|
197
|
+
cols.map do |c|
|
|
198
|
+
begin
|
|
199
|
+
os_info.send(c)
|
|
200
|
+
rescue # OperatingSystemSKU doesn't exist in all versions of Windows
|
|
201
|
+
nil
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|