Skip to content

Commit d401788

Browse files
committed
-Add QueryServiceConfig2A stub.
-Implement QueryServiceObjectSecurity and SetServiceObjectSecurity. svn path=/trunk/; revision=20311
1 parent e0189ae commit d401788

File tree

5 files changed

+226
-32
lines changed

5 files changed

+226
-32
lines changed

reactos/include/idl/svcctl.idl

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define BOOL unsigned long
1111
#define SC_HANDLE unsigned int
1212
#define SC_LOCK unsigned int
13+
#define SERVICE_STATUS_HANDLE unsigned long
1314
#define LPSTR char*
1415
#define LPCSTR char*
1516
#define LPWSTR wchar_t*
@@ -57,18 +58,28 @@ cpp_quote("#endif")
5758
[out] SC_LOCK *hLock);
5859

5960
/* Function 4 */
60-
DWORD ScmrQueryServiceObjectSecurity([in] handle_t BindingHandle); /* FIXME */
61+
DWORD ScmrQueryServiceObjectSecurity([in] handle_t BindingHandle,
62+
[in] SC_HANDLE hService,
63+
[in] DWORD dwSecurityInformation,
64+
[out, size_is(dwSecuityDescriptorSize)] unsigned char *lpSecurityDescriptor,
65+
[in] DWORD dwSecuityDescriptorSize,
66+
[out] LPDWORD pcbBytesNeeded);
6167

6268
/* Function 5 */
63-
DWORD ScmrSetServiceObjectSecurity([in] handle_t BindingHandle); /* FIXME */
69+
DWORD ScmrSetServiceObjectSecurity([in] handle_t BindingHandle,
70+
[in] SC_HANDLE hService,
71+
[in] DWORD dwSecurityInformation,
72+
[in, size_is(dwSecuityDescriptorSize)] unsigned char *lpSecurityDescriptor,
73+
[in] DWORD dwSecuityDescriptorSize);
6474

6575
/* Function 6 */
6676
DWORD ScmrQueryServiceStatus([in] handle_t BindingHandle,
6777
[in] SC_HANDLE hSCManager,
6878
[out] LPSERVICE_STATUS lpServiceStatus);
6979

7080
/* Function 7 */
71-
DWORD ScmrSetServiceStatus([in] handle_t BindingHandle); /* FIXME */
81+
DWORD ScmrSetServiceStatus([in] handle_t BindingHandle,
82+
[in] SERVICE_STATUS_HANDLE hServiceStatus); /* FIXME */
7283

7384
/* Function 8 */
7485
DWORD ScmrUnlockServiceDatabase([in] handle_t BindingHandle,
@@ -78,6 +89,13 @@ cpp_quote("#endif")
7889
DWORD ScmrNotifyBootConfigStatus([in] handle_t BindingHandle,
7990
[in] BOOL BootAcceptable);
8091

92+
/* Function 10 */
93+
DWORD ScmrI_ScSetServiceBitsW([in] handle_t BindingHandle,
94+
[in] SERVICE_STATUS_HANDLE hServiceStatus,
95+
[in] DWORD dwServiceBits,
96+
[in] BOOL bSetBitsOn,
97+
[in] BOOL bUpdateImmediately,
98+
[in, string, unique] LPWSTR lpString);
8199

82100
/* Function 11 */
83101
DWORD ScmrChangeServiceConfigW([in] handle_t BindingHandle,
@@ -132,7 +150,7 @@ cpp_quote("#endif")
132150
[in] DWORD dwBufSize,
133151
[out] LPDWORD pcbBytesNeeded,
134152
[out] LPDWORD lpServicesReturned,
135-
[in, out] LPDWORD lpResumeHandle); /* FIXME: unique */
153+
[in, out, unique] LPDWORD lpResumeHandle);
136154

137155
/* Function 15 */
138156
DWORD ScmrOpenSCManagerW([in] handle_t BindingHandle,

reactos/lib/advapi32/advapi32.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ PrivilegedServiceAuditAlarmW@20
449449
;QueryAllTracesA
450450
;QueryAllTracesW
451451
QueryRecoveryAgentsOnEncryptedFile@8
452-
;QueryServiceConfig2A@20
452+
QueryServiceConfig2A@20
453453
QueryServiceConfig2W@20
454454
QueryServiceConfigA@16
455455
QueryServiceConfigW@16

reactos/lib/advapi32/service/scm.c

Lines changed: 105 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,8 +1035,7 @@ QueryServiceConfigA(
10351035
*
10361036
* @implemented
10371037
*/
1038-
BOOL
1039-
STDCALL
1038+
BOOL STDCALL
10401039
QueryServiceConfigW(SC_HANDLE hService,
10411040
LPQUERY_SERVICE_CONFIGW lpServiceConfig,
10421041
DWORD cbBufSize,
@@ -1094,22 +1093,40 @@ QueryServiceConfigW(SC_HANDLE hService,
10941093
}
10951094

10961095

1096+
/**********************************************************************
1097+
* QueryServiceConfig2A
1098+
*
1099+
* @unimplemented
1100+
*/
1101+
BOOL
1102+
STDCALL
1103+
QueryServiceConfig2A(
1104+
SC_HANDLE hService,
1105+
DWORD dwInfo,
1106+
LPBYTE lpBuffer,
1107+
DWORD cbBufSize,
1108+
LPDWORD pcbBytesNeeded)
1109+
{
1110+
DPRINT1("QueryServiceConfig2A is unimplemented\n");
1111+
return FALSE;
1112+
}
1113+
1114+
10971115
/**********************************************************************
10981116
* QueryServiceConfig2W
10991117
*
11001118
* @unimplemented
11011119
*/
11021120
BOOL
11031121
STDCALL
1104-
QueryServiceConfig2W
1105-
(
1122+
QueryServiceConfig2W(
11061123
SC_HANDLE hService,
11071124
DWORD dwInfo,
11081125
LPBYTE lpBuffer,
11091126
DWORD cbBufSize,
11101127
LPDWORD pcbBytesNeeded)
11111128
{
1112-
DPRINT1("QueryServiceConfigW2 is unimplemented\n");
1129+
DPRINT1("QueryServiceConfig2W is unimplemented\n");
11131130
return FALSE;
11141131
}
11151132

@@ -1155,20 +1172,37 @@ QueryServiceLockStatusW(
11551172
/**********************************************************************
11561173
* QueryServiceObjectSecurity
11571174
*
1158-
* @unimplemented
1175+
* @implemented
11591176
*/
1160-
BOOL
1161-
STDCALL
1162-
QueryServiceObjectSecurity(
1163-
SC_HANDLE hService,
1164-
SECURITY_INFORMATION dwSecurityInformation,
1165-
PSECURITY_DESCRIPTOR lpSecurityDescriptor,
1166-
DWORD cbBufSize,
1167-
LPDWORD pcbBytesNeeded)
1177+
BOOL STDCALL
1178+
QueryServiceObjectSecurity(SC_HANDLE hService,
1179+
SECURITY_INFORMATION dwSecurityInformation,
1180+
PSECURITY_DESCRIPTOR lpSecurityDescriptor,
1181+
DWORD cbBufSize,
1182+
LPDWORD pcbBytesNeeded)
11681183
{
1169-
DPRINT1("QueryServiceObjectSecurity is unimplemented\n");
1170-
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1171-
return FALSE;
1184+
DWORD dwError;
1185+
1186+
DPRINT("QueryServiceObjectSecurity(%p, %lu, %p)\n",
1187+
hService, dwSecurityInformation, lpSecurityDescriptor);
1188+
1189+
HandleBind();
1190+
1191+
/* Call to services.exe using RPC */
1192+
dwError = ScmrQueryServiceObjectSecurity(BindingHandle,
1193+
(unsigned int)hService,
1194+
dwSecurityInformation,
1195+
(unsigned char *)lpSecurityDescriptor,
1196+
cbBufSize,
1197+
pcbBytesNeeded);
1198+
if (dwError != ERROR_SUCCESS)
1199+
{
1200+
DPRINT1("QueryServiceObjectSecurity() failed (Error %lu)\n", dwError);
1201+
SetLastError(dwError);
1202+
return FALSE;
1203+
}
1204+
1205+
return TRUE;
11721206
}
11731207

11741208

@@ -1225,15 +1259,64 @@ QueryServiceStatusEx(SC_HANDLE hService,
12251259
/**********************************************************************
12261260
* SetServiceObjectSecurity
12271261
*
1228-
* @unimplemented
1262+
* @implemented
12291263
*/
12301264
BOOL STDCALL
12311265
SetServiceObjectSecurity(SC_HANDLE hService,
1232-
SECURITY_INFORMATION dwSecurityInformation,
1233-
PSECURITY_DESCRIPTOR lpSecurityDescriptor)
1266+
SECURITY_INFORMATION dwSecurityInformation,
1267+
PSECURITY_DESCRIPTOR lpSecurityDescriptor)
12341268
{
1235-
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1236-
return FALSE;
1269+
PSECURITY_DESCRIPTOR SelfRelativeSD = NULL;
1270+
ULONG Length;
1271+
NTSTATUS Status;
1272+
DWORD dwError;
1273+
1274+
Length = 0;
1275+
Status = RtlMakeSelfRelativeSD(lpSecurityDescriptor,
1276+
SelfRelativeSD,
1277+
&Length);
1278+
if (Status != STATUS_BUFFER_TOO_SMALL)
1279+
{
1280+
SetLastError(ERROR_INVALID_PARAMETER);
1281+
return FALSE;
1282+
}
1283+
1284+
SelfRelativeSD = HeapAlloc(GetProcessHeap(), 0, Length);
1285+
if (SelfRelativeSD == NULL)
1286+
{
1287+
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1288+
return FALSE;
1289+
}
1290+
1291+
Status = RtlMakeSelfRelativeSD(lpSecurityDescriptor,
1292+
SelfRelativeSD,
1293+
&Length);
1294+
if (!NT_SUCCESS(Status))
1295+
{
1296+
HeapFree(GetProcessHeap(), 0, SelfRelativeSD);
1297+
SetLastError(RtlNtStatusToDosError(Status));
1298+
return FALSE;
1299+
}
1300+
1301+
HandleBind();
1302+
1303+
/* Call to services.exe using RPC */
1304+
dwError = ScmrSetServiceObjectSecurity(BindingHandle,
1305+
(unsigned int)hService,
1306+
dwSecurityInformation,
1307+
(unsigned char *)SelfRelativeSD,
1308+
Length);
1309+
1310+
HeapFree(GetProcessHeap(), 0, SelfRelativeSD);
1311+
1312+
if (dwError != ERROR_SUCCESS)
1313+
{
1314+
DPRINT1("ScmrServiceObjectSecurity() failed (Error %lu)\n", dwError);
1315+
SetLastError(dwError);
1316+
return FALSE;
1317+
}
1318+
1319+
return TRUE;
12371320
}
12381321

12391322

reactos/subsys/system/services/rpcserver.c

Lines changed: 96 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,16 +453,91 @@ ScmrLockServiceDatabase(handle_t BindingHandle,
453453

454454
/* Function 4 */
455455
unsigned long
456-
ScmrQueryServiceObjectSecurity(handle_t BindingHandle)
456+
ScmrQueryServiceObjectSecurity(handle_t BindingHandle,
457+
unsigned int hService,
458+
unsigned long dwSecurityInformation,
459+
unsigned char *lpSecurityDescriptor,
460+
unsigned long dwSecuityDescriptorSize,
461+
unsigned long *pcbBytesNeeded)
457462
{
458-
DPRINT1("ScmrQueryServiceSecurity() is unimplemented\n");
459-
return ERROR_CALL_NOT_IMPLEMENTED;
463+
PSERVICE_HANDLE hSvc;
464+
PSERVICE lpService;
465+
ULONG DesiredAccess = 0;
466+
NTSTATUS Status;
467+
DWORD dwBytesNeeded;
468+
DWORD dwError;
469+
470+
DPRINT("ScmrQueryServiceSecurity() called\n");
471+
472+
hSvc = (PSERVICE_HANDLE)hService;
473+
if (hSvc->Handle.Tag != SERVICE_TAG)
474+
{
475+
DPRINT1("Invalid handle tag!\n");
476+
return ERROR_INVALID_HANDLE;
477+
}
478+
479+
if (dwSecurityInformation & (DACL_SECURITY_INFORMATION ||
480+
GROUP_SECURITY_INFORMATION ||
481+
OWNER_SECURITY_INFORMATION))
482+
DesiredAccess |= READ_CONTROL;
483+
484+
if (dwSecurityInformation & SACL_SECURITY_INFORMATION)
485+
DesiredAccess |= ACCESS_SYSTEM_SECURITY;
486+
487+
if (!RtlAreAllAccessesGranted(hSvc->Handle.DesiredAccess,
488+
DesiredAccess))
489+
{
490+
DPRINT1("Insufficient access rights! 0x%lx\n", hSvc->Handle.DesiredAccess);
491+
return ERROR_ACCESS_DENIED;
492+
}
493+
494+
lpService = hSvc->ServiceEntry;
495+
if (lpService == NULL)
496+
{
497+
DPRINT1("lpService == NULL!\n");
498+
return ERROR_INVALID_HANDLE;
499+
}
500+
501+
/* FIXME: Lock the service list */
502+
503+
Status = RtlQuerySecurityObject(lpService->lpSecurityDescriptor,
504+
dwSecurityInformation,
505+
(PSECURITY_DESCRIPTOR)lpSecurityDescriptor,
506+
dwSecuityDescriptorSize,
507+
&dwBytesNeeded);
508+
509+
/* FIXME: Unlock the service list */
510+
511+
if (NT_SUCCESS(Status))
512+
{
513+
*pcbBytesNeeded = dwBytesNeeded;
514+
dwError = STATUS_SUCCESS;
515+
}
516+
else if (Status == STATUS_BUFFER_TOO_SMALL)
517+
{
518+
*pcbBytesNeeded = dwBytesNeeded;
519+
dwError = ERROR_INSUFFICIENT_BUFFER;
520+
}
521+
else if (Status == STATUS_BAD_DESCRIPTOR_FORMAT)
522+
{
523+
dwError = ERROR_GEN_FAILURE;
524+
}
525+
else
526+
{
527+
dwError = RtlNtStatusToDosError(Status);
528+
}
529+
530+
return dwError;
460531
}
461532

462533

463534
/* Function 5 */
464535
unsigned long
465-
ScmrSetServiceObjectSecurity(handle_t BindingHandle)
536+
ScmrSetServiceObjectSecurity(handle_t BindingHandle,
537+
unsigned int hService,
538+
unsigned long dwSecurityInformation,
539+
unsigned char *lpSecurityDescriptor,
540+
unsigned long dwSecuityDescriptorSize)
466541
{
467542
DPRINT1("ScmrSetServiceSecurity() is unimplemented\n");
468543
return ERROR_CALL_NOT_IMPLEMENTED;
@@ -515,7 +590,8 @@ ScmrQueryServiceStatus(handle_t BindingHandle,
515590

516591
/* Function 7 */
517592
unsigned long
518-
ScmrSetServiceStatus(handle_t BindingHandle)
593+
ScmrSetServiceStatus(handle_t BindingHandle,
594+
unsigned long hServiceStatus) /* FIXME */
519595
{
520596
DPRINT1("ScmrSetServiceStatus() is unimplemented\n");
521597
/* FIXME */
@@ -545,6 +621,21 @@ ScmrNotifyBootConfigStatus(handle_t BindingHandle,
545621
}
546622

547623

624+
/* Function 10 */
625+
unsigned long
626+
ScmrI_ScSetServiceBitsW(handle_t BindingHandle,
627+
unsigned long hServiceStatus,
628+
unsigned long dwServiceBits,
629+
unsigned long bSetBitsOn,
630+
unsigned long bUpdateImmediately,
631+
wchar_t *lpString)
632+
{
633+
DPRINT1("ScmrI_ScSetServiceBitsW() called\n");
634+
/* FIXME */
635+
return ERROR_SUCCESS;
636+
}
637+
638+
548639
/* Function 11 */
549640
unsigned long
550641
ScmrChangeServiceConfigW(handle_t BiningHandle,

reactos/subsys/system/services/services.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ typedef struct _SERVICE
2525

2626
ULONG Flags;
2727

28+
PSECURITY_DESCRIPTOR lpSecurityDescriptor;
29+
2830
BOOLEAN ServiceVisited;
2931

3032
HANDLE ControlPipeHandle;

0 commit comments

Comments
 (0)