Changeset 58297 in vbox
- Timestamp:
- Oct 18, 2015 3:12:50 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/localipc.h
r58295 r58297 77 77 /** The server can handle multiple sessions. */ 78 78 #define RTLOCALIPC_FLAGS_MULTI_SESSION RT_BIT_32(0) 79 /** Native name, as apposed to a portable one. */ 80 #define RTLOCALIPC_FLAGS_NATIVE_NAME RT_BIT_32(1) 79 81 /** The mask of valid flags. */ 80 #define RTLOCALIPC_FLAGS_VALID_MASK UINT32_C(0x0000000 1)82 #define RTLOCALIPC_FLAGS_VALID_MASK UINT32_C(0x00000003) 81 83 /** @} */ 82 84 … … 124 126 * @param phSession Where to store the sesson handle on success. 125 127 * @param pszName The server name (see RTLocalIpcServerCreate for details). 126 * @param fFlags Flags . Current undefined, pass 0.128 * @param fFlags Flags, RTLOCALIPC_C_FLAGS_XXX. 127 129 */ 128 130 RTDECL(int) RTLocalIpcSessionConnect(PRTLOCALIPCSESSION phSession, const char *pszName, uint32_t fFlags); 131 132 /** @name RTLOCALIPC_C_FLAGS_XXX - RTLocalIpcSessionConnect flags 133 * @{ */ 134 /** Native name, as apposed to a portable one. */ 135 #define RTLOCALIPC_C_FLAGS_NATIVE_NAME RT_BIT_32(0) 136 /** The mask of valid flags. */ 137 #define RTLOCALIPC_C_FLAGS_VALID_MASK UINT32_C(0x00000001) 138 /** @} */ 129 139 130 140 -
trunk/src/VBox/Runtime/r3/posix/localipc-posix.cpp
r58295 r58297 55 55 56 56 #include "internal/magics.h" 57 #include "internal/path.h" 57 58 #include "internal/socket.h" 58 59 … … 113 114 114 115 115 /** Local IPC name prefix . */116 /** Local IPC name prefix for portable names. */ 116 117 #define RTLOCALIPC_POSIX_NAME_PREFIX "/tmp/.iprt-localipc-" 117 118 … … 122 123 * @returns IPRT status code. 123 124 * @param pszName The name to validate. 124 * @param pcchName Where to return the length.125 */ 126 static int rtLocalIpcPosixValidateName(const char *pszName, size_t *pcchName)125 * @param fNative Whether it's a native name or a portable name. 126 */ 127 static int rtLocalIpcPosixValidateName(const char *pszName, bool fNative) 127 128 { 128 129 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 129 130 uint32_t cchName = 0; 131 for (;;)130 AssertReturn(*pszName, VERR_INVALID_NAME); 131 132 if (!fNative) 132 133 { 133 char ch = pszName[cchName]; 134 if (!ch) 135 break; 136 AssertReturn(!RT_C_IS_CNTRL(ch), VERR_INVALID_NAME); 137 AssertReturn((unsigned)ch < 0x80, VERR_INVALID_NAME); 138 AssertReturn(ch != '\\', VERR_INVALID_NAME); 139 AssertReturn(ch != '/', VERR_INVALID_NAME); 140 cchName++; 134 for (;;) 135 { 136 char ch = *pszName++; 137 if (!ch) 138 break; 139 AssertReturn(!RT_C_IS_CNTRL(ch), VERR_INVALID_NAME); 140 AssertReturn((unsigned)ch < 0x80, VERR_INVALID_NAME); 141 AssertReturn(ch != '\\', VERR_INVALID_NAME); 142 AssertReturn(ch != '/', VERR_INVALID_NAME); 143 } 141 144 } 142 143 *pcchName = cchName;144 AssertReturn(sizeof(RTLOCALIPC_POSIX_NAME_PREFIX) + cchName <= RT_SIZEOFMEMB(struct sockaddr_un, sun_path),145 VERR_FILENAME_TOO_LONG);146 AssertReturn(cchName, VERR_INVALID_NAME);145 else 146 { 147 int rc = RTStrValidateEncoding(pszName); 148 AssertRCReturn(rc, rc); 149 } 147 150 148 151 return VINF_SUCCESS; … … 157 160 * @param pcbAddr Where to return the address size. 158 161 * @param pszName The user specified name (valid). 159 * @param cchName The user specified name length. 160 */ 161 static int rtLocalIpcPosixConstructName(struct sockaddr_un *pAddr, uint8_t *pcbAddr, const char *pszName, size_t cchName) 162 { 163 AssertMsgReturn(cchName + sizeof(RTLOCALIPC_POSIX_NAME_PREFIX) <= sizeof(pAddr->sun_path), 164 ("cchName=%zu sizeof(sun_path)=%zu\n", cchName, sizeof(pAddr->sun_path)), 165 VERR_FILENAME_TOO_LONG); 166 167 /** @todo Bother converting to local codeset/encoding?? */ 168 169 RT_ZERO(*pAddr); 162 * @param fNative Whether it's a native name or a portable name. 163 */ 164 static int rtLocalIpcPosixConstructName(struct sockaddr_un *pAddr, uint8_t *pcbAddr, const char *pszName, bool fNative) 165 { 166 const char *pszNativeName; 167 int rc = rtPathToNative(&pszNativeName, pszName, NULL /*pszBasePath not support*/); 168 if (RT_SUCCESS(rc)) 169 { 170 size_t cchNativeName = strlen(pszNativeName); 171 size_t cbFull = !fNative ? cchNativeName + sizeof(RTLOCALIPC_POSIX_NAME_PREFIX) : cchNativeName + 1; 172 if (cbFull <= sizeof(pAddr->sun_path)) 173 { 174 RT_ZERO(*pAddr); 170 175 #ifdef RT_OS_OS2 /* Size must be exactly right on OS/2. */ 171 *pcbAddr = sizeof(*pAddr);176 *pcbAddr = sizeof(*pAddr); 172 177 #else 173 *pcbAddr = RT_OFFSETOF(struct sockaddr_un, sun_path) + (uint8_t)cchName + sizeof(RTLOCALIPC_POSIX_NAME_PREFIX);178 *pcbAddr = RT_OFFSETOF(struct sockaddr_un, sun_path) + (uint8_t)cbFull; 174 179 #endif 175 180 #ifdef HAVE_SUN_LEN_MEMBER 176 pAddr->sun_len = *pcbAddr;181 pAddr->sun_len = *pcbAddr; 177 182 #endif 178 pAddr->sun_family = AF_LOCAL; 179 memcpy(pAddr->sun_path, RTLOCALIPC_POSIX_NAME_PREFIX, sizeof(RTLOCALIPC_POSIX_NAME_PREFIX) - 1); 180 memcpy(&pAddr->sun_path[sizeof(RTLOCALIPC_POSIX_NAME_PREFIX) - 1], pszName, cchName + 1); 181 182 return VINF_SUCCESS; 183 pAddr->sun_family = AF_LOCAL; 184 185 if (!fNative) 186 { 187 memcpy(pAddr->sun_path, RTLOCALIPC_POSIX_NAME_PREFIX, sizeof(RTLOCALIPC_POSIX_NAME_PREFIX) - 1); 188 memcpy(&pAddr->sun_path[sizeof(RTLOCALIPC_POSIX_NAME_PREFIX) - 1], pszNativeName, cchNativeName + 1); 189 } 190 else 191 memcpy(pAddr->sun_path, pszNativeName, cchNativeName + 1); 192 } 193 else 194 rc = VERR_FILENAME_TOO_LONG; 195 rtPathFreeNative(pszNativeName, pszName); 196 } 197 return rc; 183 198 } 184 199 … … 195 210 AssertReturn(!(fFlags & ~RTLOCALIPC_FLAGS_VALID_MASK), VERR_INVALID_FLAGS); 196 211 197 size_t cchName; 198 int rc = rtLocalIpcPosixValidateName(pszName, &cchName); 212 int rc = rtLocalIpcPosixValidateName(pszName, RT_BOOL(fFlags & RTLOCALIPC_FLAGS_NATIVE_NAME)); 199 213 if (RT_SUCCESS(rc)) 200 214 { … … 222 236 223 237 uint8_t cbAddr; 224 rc = rtLocalIpcPosixConstructName(&pThis->Name, &cbAddr, pszName, cchName); 238 rc = rtLocalIpcPosixConstructName(&pThis->Name, &cbAddr, pszName, 239 RT_BOOL(fFlags & RTLOCALIPC_FLAGS_NATIVE_NAME)); 225 240 if (RT_SUCCESS(rc)) 226 241 { … … 475 490 *phSession = NIL_RTLOCALIPCSESSION; 476 491 477 AssertReturn(!fFlags, VERR_INVALID_FLAGS); 478 479 size_t cchName; 480 int rc = rtLocalIpcPosixValidateName(pszName, &cchName); 492 AssertReturn(!(fFlags & ~RTLOCALIPC_C_FLAGS_VALID_MASK), VERR_INVALID_FLAGS); 493 494 int rc = rtLocalIpcPosixValidateName(pszName, RT_BOOL(fFlags & RTLOCALIPC_C_FLAGS_NATIVE_NAME)); 481 495 if (RT_SUCCESS(rc)) 482 496 { … … 507 521 struct sockaddr_un Addr; 508 522 uint8_t cbAddr; 509 rc = rtLocalIpcPosixConstructName(&Addr, &cbAddr, pszName, cchName);523 rc = rtLocalIpcPosixConstructName(&Addr, &cbAddr, pszName, RT_BOOL(fFlags & RTLOCALIPC_C_FLAGS_NATIVE_NAME)); 510 524 if (RT_SUCCESS(rc)) 511 525 {
Note:
See TracChangeset
for help on using the changeset viewer.