Я создаю сервис windows, используя windows программирование в c. Я использую CreateService () для его создания! Ни один пользователь не должен иметь доступ к удалению этой службы !, только доступ к удалению должен иметь только .exe-файл этой службы, другие не должны иметь права на удаление! Мне нужно изменить DACL дескриптора безопасности, как мне нужно дать разрешения для опекунов?
Я приложил код для DACL, где мне нужно изменить?
void Update_DACL_Everyone()
{
SC_HANDLE schSCManager = NULL , schService = NULL;
PSECURITY_DESCRIPTOR psd = NULL;
SECURITY_DESCRIPTOR sd;
DWORD dwBytesNeeded = 0 , dwSize = 0 , dwError = 0;
BOOL bDaclPresent = FALSE , bDaclDefaulted = FALSE;
PACL pacl = NULL , pNewAcl = NULL;
EXPLICIT_ACCESS ea;
schSCManager = OpenSCManager( NULL , NULL , SC_MANAGER_ALL_ACCESS );
if (NULL == schSCManager)
{
printf("OpenSCManager failed with error code %d\n", GetLastError());
exit(0);
}
schService = OpenService( schSCManager, ServiceName , READ_CONTROL | WRITE_DAC );
if (schService == NULL)
{
printf("OpenService failed with error code %d\n", GetLastError());
CloseServiceHandle(schSCManager);
exit(0);
}
if(!QueryServiceObjectSecurity( schService , DACL_SECURITY_INFORMATION , psd , 0 , &dwBytesNeeded ))
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
dwSize = dwBytesNeeded;
psd = (PSECURITY_DESCRIPTOR)HeapAlloc( GetProcessHeap() , HEAP_ZERO_MEMORY , dwSize );
if (psd == NULL)
{
printf("HeapAlloc failed with exception\n");
goto dacl_cleanup;
}
if(!QueryServiceObjectSecurity( schService , DACL_SECURITY_INFORMATION , psd , dwSize , &dwBytesNeeded ))
{
printf("QueryServiceObjectSecurity failed with error code %d\n", GetLastError());
goto dacl_cleanup;
}
}
else
{
printf("QueryServiceObjectSecurity failed with error code %d\n", GetLastError());
goto dacl_cleanup;
}
}
if (!GetSecurityDescriptorDacl(psd , &bDaclPresent , &pacl , &bDaclDefaulted))
{
printf("GetSecurityDescriptorDacl failed with error code %d\n", GetLastError());
goto dacl_cleanup;
}
BuildExplicitAccessWithName(&ea,TEXT("Everyone"), READ_CONTROL | SERVICE_QUERY_CONFIG |
SERVICE_QUERY_STATUS | WRITE_DAC,
SET_ACCESS,NO_INHERITANCE);
dwError = SetEntriesInAcl(1, &ea, pacl, &pNewAcl);
if (dwError != ERROR_SUCCESS)
{
printf("SetEntriesInAcl failed with error code %d\n", dwError);
goto dacl_cleanup;
}
if (!InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION))
{
printf("InitializeSecurityDescriptor failed with error code %d\n", GetLastError());
goto dacl_cleanup;
}
if (!SetSecurityDescriptorDacl(&sd,TRUE, pNewAcl, FALSE))
{
printf("SetSecurityDescriptorDacl failed with error code %d\n", GetLastError());
goto dacl_cleanup;
}
if (!SetServiceObjectSecurity(schService , DACL_SECURITY_INFORMATION , &sd))
{
printf("SetServiceObjectSecurity failed with error code %d\n", GetLastError());
goto dacl_cleanup;
}
else printf("Everyone DACL updated successfully\n");
dacl_cleanup:
CloseServiceHandle( schSCManager);
CloseServiceHandle(schService);
if(NULL != pNewAcl)
LocalFree((HLOCAL)pNewAcl);
if(NULL != psd)
HeapFree(GetProcessHeap(), 0, (LPVOID)psd);
}