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
12 BOOL
SdShow(LPCTSTR ServiceName
)
14 SC_HANDLE hManager
= NULL
;
15 SC_HANDLE hService
= NULL
;
17 DWORD cbBytesNeeded
= 0;
18 PSECURITY_DESCRIPTOR pSecurityDescriptor
= NULL
;
19 LPTSTR pStringBuffer
= NULL
;
22 _tprintf(_T("service to show sd - %s\n\n"), ServiceName
);
25 hManager
= OpenSCManager(NULL
,
30 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
35 hService
= OpenService(hManager
, ServiceName
, READ_CONTROL
);
38 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
43 if (!QueryServiceObjectSecurity(hService
,
44 DACL_SECURITY_INFORMATION
,
45 (PSECURITY_DESCRIPTOR
)&pSecurityDescriptor
,
46 sizeof(PSECURITY_DESCRIPTOR
),
49 if (cbBytesNeeded
== 0)
51 _tprintf(_T("[SC] QueryServiceObjectSecurity FAILED %lu:\n\n"), GetLastError());
57 pSecurityDescriptor
= HeapAlloc(GetProcessHeap(), 0, cbBytesNeeded
);
58 if (pSecurityDescriptor
== NULL
)
60 SetLastError(ERROR_OUTOFMEMORY
);
61 _tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
66 if (!QueryServiceObjectSecurity(hService
,
67 DACL_SECURITY_INFORMATION
,
72 _tprintf(_T("[SC] QueryServiceObjectSecurity FAILED %lu:\n\n"), GetLastError());
77 if (!ConvertSecurityDescriptorToStringSecurityDescriptor(pSecurityDescriptor
,
79 DACL_SECURITY_INFORMATION
,
83 _tprintf(_T("[SC] ConvertSecurityDescriptorToStringSecurityDescriptor FAILED %lu:\n\n"), GetLastError());
88 _tprintf(_T("\n%s\n"), pStringBuffer
);
94 if (pStringBuffer
!= NULL
)
95 LocalFree(pStringBuffer
);
97 if (pSecurityDescriptor
!= NULL
)
98 HeapFree(GetProcessHeap(), 0, pSecurityDescriptor
);
101 CloseServiceHandle(hService
);
104 CloseServiceHandle(hManager
);