diff options
Diffstat (limited to 'distro')
25 files changed, 364 insertions, 41 deletions
diff --git a/distro/common/markdown/man1/chef-shell.mkd b/distro/common/markdown/man1/chef-shell.mkd index 5525ef8ea9..216dc73d41 100644 --- a/distro/common/markdown/man1/chef-shell.mkd +++ b/distro/common/markdown/man1/chef-shell.mkd @@ -131,8 +131,8 @@ Recipe mode implements Chef's recipe DSL. Exhaustively documenting this DSL is outside the scope of this document. See the following pages in the Chef documentation for more information: - * <http://wiki.opscode.com/display/chef/Resources> - * <http://wiki.opscode.com/display/chef/Recipes> + * <http://docs.chef.io/resources.html> + * <http://docs.chef.io/recipes.html> Once you have defined resources in the recipe, you can trigger a convergence run via `run_chef` @@ -176,7 +176,7 @@ libraries. ## SEE ALSO chef-client(8) knife(1) - <http://wiki.opscode.com/display/chef/Chef+Shell> + <http://docs.chef.io/ctl_chef_shell.html> ## AUTHOR @@ -192,4 +192,4 @@ libraries. ## CHEF - chef-shell is distributed with Chef. <http://wiki.opscode.com/display/chef/Home> + chef-shell is distributed with Chef. <http://docs.chef.io> diff --git a/distro/common/markdown/man1/knife-bootstrap.mkd b/distro/common/markdown/man1/knife-bootstrap.mkd index cb292de311..a1a2d3460c 100644 --- a/distro/common/markdown/man1/knife-bootstrap.mkd +++ b/distro/common/markdown/man1/knife-bootstrap.mkd @@ -138,4 +138,4 @@ to other users via the process list using tools such as ps(1). ## CHEF - Knife is distributed with Chef. <http://wiki.opscode.com/display/chef/Home> + Knife is distributed with Chef. <http://docs.chef.io> diff --git a/distro/common/markdown/man1/knife-client.mkd b/distro/common/markdown/man1/knife-client.mkd index e7b732ef71..b95a578391 100644 --- a/distro/common/markdown/man1/knife-client.mkd +++ b/distro/common/markdown/man1/knife-client.mkd @@ -99,5 +99,5 @@ setting up a host for management with Chef. Permission is granted to copy, distribute and / or modify this document under the terms of the Apache 2.0 License. ## CHEF - Knife is distributed with Chef. <http://wiki.opscode.com/display/chef/Home> + Knife is distributed with Chef. <http://docs.chef.io> diff --git a/distro/common/markdown/man1/knife-configure.mkd b/distro/common/markdown/man1/knife-configure.mkd index 507d30db4e..f3a4ef02bb 100644 --- a/distro/common/markdown/man1/knife-configure.mkd +++ b/distro/common/markdown/man1/knife-configure.mkd @@ -66,5 +66,5 @@ the specified _directory_. Permission is granted to copy, distribute and / or modify this document under the terms of the Apache 2.0 License. ## CHEF - Knife is distributed with Chef. <http://wiki.opscode.com/display/chef/Home> + Knife is distributed with Chef. <http://docs.chef.io> diff --git a/distro/common/markdown/man1/knife-cookbook-site.mkd b/distro/common/markdown/man1/knife-cookbook-site.mkd index 9496cf1765..68bc8433df 100644 --- a/distro/common/markdown/man1/knife-cookbook-site.mkd +++ b/distro/common/markdown/man1/knife-cookbook-site.mkd @@ -119,5 +119,5 @@ Uploading cookbooks to the Opscode cookbooks site: Permission is granted to copy, distribute and / or modify this document under the terms of the Apache 2.0 License. ## CHEF - Knife is distributed with Chef. <http://wiki.opscode.com/display/chef/Home> + Knife is distributed with Chef. <http://docs.chef.io> diff --git a/distro/common/markdown/man1/knife-cookbook.mkd b/distro/common/markdown/man1/knife-cookbook.mkd index deaf00447a..6a56059e80 100644 --- a/distro/common/markdown/man1/knife-cookbook.mkd +++ b/distro/common/markdown/man1/knife-cookbook.mkd @@ -236,7 +236,7 @@ to specify alternate files to be used on a specific OS platform or host. The default specificity setting is _default_, that is files in `COOKBOOK/files/default` will be used when a more specific copy is not available. Further documentation for this feature is available on the -Chef wiki: <http://wiki.opscode.com/display/chef/File+Distribution#FileDistribution-FileSpecificity> +Chef wiki: <https://docs.chef.io/resource_cookbook_file.html#file-specificity> Cookbooks also contain a metadata file that defines various properties of the cookbook. The most important of these are the _version_ and the @@ -248,8 +248,8 @@ cookbook. ## SEE ALSO __knife-environment(1)__ __knife-cookbook-site(1)__ - <http://wiki.opscode.com/display/chef/Cookbooks> - <http://wiki.opscode.com/display/chef/Metadata> + <http://docs.chef.io/cookbooks.html> + <http://docs.chef.io/cookbook_repo.html> ## AUTHOR Chef was written by Adam Jacob <adam@opscode.com> with many contributions from the community. @@ -260,4 +260,4 @@ cookbook. ## CHEF - Knife is distributed with Chef. <http://wiki.opscode.com/display/chef/Home> + Knife is distributed with Chef. <http://docs.chef.io> diff --git a/distro/common/markdown/man1/knife-data-bag.mkd b/distro/common/markdown/man1/knife-data-bag.mkd index 53abf95272..cab28a2f7f 100644 --- a/distro/common/markdown/man1/knife-data-bag.mkd +++ b/distro/common/markdown/man1/knife-data-bag.mkd @@ -117,5 +117,5 @@ encryption keys. Permission is granted to copy, distribute and / or modify this document under the terms of the Apache 2.0 License. ## CHEF - Knife is distributed with Chef. http://wiki.opscode.com/display/chef/Home + Knife is distributed with Chef. http://docs.chef.io/ diff --git a/distro/common/markdown/man1/knife-environment.mkd b/distro/common/markdown/man1/knife-environment.mkd index 98ca4997bd..06bf423dc0 100644 --- a/distro/common/markdown/man1/knife-environment.mkd +++ b/distro/common/markdown/man1/knife-environment.mkd @@ -137,8 +137,8 @@ The Ruby format of an environment is as follows: ## SEE ALSO __knife-node(1)__ __knife-cookbook(1)__ __knife-role(1)__ - <http://wiki.opscode.com/display/chef/Environments> - <http://wiki.opscode.com/display/chef/Version+Constraints> + <http://docs.chef.io/environments.html> + <http://docs.chef.io/cookbook_versions.html> ## AUTHOR Chef was written by Adam Jacob <adam@opscode.com> with many contributions from the community. @@ -148,4 +148,4 @@ The Ruby format of an environment is as follows: Permission is granted to copy, distribute and / or modify this document under the terms of the Apache 2.0 License. ## CHEF - Knife is distributed with Chef. <http://wiki.opscode.com/display/chef/Home> + Knife is distributed with Chef. <http://docs.chef.io> diff --git a/distro/common/markdown/man1/knife-exec.mkd b/distro/common/markdown/man1/knife-exec.mkd index d4aa87ca46..1b60177d16 100644 --- a/distro/common/markdown/man1/knife-exec.mkd +++ b/distro/common/markdown/man1/knife-exec.mkd @@ -39,4 +39,4 @@ description of the commands available. ## CHEF - Knife is distributed with Chef. <http://wiki.opscode.com/display/chef/Home> + Knife is distributed with Chef. <http://docs.chef.io> diff --git a/distro/common/markdown/man1/knife-index.mkd b/distro/common/markdown/man1/knife-index.mkd index 812f3fe7dd..f1425b8013 100644 --- a/distro/common/markdown/man1/knife-index.mkd +++ b/distro/common/markdown/man1/knife-index.mkd @@ -26,5 +26,5 @@ time for all objects to be indexed and available for search. Permission is granted to copy, distribute and / or modify this document under the terms of the Apache 2.0 License. ## CHEF - Knife is distributed with Chef. <http://wiki.opscode.com/display/chef/Home> + Knife is distributed with Chef. <http://docs.chef.io> diff --git a/distro/common/markdown/man1/knife-node.mkd b/distro/common/markdown/man1/knife-node.mkd index 72b7d0072f..0262d64702 100644 --- a/distro/common/markdown/man1/knife-node.mkd +++ b/distro/common/markdown/man1/knife-node.mkd @@ -126,5 +126,5 @@ When adding a recipe to a run list, there are several valid formats: Permission is granted to copy, distribute and / or modify this document under the terms of the Apache 2.0 License. ## CHEF - Knife is distributed with Chef. <http://wiki.opscode.com/display/chef/Home> + Knife is distributed with Chef. <http://docs.chef.io> diff --git a/distro/common/markdown/man1/knife-role.mkd b/distro/common/markdown/man1/knife-role.mkd index 7e0dac9bc5..e202c52d81 100644 --- a/distro/common/markdown/man1/knife-role.mkd +++ b/distro/common/markdown/man1/knife-role.mkd @@ -70,8 +70,8 @@ run\_list. ## SEE ALSO __knife-node(1)__ __knife-environment(1)__ - <http://wiki.opscode.com/display/chef/Roles> - <http://wiki.opscode.com/display/chef/Attributes> + <http://docs.chef.io/roles.html> + <http://docs.chef.io/attributes.html> ## AUTHOR Chef was written by Adam Jacob <adam@opscode.com> with many contributions from the community. @@ -81,5 +81,5 @@ run\_list. Permission is granted to copy, distribute and / or modify this document under the terms of the Apache 2.0 License. ## CHEF - Knife is distributed with Chef. <http://wiki.opscode.com/display/chef/Home> + Knife is distributed with Chef. <http://docs.chef.io> diff --git a/distro/common/markdown/man1/knife-search.mkd b/distro/common/markdown/man1/knife-search.mkd index d6729be322..b289b2c83b 100644 --- a/distro/common/markdown/man1/knife-search.mkd +++ b/distro/common/markdown/man1/knife-search.mkd @@ -164,7 +164,7 @@ Find all nodes running CentOS in the production environment: ## SEE ALSO __knife-ssh__(1) - <http://wiki.opscode.com/display/chef/Attributes> + <http://docs.chef.io/attributes.html> [Lucene Query Parser Syntax](http://lucene.apache.org/java/2_3_2/queryparsersyntax.html) ## AUTHOR @@ -175,6 +175,6 @@ Find all nodes running CentOS in the production environment: Permission is granted to copy, distribute and / or modify this document under the terms of the Apache 2.0 License. ## CHEF - Knife is distributed with Chef. <http://wiki.opscode.com/display/chef/Home> + Knife is distributed with Chef. <http://docs.chef.io> diff --git a/distro/common/markdown/man1/knife-ssh.mkd b/distro/common/markdown/man1/knife-ssh.mkd index 07fc5940ce..7d37075470 100644 --- a/distro/common/markdown/man1/knife-ssh.mkd +++ b/distro/common/markdown/man1/knife-ssh.mkd @@ -64,6 +64,6 @@ The available multiplexers are: Permission is granted to copy, distribute and / or modify this document under the terms of the Apache 2.0 License. ## CHEF - Knife is distributed with Chef. <http://wiki.opscode.com/display/chef/Home> + Knife is distributed with Chef. <http://docs.chef.io> diff --git a/distro/common/markdown/man1/knife-status.mkd b/distro/common/markdown/man1/knife-status.mkd index 07f0ff305a..0a969e40dd 100644 --- a/distro/common/markdown/man1/knife-status.mkd +++ b/distro/common/markdown/man1/knife-status.mkd @@ -31,6 +31,6 @@ may not be publicly reachable. Permission is granted to copy, distribute and / or modify this document under the terms of the Apache 2.0 License. ## CHEF - Knife is distributed with Chef. <http://wiki.opscode.com/display/chef/Home> + Knife is distributed with Chef. <http://docs.chef.io> diff --git a/distro/common/markdown/man1/knife-tag.mkd b/distro/common/markdown/man1/knife-tag.mkd index 6a1a2c4b56..b5bbb8236f 100644 --- a/distro/common/markdown/man1/knife-tag.mkd +++ b/distro/common/markdown/man1/knife-tag.mkd @@ -35,5 +35,5 @@ Lists the tags applied to _node_ Permission is granted to copy, distribute and / or modify this document under the terms of the Apache 2.0 License. ## CHEF - Knife is distributed with Chef. <http://wiki.opscode.com/display/chef/Home> + Knife is distributed with Chef. <http://docs.chef.io> diff --git a/distro/common/markdown/man1/knife.mkd b/distro/common/markdown/man1/knife.mkd index c3add163f9..3d7c095c10 100644 --- a/distro/common/markdown/man1/knife.mkd +++ b/distro/common/markdown/man1/knife.mkd @@ -186,7 +186,7 @@ recommended though, and git fits with a lot of the workflow paradigms. __knife-node(1)__ __knife-recipe(1)__ __knife-role(1)__ __knife-search(1)__ __knife-ssh(1)__ __knife-tag(1)__ - Complete Chef documentation is available online: <http://wiki.opscode.com/display/chef/Home/> + Complete Chef documentation is available online: <http://docs.chef.io/> JSON is JavaScript Object Notation <http://json.org/> @@ -209,5 +209,5 @@ recommended though, and git fits with a lot of the workflow paradigms. On some systems, the complete text of the Apache 2.0 License may be found in `/usr/share/common-licenses/Apache-2.0`. ## CHEF - Knife is distributed with Chef. <http://wiki.opscode.com/display/chef/Home> + Knife is distributed with Chef. <http://docs.chef.io/> diff --git a/distro/common/markdown/man8/chef-client.mkd b/distro/common/markdown/man8/chef-client.mkd index e37d283133..ffe444ecf2 100644 --- a/distro/common/markdown/man8/chef-client.mkd +++ b/distro/common/markdown/man8/chef-client.mkd @@ -59,8 +59,7 @@ are largely services that exist only to provide the Client with information. ## SEE ALSO -Full documentation for Chef and chef-client is located on the Chef -wiki, http://wiki.opscode.com/display/chef/Home. +Full documentation for Chef and chef-client is located on docs site, http://docs.chef.io/. ## AUTHOR diff --git a/distro/common/markdown/man8/chef-expander.mkd b/distro/common/markdown/man8/chef-expander.mkd index 9190a9aebb..a2bb7d72b0 100644 --- a/distro/common/markdown/man8/chef-expander.mkd +++ b/distro/common/markdown/man8/chef-expander.mkd @@ -67,8 +67,7 @@ See __chef-expanderctl__(8) for details. __chef-expanderctl__(8) __chef-solr__(8) -Full documentation for Chef and chef-server is located on the Chef -wiki, http://wiki.opscode.com/display/chef/Home. +Full documentation for Chef and chef-server is located on docs site, http://docs.chef.io/. ## AUTHOR diff --git a/distro/common/markdown/man8/chef-expanderctl.mkd b/distro/common/markdown/man8/chef-expanderctl.mkd index 03ce6af8ac..db593cb47a 100644 --- a/distro/common/markdown/man8/chef-expanderctl.mkd +++ b/distro/common/markdown/man8/chef-expanderctl.mkd @@ -43,8 +43,7 @@ be restarted by the master process. __chef-expander-cluster__(8) __chef-solr__(8) -Full documentation for Chef and chef-server is located on the Chef -wiki, http://wiki.opscode.com/display/chef/Home. +Full documentation for Chef and chef-server is located on docs site, http://docs.chef.io/. ## AUTHOR diff --git a/distro/common/markdown/man8/chef-server-webui.mkd b/distro/common/markdown/man8/chef-server-webui.mkd index 977e1495e2..b176d12690 100644 --- a/distro/common/markdown/man8/chef-server-webui.mkd +++ b/distro/common/markdown/man8/chef-server-webui.mkd @@ -106,7 +106,7 @@ The default credentials are: ## SEE ALSO Full documentation for Chef and chef-server-webui (Management Console) -is located on the Chef wiki, http://wiki.opscode.com/display/chef/Home. +is located on the Chef docs site, http://docs.chef.io/. ## AUTHOR diff --git a/distro/common/markdown/man8/chef-server.mkd b/distro/common/markdown/man8/chef-server.mkd index 1b0f35eb77..46a5ea4346 100644 --- a/distro/common/markdown/man8/chef-server.mkd +++ b/distro/common/markdown/man8/chef-server.mkd @@ -106,8 +106,7 @@ __chef-client__(8) __chef-server-webui__(8) __knife__(1) -Full documentation for Chef and chef-server is located on the Chef -wiki, http://wiki.opscode.com/display/chef/Home. +Full documentation for Chef and chef-server is located on docs site, http://docs.chef.io/. ## AUTHOR diff --git a/distro/common/markdown/man8/chef-solo.mkd b/distro/common/markdown/man8/chef-solo.mkd index 861a0faa2d..9d5d9a43b7 100644 --- a/distro/common/markdown/man8/chef-solo.mkd +++ b/distro/common/markdown/man8/chef-solo.mkd @@ -92,8 +92,8 @@ and use the run_list from ~/node.json. ## SEE ALSO -Full documentation for Chef and chef-solo is located on the Chef wiki, -http://wiki.opscode.com/display/chef/Home. +Full documentation for Chef and chef-solo is located on the Chef docs site, +http://docs.chef.io/. ## AUTHOR diff --git a/distro/common/markdown/man8/chef-solr.mkd b/distro/common/markdown/man8/chef-solr.mkd index 02e7d6285e..a210a90a07 100644 --- a/distro/common/markdown/man8/chef-solr.mkd +++ b/distro/common/markdown/man8/chef-solr.mkd @@ -75,7 +75,7 @@ when prompted for confirmation. The process should look like this: __chef-expander-cluster__(8) Full documentation for Chef and chef-server is located on the Chef -wiki, http://wiki.opscode.com/display/chef/Home. +Docs site, http://docs.chef.io/. ## AUTHOR diff --git a/distro/powershell/chef/chef.psm1 b/distro/powershell/chef/chef.psm1 new file mode 100644 index 0000000000..6646226795 --- /dev/null +++ b/distro/powershell/chef/chef.psm1 @@ -0,0 +1,327 @@ + +function Load-Win32Bindings { + Add-Type -TypeDefinition @" +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace Chef +{ + +[StructLayout(LayoutKind.Sequential)] +public struct PROCESS_INFORMATION +{ + public IntPtr hProcess; + public IntPtr hThread; + public uint dwProcessId; + public uint dwThreadId; +} + +[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] +public struct STARTUPINFO +{ + public uint cb; + public string lpReserved; + public string lpDesktop; + public string lpTitle; + public uint dwX; + public uint dwY; + public uint dwXSize; + public uint dwYSize; + public uint dwXCountChars; + public uint dwYCountChars; + public uint dwFillAttribute; + public STARTF dwFlags; + public ShowWindow wShowWindow; + public short cbReserved2; + public IntPtr lpReserved2; + public IntPtr hStdInput; + public IntPtr hStdOutput; + public IntPtr hStdError; +} + +[StructLayout(LayoutKind.Sequential)] +public struct SECURITY_ATTRIBUTES +{ + public int length; + public IntPtr lpSecurityDescriptor; + public bool bInheritHandle; +} + +[Flags] +public enum CreationFlags : int +{ + NONE = 0, + DEBUG_PROCESS = 0x00000001, + DEBUG_ONLY_THIS_PROCESS = 0x00000002, + CREATE_SUSPENDED = 0x00000004, + DETACHED_PROCESS = 0x00000008, + CREATE_NEW_CONSOLE = 0x00000010, + CREATE_NEW_PROCESS_GROUP = 0x00000200, + CREATE_UNICODE_ENVIRONMENT = 0x00000400, + CREATE_SEPARATE_WOW_VDM = 0x00000800, + CREATE_SHARED_WOW_VDM = 0x00001000, + CREATE_PROTECTED_PROCESS = 0x00040000, + EXTENDED_STARTUPINFO_PRESENT = 0x00080000, + CREATE_BREAKAWAY_FROM_JOB = 0x01000000, + CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x02000000, + CREATE_DEFAULT_ERROR_MODE = 0x04000000, + CREATE_NO_WINDOW = 0x08000000, +} + +[Flags] +public enum STARTF : uint +{ + STARTF_USESHOWWINDOW = 0x00000001, + STARTF_USESIZE = 0x00000002, + STARTF_USEPOSITION = 0x00000004, + STARTF_USECOUNTCHARS = 0x00000008, + STARTF_USEFILLATTRIBUTE = 0x00000010, + STARTF_RUNFULLSCREEN = 0x00000020, // ignored for non-x86 platforms + STARTF_FORCEONFEEDBACK = 0x00000040, + STARTF_FORCEOFFFEEDBACK = 0x00000080, + STARTF_USESTDHANDLES = 0x00000100, +} + +public enum ShowWindow : short +{ + SW_HIDE = 0, + SW_SHOWNORMAL = 1, + SW_NORMAL = 1, + SW_SHOWMINIMIZED = 2, + SW_SHOWMAXIMIZED = 3, + SW_MAXIMIZE = 3, + SW_SHOWNOACTIVATE = 4, + SW_SHOW = 5, + SW_MINIMIZE = 6, + SW_SHOWMINNOACTIVE = 7, + SW_SHOWNA = 8, + SW_RESTORE = 9, + SW_SHOWDEFAULT = 10, + SW_FORCEMINIMIZE = 11, + SW_MAX = 11 +} + +public enum StandardHandle : int +{ + Input = -10, + Output = -11, + Error = -12 +} + +public static class Kernel32 +{ + [DllImport("kernel32.dll", SetLastError=true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool CreateProcess( + string lpApplicationName, + string lpCommandLine, + ref SECURITY_ATTRIBUTES lpProcessAttributes, + ref SECURITY_ATTRIBUTES lpThreadAttributes, + [MarshalAs(UnmanagedType.Bool)] bool bInheritHandles, + CreationFlags dwCreationFlags, + IntPtr lpEnvironment, + string lpCurrentDirectory, + ref STARTUPINFO lpStartupInfo, + out PROCESS_INFORMATION lpProcessInformation); + + [DllImport("kernel32.dll", SetLastError=true)] + public static extern IntPtr GetStdHandle( + StandardHandle nStdHandle); + + [DllImport("kernel32", SetLastError=true)] + public static extern int WaitForSingleObject( + IntPtr hHandle, + int dwMilliseconds); + + [DllImport("kernel32", SetLastError=true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool CloseHandle( + IntPtr hObject); + + [DllImport("kernel32", SetLastError=true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool GetExitCodeProcess( + IntPtr hProcess, + out int lpExitCode); +} +} +"@ +} + +function Run-ExecutableAndWait($AppPath, $ArgumentString) { + # Use the Win32 API to create a new process and wait for it to terminate. + $null = Load-Win32Bindings + + $si = New-Object Chef.STARTUPINFO + $pi = New-Object Chef.PROCESS_INFORMATION + + $si.cb = [System.Runtime.InteropServices.Marshal]::SizeOf($si) + $si.wShowWindow = [Chef.ShowWindow]::SW_SHOW + $si.dwFlags = [Chef.STARTF]::STARTF_USESTDHANDLES + $si.hStdError = [Chef.Kernel32]::GetStdHandle([Chef.StandardHandle]::Error) + $si.hStdOutput = [Chef.Kernel32]::GetStdHandle([Chef.StandardHandle]::Output) + $si.hStdInput = [Chef.Kernel32]::GetStdHandle([Chef.StandardHandle]::Input) + + $pSec = New-Object Chef.SECURITY_ATTRIBUTES + $pSec.Length = [System.Runtime.InteropServices.Marshal]::SizeOf($pSec) + $pSec.bInheritHandle = $true + $tSec = New-Object Chef.SECURITY_ATTRIBUTES + $tSec.Length = [System.Runtime.InteropServices.Marshal]::SizeOf($tSec) + $tSec.bInheritHandle = $true + + $success = [Chef.Kernel32]::CreateProcess($AppPath, $ArgumentString, [ref] $pSec, [ref] $tSec, $true, [Chef.CreationFlags]::NONE, [IntPtr]::Zero, $pwd, [ref] $si, [ref] $pi) + if (-Not $success) { + $reason = [System.Runtime.InteropServices.Marshal]::GetLastWin32Error() + throw "Unable to create process [$ArgumentString]. Error code $reason." + } + $waitReason = [Chef.Kernel32]::WaitForSingleObject($pi.hProcess, -1) + if ($waitReason -ne 0) { + if ($waitReason -eq -1) { + $reason = [System.Runtime.InteropServices.Marshal]::GetLastWin32Error() + throw "Could not wait for process to terminate. Error code $reason." + } else { + throw "WaitForSingleObject failed with return code $waitReason - it's impossible!" + } + } + $success = [Chef.Kernel32]::GetExitCodeProcess($pi.hProcess, [ref] $global:LASTEXITCODE) + if (-Not $success) { + $reason = [System.Runtime.InteropServices.Marshal]::GetLastWin32Error() + throw "Process exit code unavailable. Error code $reason." + } + $success = [Chef.Kernel32]::CloseHandle($pi.hProcess) + if (-Not $success) { + $reason = [System.Runtime.InteropServices.Marshal]::GetLastWin32Error() + throw "Unable to release process handle. Error code $reason." + } + $success = [Chef.Kernel32]::CloseHandle($pi.hThread) + if (-Not $success) { + $reason = [System.Runtime.InteropServices.Marshal]::GetLastWin32Error() + throw "Unable to release thread handle. Error code $reason." + } +} + +function Get-ScriptDirectory { + if (!$PSScriptRoot) { + $Invocation = (Get-Variable MyInvocation -Scope 1).Value + $PSScriptRoot = Split-Path $Invocation.MyCommand.Path + } + $PSScriptRoot +} + +function Run-RubyCommand($command, $argList) { + # This method exists to take the given list of arguments and get it past ruby's command-line + # interpreter unscathed and untampered. See https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1582 + # for a list of transformations that ruby attempts to perform with your command-line arguments + # before passing it onto a script. The most important task is to defeat the globbing + # and wild-card expansion that ruby performs. Note that ruby does not use MSVCRT's argc/argv + # and deliberately reparses the raw command-line instead. + # + # To stop ruby from interpreting command-line arguments as globs, they need to be enclosed in ' + # Ruby doesn't allow any escape characters inside '. This unfortunately prevents us from sending + # any strings which themselves contain '. Ruby does allow multi-fragment arguments though. + # "foo bar"'baz qux'123"foo" is interpreted as 1 argument because there are no un-escaped + # whitespace there. The argument would be interpreted as the string "foo barbaz qux123foo". + # This lets us escape ' characters by exiting the ' quoted string, injecting a "'" fragment and + # then resuming the ' quoted string again. + # + # In the process of defeating ruby, one must also defeat the helpfulness of powershell. + # When arguments come into this method, the standard PS rules for interpreting cmdlet arguments + # apply. When using & (call operator) and providing an array of arguments, powershell (verified + # on PS 4.0 on Windows Server 2012R2) will not evaluate them but (contrary to documentation), + # it will still marginally interpret them. The behaviour of PS 5.0 seems to be different but + # ignore that for now. If any of the provided arguments has a space in it, powershell checks + # the first and last character to ensure that they are " characters (and that's all it checks). + # If they are not, it will blindly surround that argument with " characters. It won't do this + # operation if no space is present, even if other special characters are present. If it notices + # leading and trailing " characters, it won't actually check to see if there are other " + # characters in the string. Since PS 5.0 changes this behavior, we could consider using the --% + # "stop screwing up my arguments" operator, which is available since PS 3.0. When encountered + # --% indicates that the rest of line is to be sent literally... except if the parser encounters + # %FOO% cmd style environment variables. Because reasons. And there is no way to escape the + # % character in *any* waym shape or form. + # https://connect.microsoft.com/PowerShell/feedback/details/376207/executing-commands-which-require-quotes-and-variables-is-practically-impossible + # + # In case you think that you're either reading this incorrectly or that I'm full of shit, here + # are some examples. These use EchoArgs.exe from the PowerShell Community Extensions package. + # I have not included the argument parsing output from EchoArgs.exe to prevent confusing you with + # more details about MSVCRT's parsing algorithm. + # + # $x = "foo '' bar `"baz`"" + # & EchoArgs @($x, $x) + # Command line: + # "C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\Pscx\Apps\EchoArgs.exe" "foo '' bar "baz"" "foo '' bar "baz"" + # + # $x = "abc'123'nospace`"lulz`"!!!" + # & EchoArgs @($x, $x) + # Command line: + # "C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\Pscx\Apps\EchoArgs.exe" abc'123'nospace"lulz"!!! abc'123'nospace"lulz"!!! + # + # $x = "`"`"Look ma! Tonnes of spaces! 'foo' 'bar'`"`"" + # & EchoArgs @($x, $x) + # Command line: + # "C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\Pscx\Apps\EchoArgs.exe" ""Look ma! Tonnes of spaces! 'foo' 'bar'"" ""Look ma! Tonnes of spaces! 'foo' 'bar'"" + # + # Given all this, we can now device a strategy to work around all these immensely helpful, well + # documented and useful tools by looking at each incoming argument, escaping any ' characters + # with a '"'"' sequence, surrounding each argument with ' & joining them with a space separating + # them. + # There is another bug (https://bugs.ruby-lang.org/issues/11142) that causes ruby to mangle any + # "" two-character double quote sequence but since we always emit our strings inside ' except for + # ' characters, this should be ok. Just remember that an argument '' should get translated to + # ''"'"''"'"'' on the command line. If those intervening empty ''s are not present, the presence + # of "" will cause ruby to mangle that argument. + $transformedList = $argList | foreach { "'" + ( $_ -replace "'","'`"'`"'" ) + "'" } + $fortifiedArgString = $transformedList -join ' ' + + # Use the correct embedded ruby path. We'll be deployed at a path that looks like + # [C:\opscode or some other prefix]\chef\modules\chef + $ruby = Join-Path (Get-ScriptDirectory) "..\..\embedded\bin\ruby.exe" + $commandPath = Join-Path (Get-ScriptDirectory) "..\..\bin\$command" + + Run-ExecutableAndWait $ruby """$ruby"" '$commandPath' $fortifiedArgString" +} + + +function chef-apply { + Run-RubyCommand 'chef-apply' $args +} + +function chef-client { + Run-RubyCommand 'chef-client' $args +} + +function chef-service-manager { + Run-RubyCommand 'chef-service-manager' $args +} + +function chef-shell { + Run-RubyCommand 'chef-shell' $args +} + +function chef-solo { + Run-RubyCommand 'chef-solo' $args +} + +function chef-windows-service { + Run-RubyCommand 'chef-windows-service' $args +} + +function knife { + Run-RubyCommand 'knife' $args +} + +Export-ModuleMember -function chef-apply +Export-ModuleMember -function chef-client +Export-ModuleMember -function chef-service-manager +Export-ModuleMember -function chef-shell +Export-ModuleMember -function chef-solo +Export-ModuleMember -function chef-windows-service +Export-ModuleMember -function knife + +# To debug this module, uncomment the line below and then run the following. +# Export-ModuleMember -function Run-RubyCommand +# Remove-Module chef +# Import-Module chef +# "puts ARGV" | Out-File C:\opscode\chef\bin\puts_args +# Run-RubyCommand puts_args 'Here' "are" some '"very interesting"' 'arguments[to]' "`"try out`"" |