Microsoft KB Archive/94839

{|
 * width="100%"|

-

The information in this article applies to:


 * Microsoft Win32 Application Programming Interface (API), included with:
 * Microsoft Windows NT, versions 3.1, 3.5

-

SUMMARY
All Win32 APIs that allow security to be specified take a parameter of type LPSECURITY_ATTRIBUTES as the means to attach the security descriptor. However, it is a common error to pass a PSECURITY_DESCRIPTOR type to such functions instead. Because PSECURITY_DESCRIPTOR is of type LPVOID (for opaque data-type reasons), by C Language definition, it is implicitly converted to the correct type. Therefore, the compiler does not generate any warnings; however, unexpected run-time errors will result.

MORE INFORMATION
Below is a correct example of creating a named pipe with a security descriptor attached.

Sample Code
  saSecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); saSecurityAttributes.lpSecurityDescriptor = psdAbsoluteSD; saSecurityAttributes.bInheritHandle = FALSE;

hPipe = CreateNamedPipe(TEST_PIPE_NAME,                          PIPE_ACCESS_DUPLEX,

(PIPE_TYPE_BYTE|PIPE_READMODE_BYTE|PIPE_WAIT), 100, // maximum instances 0,   // output buffer, sized as needed 0,   // input buffer, sized as needed 100, // timeout in milliseconds

(LPSECURITY_ATTRIBUTES)&saSecurityAttributes);  if( INVALID_HANDLE_VALUE == hPipe )   { // handle error   } Additional query words: 3.10 3.50

Keywords         : Version          : winnt:3.1,3.5 Platform         : winnt Issue type       :
 * }