Platform SDK: Access Control |
The QueryServiceObjectSecurity function retrieves a copy of the security descriptor associated with a service object.
Windows NT 4.0 and later: You can use the GetNamedSecurityInfo function.
BOOL QueryServiceObjectSecurity( SC_HANDLE hService, // handle to service SECURITY_INFORMATION dwSecurityInformation, // request PSECURITY_DESCRIPTOR lpSecurityDescriptor, // SD DWORD cbBufSize, // size of SD LPDWORD pcbBytesNeeded // bytes needed );
Value | Meaning |
---|---|
DACL_SECURITY_INFORMATION | Requests the object's discretionary access control list (ACL). |
GROUP_SECURITY_INFORMATION | Requests the object's primary group SID. |
OWNER_SECURITY_INFORMATION | Requests the object's owner security identifier (SID). |
SACL_SECURITY_INFORMATION | Requests the object's system ACL. The calling process must have the SE_SECURITY_NAME privilege. The proper way to obtain this access is to enable the SE_SECURITY_NAME privilege in the caller's current access token, open the handle for ACCESS_SYSTEM_SECURITY access, and then disable the privilege. |
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
The following error codes may be set by the service control manager. Other error codes may be set by the registry functions that are called by the service control manager.
Value | Meaning |
---|---|
ERROR_ACCESS_DENIED | The specified handle was not opened with READ_CONTROL access, or the calling process is not the owner of the object. |
ERROR_INVALID_HANDLE | The specified handle is invalid. |
ERROR_INSUFFICIENT_BUFFER | There is more security descriptor information than would fit into the lpSecurityDescriptor buffer. The number of bytes required to get all the information is returned in the pcbBytesNeeded parameter. Nothing is written to the lpSecurityDescriptor buffer. |
ERROR_INVALID_PARAMETER | The specified security information is invalid. |
When a service is created, the service control manager assigns a default security descriptor to the service object. To retrieve a copy of the security descriptor for a service object, call the QueryServiceObjectSecurity function. To change the security descriptor, call the SetServiceObjectSecurity function. For a description of the default security descriptor for a service object, see Service Security.
To read the owner, group, or DACL from the service object's security descriptor, the calling process must have been granted READ_CONTROL access when the handle was opened. To get READ_CONTROL access, the caller must be the owner of the object or the object's DACL must grant the access.
To read the SACL from the security descriptor, the calling process must have been granted ACCESS_SYSTEM_SECURITY access when the handle was opened. The proper way to get this access is to enable the SE_SECURITY_NAME privilege in the caller's current token, open the handle for ACCESS_SYSTEM_SECURITY access, and then disable the privilege.
Windows NT/2000: Requires Windows NT 3.1 or later.
Header: Declared in Winsvc.h; include Windows.h.
Library: Use Advapi32.lib.
Low-Level Access-Control Overview, Low-Level Access Control Functions, CreateService, OpenService, SECURITY_DESCRIPTOR, SetServiceObjectSecurity