Changeset 58361 in vbox for trunk/src/VBox/Additions/WINNT
- Timestamp:
- Oct 21, 2015 3:14:02 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/SharedFolders/driver/vbsf.c
r58196 r58361 634 634 case IRP_MJ_DEVICE_CONTROL: 635 635 { 636 Log(("VBOXSF: MRxDevFcbXXXControlFile: IRP_MJ_DEVICE_CONTROL: InputBuffer %p/%d, OutputBuffer %p/%d\n", 637 LowIoContext->ParamsFor.IoCtl.pInputBuffer, 638 LowIoContext->ParamsFor.IoCtl.InputBufferLength, 639 LowIoContext->ParamsFor.IoCtl.pOutputBuffer, 640 LowIoContext->ParamsFor.IoCtl.OutputBufferLength)); 641 636 642 switch (LowIoContext->ParamsFor.IoCtl.IoControlCode) 637 643 { … … 655 661 uint8_t *pu8Out = (uint8_t *)LowIoContext->ParamsFor.IoCtl.pOutputBuffer; 656 662 663 BOOLEAN fLocked = FALSE; 664 657 665 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETLIST\n")); 658 666 659 if (!pDeviceExtension) 660 { 661 RxContext->InformationToReturn = 0; 667 RxContext->InformationToReturn = 0; 668 669 if ( !pDeviceExtension 670 || cbOut < _MRX_MAX_DRIVE_LETTERS) 671 { 672 Status = STATUS_INVALID_PARAMETER; 662 673 break; 663 674 } 664 675 665 if (cbOut >= _MRX_MAX_DRIVE_LETTERS && pu8Out) 666 { 667 BOOLEAN fLocked = FALSE; 668 669 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETLIST: Copying local connections\n")); 670 671 fLocked = ExTryToAcquireFastMutex(&pDeviceExtension->mtxLocalCon); 672 676 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETLIST: Copying local connections\n")); 677 678 fLocked = ExTryToAcquireFastMutex(&pDeviceExtension->mtxLocalCon); 679 680 __try 681 { 673 682 RtlCopyMemory(pu8Out, pDeviceExtension->cLocalConnections, _MRX_MAX_DRIVE_LETTERS); 674 675 if (fLocked)676 {677 ExReleaseFastMutex(&pDeviceExtension->mtxLocalCon);678 }679 680 683 RxContext->InformationToReturn = _MRX_MAX_DRIVE_LETTERS; 681 684 } 682 else 683 { 684 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETLIST: cbOut is too small %d bytes\n", 685 cbOut)); 686 RxContext->InformationToReturn = 0; 687 } 688 689 Status = STATUS_SUCCESS; 685 __except(EXCEPTION_EXECUTE_HANDLER) 686 { 687 Status = STATUS_INVALID_PARAMETER; 688 } 689 690 if (fLocked) 691 { 692 ExReleaseFastMutex(&pDeviceExtension->mtxLocalCon); 693 fLocked = FALSE; 694 } 695 690 696 break; 691 697 } … … 699 705 uint8_t *pu8Out = (uint8_t *)LowIoContext->ParamsFor.IoCtl.pOutputBuffer; 700 706 707 int vboxRC; 708 SHFLMAPPING mappings[_MRX_MAX_DRIVE_LETTERS]; 709 uint32_t cMappings = RT_ELEMENTS(mappings); 710 701 711 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETGLOBALLIST\n")); 702 712 703 713 RxContext->InformationToReturn = 0; 704 714 705 if (!pDeviceExtension) 715 if ( !pDeviceExtension 716 || cbOut < _MRX_MAX_DRIVE_LETTERS) 717 { 718 Status = STATUS_INVALID_PARAMETER; 706 719 break; 707 708 if (cbOut >= _MRX_MAX_DRIVE_LETTERS && pu8Out) 709 { 710 SHFLMAPPING mappings[_MRX_MAX_DRIVE_LETTERS]; 711 uint32_t cMappings = RT_ELEMENTS(mappings); 712 713 int vboxRC = VbglR0SfQueryMappings(&pDeviceExtension->hgcmClient, mappings, &cMappings); 714 715 if (vboxRC == VINF_SUCCESS) 720 } 721 722 vboxRC = VbglR0SfQueryMappings(&pDeviceExtension->hgcmClient, mappings, &cMappings); 723 if (vboxRC == VINF_SUCCESS) 724 { 725 __try 716 726 { 717 727 uint32_t i; … … 727 737 RxContext->InformationToReturn = _MRX_MAX_DRIVE_LETTERS; 728 738 } 729 else739 __except(EXCEPTION_EXECUTE_HANDLER) 730 740 { 731 Status = VBoxErrorToNTStatus(vboxRC); 732 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETGLOBALLIST failed: 0x%08X\n", 733 Status)); 741 Status = STATUS_INVALID_PARAMETER; 734 742 } 735 743 } 736 737 Status = STATUS_SUCCESS; 744 else 745 { 746 Status = VBoxErrorToNTStatus(vboxRC); 747 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETGLOBALLIST failed: 0x%08X\n", 748 Status)); 749 } 750 738 751 break; 739 752 } … … 747 760 ULONG cbConnectName = LowIoContext->ParamsFor.IoCtl.InputBufferLength; 748 761 PWCHAR pwcConnectName = (PWCHAR)LowIoContext->ParamsFor.IoCtl.pInputBuffer; 749 750 762 ULONG cbRemoteName = LowIoContext->ParamsFor.IoCtl.OutputBufferLength; 751 763 PWCHAR pwcRemoteName = (PWCHAR)LowIoContext->ParamsFor.IoCtl.pOutputBuffer; 752 764 753 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: ConnectName = %.*ls, Len = %d, RemoteName = 0x%p, Len = %d\n", 754 cbConnectName / sizeof(WCHAR), pwcConnectName, cbConnectName, pwcRemoteName, cbRemoteName)); 755 756 if (!pDeviceExtension) 765 BOOLEAN fMutexAcquired = FALSE; 766 767 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN\n")); 768 769 RxContext->InformationToReturn = 0; 770 771 if ( !pDeviceExtension 772 || cbConnectName < sizeof(WCHAR)) 757 773 { 758 774 Status = STATUS_INVALID_PARAMETER; … … 762 778 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: Looking up connection name and connections\n")); 763 779 764 if (cbConnectName > sizeof(WCHAR) && pwcConnectName) 765 { 766 ULONG cbLocalConnectionName; 767 780 __try 781 { 768 782 uint32_t idx = *pwcConnectName - L'A'; 769 783 770 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: Index = %d\n", idx)); 771 772 if (idx >= RTL_NUMBER_OF(pDeviceExtension->wszLocalConnectionName)) 784 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: ConnectName = %.*ls, Len = %d, Index = %d\n", 785 cbConnectName / sizeof(WCHAR), pwcConnectName, cbConnectName, idx)); 786 787 if (idx < RTL_NUMBER_OF(pDeviceExtension->wszLocalConnectionName)) 788 { 789 ExAcquireFastMutex(&pDeviceExtension->mtxLocalCon); 790 fMutexAcquired = TRUE; 791 792 if (pDeviceExtension->wszLocalConnectionName[idx]) 793 { 794 ULONG cbLocalConnectionName = pDeviceExtension->wszLocalConnectionName[idx]->Length; 795 796 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: LocalConnectionName = %.*ls\n", 797 cbLocalConnectionName / sizeof(WCHAR), pDeviceExtension->wszLocalConnectionName[idx]->Buffer)); 798 799 if ((pDeviceExtension->cLocalConnections[idx]) && (cbLocalConnectionName <= cbRemoteName)) 800 { 801 RtlZeroMemory(pwcRemoteName, cbRemoteName); 802 RtlCopyMemory(pwcRemoteName, 803 pDeviceExtension->wszLocalConnectionName[idx]->Buffer, 804 cbLocalConnectionName); 805 806 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: Remote name = %.*ls, Len = %d\n", 807 cbLocalConnectionName / sizeof(WCHAR), pwcRemoteName, cbLocalConnectionName)); 808 } 809 else 810 { 811 Status = STATUS_BUFFER_TOO_SMALL; 812 } 813 814 RxContext->InformationToReturn = cbLocalConnectionName; 815 } 816 else 817 { 818 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: LocalConnectionName is NULL!\n")); 819 Status = STATUS_BAD_NETWORK_NAME; 820 } 821 } 822 else 773 823 { 774 824 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: Index is invalid!\n")); 775 825 Status = STATUS_INVALID_PARAMETER; 776 break;777 826 } 778 779 ExAcquireFastMutex(&pDeviceExtension->mtxLocalCon); 780 781 if (!pDeviceExtension->wszLocalConnectionName[idx]) 782 { 783 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: LocalConnectionName is NULL!\n")); 784 ExReleaseFastMutex(&pDeviceExtension->mtxLocalCon); 785 Status = STATUS_BAD_NETWORK_NAME; 786 break; 787 } 788 789 cbLocalConnectionName = pDeviceExtension->wszLocalConnectionName[idx]->Length; 790 791 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: LocalConnectionName = %.*ls\n", 792 cbLocalConnectionName / sizeof(WCHAR), pDeviceExtension->wszLocalConnectionName[idx]->Buffer)); 793 794 if ((pDeviceExtension->cLocalConnections[idx]) && (cbLocalConnectionName <= cbRemoteName)) 795 { 796 RtlZeroMemory(pwcRemoteName, cbRemoteName); 797 RtlCopyMemory(pwcRemoteName, pDeviceExtension->wszLocalConnectionName[idx]->Buffer, cbLocalConnectionName); 798 799 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: Remote name = %.*ls, Len = %d\n", 800 cbLocalConnectionName / sizeof(WCHAR), pwcRemoteName, cbLocalConnectionName)); 801 802 RxContext->InformationToReturn = cbLocalConnectionName; 803 } 804 else 805 { 806 Status = STATUS_BUFFER_TOO_SMALL; 807 RxContext->InformationToReturn = cbLocalConnectionName; 808 } 809 827 } 828 __except(EXCEPTION_EXECUTE_HANDLER) 829 { 830 Status = STATUS_INVALID_PARAMETER; 831 } 832 833 if (fMutexAcquired) 834 { 810 835 ExReleaseFastMutex(&pDeviceExtension->mtxLocalCon); 811 } 812 else 813 { 814 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: bad connect name!n")); 815 Status = STATUS_BAD_NETWORK_NAME; 836 fMutexAcquired = FALSE; 816 837 } 817 838 … … 821 842 case IOCTL_MRX_VBOX_GETGLOBALCONN: 822 843 { 823 ULONG ReturnedSize = 0; 824 825 uint8_t *pConnectId = (uint8_t *)LowIoContext->ParamsFor.IoCtl.pInputBuffer; 844 ULONG cbConnectId = LowIoContext->ParamsFor.IoCtl.InputBufferLength; 845 uint8_t *pu8ConnectId = (uint8_t *)LowIoContext->ParamsFor.IoCtl.pInputBuffer; 826 846 ULONG cbRemoteName = LowIoContext->ParamsFor.IoCtl.OutputBufferLength; 827 847 PWCHAR pwcRemoteName = (PWCHAR)LowIoContext->ParamsFor.IoCtl.pOutputBuffer; … … 830 850 PSHFLSTRING pString; 831 851 832 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETGLOBALCONN: Connection ID = %d, RemoteName = 0x%x, Len = %d\n", 833 *pConnectId, pwcRemoteName, cbRemoteName)); 852 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETGLOBALCONN\n")); 853 854 RxContext->InformationToReturn = 0; 855 856 if ( !pDeviceExtension 857 || cbConnectId < sizeof(uint8_t)) 858 { 859 Status = STATUS_INVALID_PARAMETER; 860 break; 861 } 834 862 835 863 /* Allocate empty string where the host can store cbRemoteName bytes. */ … … 838 866 break; 839 867 840 vboxRC = VbglR0SfQueryMapName(&pDeviceExtension->hgcmClient, 841 (*pConnectId) & ~0x80 /** @todo fix properly */, 842 pString, ShflStringSizeOfBuffer(pString)); 843 if ( vboxRC == VINF_SUCCESS 844 && pString->u16Length < cbRemoteName) 845 { 846 ReturnedSize = pString->u16Length; 847 RtlCopyMemory(pwcRemoteName, pString->String.ucs2, pString->u16Length); 848 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETGLOBALCONN: Returned name = %.*ls, Len = %d\n", 849 ReturnedSize / sizeof(WCHAR), pwcRemoteName, ReturnedSize)); 850 Status = STATUS_SUCCESS; 851 } 852 else 853 Status = STATUS_BAD_NETWORK_NAME; 868 __try 869 { 870 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETGLOBALCONN: Connection ID = %d\n", 871 *pu8ConnectId)); 872 873 vboxRC = VbglR0SfQueryMapName(&pDeviceExtension->hgcmClient, 874 (*pu8ConnectId) & ~0x80 /** @todo fix properly */, 875 pString, ShflStringSizeOfBuffer(pString)); 876 if ( vboxRC == VINF_SUCCESS 877 && pString->u16Length < cbRemoteName) 878 { 879 RtlCopyMemory(pwcRemoteName, pString->String.ucs2, pString->u16Length); 880 Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETGLOBALCONN: Returned name = %.*ls, Len = %d\n", 881 pString->u16Length / sizeof(WCHAR), pwcRemoteName, pString->u16Length)); 882 RxContext->InformationToReturn = pString->u16Length; 883 } 884 else 885 { 886 Status = STATUS_BAD_NETWORK_NAME; 887 } 888 } 889 __except(EXCEPTION_EXECUTE_HANDLER) 890 { 891 Status = STATUS_INVALID_PARAMETER; 892 } 854 893 855 894 vbsfFreeNonPagedMem(pString); 856 895 857 RxContext->InformationToReturn = ReturnedSize;858 896 break; 859 897 } … … 1139 1177 UNICODE_STRING FileName; 1140 1178 1179 BOOLEAN fMutexAcquired = FALSE; 1180 1141 1181 Log(("VBOXSF: vbsfCreateConnection\n")); 1142 1182 … … 1149 1189 1150 1190 pDeviceExtension = VBoxMRxGetDeviceExtension(RxContext); 1191 if (!pDeviceExtension) 1192 return STATUS_INVALID_PARAMETER; 1151 1193 1152 1194 LowIoContext = &RxContext->LowIoContext; … … 1154 1196 pwcConnectName = (PWCHAR)LowIoContext->ParamsFor.IoCtl.pInputBuffer; 1155 1197 1156 if (!pDeviceExtension)1157 return STATUS_INVALID_PARAMETER;1158 1159 1198 if (cbConnectName == 0 || !pwcConnectName) 1160 1199 { … … 1163 1202 } 1164 1203 1165 Log(("VBOXSF: vbsfCreateConnection: Name = %.*ls, Len = %d\n", 1166 cbConnectName / sizeof(WCHAR), pwcConnectName, cbConnectName)); 1167 1168 FileName.Buffer = pwcConnectName; 1169 FileName.Length = (USHORT)cbConnectName; 1170 FileName.MaximumLength = (USHORT)cbConnectName; 1171 1172 Handle = vbsfOpenConnectionHandle(&FileName); 1173 1174 if (Handle != INVALID_HANDLE_VALUE) 1175 { 1176 PWCHAR pwc; 1177 ULONG i; 1178 1179 ZwClose(Handle); 1180 1181 /* Skip the "\Device\VBoxMiniRdr\;X:" of the string "\Device\VBoxMiniRdr\;X:\vboxsrv\sf" */ 1182 pwc = pwcConnectName; 1183 for (i = 0; i < cbConnectName; i += sizeof(WCHAR)) 1204 __try 1205 { 1206 Log(("VBOXSF: vbsfCreateConnection: Name = %.*ls, Len = %d\n", 1207 cbConnectName / sizeof(WCHAR), pwcConnectName, cbConnectName)); 1208 1209 FileName.Buffer = pwcConnectName; 1210 FileName.Length = (USHORT)cbConnectName; 1211 FileName.MaximumLength = (USHORT)cbConnectName; 1212 1213 Handle = vbsfOpenConnectionHandle(&FileName); 1214 1215 if (Handle != INVALID_HANDLE_VALUE) 1184 1216 { 1185 if (*pwc == L':') 1186 break; 1187 pwc++; 1188 } 1189 1190 if (i >= sizeof(WCHAR) && i < cbConnectName) 1191 { 1192 pwc--; /* Go back to the drive letter, "X" for example. */ 1193 1194 if (*pwc >= L'A' && *pwc <= L'Z') /* Are we in range? */ 1217 PWCHAR pwc; 1218 ULONG i; 1219 1220 ZwClose(Handle); 1221 1222 /* Skip the "\Device\VBoxMiniRdr\;X:" of the string "\Device\VBoxMiniRdr\;X:\vboxsrv\sf" */ 1223 pwc = pwcConnectName; 1224 for (i = 0; i < cbConnectName; i += sizeof(WCHAR)) 1195 1225 { 1196 uint32_t idx = *pwc - L'A'; /* Get the index based on the driver letter numbers (26). */ 1197 1198 if (idx >= RTL_NUMBER_OF(pDeviceExtension->cLocalConnections)) 1226 if (*pwc == L':') 1227 break; 1228 pwc++; 1229 } 1230 1231 if (i >= sizeof(WCHAR) && i < cbConnectName) 1232 { 1233 pwc--; /* Go back to the drive letter, "X" for example. */ 1234 1235 if (*pwc >= L'A' && *pwc <= L'Z') /* Are we in range? */ 1199 1236 { 1200 Log(("VBOXSF: vbsfCreateConnection: Index 0x%x is invalid!\n", 1201 idx)); 1202 Status = STATUS_BAD_NETWORK_NAME; 1237 uint32_t idx = *pwc - L'A'; /* Get the index based on the driver letter numbers (26). */ 1238 1239 if (idx >= RTL_NUMBER_OF(pDeviceExtension->cLocalConnections)) 1240 { 1241 Log(("VBOXSF: vbsfCreateConnection: Index 0x%x is invalid!\n", 1242 idx)); 1243 Status = STATUS_BAD_NETWORK_NAME; 1244 } 1245 else 1246 { 1247 ExAcquireFastMutex(&pDeviceExtension->mtxLocalCon); 1248 fMutexAcquired = TRUE; 1249 1250 if (pDeviceExtension->wszLocalConnectionName[idx] != NULL) 1251 { 1252 Log(("VBOXSF: vbsfCreateConnection: LocalConnectionName at index %d is NOT empty!\n", 1253 idx)); 1254 } 1255 1256 pDeviceExtension->wszLocalConnectionName[idx] = (PUNICODE_STRING)vbsfAllocNonPagedMem(sizeof(UNICODE_STRING) + cbConnectName); 1257 1258 if (!pDeviceExtension->wszLocalConnectionName[idx]) 1259 { 1260 Log(("VBOXSF: vbsfCreateConnection: LocalConnectionName at index %d NOT allocated!\n", 1261 idx)); 1262 Status = STATUS_INSUFFICIENT_RESOURCES; 1263 } 1264 else 1265 { 1266 PUNICODE_STRING pRemoteName = pDeviceExtension->wszLocalConnectionName[idx]; 1267 1268 pRemoteName->Buffer = (PWSTR)(pRemoteName + 1); 1269 pRemoteName->Length = (USHORT)(cbConnectName - i - sizeof(WCHAR)); 1270 pRemoteName->MaximumLength = pRemoteName->Length; 1271 RtlCopyMemory(&pRemoteName->Buffer[0], pwc+2, pRemoteName->Length); 1272 1273 Log(("VBOXSF: vbsfCreateConnection: RemoteName %.*ls, Len = %d\n", 1274 pRemoteName->Length / sizeof(WCHAR), pRemoteName->Buffer, pRemoteName->Length)); 1275 1276 pDeviceExtension->cLocalConnections[idx] = TRUE; 1277 } 1278 1279 ExReleaseFastMutex(&pDeviceExtension->mtxLocalCon); 1280 fMutexAcquired = FALSE; 1281 } 1203 1282 } 1204 else 1205 { 1206 ExAcquireFastMutex(&pDeviceExtension->mtxLocalCon); 1207 1208 if (pDeviceExtension->wszLocalConnectionName[idx] != NULL) 1209 { 1210 Log(("VBOXSF: vbsfCreateConnection: LocalConnectionName at index %d is NOT empty!\n", 1211 idx)); 1212 } 1213 1214 pDeviceExtension->wszLocalConnectionName[idx] = (PUNICODE_STRING)vbsfAllocNonPagedMem(sizeof(UNICODE_STRING) + cbConnectName); 1215 1216 if (!pDeviceExtension->wszLocalConnectionName[idx]) 1217 { 1218 Log(("VBOXSF: vbsfCreateConnection: LocalConnectionName at index %d NOT allocated!\n", 1219 idx)); 1220 Status = STATUS_INSUFFICIENT_RESOURCES; 1221 } 1222 else 1223 { 1224 PUNICODE_STRING pRemoteName = pDeviceExtension->wszLocalConnectionName[idx]; 1225 1226 pRemoteName->Buffer = (PWSTR)(pRemoteName + 1); 1227 pRemoteName->Length = (USHORT)(cbConnectName - i - sizeof(WCHAR)); 1228 pRemoteName->MaximumLength = pRemoteName->Length; 1229 RtlCopyMemory(&pRemoteName->Buffer[0], pwc+2, pRemoteName->Length); 1230 1231 Log(("VBOXSF: vbsfCreateConnection: RemoteName %.*ls, Len = %d\n", 1232 pRemoteName->Length / sizeof(WCHAR), pRemoteName->Buffer, pRemoteName->Length)); 1233 1234 pDeviceExtension->cLocalConnections[idx] = TRUE; 1235 } 1236 1237 ExReleaseFastMutex(&pDeviceExtension->mtxLocalCon); 1238 } 1283 } 1284 else 1285 { 1286 Log(("VBOXSF: vbsfCreateConnection: bad format\n")); 1287 Status = STATUS_BAD_NETWORK_NAME; 1239 1288 } 1240 1289 } 1241 1290 else 1242 1291 { 1243 Log(("VBOXSF: vbsfCreateConnection: bad format\n"));1292 Log(("VBOXSF: vbsfCreateConnection: connection was not found\n")); 1244 1293 Status = STATUS_BAD_NETWORK_NAME; 1245 1294 } 1246 1295 } 1247 else 1248 { 1249 Log(("VBOXSF: vbsfCreateConnection: connection was not found\n")); 1250 Status = STATUS_BAD_NETWORK_NAME; 1296 __except(EXCEPTION_EXECUTE_HANDLER) 1297 { 1298 Status = STATUS_INVALID_PARAMETER; 1299 } 1300 1301 if (fMutexAcquired) 1302 { 1303 ExReleaseFastMutex(&pDeviceExtension->mtxLocalCon); 1304 fMutexAcquired = FALSE; 1251 1305 } 1252 1306 … … 1264 1318 PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension; 1265 1319 1320 BOOLEAN fMutexAcquired = FALSE; 1321 1322 Log(("VBOXSF: vbsfDeleteConnection\n")); 1323 1266 1324 if (!BooleanFlagOn(RxContext->Flags, RX_CONTEXT_FLAG_WAIT)) 1267 1325 { … … 1276 1334 1277 1335 pDeviceExtension = VBoxMRxGetDeviceExtension(RxContext); 1278 1279 Log(("VBOXSF: vbsfDeleteConnection: pwcConnectName = %.*ls\n", 1280 cbConnectName / sizeof(WCHAR), pwcConnectName)); 1281 1282 FileName.Buffer = pwcConnectName; 1283 FileName.Length = (USHORT)cbConnectName; 1284 FileName.MaximumLength = (USHORT)cbConnectName; 1285 1286 Handle = vbsfOpenConnectionHandle(&FileName); 1287 1288 if (Handle != INVALID_HANDLE_VALUE) 1289 { 1290 PFILE_OBJECT pFileObject; 1291 Status = ObReferenceObjectByHandle(Handle, 0L, NULL, KernelMode, (PVOID *)&pFileObject, NULL); 1292 1293 Log(("VBOXSF: vbsfDeleteConnection: ObReferenceObjectByHandle Status 0x%08X\n", 1294 Status)); 1336 if (!pDeviceExtension) 1337 return STATUS_INVALID_PARAMETER; 1338 1339 __try 1340 { 1341 Log(("VBOXSF: vbsfDeleteConnection: pwcConnectName = %.*ls\n", 1342 cbConnectName / sizeof(WCHAR), pwcConnectName)); 1343 1344 FileName.Buffer = pwcConnectName; 1345 FileName.Length = (USHORT)cbConnectName; 1346 FileName.MaximumLength = (USHORT)cbConnectName; 1347 1348 Handle = vbsfOpenConnectionHandle(&FileName); 1349 1350 if (Handle != INVALID_HANDLE_VALUE) 1351 { 1352 PFILE_OBJECT pFileObject; 1353 Status = ObReferenceObjectByHandle(Handle, 0L, NULL, KernelMode, (PVOID *)&pFileObject, NULL); 1354 1355 Log(("VBOXSF: vbsfDeleteConnection: ObReferenceObjectByHandle Status 0x%08X\n", 1356 Status)); 1357 1358 if (NT_SUCCESS(Status)) 1359 { 1360 PFOBX Fobx = (PFOBX)pFileObject->FsContext2; 1361 Log(("VBOXSF: vbsfDeleteConnection: Fobx %p\n", Fobx)); 1362 1363 if (Fobx && NodeType(Fobx) == RDBSS_NTC_V_NETROOT) 1364 { 1365 PV_NET_ROOT VNetRoot = (PV_NET_ROOT)Fobx; 1366 1367 Status = RxFinalizeConnection(VNetRoot->NetRoot, VNetRoot, TRUE); 1368 } 1369 else 1370 { 1371 Log(("VBOXSF: vbsfDeleteConnection: wrong FsContext2\n")); 1372 Status = STATUS_INVALID_DEVICE_REQUEST; 1373 } 1374 1375 ObDereferenceObject(pFileObject); 1376 } 1377 1378 ZwClose(Handle); 1379 } 1295 1380 1296 1381 if (NT_SUCCESS(Status)) 1297 1382 { 1298 PFOBX Fobx = (PFOBX)pFileObject->FsContext2; 1299 Log(("VBOXSF: vbsfDeleteConnection: Fobx %p\n", Fobx)); 1300 1301 if (Fobx && NodeType(Fobx) == RDBSS_NTC_V_NETROOT) 1383 PWCHAR pwc; 1384 ULONG i; 1385 1386 /* Skip the "\Device\VBoxMiniRdr\;X:" of the string "\Device\VBoxMiniRdr\;X:\vboxsrv\sf" */ 1387 pwc = pwcConnectName; 1388 for (i = 0; i < cbConnectName; i += sizeof(WCHAR)) 1302 1389 { 1303 PV_NET_ROOT VNetRoot = (PV_NET_ROOT)Fobx; 1304 1305 Status = RxFinalizeConnection(VNetRoot->NetRoot, VNetRoot, TRUE); 1390 if (*pwc == L':') 1391 { 1392 break; 1393 } 1394 pwc++; 1395 } 1396 1397 if (i >= sizeof(WCHAR) && i < cbConnectName) 1398 { 1399 pwc--; 1400 1401 if (*pwc >= L'A' && *pwc <= L'Z') 1402 { 1403 uint32_t idx = *pwc - L'A'; 1404 1405 if (idx >= RTL_NUMBER_OF(pDeviceExtension->cLocalConnections)) 1406 { 1407 Log(("VBOXSF: vbsfDeleteConnection: Index 0x%x is invalid!\n", 1408 idx)); 1409 Status = STATUS_BAD_NETWORK_NAME; 1410 } 1411 else 1412 { 1413 ExAcquireFastMutex(&pDeviceExtension->mtxLocalCon); 1414 fMutexAcquired = TRUE; 1415 1416 pDeviceExtension->cLocalConnections[idx] = FALSE; 1417 1418 /* Free saved name */ 1419 if (pDeviceExtension->wszLocalConnectionName[idx]) 1420 { 1421 vbsfFreeNonPagedMem(pDeviceExtension->wszLocalConnectionName[idx]); 1422 pDeviceExtension->wszLocalConnectionName[idx] = NULL; 1423 } 1424 1425 ExReleaseFastMutex(&pDeviceExtension->mtxLocalCon); 1426 fMutexAcquired = FALSE; 1427 1428 Log(("VBOXSF: vbsfDeleteConnection: deleted index 0x%x\n", 1429 idx)); 1430 } 1431 } 1306 1432 } 1307 1433 else 1308 1434 { 1309 Log(("VBOXSF: vbsfDeleteConnection: wrong FsContext2\n")); 1310 Status = STATUS_INVALID_DEVICE_REQUEST; 1311 } 1312 1313 ObDereferenceObject(pFileObject); 1314 } 1315 1316 ZwClose(Handle); 1317 } 1318 1319 if (NT_SUCCESS(Status)) 1320 { 1321 PWCHAR pwc; 1322 ULONG i; 1323 1324 /* Skip the "\Device\VBoxMiniRdr\;X:" of the string "\Device\VBoxMiniRdr\;X:\vboxsrv\sf" */ 1325 pwc = pwcConnectName; 1326 for (i = 0; i < cbConnectName; i += sizeof(WCHAR)) 1327 { 1328 if (*pwc == L':') 1329 { 1330 break; 1331 } 1332 pwc++; 1333 } 1334 1335 if (i >= sizeof(WCHAR) && i < cbConnectName) 1336 { 1337 pwc--; 1338 1339 if (*pwc >= L'A' && *pwc <= L'Z') 1340 { 1341 uint32_t idx = *pwc - L'A'; 1342 1343 if (idx >= RTL_NUMBER_OF(pDeviceExtension->cLocalConnections)) 1344 { 1345 Log(("VBOXSF: vbsfDeleteConnection: Index 0x%x is invalid!\n", 1346 idx)); 1347 Status = STATUS_BAD_NETWORK_NAME; 1348 } 1349 else 1350 { 1351 ExAcquireFastMutex(&pDeviceExtension->mtxLocalCon); 1352 1353 pDeviceExtension->cLocalConnections[idx] = FALSE; 1354 1355 /* Free saved name */ 1356 if (pDeviceExtension->wszLocalConnectionName[idx]) 1357 { 1358 vbsfFreeNonPagedMem(pDeviceExtension->wszLocalConnectionName[idx]); 1359 pDeviceExtension->wszLocalConnectionName[idx] = NULL; 1360 } 1361 1362 ExReleaseFastMutex(&pDeviceExtension->mtxLocalCon); 1363 1364 Log(("VBOXSF: vbsfDeleteConnection: deleted index 0x%x\n", 1365 idx)); 1366 } 1435 Log(("VBOXSF: vbsfCreateConnection: bad format\n")); 1436 Status = STATUS_BAD_NETWORK_NAME; 1367 1437 } 1368 1438 } 1369 else 1370 { 1371 Log(("VBOXSF: vbsfCreateConnection: bad format\n")); 1372 Status = STATUS_BAD_NETWORK_NAME; 1373 } 1439 } 1440 __except(EXCEPTION_EXECUTE_HANDLER) 1441 { 1442 Status = STATUS_INVALID_PARAMETER; 1443 } 1444 1445 if (fMutexAcquired) 1446 { 1447 ExReleaseFastMutex(&pDeviceExtension->mtxLocalCon); 1448 fMutexAcquired = FALSE; 1374 1449 } 1375 1450
Note:
See TracChangeset
for help on using the changeset viewer.