mirror of
				https://github.com/PowerShell/Win32-OpenSSH.git
				synced 2025-10-31 11:44:38 +01:00 
			
		
		
		
	shell host is now the default shell process in sshd
This commit is contained in:
		
							parent
							
								
									7bff604e70
								
							
						
					
					
						commit
						5cb9fb09ed
					
				
							
								
								
									
										46
									
								
								channels.c
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								channels.c
									
									
									
									
									
								
							| @ -2479,53 +2479,7 @@ channel_input_data(int type, u_int32_t seq, void *ctxt) | |||||||
| 	if (c->datagram) | 	if (c->datagram) | ||||||
| 		buffer_put_string(&c->output, data, data_len); | 		buffer_put_string(&c->output, data, data_len); | ||||||
| 	else { | 	else { | ||||||
| 		#if(0)//ndef WIN32_FIXME
 |  | ||||||
| 		buffer_append(&c->output, data, data_len); | 		buffer_append(&c->output, data, data_len); | ||||||
| 		#else |  | ||||||
| 		if ( c->client_tty ) |  | ||||||
| 			buffer_append(&c->output, data, data_len); |  | ||||||
| 			//telProcessNetwork ( data, data_len ); // run it by ANSI engine if it is the ssh client
 |  | ||||||
| 		else { |  | ||||||
| 				#ifdef WIN32_PRAGMA_REMCON |  | ||||||
| 				buffer_append(&c->output, data, data_len); // it is the sshd server, so pass it on
 |  | ||||||
| 				#else |  | ||||||
| 				if  ( ( c->isatty) && (data_len ==1) && (data[0] == '\003') ) { |  | ||||||
| 						/* send control-c to the shell process */ |  | ||||||
| 						if ( GenerateConsoleCtrlEvent ( CTRL_C_EVENT, 0 ) ) { |  | ||||||
| 						} |  | ||||||
| 						else { |  | ||||||
| 							debug3("GenerateConsoleCtrlEvent failed with %d\n",GetLastError()); |  | ||||||
| 						} |  | ||||||
| 				} |  | ||||||
| 				else { |  | ||||||
| 					// avoid sending the 4 arrow keys out to remote for now "ESC[A" ..
 |  | ||||||
| 					if ( (c->isatty) && (data_len ==3) && (data[0] == '\033') && (data[1] == '[')) { |  | ||||||
| 						if ( ( data[2] == 'A') ||  (data[2] == 'B') ||  (data[2] == 'C') ||  (data[2] == 'D')) |  | ||||||
| 								packet_check_eom(); |  | ||||||
| 								return 0; |  | ||||||
| 					} |  | ||||||
| 					buffer_append(&c->output, data, data_len); // it is the sshd server, so pass it on
 |  | ||||||
| 					if ( c->isatty ) {  // we echo the data if it is sshd server and pty interactive mode			
 |  | ||||||
| 					 |  | ||||||
| 						if ( (data_len ==1) && (data[0] == '\b') ) { |  | ||||||
| 							if (charinline >0) { |  | ||||||
| 								buffer_append(&c->input, "\b \b", 3); // for backspace, we need to send space and another backspace for visual erase
 |  | ||||||
| 								charinline--; |  | ||||||
| 							} |  | ||||||
| 						} |  | ||||||
| 						else { |  | ||||||
| 							buffer_append(&c->input, data, data_len); |  | ||||||
| 							charinline += data_len; // one more char on the line
 |  | ||||||
| 						} |  | ||||||
| 						 |  | ||||||
| 						if ( (data[data_len-1] == '\r') || (data[data_len-1] == '\n') ) |  | ||||||
| 							charinline = 0;  // a line has ended, begin char in line count again
 |  | ||||||
| 					} |  | ||||||
| 				} |  | ||||||
| 				#endif // WIN32_PRAGMA_REMCON
 |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		#endif |  | ||||||
| 	} | 	} | ||||||
| 	packet_check_eom(); | 	packet_check_eom(); | ||||||
| 	return 0; | 	return 0; | ||||||
|  | |||||||
							
								
								
									
										184
									
								
								contrib/win32/openssh/ssh-shellhost.vcxproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										184
									
								
								contrib/win32/openssh/ssh-shellhost.vcxproj
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,184 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||||||
|  |   <Import Project="paths.targets" /> | ||||||
|  |   <ItemGroup Label="ProjectConfigurations"> | ||||||
|  |     <ProjectConfiguration Include="Debug|Win32"> | ||||||
|  |       <Configuration>Debug</Configuration> | ||||||
|  |       <Platform>Win32</Platform> | ||||||
|  |     </ProjectConfiguration> | ||||||
|  |     <ProjectConfiguration Include="Release|Win32"> | ||||||
|  |       <Configuration>Release</Configuration> | ||||||
|  |       <Platform>Win32</Platform> | ||||||
|  |     </ProjectConfiguration> | ||||||
|  |     <ProjectConfiguration Include="Debug|x64"> | ||||||
|  |       <Configuration>Debug</Configuration> | ||||||
|  |       <Platform>x64</Platform> | ||||||
|  |     </ProjectConfiguration> | ||||||
|  |     <ProjectConfiguration Include="Release|x64"> | ||||||
|  |       <Configuration>Release</Configuration> | ||||||
|  |       <Platform>x64</Platform> | ||||||
|  |     </ProjectConfiguration> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\shell-host.c" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <PropertyGroup Label="Globals"> | ||||||
|  |     <ProjectGuid>{C0AE8A30-E4FA-49CE-A2B5-0C072C77EC64}</ProjectGuid> | ||||||
|  |     <Keyword>Win32Proj</Keyword> | ||||||
|  |     <RootNamespace>shellhost</RootNamespace> | ||||||
|  |     <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion> | ||||||
|  |     <ProjectName>ssh-shellhost</ProjectName> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||||||
|  |     <ConfigurationType>Application</ConfigurationType> | ||||||
|  |     <UseDebugLibraries>true</UseDebugLibraries> | ||||||
|  |     <PlatformToolset>v140</PlatformToolset> | ||||||
|  |     <CharacterSet>Unicode</CharacterSet> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||||||
|  |     <ConfigurationType>Application</ConfigurationType> | ||||||
|  |     <UseDebugLibraries>false</UseDebugLibraries> | ||||||
|  |     <PlatformToolset>v140</PlatformToolset> | ||||||
|  |     <WholeProgramOptimization>true</WholeProgramOptimization> | ||||||
|  |     <CharacterSet>Unicode</CharacterSet> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||||||
|  |     <ConfigurationType>Application</ConfigurationType> | ||||||
|  |     <UseDebugLibraries>true</UseDebugLibraries> | ||||||
|  |     <PlatformToolset>v140</PlatformToolset> | ||||||
|  |     <CharacterSet>Unicode</CharacterSet> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||||||
|  |     <ConfigurationType>Application</ConfigurationType> | ||||||
|  |     <UseDebugLibraries>false</UseDebugLibraries> | ||||||
|  |     <PlatformToolset>v140</PlatformToolset> | ||||||
|  |     <WholeProgramOptimization>true</WholeProgramOptimization> | ||||||
|  |     <CharacterSet>Unicode</CharacterSet> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||||||
|  |   <ImportGroup Label="ExtensionSettings"> | ||||||
|  |   </ImportGroup> | ||||||
|  |   <ImportGroup Label="Shared"> | ||||||
|  |   </ImportGroup> | ||||||
|  |   <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||||||
|  |     <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||||||
|  |   </ImportGroup> | ||||||
|  |   <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||||||
|  |     <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||||||
|  |   </ImportGroup> | ||||||
|  |   <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||||||
|  |     <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||||||
|  |   </ImportGroup> | ||||||
|  |   <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||||||
|  |     <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||||||
|  |   </ImportGroup> | ||||||
|  |   <PropertyGroup Label="UserMacros" /> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||||||
|  |     <LinkIncremental>true</LinkIncremental> | ||||||
|  |     <OutDir>$(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\</OutDir> | ||||||
|  |     <IntDir>$(Platform)\$(Configuration)\$(TargetName)\</IntDir> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||||||
|  |     <LinkIncremental>true</LinkIncremental> | ||||||
|  |     <OutDir>$(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\</OutDir> | ||||||
|  |     <IntDir>$(Platform)\$(Configuration)\$(TargetName)\</IntDir> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||||||
|  |     <LinkIncremental>false</LinkIncremental> | ||||||
|  |     <OutDir>$(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\</OutDir> | ||||||
|  |     <IntDir>$(Platform)\$(Configuration)\$(TargetName)\</IntDir> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||||||
|  |     <LinkIncremental>false</LinkIncremental> | ||||||
|  |     <OutDir>$(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\</OutDir> | ||||||
|  |     <IntDir>$(Platform)\$(Configuration)\$(TargetName)\</IntDir> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||||||
|  |     <ClCompile> | ||||||
|  |       <PrecompiledHeader> | ||||||
|  |       </PrecompiledHeader> | ||||||
|  |       <WarningLevel>Level1</WarningLevel> | ||||||
|  |       <Optimization>Disabled</Optimization> | ||||||
|  |       <PreprocessorDefinitions>_WIN32_WINNT=0x501;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|  |       <SDLCheck>false</SDLCheck> | ||||||
|  |       <AdditionalIncludeDirectories> | ||||||
|  |       </AdditionalIncludeDirectories> | ||||||
|  |       <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | ||||||
|  |       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> | ||||||
|  |     </ClCompile> | ||||||
|  |     <Link> | ||||||
|  |       <SubSystem>Console</SubSystem> | ||||||
|  |       <GenerateDebugInformation>true</GenerateDebugInformation> | ||||||
|  |       <AdditionalDependencies>bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;win32compat.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||||||
|  |       <AdditionalLibraryDirectories>$(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Debug-Path)lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||||||
|  |     </Link> | ||||||
|  |   </ItemDefinitionGroup> | ||||||
|  |   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||||||
|  |     <ClCompile> | ||||||
|  |       <PrecompiledHeader> | ||||||
|  |       </PrecompiledHeader> | ||||||
|  |       <WarningLevel>Level1</WarningLevel> | ||||||
|  |       <Optimization>Disabled</Optimization> | ||||||
|  |       <PreprocessorDefinitions>_WIN32_WINNT=0x501;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|  |       <SDLCheck>false</SDLCheck> | ||||||
|  |       <AdditionalIncludeDirectories> | ||||||
|  |       </AdditionalIncludeDirectories> | ||||||
|  |       <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | ||||||
|  |       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> | ||||||
|  |     </ClCompile> | ||||||
|  |     <Link> | ||||||
|  |       <SubSystem>Console</SubSystem> | ||||||
|  |       <GenerateDebugInformation>true</GenerateDebugInformation> | ||||||
|  |       <AdditionalDependencies>bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;win32compat.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||||||
|  |       <AdditionalLibraryDirectories>$(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Debug-Path)lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||||||
|  |     </Link> | ||||||
|  |   </ItemDefinitionGroup> | ||||||
|  |   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||||||
|  |     <ClCompile> | ||||||
|  |       <WarningLevel>Level1</WarningLevel> | ||||||
|  |       <PrecompiledHeader> | ||||||
|  |       </PrecompiledHeader> | ||||||
|  |       <Optimization>MaxSpeed</Optimization> | ||||||
|  |       <FunctionLevelLinking>true</FunctionLevelLinking> | ||||||
|  |       <IntrinsicFunctions>true</IntrinsicFunctions> | ||||||
|  |       <PreprocessorDefinitions>_WIN32_WINNT=0x501;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|  |       <SDLCheck>false</SDLCheck> | ||||||
|  |       <AdditionalIncludeDirectories> | ||||||
|  |       </AdditionalIncludeDirectories> | ||||||
|  |       <RuntimeLibrary>MultiThreaded</RuntimeLibrary> | ||||||
|  |     </ClCompile> | ||||||
|  |     <Link> | ||||||
|  |       <SubSystem>Console</SubSystem> | ||||||
|  |       <GenerateDebugInformation>No</GenerateDebugInformation> | ||||||
|  |       <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||||||
|  |       <OptimizeReferences>true</OptimizeReferences> | ||||||
|  |       <AdditionalDependencies>bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;win32compat.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||||||
|  |       <AdditionalLibraryDirectories>$(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Release-Path)lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||||||
|  |     </Link> | ||||||
|  |   </ItemDefinitionGroup> | ||||||
|  |   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||||||
|  |     <ClCompile> | ||||||
|  |       <WarningLevel>Level1</WarningLevel> | ||||||
|  |       <PrecompiledHeader> | ||||||
|  |       </PrecompiledHeader> | ||||||
|  |       <Optimization>MaxSpeed</Optimization> | ||||||
|  |       <FunctionLevelLinking>true</FunctionLevelLinking> | ||||||
|  |       <IntrinsicFunctions>true</IntrinsicFunctions> | ||||||
|  |       <PreprocessorDefinitions>_WIN32_WINNT=0x501;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|  |       <SDLCheck>false</SDLCheck> | ||||||
|  |       <AdditionalIncludeDirectories> | ||||||
|  |       </AdditionalIncludeDirectories> | ||||||
|  |       <RuntimeLibrary>MultiThreaded</RuntimeLibrary> | ||||||
|  |     </ClCompile> | ||||||
|  |     <Link> | ||||||
|  |       <SubSystem>Console</SubSystem> | ||||||
|  |       <GenerateDebugInformation>No</GenerateDebugInformation> | ||||||
|  |       <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||||||
|  |       <OptimizeReferences>true</OptimizeReferences> | ||||||
|  |     </Link> | ||||||
|  |   </ItemDefinitionGroup> | ||||||
|  |   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||||||
|  |   <ImportGroup Label="ExtensionTargets"> | ||||||
|  |   </ImportGroup> | ||||||
|  | </Project> | ||||||
| @ -286,13 +286,13 @@ struct passwd *getpwuid(uid_t uid) | |||||||
|    * Get default shell path. |    * Get default shell path. | ||||||
|    */ |    */ | ||||||
|    |    | ||||||
|   GetSystemDirectory(pw_shellpath, MAX_PATH); |   //GetSystemDirectory(pw_shellpath, MAX_PATH);
 | ||||||
|    |    | ||||||
|   debug3("getpwuid: system dir [%s]", pw_shellpath); |   //debug3("getpwuid: system dir [%s]", pw_shellpath);
 | ||||||
|  |   pw_shellpath[0] = '\0'; | ||||||
|  |   strcat(pw_shellpath, "ssh-shellhost.exe"); | ||||||
|    |    | ||||||
|   strcat(pw_shellpath, "\\cmd.exe"); |   //debug3("getpwuid: shell path [%s]", pw_shellpath);
 | ||||||
|    |  | ||||||
|   debug3("getpwuid: shell path [%s]", pw_shellpath); |  | ||||||
| 
 | 
 | ||||||
|   /*
 |   /*
 | ||||||
|    * Get home directory path (if this fails, |    * Get home directory path (if this fails, | ||||||
| @ -381,13 +381,14 @@ struct passwd *getpwnam(const char *userin) | |||||||
|    * Get default shell path. |    * Get default shell path. | ||||||
|    */ |    */ | ||||||
|    |    | ||||||
|   GetSystemDirectory(pw_shellpath, MAX_PATH); |    //GetSystemDirectory(pw_shellpath, MAX_PATH);
 | ||||||
| 
 | 
 | ||||||
|   debug3("getpwnam: system dir [%s]", pw_shellpath); |    //debug3("getpwuid: system dir [%s]", pw_shellpath);
 | ||||||
| 
 | 
 | ||||||
|   strcat(pw_shellpath, "\\cmd.exe"); |   pw_shellpath[0] = '\0'; | ||||||
|  |   strcat(pw_shellpath, "ssh-shellhost.exe"); | ||||||
| 
 | 
 | ||||||
|   debug3("getpwnam: shell path [%s]", pw_shellpath); |   //debug3("getpwuid: shell path [%s]", pw_shellpath);
 | ||||||
| 
 | 
 | ||||||
|   /*
 |   /*
 | ||||||
|    * Copy user name to static structure. |    * Copy user name to static structure. | ||||||
|  | |||||||
| @ -156,6 +156,8 @@ int wmain(int ac, wchar_t **av) { | |||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		while (i < rd) { | 		while (i < rd) { | ||||||
|  | 			/* TODO - handle any pty data*/ | ||||||
|  | 
 | ||||||
| 			/* skip them for now*/ | 			/* skip them for now*/ | ||||||
| 			if ((rd - i >= 3) && (buf[i] == '\033') && (buf[i + 1] == '[') | 			if ((rd - i >= 3) && (buf[i] == '\033') && (buf[i + 1] == '[') | ||||||
| 				&& (buf[i + 2] >= 'A') && (buf[i + 2] <= 'D')) { | 				&& (buf[i + 2] >= 'A') && (buf[i + 2] <= 'D')) { | ||||||
|  | |||||||
							
								
								
									
										169
									
								
								session.c
									
									
									
									
									
								
							
							
						
						
									
										169
									
								
								session.c
									
									
									
									
									
								
							| @ -501,45 +501,6 @@ do_authenticated1(Authctxt *authctxt) | |||||||
| #define USE_PIPES 1 | #define USE_PIPES 1 | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef WIN32_FIXME |  | ||||||
| HANDLE hConIn = NULL; |  | ||||||
| HANDLE hConOut = NULL; |  | ||||||
| HANDLE hConErr = NULL; |  | ||||||
| 
 |  | ||||||
| BOOL MakeNewConsole(void) |  | ||||||
| { |  | ||||||
| 	BOOL bRet = TRUE; |  | ||||||
| 
 |  | ||||||
| 	if (!(bRet = FreeConsole())) return bRet; |  | ||||||
| 	if (!(bRet = AllocConsole())) return bRet; |  | ||||||
| 	HANDLE hTemp; |  | ||||||
| 
 |  | ||||||
| 	hTemp = CreateFile("CONIN$",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,0,OPEN_EXISTING,0,0); |  | ||||||
| 	if (INVALID_HANDLE_VALUE != hTemp) |  | ||||||
| 	{ |  | ||||||
| 		DuplicateHandle(GetCurrentProcess(),hTemp,GetCurrentProcess(),&hConIn, 0,TRUE,DUPLICATE_SAME_ACCESS); |  | ||||||
| 		CloseHandle(hTemp); |  | ||||||
| 	} else |  | ||||||
| 		return FALSE; |  | ||||||
| 
 |  | ||||||
| 	hTemp = CreateFile("CONOUT$",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0); |  | ||||||
| 	if (INVALID_HANDLE_VALUE != hTemp) |  | ||||||
| 	{ |  | ||||||
| 		DuplicateHandle(GetCurrentProcess(),hTemp,GetCurrentProcess(),&hConOut, 0,TRUE,DUPLICATE_SAME_ACCESS); |  | ||||||
| 		DuplicateHandle(GetCurrentProcess(),hTemp,GetCurrentProcess(),&hConErr, 0,TRUE,DUPLICATE_SAME_ACCESS); |  | ||||||
| 		CloseHandle(hTemp); |  | ||||||
| 
 |  | ||||||
| 	} else |  | ||||||
| 		return FALSE; |  | ||||||
| 
 |  | ||||||
| 	SetStdHandle(STD_INPUT_HANDLE,hConIn); |  | ||||||
| 	SetStdHandle(STD_OUTPUT_HANDLE,hConOut); |  | ||||||
| 	SetStdHandle(STD_ERROR_HANDLE,hConErr); |  | ||||||
| 
 |  | ||||||
| 	return TRUE; |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
| /*
 | /*
 | ||||||
|  * This is called to fork and execute a command when we have no tty.  This |  * This is called to fork and execute a command when we have no tty.  This | ||||||
|  * will call do_child from the child, and server_loop from the parent after |  * will call do_child from the child, and server_loop from the parent after | ||||||
| @ -575,9 +536,9 @@ do_exec_no_pty(Session *s, const char *command) | |||||||
|   PROCESS_INFORMATION pi; |   PROCESS_INFORMATION pi; | ||||||
|   STARTUPINFOW si; |   STARTUPINFOW si; | ||||||
|    |    | ||||||
|   int sockin[2]; |   int pipein[2]; | ||||||
|   int sockout[2]; |   int pipeout[2]; | ||||||
|   int sockerr[2]; |   int pipeerr[2]; | ||||||
|    |    | ||||||
|   BOOL b; |   BOOL b; | ||||||
|    |    | ||||||
| @ -626,8 +587,10 @@ do_exec_no_pty(Session *s, const char *command) | |||||||
|   /*
 |   /*
 | ||||||
|    * Create three socket pairs for stdin, stdout and stderr  |    * Create three socket pairs for stdin, stdout and stderr  | ||||||
|    */ |    */ | ||||||
|  |   pipe(pipein); | ||||||
| 
 | 
 | ||||||
|   #ifdef WIN32_PRAGMA_REMCON |   pipe(pipeout); | ||||||
|  |   pipe(pipeerr); | ||||||
| 
 | 
 | ||||||
|   int retcode = -1; |   int retcode = -1; | ||||||
|   if ( (!s -> is_subsystem) && (s ->ttyfd != -1)) |   if ( (!s -> is_subsystem) && (s ->ttyfd != -1)) | ||||||
| @ -637,52 +600,17 @@ do_exec_no_pty(Session *s, const char *command) | |||||||
| 	extern HANDLE hConsole ; | 	extern HANDLE hConsole ; | ||||||
| 	hConsole = GetStdHandle (STD_OUTPUT_HANDLE); | 	hConsole = GetStdHandle (STD_OUTPUT_HANDLE); | ||||||
| 	ConSetScreenSize( s->col, s->row ); | 	ConSetScreenSize( s->col, s->row ); | ||||||
| 	socketpair(sockin); | 	s->ptyfd = pipein[1]; // hConsole; // the pty is the Windows console output handle in our Win32 port
 | ||||||
| 	s->ptyfd = sockin[1]; // hConsole; // the pty is the Windows console output handle in our Win32 port
 |  | ||||||
|   } |   } | ||||||
|   else |  | ||||||
| 	socketpair(sockin); |  | ||||||
|   #else |  | ||||||
|   HANDLE wfdtocmd = -1; |  | ||||||
|   int retcode = -1; |  | ||||||
|   if ((!s->is_subsystem) && (s->ttyfd != -1)) |  | ||||||
|   { |  | ||||||
| 	  //FreeConsole();
 |  | ||||||
| 	  //AllocConsole();
 |  | ||||||
| 	  MakeNewConsole(); |  | ||||||
| 	  prot_scr_width = s->col; |  | ||||||
| 	  prot_scr_height = s->row; |  | ||||||
| 	  extern HANDLE hConsole; |  | ||||||
| 	  hConsole = GetStdHandle(STD_OUTPUT_HANDLE); |  | ||||||
| 	  ConSetScreenSize(s->col, s->row); |  | ||||||
| 	  s->ptyfd = hConsole; // the pty is the Windows console output handle in our Win32 port
 |  | ||||||
| 
 | 
 | ||||||
| 	  wfdtocmd = GetStdHandle(STD_INPUT_HANDLE); // we use this console handle to feed input to Windows shell cmd.exe
 |   debug3("sockin[0]: %d sockin[1]: %d", pipein[0], pipein[1]); | ||||||
| 	  sockin[1] = allocate_sfd((int)wfdtocmd); // put the std input handle in our global general handle table
 |   debug3("sockout[0]: %d sockout[1]: %d", pipeout[0], pipeout[1]); | ||||||
|   } |   debug3("sockerr[0]: %d sockerr[1]: %d", pipeerr[0], pipeerr[1]); | ||||||
|   else |  | ||||||
| 	  pipe(sockin); |  | ||||||
|   #endif |  | ||||||
| 
 | 
 | ||||||
|   pipe(sockout); |  | ||||||
|   pipe(sockerr); |  | ||||||
| 
 | 
 | ||||||
|   debug3("sockin[0]: %d sockin[1]: %d", sockin[0], sockin[1]); |   SetHandleInformation(sfd_to_handle(pipein[1]), HANDLE_FLAG_INHERIT, 0); | ||||||
|   debug3("sockout[0]: %d sockout[1]: %d", sockout[0], sockout[1]); |   SetHandleInformation(sfd_to_handle(pipeout[0]), HANDLE_FLAG_INHERIT, 0); | ||||||
|   debug3("sockerr[0]: %d sockerr[1]: %d", sockerr[0], sockerr[1]); |   SetHandleInformation(sfd_to_handle(pipeerr[0]), HANDLE_FLAG_INHERIT, 0); | ||||||
| 
 |  | ||||||
|   #ifndef WIN32_PRAGMA_REMCON |  | ||||||
|  // if ( (s -> is_subsystem) || (s ->ttyfd == -1))
 |  | ||||||
| 	//crlf_sfd(sockin[1]);
 |  | ||||||
| 
 |  | ||||||
|  // crlf_sfd(sockout[1]);
 |  | ||||||
| 
 |  | ||||||
|   if ( (s -> is_subsystem) || (s ->ttyfd == -1)) |  | ||||||
|   #endif |  | ||||||
| 	  SetHandleInformation(sfd_to_handle(sockin[1]), HANDLE_FLAG_INHERIT, 0); |  | ||||||
| 
 |  | ||||||
|   SetHandleInformation(sfd_to_handle(sockout[1]), HANDLE_FLAG_INHERIT, 0); |  | ||||||
|   SetHandleInformation(sfd_to_handle(sockerr[1]), HANDLE_FLAG_INHERIT, 0); |  | ||||||
| 
 | 
 | ||||||
|   /*
 |   /*
 | ||||||
|    * Assign sockets to StartupInfo  |    * Assign sockets to StartupInfo  | ||||||
| @ -705,23 +633,11 @@ do_exec_no_pty(Session *s, const char *command) | |||||||
|   si.cbReserved2      = 0; |   si.cbReserved2      = 0; | ||||||
|   si.lpReserved2      = 0; |   si.lpReserved2      = 0; | ||||||
| 
 | 
 | ||||||
|   #ifdef WIN32_PRAGMA_REMCON | 	si.hStdInput = (HANDLE) sfd_to_handle(pipein[0]); | ||||||
|   if (0) { | 	si.hStdOutput = (HANDLE) sfd_to_handle(pipeout[1]); | ||||||
|   #else | 	si.hStdError = (HANDLE) sfd_to_handle(pipeerr[1]); | ||||||
|   if ( (!s -> is_subsystem) && (s ->ttyfd != -1) ) { |  | ||||||
|    |  | ||||||
| 	  si.hStdInput = GetStdHandle (STD_INPUT_HANDLE) ; // shell tty interactive session gets a console input for Win32
 |  | ||||||
| 	  si.hStdOutput = (HANDLE) sfd_to_handle(sockout[0]); |  | ||||||
| 	  si.hStdError = (HANDLE) sfd_to_handle(sockerr[0]); |  | ||||||
| 	  si.lpDesktop = NULL ; //winstadtname_w ;
 |  | ||||||
|   #endif |  | ||||||
|   } |  | ||||||
|   else { |  | ||||||
| 	  si.hStdInput = (HANDLE) sfd_to_handle(sockin[0]); |  | ||||||
| 	  si.hStdOutput = (HANDLE) sfd_to_handle(sockout[0]); |  | ||||||
| 	  si.hStdError = (HANDLE) sfd_to_handle(sockerr[0]); |  | ||||||
| 	si.lpDesktop = NULL; //L"winsta0\\default";
 | 	si.lpDesktop = NULL; //L"winsta0\\default";
 | ||||||
|   } | 
 | ||||||
|   //si.wShowWindow = SW_HIDE;
 |   //si.wShowWindow = SW_HIDE;
 | ||||||
|   //si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
 |   //si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
 | ||||||
| 
 | 
 | ||||||
| @ -767,14 +683,14 @@ do_exec_no_pty(Session *s, const char *command) | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   #if 0 |   #if 1 | ||||||
|    |    | ||||||
|   set_nonblock(sockin[0]); |   set_nonblock(pipein[0]); | ||||||
|   set_nonblock(sockin[1]); |   set_nonblock(pipein[1]); | ||||||
|   set_nonblock(sockout[0]); |   set_nonblock(pipeout[0]); | ||||||
|   set_nonblock(sockout[1]); |   set_nonblock(pipeout[1]); | ||||||
|   set_nonblock(sockerr[0]); |   set_nonblock(pipeerr[0]); | ||||||
|   set_nonblock(sockerr[1]); |   set_nonblock(pipeerr[1]); | ||||||
|    |    | ||||||
|   #endif |   #endif | ||||||
| 
 | 
 | ||||||
| @ -931,15 +847,15 @@ do_exec_no_pty(Session *s, const char *command) | |||||||
|    |    | ||||||
|   GetUserName(name, &size); |   GetUserName(name, &size); | ||||||
| 
 | 
 | ||||||
| #ifndef WIN32_PRAGMA_REMCON | //#ifndef WIN32_PRAGMA_REMCON
 | ||||||
|   if ( (!s -> is_subsystem) && (s ->ttyfd != -1)) { | //  if ( (!s -> is_subsystem) && (s ->ttyfd != -1)) {
 | ||||||
| 	  // Send to the remote client ANSI/VT Sequence so that they send us CRLF in place of LF
 | //	  // Send to the remote client ANSI/VT Sequence so that they send us CRLF in place of LF
 | ||||||
| 	  char *inittermseq = "\033[20h\033[?7h\0" ; // LFtoCRLF AUTOWRAPON
 | //	  char *inittermseq = "\033[20h\033[?7h\0" ; // LFtoCRLF AUTOWRAPON
 | ||||||
| 	  Channel *c=channel_by_id ( s->chanid ); | //	  Channel *c=channel_by_id ( s->chanid );
 | ||||||
| 	  buffer_append(&c->input, inittermseq, strlen(inittermseq)); | //	  buffer_append(&c->input, inittermseq, strlen(inittermseq));
 | ||||||
| 	  channel_output_poll(); | //	  channel_output_poll();
 | ||||||
|   } | //  }
 | ||||||
| #endif | //#endif
 | ||||||
| 
 | 
 | ||||||
|   //if (s ->ttyfd != -1) {
 |   //if (s ->ttyfd != -1) {
 | ||||||
|   	  // set the channel to tty interactive type
 |   	  // set the channel to tty interactive type
 | ||||||
| @ -962,7 +878,7 @@ do_exec_no_pty(Session *s, const char *command) | |||||||
|   wchar_t exec_command_w[MAX_PATH]; |   wchar_t exec_command_w[MAX_PATH]; | ||||||
|    |    | ||||||
|   MultiByteToWideChar(CP_UTF8, 0, exec_command, -1, exec_command_w, MAX_PATH); |   MultiByteToWideChar(CP_UTF8, 0, exec_command, -1, exec_command_w, MAX_PATH); | ||||||
|   DWORD	dwStartupFlags = CREATE_SUSPENDED ;  // 0
 |   DWORD	dwStartupFlags = 0;// CREATE_SUSPENDED;  // 0
 | ||||||
|   |   | ||||||
|   SetConsoleCtrlHandler(NULL, FALSE); |   SetConsoleCtrlHandler(NULL, FALSE); | ||||||
|   b = CreateProcessAsUserW(hToken, NULL, exec_command_w, NULL, NULL, TRUE, |   b = CreateProcessAsUserW(hToken, NULL, exec_command_w, NULL, NULL, TRUE, | ||||||
| @ -1020,15 +936,10 @@ do_exec_no_pty(Session *s, const char *command) | |||||||
|   /* 
 |   /* 
 | ||||||
|    * We are the parent.  Close the child sides of the socket pairs.  |    * We are the parent.  Close the child sides of the socket pairs.  | ||||||
|    */ |    */ | ||||||
|   #ifndef WIN32_PRAGMA_REMCON |  | ||||||
|   if ( (s -> is_subsystem) || (s ->ttyfd == -1)) |  | ||||||
| 	close(sockin[0]); |  | ||||||
|   #else |  | ||||||
| 	close(sockin[0]); |  | ||||||
|   #endif |  | ||||||
| 
 | 
 | ||||||
|   close(sockout[0]); |   close(pipein[0]); | ||||||
|   close(sockerr[0]); |   close(pipeout[1]); | ||||||
|  |   close(pipeout[1]); | ||||||
| 
 | 
 | ||||||
|   ResumeThread ( pi.hThread ); /* now let cmd shell main thread be active s we have closed all i/o file handle that cmd will use */ |   ResumeThread ( pi.hThread ); /* now let cmd shell main thread be active s we have closed all i/o file handle that cmd will use */ | ||||||
|   SetConsoleCtrlHandler(NULL, TRUE); |   SetConsoleCtrlHandler(NULL, TRUE); | ||||||
| @ -1057,13 +968,13 @@ do_exec_no_pty(Session *s, const char *command) | |||||||
|   if (compat20)  |   if (compat20)  | ||||||
|   { |   { | ||||||
| 	if ( s->ttyfd == -1) | 	if ( s->ttyfd == -1) | ||||||
| 		session_set_fds(s, sockin[1], sockout[1], sockerr[1], s -> is_subsystem, 0); | 		session_set_fds(s, pipein[1], pipeout[0], pipeerr[0], s -> is_subsystem, 0); | ||||||
| 	else | 	else | ||||||
| 		session_set_fds(s, sockin[1], sockout[1], sockerr[1], s -> is_subsystem, 1); // tty interctive session
 | 		session_set_fds(s, pipein[1], pipeout[0], pipeerr[0], s -> is_subsystem, 1); // tty interctive session
 | ||||||
|   }  |   }  | ||||||
|   else  |   else  | ||||||
|   { |   { | ||||||
|     server_loop(pi.hProcess, sockin[1], sockout[1], sockerr[1]); |     server_loop(pi.hProcess, pipein[1], pipeout[0], pipeerr[0]); | ||||||
|      |      | ||||||
|     /* 
 |     /* 
 | ||||||
|      * server_loop has closed inout[0] and err[0].  |      * server_loop has closed inout[0] and err[0].  | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user