Group Listing problem

J

Jason S

Hello group,

Trying to get a list of groups, including nested groups, for an account.
Anyone see any problem with this code? It is returing a LOT of 122
ERROR_INSUFFICIENT_BUFFER errors.

ArrayList alGroups = new ArrayList();
int bufferSize = 1024;
int groupLength = bufferSize;
int domainLength = bufferSize;
int sidNameUse= 0;
int errorReturn;
StringBuilder group;
StringBuilder domain;
string[] props = {"tokenGroups"};

_de.RefreshCache(props);

foreach(byte[] sid in _de.Properties["tokenGroups"])
{
IntPtr sidPtr = Marshal.AllocHGlobal(sid.Length);
Marshal.Copy(sid, 0, sidPtr, sid.Length);
group = new StringBuilder(bufferSize);
domain = new StringBuilder(bufferSize);

errorReturn = LookupAccountSid(null, sidPtr, group, ref groupLength,
domain, ref domainLength, out sidNameUse);

if(errorReturn == 0)
group = new StringBuilder("Error: " + Marshal.GetLastWin32Error());

alGroups.Add(group);

Marshal.FreeHGlobal(sidPtr);
}

_groups = alGroups;


I have tried multiple buffer lengths... nothing seems to work. I am also
getting a ERROR_NONE_MAPPED error once as well.

TIA,
Jason S.
 
J

Jason S

Ok, found a later post by Willy that cleared it up. Evidently you need to
call LookupAccountSid twice each time... once to prime the buffers and then
again to get the info.

Still getting the ERROR_NONE_MAPPED error tho....

Jason S.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top