Changeset 47083 in vbox for trunk/src/VBox
- Timestamp:
- Jul 10, 2013 3:38:57 PM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 87134
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/localipc-win.cpp
r47051 r47083 178 178 179 179 /** 180 * Builds and allocates the security descriptor required for securing the local pipe. 181 * 182 * @return IPRT status code. 183 * @param ppDesc Where to store the allocated security descriptor on success. 184 * Must be free'd using LocalFree(). 185 */ 186 static int rtLocalIpcServerWinAllocSecurityDescriptior(PSECURITY_DESCRIPTOR *ppDesc) 187 { 188 /** @todo Stuff this into RTInitOnce? Later. */ 189 PFNCONVERTSTRINGSECURITYDESCRIPTORTOSECURITYDESCRIPTOR 190 pfnConvertStringSecurityDescriptorToSecurityDescriptor = NULL; 191 192 RTLDRMOD hAdvApi32 = NIL_RTLDRMOD; 193 int rc = RTLdrLoadSystem("Advapi32.dll", true /*fNoUnload*/, &hAdvApi32); 194 if (RT_SUCCESS(rc)) 195 rc = RTLdrGetSymbol(hAdvApi32, "ConvertStringSecurityDescriptorToSecurityDescriptorW", 196 (void**)&pfnConvertStringSecurityDescriptorToSecurityDescriptor); 197 198 PSECURITY_DESCRIPTOR pSecDesc = NULL; 199 if (RT_SUCCESS(rc)) 200 { 201 AssertPtr(pfnConvertStringSecurityDescriptorToSecurityDescriptor); 202 203 /* 204 * We'll create a security descriptor from a SDDL that denies 205 * access to network clients (this is local IPC after all), it 206 * makes some further restrictions to prevent non-authenticated 207 * users from screwing around. 208 */ 209 PRTUTF16 pwszSDDL; 210 rc = RTStrToUtf16(RTLOCALIPC_WIN_SDDL, &pwszSDDL); 211 if (RT_SUCCESS(rc)) 212 { 213 if (!pfnConvertStringSecurityDescriptorToSecurityDescriptor((LPCTSTR)pwszSDDL, 214 SDDL_REVISION_1, 215 &pSecDesc, 216 NULL)) 217 { 218 rc = RTErrConvertFromWin32(GetLastError()); 219 } 220 221 RTUtf16Free(pwszSDDL); 222 } 223 } 224 else 225 { 226 /* Windows OSes < W2K SP2 not supported for now, bail out. */ 227 /** @todo Implement me! */ 228 rc = VERR_NOT_SUPPORTED; 229 } 230 231 if (hAdvApi32 != NIL_RTLDRMOD) 232 RTLdrClose(hAdvApi32); 233 234 if (RT_SUCCESS(rc)) 235 { 236 AssertPtr(pSecDesc); 237 *ppDesc = pSecDesc; 238 } 239 240 return rc; 241 } 242 243 /** 180 244 * Creates a named pipe instance. 181 245 * … … 193 257 *phNmPipe = INVALID_HANDLE_VALUE; 194 258 195 /** @todo Stuff this into RTInitOnce. Later. */ 196 PFNCONVERTSTRINGSECURITYDESCRIPTORTOSECURITYDESCRIPTOR 197 pfnConvertStringSecurityDescriptorToSecurityDescriptor = NULL; 198 199 RTLDRMOD hAdvApi32 = NIL_RTLDRMOD; 200 int rc = RTLdrLoadSystem("Advapi32.lib", true /*fNoUnload*/, &hAdvApi32); 259 PSECURITY_DESCRIPTOR pSecDesc; 260 int rc = rtLocalIpcServerWinAllocSecurityDescriptior(&pSecDesc); 201 261 if (RT_SUCCESS(rc)) 202 rc = RTLdrGetSymbol(hAdvApi32, "ConvertStringSecurityDescriptorToSecurityDescriptor",203 (void**)&pfnConvertStringSecurityDescriptorToSecurityDescriptor);204 205 PSECURITY_DESCRIPTOR pSecDesc = NULL;206 if (RT_SUCCESS(rc))207 {208 AssertPtr(pfnConvertStringSecurityDescriptorToSecurityDescriptor);209 210 /*211 * We'll create a security descriptor from a SDDL that denies212 * access to network clients (this is local IPC after all), it213 * makes some further restrictions to prevent non-authenticated214 * users from screwing around.215 */216 if (!pfnConvertStringSecurityDescriptorToSecurityDescriptor(RTLOCALIPC_WIN_SDDL,217 SDDL_REVISION_1,218 &pSecDesc,219 NULL))220 {221 rc = RTErrConvertFromWin32(GetLastError());222 }223 }224 else225 {226 /* Windows OSes < W2K SP2 not supported for now, bail out. */227 /** @todo Implement me! */228 rc = VERR_NOT_SUPPORTED;229 }230 231 if (hAdvApi32 != NIL_RTLDRMOD)232 RTLdrClose(hAdvApi32);233 234 if (RT_SUCCESS(rc))235 262 { 236 263 SECURITY_ATTRIBUTES SecAttrs; 237 SecAttrs.nLength = sizeof(S ecAttrs);264 SecAttrs.nLength = sizeof(SECURITY_ATTRIBUTES); 238 265 SecAttrs.lpSecurityDescriptor = pSecDesc; 239 266 SecAttrs.bInheritHandle = FALSE; … … 276 303 PAGE_SIZE, /* nInBufferSize (ditto) */ 277 304 30*1000, /* nDefaultTimeOut = 30 sec */ 278 &SecAttrs); /* lpSecurityAttributes */ 279 305 NULL /** @todo !!! Fix this !!! &SecAttrs */); /* lpSecurityAttributes */ 280 306 LocalFree(pSecDesc); 281 307 if (hNmPipe != INVALID_HANDLE_VALUE) … … 300 326 AssertReturn(*pszName, VERR_INVALID_PARAMETER); 301 327 AssertReturn(!(fFlags & ~(RTLOCALIPC_FLAGS_VALID_MASK)), VERR_INVALID_PARAMETER); 302 303 AssertReturn(fFlags & RTLOCALIPC_FLAGS_MULTI_SESSION, VERR_NOT_IMPLEMENTED); /** @todo implement !RTLOCALIPC_FLAGS_MULTI_SESSION */ 328 AssertReturn((fFlags & RTLOCALIPC_FLAGS_MULTI_SESSION), VERR_INVALID_PARAMETER); /** @todo Implement !RTLOCALIPC_FLAGS_MULTI_SESSION */ 304 329 305 330 /* … … 448 473 449 474 RTCritSectEnter(&pThis->CritSect); 450 if ( 451 && 475 if ( !pThis->fCancelled /* Event signalled but not cancelled? */ 476 && pThis->u32Magic == RTLOCALIPCSERVER_MAGIC) 452 477 { 453 478 /* … … 462 487 { 463 488 HANDLE hNmPipe; 464 DWORD err= rtLocalIpcServerWinCreatePipeInstance(&hNmPipe, pThis->szName, false /* fFirst */);465 if ( err == NO_ERROR)489 rc = rtLocalIpcServerWinCreatePipeInstance(&hNmPipe, pThis->szName, false /* fFirst */); 490 if (RT_SUCCESS(rc)) 466 491 { 467 492 HANDLE hNmPipeSession = pThis->hNmPipe; /* consumed */ … … 475 500 * the client and fail. Don't try service the client here. 476 501 */ 477 rc = RTErrConvertFromWin32(err);478 502 fRc = DisconnectNamedPipe(pThis->hNmPipe); 479 503 AssertMsg(fRc, ("%d\n", GetLastError())); … … 550 574 { 551 575 AssertPtrReturn(phClientSession, VERR_INVALID_POINTER); 552 AssertReturn(hNmPipeSession != INVALID_HANDLE_VALUE, VERR_INVALID_ PARAMETER);576 AssertReturn(hNmPipeSession != INVALID_HANDLE_VALUE, VERR_INVALID_HANDLE); 553 577 554 578 int rc; … … 598 622 AssertPtrReturn(phSession, VERR_INVALID_POINTER); 599 623 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 624 AssertReturn(*pszName, VERR_INVALID_PARAMETER); 600 625 AssertReturn(!fFlags, VERR_INVALID_PARAMETER); /* Flags currently unused, must be 0. */ 601 626 … … 626 651 if (RTStrAPrintf(&pszPipe, "%s%s", RTLOCALIPC_WIN_PREFIX, pszName)) 627 652 { 628 HANDLE hPipe = CreateFile(pszPipe, /* pipe name */ 629 GENERIC_READ | /* read and write access */ 630 GENERIC_WRITE, 631 0, /* no sharing */ 632 NULL, /* default security attributes */ 633 OPEN_EXISTING, /* opens existing pipe */ 634 FILE_FLAG_OVERLAPPED, /* default attributes */ 635 NULL); /* no template file */ 636 RTStrFree(pszPipe); 637 if (hPipe != INVALID_HANDLE_VALUE) 653 PSECURITY_DESCRIPTOR pSecDesc; 654 rc = rtLocalIpcServerWinAllocSecurityDescriptior(&pSecDesc); 655 if (RT_SUCCESS(rc)) 638 656 { 639 pThis->hNmPipe = hPipe; 640 return VINF_SUCCESS; 657 SECURITY_ATTRIBUTES SecAttrs; 658 SecAttrs.nLength = sizeof(SECURITY_ATTRIBUTES); 659 SecAttrs.lpSecurityDescriptor = pSecDesc; 660 SecAttrs.bInheritHandle = FALSE; 661 662 HANDLE hPipe = CreateFile(pszPipe, /* pipe name */ 663 GENERIC_READ | /* read and write access */ 664 GENERIC_WRITE, 665 0, /* no sharing */ 666 &SecAttrs, /* default security attributes */ 667 OPEN_EXISTING, /* opens existing pipe */ 668 FILE_FLAG_OVERLAPPED, /* default attributes */ 669 NULL); /* no template file */ 670 LocalFree(pSecDesc); 671 RTStrFree(pszPipe); 672 673 if (hPipe != INVALID_HANDLE_VALUE) 674 { 675 pThis->hNmPipe = hPipe; 676 *phSession = pThis; 677 return VINF_SUCCESS; 678 } 679 else 680 rc = RTErrConvertFromWin32(GetLastError()); 641 681 } 642 else643 rc = RTErrConvertFromWin32(GetLastError());644 682 } 645 683 else … … 690 728 if (hSession == NIL_RTLOCALIPCSESSION) 691 729 return VINF_SUCCESS; 692 PRTLOCALIPCSESSIONINT pThis = ( RTLOCALIPCSESSION)hSession;730 PRTLOCALIPCSESSIONINT pThis = (PRTLOCALIPCSESSIONINT)hSession; 693 731 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 694 AssertReturn(pThis->u32Magic != RTLOCALIPCSESSION_MAGIC, VERR_INVALID_MAGIC);732 AssertReturn(pThis->u32Magic == RTLOCALIPCSESSION_MAGIC, VERR_INVALID_MAGIC); 695 733 696 734 /* … … 719 757 RTDECL(int) RTLocalIpcSessionRead(RTLOCALIPCSESSION hSession, void *pvBuffer, size_t cbBuffer, size_t *pcbRead) 720 758 { 721 PRTLOCALIPCSESSIONINT pThis = hSession;759 PRTLOCALIPCSESSIONINT pThis = (PRTLOCALIPCSESSIONINT)hSession; 722 760 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 723 761 AssertReturn(pThis->u32Magic == RTLOCALIPCSESSION_MAGIC, VERR_INVALID_HANDLE); … … 867 905 RTDECL(int) RTLocalIpcSessionWrite(RTLOCALIPCSESSION hSession, const void *pvBuffer, size_t cbBuffer) 868 906 { 869 PRTLOCALIPCSESSIONINT pThis = hSession;907 PRTLOCALIPCSESSIONINT pThis = (PRTLOCALIPCSESSIONINT)hSession; 870 908 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 871 909 AssertReturn(pThis->u32Magic == RTLOCALIPCSESSION_MAGIC, VERR_INVALID_HANDLE); … … 964 1002 RTDECL(int) RTLocalIpcSessionWaitForData(RTLOCALIPCSESSION hSession, uint32_t cMillies) 965 1003 { 966 PRTLOCALIPCSESSIONINT pThis = hSession;1004 PRTLOCALIPCSESSIONINT pThis = (PRTLOCALIPCSESSIONINT)hSession; 967 1005 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 968 1006 AssertReturn(pThis->u32Magic == RTLOCALIPCSESSION_MAGIC, VERR_INVALID_HANDLE); … … 975 1013 { 976 1014 pThis->cRefs++; 1015 pThis->fCancelled = false; /* Reset canellation status. */ 977 1016 RTCritSectLeave(&pThis->CritSect); 978 1017 … … 992 1031 else if (dwRc == WAIT_FAILED) 993 1032 rc = RTErrConvertFromWin32(GetLastError()); 1033 else if (pThis->fCancelled) 1034 rc = VERR_CANCELLED; 994 1035 995 1036 pThis->cRefs--; … … 1006 1047 RTDECL(int) RTLocalIpcSessionCancel(RTLOCALIPCSESSION hSession) 1007 1048 { 1008 return VINF_SUCCESS; 1049 PRTLOCALIPCSESSIONINT pThis = (PRTLOCALIPCSESSIONINT)hSession; 1050 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 1051 AssertReturn(pThis->u32Magic == RTLOCALIPCSESSION_MAGIC, VERR_INVALID_HANDLE); 1052 1053 /* 1054 * Enter the critical section, then set the cancellation flag 1055 * and signal the event (to wake up anyone in/at WaitForSingleObject). 1056 */ 1057 int rc = RTCritSectEnter(&pThis->CritSect); 1058 if (RT_SUCCESS(rc)) 1059 { 1060 ASMAtomicUoWriteBool(&pThis->fCancelled, true); 1061 BOOL fRc = SetEvent(pThis->hEvent); 1062 AssertMsg(fRc, ("%d\n", GetLastError())); NOREF(fRc); 1063 1064 RTCritSectLeave(&pThis->CritSect); 1065 } 1066 1067 return rc; 1009 1068 } 1010 1069 -
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r46638 r47083 80 80 tstLdrLoad \ 81 81 tstRTList \ 82 tstRTLocalIpc \ 82 83 tstRTLockValidator \ 83 84 tstLog \ … … 400 401 tstRTList_SOURCES = tstRTList.cpp 401 402 403 tstRTLocalIpc_TEMPLATE = VBOXR3TSTEXE 404 tstRTLocalIpc_SOURCES = tstRTLocalIpc.cpp 405 402 406 tstRTLockValidator_TEMPLATE = VBOXR3TSTEXE 403 407 tstRTLockValidator_SOURCES = tstRTLockValidator.cpp
Note:
See TracChangeset
for help on using the changeset viewer.