![]() |
Admin
Frage:
wenn ich für alle Benutzer die Adminstatoren sind,eine spezielle Funktion eingebaut habe und will das nur diese die erwähnte Funktion benûtzen können, wie finde ich heraus ob sie zur Administrator-Gruppe von einem PC gehören. Wäre echt froh wenn das jemand wüsste... :thumb: OnFire :gruebel: |
Re: Admin
Welche Delphi-Version nutzt Du denn?
...:cat:... |
Re: Admin
|
Re: Admin
Delphi 5
|
Re: Admin
Ich glaube, die Version von Nico ist sicherer:
Delphi-Quellcode:
function GetAdminSid: PSID;
const // bekannte SIDs ... (WinNT.h) SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5)); // bekannte RIDs ... (WinNT.h) SECURITY_BUILTIN_DOMAIN_RID: DWORD = $00000020; DOMAIN_ALIAS_RID_ADMINS: DWORD = $00000220; begin Result := nil; AllocateAndInitializeSid(SECURITY_NT_AUTHORITY, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, Result); end; //////////////////////////////////////////////////////////////////////////////// // // IsAdmin // Autor: Nico Bendlin function IsAdmin: LongBool; var TokenHandle: THandle; ReturnLength: DWORD; TokenInformation: PTokenGroups; AdminSid: PSID; Loop: Integer; begin Result := False; TokenHandle := 0; if OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, TokenHandle) then try ReturnLength := 0; GetTokenInformation(TokenHandle, TokenGroups, nil, 0, ReturnLength); TokenInformation := GetMemory(ReturnLength); if Assigned(TokenInformation) then try if GetTokenInformation(TokenHandle, TokenGroups, TokenInformation, ReturnLength, ReturnLength) then begin AdminSid := GetAdminSid; for Loop := 0 to TokenInformation^.GroupCount - 1 do begin if EqualSid(TokenInformation^.Groups[Loop].Sid, AdminSid) then begin Result := True; Break; end; end; FreeSid(AdminSid); end; finally FreeMemory(TokenInformation); end; finally CloseHandle(TokenHandle); end; end; |
Re: Admin
Funktioniert das auch bei XP??? :gruebel: :gruebel:
|
Re: Admin
Ja. Aber probier´s doch einfach. :roll:
|
Re: Admin
Ist zwar schon etwas älter... aber was liefert die Funktion unter Win9x?
|
Re: Admin
![]() Zitat:
|
Re: Admin
Die Frage ist eben, welchen Wert liefert mir die Funktion zurück? "Wird nicht straten" wird wohl nicht passieren... es gibt höchstens einen Fehler...
|
Re: Admin
Dadurch, daß die Funktionen fest eingelinkt sind, wird die Applikation ganz einfach nicht starten können, weil der PE-Loader bestimmte Importe nicht auflösen kann.
@Luckie: Hau'n wir uns jetzt? Ich benutze in CMDasSYS eine Funktion, welche ganz ähnlich aussieht ;) ... die ursprüngliche Fassung stammt aus dem BDN soweit ich weiß - und ist nichts anderes als die Konvertierung von einem MSDN-Beispiel. Ist also nix besonderes. |
Re: Admin
@FriFra: Siehe Ollis Beitrag, das programm wird nicht starten. ;)
@Olli: Hauen, mit dir, wegen Code von Nico? :shock: :gruebel: |
Re: Admin
Und wie kann ich dann eine entspr. Prüfung so durchführen, dass mein programm auch noch unter Win9x startet?
Denkbar wäre hier doch sicherlich der Aufruf irgendwelcher API Funktionen aus dynamisch geladenen windows dll's... |
Re: Admin
Lade die Funktionen dynamisch.
|
Re: Admin
Zitat:
@Luckie: Wer sagt die sei von Nico ... die sieht meiner so ähnlich. Jetzt muß ich dich leider verklagen :mrgreen: ... ich will nur sagen, daß es gerade bei solchen PD-Funktionen nicht mehr darauf ankommt einen Autoren zu nennen, ganz einfach weil sie PD sind. |
Re: Admin
Welche Funktionen aus welcher dll muss ich vwerwenden um das ganze Win98 Kompatibel zu bekommen?
P.S.: Ich installiere mir gerade mal eine Win98SE Maschine unter VMWare, damit ich mal wieder darauf testen kann ;) |
Re: Admin
Zitat:
Definitiv: OpenProcessToken GetTokenInformation AllocateAndInitializeSid EqualSid FreeSid |
Re: Admin
Jetzt läuft mein VMware Windows98SE und das Programm funktioniert wunderbar ;)
Ich hab die Funktion der Schweizer noch etwas angepasst, so dass bei allen OS < NT4 immer True geliefert wird:
Delphi-Quellcode:
function TDupFind_Main.IsAdmin: Boolean;
const { operating system (OS)constants } cOsUnknown = -1; cOsWin95 = 0; cOsWin98 = 1; cOsWin98SE = 2; cOsWinME = 3; cOsWinNT = 4; cOsWin2000 = 5; cOsXP = 6; cOsWin2003 = 7; cOsWinNew = 8; function GetOperatingSystem: Integer; var osVerInfo: TOSVersionInfo; majorVer, minorVer: Integer; begin Result := cOsUnknown; { set operating system type flag } osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); if GetVersionEx(osVerInfo) then begin majorVer := osVerInfo.dwMajorVersion; minorVer := osVerInfo.dwMinorVersion; case osVerInfo.dwPlatformId of VER_PLATFORM_WIN32_NT: { Windows NT/2000 } begin if majorVer <= 4 then Result := cOsWinNT else if (majorVer = 5) and (minorVer = 0) then Result := cOsWin2000 else if (majorVer = 5) and (minorVer = 1) then Result := cOsXP else if (majorVer = 5) and (minorVer = 2) then Result := cOsWin2003 else if (majorVer = 5) and (minorVer >= 3) then Result := cOsWinNew else Result := cOsUnknown; end; VER_PLATFORM_WIN32_WINDOWS: { Windows 9x/ME } begin if (majorVer = 4) and (minorVer = 0) then Result := cOsWin95 else if (majorVer = 4) and (minorVer = 10) then begin if osVerInfo.szCSDVersion[1] = 'A' then Result := cOsWin98SE else Result := cOsWin98; end else if (majorVer = 4) and (minorVer = 90) then Result := cOsWinME else Result := cOsUnknown; end; else Result := cOsUnknown; end; end else Result := cOsUnknown; end; const SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5)); SECURITY_BUILTIN_DOMAIN_RID = $00000020; DOMAIN_ALIAS_RID_ADMINS = $00000220; var hAccessToken: THandle; ptgGroups: PTokenGroups; dwInfoBufferSize: DWORD; psidAdministrators: PSID; x: Integer; bSuccess: BOOL; TmpOS: integer; begin if GetOperatingSystem < 4 then Result := True else begin Result := False; bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True, hAccessToken); if not bSuccess then begin if GetLastError = ERROR_NO_TOKEN then bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, hAccessToken); end; if bSuccess then begin GetMem(ptgGroups, 1024); bSuccess := GetTokenInformation(hAccessToken, TokenGroups, ptgGroups, 1024, dwInfoBufferSize); CloseHandle(hAccessToken); if bSuccess then begin AllocateAndInitializeSid(SECURITY_NT_AUTHORITY, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, psidAdministrators); {$R-} for x := 0 to ptgGroups.GroupCount - 1 do if EqualSid(psidAdministrators, ptgGroups.Groups[x].Sid) then begin Result := True; Break; end; {$R+} FreeSid(psidAdministrators); end; FreeMem(ptgGroups); end; end; end; |
Re: Admin
Wo lädst du denn da die Funktionen dynamisch?
|
Re: Admin
Nirgends! Ich hab einfach nicht glauben wollen, dass das Programm mit dieser Funktion nicht startetm und hab das ganze jetzt einfach mal getestet...
Die Idee mit dem dynamischen Laden der entspr. dll-Funktionen kam mir ja nur, weil hier mehrfach behauptet wurde, dass diese Funktionen "fest eingelinkt sind" und das Programm deshalb nicht starten würde... es startet aber :roll: :???: |
Re: Admin
Das überrascht mich jetzt aber doch etwas. :gruebel: OLLI!!!!!
Prüf mal explizit den Errorcode. Kommt da eventuell so was bei raus wie: ERROR_NOT_SUPPORTED oder so was? Es kann sein, dass es unter Consumer Windows einfach nur eine leere Hülle ist. |
Re: Admin
Zitat:
Zitat:
|
Re: Admin
ROFLMAO, bin auch überrascht, habe es aber auf Windows 95B getestet ... dort gibt es eine ADVAPI32.DLL und diese enthält u.a. die genannten Exporte. Jetzt kommt der Witz: die machen natürlich nix und viele der Exporte zeigen sogar auf den gleichen Code. Beispiel:
Code:
Also nochmal Glück gehabt, FriFra :zwinker: ... die tun nix, außer zu tun, daß dein Code tun tut :mrgreen:
[color=red].text:BFEC20FC ; Exported entry 24. ControlService
.text:BFEC20FC ; Exported entry 25. CopySid .text:BFEC20FC ; Exported entry 59. DuplicateToken .text:BFEC20FC ; Exported entry 68. GetAce .text:BFEC20FC ; Exported entry 77. GetSecurityDescriptorControl .text:BFEC20FC ; Exported entry 79. GetSecurityDescriptorGroup .text:BFEC20FC ; Exported entry 81. GetSecurityDescriptorOwner .text:BFEC20FC ; Exported entry 97. InitializeAcl .text:BFEC20FC ; Exported entry 99. InitializeSid .text:BFEC20FC ; Exported entry 102. IsTextUnicode .text:BFEC20FC ; Exported entry 117. LookupPrivilegeValueA .text:BFEC20FC ; Exported entry 118. LookupPrivilegeValueW .text:BFEC20FC ; Exported entry 120. MakeSelfRelativeSD .text:BFEC20FC ; Exported entry 124. ObjectCloseAuditAlarmA .text:BFEC20FC ; Exported entry 125. ObjectCloseAuditAlarmW .text:BFEC20FC ; Exported entry 134. OpenProcessToken .text:BFEC20FC ; Exported entry 135. OpenSCManagerA .text:BFEC20FC ; Exported entry 136. OpenSCManagerW .text:BFEC20FC ; Exported entry 137. OpenServiceA .text:BFEC20FC ; Exported entry 138. OpenServiceW .text:BFEC20FC ; Exported entry 140. PrivilegeCheck .text:BFEC20FC ; Exported entry 153. RegConnectRegistryW .text:BFEC20FC ; Exported entry 157. RegCreateKeyW .text:BFEC20FC ; Exported entry 171. RegLoadKeyW .text:BFEC20FC ; Exported entry 176. RegOpenKeyW .text:BFEC20FC ; Exported entry 189. RegRestoreKeyW .text:BFEC20FC ; Exported entry 191. RegSaveKeyW .text:BFEC20FC ; Exported entry 207. SetFileSecurityA .text:BFEC20FC ; Exported entry 208. SetFileSecurityW .text:BFEC20FC ; Exported entry 209. SetKernelObjectSecurity .text:BFEC20FC ; Exported entry 216. SetServiceObjectSecurity .text:BFEC20FC ; Exported entry 220. StartServiceA .text:BFEC20FC ; Exported entry 223. StartServiceW[/color] .text:BFEC20FC .text:BFEC20FC ; ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ S U B R O U T I N E ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ .text:BFEC20FC .text:BFEC20FC .text:BFEC20FC ; BOOL __stdcall StartServiceW(SC_HANDLE hService,DWORD dwNumServiceArgs,LPCWSTR *lpServiceArgVectors) .text:BFEC20FC public StartServiceW .text:BFEC20FC StartServiceW proc near .text:BFEC20FC xor eax, eax ; ControlService .text:BFEC20FC ; CopySid .text:BFEC20FC ; DuplicateToken .text:BFEC20FC ; GetAce .text:BFEC20FC ; GetSecurityDescriptorControl .text:BFEC20FC ; GetSecurityDescriptorGroup .text:BFEC20FC ; GetSecurityDescriptorOwner .text:BFEC20FC ; InitializeAcl .text:BFEC20FC ; InitializeSid .text:BFEC20FC ; IsTextUnicode .text:BFEC20FC ; LookupPrivilegeValueA .text:BFEC20FC ; LookupPrivilegeValueW .text:BFEC20FC ; MakeSelfRelativeSD .text:BFEC20FC ; ObjectCloseAuditAlarmA .text:BFEC20FC ; ObjectCloseAuditAlarmW .text:BFEC20FC ; OpenProcessToken .text:BFEC20FC ; OpenSCManagerA .text:BFEC20FC ; OpenSCManagerW .text:BFEC20FC ; OpenServiceA .text:BFEC20FC ; OpenServiceW .text:BFEC20FC ; PrivilegeCheck .text:BFEC20FC ; RegConnectRegistryW .text:BFEC20FC ; RegCreateKeyW .text:BFEC20FC ; RegLoadKeyW .text:BFEC20FC ; RegOpenKeyW .text:BFEC20FC ; RegRestoreKeyW .text:BFEC20FC ; RegSaveKeyW .text:BFEC20FC ; SetFileSecurityA .text:BFEC20FC ; SetFileSecurityW .text:BFEC20FC ; SetKernelObjectSecurity .text:BFEC20FC ; SetServiceObjectSecurity .text:BFEC20FC ; StartServiceA .text:BFEC20FE mov cl, 3 .text:BFEC2100 jmp loc_BFEC1356 .text:BFEC2100 StartServiceW endp |
Re: Admin
Zitat:
|
Re: Admin
Zitat:
|
Re: Admin
Ui, dann habe ich ja mal in Schwarze getippt. :) Aber wird noch nicht mal ERROR_NOT_SUPPORTED zurückgegeben?
|
Re: Admin
Da wo was zurückgegeben wird, scheint das 0 zu sein, also ERROR_SUCCESS.
|
Re: Admin
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:55 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