ReactOS 0.4.15-dev-5664-g3bf4ef6
sdshow.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/sdshow.c
5 * PURPOSE: Show a service security descriptor
6 * COPYRIGHT: Copyright 2016 Eric Kohl
7 *
8 */
9
10#include "sc.h"
11
13{
14 SC_HANDLE hManager = NULL;
15 SC_HANDLE hService = NULL;
16 BOOL bResult = TRUE;
17 DWORD cbBytesNeeded = 0;
18 PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
19 LPTSTR pStringBuffer = NULL;
20
21#ifdef SCDBG
22 _tprintf(_T("service to show sd - %s\n\n"), ServiceName);
23#endif
24
25 hManager = OpenSCManager(NULL,
26 NULL,
28 if (hManager == NULL)
29 {
30 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
31 bResult = FALSE;
32 goto done;
33 }
34
35 hService = OpenService(hManager, ServiceName, READ_CONTROL);
36 if (hService == NULL)
37 {
38 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
39 bResult = FALSE;
40 goto done;
41 }
42
43 if (!QueryServiceObjectSecurity(hService,
45 (PSECURITY_DESCRIPTOR)&pSecurityDescriptor,
47 &cbBytesNeeded))
48 {
49 if (cbBytesNeeded == 0)
50 {
51 _tprintf(_T("[SC] QueryServiceObjectSecurity FAILED %lu:\n\n"), GetLastError());
52 bResult = FALSE;
53 goto done;
54 }
55 }
56
57 pSecurityDescriptor = HeapAlloc(GetProcessHeap(), 0, cbBytesNeeded);
58 if (pSecurityDescriptor == NULL)
59 {
61 _tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
62 bResult = FALSE;
63 goto done;
64 }
65
66 if (!QueryServiceObjectSecurity(hService,
68 pSecurityDescriptor,
69 cbBytesNeeded,
70 &cbBytesNeeded))
71 {
72 _tprintf(_T("[SC] QueryServiceObjectSecurity FAILED %lu:\n\n"), GetLastError());
73 bResult = FALSE;
74 goto done;
75 }
76
80 &pStringBuffer,
81 NULL))
82 {
83 _tprintf(_T("[SC] ConvertSecurityDescriptorToStringSecurityDescriptor FAILED %lu:\n\n"), GetLastError());
84 bResult = FALSE;
85 goto done;
86 }
87
88 _tprintf(_T("\n%s\n"), pStringBuffer);
89
90done:
91 if (bResult == FALSE)
93
94 if (pStringBuffer != NULL)
95 LocalFree(pStringBuffer);
96
97 if (pSecurityDescriptor != NULL)
98 HeapFree(GetProcessHeap(), 0, pSecurityDescriptor);
99
100 if (hService)
101 CloseServiceHandle(hService);
102
103 if (hManager)
104 CloseServiceHandle(hManager);
105
106 return bResult;
107}
static WCHAR ServiceName[]
Definition: browser.c:19
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define SetLastError(x)
Definition: compat.h:752
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define _tprintf
Definition: tchar.h:506
DWORD ReportLastError(void)
Definition: loadlib.c:67
#define READ_CONTROL
Definition: nt_native.h:58
BOOL WINAPI QueryServiceObjectSecurity(SC_HANDLE hService, SECURITY_INFORMATION dwSecurityInformation, PSECURITY_DESCRIPTOR lpSecurityDescriptor, DWORD cbBufSize, LPDWORD pcbBytesNeeded)
Definition: scm.c:2680
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
#define ConvertSecurityDescriptorToStringSecurityDescriptor
Definition: sddl.h:164
#define SDDL_REVISION_1
Definition: sddl.h:30
BOOL SdShow(LPCTSTR ServiceName)
Definition: sdshow.c:12
#define _T(x)
Definition: vfdio.h:22
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#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
CHAR * LPTSTR
Definition: xmlstorage.h:192