Determine Global Group vs User in Local?

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Determine Global Group vs User in Local?

    This code enumerates all local group members
    (Win2K web server member server in a
    Win2K domain). But if a member
    is a global group, I need to
    know it. Currently I can't tell
    if the entry in the local
    group is a user or a global.

    How to tell the difference?

    Thanks.

    string localGroupName = "":
    string bV = "";
    string locPath = "WinNT://" +
    System.Environment.GetEnvironmentVariable
    ( "COMPUTERNAME" );
    DirectoryEntry localGroup;
    try
    {
    localGroup = new DirectoryEntry( locPath + "/" +
    localGroupName + ",group" );
    object allMembers = localGroup.Invoke( "Members" );
    foreach ( object groupMember in (IEnumerable)
    allMembers )
    {
    DirectoryEntry memberEntry = new DirectoryEntry(
    groupMember );
    bV += memberEntry.Path.ToLower().Replace( "/",@"\" )
    + ":";
    }
    }
    catch( System.Runtime.InteropServices.COMException
    xxxCom )
    {
    bV = xxxCom.ToString();
    }
    return bV;

    localhost Guest

  2. Similar Questions and Discussions

    1. How to determine if a user (integrated authentication) is part of a domain security group.
      I am trying to determine from an ASP.NET 1.1 page if a user is a member of a Global Security group (Windows 2000). When I check...
    2. Module to determine Windows file types on local machine?
      I'd like to be able to determine the file types defined on the PC loading a web page. Specifically, I'd like to find the file types defined for...
    3. Global Group Enum From Local ?
      I have the code below that successfully gives all of the entries in a local group. But if an entry is a global group, then those users are not...
    4. Local group authorization
      I'm trying to do some role-base authorization in web.config with groups that exist on the server machine but not in the domain which the server is a...
    5. Adding user to Local Group Administrator
      When trying to add a user to the local group administrators, I do not see the domain name in the locations field. I only see the local computer...
  3. #2

    Default RE: Determine Global Group vs User in Local?

    You may query the whole domain with LDAP to see if there is a group with
    such a name. For example:

    DirectoryEntry oGrp = new
    DirectoryEntry("LDAP://CN=MyGroup,CN=Users,DC=Fabrikam,DC=com");

    Hope this help,

    Luke
    Microsoft Online Support

    Get Secure! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    MSFT Guest

  4. #3

    Default RE: Determine Global Group vs User in Local?


    That is not a workable option for me.

    The web server in question has a local group with 6
    domain users, 3 global groups from one account domain,
    and 2 global groups from another account domain. I
    cannot reasonably make 11 LDAP queries to one account
    domain to see if every entry is a group and then then
    same 11 queries to another domain.

    If I look at local group membership in the Computer
    Management MMC, the GUI displays whether an entry is a
    user or a global group. I need to do the same thing, but
    with C# code.

    How can I tell if an entry in a local group on a web
    server (member server) is a global group or a user
    account?

    Thanks.

    >-----Original Message-----
    >You may query the whole domain with LDAP to see if there
    is a group with
    >such a name. For example:
    >
    >DirectoryEntry oGrp = new
    >DirectoryEntry
    ("LDAP://CN=MyGroup,CN=Users,DC=Fabrikam,DC=com");
    >
    >Hope this help,
    >
    >Luke
    >Microsoft Online Support
    >
    >Get Secure! [url]www.microsoft.com/security[/url]
    >(This posting is provided "AS IS", with no warranties,
    and confers no
    >rights.)
    >
    >.
    >
    localhost Guest

  5. #4

    Default RE: Determine Global Group vs User in Local?

    You may use the Groups of IADsUser. For example:

    string strUserADsPath =
    "LDAP://fabrikam/cn=luke,cn=users,dc=fabrikam,dc=com";
    DirectoryEntry oUser;
    oUser = new DirectoryEntry(strUserADsPath);
    // Invoke IADsUser::Groups method.
    object groups = oUser.Invoke("Groups");
    foreach ( object group in (IEnumerable)groups)
    {
    // Get the Directory Entry.
    DirectoryEntry groupEntry = new DirectoryEntry(group);
    listBox1.Items.Add(groupEntry.Name);
    }

    Luke
    Microsoft Online Support

    Get Secure! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)


    MSFT Guest

  6. #5

    Default RE: Determine Global Group vs User in Local?


    That does not appear to work. I am attempting to
    enumerate entities in a local group on a web server that
    is a member server, I am not querying a domain at all.

    My understanding is that the LDAP:// space is useful for
    querying a (remote) domain, but when querying a local non-
    Domain Controller server, the WinNT:// space must be used.

    I want to know which entities in a given local group are
    users, and which are global groups. That's it. I don't
    want to query any domains outside of the local machine.

    If you look in the "Users" localgroup on a web server
    that is a member of a domain, you will see that by
    default the "ASPNET" user is in there, and
    the "domain\domain users" group is there also. I want to
    programmatically tell which entry is a user and which is
    a group.

    Thanks.




    >-----Original Message-----
    >You may use the Groups of IADsUser. For example:
    >
    [snip]
    localhost Guest

  7. #6

    Default RE: Determine Global Group vs User in Local?


    This code shows each entry in the local group, but does
    not differentiate between domain users and domain
    groups. I need to know which is which. I am sure my
    code is close, I just need a little help getting all the
    way complete.

    string localGroupName = "users";
    string locPath = "WinNT://" +
    System.Environment.GetEnvironmentVariable
    ( "COMPUTERNAME" ) +
    "/" +
    localGroupName
    + ",group" ;
    object allMembers = localGroup.Invoke( "Members" );
    foreach ( object groupMember in (IEnumerable)
    allMembers )
    {
    DirectoryEntry memberEntry = new DirectoryEntry(
    groupMember );
    returnVal += memberEntry.Path.ToLower().Replace
    ( "/",@"\" ) + ":\n\n";
    }
    Console.WriteLine( returnVal );


    Thanks.
    localhost Guest

  8. #7

    Default RE: Determine Global Group vs User in Local?


    This appears to work, but I do not think it is the best
    or fastest way to check local group entity types. Is
    there a better way to make this happen?

    using System;
    using System.Collections;
    using System.Runtime.InteropServices;
    using System.DirectoryServices;
    using ActiveDs;
    using System.Text;
    using System.Configuration;

    class LocalGroupEnum
    {

    [STAThread]
    static void Main(string[] args)
    {
    //string localGroupName = args[0].ToString().Trim();
    string localGroupName = "users";
    string locPath = "WinNT://" +
    System.Environment.GetEnvironmentVariable
    ( "COMPUTERNAME" ) +
    "/" +
    localGroupName
    + ",group" ;
    DirectoryEntry localGroup = new DirectoryEntry( locPath );
    object allMembers = localGroup.Invoke( "Members" );
    foreach ( object groupMember in (IEnumerable)
    allMembers )
    {
    DirectoryEntry memberEntry = new DirectoryEntry(
    groupMember );
    Console.Write( memberEntry.Path.ToLower().Replace
    ("winnt://","").Replace("/",@"\") );
    if ( memberEntry.Properties.Contains("grouptype") )
    {
    Console.WriteLine( "***" );
    }
    Console.WriteLine( "\n\n" );
    }
    Console.Read();
    }
    }


    Thanks.
    localhost Guest

  9. #8

    Default RE: Determine Global Group vs User in Local?

    I think you are just on the right way. The groupType property is the best
    way we can check if a group is a local or global group. It is a
    single-value property that is an integer that specifies the group type and
    scope using the following bit flags:

    ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP
    ADS_GROUP_TYPE_GLOBAL_GROUP
    ADS_GROUP_TYPE_UNIVERSAL_GROUP
    ADS_GROUP_TYPE_SECURITY_ENABLED

    Luke
    Microsoft Online Support

    Get Secure! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    MSFT Guest

  10. #9

    Default RE: Determine Global Group vs User in Local?


    Thanks. Can you post a complete code example "solve
    HOWTO", using the constants you just provided?

    Thanks again.
    localhost Guest

  11. #10

    Default RE: Determine Global Group vs User in Local?

    Hope this help:


    string locPath = "WinNT://MyComputer/administrators,group" ;
    DirectoryEntry localGroup = new DirectoryEntry( locPath );
    object allMembers = localGroup.Invoke( "Members" );
    foreach ( object groupMember in (IEnumerable)allMembers )
    {

    DirectoryEntry oUser= new DirectoryEntry (groupMember);

    try
    {
    object groups = oUser.Invoke("Groups");
    foreach ( object group in (IEnumerable)groups)
    {
    // Get the Directory Entry.
    DirectoryEntry groupEntry = new DirectoryEntry(group);

    string gType=groupEntry.Properties["groupType"].Value.ToString();
    if (gType=="2" )
    Console.WriteLine(groupEntry.Name );

    //Console.WriteLine(groupT.ToString() );
    }
    }
    catch (Exception e)
    {


    }








    }
    Console.Read();




    Luke
    Microsoft Online Support

    Get Secure! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    MSFT Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139