![]() |
Pipe Zugriff auf user beschränken
Versuche jetzt seit einer Woche die Pipe in den Griff zu bekommen. Leider ohne Erfolg. Kann mir da jemand helfen?
Hintergrund: Ich benutze die Pipe Unit von rllibby stand 12.01.2010 Funktioniert sehr gut und läuft seit Jahren. Wird benutzt für eine Stream zwischen einen Windows Service und einer Applikation, die unter normalen User rechten läuft. In rllibby's code wird der SecurityDescriptor mit NIL initialisiert. Damit kann die ACL für freies Zugreifen benutzt werden. Auch vom Netz her kann an die Named Pipe einfach was gesendet werden und der Service führt es mit vollen Rechten aus. Das soll nicht mehr sein. Ich habe also das umgekehrte Problem: Es funktioniert immer und soll in die Schranken verwiesen werden. Es gibt einen Administrator ACount, den ich gerne benutzen würde. Der Service und auch der Client soll mit diesen Acount Rechten arbeiten, so dass ein mit NIL initialisierter oder auch ein mit Administrator initialisierter ACL sich nicht mehr verbinden kann. Übrigens verwendet ich Jedi Aufrufe gewollt nicht, da es immer wieder Probleme mit JwaWindows im Zusammenspiel mit den anderen Units gibt. Hier der Init-Abschnitt:
Code:
Besonders der Abschnitt mit dem StringSecurityDescriptor ist nicht so ganz Einfach zu verstehen.
procedure InitializeSecurity(var sa: TSecurityAttributes; Client: Boolean=false);
type PTokenUser = ^_TOKEN_USER; _TOKEN_USER = record User: SID_AND_ATTRIBUTES; end; const RAUN = 'EMOSWebAdmin'; RAPW = 'halleluja'; var phToken: THandle; dwInfoBufferSize: DWORD; ptgUser: PTokenUser; pSidStr: PChar; SidStr:String; sd : PSecurityDescriptor; begin if Client then begin // Allocate memory for the security descriptor sd := AllocMem(SECURITY_DESCRIPTOR_MIN_LENGTH); // Initialize the new security descriptor if InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION) then begin // Add a NULL descriptor ACL to the security descriptor if SetSecurityDescriptorDacl(sd, True, nil, False) then begin // Set up the security attributes structure SA.nLength := SizeOf(TSecurityAttributes); SA.lpSecurityDescriptor := sd; SA.bInheritHandle := True; end else // Failed to init the sec descriptor RaiseWindowsError; end else // Failed to init the sec descriptor RaiseWindowsError; end else begin if LogonUser(PChar(RAUN), '', PChar(RAPW),LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, phToken) then begin GetTokenInformation(phToken, TokenUser, nil, 0, dwInfoBufferSize); ptgUser := GetMemory(dwInfoBufferSize); GetTokenInformation(phToken, TokenUser, ptgUser, dwInfoBufferSize, dwInfoBufferSize); ConvertSidToStringSidA(ptgUser.User.Sid, pSidStr); SidStr:=pSidStr; FreeMemory(ptgUser); LocalFree(HLOCAL(pSidStr)); CloseHandle(phToken); end else RaiseWindowsError; sa.nLength:= sizeof(sa); sa.bInheritHandle:= true; if NOT ConvertStringSecurityDescriptorToSecurityDescriptorA(PChar( 'D:' + // Discretionary ACL '(D;OICI;GA;;;BG)' + // Deny access to built-in guests '(D;OICI;GA;;;AN)' + // Deny access to anonymous logon '(A;OICI;GRGWGX;;;AU)' + // access to authenticated users '(D;OICI;GA;;;BA)' + // Deny access to administrators '(A;OICI;GRGWGX;;;' + SidStr + ')' // Access for Admin user ), SDDL_REVISION_1, sa.lpSecurityDescriptor, nil) then RaiseWindowsError; end; end; //create Client Pipe (Ausschnitt) : : if WaitNamedPipe(PChar(szName), WaitTime) then begin // Attempt to create client side handle FPipe := CreateFile(PChar(szName), GENERIC_READ or GENERIC_WRITE, 0, @FSA, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED, 0); // Success if we have a valid handle if IsHandle(FPipe) then begin : : // create pipe Server (Ausschnitt) : : // Create the outbound pipe first FPipe := CreateNamedPipe(PChar(resPipeBaseName + FPipeName), PIPE_OPENMODE, PIPE_MODE, PIPE_INSTANCES, 0, 0, 1000, @FSA); // Resource protection try // Set result value based on valid handle if IsHandle(FPipe) then : : die Aufrufe von "InitializeSecurity(FSA, true);" und "FinalizeSecurity(FSA, true);" habe ich mal weggelassen. Kann mir da jemand helfen... Danke. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:21 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz