Code: Alles auswählen
program Test;
{$Mode ObjFpc}{$H+}
uses BaseUnix, process;
var
outputstr: String;
begin
fpsetuid(fpgeteuid); // Für den Aufruf von Runcommand wichtig damit das die richtige UID erbt
WriteLn(fpgeteuid); // Bisschen debugging
Runcommand('/bin/sh',['-c','whoami'],outputstr,[postderrtooutput]);
writeln( outputstr);
end.
Code: Alles auswählen
➜ fpc ./test.pas
Free Pascal Compiler version 3.2.2 [2023/10/09] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling ./test.pas
Linking test
14 lines compiled, 0.2 sec
➜ ./test
1000
frederic
➜ sudo chown root:root test
➜ sudo chmod +s test
➜ ./test
0
root