mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-07-31 01:35:11 +02:00
fix for msrc cases
This commit is contained in:
parent
414d8531ce
commit
fd424a5197
@ -37,6 +37,9 @@
|
|||||||
|
|
||||||
#pragma warning(push, 3)
|
#pragma warning(push, 3)
|
||||||
|
|
||||||
|
/* Pattern-list of allowed PKCS#11/Security key paths */
|
||||||
|
char* allowed_providers = NULL;
|
||||||
|
|
||||||
int remote_add_provider;
|
int remote_add_provider;
|
||||||
|
|
||||||
int scm_start_service(DWORD, LPWSTR*);
|
int scm_start_service(DWORD, LPWSTR*);
|
||||||
@ -134,8 +137,25 @@ wmain(int argc, wchar_t **wargv)
|
|||||||
fatal("Unknown -O option; only allow-remote-pkcs11 is supported");
|
fatal("Unknown -O option; only allow-remote-pkcs11 is supported");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (wcsncmp(wargv[i], L"-P", 2) == 0) {
|
||||||
|
if (allowed_providers != NULL)
|
||||||
|
fatal("-P option already specified");
|
||||||
|
if ((i + 1) < argc) {
|
||||||
|
i++;
|
||||||
|
if ((allowed_providers = utf16_to_utf8(wargv[i])) == NULL)
|
||||||
|
fatal("Invalid argument for -P option");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fatal("Missing argument for -P option");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (allowed_providers == NULL) {
|
||||||
|
agent_initialize_allow_list();
|
||||||
|
}
|
||||||
|
|
||||||
if (!StartServiceCtrlDispatcherW(dispatch_table)) {
|
if (!StartServiceCtrlDispatcherW(dispatch_table)) {
|
||||||
if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
|
if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
|
||||||
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
|
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
|
||||||
|
@ -34,9 +34,11 @@
|
|||||||
#include <UserEnv.h>
|
#include <UserEnv.h>
|
||||||
#include "..\misc_internal.h"
|
#include "..\misc_internal.h"
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
#include "xmalloc.h"
|
||||||
|
|
||||||
#define BUFSIZE 5 * 1024
|
#define BUFSIZE 5 * 1024
|
||||||
|
|
||||||
|
extern char* allowed_providers;
|
||||||
extern int remote_add_provider;
|
extern int remote_add_provider;
|
||||||
|
|
||||||
char* sshagent_con_username;
|
char* sshagent_con_username;
|
||||||
@ -170,11 +172,11 @@ agent_listen_loop()
|
|||||||
GetModuleFileNameW(NULL, module_path, PATH_MAX);
|
GetModuleFileNameW(NULL, module_path, PATH_MAX);
|
||||||
SetHandleInformation(con, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
|
SetHandleInformation(con, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
|
||||||
if (remote_add_provider == 1) {
|
if (remote_add_provider == 1) {
|
||||||
if (swprintf_s(path, PATH_MAX, L"%s %d %s", module_path, (int)(intptr_t)con, L"-Oallow-remote-pkcs11") == -1)
|
if (swprintf_s(path, PATH_MAX, L"%s %d %s -P \"%S\"", module_path, (int)(intptr_t)con, L"-Oallow-remote-pkcs11", allowed_providers) == -1)
|
||||||
verbose("Failed to create child process %ls ERROR:%d", module_path, GetLastError());
|
verbose("Failed to create child process %ls ERROR:%d", module_path, GetLastError());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (swprintf_s(path, PATH_MAX, L"%s %d", module_path, (int)(intptr_t)con) == -1)
|
if (swprintf_s(path, PATH_MAX, L"%s %d -P \"%S\"", module_path, (int)(intptr_t)con, allowed_providers) == -1)
|
||||||
verbose("Failed to create child process %ls ERROR:%d", module_path, GetLastError());
|
verbose("Failed to create child process %ls ERROR:%d", module_path, GetLastError());
|
||||||
}
|
}
|
||||||
if (CreateProcessW(NULL, path, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi) == FALSE) {
|
if (CreateProcessW(NULL, path, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi) == FALSE) {
|
||||||
@ -408,3 +410,30 @@ agent_process_connection(HANDLE pipe)
|
|||||||
iocp_work(NULL);
|
iocp_work(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
agent_initialize_allow_list() {
|
||||||
|
/*
|
||||||
|
* allowed paths for PKCS11 libraries,
|
||||||
|
* initialize to ProgramFiles and ProgramFiles(x86) by default
|
||||||
|
* upstream uses /usr/lib/* and /usr/local/lib/*
|
||||||
|
*/
|
||||||
|
size_t prog_files_len = 0, prog_files_x86_len = 0;
|
||||||
|
char* prog_files = NULL, * prog_files_x86 = NULL;
|
||||||
|
|
||||||
|
_dupenv_s(&prog_files, &prog_files_len, "ProgramFiles");
|
||||||
|
if (!prog_files)
|
||||||
|
fatal("couldn't find ProgramFiles environment variable");
|
||||||
|
convertToForwardslash(prog_files);
|
||||||
|
|
||||||
|
_dupenv_s(&prog_files_x86, &prog_files_x86_len, "ProgramFiles(x86)");
|
||||||
|
if (!prog_files_x86)
|
||||||
|
fatal("couldn't find ProgramFiles environment variable");
|
||||||
|
convertToForwardslash(prog_files_x86);
|
||||||
|
|
||||||
|
size_t allowed_providers_len = 1 + prog_files_len + 4 + prog_files_x86_len + 3;
|
||||||
|
allowed_providers = xmalloc(allowed_providers_len);
|
||||||
|
sprintf_s(allowed_providers, allowed_providers_len, "/%s/*,/%s/*", prog_files, prog_files_x86);
|
||||||
|
|
||||||
|
free(prog_files);
|
||||||
|
free(prog_files_x86);
|
||||||
|
}
|
||||||
|
@ -63,3 +63,4 @@ void agent_start(BOOL);
|
|||||||
void agent_process_connection(HANDLE);
|
void agent_process_connection(HANDLE);
|
||||||
void agent_shutdown();
|
void agent_shutdown();
|
||||||
void agent_cleanup_connection(struct agent_connection*);
|
void agent_cleanup_connection(struct agent_connection*);
|
||||||
|
void agent_initialize_allow_list();
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "agent.h"
|
#include "agent.h"
|
||||||
#include "agent-request.h"
|
#include "agent-request.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "match.h"
|
||||||
#include <sddl.h>
|
#include <sddl.h>
|
||||||
#ifdef ENABLE_PKCS11
|
#ifdef ENABLE_PKCS11
|
||||||
#include "ssh-pkcs11.h"
|
#include "ssh-pkcs11.h"
|
||||||
@ -44,6 +45,7 @@
|
|||||||
#define MAX_VALUE_NAME_LENGTH 16383
|
#define MAX_VALUE_NAME_LENGTH 16383
|
||||||
#define MAX_VALUE_DATA_LENGTH 2048
|
#define MAX_VALUE_DATA_LENGTH 2048
|
||||||
|
|
||||||
|
extern char* allowed_providers;
|
||||||
extern int remote_add_provider;
|
extern int remote_add_provider;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -675,6 +677,12 @@ int process_add_smartcard_key(struct sshbuf* request, struct sshbuf* response, s
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (match_pattern_list(canonical_provider, allowed_providers, 0) != 1) {
|
||||||
|
verbose("refusing PKCS#11 add of \"%.100s\": "
|
||||||
|
"provider not allowed", canonical_provider);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove 'drive root' if exists
|
// Remove 'drive root' if exists
|
||||||
if (canonical_provider[0] == '/')
|
if (canonical_provider[0] == '/')
|
||||||
memmove(canonical_provider, canonical_provider + 1, strlen(canonical_provider));
|
memmove(canonical_provider, canonical_provider + 1, strlen(canonical_provider));
|
||||||
@ -766,6 +774,8 @@ done:
|
|||||||
free(pubkey_blob);
|
free(pubkey_blob);
|
||||||
if (provider)
|
if (provider)
|
||||||
free(provider);
|
free(provider);
|
||||||
|
if (allowed_providers)
|
||||||
|
free(allowed_providers);
|
||||||
if (pin) {
|
if (pin) {
|
||||||
SecureZeroMemory(pin, (DWORD)pin_len);
|
SecureZeroMemory(pin, (DWORD)pin_len);
|
||||||
free(pin);
|
free(pin);
|
||||||
|
4
scp.c
4
scp.c
@ -2117,7 +2117,11 @@ sink(int argc, char **argv, const char *src)
|
|||||||
SCREWUP("size out of range");
|
SCREWUP("size out of range");
|
||||||
size = (off_t)ull;
|
size = (off_t)ull;
|
||||||
|
|
||||||
|
#ifdef WINDOWS
|
||||||
|
if (*cp == '\0' || strchr(cp, '/') != NULL || strchr(cp, '\\') != NULL ||
|
||||||
|
#else
|
||||||
if (*cp == '\0' || strchr(cp, '/') != NULL ||
|
if (*cp == '\0' || strchr(cp, '/') != NULL ||
|
||||||
|
#endif
|
||||||
strcmp(cp, ".") == 0 || strcmp(cp, "..") == 0) {
|
strcmp(cp, ".") == 0 || strcmp(cp, "..") == 0) {
|
||||||
run_err("error: unexpected filename: %s", cp);
|
run_err("error: unexpected filename: %s", cp);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -84,7 +84,12 @@ extern int showprogress;
|
|||||||
#ifdef HAVE_CYGWIN
|
#ifdef HAVE_CYGWIN
|
||||||
# define SFTP_DIRECTORY_CHARS "/\\"
|
# define SFTP_DIRECTORY_CHARS "/\\"
|
||||||
#else /* HAVE_CYGWIN */
|
#else /* HAVE_CYGWIN */
|
||||||
|
#ifdef WINDOWS
|
||||||
|
// Win32-OpenSSH converts all '/' to '\\' so search for '\\' instead
|
||||||
|
# define SFTP_DIRECTORY_CHARS "\\"
|
||||||
|
#else
|
||||||
# define SFTP_DIRECTORY_CHARS "/"
|
# define SFTP_DIRECTORY_CHARS "/"
|
||||||
|
#endif /* WINDOWS */
|
||||||
#endif /* HAVE_CYGWIN */
|
#endif /* HAVE_CYGWIN */
|
||||||
|
|
||||||
struct sftp_conn {
|
struct sftp_conn {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user