2 * Network Store Interface
4 * Copyright 2021 Huw Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/heap.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(nsi
);
33 static inline HANDLE
get_nsi_device( void )
35 return CreateFileW( L
"\\\\.\\Nsi", 0, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, NULL
);
38 DWORD WINAPI
NsiAllocateAndGetTable( DWORD unk
, const NPI_MODULEID
*module
, DWORD table
, void **key_data
, DWORD key_size
,
39 void **rw_data
, DWORD rw_size
, void **dynamic_data
, DWORD dynamic_size
,
40 void **static_data
, DWORD static_size
, DWORD
*count
, DWORD unk2
)
43 void *data
[4] = { NULL
};
44 DWORD sizes
[4] = { key_size
, rw_size
, dynamic_size
, static_size
};
47 TRACE( "%d %p %d %p %d %p %d %p %d %p %d %p %d\n", unk
, module
, table
, key_data
, key_size
,
48 rw_data
, rw_size
, dynamic_data
, dynamic_size
, static_data
, static_size
, count
, unk2
);
50 for (attempt
= 0; attempt
< 5; attempt
++)
52 err
= NsiEnumerateObjectsAllParameters( unk
, 0, module
, table
, NULL
, 0, NULL
, 0, NULL
, 0, NULL
, 0, &num
);
55 for (i
= 0; i
< ARRAY_SIZE(data
); i
++)
59 data
[i
] = heap_alloc( sizes
[i
] * num
);
62 err
= ERROR_OUTOFMEMORY
;
68 err
= NsiEnumerateObjectsAllParameters( unk
, 0, module
, table
, data
[0], sizes
[0], data
[1], sizes
[1],
69 data
[2], sizes
[2], data
[3], sizes
[3], &num
);
70 if (err
!= ERROR_MORE_DATA
) break;
72 NsiFreeTable( data
[0], data
[1], data
[2], data
[3] );
73 memset( data
, 0, sizeof(data
) );
78 if (sizes
[0]) *key_data
= data
[0];
79 if (sizes
[1]) *rw_data
= data
[1];
80 if (sizes
[2]) *dynamic_data
= data
[2];
81 if (sizes
[3]) *static_data
= data
[3];
86 if (err
) NsiFreeTable( data
[0], data
[1], data
[2], data
[3] );
90 DWORD WINAPI
NsiEnumerateObjectsAllParameters( DWORD unk
, DWORD unk2
, const NPI_MODULEID
*module
, DWORD table
,
91 void *key_data
, DWORD key_size
, void *rw_data
, DWORD rw_size
,
92 void *dynamic_data
, DWORD dynamic_size
, void *static_data
, DWORD static_size
,
95 struct nsi_enumerate_all_ex params
;
98 TRACE( "%d %d %p %d %p %d %p %d %p %d %p %d %p\n", unk
, unk2
, module
, table
, key_data
, key_size
,
99 rw_data
, rw_size
, dynamic_data
, dynamic_size
, static_data
, static_size
, count
);
101 params
.unknown
[0] = 0;
102 params
.unknown
[1] = 0;
103 params
.module
= module
;
104 params
.table
= table
;
105 params
.first_arg
= unk
;
106 params
.second_arg
= unk2
;
107 params
.key_data
= key_data
;
108 params
.key_size
= key_size
;
109 params
.rw_data
= rw_data
;
110 params
.rw_size
= rw_size
;
111 params
.dynamic_data
= dynamic_data
;
112 params
.dynamic_size
= dynamic_size
;
113 params
.static_data
= static_data
;
114 params
.static_size
= static_size
;
115 params
.count
= *count
;
117 err
= NsiEnumerateObjectsAllParametersEx( ¶ms
);
118 *count
= params
.count
;
122 DWORD WINAPI
NsiEnumerateObjectsAllParametersEx( struct nsi_enumerate_all_ex
*params
)
124 DWORD out_size
, received
, err
= ERROR_SUCCESS
;
125 HANDLE device
= get_nsi_device();
126 struct nsiproxy_enumerate_all in
;
129 if (device
== INVALID_HANDLE_VALUE
) return GetLastError();
131 out_size
= sizeof(DWORD
) +
132 (params
->key_size
+ params
->rw_size
+ params
->dynamic_size
+ params
->static_size
) * params
->count
;
134 out
= heap_alloc( out_size
);
137 CloseHandle( device
);
138 return ERROR_OUTOFMEMORY
;
141 in
.module
= *params
->module
;
142 in
.first_arg
= params
->first_arg
;
143 in
.second_arg
= params
->second_arg
;
144 in
.table
= params
->table
;
145 in
.key_size
= params
->key_size
;
146 in
.rw_size
= params
->rw_size
;
147 in
.dynamic_size
= params
->dynamic_size
;
148 in
.static_size
= params
->static_size
;
149 in
.count
= params
->count
;
151 if (!DeviceIoControl( device
, IOCTL_NSIPROXY_WINE_ENUMERATE_ALL
, &in
, sizeof(in
), out
, out_size
, &received
, NULL
))
152 err
= GetLastError();
153 if (err
== ERROR_SUCCESS
|| err
== ERROR_MORE_DATA
)
155 params
->count
= *(DWORD
*)out
;
156 ptr
= out
+ sizeof(DWORD
);
157 if (params
->key_size
) memcpy( params
->key_data
, ptr
, params
->key_size
* params
->count
);
158 ptr
+= params
->key_size
* in
.count
;
159 if (params
->rw_size
) memcpy( params
->rw_data
, ptr
, params
->rw_size
* params
->count
);
160 ptr
+= params
->rw_size
* in
.count
;
161 if (params
->dynamic_size
) memcpy( params
->dynamic_data
, ptr
, params
->dynamic_size
* params
->count
);
162 ptr
+= params
->dynamic_size
* in
.count
;
163 if (params
->static_size
) memcpy( params
->static_data
, ptr
, params
->static_size
* params
->count
);
167 CloseHandle( device
);
172 void WINAPI
NsiFreeTable( void *key_data
, void *rw_data
, void *dynamic_data
, void *static_data
)
174 TRACE( "%p %p %p %p\n", key_data
, rw_data
, dynamic_data
, static_data
);
175 heap_free( key_data
);
176 heap_free( rw_data
);
177 heap_free( dynamic_data
);
178 heap_free( static_data
);
181 DWORD WINAPI
NsiGetAllParameters( DWORD unk
, const NPI_MODULEID
*module
, DWORD table
, const void *key
, DWORD key_size
,
182 void *rw_data
, DWORD rw_size
, void *dynamic_data
, DWORD dynamic_size
,
183 void *static_data
, DWORD static_size
)
185 struct nsi_get_all_parameters_ex params
;
187 TRACE( "%d %p %d %p %d %p %d %p %d %p %d\n", unk
, module
, table
, key
, key_size
,
188 rw_data
, rw_size
, dynamic_data
, dynamic_size
, static_data
, static_size
);
190 params
.unknown
[0] = 0;
191 params
.unknown
[1] = 0;
192 params
.module
= module
;
193 params
.table
= table
;
194 params
.first_arg
= unk
;
197 params
.key_size
= key_size
;
198 params
.rw_data
= rw_data
;
199 params
.rw_size
= rw_size
;
200 params
.dynamic_data
= dynamic_data
;
201 params
.dynamic_size
= dynamic_size
;
202 params
.static_data
= static_data
;
203 params
.static_size
= static_size
;
205 return NsiGetAllParametersEx( ¶ms
);
208 DWORD WINAPI
NsiGetAllParametersEx( struct nsi_get_all_parameters_ex
*params
)
210 HANDLE device
= get_nsi_device();
211 struct nsiproxy_get_all_parameters
*in
;
212 ULONG in_size
= FIELD_OFFSET( struct nsiproxy_get_all_parameters
, key
[params
->key_size
] ), received
;
213 ULONG out_size
= params
->rw_size
+ params
->dynamic_size
+ params
->static_size
;
214 DWORD err
= ERROR_SUCCESS
;
217 if (device
== INVALID_HANDLE_VALUE
) return GetLastError();
219 in
= heap_alloc( in_size
);
220 out
= heap_alloc( out_size
);
223 err
= ERROR_OUTOFMEMORY
;
227 in
->module
= *params
->module
;
228 in
->first_arg
= params
->first_arg
;
229 in
->table
= params
->table
;
230 in
->key_size
= params
->key_size
;
231 in
->rw_size
= params
->rw_size
;
232 in
->dynamic_size
= params
->dynamic_size
;
233 in
->static_size
= params
->static_size
;
234 memcpy( in
->key
, params
->key
, params
->key_size
);
236 if (!DeviceIoControl( device
, IOCTL_NSIPROXY_WINE_GET_ALL_PARAMETERS
, in
, in_size
, out
, out_size
, &received
, NULL
))
237 err
= GetLastError();
238 if (err
== ERROR_SUCCESS
)
241 if (params
->rw_size
) memcpy( params
->rw_data
, ptr
, params
->rw_size
);
242 ptr
+= params
->rw_size
;
243 if (params
->dynamic_size
) memcpy( params
->dynamic_data
, ptr
, params
->dynamic_size
);
244 ptr
+= params
->dynamic_size
;
245 if (params
->static_size
) memcpy( params
->static_data
, ptr
, params
->static_size
);
251 CloseHandle( device
);
255 DWORD WINAPI
NsiGetParameter( DWORD unk
, const NPI_MODULEID
*module
, DWORD table
, const void *key
, DWORD key_size
,
256 DWORD param_type
, void *data
, DWORD data_size
, DWORD data_offset
)
258 struct nsi_get_parameter_ex params
;
260 FIXME( "%d %p %d %p %d %d %p %d %d: stub\n", unk
, module
, table
, key
, key_size
,
261 param_type
, data
, data_size
, data_offset
);
263 params
.unknown
[0] = 0;
264 params
.unknown
[1] = 0;
265 params
.module
= module
;
266 params
.table
= table
;
267 params
.first_arg
= unk
;
270 params
.key_size
= key_size
;
271 params
.param_type
= param_type
;
273 params
.data_size
= data_size
;
274 params
.data_offset
= data_offset
;
275 return NsiGetParameterEx( ¶ms
);
278 DWORD WINAPI
NsiGetParameterEx( struct nsi_get_parameter_ex
*params
)
280 return ERROR_CALL_NOT_IMPLEMENTED
;