class Chef::Util::Windows::NetUse
Constants
- SIZEOF_USE_INFO_2
- USE_FORCE
- USE_INFO_2
- USE_INFO_2_TEMPLATE
- USE_LOTS_OF_FORCE
- USE_NOFORCE
Public Class Methods
new(localname)
click to toggle source
# File lib/chef/util/windows/net_use.rb, line 76 def initialize(localname) @localname = localname @name = multi_to_wide(localname) end
Public Instance Methods
add(args)
click to toggle source
# File lib/chef/util/windows/net_use.rb, line 81 def add(args) if args.class == String remote = args args = Hash.new args[:remote] = remote end args[:local] ||= @localname use = use_info_2(args) buffer = use_info_2_pack(use) rc = NetUseAdd.call(nil, 2, buffer, nil) if rc != NERR_Success raise ArgumentError, get_last_error(rc) end end
delete()
click to toggle source
XXX should we use some FORCE here?
# File lib/chef/util/windows/net_use.rb, line 115 def delete rc = NetUseDel.call(nil, @name, USE_NOFORCE) if rc != NERR_Success raise ArgumentError, get_last_error(rc) end end
device()
click to toggle source
# File lib/chef/util/windows/net_use.rb, line 111 def device get_info()[:remote] end
get_info()
click to toggle source
# File lib/chef/util/windows/net_use.rb, line 96 def get_info ptr = 0.chr * PTR_SIZE rc = NetUseGetInfo.call(nil, @name, 2, ptr) if rc != NERR_Success raise ArgumentError, get_last_error(rc) end ptr = ptr.unpack('L')[0] buffer = 0.chr * SIZEOF_USE_INFO_2 memcpy(buffer, ptr, buffer.size) NetApiBufferFree(ptr) use_info_2_unpack(buffer) end
Private Instance Methods
use_info_2(args)
click to toggle source
# File lib/chef/util/windows/net_use.rb, line 53 def use_info_2(args) USE_INFO_2.collect { |field| args.include?(field[0]) ? args[field[0]] : field[1] } end
use_info_2_pack(use)
click to toggle source
# File lib/chef/util/windows/net_use.rb, line 59 def use_info_2_pack(use) use.collect { |v| v.class == Fixnum ? v : str_to_ptr(multi_to_wide(v)) }.pack(USE_INFO_2_TEMPLATE) end
use_info_2_unpack(buffer)
click to toggle source
# File lib/chef/util/windows/net_use.rb, line 65 def use_info_2_unpack(buffer) use = Hash.new USE_INFO_2.each_with_index do |field,offset| use[field[0]] = field[1].class == Fixnum ? dword_to_i(buffer, offset) : lpwstr_to_s(buffer, offset) end use end