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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9740f4c12d6acbd2ec1543f1b2df97e2b4ecd80
|
4
|
+
data.tar.gz: 89ebad17dc6a96c7354a06754dfc79f76d7bde8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d389e520e1ab8e5e29920b6a29c082f71a4d4b5a42021c4ba201d2ce1a71c7f2c355e9c1b420290d7c8fdd34972d7e25a50dc1e5423a62610133f11f659cc5dd
|
7
|
+
data.tar.gz: 66f36da0548a51a88bf410f3fb91cce72da8eb5cdf5a8ba0680a051cac1842b7ac04c14b91fc959b4ad0566f5683ebb0842d8233f9ead53a9d88d81db7a3bb9f
|
data/lib/dhcpsapi/class.rb
CHANGED
@@ -1,78 +1,4 @@
|
|
1
1
|
module DhcpsApi
|
2
|
-
#
|
3
|
-
# DHCP_CLASS_INFO data structure describes an option class.
|
4
|
-
#
|
5
|
-
# Available fields:
|
6
|
-
# :class_name [String],
|
7
|
-
# :class_comment [String],
|
8
|
-
# :is_vendor [Boolean],
|
9
|
-
# :flags [Fixnum],
|
10
|
-
# :class_data [String]
|
11
|
-
#
|
12
|
-
# @see https://msdn.microsoft.com/en-us/library/windows/desktop/dd897569(v=vs.85).aspx
|
13
|
-
#
|
14
|
-
class DHCP_CLASS_INFO < DHCPS_Struct
|
15
|
-
layout :class_name, :pointer,
|
16
|
-
:class_comment, :pointer,
|
17
|
-
:class_data_length, :uint32,
|
18
|
-
:is_vendor, :bool,
|
19
|
-
:flags, :uint32,
|
20
|
-
:class_data, :pointer
|
21
|
-
|
22
|
-
ruby_struct_attr :to_string, :class_name, :class_comment, :policy_name
|
23
|
-
ruby_struct_attr :class_data_as_string, :class_data
|
24
|
-
|
25
|
-
private
|
26
|
-
def class_data_as_string(unused)
|
27
|
-
self[:class_data].read_array_of_type(:uint8, :read_uint8, self[:class_data_length])
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# DHCP_CLASS_INFO data structure describes an array of option classes.
|
33
|
-
#
|
34
|
-
# Available fields:
|
35
|
-
# :num_elements [Fixnum],
|
36
|
-
# :classes [Array<Hash>]
|
37
|
-
#
|
38
|
-
# @see https://msdn.microsoft.com/en-us/library/windows/desktop/dd897570(v=vs.85).aspx
|
39
|
-
#
|
40
|
-
class DHCP_CLASS_INFO_ARRAY < DHCPS_Struct
|
41
|
-
layout :num_elements, :uint32,
|
42
|
-
:classes, :pointer
|
43
|
-
end
|
44
|
-
|
45
|
-
=begin
|
46
|
-
DWORD DhcpEnumClasses(
|
47
|
-
_In_ LPWSTR ServerIpAddress,
|
48
|
-
_In_ DWORD ReservedMustBeZero,
|
49
|
-
_Inout_ DHCP_RESUME_HANDLE *ResumeHandle,
|
50
|
-
_In_ DWORD PreferredMaximum,
|
51
|
-
_Out_ LPDHCP_CLASS_INFO_ARRAY *ClassInfoArray,
|
52
|
-
_Out_ DWORD *nRead,
|
53
|
-
_Out_ DWORD *nTotal
|
54
|
-
);
|
55
|
-
=end
|
56
|
-
attach_function :DhcpEnumClasses, [:pointer, :uint32, :pointer, :uint32, :pointer, :pointer, :pointer], :uint32
|
57
|
-
|
58
|
-
=begin
|
59
|
-
DWORD DhcpCreateClass(
|
60
|
-
_In_ LPWSTR ServerIpAddress,
|
61
|
-
_In_ DWORD ReservedMustBeZero,
|
62
|
-
_In_ LPDHCP_CLASS_INFO ClassInfo
|
63
|
-
);
|
64
|
-
=end
|
65
|
-
attach_function :DhcpCreateClass, [:pointer, :uint32, :pointer], :uint32
|
66
|
-
|
67
|
-
=begin
|
68
|
-
DWORD DhcpDeleteClass(
|
69
|
-
_In_ LPWSTR ServerIpAddress,
|
70
|
-
_In_ DWORD ReservedMustBeZero,
|
71
|
-
_In_ LPWSTR ClassName
|
72
|
-
);
|
73
|
-
=end
|
74
|
-
attach_function :DhcpDeleteClass, [:pointer, :uint32, :pointer], :uint32
|
75
|
-
|
76
2
|
module Class
|
77
3
|
# Returns option classes available on the server as a List of DHCP_CLASS_INFOs represented as Hashmaps.
|
78
4
|
#
|
@@ -111,7 +37,7 @@ module DhcpsApi
|
|
111
37
|
to_create[:class_data] = FFI::MemoryPointer.from_string(to_wchar_string(data))
|
112
38
|
to_create[:class_data_length] = to_wchar_string(data).bytes.size
|
113
39
|
|
114
|
-
error = DhcpsApi.DhcpCreateClass(to_wchar_string(server_ip_address), 0, to_create.pointer)
|
40
|
+
error = DhcpsApi::Win2008::Class.DhcpCreateClass(to_wchar_string(server_ip_address), 0, to_create.pointer)
|
115
41
|
raise DhcpsApi::Error.new("Error creating class.", error) if error != 0
|
116
42
|
|
117
43
|
to_create.as_ruby_struct
|
@@ -128,7 +54,7 @@ module DhcpsApi
|
|
128
54
|
# @return [void]
|
129
55
|
#
|
130
56
|
def delete_class(class_name)
|
131
|
-
error = DhcpsApi.DhcpDeleteClass(to_wchar_string(server_ip_address), 0, to_wchar_string(class_name))
|
57
|
+
error = DhcpsApi::Win2008::Class.DhcpDeleteClass(to_wchar_string(server_ip_address), 0, to_wchar_string(class_name))
|
132
58
|
raise DhcpsApi::Error.new("Error deleting class.", error) if error != 0
|
133
59
|
end
|
134
60
|
|
@@ -139,7 +65,7 @@ module DhcpsApi
|
|
139
65
|
elements_read_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, 0)
|
140
66
|
elements_total_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, 0)
|
141
67
|
|
142
|
-
error = DhcpsApi.DhcpEnumClasses(
|
68
|
+
error = DhcpsApi::Win2008::Class.DhcpEnumClasses(
|
143
69
|
to_wchar_string(server_ip_address), 0, resume_handle_ptr, preferred_maximum,
|
144
70
|
class_info_ptr_ptr, elements_read_ptr, elements_total_ptr)
|
145
71
|
|
data/lib/dhcpsapi/client.rb
CHANGED
@@ -1,127 +1,4 @@
|
|
1
1
|
module DhcpsApi
|
2
|
-
=begin
|
3
|
-
typedef struct _DHCP_CLIENT_INFO_PB {
|
4
|
-
DHCP_IP_ADDRESS ClientIpAddress;
|
5
|
-
DHCP_IP_MASK SubnetMask;
|
6
|
-
DHCP_CLIENT_UID ClientHardwareAddress;
|
7
|
-
LPWSTR ClientName;
|
8
|
-
LPWSTR ClientComment;
|
9
|
-
DATE_TIME ClientLeaseExpires;
|
10
|
-
DHCP_HOST_INFO OwnerHost;
|
11
|
-
BYTE bClientType;
|
12
|
-
BYTE AddressState;
|
13
|
-
QuarantineStatus Status;
|
14
|
-
DATE_TIME ProbationEnds;
|
15
|
-
BOOL QuarantineCapable;
|
16
|
-
DWORD FilterStatus;
|
17
|
-
LPWSTR PolicyName;
|
18
|
-
} DHCP_CLIENT_INFO_PB, *LPDHCP_CLIENT_INFO_PB;
|
19
|
-
=end
|
20
|
-
class DHCP_CLIENT_INFO_PB < DHCPS_Struct
|
21
|
-
layout :client_ip_address, :uint32,
|
22
|
-
:subnet_mask, :uint32,
|
23
|
-
:client_hardware_address, DHCP_CLIENT_UID,
|
24
|
-
:client_name, :pointer,
|
25
|
-
:client_comment, :pointer,
|
26
|
-
:client_lease_expires, DATE_TIME,
|
27
|
-
:owner_host, DHCP_HOST_INFO,
|
28
|
-
:b_client_type, :uint8, # see ClientType
|
29
|
-
:address_state, :uint8,
|
30
|
-
:status, :uint32,
|
31
|
-
:probation_ends, DATE_TIME,
|
32
|
-
:quarantine_capable, :bool,
|
33
|
-
:filter_status, :uint32,
|
34
|
-
:policy_name, :pointer
|
35
|
-
|
36
|
-
ruby_struct_attr :uint32_to_ip, :client_ip_address, :subnet_mask
|
37
|
-
ruby_struct_attr :dhcp_client_uid_to_mac, :client_hardware_address
|
38
|
-
ruby_struct_attr :to_string, :client_name, :client_comment, :policy_name
|
39
|
-
end
|
40
|
-
|
41
|
-
=begin
|
42
|
-
typedef struct _DHCP_CLIENT_INFO_V4 {
|
43
|
-
DHCP_IP_ADDRESS ClientIpAddress;
|
44
|
-
DHCP_IP_MASK SubnetMask;
|
45
|
-
DHCP_CLIENT_UID ClientHardwareAddress;
|
46
|
-
LPWSTR ClientName;
|
47
|
-
LPWSTR ClientComment;
|
48
|
-
DATE_TIME ClientLeaseExpires;
|
49
|
-
DHCP_HOST_INFO OwnerHost;
|
50
|
-
BYTE bClientType;
|
51
|
-
} DHCP_CLIENT_INFO_V4, *LPDHCP_CLIENT_INFO_V4;
|
52
|
-
=end
|
53
|
-
class DHCP_CLIENT_INFO_V4 < DHCPS_Struct
|
54
|
-
layout :client_ip_address, :uint32,
|
55
|
-
:subnet_mask, :uint32,
|
56
|
-
:client_hardware_address, DHCP_CLIENT_UID,
|
57
|
-
:client_name, :pointer,
|
58
|
-
:client_comment, :pointer,
|
59
|
-
:client_lease_expires, DATE_TIME,
|
60
|
-
:owner_host, DHCP_HOST_INFO,
|
61
|
-
:client_type, :uint8 # see ClientType
|
62
|
-
|
63
|
-
ruby_struct_attr :uint32_to_ip, :client_ip_address, :subnet_mask
|
64
|
-
ruby_struct_attr :dhcp_client_uid_to_mac, :client_hardware_address
|
65
|
-
ruby_struct_attr :to_string, :client_name, :client_comment
|
66
|
-
end
|
67
|
-
|
68
|
-
=begin
|
69
|
-
typedef struct _DHCP_CLIENT_INFO_PB_ARRAY {
|
70
|
-
DWORD NumElements;
|
71
|
-
LPDHCP_CLIENT_INFO_PB *Clients;
|
72
|
-
} DHCP_CLIENT_INFO_PB_ARRAY, *LPDHCP_CLIENT_INFO_PB_ARRAY;
|
73
|
-
=end
|
74
|
-
class DHCP_CLIENT_INFO_PB_ARRAY < DHCPS_Struct
|
75
|
-
layout :num_elements, :uint32,
|
76
|
-
:clients, :pointer
|
77
|
-
end
|
78
|
-
|
79
|
-
=begin
|
80
|
-
DWORD DhcpCreateClientInfoV4(
|
81
|
-
_In_ DHCP_CONST WCHAR *ServerIpAddress,
|
82
|
-
_In_ LPDHCP_CONST DHCP_CLIENT_INFO_V4 ClientInfo
|
83
|
-
);
|
84
|
-
=end
|
85
|
-
attach_function :DhcpCreateClientInfoV4, [:pointer, :pointer], :uint32
|
86
|
-
|
87
|
-
=begin
|
88
|
-
DWORD DhcpSetClientInfoV4(
|
89
|
-
_In_ DHCP_CONST WCHAR *ServerIpAddress,
|
90
|
-
_In_ DHCP_CONST DHCP_CLIENT_INFO_V4 *ClientInfo
|
91
|
-
);
|
92
|
-
=end
|
93
|
-
attach_function :DhcpSetClientInfoV4, [:pointer, :pointer], :uint32
|
94
|
-
|
95
|
-
=begin
|
96
|
-
DWORD DHCP_API_FUNCTION DhcpGetClientInfoV4(
|
97
|
-
_In_ DHCP_CONST WCHAR ServerIpAddress,
|
98
|
-
_In_ DHCP_CONST DHCP_SEARCH_INFO SearchInfo,
|
99
|
-
_Out_ LPDHCP_CLIENT_INFO_V4 *ClientInfo
|
100
|
-
);
|
101
|
-
=end
|
102
|
-
attach_function :DhcpGetClientInfoV4, [:pointer, DHCP_SEARCH_INFO.by_value, :pointer], :uint32
|
103
|
-
|
104
|
-
=begin
|
105
|
-
DWORD DHCP_API_FUNCTION DhcpV4EnumSubnetClients(
|
106
|
-
_In_opt_ DHCP_CONST WCHAR *ServerIpAddress,
|
107
|
-
_In_ DHCP_IP_ADDRESS SubnetAddress,
|
108
|
-
_Inout_ DHCP_RESUME_HANDLE *ResumeHandle,
|
109
|
-
_In_ DWORD PreferredMaximum,
|
110
|
-
_Out_ LPDHCP_CLIENT_INFO_PB_ARRAY *ClientInfo,
|
111
|
-
_Out_ DWORD *ClientsRead,
|
112
|
-
_Out_ DWORD *ClientsTotal
|
113
|
-
);
|
114
|
-
=end
|
115
|
-
attach_function :DhcpV4EnumSubnetClients, [:pointer, :uint32, :pointer, :uint32, :pointer, :pointer, :pointer], :uint32
|
116
|
-
|
117
|
-
=begin
|
118
|
-
DWORD DHCP_API_FUNCTION DhcpDeleteClientInfo(
|
119
|
-
_In_ DHCP_CONST WCHAR *ServerIpAddress,
|
120
|
-
_In_ DHCP_CONST DHCP_SEARCH_INFO *ClientInfo
|
121
|
-
);
|
122
|
-
=end
|
123
|
-
attach_function :DhcpDeleteClientInfo, [:pointer, :pointer], :uint32
|
124
|
-
|
125
2
|
module Client
|
126
3
|
def list_clients(subnet_address)
|
127
4
|
items, _ = retrieve_items(:dhcp_v4_enum_subnet_clients, subnet_address, 1024, 0)
|
@@ -143,7 +20,7 @@ typedef struct _DHCP_CLIENT_INFO_PB_ARRAY {
|
|
143
20
|
to_create[:client_lease_expires][:dw_high_date_time] = 0
|
144
21
|
to_create[:client_type] = client_type
|
145
22
|
|
146
|
-
error = DhcpsApi.DhcpCreateClientInfoV4(to_wchar_string(server_ip_address), to_create.pointer)
|
23
|
+
error = DhcpsApi::Win2008::Client.DhcpCreateClientInfoV4(to_wchar_string(server_ip_address), to_create.pointer)
|
147
24
|
raise DhcpsApi::Error.new("Error creating client.", error) if error != 0
|
148
25
|
|
149
26
|
to_create.as_ruby_struct
|
@@ -164,7 +41,7 @@ typedef struct _DHCP_CLIENT_INFO_PB_ARRAY {
|
|
164
41
|
to_modify[:client_lease_expires][:dw_high_date_time] = 0
|
165
42
|
to_modify[:client_type] = client_type
|
166
43
|
|
167
|
-
error = DhcpsApi.DhcpSetClientInfoV4(to_wchar_string(server_ip_address), to_modify.pointer)
|
44
|
+
error = DhcpsApi::Win2008::Client.DhcpSetClientInfoV4(to_wchar_string(server_ip_address), to_modify.pointer)
|
168
45
|
raise DhcpsApi::Error.new("Error modifying client.", error) if error != 0
|
169
46
|
|
170
47
|
to_modify.as_ruby_struct
|
@@ -203,7 +80,7 @@ typedef struct _DHCP_CLIENT_INFO_PB_ARRAY {
|
|
203
80
|
search_info[:search_type] = DhcpsApi::DHCP_SEARCH_INFO_TYPE::DhcpClientHardwareAddress
|
204
81
|
search_info[:search_info][:client_hardware_address].initialize_with_subnet_and_mac_addresses(subnet_address, client_mac_address)
|
205
82
|
|
206
|
-
error = DhcpsApi.DhcpDeleteClientInfo(to_wchar_string(server_ip_address), search_info.pointer)
|
83
|
+
error = DhcpsApi::Win2008::Client.DhcpDeleteClientInfo(to_wchar_string(server_ip_address), search_info.pointer)
|
207
84
|
raise DhcpsApi::Error.new("Error deleting client.", error) if error != 0
|
208
85
|
end
|
209
86
|
|
@@ -212,7 +89,7 @@ typedef struct _DHCP_CLIENT_INFO_PB_ARRAY {
|
|
212
89
|
search_info[:search_type] = DhcpsApi::DHCP_SEARCH_INFO_TYPE::DhcpClientIpAddress
|
213
90
|
search_info[:search_info][:client_ip_address] = ip_to_uint32(client_ip_address)
|
214
91
|
|
215
|
-
error = DhcpsApi.DhcpDeleteClientInfo(to_wchar_string(server_ip_address), search_info.pointer)
|
92
|
+
error = DhcpsApi::Win2008::Client.DhcpDeleteClientInfo(to_wchar_string(server_ip_address), search_info.pointer)
|
216
93
|
raise DhcpsApi::Error.new("Error deleting client.", error) if error != 0
|
217
94
|
end
|
218
95
|
|
@@ -221,7 +98,7 @@ typedef struct _DHCP_CLIENT_INFO_PB_ARRAY {
|
|
221
98
|
search_info[:search_type] = DhcpsApi::DHCP_SEARCH_INFO_TYPE::DhcpClientName
|
222
99
|
search_info[:search_info][:client_name] = FFI::MemoryPointer.from_string(to_wchar_string(client_name))
|
223
100
|
|
224
|
-
error = DhcpsApi.DhcpDeleteClientInfo(to_wchar_string(server_ip_address), search_info.pointer)
|
101
|
+
error = DhcpsApi::Win2008::Client.DhcpDeleteClientInfo(to_wchar_string(server_ip_address), search_info.pointer)
|
225
102
|
raise DhcpsApi::Error.new("Error deleting client.", error) if error != 0
|
226
103
|
end
|
227
104
|
|
@@ -229,7 +106,7 @@ typedef struct _DHCP_CLIENT_INFO_PB_ARRAY {
|
|
229
106
|
def get_client(search_info, client_id)
|
230
107
|
client_info_ptr_ptr = FFI::MemoryPointer.new(:pointer)
|
231
108
|
|
232
|
-
error = DhcpsApi.DhcpGetClientInfoV4(to_wchar_string(server_ip_address), search_info.pointer, client_info_ptr_ptr)
|
109
|
+
error = DhcpsApi::Win2008::Client.DhcpGetClientInfoV4(to_wchar_string(server_ip_address), search_info.pointer, client_info_ptr_ptr)
|
233
110
|
if is_error?(error)
|
234
111
|
unless (client_info_ptr_ptr.null? || (to_free = client_info_ptr_ptr.read_pointer).null?)
|
235
112
|
free_memory(DhcpsApi::DHCP_CLIENT_INFO_V4.new(to_free))
|
@@ -250,7 +127,7 @@ typedef struct _DHCP_CLIENT_INFO_PB_ARRAY {
|
|
250
127
|
elements_read_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, 0)
|
251
128
|
elements_total_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, 0)
|
252
129
|
|
253
|
-
error = DhcpsApi.DhcpV4EnumSubnetClients(
|
130
|
+
error = DhcpsApi::Win2012::Client.DhcpV4EnumSubnetClients(
|
254
131
|
to_wchar_string(server_ip_address), ip_to_uint32(subnet_address), resume_handle_ptr, preferred_maximum,
|
255
132
|
client_info_ptr_ptr, elements_read_ptr, elements_total_ptr)
|
256
133
|
return empty_response if error == 259
|
data/lib/dhcpsapi/common.rb
CHANGED
@@ -63,17 +63,10 @@ module DhcpsApi
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
=begin
|
67
|
-
VOID DHCP_API_FUNCTION DhcpRpcFreeMemory(
|
68
|
-
PVOID BufferPointer
|
69
|
-
);
|
70
|
-
=end
|
71
|
-
attach_function :DhcpRpcFreeMemory, [:pointer], :void
|
72
|
-
|
73
66
|
# @private
|
74
67
|
module CommonMethods
|
75
68
|
def free_memory(a_struct)
|
76
|
-
DhcpsApi.DhcpRpcFreeMemory(a_struct.pointer)
|
69
|
+
DhcpsApi::Win2008::Common.DhcpRpcFreeMemory(a_struct.pointer)
|
77
70
|
end
|
78
71
|
|
79
72
|
def retrieve_items(method_to_call, *args)
|