Author: ekohl
Date: Tue Jun 7 21:51:37 2016
New Revision: 71590
URL:
http://svn.reactos.org/svn/reactos?rev=71590&view=rev
Log:
[SC]
Add the sdshow command.
Added:
trunk/reactos/base/applications/sc/sdshow.c (with props)
Modified:
trunk/reactos/base/applications/sc/CMakeLists.txt
trunk/reactos/base/applications/sc/sc.c
trunk/reactos/base/applications/sc/sc.h
trunk/reactos/base/applications/sc/usage.c
Modified: trunk/reactos/base/applications/sc/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/CMake…
==============================================================================
--- trunk/reactos/base/applications/sc/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/base/applications/sc/CMakeLists.txt [iso-8859-1] Tue Jun 7 21:51:37
2016
@@ -8,6 +8,7 @@
print.c
query.c
sc.c
+ sdshow.c
start.c
usage.c
sc.h)
Modified: trunk/reactos/base/applications/sc/sc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/sc.c?…
==============================================================================
--- trunk/reactos/base/applications/sc/sc.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/sc/sc.c [iso-8859-1] Tue Jun 7 21:51:37 2016
@@ -179,6 +179,18 @@
else
ControlUsage();
}
+ else if (!lstrcmpi(Command, _T("sdshow")))
+ {
+ if (ArgCount > 0)
+ {
+ ServiceName = *ServiceArgs++;
+ ArgCount--;
+
+ SdShow(ServiceName);
+ }
+ else
+ SdShowUsage();
+ }
else
{
MainUsage();
Modified: trunk/reactos/base/applications/sc/sc.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/sc.h?…
==============================================================================
--- trunk/reactos/base/applications/sc/sc.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/sc/sc.h [iso-8859-1] Tue Jun 7 21:51:37 2016
@@ -6,6 +6,7 @@
#include <windef.h>
#include <winbase.h>
#include <winsvc.h>
+#include <sddl.h>
#include <tchar.h>
#define SCDBG
@@ -18,6 +19,7 @@
BOOL Query(LPCTSTR *ServiceArgs, DWORD ArgCount, BOOL bExtended);
LPSERVICE_STATUS_PROCESS QueryService(LPCTSTR ServiceName);
+BOOL SdShow(LPCTSTR ServiceName);
/* print and error functions */
VOID PrintService(LPCTSTR ServiceName, LPSERVICE_STATUS_PROCESS pStatus, BOOL
bExtended);
@@ -35,5 +37,6 @@
VOID DeleteUsage(VOID);
VOID CreateUsage(VOID);
VOID ControlUsage(VOID);
+VOID SdShowUsage(VOID);
#endif /* _SC_PCH_ */
Added: trunk/reactos/base/applications/sc/sdshow.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/sdsho…
==============================================================================
--- trunk/reactos/base/applications/sc/sdshow.c (added)
+++ trunk/reactos/base/applications/sc/sdshow.c [iso-8859-1] Tue Jun 7 21:51:37 2016
@@ -0,0 +1,101 @@
+/*
+ * PROJECT: ReactOS Services
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: base/applications/sc/sdshow.c
+ * PURPOSE: Show a service security descriptor
+ * COPYRIGHT: Copyright 2016 Eric Kohl
+ *
+ */
+
+#include "sc.h"
+
+BOOL SdShow(LPCTSTR ServiceName)
+{
+ SC_HANDLE hManager = NULL;
+ SC_HANDLE hService = NULL;
+ BOOL bResult = TRUE;
+ DWORD cbBytesNeeded = 0;
+ PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
+ LPTSTR pStringBuffer = NULL;
+
+#ifdef SCDBG
+ _tprintf(_T("service to show sd - %s\n\n"), ServiceName);
+#endif
+
+ hManager = OpenSCManager(NULL,
+ NULL,
+ SC_MANAGER_CONNECT);
+ if (hManager == NULL)
+ {
+ bResult = FALSE;
+ goto done;
+ }
+
+ hService = OpenService(hManager, ServiceName, READ_CONTROL);
+ if (hService == NULL)
+ {
+ bResult = FALSE;
+ goto done;
+ }
+
+ if (!QueryServiceObjectSecurity(hService,
+ DACL_SECURITY_INFORMATION,
+ (PSECURITY_DESCRIPTOR)&pSecurityDescriptor,
+ sizeof(PSECURITY_DESCRIPTOR),
+ &cbBytesNeeded))
+ {
+ if (cbBytesNeeded == 0)
+ {
+ bResult = FALSE;
+ goto done;
+ }
+ }
+
+ pSecurityDescriptor = HeapAlloc(GetProcessHeap(), 0, cbBytesNeeded);
+ if (pSecurityDescriptor == NULL)
+ {
+ SetLastError(ERROR_OUTOFMEMORY);
+ bResult = FALSE;
+ goto done;
+ }
+
+ if (!QueryServiceObjectSecurity(hService,
+ DACL_SECURITY_INFORMATION,
+ pSecurityDescriptor,
+ cbBytesNeeded,
+ &cbBytesNeeded))
+ {
+ bResult = FALSE;
+ goto done;
+ }
+
+ if (!ConvertSecurityDescriptorToStringSecurityDescriptor(pSecurityDescriptor,
+ SDDL_REVISION_1,
+ DACL_SECURITY_INFORMATION,
+ &pStringBuffer,
+ NULL))
+ {
+ bResult = FALSE;
+ goto done;
+ }
+
+ _tprintf(_T("\n%s\n"), pStringBuffer);
+
+done:
+ if (bResult == FALSE)
+ ReportLastError();
+
+ if (pStringBuffer != NULL)
+ LocalFree(pStringBuffer);
+
+ if (pSecurityDescriptor != NULL)
+ HeapFree(GetProcessHeap(), 0, pSecurityDescriptor);
+
+ if (hService)
+ CloseServiceHandle(hService);
+
+ if (hManager)
+ CloseServiceHandle(hManager);
+
+ return bResult;
+}
Propchange: trunk/reactos/base/applications/sc/sdshow.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/base/applications/sc/usage.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/usage…
==============================================================================
--- trunk/reactos/base/applications/sc/usage.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/sc/usage.c [iso-8859-1] Tue Jun 7 21:51:37 2016
@@ -41,8 +41,8 @@
// "\t qfailure : Queries the actions taken by a service upon
failure.\n"
_T("\t delete : Deletes a service (from the registry).\n")
_T("\t create : Creates a service. (adds it to the registry).\n")
- _T("\t control : Sends a control to a service.\n"));
-// "\t sdshow : Displays a service's security descriptor.\n")
+ _T("\t control : Sends a control to a service.\n")
+ _T("\t sdshow : Displays a service's security
descriptor.\n"));
// "\t sdset : Sets a service's security descriptor.\n")
// "\t GetDisplayName : Gets the DisplayName for a service.\n")
// "\t GetKeyName : Gets the ServiceKeyName for a service.\n")
@@ -190,3 +190,11 @@
_T("USAGE:\n")
_T(" sc <server> control [service name]
<value>\n"));
}
+
+VOID SdShowUsage(VOID)
+{
+ _tprintf(_T("DESCRIPTION:\n")
+ _T(" Displays a service's security descriptor in SDDL
format.\n")
+ _T("USAGE:\n")
+ _T(" sc <server> sdshow <service
name>\n"));
+}