function decode_sid(sid,pgid:ansistring):string;var version,authority,s:string; subauth_count:integer; x,y,high,low:integer;begin result:='S'; //First byte is the version version:= intTostr(ord(sid[1])); result:=result+'-'+version; //Get the second byte authority:= intTostr(ord(sid[2])); result:=result+'-'+authority; //btye 8 is the number of sub auth subauth_count:= ord(sid[8]); high:=12; low:=9; //Process the sub authorities //For the purpose of getting the primary group //I skip the last one and instead use the //primary groupid value. for y := 0 to subauth_count-2 do begin for x := high downto low do s:=s+IntToHex(Ord(sid[x]), 2); s:=intTostr(strToint('$'+s)); result:=result+'-'+s; high:=high+4; low:=low+4; s:=''; end; result:=result+'-'+pgid;end;