@@ -507,34 +507,48 @@ BOOL DeleteWindowsService(LPCWSTR name)
507
507
HANDLE CreatePublicNamedPipe (LPCWSTR name )
508
508
{
509
509
// Get security attributes for "EVERYONE", so the named pipe is accessible to all processes.
510
+ HANDLE result = INVALID_HANDLE_VALUE ;
510
511
511
512
SID_IDENTIFIER_AUTHORITY authority = SECURITY_WORLD_SID_AUTHORITY ;
512
513
PSID everyoneSid ;
513
- if (!AllocateAndInitializeSid (& authority , 1 , SECURITY_WORLD_RID , 0 , 0 , 0 , 0 , 0 , 0 , 0 , & everyoneSid )) return INVALID_HANDLE_VALUE ;
514
-
515
- EXPLICIT_ACCESSW explicitAccess ;
516
- i_memset (& explicitAccess , 0 , sizeof (EXPLICIT_ACCESSW ));
517
- explicitAccess .grfAccessPermissions = FILE_ALL_ACCESS ;
518
- explicitAccess .grfAccessMode = SET_ACCESS ;
519
- explicitAccess .grfInheritance = NO_INHERITANCE ;
520
- explicitAccess .Trustee .TrusteeForm = TRUSTEE_IS_SID ;
521
- explicitAccess .Trustee .TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP ;
522
- explicitAccess .Trustee .ptstrName = (LPWSTR )everyoneSid ;
523
-
524
- PACL acl ;
525
- if (SetEntriesInAclW (1 , & explicitAccess , NULL , & acl ) != ERROR_SUCCESS ) return INVALID_HANDLE_VALUE ;
526
-
527
- PSECURITY_DESCRIPTOR securityDescriptor = (PSECURITY_DESCRIPTOR )LocalAlloc (LPTR , SECURITY_DESCRIPTOR_MIN_LENGTH );
528
- if (!securityDescriptor ||
529
- !InitializeSecurityDescriptor (securityDescriptor , SECURITY_DESCRIPTOR_REVISION ) ||
530
- !SetSecurityDescriptorDacl (securityDescriptor , TRUE, acl , FALSE)) return INVALID_HANDLE_VALUE ;
531
-
532
- SECURITY_ATTRIBUTES securityAttributes ;
533
- securityAttributes .nLength = sizeof (SECURITY_ATTRIBUTES );
534
- securityAttributes .lpSecurityDescriptor = securityDescriptor ;
535
- securityAttributes .bInheritHandle = FALSE;
536
-
537
- return CreateNamedPipeW (name , PIPE_ACCESS_DUPLEX , PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT , PIPE_UNLIMITED_INSTANCES , 1024 , 1024 , NMPWAIT_USE_DEFAULT_WAIT , & securityAttributes );
514
+ if (AllocateAndInitializeSid (& authority , 1 , SECURITY_WORLD_RID , 0 , 0 , 0 , 0 , 0 , 0 , 0 , & everyoneSid ))
515
+ {
516
+ EXPLICIT_ACCESSW explicitAccess ;
517
+ i_memset (& explicitAccess , 0 , sizeof (EXPLICIT_ACCESSW ));
518
+ explicitAccess .grfAccessPermissions = FILE_ALL_ACCESS ;
519
+ explicitAccess .grfAccessMode = SET_ACCESS ;
520
+ explicitAccess .grfInheritance = NO_INHERITANCE ;
521
+ explicitAccess .Trustee .TrusteeForm = TRUSTEE_IS_SID ;
522
+ explicitAccess .Trustee .TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP ;
523
+ explicitAccess .Trustee .ptstrName = (LPWSTR )everyoneSid ;
524
+
525
+ PACL acl ;
526
+ if (SetEntriesInAclW (1 , & explicitAccess , NULL , & acl ) == ERROR_SUCCESS )
527
+ {
528
+ PSECURITY_DESCRIPTOR securityDescriptor = (PSECURITY_DESCRIPTOR )LocalAlloc (LPTR , SECURITY_DESCRIPTOR_MIN_LENGTH );
529
+ if (securityDescriptor )
530
+ {
531
+ if (InitializeSecurityDescriptor (securityDescriptor , SECURITY_DESCRIPTOR_REVISION ) &&
532
+ SetSecurityDescriptorDacl (securityDescriptor , TRUE, acl , FALSE))
533
+ {
534
+ SECURITY_ATTRIBUTES securityAttributes ;
535
+ securityAttributes .nLength = sizeof (SECURITY_ATTRIBUTES );
536
+ securityAttributes .lpSecurityDescriptor = securityDescriptor ;
537
+ securityAttributes .bInheritHandle = FALSE;
538
+
539
+ result = CreateNamedPipeW (name , PIPE_ACCESS_DUPLEX , PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT , PIPE_UNLIMITED_INSTANCES , 1024 , 1024 , NMPWAIT_USE_DEFAULT_WAIT , & securityAttributes );
540
+ }
541
+
542
+ LocalFree (securityDescriptor );
543
+ }
544
+
545
+ LocalFree (acl );
546
+ }
547
+
548
+ FreeSid (everyoneSid );
549
+ }
550
+
551
+ return result ;
538
552
}
539
553
540
554
BOOL IsExecutable64Bit (LPBYTE image , LPBOOL is64Bit )
0 commit comments