Problem passing telnet socket to spawned process
- From: Bob Watson <BobW@xxxxxxxxxxxxxxxxx>
- Date: Tue, 13 Jun 2006 06:47:01 -0700
We have proprietary software which accepts a telnet connection, creates a new
process and passes the telnet socket down as stdin/stdout/stderr. This
software has run successfully for years, including on Windows XP SP2.
However it fails on one particular PC running Windows XP SP2. The created
process is unable to use the socket handle, setsockopt() gives an error of
10038 - ‘An operation was attempted on something that is not a socket.’.
Test code has been added to the created process to test the socket at the
start of main(). This test code shows the handle to be invalid on entry to
main.
Test code has been added to the telnet server service to ensure that the
socket is still valid after the new process has been created.
The following code segments and comments below show the sequence of events.
Can anyone suggest what the problem might be, or what we should try next?
=============
Telnet server service
=============
EnterCriticalSection(&csSocket);
if (!SetHandleInformation(hIO, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT))
{
EventLog->LogException("LaunchReality",
"SetHandleInformation", GetLastError());
}
pStartInfo->dwFlags |= STARTF_USESTDHANDLES;
pStartInfo->hStdInput =
pStartInfo->hStdOutput =
pStartInfo->hStdError = hIO;
BOOL res = CreateProcessAsUser(UserToken, // User Token
NULL, // -> Name of executable module
pCmd, // -> Command line string
&sa, // -> Process security
attributes
NULL, // -> Thread security attributes
TRUE, // Handle inheritance flag
DETACHED_PROCESS, // Creation flags
Environment, // -> new environment block
StartDirectory, // -> current directory name
pStartInfo, // -> STARTINFO structure
pProcessInfo // -> PROCESS_INFORMATION structure
);
/*>>>> START TEMPORARY SOCKET TEST CODE */
{
int SysErr, FileType;
int TrueI=1; // ==> (A1) Wait here until reach B6 in new
process
FileType = GetFileType(hIO); // ==> (A2) File type 3 – FILE_TYPE_PIPE
if (setsockopt((SOCKET)hIO,SOL_SOCKET,SO_OOBINLINE,
(char*)&TrueI,sizeof TrueI))
{ // ==> (A3) Successful, hIO is HANDLE 0x69c, as in new process
SysErr = GetLastError();
}
}
/*>>>> END TEMPORARY SOCKET TEST CODE */
===============
Newly created process
===============
int main(int argc, char **argv)
{
/*>>>> START TEMPORARY SOCKET TEST CODE */
int SysErr;
int TrueI=1, FileType;
HANDLE SockH;
WSADATA WSAData;
Sleep(30000);
/* Need this compatibility in winsock */
#define WINSOCKREV MAKEWORD(1,1)
SysErr = WSAStartup(WINSOCKREV,&WSAData); // ==> (B1) Successful
if (!SysErr)
{
if ((SockH = GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE)
{ // ==> (B2) Successful, HANDLE
0x69c, as in service
SockH = GetStdHandle(STD_OUTPUT_HANDLE);
}
if (SockH != INVALID_HANDLE_VALUE)
{
FileType = GetFileType(SockH); // ==> (B3) File type 3 –
FILE_TYPE_PIPE
if (setsockopt((SOCKET)SockH,SOL_SOCKET,SO_OOBINLINE,
(char*)&TrueI,sizeof TrueI))
{ // ==> (B4) Failed
SysErr = GetLastError(); // ==> (B5) 10038 - An
operation was attempted on something that is not a socket.
}
}
} // ==> (B6)
/*>>>> END TEMPORARY SOCKET TEST CODE */
-- End --
.
- Follow-Ups:
- RE: Problem passing telnet socket to spawned process
- From: Charles Wang
- Re:Problem passing telnet socket to spawned process
- From: anton bassov
- RE: Problem passing telnet socket to spawned process
- Prev by Date: Re: Linking DLL Statically
- Next by Date: ZwQueryKey with class Name returns 0x80000005 even when supplied with big enough output buffer
- Previous by thread: How is Windows Explorer doing an Alias?
- Next by thread: Re:Problem passing telnet socket to spawned process
- Index(es):
Relevant Pages
|