Check a collection of SIDs for membership in a given group

JadziaMD

I have a collection of SID values and need to display if they are in a given group. I know I can do that with CheckTokenMembership, if I had a token handle. How do I get a token handle from an SID in Windows?

xMRi
  1. Use LookupAccountSid to get the account for the SID
  2. Use NetUserGetGroups to get all groups this account is a member of.
    EDIT Note from eryksun: Check target group's SID first. If it's SidTypeGroup, call NetUserGetGroups. If it's SidTypeAlias, call NetUserGetLocalGroups (AKA aliases, such as "BUILTIN\Administrators")
  3. Use LookupAccountName to get the SIDs of the group.
  4. Check if account SID (step 1) is member of the SID collection (step 3). Use EqualSid function.

You find appropriate old code one the old win32.mvps.org pages. Sadly the page is gone. But Wayback machine helps. Here a link to the old fksec samples

You find an easy to use sid class there. It also provides sid::MemberOf and sid::Members functions. The code isn't my style but it works.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Receive all membership groups' SIDs that a user belongs to?

How to check firestore rule for group membership

Group Laravel collection by the given key

How to check if a user that is in Azure Active Directory belongs to a specific group membership?

Create a collection of sub collection from a given Collection (Group By) in Java

Check if Collection of DTOs sorted by a given field

On Shopify, check if a given product is not on any collection

Retrieving group membership in LDAP

requesting membership to a group mvc

Select based on group membership

how to get the group membership?

Searching for AD Group Membership

Read Active Directory SIDs in Local Administrators Group when Off Premises

Check if membership exists

Check Acive Directory Group Membership form within SSRS Report Custom Code

Azure AD - Check for security group membership - (Node.js, passport, Azure Web App)

Python - check list membership and store parent group name in a column / multiple lambda statements?

How to check if collection contains items in given order using Hamcrest

How to check if a given filter exists in the filter's collection of the store?

Yammer - Group Membership REST Endpoints?

Hive: how to compare group membership

Slow AD group membership lookup

Azure ad group membership claims

Group Membership does not include Contacts

randomly reassign group membership with condition

Add group membership to AD with PyAD

search group membership for a list of users

String vs list membership check

unexpected behaviour of dictionary membership check