1
這裏是我借用的代碼,我不知道在哪裏,也許在這裏或codeguru或codeproject。此代碼是否爲此命名管道設置了任何安全性?
無論如何,我想知道如果我可以只傳遞NULL作爲CreateNamedPipe
中的最後一個參數,或者是sa
結構正在執行超出NULL的某種類型的安全性?
// Setup the named pipe with a security attribute so it is open to anyone that enquires.
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, TRUE, (PACL) NULL, FALSE);
sa.nLength = (DWORD) sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = (LPVOID) &sd;
sa.bInheritHandle = TRUE;
do
{
hPipe = CreateNamedPipe(lpszPipename,PIPE_ACCESS_DUPLEX,PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,PIPE_UNLIMITED_INSTANCES,BUFSIZE,BUFSIZE,5000,&sa);
if (hPipe != INVALID_HANDLE_VALUE)
{
if (ConnectNamedPipe(hPipe, NULL)) {