ReactOS 0.4.15-dev-8191-gbc6c731
sdset.c File Reference
#include "sc.h"
Include dependency graph for sdset.c:

Go to the source code of this file.

Functions

BOOL SdSet (LPCTSTR ServiceName, LPCTSTR StringSecurityDescriptor)
 

Function Documentation

◆ SdSet()

BOOL SdSet ( LPCTSTR  ServiceName,
LPCTSTR  StringSecurityDescriptor 
)

Definition at line 12 of file sdset.c.

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,
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,
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,
54 pSecurityDescriptor))
55 {
56 _tprintf(_T("[SC] SetServiceObjectSecurity FAILED %lu:\n\n"), GetLastError());
57 bResult = FALSE;
58 goto done;
59 }
60
61done:
62 if (bResult == FALSE)
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}
static WCHAR ServiceName[]
Definition: browser.c:19
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define _tprintf
Definition: tchar.h:506
DWORD ReportLastError(void)
Definition: loadlib.c:67
#define WRITE_DAC
Definition: nt_native.h:59
BOOL WINAPI SetServiceObjectSecurity(SC_HANDLE hService, SECURITY_INFORMATION dwSecurityInformation, PSECURITY_DESCRIPTOR lpSecurityDescriptor)
Definition: scm.c:2774
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
#define ConvertStringSecurityDescriptorToSecurityDescriptor
Definition: sddl.h:162
#define SDDL_REVISION_1
Definition: sddl.h:30
uint32_t ULONG
Definition: typedefs.h:59
#define _T(x)
Definition: vfdio.h:22
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define OpenSCManager
Definition: winsvc.h:575
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
#define OpenService
Definition: winsvc.h:576
#define DACL_SECURITY_INFORMATION
Definition: setypes.h:125

Referenced by ScControl().