[RAPPS] Bulk install!
[reactos.git] / reactos / base / applications / sc / sdset.c
1 /*
2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/sc/sdset.c
5 * PURPOSE: Set a service security descriptor
6 * COPYRIGHT: Copyright 2016 Eric Kohl
7 *
8 */
9
10 #include "sc.h"
11
12 BOOL SdSet(LPCTSTR ServiceName, LPCTSTR StringSecurityDescriptor)
13 {
14 SC_HANDLE hManager = NULL;
15 SC_HANDLE hService = NULL;
16 BOOL bResult = TRUE;
17 ULONG ulSecurityDescriptorSize = 0;
18 PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
19
20 #ifdef SCDBG
21 _tprintf(_T("service to set sd - %s\n\n"), ServiceName);
22 #endif
23
24 hManager = OpenSCManager(NULL,
25 NULL,
26 SC_MANAGER_CONNECT);
27 if (hManager == NULL)
28 {
29 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
30 bResult = FALSE;
31 goto done;
32 }
33
34 hService = OpenService(hManager, ServiceName, WRITE_DAC);
35 if (hService == NULL)
36 {
37 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
38 bResult = FALSE;
39 goto done;
40 }
41
42 if (!ConvertStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
43 SDDL_REVISION_1,
44 &pSecurityDescriptor,
45 &ulSecurityDescriptorSize))
46 {
47 _tprintf(_T("[SC] ConvertStringSecurityDescriptorToSecurityDescriptor FAILED %lu:\n\n"), GetLastError());
48 bResult = FALSE;
49 goto done;
50 }
51
52 if (!SetServiceObjectSecurity(hService,
53 DACL_SECURITY_INFORMATION,
54 pSecurityDescriptor))
55 {
56 _tprintf(_T("[SC] SetServiceObjectSecurity FAILED %lu:\n\n"), GetLastError());
57 bResult = FALSE;
58 goto done;
59 }
60
61 done:
62 if (bResult == FALSE)
63 ReportLastError();
64
65 if (pSecurityDescriptor != NULL)
66 LocalFree(pSecurityDescriptor);
67
68 if (hService)
69 CloseServiceHandle(hService);
70
71 if (hManager)
72 CloseServiceHandle(hManager);
73
74 return bResult;
75 }