ReactOS  0.4.15-dev-2985-g54406bf
fxregistryapi.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxRegistryAPI.cpp
8 
9 Abstract:
10 
11  This module implements registry access in the framework
12 
13 Author:
14 
15 
16 
17 Environment:
18 
19  Both kernel and user mode
20 
21 Revision History:
22 
23 --*/
24 
25 #include "fxsupportpch.hpp"
26 
27 extern "C" {
28 // #include "FxRegistryAPI.tmh"
29 #define RtlSizeTToULong RtlULongPtrToULong
30 }
31 
32 extern "C" {
33 //
34 // Not in a public header that we can reach, but is documented
35 //
38 NTAPI
40  __in IN HANDLE Key,
42  );
43 }
44 
45 
46 //
47 // Extern "C" the entire file
48 //
49 extern "C" {
50 
54 STDCALL
55 WDFEXPORT(WdfRegistryOpenKey)(
56  __in
58  __in_opt
59  WDFKEY ParentKey,
60  __in
62  __in
64  __in_opt
66  __out
67  WDFKEY* Key
68  )
69 {
70  DDI_ENTRY();
71 
75  WDFKEY keyHandle;
77 
79  keyHandle = NULL;
80 
81  if (ParentKey != NULL) {
83 
85  ParentKey,
87  (PVOID*) &pParent,
89 
90  parentHandle = pParent->GetHandle();
91  }
92  else {
94 
95  //
96  // Get the parent's globals if it is present
97  //
99  KeyAttributes))) {
100  FxObject* pParent;
101 
103  KeyAttributes->ParentObject,
105  (PVOID*)&pParent,
107  }
108  }
109 
112 
113  *Key = NULL;
114 
117  return status;
118  }
119 
121  if (!NT_SUCCESS(status)) {
122  return status;
123  }
124 
126  if (!NT_SUCCESS(status)) {
127  return status;
128  }
129 
131  if (pKey == NULL) {
133 
136  "Could not allocate memory for a WDFKEY, %!STATUS!", status);
137 
138  return status;
139  }
140 
142 
145 
146  if (NT_SUCCESS(status)) {
147  *Key = keyHandle;
148  }
149  else {
152  "new WDFKEY object open failed, %!STATUS!", status);
153  }
154  }
155 
156  if (!NT_SUCCESS(status)) {
158  pKey = NULL;
159  }
160 
161  return status;
162 }
163 
166 NTSTATUS
167 STDCALL
168 WDFEXPORT(WdfRegistryCreateKey)(
169  __in
171  __in_opt
172  WDFKEY ParentKey,
173  __in
175  __in
177  __in
179  __out_opt
181  __in_opt
183  __out
184  WDFKEY* Key
185  )
186 {
187  DDI_ENTRY();
188 
190  FxRegKey* pKey;
192  WDFKEY keyHandle;
194 
196 
197  if (ParentKey != NULL) {
198  FxRegKey* pParent;
199 
201  ParentKey,
203  (PVOID*) &pParent,
205 
206  parentHandle = pParent->GetHandle();
207  }
208  else {
209  parentHandle = NULL;
210 
211  //
212  // Get the parent's globals if it is present
213  //
215  KeyAttributes))) {
216  FxObject* pParent;
217 
219  KeyAttributes->ParentObject,
221  (PVOID*)&pParent,
223  }
224  }
225 
228 
229  *Key = NULL;
230  keyHandle = NULL;
231 
233  if (!NT_SUCCESS(status)) {
234  return status;
235  }
236 
238  if (!NT_SUCCESS(status)) {
239  return status;
240  }
241 
243  if (!NT_SUCCESS(status)) {
244  return status;
245  }
246 
248 
249  if (pKey == NULL) {
253  "Could not allocate memory for WDFKEY, %!STATUS!", status);
254 
255  return status;
256  }
257 
259 
260  if (NT_SUCCESS(status)) {
261  status = pKey->Create(parentHandle,
262  KeyName,
266 
267  if (NT_SUCCESS(status)) {
268  *Key = keyHandle;
269  }
270  else {
273  "Registry key creation failed, %!STATUS!", status);
274  }
275  }
276 
277  if (!NT_SUCCESS(status)) {
279  pKey = NULL;
280  }
281 
282  return status;
283 }
284 
286 VOID
287 STDCALL
288 WDFEXPORT(WdfRegistryClose)(
289  __in
291  __in
292  WDFKEY Key
293  )
294 {
295  DDI_ENTRY();
296 
298  FxRegKey* pKey;
300 
302  Key,
304  (PVOID*) &pKey,
306 
308  if (!NT_SUCCESS(status)) {
310  return;
311  }
312 
313  pKey->Close();
314 
315  pKey->DeleteObject();
316 }
317 
319 HANDLE
320 STDCALL
321 WDFEXPORT(WdfRegistryWdmGetHandle)(
322  __in
324  __in
325  WDFKEY Key
326  )
327 {
328  DDI_ENTRY();
329 
330  FxRegKey* pKey;
331 
333  Key,
335  (PVOID*) &pKey);
336 
337  return pKey->GetHandle();
338 }
339 
342 NTSTATUS
343 STDCALL
344 WDFEXPORT(WdfRegistryRemoveKey)(
345  __in
347  __in
348  WDFKEY Key
349  )
350 {
351  DDI_ENTRY();
352 
354  FxRegKey* pKey;
356 
358  Key,
360  (PVOID*) &pKey,
362 
364  if (!NT_SUCCESS(status)) {
365  return status;
366  }
367 
369 
370  if (NT_SUCCESS(status)) {
371  //
372  // pKey->GetHandle() is now useless, delete the Fx object
373  //
374  pKey->DeleteObject();
375  }
376 
377  return status;
378 }
379 
382 NTSTATUS
383 STDCALL
384 WDFEXPORT(WdfRegistryRemoveValue)(
385  __in
387  __in
388  WDFKEY Key,
389  __in
391  )
392 {
393  DDI_ENTRY();
394 
396  FxRegKey* pKey;
398 
400  Key,
402  (PVOID*) &pKey,
404 
406  if (!NT_SUCCESS(status)) {
407  return status;
408  }
409 
411  if (!NT_SUCCESS(status)) {
412  return status;
413  }
414 
416 
418 
419  return status;
420 }
421 
424 NTSTATUS
425 STDCALL
426 WDFEXPORT(WdfRegistryQueryValue)(
427  __in
429  __in
430  WDFKEY Key,
431  __in
433  __in
436  PVOID Value,
437  __out_opt
439  __out_opt
441  )
442 {
443  DDI_ENTRY();
444 
446  FxRegKey* pKey;
448 
450  Key,
452  (PVOID*) &pKey,
454 
456 
458  if (!NT_SUCCESS(status)) {
459  return status;
460  }
461 
463  if (!NT_SUCCESS(status)) {
464  return status;
465  }
466 
467  status = FxRegKey::_QueryValue(pFxDriverGlobals,
468  pKey->GetHandle(),
469  ValueName,
470  ValueLength,
471  Value,
473  ValueType);
474  if (!NT_SUCCESS(status)) {
475  UCHAR traceLevel = TRACE_LEVEL_ERROR;
476 
477  //
478  // Label message as Verbose if this is the known pattern of
479  // passing a 0-length NULL buffer to query the required buffer size.
480  //
481  if (status == STATUS_BUFFER_OVERFLOW && Value == NULL && ValueLength == 0) {
482  traceLevel = TRACE_LEVEL_VERBOSE;
483  }
484 
486  "WDFKEY %p QueryValue failed, %!STATUS!",
487  Key, status);
488  }
489 
490  return status;
491 }
492 
495 NTSTATUS
496 STDCALL
497 WDFEXPORT(WdfRegistryQueryMemory)(
498  __in
500  __in
501  WDFKEY Key,
502  __in
504  __in
507  __in_opt
509  __out
510  WDFMEMORY* Memory,
511  __out_opt
513  )
514 {
515  DDI_ENTRY();
516 
517  FxRegKey* pKey;
522 
524  Key,
526  (PVOID*) &pKey,
528 
531 
532  *Memory = NULL;
533 
535  if (!NT_SUCCESS(status)) {
536  return status;
537  }
538 
540 
542  if (!NT_SUCCESS(status)) {
543  return status;
544  }
545 
547  if (!NT_SUCCESS(status)) {
548  return status;
549  }
550 
551  //
552  // Query the buffer length required.
553  //
554  status = pKey->QueryValue(ValueName, 0, NULL, &dataLength, NULL);
556  return status;
557  }
558 
559  dataBuffer = FxPoolAllocate(pFxDriverGlobals, PagedPool, dataLength);
560  if (dataBuffer == NULL) {
562 
565  "WDFKEY %p KEY_VALUE_PARTIAL_INFORMATION allocation failed, %!STATUS!",
566  Key, status);
567 
568  return status;
569  }
570 
572  if (NT_SUCCESS(status)) {
574 
577  PoolType,
579  dataLength,
580  &pObject);
581 
582  if (NT_SUCCESS(status)) {
584 
585  if (NT_SUCCESS(status)) {
586  RtlCopyMemory(pObject->GetBuffer(),
587  dataBuffer,
588  dataLength);
589  }
590  else {
592  }
593  }
594  else {
597  "WDFKEY %p WDFMEMORY object create failed, %!STATUS!",
598  Key, status);
599  }
600  }
601  else {
603  "WDFKEY %p QueryPartial failed, %!STATUS!",
604  Key, status);
605  }
606 
608 
609  return status;
610 }
611 
614 NTSTATUS
615 STDCALL
616 WDFEXPORT(WdfRegistryQueryMultiString)(
617  __in
619  __in
620  WDFKEY Key,
621  __in
623  __in_opt
625  __in
626  WDFCOLLECTION Collection
627  )
628 {
629  DDI_ENTRY();
630 
634  FxRegKey* pKey;
638 
640  Key,
642  (PVOID*) &pKey,
644 
645  pDeviceBase = NULL;
646 
649 
651  if (!NT_SUCCESS(status)) {
652  return status;
653  }
654 
656  if (!NT_SUCCESS(status)) {
657  return status;
658  }
659 
661  if (!NT_SUCCESS(status)) {
662  return status;
663  }
664 
666  Collection,
668  (PVOID*) &pCollection);
669 
672 
673  status = pKey->QueryValue(ValueName, 0, NULL, &dataLength, &type);
677  "WDFKEY %p QueryPartial failed: %!STATUS!", Key, status);
678 
679  return status;
680  }
681 
682  if (type != REG_MULTI_SZ) {
684  }
685 
686  dataBuffer = FxPoolAllocate(pFxDriverGlobals, PagedPool, dataLength);
687  if (dataBuffer == NULL) {
689 
692  "WDFKEY %p KEY_VALUE_PARTIAL_INFORMATION allocation failed, %!STATUS!",
693  Key, status);
694 
695  return status;
696  }
697 
699  if (NT_SUCCESS(status)) {
700  //
701  // Verify that the data from the registry is a valid multi-sz string.
702  //
704  ValueName,
705  (PWCHAR) dataBuffer,
706  dataLength);
707  }
708 
709  if (NT_SUCCESS(status)) {
710  ULONG initialCount;
711  PWCHAR pCur;
712 
713  initialCount = pCollection->Count();
714  pCur = (PWCHAR) dataBuffer;
715 
716  while (*pCur != UNICODE_NULL) {
717  FxString* pString;
718 
721 
722  if (pString != NULL) {
723  if (pDeviceBase != NULL) {
725  }
726 
728 
729  if (NT_SUCCESS(status)) {
731 
733  }
734 
735  if (NT_SUCCESS(status)) {
736  if (pCollection->Add(pString) == FALSE) {
738 
741  "WDFKEY %p, WDFCOLLECTION %p, collection add failed "
742  "%!STATUS!", Key, Collection, status);
743  }
744  }
745 
746  if (!NT_SUCCESS(status)) {
747  //
748  // Delete the string we just created
749  //
751  }
752  else {
753  //
754  // NT_SUCCES(status)
755  //
756  // Either the caller is responsible for freeing the
757  // WDFSTRING or it has been parented to another object.
758  //
759  DO_NOTHING();
760  }
761  }
762  else {
764  }
765 
766  if (!NT_SUCCESS(status)) {
769  "WDFKEY %p: WDFSTRING creation failed: %!STATUS!",
770  Key, status);
771  break;
772  }
773 
774  //
775  // Increment to the next string in the multi sz (length of string +
776  // 1 for the NULL)
777  //
778  pCur += wcslen(pCur) + 1;
779  }
780 
781  if (!NT_SUCCESS(status)) {
782  //
783  // Clear out all the items we added to the collection
784  //
785  while (pCollection->Count() > initialCount) {
786  pCollection->Remove(initialCount);
787  }
788  }
789  }
790 
792 
793  return status;
794 }
795 
798 NTSTATUS
799 STDCALL
800 WDFEXPORT(WdfRegistryQueryUnicodeString)(
801  __in
803  __in
804  WDFKEY Key,
805  __in
807  __out_opt
811  )
812 {
813  DDI_ENTRY();
814 
816  FxRegKey* pKey;
820 
822  Key,
824  (PVOID*) &pKey,
826 
828 
830  if (!NT_SUCCESS(status)) {
831  return status;
832  }
833 
835  if (!NT_SUCCESS(status)) {
836  return status;
837  }
838 
839  if (Value != NULL) {
841  if (!NT_SUCCESS(status)) {
842  return status;
843  }
844  }
845 
846  if (Value == NULL) {
847  //
848  // Caller wants to know just the length
849  //
850  dataLength = 0;
851  dataBuffer = NULL;
852  }
853  else {
854  dataLength = Value->MaximumLength;
855  dataBuffer = FxPoolAllocate(pFxDriverGlobals, PagedPool, dataLength);
856 
857  if (dataBuffer == NULL) {
859 
862  "WDFKEY %p KEY_VALUE_PARTIAL_INFORMATION allocation failed, "
863  "%!STATUS!", Key, status);
864 
865  return status;
866  }
867  }
868 
873  }
874 
875  //
876  // Set ValueByteLength before doing the copy
877  //
879  //
880  // pPartial->DataLength is in bytes, convert to number of
881  // WCHARs
882  //
883  if (ValueByteLength != NULL) {
885  }
886  }
887 
888  if (NT_SUCCESS(status) && Value != NULL) {
889 
890 
891 
892 
895 
896  //
897  // pPartial->DataLength cannot be greater than Value->MaximumLength
898  // based on the call to _ComputePartialSize above. So it is safe to
899  // copy the pPartial data buffer to the Value buffer.
900  //
901  __analysis_assume(dataLength <= Value->MaximumLength);
903 
904  //terminating null shouldn't be included in the Length
905  Value->Length = (USHORT)dataLength;
906 
907  if (Value->Buffer[Value->Length/sizeof(WCHAR)-1] == UNICODE_NULL) {
908  Value->Length -= sizeof(WCHAR);
909  }
910  }
911 
912  if (dataBuffer != NULL) {
914  }
915 
916  return status;
917 }
918 
921 NTSTATUS
922 STDCALL
923 WDFEXPORT(WdfRegistryQueryString)(
924  __in
926  __in
927  WDFKEY Key,
928  __in
930  __in
931  WDFSTRING String
932  )
933 {
934  DDI_ENTRY();
935 
938  FxRegKey* pKey;
942 
944  Key,
946  (PVOID*) &pKey,
948 
951 
953  if (!NT_SUCCESS(status)) {
954  return status;
955  }
956 
958  if (!NT_SUCCESS(status)) {
959  return status;
960  }
961 
963  String,
965  (PVOID*) &pString);
966 
967  status = pKey->QueryValue(ValueName, 0, NULL, &dataLength, &type);
968  if (NT_SUCCESS(status) &&
971  }
972 
975  "WDFKEY %p, QueryPartial failed, %!STATUS!",
976  Key, status);
977  return status;
978  }
979 
980  dataBuffer = FxPoolAllocate(pFxDriverGlobals, PagedPool, dataLength);
981  if (dataBuffer == NULL) {
983 
986  "WDFKEY %p KEY_VALUE_PARTIAL_INFORMATION allocation failed, "
987  "%!STATUS!", Key, status);
988 
989  return status;
990  }
991 
993  if (NT_SUCCESS(status) &&
996  }
997 
998  if (NT_SUCCESS(status)) {
999  if (dataLength <= USHORT_MAX) {
1000  UNICODE_STRING tmp;
1001 
1002  if (dataLength == 0x0) {
1003  //
1004  // Empty string
1005  //
1006  tmp.Buffer = L"";
1007  tmp.Length = 0;
1008  tmp.MaximumLength = 0;
1009  }
1010  else {
1011 
1012  //
1013  // The string we read may not be NULL terminated, so put it into a
1014  // UNICODE_STRING. If the final character is NULL, shorten the
1015  // length of the string so that it does not include for the NULL.
1016  //
1017  // If there are embedded NULLs in the string previous to the final
1018  // character, we leave them in place.
1019  //
1020  tmp.Buffer = (PWCHAR) dataBuffer;
1021  tmp.Length = (USHORT) dataLength;
1022  tmp.MaximumLength = tmp.Length;
1023 
1024  if (tmp.Buffer[(tmp.Length/sizeof(WCHAR))-1] == UNICODE_NULL) {
1025  //
1026  // Do not include the UNICODE_NULL in the length
1027  //
1028  tmp.Length -= sizeof(WCHAR);
1029  }
1030  }
1031 
1032  status = pString->Assign(&tmp);
1033  }
1034  else {
1036 
1039  "WDFKEY %p QueryPartial failed, Length %d > max %d, %!STATUS!",
1041  }
1042  }
1043  else {
1046  "WDFKEY %p QueryPartial failed, Length %d, %!STATUS!",
1047  Key, dataLength, status);
1048  }
1049 
1051 
1052  return status;
1053 }
1054 
1057 NTSTATUS
1058 STDCALL
1059 WDFEXPORT(WdfRegistryQueryULong)(
1060  __in
1062  __in
1063  WDFKEY Key,
1064  __in
1066  __out
1067  PULONG Value
1068  )
1069 {
1070  DDI_ENTRY();
1071 
1073  FxRegKey* pKey;
1074  NTSTATUS status;
1075 
1077  Key,
1079  (PVOID*) &pKey,
1080  &pFxDriverGlobals);
1081 
1084 
1086  if (!NT_SUCCESS(status)) {
1087  return status;
1088  }
1089 
1091  if (!NT_SUCCESS(status)) {
1092  return status;
1093  }
1094 
1095  status = FxRegKey::_QueryULong(pKey->GetHandle(), ValueName, Value);
1096 
1097  if (!NT_SUCCESS(status)) {
1100  "WDFKEY %p, QueryULong, %!STATUS!", Key, status);
1101  }
1102 
1103  return status;
1104 }
1105 
1106 
1109 NTSTATUS
1110 STDCALL
1111 WDFEXPORT(WdfRegistryAssignValue)(
1112  __in
1114  __in
1115  WDFKEY Key,
1116  __in
1118  __in
1119  ULONG ValueType,
1120  __in
1123  PVOID Value
1124  )
1125 {
1126  DDI_ENTRY();
1127 
1129  FxRegKey* pKey;
1130  NTSTATUS status;
1131 
1133  Key,
1135  (PVOID*) &pKey,
1136  &pFxDriverGlobals);
1137 
1139 
1141  if (!NT_SUCCESS(status)) {
1142  return status;
1143  }
1144 
1146  if (!NT_SUCCESS(status)) {
1147  return status;
1148  }
1149 
1150  status = pKey->SetValue(ValueName, ValueType, Value, ValueLength);
1151 
1152  if (!NT_SUCCESS(status)) {
1154  "WDFKEY %p SetValue, %!STATUS!", Key, status);
1155  }
1156 
1157  return status;
1158 }
1159 
1160 
1163 NTSTATUS
1164 STDCALL
1165 WDFEXPORT(WdfRegistryAssignMemory)(
1166  __in
1168  __in
1169  WDFKEY Key,
1170  __in
1172  __in
1173  ULONG ValueType,
1174  __in
1175  WDFMEMORY Memory,
1176  __in_opt
1178  )
1180  DDI_ENTRY();
1181 
1184  FxRegKey* pKey;
1187  NTSTATUS status;
1188 
1190  Key,
1192  (PVOID*) &pKey,
1193  &pFxDriverGlobals);
1194 
1197 
1199  if (!NT_SUCCESS(status)) {
1200  return status;
1201  }
1202 
1204  if (!NT_SUCCESS(status)) {
1205  return status;
1206  }
1207 
1209  Memory,
1211  (PVOID*) &pMemory);
1212 
1213  pBuffer = pMemory->GetBuffer();
1215 
1218 
1219  if (!NT_SUCCESS(status)) {
1222  "WDFKEY %p, WDFMEMORY %p Offsets overflowed, %!STATUS!",
1223  Key, Memory, status);
1224 
1225  return status;
1226  }
1227 
1228  if (MemoryOffsets->BufferLength > 0) {
1229  status = RtlSizeTToULong(MemoryOffsets->BufferLength, &length);
1230 
1231  if (!NT_SUCCESS(status)) {
1234  "WDFKEY %p, WDFMEMORY %p BufferLength in Offsets truncated, "
1235  "%!STATUS!", Key, Memory, status);
1236 
1237  return status;
1238  }
1239  }
1240 
1241  pBuffer = WDF_PTR_ADD_OFFSET(pBuffer, MemoryOffsets->BufferOffset);
1242  }
1243 
1244  status = pKey->SetValue(ValueName, ValueType, pBuffer, length);
1245 
1246  if (!NT_SUCCESS(status)) {
1248  "WDFKEY handle %p SetValue, %!STATUS!", Key, status);
1249  }
1250 
1251  return status;
1252 }
1253 
1256 NTSTATUS
1257 STDCALL
1258 WDFEXPORT(WdfRegistryAssignULong)(
1259  __in
1261  __in
1262  WDFKEY Key,
1263  __in
1265  __in
1266  ULONG Value
1267  )
1268 {
1269  DDI_ENTRY();
1270 
1272  FxRegKey* pKey;
1273  NTSTATUS status;
1274 
1276  Key,
1278  (PVOID*) &pKey,
1279  &pFxDriverGlobals);
1280 
1282 
1284  if (!NT_SUCCESS(status)) {
1285  return status;
1286  }
1287 
1289  if (!NT_SUCCESS(status)) {
1290  return status;
1291  }
1292 
1293  status = pKey->SetValue(ValueName, REG_DWORD, &Value, sizeof(Value));
1294 
1295  if (!NT_SUCCESS(status)) {
1297  "WDFKEY %p SetValue, %!STATUS!",
1298  Key, status);
1299  }
1300 
1301  return status;
1302 }
1303 
1306 NTSTATUS
1307 STDCALL
1308 WDFEXPORT(WdfRegistryAssignUnicodeString)(
1309  __in
1311  __in
1312  WDFKEY Key,
1313  __in
1315  __in
1317  )
1318 {
1319  DDI_ENTRY();
1320 
1322  FxRegKey* pKey;
1323  NTSTATUS status;
1325  ULONG length;
1326 
1328  Key,
1330  (PVOID*) &pKey,
1331  &pFxDriverGlobals);
1332 
1335 
1336  tempValueBuf = NULL;
1337 
1339  if (!NT_SUCCESS(status)) {
1340  return status;
1341  }
1342 
1344  if (!NT_SUCCESS(status)) {
1345  return status;
1346  }
1347 
1349  if (!NT_SUCCESS(status)) {
1350  return status;
1351  }
1352 
1353  length = Value->Length + sizeof(UNICODE_NULL);
1354 
1355  //
1356  // Buffer must be NULL terminated and Length of the buffer must also include the NULL
1357  // Allocate a temporary buffer and NULL terminate it.
1358  //
1359  tempValueBuf = (PWCHAR) FxPoolAllocate(pFxDriverGlobals, PagedPool, length);
1360 
1361  if (tempValueBuf == NULL) {
1363 
1365  "WDFKEY %p allocate temporary buffer failed, "
1366  "%!STATUS!", Key, status);
1367 
1368  return status;
1369  }
1370 
1371  //
1372  // Copy over the string from the callers buffer and make sure it is
1373  // NULL terminated.
1374  //
1375  RtlCopyMemory(tempValueBuf, Value->Buffer, Value->Length);
1376  tempValueBuf[Value->Length/sizeof(WCHAR)] = UNICODE_NULL;
1377 
1378  status = pKey->SetValue(ValueName, REG_SZ, tempValueBuf, length);
1379 
1381 
1382  if (!NT_SUCCESS(status)) {
1384  "WDFKEY %p set value failed, %!STATUS!",
1385  Key, status);
1386  }
1387 
1388  return status;
1389 }
1390 
1393 NTSTATUS
1394 STDCALL
1395 WDFEXPORT(WdfRegistryAssignString)(
1396  __in
1398  __in
1399  WDFKEY Key,
1400  __in
1402  __in
1403  WDFSTRING String
1404  )
1405 {
1406  DDI_ENTRY();
1407 
1409  FxString* pString;
1410  FxRegKey* pKey;
1411  NTSTATUS status;
1412 
1414  Key,
1416  (PVOID*) &pKey,
1417  &pFxDriverGlobals);
1418 
1421 
1423  if (!NT_SUCCESS(status)) {
1424  return status;
1425  }
1426 
1428  if (!NT_SUCCESS(status)) {
1429  return status;
1430  }
1431 
1433  String,
1435  (PVOID*) &pString);
1436 
1437  status = pKey->SetValue(ValueName,
1438  REG_SZ,
1439  pString->Buffer(),
1440  pString->ByteLength(TRUE));
1441 
1442  if (!NT_SUCCESS(status)) {
1444  "WDFKEY handle %p SetValue, %!STATUS!",
1445  Key, status);
1446  }
1447 
1448  return status;
1449 }
1450 
1453 NTSTATUS
1454 STDCALL
1455 WDFEXPORT(WdfRegistryAssignMultiString)(
1456  __in
1458  __in
1459  WDFKEY Key,
1460  __in
1462  __in
1463  WDFCOLLECTION StringsCollection
1464  )
1466  DDI_ENTRY();
1467 
1470  FxRegKey* pKey;
1472  NTSTATUS status;
1473  ULONG length;
1475 
1477  Key,
1479  (PVOID*) &pKey,
1480  &pFxDriverGlobals);
1481 
1484 
1486  if (!NT_SUCCESS(status)) {
1487  return status;
1488  }
1489 
1491  if (!NT_SUCCESS(status)) {
1492  return status;
1493  }
1494 
1498  (PVOID *) &pCollection);
1499 
1500  valid = FALSE;
1501 
1504  &length);
1505 
1506  if (!NT_SUCCESS(status)) {
1508  "WDFCOLLECTION %p, collection too large to fit into "
1509  "a ULONG, %!STATUS!", StringsCollection, status);
1510  return status;
1511  }
1512 
1513  if (valid == FALSE) {
1516  "WDFKEY %p, WDFCOLLECTION %p contains "
1517  "non string objects, %!STATUS!",
1519  return status;
1520  }
1521 
1522  pValue = (PWCHAR) FxPoolAllocate(pFxDriverGlobals, PagedPool, length);
1523 
1524  if (pValue == NULL) {
1526 
1528  "WDFKEY %p allocate for query buffer failed, "
1529  "%!STATUS!", Key, status);
1530 
1531  return status;
1532  }
1533 
1535 
1536  status = pKey->SetValue(ValueName, REG_MULTI_SZ, pValue, length);
1537 
1538  if (!NT_SUCCESS(status)) {
1540  "WDFKEY %p SetValue, %!STATUS!",
1541  Key, status);
1542  }
1543 
1544  FxPoolFree(pValue);
1545 
1546  return status;
1547 }
1548 
1549 } // extern "C"
WDFKEY keyHandle
#define DDI_ENTRY()
Definition: fxglobalskm.h:56
#define RtlSizeTToULong
virtual VOID DeleteObject(VOID)
FxObject * pObject
#define IN
Definition: typedefs.h:39
_Must_inspect_result_ NTSTATUS ValidateMemoryOffsets(__in_opt PWDFMEMORY_OFFSET Offsets)
Definition: ifxmemory.hpp:105
#define USHORT_MAX
Definition: intsafe.h:147
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2654
_Must_inspect_result_ __in WDFKEY __in PCUNICODE_STRING __in WDFCOLLECTION StringsCollection
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ __in_opt WDFKEY __in PCUNICODE_STRING __in ACCESS_MASK __in_opt PWDF_OBJECT_ATTRIBUTES KeyAttributes
FxString * pString
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_opt_ PWDF_OBJECT_ATTRIBUTES StringsAttributes
Definition: wdfregistry.h:367
GLint x0
Definition: linetemp.h:95
_Must_inspect_result_ NTSTATUS Commit(__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out_opt WDFOBJECT *ObjectHandle, __in_opt FxObject *Parent=NULL, __in BOOLEAN AssignDriverAsDefaultParent=TRUE)
Definition: fxobject.cpp:904
_Must_inspect_result_ __in_opt WDFKEY __in PCUNICODE_STRING __in ACCESS_MASK __in_opt PWDF_OBJECT_ATTRIBUTES __out WDFKEY * Key
_Must_inspect_result_ __in_opt WDFKEY __in PCUNICODE_STRING __in ACCESS_MASK DesiredAccess
FxDeviceBase * pDeviceBase
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define WDF_PTR_ADD_OFFSET(_ptr, _offset)
Definition: wdfcore.h:144
#define __in_opt
Definition: dbghelp.h:38
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS status
PWCHAR pValue
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ WDFCOLLECTION Collection
Definition: wdfregistry.h:367
#define __analysis_assume(expr)
Definition: ms_sal.h:2893
__inline HANDLE GetHandle(VOID)
Definition: fxregkey.hpp:103
LONG NTSTATUS
Definition: precomp.h:26
ULONG type
NTSYSAPI NTSTATUS NTAPI ZwDeleteValueKey(__in IN HANDLE Key, __in IN PUNICODE_STRING ValueName)
_Must_inspect_result_ __in WDFKEY __in PCUNICODE_STRING __out_opt PUSHORT ValueByteLength
ULONG dataLength
_Must_inspect_result_ __in_opt WDFKEY __in PCUNICODE_STRING KeyName
VOID SetDeviceBase(__in CfxDeviceBase *DeviceBase)
Definition: fxobject.hpp:797
DriverGlobals
uint16_t * PWCHAR
Definition: typedefs.h:56
#define __inout_opt
Definition: dbghelp.h:53
_Must_inspect_result_ __in WDFKEY __in PCUNICODE_STRING __in ULONG __in WDFMEMORY __in_opt PWDFMEMORY_OFFSET MemoryOffsets
BOOLEAN Add(__in FxObject *Item)
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:279
#define NTSYSAPI
Definition: ntoskrnl.h:14
_Must_inspect_result_ __in_opt WDFKEY __in PCUNICODE_STRING __in ACCESS_MASK __in ULONG __out_opt PULONG CreateDisposition
PVOID dataBuffer
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT ValueByteLength
Definition: wdfregistry.h:406
static FxDeviceBase * _SearchForDevice(__in FxObject *Object, __out_opt IFxHasCallbacks **Callbacks)
_Must_inspect_result_ __in WDFKEY __in PCUNICODE_STRING __in WDFSTRING String
#define __out_opt
Definition: dbghelp.h:65
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2430
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
_Must_inspect_result_ __in_opt WDFKEY ParentKey
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define REG_MULTI_SZ
Definition: nt_native.h:1501
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
_Must_inspect_result_ NTSTATUS __inline FxValidateObjectAttributesForParentHandle(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
#define __out
Definition: dbghelp.h:62
static __inline NTSTATUS MxDeleteKey(_In_ HANDLE KeyHandle)
Definition: mxgeneralkm.h:634
unsigned char BOOLEAN
_Must_inspect_result_ __in WDFKEY __in PCUNICODE_STRING ValueName
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _In_ WDFMEMORY _In_opt_ PWDFMEMORY_OFFSET MemoryOffsets
Definition: wdfregistry.h:558
_Must_inspect_result_ __in_opt WDFKEY __in PCUNICODE_STRING __in ACCESS_MASK __in ULONG CreateOptions
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2697
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK _In_opt_ PWDF_OBJECT_ATTRIBUTES KeyAttributes
Definition: wdfdevice.h:2654
size_t FxCalculateTotalStringSize(__in FxCollectionInternal *StringCollection, __in BOOLEAN Verify=FALSE, __out_opt PBOOLEAN ContainsOnlyStrings=NULL)
Definition: stringutil.cpp:32
_Must_inspect_result_ __in WDFKEY __in PCUNICODE_STRING __in ULONG __out_opt PULONG ValueLengthQueried
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG _In_ _Out_ WDFMEMORY * Memory
Definition: wdfmemory.h:169
#define STATUS_INVALID_BUFFER_SIZE
Definition: ntstatus.h:650
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
_Must_inspect_result_ __in WDFKEY __in PCUNICODE_STRING __in_opt PWDF_OBJECT_ATTRIBUTES StringsAttributes
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: ntstatus.h:273
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG _Out_opt_ PULONG CreateDisposition
Definition: wdfregistry.h:112
FxPointerNotNull(pFxDriverGlobals, KeyName)
_In_ WDFDMATRANSACTION _In_ size_t MaximumLength
_Must_inspect_result_ __in WDFKEY __in PCUNICODE_STRING __in ULONG __out_opt PULONG __out_opt PULONG ValueType
#define STDCALL
Definition: wdf.h:45
#define ASSERT(a)
Definition: mode.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
INT POOL_TYPE
Definition: typedefs.h:78
PVOID pBuffer
FxPoolFree(dataBuffer)
_Must_inspect_result_ NTSTATUS Assign(__in PCWSTR SourceString)
Definition: fxstring.cpp:57
_Must_inspect_result_ __in WDFKEY __in PCUNICODE_STRING __in ULONG ValueLength
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _In_ _Strict_type_match_ POOL_TYPE _In_opt_ PWDF_OBJECT_ATTRIBUTES MemoryAttributes
Definition: wdfmemory.h:407
__inline PWCHAR Buffer(VOID)
Definition: fxstring.hpp:144
PWCHAR tempValueBuf
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
_Must_inspect_result_ NTSTATUS __inline FxValidateUnicodeString(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PCUNICODE_STRING String)
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
BOOLEAN valid
#define _Must_inspect_result_
Definition: ms_sal.h:558
ULONG length
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG CreateOptions
Definition: wdfregistry.h:112
_Must_inspect_result_ __in WDFKEY __in PCUNICODE_STRING __in __drv_strictTypeMatch(1) POOL_TYPE PoolType
_Must_inspect_result_ __in WDFKEY __in PCUNICODE_STRING __in ULONG __out_bcount_opt(ValueLength) PVOID Value
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
PFX_DRIVER_GLOBALS pFxDriverGlobals
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), Key, FX_TYPE_REG_KEY,(PVOID *) &pKey)
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Key, FX_TYPE_REG_KEY,(PVOID *) &pKey, &pFxDriverGlobals)
_Must_inspect_result_ __in WDFKEY __in PCUNICODE_STRING __in ULONG __in ULONG __in_ecount(ValueLength) PVOID Value)
static BOOLEAN __inline _IsValidSzType(__in ULONG RegValueType)
Definition: fxregkey.hpp:230
__inline USHORT ByteLength(__in BOOLEAN IncludeNull)
Definition: fxstring.hpp:94
_Must_inspect_result_ __in WDFKEY __in PCUNICODE_STRING __in_opt PWDF_OBJECT_ATTRIBUTES __in WDFCOLLECTION Collection
_Must_inspect_result_ _In_opt_ WDFKEY ParentKey
Definition: wdfregistry.h:69
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
_Must_inspect_result_ __in WDFKEY __in PCUNICODE_STRING __out_opt PUSHORT __inout_opt PUNICODE_STRING Value
unsigned short USHORT
Definition: pedump.c:61
HANDLE parentHandle
SINGLE_LIST_ENTRY * pCur
unsigned char dummy
Definition: maze.c:118
FxCollection * pCollection
FxVerifierCheckNxPoolType(pFxDriverGlobals, PoolType, pFxDriverGlobals->Tag)
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
RtlCopyMemory(tempValueBuf, Value->Buffer, Value->Length)
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ WDFCOLLECTION StringsCollection
Definition: wdfregistry.h:601
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
NTSTATUS Remove(__in ULONG Index)
UNICODE_STRING * PUNICODE_STRING
Definition: env_spec_w32.h:373
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
_Must_inspect_result_ __drv_maxIRQL(PASSIVE_LEVEL) NTSTATUS STDCALL WDFEXPORT(WdfRegistryOpenKey)(__in PWDF_DRIVER_GLOBALS DriverGlobals
static _Must_inspect_result_ NTSTATUS _VerifyMultiSzString(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PCUNICODE_STRING RegValueName, __in_bcount(DataLength) PWCHAR DataString, __in ULONG DataLength)
Definition: fxregkey.cpp:14
FxRegKey * pKey
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3810
FxCopyMultiSz(pValue, pCollection)
unsigned int ULONG
Definition: retypes.h:1
FxObject * pParent
Definition: fxdpcapi.cpp:86
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
IFxMemory * pMemory
#define TRACINGERROR
Definition: dbgtrace.h:63
#define __in
Definition: dbghelp.h:35
#define REG_DWORD
Definition: sdbapi.c:596
_Must_inspect_result_ __in WDFKEY __in PCUNICODE_STRING __in __in_opt PWDF_OBJECT_ATTRIBUTES __out WDFMEMORY * Memory
virtual size_t GetBufferSize(VOID)=0
unsigned short * PUSHORT
Definition: retypes.h:2
ULONG ACCESS_MASK
Definition: nt_native.h:40
FxVerifierDbgBreakPoint(pFxDriverGlobals)
virtual PVOID GetBuffer(VOID)=0
#define DO_NOTHING()
Definition: mxgeneral.h:32
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS DriverGlobals, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __in POOL_TYPE PoolType, __in ULONG PoolTag, __in size_t BufferSize, __out FxMemoryObject **Object)
#define REG_SZ
Definition: layer.c:22
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG ValueLength
Definition: wdfregistry.h:271
Definition: ps.c:97