# class Puppet::Util::ADSI::User

### Attributes

name[R]
native_user[RW]

### Public Class Methods

create(name) click to toggle source

    # File lib/puppet/util/adsi.rb, line 163
    def self.create(name)
      # Windows error 1379: The specified local group already exists.
      raise Puppet::Error.new( "Cannot create user if group '#{name}' exists." ) if Puppet::Util::ADSI::Group.exists? name
      new(name, Puppet::Util::ADSI.create(name, 'user'))
    end

delete(name) click to toggle source

    # File lib/puppet/util/adsi.rb, line 173
    def self.delete(name)
      Puppet::Util::ADSI.delete(name, 'user')
    end

each(&block) click to toggle source

    # File lib/puppet/util/adsi.rb, line 177
    def self.each(&block)
      wql = Puppet::Util::ADSI.execquery("select * from win32_useraccount")

      users = []
      wql.each do |u|
        users << new(u.name, u)
      end

      users.each(&block)
    end

exists?(name) click to toggle source

    # File lib/puppet/util/adsi.rb, line 169
    def self.exists?(name)
      Puppet::Util::ADSI::connectable?(User.uri(name))
    end

logon(name, password) click to toggle source

    # File lib/puppet/util/adsi.rb, line 85
    def self.logon(name, password)
      Puppet::Util::Windows::User.password_is?(name, password)
    end

new(name, native_user = nil) click to toggle source

    # File lib/puppet/util/adsi.rb, line 68
    def initialize(name, native_user = nil)
      @name = name
      @native_user = native_user
    end

uri(name) click to toggle source

    # File lib/puppet/util/adsi.rb, line 77
    def self.uri(name)
      Puppet::Util::ADSI.uri(name, 'user')
    end

### Public Instance Methods

[](attribute) click to toggle source

    # File lib/puppet/util/adsi.rb, line 89
    def [](attribute)
      native_user.Get(attribute)
    end

[]=(attribute, value) click to toggle source

    # File lib/puppet/util/adsi.rb, line 93
    def []=(attribute, value)
      native_user.Put(attribute, value)
    end

add_flag(flag_name, value) click to toggle source

    # File lib/puppet/util/adsi.rb, line 110
    def add_flag(flag_name, value)
      flag = native_user.Get(flag_name) rescue 0

      native_user.Put(flag_name, flag | value)

      commit
    end

add_to_group(*group_names)
Alias for: add_to_groups
add_to_groups(*group_names) click to toggle source

    # File lib/puppet/util/adsi.rb, line 132
    def add_to_groups(*group_names)
      group_names.each do |group_name|
        Puppet::Util::ADSI::Group.new(group_name).add_member(@name)
      end
    end

Also aliased as: add_to_group
commit() click to toggle source

    # File lib/puppet/util/adsi.rb, line 97
    def commit
      begin
        native_user.SetInfo unless native_user.nil?
      rescue Exception => e
        raise Puppet::Error.new( "User update failed: #{e}" )
      end
      self
    end

groups() click to toggle source

    # File lib/puppet/util/adsi.rb, line 125
    def groups
      # WIN32OLE objects aren't enumerable, so no map
      groups = []
      native_user.Groups.each {|g| groups << g.Name} rescue nil
      groups
    end

password=(password) click to toggle source

    # File lib/puppet/util/adsi.rb, line 118
    def password=(password)
      native_user.SetPassword(password)
      commit
      fADS_UF_DONT_EXPIRE_PASSWD = 0x10000
      add_flag("UserFlags", fADS_UF_DONT_EXPIRE_PASSWD)
    end

password_is?(password) click to toggle source

    # File lib/puppet/util/adsi.rb, line 106
    def password_is?(password)
      self.class.logon(name, password)
    end

remove_from_group(*group_names)
Alias for: remove_from_groups
remove_from_groups(*group_names) click to toggle source

    # File lib/puppet/util/adsi.rb, line 139
    def remove_from_groups(*group_names)
      group_names.each do |group_name|
        Puppet::Util::ADSI::Group.new(group_name).remove_member(@name)
      end
    end

Also aliased as: remove_from_group
set_groups(desired_groups, minimum = true) click to toggle source

    # File lib/puppet/util/adsi.rb, line 146
    def set_groups(desired_groups, minimum = true)
      return if desired_groups.nil? or desired_groups.empty?

      desired_groups = desired_groups.split(',').map(&:strip)

      current_groups = self.groups

      # First we add the user to all the groups it should be in but isn't
      groups_to_add = desired_groups - current_groups
      add_to_groups(*groups_to_add)

      # Then we remove the user from all groups it is in but shouldn't be, if
      # that's been requested
      groups_to_remove = current_groups - desired_groups
      remove_from_groups(*groups_to_remove) unless minimum
    end

uri() click to toggle source

    # File lib/puppet/util/adsi.rb, line 81
    def uri
      self.class.uri(name)
    end