Author: ekohl
Date: Sat Jun 11 15:01:01 2016
New Revision: 71612
URL:
http://svn.reactos.org/svn/reactos?rev=71612&view=rev
Log:
[SC]
Implement the sdset command.
Added:
trunk/reactos/base/applications/sc/sdset.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] Sat Jun 11 15:01:01
2016
@@ -8,6 +8,7 @@
print.c
query.c
sc.c
+ sdset.c
sdshow.c
start.c
usage.c
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] Sat Jun 11 15:01:01 2016
@@ -191,6 +191,23 @@
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();
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] Sat Jun 11 15:01:01 2016
@@ -20,6 +20,7 @@
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 CreateUsage(VOID);
VOID ControlUsage(VOID);
VOID SdShowUsage(VOID);
+VOID SdSetUsage(VOID);
#endif /* _SC_PCH_ */
Added: trunk/reactos/base/applications/sc/sdset.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/sdset…
==============================================================================
--- trunk/reactos/base/applications/sc/sdset.c (added)
+++ trunk/reactos/base/applications/sc/sdset.c [iso-8859-1] Sat Jun 11 15:01:01 2016
@@ -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;
+}
Propchange: trunk/reactos/base/applications/sc/sdset.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] Sat Jun 11 15:01:01 2016
@@ -42,8 +42,8 @@
_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 @@
_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"));
+}