ReactOS 0.4.16-dev-329-g9223134
sdset.c
Go to the documentation of this file.
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
12BOOL 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,
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
BOOL SdSet(LPCTSTR ServiceName, LPCTSTR StringSecurityDescriptor)
Definition: sdset.c:12
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
const CHAR * LPCTSTR
Definition: xmlstorage.h:193