Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Acquiring NT Group RID's

by enoch (Chaplain)
on Mar 21, 2001 at 08:36 UTC ( [id://65958]=perlquestion: print w/replies, xml ) Need Help??

enoch has asked for the wisdom of the Perl Monks concerning the following question:

I have been scouring around the back-alleys of Win32 Perl web-sites looking for an example of obtaining the RID's (Relative ID) of NT Groups located on a PDC. I came up with nothing direct. I pieced together a dirty hack where I can get a user's attributes, and, from there, pull the RID of the user's primary group.

Here is the snippet of code to get a group's RID from a user's primary group:
if(Win32::AdminMisc::UserGetMiscAttributes('DOMAIN', "user", \%Hash)){ print "The user is in the primary group with a RID $Hash{USER_PRIM +ARY_GROUP_ID}\n"; }
But, I do not want to go scouring the PDC for user's in each singular group. I want a way to say:
$groupRID = getRID($groupName); print "$groupName has the RID $groupRID.\n";
Though, I may be asking too much. Are there any Win32 guru's out there who have found a solution to this query.

Jeremy

Replies are listed 'Best First'.
(tye)Re: Acquiring NT Group RID's
by tye (Sage) on Mar 21, 2001 at 09:57 UTC

    I believe that a RIDs are just a subset of SIDs and so you can find them via:

    use Win32; my( $domain, $sid, $type ); foreach my $id ( "Administrator", "Administrators", "Domain Admins" ) { if( ! Win32::LookupAccountName( "", $id, $domain, $sid, $type ) ) { warn "Can't lookup SID ($id): $^E\n"; } else { print "$id is of type $type and belongs to $domain.\n"; } } __END__ Administrator is of type 1 and belongs to MY-COMPUTER. Administrators is of type 4 and belongs to BUILTIN. Domain Admins is of type 2 and belongs to MYDOMAIN.

    Update: Oh, you probably want a nice string version of the RID... I'll try to look up how to do that tomorrow unless someone beats me to it (please). (:

            - tye (but my friends call me "Tye")
      Yea, I need the nice number version (i.e. 512 or 9090 or whatever -- I wish I could just look in /etc/group for this). I was just researching using Win32::GetGroups to grab an array of all of the groups. Then, with a test account, iterate through the groups, setting the user's primary group each loop, and pulling the USER_PRIMARY_GROUP_ID from the user. Something akin to:
      use strict; use Win32::AdminMisc; my $user = "test_user"; my %hash,@groupList,$group; Win32::AdminMisc::GetGroups( "DOMAIN", GROUP_TYPE_GLOBAL, \@groupList) +; #iterate through groups foreach $group (@groupList) { #set the user's primary group Win32::AdminMisc::UserSetMiscAttributes('DOMAIN',$user,USER_PRIMAR +Y_GROUP => $group); #get user's attributes Win32::AdminMisc::UserGetMiscAttributes('WSOM',$user,\%hash); #print out group RID print $group. " has RID " . $hash{USER_PRIMARY_GROUP_ID}; }
      Unfortunately, Win32::AdminMisc::UserSetMiscAttributes('DOMAIN',$user,USER_PRIMARY_GROUP => $group) does not exist. There is no USER_PRIMARY_GROUP; there is only USER_PRIMARY_GROUP_ID. So, to set a user's primary group, you need the group's RID beforehand.

      Foiled Again,
      Jeremy
Re: Acquiring NT Group RID's
by LD2 (Curate) on Mar 21, 2001 at 09:04 UTC
      Got them both. Could not find info other than what is above.

      Thanks though,
      Jeremy

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://65958]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 22:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found