Some of the processing reminds me of GetRID ...

GetRID() discussion

Problem is, Kixtart doesn't handle variant byte arrays very well (ie, not at all), so need to use one of the reskit addons like adssecurity to translate SID's to strings...

-Shawn