Autor Beitrag
Cronen
Hält's aus hier
Beiträge: 2


Turbo Delphi W32 Prof
BeitragVerfasst: Fr 05.09.03 12:59 
Hallo,
Ich möchte in ein Programm in einem Win2000-Netzwerk vor unebrechtigten Zugriff schützen.Die Zugriffskontrolle soll dabei im Hintergrund unbermerkt durch den Anwender auf Grundlage der Benutzerverwaltung von Windows 2000 stattfinden. Das Programm soll nur starten wenn der im System angemeldete User einer bestimmten Beutzergruppe angehört.

Und hier liegt mein Problem: Den User festzustellen kann ich mit der Funktion GetUserName. Aber wie stelle ich fest ob dieser User dieser Gruppe gehöhrt?

Hier bin ich nicht fündig geworden. Wer kann mir helfen? (Da ich kein Profi bin wenns geht mit Code)
lemming
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 470

Mac OS 10.3.1
Delphi 6 Pro, Kylix 3
BeitragVerfasst: Mi 10.09.03 13:52 
Es gibt unter Windows das kleine Programm
net.exe. Damit läßt sich allerlei unfug treiben.

Z.B. alle User eine Gruppe ausgeben:
ausblenden Quelltext
1:
net group GG-Programmierung /domain					


Du musst das Ergebniss nur noch per Capture abfangen. oder lässt es gleich in eine Textdatei schreiben.

ausblenden Quelltext
1:
net group GG-Programmierung /domain >gruppe.txt					


-lemming
barfuesser
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 324



BeitragVerfasst: Mi 10.09.03 14:37 
Zitat:

It is often useful to know if the account under which your application is
running is a member of the "Administrators" group. The sample code below
demonstrates a method of making this determination:

Sample Code
-----------
ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
BOOL IsAdmin(void)
{
   HANDLE hProcess, hAccessToken;
   UCHAR InfoBuffer[1024];
   PTOKEN_GROUPS ptgGroups = (PTOKEN_GROUPS)InfoBuffer;
   DWORD dwInfoBufferSize;
   SID_NAME_USE snuInfo;
   UCHAR szAccountName[256], szDomainName[256];

   DWORD dwAccountNameSize, dwDomainNameSize;
   UINT x;

   hProcess = GetCurrentProcess();

   if(!OpenProcessToken(hProcess,TOKEN_READ,&hAccessToken))
      return(FALSE);

   if(!GetTokenInformation(hAccessToken,TokenGroups,InfoBuffer,
     1024, &dwInfoBufferSize)) return(FALSE);

   for(x=0;x<ptgGroups->GroupCount;x++)
   {
      dwAccountNameSize = 256;
      dwDomainNameSize = 256;

      LookupAccountSid(NULL, ptgGroups->Groups[x].Sid,
      szAccountName, &dwAccountNameSize,

      szDomainName, &dwDomainNameSize, &snuInfo);

      if(!strcmp(szAccountName,"Administrators") &&
      !strcmp(szDomainName,"BUILTIN"))
      return(TRUE);
  }
  return(FALSE);
}


ein Beispiel aus der Win32 Developers References zu erreichen über Delphi->Hilfe->Windows SDK

barfuesser
Tana´Ri
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 230



BeitragVerfasst: Mi 10.09.03 14:48 
@lemming: Wie funktioniert das genau ? könntest du mirs erklären plus ein kleines beispiel.

_________________
mfg
Tana´Ri
lemming
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 470

Mac OS 10.3.1
Delphi 6 Pro, Kylix 3
BeitragVerfasst: Do 11.09.03 10:27 
Diese Monster Prozedur gibt dir das Ergebnis von Konsolenprogramme wieder.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
procedure CaptureDosCmd(command:String;OutputMemo:TMemo);
.
.
.
procedure TMain.CaptureDosCmd(command:String;OutputMemo:TMemo);
const
  CaptureBufferSize = 2500;
var  
  SecAttrib         : TSecurityAttributes;
  ReadPipe,writePipe   : THandle;
  Startup               : TStartUpInfo;
  ProcessInfo         : TProcessInformation;
  CaptureBuffer              : Pchar;
  BytesRead           : DWord;
  WaitHandle          : DWord;

begin  
  OutPutMemo.Lines.clear;
  //OutputMemo.lines.add('executing "' + command + '"');
  With SecAttrib do  
  begin    
    nlength              := SizeOf(TSecurityAttributes);
    binherithandle       := true;
    lpsecuritydescriptor := nil;
  end;
  
  if Createpipe (ReadPipe, writePipe, @SecAttrib, 0then  
  begin    
    CaptureBuffer  := AllocMem(CaptureBufferSize + 1);
    FillChar(Startup,Sizeof(Startup),#0);
    Startup.cb          := SizeOf(Startup);
    Startup.hStdOutput  := writePipe;
    Startup.hStdInput   := ReadPipe;
    Startup.dwFlags     := STARTF_USESTDHANDLES + STARTF_USESHOWWINDOW;
    Startup.wShowWindow := SW_HIDE;
    if CreateProcess(nil, PChar(command), @SecAttrib, @SecAttrib, true, NORMAL_PRIORITY_CLASS, nilnil, Startup, ProcessInfo) then    
    begin      
      repeat 
        WaitHandle := WaitForSingleObject( ProcessInfo.hProcess,100);
        Application.ProcessMessages;
      until (WaitHandle <> WAIT_TIMEOUT) or application.terminated;

      if not application.terminated then 
      Repeat 
        BytesRead := 0;
        ReadFile(ReadPipe,CaptureBuffer[0],CaptureBufferSize,BytesRead,nil);        
        CaptureBuffer[BytesRead]:= #0;
        OemToAnsi(CaptureBuffer,CaptureBuffer);
        OutputMemo.Text := OutputMemo.Text+String(CaptureBuffer);
      until (BytesRead < CaptureBufferSize);      
    end 
    else OutPutMemo.lines.add('Operation wurde abgebrochen!');    
    
    FreeMem(CaptureBuffer);    
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);
    CloseHandle(ReadPipe);
    CloseHandle(writePipe);  
  end 
  else OutPutMemo.lines.add('Konnte Kommando nicht starten, Fehler: #'+  inttostr(getlasterror));
end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
  CaptureDosCmd('net group GG-Programmierung /domain', MemoOutput);
  
if Pos(Username + '  ', MemoOutput.Text) then //Das Leerzeichen hinter dem Username aus Sicherheitsgründen. Sonst unterscheidet er nicht zwischen Eckhard und Eckhardt
begin
.
.
//hier dein Code wenn er in der Gruppe gefunden wurde
.
end;


-lemming