Changeset 10530 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Jul 11, 2008 2:46:47 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 33215
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/SrvIntNetR0.cpp
r10524 r10530 83 83 void *pvObj; 84 84 } INTNETIF; 85 /** Pointer to an internal network interface. */ 85 86 typedef INTNETIF *PINTNETIF; 86 87 … … 103 104 /** The SUPR0 object id. */ 104 105 void *pvObj; 105 /** Access restricted?*/106 bool fRestrictAccess;106 /** Network creation flags (INTNET_OPEN_FLAGS_*). */ 107 uint32_t fFlags; 107 108 /** The length of the network name. */ 108 109 uint8_t cchName; 109 110 /** The network name. */ 110 111 char szName[INTNET_MAX_NETWORK_NAME]; 112 /** The trunk type. */ 113 INTNETTRUNKTYPE enmTrunkType; 114 /** The trunk name. */ 115 char szTrunk[INTNET_MAX_TRUNK_NAME]; 111 116 } INTNETNETWORK; 117 /** Pointer to an internal network. */ 112 118 typedef INTNETNETWORK *PINTNETNETWORK; 113 119 … … 1272 1278 * 1273 1279 * @returns VBox status code. 1274 * @param pIntNet The instance data. 1275 * @param pSession The current session. 1276 * @param pszNetwork The network name. This has a valid length. 1277 * @param ppNetwork Where to store the pointer to the network on success. 1278 */ 1279 static int intnetOpenNetwork(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, PINTNETNETWORK *ppNetwork) 1280 { 1281 LogFlow(("intnetOpenNetwork: pIntNet=%p pSession=%p pszNetwork=%p:{%s} ppNetwork=%p\n", 1282 pIntNet, pSession, pszNetwork, pszNetwork, ppNetwork)); 1283 1280 * @param pIntNet The instance data. 1281 * @param pSession The current session. 1282 * @param pszNetwork The network name. This has a valid length. 1283 * @param enmTrunkType The trunk type. 1284 * @param pszTrunk The trunk name. Its meaning is specfic to the type. 1285 * @param fFlags Flags, see INTNET_OPEN_FLAGS_*. 1286 * @param ppNetwork Where to store the pointer to the network on success. 1287 */ 1288 static int intnetOpenNetwork(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, INTNETTRUNKTYPE enmTrunkType, 1289 const char *pszTrunk, uint32_t fFlags, PINTNETNETWORK *ppNetwork) 1290 { 1291 LogFlow(("intnetOpenNetwork: pIntNet=%p pSession=%p pszNetwork=%p:{%s} enmTrunkType=%d pszTrunk=%p:{%s} fFlags=%#x ppNetwork=%p\n", 1292 pIntNet, pSession, pszNetwork, pszNetwork, enmTrunkType, pszTrunk, pszTrunk, fFlags, ppNetwork)); 1293 1294 /* just pro forma validation, the caller is internal. */ 1284 1295 AssertPtr(pIntNet); 1285 1296 AssertPtr(pSession); 1286 1297 AssertPtr(pszNetwork); 1298 Assert(enmTrunkType > kIntNetTrunkType_Invalid && enmTrunkType < kIntNetTrunkType_End); 1299 AssertPtr(pszTrunk); 1300 Assert(!(fFlags & ~(INTNET_OPEN_FLAGS_PUBLIC))); 1287 1301 AssertPtr(ppNetwork); 1288 1302 *ppNetwork = NULL; … … 1304 1318 { 1305 1319 /* 1306 * Increment the reference and check that the1307 * session can access this network.1320 * Found the network, now check that we have the same ideas 1321 * about the trunk setup and security. 1308 1322 */ 1309 int rc = SUPR0ObjAddRef(pCur->pvObj, pSession);1310 RTSpinlockRelease(pIntNet->Spinlock, &Tmp);1311 1312 if (VBOX_SUCCESS(rc))1323 int rc; 1324 if ( enmTrunkType == kIntNetTrunkType_WhateverNone 1325 || ( pCur->enmTrunkType == enmTrunkType 1326 && !strcmp(pCur->szTrunk, pszTrunk))) 1313 1327 { 1314 if (pCur->fRestrictAccess) 1315 rc = SUPR0ObjVerifyAccess(pCur->pvObj, pSession, pCur->szName); 1316 if (VBOX_SUCCESS(rc)) 1317 *ppNetwork = pCur; 1328 if (!((pCur->fFlags ^ fFlags) & (INTNET_OPEN_FLAGS_PUBLIC))) 1329 { 1330 /* 1331 * Increment the reference and check that the 1332 * session can access this network. 1333 */ 1334 rc = SUPR0ObjAddRef(pCur->pvObj, pSession); 1335 RTSpinlockRelease(pIntNet->Spinlock, &Tmp); 1336 1337 if (VBOX_SUCCESS(rc)) 1338 { 1339 if (!(pCur->fFlags & INTNET_OPEN_FLAGS_PUBLIC)) 1340 rc = SUPR0ObjVerifyAccess(pCur->pvObj, pSession, pCur->szName); 1341 if (VBOX_SUCCESS(rc)) 1342 *ppNetwork = pCur; 1343 else 1344 { 1345 RTSpinlockAcquire(pIntNet->Spinlock, &Tmp); 1346 SUPR0ObjRelease(pCur->pvObj, pSession); 1347 RTSpinlockRelease(pIntNet->Spinlock, &Tmp); 1348 } 1349 } 1350 } 1318 1351 else 1319 { 1320 RTSpinlockAcquire(pIntNet->Spinlock, &Tmp); 1321 SUPR0ObjRelease(pCur->pvObj, pSession); 1322 RTSpinlockRelease(pIntNet->Spinlock, &Tmp); 1323 } 1352 rc = VERR_INTNET_INCOMPATIBLE_FLAGS; 1324 1353 } 1354 else 1355 rc = VERR_INTNET_INCOMPATIBLE_TRUNK; 1356 1325 1357 LogFlow(("intnetOpenNetwork: returns %Vrc *ppNetwork=%p\n", rc, *ppNetwork)); 1326 1358 return rc; … … 1330 1362 RTSpinlockRelease(pIntNet->Spinlock, &Tmp); 1331 1363 1332 LogFlow(("intnetOpenNetwork: returns VERR_ FILE_NOT_FOUND\n"));1333 return VERR_ FILE_NOT_FOUND;1364 LogFlow(("intnetOpenNetwork: returns VERR_NOT_FOUND\n")); 1365 return VERR_NOT_FOUND; 1334 1366 } 1335 1367 … … 1343 1375 * @returns VBox status code. 1344 1376 * @param pIntNet The instance data. 1377 * @param pSession The session handle. 1345 1378 * @param pszNetwork The name of the network. This must be at least one character long and no longer 1346 1379 * than the INTNETNETWORK::szName. 1347 * @param fRestrictAccess Whether new participants should be subjected to access check or not. 1348 * @param pSession The session handle. 1380 * @param enmTrunkType The trunk type. 1381 * @param pszTrunk The trunk name. Its meaning is specfic to the type. 1382 * @param fFlags Flags, see INTNET_OPEN_FLAGS_*. 1349 1383 * @param ppNetwork Where to store the network. 1350 1384 */ 1351 static int intnetCreateNetwork(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, bool fRestrictAccess, PINTNETNETWORK *ppNetwork) 1352 { 1353 LogFlow(("intnetCreateNetwork: pIntNet=%p pSession=%p pszNetwork=%p:{%s} ppNetwork=%p\n", 1354 pIntNet, pSession, pszNetwork, pszNetwork, ppNetwork)); 1355 1385 static int intnetCreateNetwork(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, INTNETTRUNKTYPE enmTrunkType, 1386 const char *pszTrunk, uint32_t fFlags, PINTNETNETWORK *ppNetwork) 1387 { 1388 LogFlow(("intnetCreateNetwork: pIntNet=%p pSession=%p pszNetwork=%p:{%s} enmTrunkType=%d pszTrunk=%p:{%s} fFlags=%#x ppNetwork=%p\n", 1389 pIntNet, pSession, pszNetwork, pszNetwork, enmTrunkType, pszTrunk, pszTrunk, fFlags, ppNetwork)); 1390 1391 /* just pro forma validation, the caller is internal. */ 1356 1392 AssertPtr(pIntNet); 1357 1393 AssertPtr(pSession); 1358 1394 AssertPtr(pszNetwork); 1395 Assert(enmTrunkType > kIntNetTrunkType_Invalid && enmTrunkType < kIntNetTrunkType_End); 1396 AssertPtr(pszTrunk); 1397 Assert(!(fFlags & ~(INTNET_OPEN_FLAGS_PUBLIC))); 1359 1398 AssertPtr(ppNetwork); 1360 1399 *ppNetwork = NULL; … … 1387 1426 //pNew->pIFs = NULL; 1388 1427 pNew->pIntNet = pIntNet; 1428 pNew->fFlags = fFlags; 1389 1429 pNew->cchName = cchName; 1390 pNew->fRestrictAccess = fRestrictAccess;1391 1430 Assert(cchName && cchName < sizeof(pNew->szName)); /* caller's responsibility. */ 1392 1431 memcpy(pNew->szName, pszNetwork, cchName); /* '\0' by alloc. */ 1432 pNew->enmTrunkType = enmTrunkType; 1433 Assert(strlen(pszTrunk) < sizeof(pNew->szTrunk)); /* caller's responsibility. */ 1434 strcpy(pNew->szTrunk, pszTrunk); 1393 1435 1394 1436 /* … … 1399 1441 { 1400 1442 /* 1401 * Insert the network into the list.1443 * Check again that the network doesn't exist and then link in the new one. 1402 1444 * This must be done before we attempt any SUPR0ObjRelease call. 1403 1445 */ 1404 1446 RTSpinlockAcquire(pIntNet->Spinlock, &Tmp); 1447 for (PINTNETNETWORK pCur = pIntNet->pNetworks; pCur; pCur = pCur->pNext) 1448 if ( pCur->cchName == cchName 1449 && !memcmp(pCur->szName, pszNetwork, cchName)) 1450 rc = VERR_ALREADY_EXISTS; 1405 1451 pNew->pNext = pIntNet->pNetworks; 1406 1452 pIntNet->pNetworks = pNew; 1407 1453 RTSpinlockRelease(pIntNet->Spinlock, &Tmp); 1408 1454 1409 /* 1410 * Check if the current session is actually allowed to create and open 1411 * the network. It is possible to implement network name based policies 1412 * and these must be checked now. SUPR0ObjRegister does no such checks. 1413 */ 1414 rc = SUPR0ObjVerifyAccess(pNew->pvObj, pSession, pNew->szName); 1415 if (VBOX_SUCCESS(rc)) 1455 if (RT_SUCCESS(rc)) 1416 1456 { 1417 *ppNetwork = pNew; 1418 LogFlow(("intnetCreateNetwork: returns VINF_SUCCESS *ppNetwork=%p\n", pNew)); 1419 return VINF_SUCCESS; 1457 /* 1458 * Check if the current session is actually allowed to create and open 1459 * the network. It is possible to implement network name based policies 1460 * and these must be checked now. SUPR0ObjRegister does no such checks. 1461 */ 1462 rc = SUPR0ObjVerifyAccess(pNew->pvObj, pSession, pNew->szName); 1463 if (VBOX_SUCCESS(rc)) 1464 { 1465 *ppNetwork = pNew; 1466 LogFlow(("intnetCreateNetwork: returns VINF_SUCCESS *ppNetwork=%p\n", pNew)); 1467 return VINF_SUCCESS; 1468 } 1420 1469 } 1421 1470 … … 1474 1523 const char *pszTrunkEnd = (const char *)memchr(pszTrunk, '\0', INTNET_MAX_TRUNK_NAME); 1475 1524 AssertReturn(pszTrunkEnd, VERR_INVALID_PARAMETER); 1476 if (pszTrunkEnd == pszTrunk) 1477 pszTrunk = NULL; 1478 } 1525 } 1526 else 1527 pszTrunk = ""; 1528 1479 1529 AssertMsgReturn(enmTrunkType > kIntNetTrunkType_Invalid && enmTrunkType < kIntNetTrunkType_End, 1480 1530 ("%d\n", enmTrunkType), VERR_INVALID_PARAMETER); … … 1508 1558 */ 1509 1559 PINTNETNETWORK pNetwork; 1510 rc = intnetOpenNetwork(pIntNet, pSession, pszNetwork, &pNetwork);1511 if (rc == VERR_ FILE_NOT_FOUND)1512 rc = intnetCreateNetwork(pIntNet, pSession, pszNetwork, !(fFlags & INTNET_OPEN_FLAGS_PUBLIC), &pNetwork);1560 rc = intnetOpenNetwork(pIntNet, pSession, pszNetwork, enmTrunkType, pszTrunk, fFlags, &pNetwork); 1561 if (rc == VERR_NOT_FOUND) 1562 rc = intnetCreateNetwork(pIntNet, pSession, pszNetwork, enmTrunkType, pszTrunk, fFlags, &pNetwork); 1513 1563 if (VBOX_SUCCESS(rc)) 1514 1564 {
Note:
See TracChangeset
for help on using the changeset viewer.