| Sharing Objects with a ServiceLast reviewed: December 4, 1996Article ID: Q106387 | 
| The information in this article applies to: 
 
 SUMMARYTo share objects (file mapping, synchronization, and so forth) created by a service, you must place a null DACL (discretionary access-control list) in the security descriptor field when the object is created. This grants everyone access to the object. 
 MORE INFORMATIONThis null DACL is not the same as a NULL, which is used to specify the default security descriptor. For example, the following code can be used to create a mutex with a null DACL: 
    PSECURITY_DESCRIPTOR    pSD;
   SECURITY_ATTRIBUTES     sa;
   pSD = (PSECURITY_DESCRIPTOR) LocalAlloc( LPTR,
                  SECURITY_DESCRIPTOR_MIN_LENGTH);
   if (pSD == NULL)
   {
      Error(...);
   }
   if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION))
   {
      Error(...);
   }
   // Add a NULL DACL to the security descriptor..
   if (!SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE))
   {
      Error(...);
   }
   sa.nLength = sizeof(sa);
   sa.lpSecurityDescriptor = pSD;
   sa.bInheritHandle = TRUE;
   mutex = CreateMutex( &sa, FALSE, "SOMENAME" );
If you are creating one of these objects in an application and the object
will be shared with a service, you could also use a null DACL to grant
everyone access. As an alternative, you could add an access-control entry
(ACE) to the DACL that grants access to the user account that the service
is running under. This would restrict access to the object to the service.For a more detailed example, please see the SERVICES sample. 
 | 
| Additional reference words: 3.10 3.50 
 © 1998 Microsoft Corporation. All rights reserved. Terms of Use. |