# class Chef::Provider::Group::Windows

### Public Class Methods

new(new_resource,run_context) click to toggle source
Calls superclass method Chef::Provider::Group.new

    # File lib/chef/provider/group/windows.rb, line 29
    def initialize(new_resource,run_context)
      super
      @net_group = Chef::Util::Windows::NetGroup.new(@new_resource.group_name)
    end

### Public Instance Methods

create_group() click to toggle source

    # File lib/chef/provider/group/windows.rb, line 53
    def create_group
      @net_group.local_add
      manage_group
    end

has_current_group_member?(member) click to toggle source

    # File lib/chef/provider/group/windows.rb, line 80
    def has_current_group_member?(member)
      member_sid = local_group_name_to_sid(member)
      @current_resource.members.include?(member_sid)
    end

load_current_resource() click to toggle source

    # File lib/chef/provider/group/windows.rb, line 34
    def load_current_resource
      @current_resource = Chef::Resource::Group.new(@new_resource.name)
      @current_resource.group_name(@new_resource.group_name)

      members = nil
      begin
        members = @net_group.local_get_members
      rescue => e
        @group_exists = false
        Chef::Log.debug("#{@new_resource} group does not exist")
      end

      if members
        @current_resource.members(members)
      end

      @current_resource
    end

local_group_name_to_sid(group_name) click to toggle source

    # File lib/chef/provider/group/windows.rb, line 89
    def local_group_name_to_sid(group_name)
      locally_qualified_name = group_name.include?("\\") ? group_name : "#{ENV['COMPUTERNAME']}\\#{group_name}"
      Chef::ReservedNames::Win32::Security.lookup_account_name(locally_qualified_name)[1].to_s
    end

manage_group() click to toggle source

    # File lib/chef/provider/group/windows.rb, line 58
    def manage_group
      if @new_resource.append
        members_to_be_added = [ ]
        @new_resource.members.each do |member|
          members_to_be_added << member if ! has_current_group_member?(member)
        end

        # local_add_members will raise ERROR_MEMBER_IN_ALIAS if a
        # member already exists in the group.
        @net_group.local_add_members(members_to_be_added) unless members_to_be_added.empty?

        members_to_be_removed = [ ]
        @new_resource.excluded_members.each do |member|
          member_sid = local_group_name_to_sid(member)
          members_to_be_removed << member if has_current_group_member?(member)
        end
        @net_group.local_delete_members(members_to_be_removed) unless members_to_be_removed.empty?
      else
        @net_group.local_set_members(@new_resource.members)
      end
    end

remove_group() click to toggle source

    # File lib/chef/provider/group/windows.rb, line 85
    def remove_group
      @net_group.local_delete
    end