1

我对 WDK 很陌生,我正在尝试创建一个虚拟打印机驱动程序,它将使用命名管道将数据发送到用户应用程序。我使用“XPSDrv 驱动程序和过滤器示例”作为开始。我在放置此客户端代码的末尾添加了新过滤器:

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);
}

代码适用于控制台应用程序项目,但不适用于 UMDF 打印机驱动程序。服务器也是一个始终启动的控制台应用程序。有人知道为什么吗?或者,也许您知道如何调试打印机驱动程序的简单方法?

一切顺利,丹尼尔

4

2 回答 2

2

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.

于 2012-11-12T18:23:34.963 回答
0

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);
于 2012-11-12T14:34:30.927 回答