mirror of
https://github.com/reactos/reactos.git
synced 2025-01-05 22:12:46 +00:00
[SC]
Add the sdshow command. svn path=/trunk/; revision=71590
This commit is contained in:
parent
4460ce3990
commit
97556cc77d
5 changed files with 127 additions and 2 deletions
|
@ -8,6 +8,7 @@ list(APPEND SOURCE
|
||||||
print.c
|
print.c
|
||||||
query.c
|
query.c
|
||||||
sc.c
|
sc.c
|
||||||
|
sdshow.c
|
||||||
start.c
|
start.c
|
||||||
usage.c
|
usage.c
|
||||||
sc.h)
|
sc.h)
|
||||||
|
|
|
@ -179,6 +179,18 @@ ScControl(LPCTSTR Server, // remote machine name
|
||||||
else
|
else
|
||||||
ControlUsage();
|
ControlUsage();
|
||||||
}
|
}
|
||||||
|
else if (!lstrcmpi(Command, _T("sdshow")))
|
||||||
|
{
|
||||||
|
if (ArgCount > 0)
|
||||||
|
{
|
||||||
|
ServiceName = *ServiceArgs++;
|
||||||
|
ArgCount--;
|
||||||
|
|
||||||
|
SdShow(ServiceName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SdShowUsage();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MainUsage();
|
MainUsage();
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <windef.h>
|
#include <windef.h>
|
||||||
#include <winbase.h>
|
#include <winbase.h>
|
||||||
#include <winsvc.h>
|
#include <winsvc.h>
|
||||||
|
#include <sddl.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
|
|
||||||
#define SCDBG
|
#define SCDBG
|
||||||
|
@ -18,6 +19,7 @@ BOOL Control(DWORD Control, LPCTSTR ServiceName, LPCTSTR *Args, INT ArgCount);
|
||||||
BOOL Query(LPCTSTR *ServiceArgs, DWORD ArgCount, BOOL bExtended);
|
BOOL Query(LPCTSTR *ServiceArgs, DWORD ArgCount, BOOL bExtended);
|
||||||
|
|
||||||
LPSERVICE_STATUS_PROCESS QueryService(LPCTSTR ServiceName);
|
LPSERVICE_STATUS_PROCESS QueryService(LPCTSTR ServiceName);
|
||||||
|
BOOL SdShow(LPCTSTR ServiceName);
|
||||||
|
|
||||||
/* print and error functions */
|
/* print and error functions */
|
||||||
VOID PrintService(LPCTSTR ServiceName, LPSERVICE_STATUS_PROCESS pStatus, BOOL bExtended);
|
VOID PrintService(LPCTSTR ServiceName, LPSERVICE_STATUS_PROCESS pStatus, BOOL bExtended);
|
||||||
|
@ -35,5 +37,6 @@ VOID DescriptionUsage(VOID);
|
||||||
VOID DeleteUsage(VOID);
|
VOID DeleteUsage(VOID);
|
||||||
VOID CreateUsage(VOID);
|
VOID CreateUsage(VOID);
|
||||||
VOID ControlUsage(VOID);
|
VOID ControlUsage(VOID);
|
||||||
|
VOID SdShowUsage(VOID);
|
||||||
|
|
||||||
#endif /* _SC_PCH_ */
|
#endif /* _SC_PCH_ */
|
||||||
|
|
101
reactos/base/applications/sc/sdshow.c
Normal file
101
reactos/base/applications/sc/sdshow.c
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -41,8 +41,8 @@ VOID MainUsage(VOID)
|
||||||
// "\t qfailure : Queries the actions taken by a service upon failure.\n"
|
// "\t qfailure : Queries the actions taken by a service upon failure.\n"
|
||||||
_T("\t delete : Deletes a service (from the registry).\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 create : Creates a service. (adds it to the registry).\n")
|
||||||
_T("\t control : Sends a control to a service.\n"));
|
_T("\t control : Sends a control to a service.\n")
|
||||||
// "\t sdshow : Displays a service's security descriptor.\n")
|
_T("\t sdshow : Displays a service's security descriptor.\n"));
|
||||||
// "\t sdset : Sets 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 GetDisplayName : Gets the DisplayName for a service.\n")
|
||||||
// "\t GetKeyName : Gets the ServiceKeyName for a service.\n")
|
// "\t GetKeyName : Gets the ServiceKeyName for a service.\n")
|
||||||
|
@ -190,3 +190,11 @@ VOID ControlUsage(VOID)
|
||||||
_T("USAGE:\n")
|
_T("USAGE:\n")
|
||||||
_T(" sc <server> control [service name] <value>\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"));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue