dhcpsapi 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dhcpsapi/class.rb +3 -77
- data/lib/dhcpsapi/client.rb +7 -130
- data/lib/dhcpsapi/common.rb +1 -8
- data/lib/dhcpsapi/data_structures.rb +654 -0
- data/lib/dhcpsapi/misc.rb +6 -18
- data/lib/dhcpsapi/option.rb +26 -112
- data/lib/dhcpsapi/option_value.rb +13 -183
- data/lib/dhcpsapi/reservation.rb +3 -63
- data/lib/dhcpsapi/server.rb +30 -1
- data/lib/dhcpsapi/subnet.rb +6 -80
- data/lib/dhcpsapi/version.rb +1 -1
- data/lib/dhcpsapi/win2008/class.rb +38 -0
- data/lib/dhcpsapi/win2008/client.rb +41 -0
- data/lib/dhcpsapi/win2008/free_memory.rb +14 -0
- data/lib/dhcpsapi/win2008/option.rb +57 -0
- data/lib/dhcpsapi/win2008/option_value.rb +61 -0
- data/lib/dhcpsapi/win2008/subnet.rb +46 -0
- data/lib/dhcpsapi/win2008/subnet_element.rb +26 -0
- data/lib/dhcpsapi/win2012/client.rb +21 -0
- data/lib/dhcpsapi/win2012/misc.rb +19 -0
- data/lib/dhcpsapi/win2012/reservation.rb +20 -0
- data/lib/dhcpsapi.rb +4 -6
- metadata +27 -21
- data/lib/dhcpsapi/common_data_structs.rb +0 -267
- data/lib/dhcpsapi/ffi.rb +0 -6
- data/lib/dhcpsapi/subnet_element.rb +0 -45
- data/lib/dhcpsapi_for_testing/server.rb +0 -9
- data/lib/dhcpsapi_for_testing.rb +0 -3
data/lib/dhcpsapi/option.rb
CHANGED
@@ -1,90 +1,4 @@
|
|
1
1
|
module DhcpsApi
|
2
|
-
=begin
|
3
|
-
typedef struct _DHCP_OPTION {
|
4
|
-
DHCP_OPTION_ID OptionID;
|
5
|
-
LPWSTR OptionName;
|
6
|
-
LPWSTR OptionComment;
|
7
|
-
DHCP_OPTION_DATA DefaultValue;
|
8
|
-
DHCP_OPTION_TYPE OptionType;
|
9
|
-
} DHCP_OPTION, *LPDHCP_OPTION;
|
10
|
-
=end
|
11
|
-
class DHCP_OPTION < DHCPS_Struct
|
12
|
-
layout :option_id, :uint32,
|
13
|
-
:option_name, :pointer,
|
14
|
-
:option_comment, :pointer,
|
15
|
-
:default_value, DHCP_OPTION_DATA,
|
16
|
-
:option_type, :uint32 # see DHCP_OPTION_TYPE
|
17
|
-
|
18
|
-
ruby_struct_attr :to_string, :option_name, :option_comment
|
19
|
-
end
|
20
|
-
|
21
|
-
=begin
|
22
|
-
typedef struct _DHCP_OPTION_ARRAY {
|
23
|
-
DWORD NumElements;
|
24
|
-
LPDHCP_OPTION Options;
|
25
|
-
} DHCP_OPTION_ARRAY, *LPDHCP_OPTION_ARRAY;
|
26
|
-
=end
|
27
|
-
class DHCP_OPTION_ARRAY < DHCPS_Struct
|
28
|
-
layout :num_elements, :uint32,
|
29
|
-
:options, :pointer
|
30
|
-
|
31
|
-
def as_ruby_struct
|
32
|
-
0.upto(self[:num_elements]-1).inject([]) do |all, offset|
|
33
|
-
all << DHCP_OPTION.new(self[:options] + offset*DHCP_OPTION.size).as_ruby_struct
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
=begin
|
39
|
-
DWORD DhcpCreateOptionV5(
|
40
|
-
_In_ LPWSTR ServerIpAddress,
|
41
|
-
_In_ DWORD Flags,
|
42
|
-
_In_ DHCP_OPTION_ID OptionId,
|
43
|
-
_In_opt_ LPWSTR ClassName,
|
44
|
-
_In_opt_ LPWSTR VendorName,
|
45
|
-
_In_ LPDHCP_OPTION OptionInfo
|
46
|
-
);
|
47
|
-
=end
|
48
|
-
attach_function :DhcpCreateOptionV5, [:pointer, :uint32, :uint32, :pointer, :pointer, :pointer], :uint32
|
49
|
-
|
50
|
-
=begin
|
51
|
-
DWORD DhcpGetOptionInfoV5(
|
52
|
-
_In_ LPWSTR ServerIpAddress,
|
53
|
-
_In_ DWORD Flags,
|
54
|
-
_In_ DHCP_OPTION_ID OptionID,
|
55
|
-
_In_ LPWSTR ClassName,
|
56
|
-
_In_ LPWSTR VendorName,
|
57
|
-
_Out_ LPDHCP_OPTION *OptionInfo
|
58
|
-
);
|
59
|
-
=end
|
60
|
-
attach_function :DhcpGetOptionInfoV5, [:pointer, :uint32, :uint32, :pointer, :pointer, :pointer], :uint32
|
61
|
-
|
62
|
-
=begin
|
63
|
-
DWORD DhcpRemoveOptionV5(
|
64
|
-
_In_ LPWSTR ServerIpAddress,
|
65
|
-
_In_ DWORD Flags,
|
66
|
-
_In_ DHCP_OPTION_ID OptionID,
|
67
|
-
_In_ LPWSTR ClassName,
|
68
|
-
_In_ LPWSTR VendorName
|
69
|
-
);
|
70
|
-
=end
|
71
|
-
attach_function :DhcpRemoveOptionV5, [:pointer, :uint32, :uint32, :pointer, :pointer], :uint32
|
72
|
-
|
73
|
-
=begin
|
74
|
-
DWORD DhcpEnumOptionsV5(
|
75
|
-
_In_ LPWSTR ServerIpAddress,
|
76
|
-
_In_ DWORD Flags,
|
77
|
-
_In_ LPWSTR ClassName,
|
78
|
-
_In_ LPWSTR VendorName,
|
79
|
-
_Inout_ DHCP_RESUME_HANDLE *ResumeHandle,
|
80
|
-
_In_ DWORD PreferredMaximum,
|
81
|
-
_Out_ LPDHCP_OPTION_ARRAY *Options,
|
82
|
-
_Out_ DWORD *OptionsRead,
|
83
|
-
_Out_ DWORD *OptionsTotal
|
84
|
-
);
|
85
|
-
=end
|
86
|
-
attach_function :DhcpEnumOptionsV5, [:pointer, :uint32, :pointer, :pointer, :pointer, :uint32, :pointer, :pointer, :pointer], :uint32
|
87
|
-
|
88
2
|
module Option
|
89
3
|
include CommonMethods
|
90
4
|
|
@@ -97,12 +11,12 @@ typedef struct _DHCP_OPTION_ARRAY {
|
|
97
11
|
option_info[:option_type] = is_array ? DhcpsApi::DHCP_OPTION_TYPE::DhcpArrayTypeOption : DhcpsApi::DHCP_OPTION_TYPE::DhcpUnaryElementTypeOption
|
98
12
|
option_info[:default_value].from_array(option_type, default_values)
|
99
13
|
|
100
|
-
error = DhcpsApi.DhcpCreateOptionV5(to_wchar_string(server_ip_address),
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
14
|
+
error = DhcpsApi::Win2008::Option.DhcpCreateOptionV5(to_wchar_string(server_ip_address),
|
15
|
+
is_vendor,
|
16
|
+
option_id,
|
17
|
+
nil,
|
18
|
+
vendor_name.nil? ? nil : FFI::MemoryPointer.from_string(to_wchar_string(vendor_name)),
|
19
|
+
option_info.pointer)
|
106
20
|
raise DhcpsApi::Error.new("Error creating option.", error) if error != 0
|
107
21
|
|
108
22
|
option_info.as_ruby_struct
|
@@ -112,12 +26,12 @@ typedef struct _DHCP_OPTION_ARRAY {
|
|
112
26
|
is_vendor = vendor_name.nil? ? 0 : DhcpsApi::DHCP_FLAGS_OPTION_IS_VENDOR
|
113
27
|
option_info_ptr_ptr = FFI::MemoryPointer.new(:pointer)
|
114
28
|
|
115
|
-
error = DhcpsApi::DhcpGetOptionInfoV5(to_wchar_string(server_ip_address),
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
29
|
+
error = DhcpsApi::Win2008::Option.DhcpGetOptionInfoV5(to_wchar_string(server_ip_address),
|
30
|
+
is_vendor,
|
31
|
+
option_id,
|
32
|
+
nil,
|
33
|
+
vendor_name.nil? ? nil : FFI::MemoryPointer.from_string(to_wchar_string(vendor_name)),
|
34
|
+
option_info_ptr_ptr)
|
121
35
|
if is_error?(error)
|
122
36
|
unless (option_info_ptr_ptr.null? || (to_free = option_info_ptr_ptr.read_pointer).null?)
|
123
37
|
free_memory(DhcpsApi::DHCP_OPTION.new(to_free))
|
@@ -133,11 +47,11 @@ typedef struct _DHCP_OPTION_ARRAY {
|
|
133
47
|
end
|
134
48
|
|
135
49
|
def delete_option(option_id, vendor_name = nil)
|
136
|
-
error = DhcpsApi::DhcpRemoveOptionV5(to_wchar_string(server_ip_address),
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
50
|
+
error = DhcpsApi::Win2008::Option.DhcpRemoveOptionV5(to_wchar_string(server_ip_address),
|
51
|
+
vendor_name.nil? ? 0 : DhcpsApi::DHCP_FLAGS_OPTION_IS_VENDOR,
|
52
|
+
option_id,
|
53
|
+
nil,
|
54
|
+
vendor_name.nil? ? nil : FFI::MemoryPointer.from_string(to_wchar_string(vendor_name)))
|
141
55
|
raise DhcpsApi::Error.new("Error deleting option.", error) if error != 0
|
142
56
|
end
|
143
57
|
|
@@ -153,15 +67,15 @@ typedef struct _DHCP_OPTION_ARRAY {
|
|
153
67
|
options_total_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, 0)
|
154
68
|
is_vendor = vendor_name.nil? ? 0 : DhcpsApi::DHCP_FLAGS_OPTION_IS_VENDOR
|
155
69
|
|
156
|
-
error = DhcpsApi.DhcpEnumOptionsV5(to_wchar_string(server_ip_address),
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
70
|
+
error = DhcpsApi::Win2008::Option.DhcpEnumOptionsV5(to_wchar_string(server_ip_address),
|
71
|
+
is_vendor,
|
72
|
+
class_name.nil? ? nil : FFI::MemoryPointer.from_string(to_wchar_string(class_name)) ,
|
73
|
+
vendor_name.nil? ? nil : FFI::MemoryPointer.from_string(to_wchar_string(vendor_name)),
|
74
|
+
resume_handle_ptr,
|
75
|
+
preferred_maximum,
|
76
|
+
options_ptr_ptr,
|
77
|
+
options_read_ptr,
|
78
|
+
options_total_ptr)
|
165
79
|
return empty_response if error == 259
|
166
80
|
if is_error?(error)
|
167
81
|
unless (options_ptr_ptr.null? || (to_free = options_ptr_ptr.read_pointer).null?)
|
@@ -1,174 +1,4 @@
|
|
1
1
|
module DhcpsApi
|
2
|
-
#
|
3
|
-
# DHCP_RESERVED_SCOPE data structure describes an reserved DHCP scope.
|
4
|
-
#
|
5
|
-
# Available fields:
|
6
|
-
# :reserved_ip_address [String],
|
7
|
-
# :reserved_ip_subnet_address [String]
|
8
|
-
#
|
9
|
-
# @see https://msdn.microsoft.com/en-us/library/windows/desktop/aa363369(v=vs.85).aspx
|
10
|
-
#
|
11
|
-
class DHCP_RESERVED_SCOPE < DHCPS_Struct
|
12
|
-
layout :reserved_ip_address, :uint32,
|
13
|
-
:reserved_ip_subnet_address, :uint32
|
14
|
-
end
|
15
|
-
|
16
|
-
#
|
17
|
-
# DHCP_RESERVED_SCOPE_UNION describes a DHCP scope.
|
18
|
-
#
|
19
|
-
# Available fields:
|
20
|
-
# :subnet_scope_info [String],
|
21
|
-
# :reserved_scope_info [DHCP_RESERVED_SCOPE],
|
22
|
-
# :m_scope_info [String],
|
23
|
-
# :default_scope_info, unused
|
24
|
-
# :global_scope_info
|
25
|
-
#
|
26
|
-
# @see https://msdn.microsoft.com/en-us/library/windows/desktop/aa363361(v=vs.85).aspx
|
27
|
-
#
|
28
|
-
class DHCP_OPTION_SCOPE_INFO_UNION < FFI::Union
|
29
|
-
layout :subnet_scope_info, :uint32,
|
30
|
-
:reserved_scope_info, DHCP_RESERVED_SCOPE,
|
31
|
-
:m_scope_info, :pointer,
|
32
|
-
:default_scope_info, :pointer, # unused
|
33
|
-
:global_scope_info, :pointer
|
34
|
-
end
|
35
|
-
|
36
|
-
#
|
37
|
-
# DHCP_OPTION_SCOPE_INFO defines information about the options provided for a certain DHCP scope.
|
38
|
-
#
|
39
|
-
# Available fields:
|
40
|
-
# :scope_type [Fixnum], see DHCP_OPTION_SCOPE_TYPE
|
41
|
-
# :scope_info [DHCP_OPTION_SCOPE_INFO_UNION],
|
42
|
-
#
|
43
|
-
# @see https://msdn.microsoft.com/en-us/library/windows/desktop/aa363361(v=vs.85).aspx
|
44
|
-
#
|
45
|
-
class DHCP_OPTION_SCOPE_INFO < DHCPS_Struct
|
46
|
-
layout :scope_type, :uint32,
|
47
|
-
:scope_info, DHCP_OPTION_SCOPE_INFO_UNION
|
48
|
-
|
49
|
-
def self.build_for_subnet_scope(subnet_ip_address)
|
50
|
-
to_return = new
|
51
|
-
to_return[:scope_type] = DHCP_OPTION_SCOPE_TYPE::DhcpSubnetOptions
|
52
|
-
to_return[:scope_info][:subnet_scope_info] = to_return.ip_to_uint32(subnet_ip_address)
|
53
|
-
to_return
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.build_for_reserved_scope(reserved_ip_address, subnet_ip_address)
|
57
|
-
to_return = new
|
58
|
-
to_return[:scope_type] = DHCP_OPTION_SCOPE_TYPE::DhcpReservedOptions
|
59
|
-
to_return[:scope_info][:reserved_scope_info][:reserved_ip_address] = to_return.ip_to_uint32(reserved_ip_address)
|
60
|
-
to_return[:scope_info][:reserved_scope_info][:reserved_ip_subnet_address] = to_return.ip_to_uint32(subnet_ip_address)
|
61
|
-
to_return
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.build_for_multicast_scope(multicast_scope_name)
|
65
|
-
to_return = new
|
66
|
-
to_return[:scope_type] = DHCP_OPTION_SCOPE_TYPE::DhcpMScopeOptions
|
67
|
-
to_return[:scope_info][:m_scope_info] = FFI::MemoryPointer.from_string(to_return.to_wchar_string(multicast_scope_name))
|
68
|
-
to_return
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.build_for_default_scope
|
72
|
-
to_return = new
|
73
|
-
to_return[:scope_type] = DHCP_OPTION_SCOPE_TYPE::DhcpDefaultOptions
|
74
|
-
to_return[:scope_info][:default_scope_info] = DHCP_OPTION_ARRAY.new.pointer
|
75
|
-
to_return
|
76
|
-
end
|
77
|
-
|
78
|
-
# TODO
|
79
|
-
def self.build_for_global_scope
|
80
|
-
raise "Not implemented yet"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
#
|
85
|
-
# DHCP_OPTION_VALUE defines a DHCP option value.
|
86
|
-
#
|
87
|
-
# Available fields:
|
88
|
-
# :option_id [Fixnum], Option id
|
89
|
-
# :value [DHCP_OPTION_DATA], option value
|
90
|
-
#
|
91
|
-
# @see https://msdn.microsoft.com/en-us/library/windows/desktop/aa363367(v=vs.85).aspx
|
92
|
-
#
|
93
|
-
class DHCP_OPTION_VALUE < DHCPS_Struct
|
94
|
-
layout :option_id, :uint32,
|
95
|
-
:value, DHCP_OPTION_DATA
|
96
|
-
end
|
97
|
-
|
98
|
-
#
|
99
|
-
# DHCP_OPTION_VALUE_ARRAY defines a list of DHCP option values.
|
100
|
-
#
|
101
|
-
# Available fields:
|
102
|
-
# :bum_elements [Fixnum], The number of option values in the list
|
103
|
-
# :values [Array<DHCP_OPTION_DATA>], Array of option values
|
104
|
-
#
|
105
|
-
# @see https://msdn.microsoft.com/en-us/library/windows/desktop/bb891963(v=vs.85).aspx
|
106
|
-
#
|
107
|
-
class DHCP_OPTION_VALUE_ARRAY < DHCPS_Struct
|
108
|
-
layout :num_elements, :uint32,
|
109
|
-
:values, :pointer
|
110
|
-
|
111
|
-
def as_ruby_struct
|
112
|
-
0.upto(self[:num_elements]-1).inject([]) do |all, offset|
|
113
|
-
all << DhcpsApi::DHCP_OPTION_VALUE.new(self[:values] + offset*DHCP_OPTION_VALUE.size).as_ruby_struct
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
=begin
|
119
|
-
DWORD DhcpEnumOptionValuesV5(
|
120
|
-
_In_ LPWSTR ServerIpAddress,
|
121
|
-
_In_ DWORD Flags,
|
122
|
-
_In_ LPWSTR ClassName,
|
123
|
-
_In_ LPWSTR VendorName,
|
124
|
-
_In_ LPDHCP_OPTION_SCOPE_INFO ScopeInfo,
|
125
|
-
_Inout_ DHCP_RESUME_HANDLE *ResumeHandle,
|
126
|
-
_In_ DWORD PreferredMaximum,
|
127
|
-
_Out_ LPDHCP_OPTION_VALUE_ARRAY *OptionValues,
|
128
|
-
_Out_ DWORD *OptionsRead,
|
129
|
-
_Out_ DWORD *OptionsTotal
|
130
|
-
);
|
131
|
-
=end
|
132
|
-
attach_function :DhcpEnumOptionValuesV5, [:pointer, :uint32, :pointer, :pointer, :pointer, :pointer, :uint32, :pointer, :pointer, :pointer], :uint32
|
133
|
-
|
134
|
-
=begin
|
135
|
-
DWORD DhcpGetOptionValueV5(
|
136
|
-
_In_ LPWSTR ServerIpAddress,
|
137
|
-
_In_ DWORD Flags,
|
138
|
-
_In_ DHCP_OPTION_ID OptionID,
|
139
|
-
_In_ LPWSTR ClassName,
|
140
|
-
_In_ LPWSTR VendorName,
|
141
|
-
_In_ DHCP_CONST DHCP_OPTION_SCOPE_INFO ScopeInfo,
|
142
|
-
_Out_ LPDHCP_OPTION_VALUE *OptionValue
|
143
|
-
);
|
144
|
-
=end
|
145
|
-
attach_function :DhcpGetOptionValueV5, [:pointer, :uint32, :uint32, :pointer, :pointer, DHCP_OPTION_SCOPE_INFO.by_value, :pointer], :uint32
|
146
|
-
|
147
|
-
=begin
|
148
|
-
DWORD DhcpRemoveOptionValueV5(
|
149
|
-
_In_ LPWSTR ServerIpAddress,
|
150
|
-
_In_ DWORD Flags,
|
151
|
-
_In_ DHCP_OPTION_ID OptionID,
|
152
|
-
_In_ LPWSTR ClassName,
|
153
|
-
_In_ LPWSTR VendorName,
|
154
|
-
_In_ DHCP_CONST DHCP_OPTION_SCOPE_INFO ScopeInfo
|
155
|
-
);
|
156
|
-
=end
|
157
|
-
attach_function :DhcpRemoveOptionValueV5, [:pointer, :uint32, :uint32, :pointer, :pointer, DHCP_OPTION_SCOPE_INFO.by_value], :uint32
|
158
|
-
|
159
|
-
=begin
|
160
|
-
DWORD DhcpSetOptionValueV5(
|
161
|
-
_In_ LPWSTR ServerIpAddress,
|
162
|
-
_In_ DWORD Flags,
|
163
|
-
_In_ DHCP_OPTION_ID OptionId,
|
164
|
-
_In_opt_ LPWSTR ClassName,
|
165
|
-
_In_opt_ LPWSTR VendorName,
|
166
|
-
_In_ LDHCP_CONST DHCP_OPTION_SCOPE_INFO ScopeInfo,
|
167
|
-
_In_ LDHCP_CONST DHCP_OPTION_DATA OptionValue
|
168
|
-
);
|
169
|
-
=end
|
170
|
-
attach_function :DhcpSetOptionValueV5, [:pointer, :uint32, :uint32, :pointer, :pointer, :pointer, :pointer], :uint32
|
171
|
-
|
172
2
|
module OptionValue
|
173
3
|
# Sets an option value for a subnet.
|
174
4
|
#
|
@@ -531,7 +361,7 @@ module DhcpsApi
|
|
531
361
|
def dhcp_set_option_value_v5(option_id, vendor_name, scope_info, option_type, values)
|
532
362
|
is_vendor = vendor_name.nil? ? 0 : DhcpsApi::DHCP_FLAGS_OPTION_IS_VENDOR
|
533
363
|
option_data = DhcpsApi::DHCP_OPTION_DATA.from_array(option_type, values)
|
534
|
-
error = DhcpsApi.DhcpSetOptionValueV5(to_wchar_string(server_ip_address),
|
364
|
+
error = DhcpsApi::Win2008::OptionValue.DhcpSetOptionValueV5(to_wchar_string(server_ip_address),
|
535
365
|
is_vendor,
|
536
366
|
option_id,
|
537
367
|
nil,
|
@@ -545,7 +375,7 @@ module DhcpsApi
|
|
545
375
|
is_vendor = vendor_name.nil? ? 0 : DhcpsApi::DHCP_FLAGS_OPTION_IS_VENDOR
|
546
376
|
option_value_ptr_ptr = FFI::MemoryPointer.new(:pointer)
|
547
377
|
|
548
|
-
error = DhcpsApi.DhcpGetOptionValueV5(to_wchar_string(server_ip_address),
|
378
|
+
error = DhcpsApi::Win2008::OptionValue.DhcpGetOptionValueV5(to_wchar_string(server_ip_address),
|
549
379
|
is_vendor,
|
550
380
|
option_id,
|
551
381
|
nil,
|
@@ -570,7 +400,7 @@ module DhcpsApi
|
|
570
400
|
def dhcp_remove_option_value_v5(option_id, vendor_name, scope_info)
|
571
401
|
is_vendor = vendor_name.nil? ? 0 : DhcpsApi::DHCP_FLAGS_OPTION_IS_VENDOR
|
572
402
|
|
573
|
-
error = DhcpsApi.DhcpRemoveOptionValueV5(to_wchar_string(server_ip_address),
|
403
|
+
error = DhcpsApi::Win2008::OptionValue.DhcpRemoveOptionValueV5(to_wchar_string(server_ip_address),
|
574
404
|
is_vendor,
|
575
405
|
option_id,
|
576
406
|
nil,
|
@@ -587,16 +417,16 @@ module DhcpsApi
|
|
587
417
|
options_total_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, 0)
|
588
418
|
is_vendor = vendor_name.nil? ? 0 : DhcpsApi::DHCP_FLAGS_OPTION_IS_VENDOR
|
589
419
|
|
590
|
-
error = DhcpsApi.DhcpEnumOptionValuesV5(to_wchar_string(server_ip_address),
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
420
|
+
error = DhcpsApi::Win2008::OptionValue.DhcpEnumOptionValuesV5(to_wchar_string(server_ip_address),
|
421
|
+
is_vendor,
|
422
|
+
nil,
|
423
|
+
vendor_name.nil? ? nil : FFI::MemoryPointer.from_string(to_wchar_string(vendor_name)),
|
424
|
+
scope_info.pointer,
|
425
|
+
resume_handle_ptr,
|
426
|
+
preferred_maximum,
|
427
|
+
option_values_ptr_ptr,
|
428
|
+
options_read_ptr,
|
429
|
+
options_total_ptr)
|
600
430
|
return empty_response if error == 259
|
601
431
|
if is_error?(error)
|
602
432
|
unless (option_values_ptr_ptr.null? || (to_free = option_values_ptr_ptr.read_pointer).null?)
|
data/lib/dhcpsapi/reservation.rb
CHANGED
@@ -1,64 +1,4 @@
|
|
1
1
|
module DhcpsApi
|
2
|
-
=begin
|
3
|
-
typedef struct _DHCP_IP_RESERVATION_INFO {
|
4
|
-
DHCP_IP_ADDRESS ReservedIpAddress;
|
5
|
-
DHCP_CLIENT_UID ReservedForClient;
|
6
|
-
LPWSTR ReservedClientName;
|
7
|
-
LPWSTR ReservedClientDesc;
|
8
|
-
BYTE bAllowedClientTypes;
|
9
|
-
BYTE fOptionsPresent;
|
10
|
-
} DHCP_IP_RESERVATION_INFO, *LPDHCP_IP_RESERVATION_INFO;
|
11
|
-
=end
|
12
|
-
class DHCP_IP_RESERVATION_INFO < DHCPS_Struct
|
13
|
-
layout :reserved_ip_address, :uint32,
|
14
|
-
:reserved_for_client, DHCP_CLIENT_UID,
|
15
|
-
:reserved_client_name, :pointer,
|
16
|
-
:reserved_client_desc, :pointer,
|
17
|
-
:b_allowed_client_types, :uint8, # see ClientType
|
18
|
-
:f_options_present, :uint8
|
19
|
-
|
20
|
-
ruby_struct_attr :uint32_to_ip, :reserved_ip_address
|
21
|
-
ruby_struct_attr :dhcp_client_uid_to_mac, :reserved_for_client
|
22
|
-
ruby_struct_attr :to_string, :reserved_client_name, :reserved_client_desc
|
23
|
-
end
|
24
|
-
|
25
|
-
=begin
|
26
|
-
typedef struct _DHCP_RESERVATION_INFO_ARRAY {
|
27
|
-
DWORD NumElements;
|
28
|
-
LPDHCP_IP_RESERVATION_INFO *Elements;
|
29
|
-
} DHCP_RESERVATION_INFO_ARRAY, *LPDHCP_RESERVATION_INFO_ARRAY;
|
30
|
-
=end
|
31
|
-
class DHCP_RESERVATION_INFO_ARRAY < DHCPS_Struct
|
32
|
-
layout :num_elements, :uint32,
|
33
|
-
:elements, :pointer
|
34
|
-
end
|
35
|
-
|
36
|
-
=begin
|
37
|
-
typedef struct _DHCP_IP_RESERVATION_V4 {
|
38
|
-
DHCP_IP_ADDRESS ReservedIpAddress;
|
39
|
-
DHCP_CLIENT_UID *ReservedForClient;
|
40
|
-
BYTE bAllowedClientTypes;
|
41
|
-
} DHCP_IP_RESERVATION_V4, *LPDHCP_IP_RESERVATION_V4;
|
42
|
-
=end
|
43
|
-
class DHCP_IP_RESERVATION_V4 < DHCPS_Struct
|
44
|
-
layout :reserved_ip_address, :uint32,
|
45
|
-
:reserved_for_client, :pointer,
|
46
|
-
:b_allowed_client_types, :uint8 # see ClientType
|
47
|
-
end
|
48
|
-
|
49
|
-
=begin
|
50
|
-
DWORD DHCP_API_FUNCTION DhcpV4EnumSubnetReservations(
|
51
|
-
_In_opt_ DHCP_CONST WCHAR *ServerIpAddress,
|
52
|
-
_In_ DHCP_IP_ADDRESS SubnetAddress,
|
53
|
-
_Inout_ DHCP_RESUME_HANDLE *ResumeHandle,
|
54
|
-
_In_ DWORD PreferredMaximum,
|
55
|
-
_Out_ LPDHCP_RESERVATION_INFO_ARRAY *EnumElementInfo,
|
56
|
-
_Out_ DWORD *ElementsRead,
|
57
|
-
_Out_ DWORD *ElementsTotal
|
58
|
-
);
|
59
|
-
=end
|
60
|
-
attach_function :DhcpV4EnumSubnetReservations, [:pointer, :uint32, :pointer, :uint32, :pointer, :pointer, :pointer], :uint32
|
61
|
-
|
62
2
|
module Reservation
|
63
3
|
include CommonMethods
|
64
4
|
|
@@ -80,7 +20,7 @@ module DhcpsApi
|
|
80
20
|
mask_as_octets = reservation_subnet_mask.split('.').map {|octet| octet.to_i}
|
81
21
|
subnet_address = (0..3).inject([]) {|all, i| all << (ip_as_octets[i] & mask_as_octets[i])}.join('.')
|
82
22
|
|
83
|
-
error = DhcpsApi.DhcpAddSubnetElementV4(to_wchar_string(server_ip_address), ip_to_uint32(subnet_address), subnet_element.pointer)
|
23
|
+
error = DhcpsApi::Win2008::SubnetElement.DhcpAddSubnetElementV4(to_wchar_string(server_ip_address), ip_to_uint32(subnet_address), subnet_element.pointer)
|
84
24
|
raise DhcpsApi::Error.new("Error creating reservation.", error) if error != 0
|
85
25
|
|
86
26
|
modify_client(reservation_ip, reservation_subnet_mask, reservation_mac, reservation_name, reservation_comment, 0, DhcpsApi::ClientType::CLIENT_TYPE_NONE)
|
@@ -97,7 +37,7 @@ module DhcpsApi
|
|
97
37
|
reserved_ip[:reserved_for_client] = DhcpsApi::DHCP_CLIENT_UID.from_mac_address(reservation_mac).pointer
|
98
38
|
reserved_ip[:b_allowed_client_types] = DhcpsApi::ClientType::CLIENT_TYPE_NONE
|
99
39
|
|
100
|
-
error = DhcpsApi.DhcpRemoveSubnetElementV4(
|
40
|
+
error = DhcpsApi::Win2008::SubnetElement.DhcpRemoveSubnetElementV4(
|
101
41
|
to_wchar_string(server_ip_address),
|
102
42
|
ip_to_uint32(subnet_address),
|
103
43
|
to_delete.pointer,
|
@@ -139,7 +79,7 @@ module DhcpsApi
|
|
139
79
|
elements_read_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, 0)
|
140
80
|
elements_total_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, 0)
|
141
81
|
|
142
|
-
error = DhcpsApi.DhcpV4EnumSubnetReservations(
|
82
|
+
error = DhcpsApi::Win2012::Reservation.DhcpV4EnumSubnetReservations(
|
143
83
|
to_wchar_string(server_ip_address), ip_to_uint32(subnet_address), resume_handle_ptr, preferred_maximum,
|
144
84
|
enum_element_info_ptr_ptr, elements_read_ptr, elements_total_ptr)
|
145
85
|
return empty_response if error == 259
|
data/lib/dhcpsapi/server.rb
CHANGED
@@ -1,19 +1,48 @@
|
|
1
1
|
module DhcpsApi
|
2
2
|
class Server
|
3
|
+
DHCPS_WIN2008_API = Object,new
|
4
|
+
DHCPS_WIN2012_API = Object,new
|
5
|
+
DHCPS_NONE = Object,new
|
6
|
+
|
3
7
|
include RubyStructAttrHelpers
|
4
8
|
include CommonMethods
|
9
|
+
|
5
10
|
include Class
|
6
11
|
include Client
|
12
|
+
include Misc
|
7
13
|
include Option
|
8
14
|
include OptionValue
|
9
15
|
include Reservation
|
10
16
|
include Subnet
|
11
|
-
include Misc
|
12
17
|
|
13
18
|
attr_reader :server_ip_address
|
14
19
|
|
15
20
|
def initialize(server_ip_address)
|
16
21
|
@server_ip_address = server_ip_address
|
17
22
|
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
level = :none
|
26
|
+
|
27
|
+
# load Win2008 (and earlier)-specific bindings
|
28
|
+
require 'dhcpsapi/win2008/free_memory'
|
29
|
+
require 'dhcpsapi/win2008/class'
|
30
|
+
require 'dhcpsapi/win2008/client'
|
31
|
+
require 'dhcpsapi/win2008/option'
|
32
|
+
require 'dhcpsapi/win2008/option_value'
|
33
|
+
require 'dhcpsapi/win2008/subnet_element'
|
34
|
+
require 'dhcpsapi/win2008/subnet'
|
35
|
+
|
36
|
+
level = :win2008
|
37
|
+
|
38
|
+
# load Win2012-specific bindings
|
39
|
+
require 'dhcpsapi/win2012/client'
|
40
|
+
require 'dhcpsapi/win2012/misc'
|
41
|
+
require 'dhcpsapi/win2012/reservation'
|
42
|
+
|
43
|
+
API_LEVEL = DHCPS_WIN2012_API
|
44
|
+
rescue Exception => e
|
45
|
+
API_LEVEL = level == :win2008 ? DHCPS_WIN2008_API : DHCPS_NONE
|
46
|
+
end
|
18
47
|
end
|
19
48
|
end
|
data/lib/dhcpsapi/subnet.rb
CHANGED
@@ -1,78 +1,4 @@
|
|
1
1
|
module DhcpsApi
|
2
|
-
=begin
|
3
|
-
typedef struct _DHCP_SUBNET_INFO {
|
4
|
-
DHCP_IP_ADDRESS SubnetAddress;
|
5
|
-
DHCP_IP_MASK SubnetMask;
|
6
|
-
LPWSTR SubnetName;
|
7
|
-
LPWSTR SubnetComment;
|
8
|
-
DHCP_HOST_INFO PrimaryHost;
|
9
|
-
DHCP_SUBNET_STATE SubnetState;
|
10
|
-
} DHCP_SUBNET_INFO, *LPDHCP_SUBNET_INFO;
|
11
|
-
=end
|
12
|
-
class DHCP_SUBNET_INFO < DHCPS_Struct
|
13
|
-
layout :subnet_address, :uint32,
|
14
|
-
:subnet_mask, :uint32,
|
15
|
-
:subnet_name, :pointer,
|
16
|
-
:subnet_comment, :pointer,
|
17
|
-
:primary_host, DHCP_HOST_INFO,
|
18
|
-
:subnet_state, :uint32
|
19
|
-
|
20
|
-
ruby_struct_attr :uint32_to_ip, :subnet_address, :subnet_mask
|
21
|
-
ruby_struct_attr :to_string, :subnet_name, :subnet_comment
|
22
|
-
end
|
23
|
-
|
24
|
-
=begin
|
25
|
-
typedef struct _DHCP_IP_RANGE {
|
26
|
-
DHCP_IP_ADDRESS StartAddress;
|
27
|
-
DHCP_IP_ADDRESS EndAddress;
|
28
|
-
} DHCP_IP_RANGE, *LPDHCP_IP_RANGE;
|
29
|
-
=end
|
30
|
-
class DHCP_IP_RANGE < DHCPS_Struct
|
31
|
-
layout :start_address, :uint32,
|
32
|
-
:end_address, :uint32
|
33
|
-
|
34
|
-
ruby_struct_attr :uint32_to_ip, :subnet_address, :subnet_mask
|
35
|
-
end
|
36
|
-
|
37
|
-
=begin
|
38
|
-
DWORD DHCP_API_FUNCTION DhcpEnumSubnets(
|
39
|
-
_In_ DHCP_CONST WCHAR *ServerIpAddress,
|
40
|
-
_Inout_ DHCP_RESUME_HANDLE *ResumeHandle,
|
41
|
-
_In_ DWORD PreferredMaximum,
|
42
|
-
_Out_ LPDHCP_IP_ARRAY *EnumInfo,
|
43
|
-
_Out_ DWORD *ElementsRead,
|
44
|
-
_Out_ DWORD *ElementsTotal
|
45
|
-
);
|
46
|
-
=end
|
47
|
-
attach_function :DhcpEnumSubnets, [:pointer, :pointer, :uint32, :pointer, :pointer, :pointer], :uint32
|
48
|
-
|
49
|
-
=begin
|
50
|
-
DWORD DHCP_API_FUNCTION DhcpCreateSubnet(
|
51
|
-
_In_ DHCP_CONST WCHAR *ServerIpAddress,
|
52
|
-
_In_ DHCP_IP_ADDRESS SubnetAddress,
|
53
|
-
_In_ DHCP_CONST DHCP_SUBNET_INFO *SubnetInfo
|
54
|
-
);
|
55
|
-
=end
|
56
|
-
attach_function :DhcpCreateSubnet, [:pointer, :uint32, :pointer], :uint32
|
57
|
-
|
58
|
-
=begin
|
59
|
-
DWORD DHCP_API_FUNCTION DhcpDeleteSubnet(
|
60
|
-
_In_ DHCP_CONST WCHAR *ServerIpAddress,
|
61
|
-
_In_ DHCP_IP_ADDRESS SubnetAddress,
|
62
|
-
_In_ DHCP_FORCE_FLAG ForceFlag
|
63
|
-
);
|
64
|
-
=end
|
65
|
-
attach_function :DhcpDeleteSubnet, [:pointer, :uint32, :uint32], :uint32
|
66
|
-
|
67
|
-
=begin
|
68
|
-
DWORD DHCP_API_FUNCTION DhcpGetSubnetInfo(
|
69
|
-
_In_ DHCP_CONST WCHAR *ServerIpAddress,
|
70
|
-
_In_ DHCP_IP_ADDRESS SubnetAddress,
|
71
|
-
_Out_ LPDHCP_SUBNET_INFO *SubnetInfo
|
72
|
-
);
|
73
|
-
=end
|
74
|
-
attach_function :DhcpGetSubnetInfo, [:pointer, :uint32, :pointer], :uint32
|
75
|
-
|
76
2
|
module Subnet
|
77
3
|
include CommonMethods
|
78
4
|
|
@@ -92,14 +18,14 @@ module DhcpsApi
|
|
92
18
|
subnet_info[:subnet_name] = FFI::MemoryPointer.from_string(to_wchar_string(subnet_name))
|
93
19
|
subnet_info[:subnet_comment] = FFI::MemoryPointer.from_string(to_wchar_string(subnet_comment))
|
94
20
|
|
95
|
-
error = DhcpsApi.DhcpCreateSubnet(to_wchar_string(server_ip_address), ip_to_uint32(subnet_address), subnet_info.pointer)
|
21
|
+
error = DhcpsApi::Win2008::Subnet.DhcpCreateSubnet(to_wchar_string(server_ip_address), ip_to_uint32(subnet_address), subnet_info.pointer)
|
96
22
|
raise DhcpsApi::Error.new("Error creating subnet.", error) if error != 0
|
97
23
|
|
98
24
|
subnet_info.as_ruby_struct
|
99
25
|
end
|
100
26
|
|
101
27
|
def delete_subnet(subnet_address, force_flag = DhcpsApi::DHCP_FORCE_FLAG::DhcpNoForce)
|
102
|
-
error = DhcpsApi.DhcpDeleteSubnet(to_wchar_string(server_ip_address), ip_to_uint32(subnet_address), force_flag)
|
28
|
+
error = DhcpsApi::Win2008::Subnet.DhcpDeleteSubnet(to_wchar_string(server_ip_address), ip_to_uint32(subnet_address), force_flag)
|
103
29
|
raise DhcpsApi::Error.new("Error deleting subnet.", error) if error != 0
|
104
30
|
end
|
105
31
|
|
@@ -110,7 +36,7 @@ module DhcpsApi
|
|
110
36
|
ip_range[:start_address] = ip_to_uint32(start_address)
|
111
37
|
ip_range[:end_address] = ip_to_uint32(end_address)
|
112
38
|
|
113
|
-
error = DhcpsApi.DhcpAddSubnetElementV4(to_wchar_string(server_ip_address), ip_to_uint32(subnet_address), subnet_element.pointer)
|
39
|
+
error = DhcpsApi::Win2008::SubnetElement.DhcpAddSubnetElementV4(to_wchar_string(server_ip_address), ip_to_uint32(subnet_address), subnet_element.pointer)
|
114
40
|
raise DhcpsApi::Error.new("Error adding a subnet range to '%s'." % [subnet_address], error) if error != 0
|
115
41
|
|
116
42
|
subnet_element.as_ruby_struct
|
@@ -123,7 +49,7 @@ module DhcpsApi
|
|
123
49
|
ip_range[:start_address] = ip_to_uint32(start_address)
|
124
50
|
ip_range[:end_address] = ip_to_uint32(end_address)
|
125
51
|
|
126
|
-
error = DhcpsApi.DhcpRemoveSubnetElementV4(
|
52
|
+
error = DhcpsApi::Win2008::SubnetElement.DhcpRemoveSubnetElementV4(
|
127
53
|
to_wchar_string(server_ip_address),
|
128
54
|
ip_to_uint32(subnet_address),
|
129
55
|
to_delete.pointer,
|
@@ -140,7 +66,7 @@ module DhcpsApi
|
|
140
66
|
def dhcp_get_subnet_info(subnet_address)
|
141
67
|
subnet_info_ptr_ptr = FFI::MemoryPointer.new(:pointer)
|
142
68
|
|
143
|
-
error = DhcpsApi.DhcpGetSubnetInfo(to_wchar_string(server_ip_address), subnet_address, subnet_info_ptr_ptr)
|
69
|
+
error = DhcpsApi::Win2008::Subnet.DhcpGetSubnetInfo(to_wchar_string(server_ip_address), subnet_address, subnet_info_ptr_ptr)
|
144
70
|
if is_error?(error)
|
145
71
|
unless (subnet_info_ptr_ptr.null? || (to_free = subnet_info_ptr_ptr.read_pointer).null?)
|
146
72
|
free_memory(DhcpsApi::DHCP_SUBNET_INFO.new(to_free))
|
@@ -161,7 +87,7 @@ module DhcpsApi
|
|
161
87
|
elements_read_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, 0)
|
162
88
|
elements_total_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, 0)
|
163
89
|
|
164
|
-
error = DhcpsApi.DhcpEnumSubnets(to_wchar_string(server_ip_address), resume_handle_ptr, preferred_maximium, dhcp_ip_array_ptr_ptr, elements_read_ptr, elements_total_ptr)
|
90
|
+
error = DhcpsApi::Win2008::Subnet.DhcpEnumSubnets(to_wchar_string(server_ip_address), resume_handle_ptr, preferred_maximium, dhcp_ip_array_ptr_ptr, elements_read_ptr, elements_total_ptr)
|
165
91
|
return empty_response if error == 259
|
166
92
|
if is_error?(error)
|
167
93
|
unless (dhcp_ip_array_ptr_ptr.null? || (to_free = dhcp_ip_array_ptr_ptr.read_pointer).null?)
|
data/lib/dhcpsapi/version.rb
CHANGED