Multiple fixes (#224)

PowerShell/Win32-OpenSSH#894
Added logic to profile path retrieval to consider environment variables in path read from registry
PowerShell/Win32-OpenSSH#883
Added flags to support libssh2 SFTP. These are No-Ops for now. We may support them later if needed. Added PowerShell/Win32-OpenSSH#915 to keep track of TODO work item
This commit is contained in:
Manoj Ampalam 2017-10-17 12:29:13 -07:00 committed by GitHub
parent 9555bd9e87
commit 21ebb53a30
4 changed files with 25 additions and 6 deletions

View File

@ -514,6 +514,9 @@ ConWriteString(char* pszString, int cbString)
int cnt = 0;
wchar_t* utf16 = NULL;
if (pszString == NULL)
return 0;
if ((needed = MultiByteToWideChar(CP_UTF8, 0, pszString, cbString, NULL, 0)) == 0 ||
(utf16 = malloc(needed * sizeof(wchar_t))) == NULL ||
(cnt = MultiByteToWideChar(CP_UTF8, 0, pszString, cbString, utf16, needed)) == 0) {
@ -536,6 +539,9 @@ ConTranslateAndWriteString(char* pszString, int cbString)
{
DWORD Result = 0;
if (pszString == NULL)
return 0;
if (hOutputConsole)
WriteConsole(hOutputConsole, pszString, cbString, &Result, 0);
else

View File

@ -347,7 +347,11 @@ createFile_flags_setup(int flags, mode_t mode, struct createFile_flags* cf_flags
// If the mode is USHRT_MAX then we will inherit the permissions from the parent folder.
if (mode != USHRT_MAX) {
/*validate mode*/
if (mode & ~(S_IRWXU | S_IRWXG | S_IRWXO)) {
/*
* __S_IFDIR __S_IFREG are added for compat
* TODO- open(__S_IFDIR) on a file and vice versa should fail
*/
if (mode & ~(S_IRWXU | S_IRWXG | S_IRWXO | __S_IFDIR | __S_IFREG)) {
debug3("open - ERROR: unsupported mode: %d", mode);
errno = ENOTSUP;
return -1;

View File

@ -59,3 +59,10 @@ int w32_allocate_fd_for_handle(HANDLE, BOOL);
# define S_IRWXU 0000700 /* read, write, execute */
# define S_IRWXG 0000070 /* read, write, execute */
# define S_IRWXO 0000007 /* read, write, execute */
/*
* File types. Note that the values are different from similar variants
* defined in stat.h. These are based on similar definition values on Linux
*/
#define __S_IFDIR 0040000 /* Directory. */
#define __S_IFREG 0100000 /* Regular file. */

View File

@ -106,7 +106,7 @@ get_passwd(const char *user_utf8, LPWSTR user_sid)
char *uname_utf8 = NULL, *uname_upn = NULL, *udom_utf8 = NULL, *pw_home_utf8 = NULL, *user_sid_utf8 = NULL;
LPBYTE user_info = NULL;
LPWSTR user_sid_local = NULL;
wchar_t reg_path[PATH_MAX], profile_home[PATH_MAX];
wchar_t reg_path[PATH_MAX], profile_home[PATH_MAX], profile_home_exp[PATH_MAX];
HKEY reg_key = 0;
int tmp_len = PATH_MAX;
PDOMAIN_CONTROLLER_INFOW pdc = NULL;
@ -165,8 +165,10 @@ get_passwd(const char *user_utf8, LPWSTR user_sid)
/* if one of below fails, set profile path to Windows directory */
if (swprintf_s(reg_path, PATH_MAX, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%ls", user_sid) == -1 ||
RegOpenKeyExW(HKEY_LOCAL_MACHINE, reg_path, 0, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_WOW64_64KEY, &reg_key) != 0 ||
RegQueryValueExW(reg_key, L"ProfileImagePath", 0, NULL, (LPBYTE)profile_home, &tmp_len) != 0)
if (GetWindowsDirectoryW(profile_home, PATH_MAX) == 0) {
RegQueryValueExW(reg_key, L"ProfileImagePath", 0, NULL, (LPBYTE)profile_home, &tmp_len) != 0 ||
ExpandEnvironmentStringsW(profile_home, NULL, 0) > PATH_MAX ||
ExpandEnvironmentStringsW(profile_home, profile_home_exp, PATH_MAX) == 0)
if (GetWindowsDirectoryW(profile_home_exp, PATH_MAX) == 0) {
debug3("GetWindowsDirectoryW failed with %d", GetLastError());
errno = EOTHER;
goto done;
@ -174,7 +176,7 @@ get_passwd(const char *user_utf8, LPWSTR user_sid)
if ((uname_utf8 = utf16_to_utf8(uname_utf16)) == NULL ||
(udom_utf16 && (udom_utf8 = utf16_to_utf8(udom_utf16)) == NULL) ||
(pw_home_utf8 = utf16_to_utf8(profile_home)) == NULL ||
(pw_home_utf8 = utf16_to_utf8(profile_home_exp)) == NULL ||
(user_sid_utf8 = utf16_to_utf8(user_sid)) == NULL) {
errno = ENOMEM;
goto done;