lib/windows/sys/admin.rb in sys-admin-1.6.1 vs lib/windows/sys/admin.rb in sys-admin-1.6.2

- old
+ new

@@ -152,10 +152,13 @@ attr_accessor :status # The user's id (RID). attr_accessor :uid + # The user's primary group ID. + attr_accessor :gid + # The user's home directory attr_accessor :dir # Used to set whether or not the account is disabled. attr_writer :disabled @@ -194,30 +197,30 @@ # * User::INTERDOMAIN_TRUST # * User::WORKSTATION_TRUST # * User::SERVER_TRUST # def account_type=(type) - case type - when TEMP_DUPLICATE - @account_type = 'duplicate' - when NORMAL - @account_type = 'normal' - when INTERDOMAIN_TRUST - @account_type = 'interdomain_trust' - when WORKSTATION_TRUST - @account_type = 'workstation_trust' - when SERVER_TRUST - @account_type = 'server_trust' - else - @account_type = 'unknown' - end + case type + when TEMP_DUPLICATE + @account_type = 'duplicate' + when NORMAL + @account_type = 'normal' + when INTERDOMAIN_TRUST + @account_type = 'interdomain_trust' + when WORKSTATION_TRUST + @account_type = 'workstation_trust' + when SERVER_TRUST + @account_type = 'server_trust' + else + @account_type = 'unknown' + end end # Returns the SID type as a human readable string. # def sid_type - @sid_type + @sid_type end # Sets the SID (Security Identifier) type to +stype+, which can be # one of the following constant values: # @@ -230,76 +233,76 @@ # * Admin::SidTypeInvalid # * Admin::SidTypeUnknown # * Admin::SidTypeComputer # def sid_type=(stype) - case stype - when Admin::SidTypeUser - @sid_type = 'user' - when Admin::SidTypeGroup - @sid_type = 'group' - when Admin::SidTypeDomain - @sid_type = 'domain' - when Admin::SidTypeAlias - @sid_type = 'alias' - when Admin::SidTypeWellKnownGroup - @sid_type = 'well_known_group' - when Admin::SidTypeDeletedAccount - @sid_type = 'deleted_account' - when Admin::SidTypeInvalid - @sid_type = 'invalid' - when Admin::SidTypeUnknown - @sid_type = 'unknown' - when Admin::SidTypeComputer - @sid_type = 'computer' - else - @sid_type = 'unknown' - end + case stype + when Admin::SidTypeUser + @sid_type = 'user' + when Admin::SidTypeGroup + @sid_type = 'group' + when Admin::SidTypeDomain + @sid_type = 'domain' + when Admin::SidTypeAlias + @sid_type = 'alias' + when Admin::SidTypeWellKnownGroup + @sid_type = 'well_known_group' + when Admin::SidTypeDeletedAccount + @sid_type = 'deleted_account' + when Admin::SidTypeInvalid + @sid_type = 'invalid' + when Admin::SidTypeUnknown + @sid_type = 'unknown' + when Admin::SidTypeComputer + @sid_type = 'computer' + else + @sid_type = 'unknown' + end end # Returns whether or not the account is disabled. # def disabled? - @disabled + @disabled end # Returns whether or not the account is local. # def local? - @local + @local end # Returns whether or not the account is locked out. # def lockout? - @lockout + @lockout end # Returns whether or not the password for the account is changeable. # def password_changeable? - @password_changeable + @password_changeable end # Returns whether or not the password for the account is changeable. # def password_expires? - @password_expires + @password_expires end # Returns whether or not the a password is required for the account. # def password_required? - @password_required + @password_required end end class Admin extend FFI::Library # The version of the sys-admin library. - VERSION = '1.6.1' + VERSION = '1.6.2' # This is the error raised in the majority of cases if anything goes wrong # with any of the Sys::Admin methods. # class Error < StandardError; end @@ -356,17 +359,18 @@ rhash end # An internal, private method for getting a list of groups for - # a particular user. + # a particular user. The first member is a list of group names, + # the second member is the primary group ID. # def self.get_groups(domain, user) array = [] - adsi = WIN32OLE.connect("WinNT://#{domain}/#{user}") + adsi = WIN32OLE.connect("WinNT://#{domain}/#{user},user") adsi.groups.each{ |g| array << g.name } - array + [array, adsi.PrimaryGroupId] end # An internal, private method for getting a list of members for # any particular group. # @@ -719,10 +723,12 @@ # the SID again to make sure if usr.kind_of?(Fixnum) next if usr != uid end + groups, primary_group = *get_groups(domain, user.name) + user_object = User.new do |u| u.account_type = user.accounttype u.caption = user.caption u.description = user.description u.disabled = user.disabled @@ -737,10 +743,11 @@ u.password_required = user.passwordrequired u.sid = user.sid u.sid_type = user.sidtype u.status = user.status u.uid = uid - u.groups = get_groups(domain, user.name) + u.gid = primary_group + u.groups = groups u.dir = get_home_dir(user.name, options[:localaccount], domain) end return user_object }