Question

I'm quite new to WDK, I'm trying to create, a virtual printer driver which will send data to user application using named pipe. I'm using 'XPSDrv Driver and Filter Sample' as start. I've added new filter at the end in which I've put this client code:

HANDLE hPipe; 
LPTSTR lpvMessage=TEXT("Message from UMDF!"); 

BOOL   fSuccess = FALSE; 
DWORD  cbToWrite, cbWritten, dwMode; 
LPTSTR lpszPipename = TEXT("\\\\.\\pipe\\mynamedpipe"); 

  hPipe = CreateFile( 
     lpszPipename,
     //GENERIC_READ |
     GENERIC_WRITE, 
     0,             
     NULL,          
     OPEN_EXISTING, 
     0,             
     NULL);         

dwMode =  PIPE_READMODE_MESSAGE; 
fSuccess = SetNamedPipeHandleState( 
  hPipe,    
  &dwMode,  
  NULL,     
  NULL);    

if (fSuccess) 
{
cbToWrite = (lstrlen(lpvMessage)+1)*sizeof(TCHAR);

fSuccess = WriteFile( 
  hPipe,
  lpvMessage,
  cbToWrite,
  &cbWritten,
  NULL);
}

Code works for a Console Application project, but doesn't work inside UMDF printer driver. Server is also a Console Application which is started all the time. Does someone has idea why? Or maybe you know easy way how can I debug printer drivers?

All the best, Daniel

Was it helpful?

Solution

The reason can be found here:

There is an important difference between an empty and a nonexistent DACL. When a DACL is empty, it contains no access control entries (ACEs); therefore, no access rights are explicitly granted. As a result, access to the object is implicitly denied.

When an object has no DACL (when the pDacl parameter is NULL), no protection is assigned to the object, and all access requests are granted.

You're passing a null pDacl, so you're making the pipe accessible to everyone.

OTHER TIPS

I've added those lines before CreateNamedPipe to my server and now it works, not sure why but it's working. If someone has any idea why I would love to know that. Before that I was haveing NULL passed despite m_pSecAttrib as last CreateNamedPipe parameter.

SECURITY_ATTRIBUTES m_pSecAttrib;
SECURITY_DESCRIPTOR* m_pSecDesc;

  m_pSecDesc = (SECURITY_DESCRIPTOR*)LocalAlloc(LPTR,SECURITY_DESCRIPTOR_MIN_LENGTH);
  InitializeSecurityDescriptor(m_pSecDesc,SECURITY_DESCRIPTOR_REVISION);
  SetSecurityDescriptorDacl(m_pSecDesc,TRUE,(PACL)NULL,FALSE);

  m_pSecAttrib.nLength = sizeof(SECURITY_ATTRIBUTES);
  m_pSecAttrib.bInheritHandle = TRUE;
  m_pSecAttrib.lpSecurityDescriptor = m_pSecDesc;

  Pipe[i].oOverlap.hEvent = hEvents[i]; 

  Pipe[i].hPipeInst = CreateNamedPipe(
     lpszPipename,
     PIPE_ACCESS_DUPLEX |
     FILE_FLAG_OVERLAPPED,
     PIPE_TYPE_MESSAGE |
     PIPE_READMODE_MESSAGE |
     PIPE_ACCEPT_REMOTE_CLIENTS |
     PIPE_WAIT,
     INSTANCES,
     BUFSIZE*sizeof(TCHAR),
     BUFSIZE*sizeof(TCHAR),
     PIPE_TIMEOUT,
     &m_pSecAttrib);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top