Implement the sdset command.

svn path=/trunk/; revision=71612
This commit is contained in:
Eric Kohl 2016-06-11 15:01:01 +00:00
parent 5965ffcd78
commit 45cc914e9f
5 changed files with 101 additions and 2 deletions

View file

@ -8,6 +8,7 @@ list(APPEND SOURCE
print.c
query.c
sc.c
sdset.c
sdshow.c
start.c
usage.c

View file

@ -191,6 +191,23 @@ ScControl(LPCTSTR Server, // remote machine name
else
SdShowUsage();
}
else if (!lstrcmpi(Command, _T("sdset")))
{
LPCTSTR SecurityDescriptor;
if (ArgCount > 1)
{
ServiceName = *ServiceArgs++;
ArgCount--;
SecurityDescriptor = *ServiceArgs++;
ArgCount--;
SdSet(ServiceName, SecurityDescriptor);
}
else
SdSetUsage();
}
else
{
MainUsage();

View file

@ -20,6 +20,7 @@ BOOL Query(LPCTSTR *ServiceArgs, DWORD ArgCount, BOOL bExtended);
LPSERVICE_STATUS_PROCESS QueryService(LPCTSTR ServiceName);
BOOL SdShow(LPCTSTR ServiceName);
BOOL SdSet(LPCTSTR ServiceName, LPCTSTR SecurityDescriptor);
/* print and error functions */
VOID PrintService(LPCTSTR ServiceName, LPSERVICE_STATUS_PROCESS pStatus, BOOL bExtended);
@ -38,5 +39,6 @@ VOID DeleteUsage(VOID);
VOID CreateUsage(VOID);
VOID ControlUsage(VOID);
VOID SdShowUsage(VOID);
VOID SdSetUsage(VOID);
#endif /* _SC_PCH_ */

View file

@ -0,0 +1,71 @@
/*
* PROJECT: ReactOS Services
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/applications/sc/sdset.c
* PURPOSE: Set a service security descriptor
* COPYRIGHT: Copyright 2016 Eric Kohl
*
*/
#include "sc.h"
BOOL SdSet(LPCTSTR ServiceName, LPCTSTR StringSecurityDescriptor)
{
SC_HANDLE hManager = NULL;
SC_HANDLE hService = NULL;
BOOL bResult = TRUE;
ULONG ulSecurityDescriptorSize = 0;
PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
#ifdef SCDBG
_tprintf(_T("service to set sd - %s\n\n"), ServiceName);
#endif
hManager = OpenSCManager(NULL,
NULL,
SC_MANAGER_CONNECT);
if (hManager == NULL)
{
bResult = FALSE;
goto done;
}
hService = OpenService(hManager, ServiceName, WRITE_DAC);
if (hService == NULL)
{
bResult = FALSE;
goto done;
}
if (!ConvertStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
SDDL_REVISION_1,
&pSecurityDescriptor,
&ulSecurityDescriptorSize))
{
bResult = FALSE;
goto done;
}
if (!SetServiceObjectSecurity(hService,
DACL_SECURITY_INFORMATION,
pSecurityDescriptor))
{
bResult = FALSE;
goto done;
}
done:
if (bResult == FALSE)
ReportLastError();
if (pSecurityDescriptor != NULL)
LocalFree(pSecurityDescriptor);
if (hService)
CloseServiceHandle(hService);
if (hManager)
CloseServiceHandle(hManager);
return bResult;
}

View file

@ -42,8 +42,8 @@ VOID MainUsage(VOID)
_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("\t sdshow : Displays a service's security descriptor.\n"));
// "\t sdset : Sets a service's security descriptor.\n")
_T("\t sdshow : Displays a service's security descriptor.\n")
_T("\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")
// "\t EnumDepend : Enumerates Service Dependencies.\n")
@ -198,3 +198,11 @@ VOID SdShowUsage(VOID)
_T("USAGE:\n")
_T(" sc <server> sdshow <service name>\n"));
}
VOID SdSetUsage(VOID)
{
_tprintf(_T("DESCRIPTION:\n")
_T(" Sets a service's security descriptor.\n")
_T("USAGE:\n")
_T(" sc <server> sdset <service name> <SD in SDDL format>\n"));
}