Named pipes over different processes
-
I am using the following code to create a named pipe
SECURITY_ATTRIBUTES saPipeSecurity = {0}; PSECURITY_DESCRIPTOR pPipeSD = NULL; if(lpSecurityAttributes == NULL) { // alloc & init SD if ( ! ( pPipeSD = ( PSECURITY_DESCRIPTOR) ( malloc ( SECURITY_DESCRIPTOR_MIN_LENGTH)) ) ) return FALSE; if ( ! InitializeSecurityDescriptor ( pPipeSD, SECURITY_DESCRIPTOR_REVISION) ) return FALSE; // set NULL DACL on the SD if ( ! SetSecurityDescriptorDacl ( pPipeSD, TRUE, ( PACL) NULL, FALSE) ) return FALSE; // now set up the security attributes saPipeSecurity.nLength = sizeof ( SECURITY_ATTRIBUTES); saPipeSecurity.bInheritHandle = TRUE; saPipeSecurity.lpSecurityDescriptor = pPipeSD; lpSecurityAttributes = &saPipeSecurity; } m_hPipe = ::CreateNamedPipe(pszPipeName, dwOpenMode, dwPipeMode, dwMaxInstances, dwOutBufferSize, dwInBufferSize, dwDefaultTimeOut, lpSecurityAttributes);
then I use a CreateProcessWithLogonW to spawn a new process that connect to this pipe using CreateFile. The createfile fails and return last error gives 5(access denied). Can anybody guess what I am doing wrong. -
I am using the following code to create a named pipe
SECURITY_ATTRIBUTES saPipeSecurity = {0}; PSECURITY_DESCRIPTOR pPipeSD = NULL; if(lpSecurityAttributes == NULL) { // alloc & init SD if ( ! ( pPipeSD = ( PSECURITY_DESCRIPTOR) ( malloc ( SECURITY_DESCRIPTOR_MIN_LENGTH)) ) ) return FALSE; if ( ! InitializeSecurityDescriptor ( pPipeSD, SECURITY_DESCRIPTOR_REVISION) ) return FALSE; // set NULL DACL on the SD if ( ! SetSecurityDescriptorDacl ( pPipeSD, TRUE, ( PACL) NULL, FALSE) ) return FALSE; // now set up the security attributes saPipeSecurity.nLength = sizeof ( SECURITY_ATTRIBUTES); saPipeSecurity.bInheritHandle = TRUE; saPipeSecurity.lpSecurityDescriptor = pPipeSD; lpSecurityAttributes = &saPipeSecurity; } m_hPipe = ::CreateNamedPipe(pszPipeName, dwOpenMode, dwPipeMode, dwMaxInstances, dwOutBufferSize, dwInBufferSize, dwDefaultTimeOut, lpSecurityAttributes);
then I use a CreateProcessWithLogonW to spawn a new process that connect to this pipe using CreateFile. The createfile fails and return last error gives 5(access denied). Can anybody guess what I am doing wrong.but what kind of a value does dwOpenMode have? Access specified when a pipe is opened (CreateFile) must be compatible with the access specified in the dwOpenMode (CreateNamedPipe). if PIPE_ACCESS_OUTBOUND or PIPE_ACCESS_INBOUND you must call CreateFile with GENERIC_READ, GENERIC_WRITE accordingly as dwDesiredAccess param.
-
but what kind of a value does dwOpenMode have? Access specified when a pipe is opened (CreateFile) must be compatible with the access specified in the dwOpenMode (CreateNamedPipe). if PIPE_ACCESS_OUTBOUND or PIPE_ACCESS_INBOUND you must call CreateFile with GENERIC_READ, GENERIC_WRITE accordingly as dwDesiredAccess param.