Skip to content

Add support of posix_spawnp #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions contrib/win32/win32compat/spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
#include "inc\spawn.h"
#include "inc\unistd.h"

int
posix_spawnp(pid_t *pidp, const char *file, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, char *const argv[], char *const envp[])
{
errno = ENOTSUP;
return -1;
}

int
posix_spawn_file_actions_init(posix_spawn_file_actions_t *file_actions)
{
Expand Down
16 changes: 11 additions & 5 deletions contrib/win32/win32compat/w32fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ int fork()
*/

static int
spawn_child_internal(char* cmd, char *const argv[], HANDLE in, HANDLE out, HANDLE err, unsigned long flags, HANDLE* as_user)
spawn_child_internal(char* cmd, char *const argv[], HANDLE in, HANDLE out, HANDLE err, unsigned long flags, HANDLE* as_user, BOOLEAN prepend_module_path)
{
PROCESS_INFORMATION pi;
STARTUPINFOW si;
Expand All @@ -1036,7 +1036,7 @@ spawn_child_internal(char* cmd, char *const argv[], HANDLE in, HANDLE out, HANDL
}

t = cmd;
if (!is_absolute_path(t))
if (!is_absolute_path(t) && prepend_module_path)
add_module_path = 1;

/* compute total cmdline len*/
Expand Down Expand Up @@ -1246,7 +1246,7 @@ fd_decode_state(char* enc_buf)
}

int
posix_spawn_internal(pid_t *pidp, const char *path, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, char *const argv[], char *const envp[], HANDLE user_token)
posix_spawn_internal(pid_t *pidp, const char *path, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, char *const argv[], char *const envp[], HANDLE user_token, BOOLEAN prepend_module_path)
{
int i, ret = -1;
int sc_flags = 0;
Expand Down Expand Up @@ -1282,7 +1282,7 @@ posix_spawn_internal(pid_t *pidp, const char *path, const posix_spawn_file_actio

if (_putenv_s(POSIX_FD_STATE, fd_info) != 0)
goto cleanup;
i = spawn_child_internal(argv[0], argv + 1, stdio_handles[STDIN_FILENO], stdio_handles[STDOUT_FILENO], stdio_handles[STDERR_FILENO], sc_flags, user_token);
i = spawn_child_internal(argv[0], argv + 1, stdio_handles[STDIN_FILENO], stdio_handles[STDOUT_FILENO], stdio_handles[STDERR_FILENO], sc_flags, user_token, prepend_module_path);
if (i == -1)
goto cleanup;
if (pidp)
Expand Down Expand Up @@ -1315,5 +1315,11 @@ posix_spawn_internal(pid_t *pidp, const char *path, const posix_spawn_file_actio
int
posix_spawn(pid_t *pidp, const char *path, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, char *const argv[], char *const envp[])
{
return posix_spawn_internal(pidp, path, file_actions, attrp, argv, envp, NULL);
return posix_spawn_internal(pidp, path, file_actions, attrp, argv, envp, NULL, TRUE);
}

int
posix_spawnp(pid_t *pidp, const char *file, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, char *const argv[], char *const envp[])
{
return posix_spawn_internal(pidp, file, file_actions, attrp, argv, envp, NULL, FALSE);
}
4 changes: 2 additions & 2 deletions readpass.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ ssh_askpass(char *askpass, const char *msg)
char* spawn_argv[2];
spawn_argv[0] = askpass;
spawn_argv[1] = NULL;
if (posix_spawn(&pid, spawn_argv[0], &actions, NULL, spawn_argv, NULL) != 0) {
if (posix_spawnp(&pid, spawn_argv[0], &actions, NULL, spawn_argv, NULL) != 0) {
posix_spawn_file_actions_destroy(&actions);
error("ssh_askpass: posix_spawn: %s", strerror(errno));
error("ssh_askpass: posix_spawnp: %s", strerror(errno));
signal(SIGCHLD, osigchld);
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion regress/pesterTests/CommonUtils.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function Add-PasswordSetting
$platform = Get-Platform
if ($platform -eq [PlatformType]::Windows) {
if (-not($env:DISPLAY)) {$env:DISPLAY = 1}
$env:SSH_ASKPASS="$($env:ComSpec) /c echo $pass"
$env:SSH_ASKPASS="cmd.exe /c echo $pass"
}
}

Expand Down
12 changes: 12 additions & 0 deletions regress/pesterTests/SSH.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,18 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
iex "cmd /c `"ssh -o UserKnownHostsFile=`"$kh`" -o StrictHostKeyChecking=no test_target hostname 2>&1`""
@(Get-Content $kh).Count | Should Be 1
}

It "ProxyCommand with file name only" {
& cmd /c "ssh -o ProxyCommand=`"cmd.exe /c echo Invalid proxy 1>&2`" abc 2>$stderrFile"
$stderrFile | Should Contain "Invalid proxy"
$stderrFile | Should Contain "Connection closed by remote host"
}

It "ProxyCommand with absolute path to the file" {
& cmd /c "ssh -o ProxyCommand=`"$($env:ComSpec) /c echo Invalid proxy 1>&2`" abc 2>$stderrFile"
$stderrFile | Should Contain "Invalid proxy"
$stderrFile | Should Contain "Connection closed by remote host"
}
}

}
1 change: 0 additions & 1 deletion regress/pesterTests/SSHDConfig.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,5 @@ Describe "Tests of sshd_config" -Tags "CI" {
Stop-SSHDTestDaemon
Remove-UserFromLocalGroup -UserName $matchuser -GroupName $allowGroup1
}
#>
}
}
4 changes: 2 additions & 2 deletions sshconnect.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port,
posix_spawn_file_actions_adddup2(&actions, pin[0], STDIN_FILENO) != 0 ||
posix_spawn_file_actions_adddup2(&actions, pout[1], STDOUT_FILENO) != 0)
fatal("posix_spawn initialization failed");
else if (posix_spawn(&pid, spawn_argv[0], &actions, NULL, spawn_argv, NULL) != 0)
fatal("posix_spawn: %s", strerror(errno));
else if (posix_spawnp(&pid, spawn_argv[0], &actions, NULL, spawn_argv, NULL) != 0)
fatal("posix_spawnp: %s", strerror(errno));

posix_spawn_file_actions_destroy(&actions);
}
Expand Down