Changeset 79200 in vbox
- Timestamp:
- Jun 18, 2019 8:53:44 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/file.h
r77830 r79200 982 982 * platform-by-platform basis as platform support is added. 983 983 * @see RTPathIsSecure for the current list of criteria. 984 * 984 985 * @returns iprt status code. 985 986 * @returns VERR_NOT_SUPPORTED if the interface can not be supported on the -
trunk/src/VBox/Runtime/generic/createtemp-generic.cpp
r76553 r79200 40 40 41 41 42 static int rtCreateTempValidateTemplate(char *pszTemplate, char **ppszX, 43 unsigned *pcXes) 44 { 45 /* 46 * Validate input and count X'es. 47 * 48 * The X'es may be trailing, or they may be a cluster of 3 or more inside 49 * the file name. 50 */ 42 /** 43 * The X'es may be trailing, or they may be a cluster of 3 or more inside 44 * the file name. 45 */ 46 static int rtCreateTempValidateTemplate(char *pszTemplate, char **ppszX, unsigned *pcXes) 47 { 51 48 AssertPtr(pszTemplate); 52 49 AssertPtr(ppszX); 53 50 AssertPtr(pcXes); 51 54 52 unsigned cXes = 0; 55 53 char *pszX = strchr(pszTemplate, '\0'); … … 66 64 do 67 65 { 68 if ( 69 && 70 && 66 if ( pszXEnd[-1] == 'X' 67 && pszXEnd[-2] == 'X' 68 && pszXEnd[-3] == 'X') 71 69 { 72 70 pszX = pszXEnd - 3; … … 87 85 88 86 /* fail if none found. */ 89 if (!cXes)90 {91 AssertFailed();92 return VERR_INVALID_PARAMETER;93 }94 87 *ppszX = pszX; 95 88 *pcXes = cXes; 89 AssertReturn(cXes > 0, VERR_INVALID_PARAMETER); 96 90 return VINF_SUCCESS; 97 91 } … … 144 138 RTDECL(int) RTDirCreateTempSecure(char *pszTemplate) 145 139 { 146 size_t cchDir;147 char chOld;148 int rc;149 140 /* bool fSafe; */ 150 141 151 142 /* Temporarily convert pszTemplate to a path. */ 143 size_t cchDir = 0; 152 144 RTPathParseSimple(pszTemplate, &cchDir, NULL, NULL); 153 ch Old = pszTemplate[cchDir];145 char chOld = pszTemplate[cchDir]; 154 146 pszTemplate[cchDir] = '\0'; 155 147 /** @todo Implement this. */ 156 rc = /* RTPathIsSecure(pszTemplate, &fSafe) */ VERR_NOT_SUPPORTED;148 int rc = /* RTPathIsSecure(pszTemplate, &fSafe) */ VERR_NOT_SUPPORTED; 157 149 pszTemplate[cchDir] = chOld; 158 150 if (RT_SUCCESS(rc) /* && fSafe */) 159 151 return RTDirCreateTemp(pszTemplate, 0700); 160 else 161 { 162 *pszTemplate = '\0'; 163 /** @todo Replace VERR_PERMISSION_DENIED. VERR_INSECURE? */ 164 return RT_FAILURE(rc) ? rc : VERR_PERMISSION_DENIED; 165 } 152 153 *pszTemplate = '\0'; 154 /** @todo Replace VERR_PERMISSION_DENIED. VERR_INSECURE? */ 155 return RT_FAILURE(rc) ? rc : VERR_PERMISSION_DENIED; 166 156 } 167 157 RT_EXPORT_SYMBOL(RTDirCreateTempSecure); … … 172 162 char *pszX = NULL; 173 163 unsigned cXes = 0; 174 RTFILE hFile;175 164 int rc = rtCreateTempValidateTemplate(pszTemplate, &pszX, &cXes); 176 165 if (RT_FAILURE(rc)) … … 179 168 return rc; 180 169 } 170 181 171 /* 182 172 * Try ten thousand times. … … 185 175 while (i-- > 0) 186 176 { 187 uint64_t fOpen = RTFILE_O_WRITE | RTFILE_O_DENY_ALL 188 | RTFILE_O_CREATE | RTFILE_O_NOT_CONTENT_INDEXED 189 | fMode << RTFILE_O_CREATE_MODE_SHIFT; 177 uint64_t fOpen = RTFILE_O_WRITE | RTFILE_O_DENY_ALL | RTFILE_O_CREATE | RTFILE_O_NOT_CONTENT_INDEXED 178 | fMode << RTFILE_O_CREATE_MODE_SHIFT; 190 179 rtCreateTempFillTemplate(pszX, cXes); 180 RTFILE hFile = NIL_RTFILE; 191 181 rc = RTFileOpen(&hFile, pszTemplate, fOpen); 192 182 if (RT_SUCCESS(rc)) … … 213 203 RTDECL(int) RTFileCreateTempSecure(char *pszTemplate) 214 204 { 215 size_t cchDir;216 char chOld;217 int rc;218 205 /* bool fSafe; */ 219 206 220 207 /* Temporarily convert pszTemplate to a path. */ 208 size_t cchDir = 0; 221 209 RTPathParseSimple(pszTemplate, &cchDir, NULL, NULL); 222 ch Old = pszTemplate[cchDir];210 char chOld = pszTemplate[cchDir]; 223 211 pszTemplate[cchDir] = '\0'; 224 212 /** @todo Implement this. */ 225 rc = /* RTPathIsSecure(pszTemplate, &fSafe) */ VERR_NOT_SUPPORTED;213 int rc = /* RTPathIsSecure(pszTemplate, &fSafe) */ VERR_NOT_SUPPORTED; 226 214 pszTemplate[cchDir] = chOld; 227 215 if (RT_SUCCESS(rc) /* && fSafe */) 228 216 return RTFileCreateTemp(pszTemplate, 0600); 229 else 230 { 231 *pszTemplate = '\0'; 232 /** @todo Replace VERR_PERMISSION_DENIED. VERR_INSECURE? */ 233 return RT_FAILURE(rc) ? rc : VERR_PERMISSION_DENIED; 234 } 217 218 *pszTemplate = '\0'; 219 /** @todo Replace VERR_PERMISSION_DENIED. VERR_INSECURE? */ 220 return RT_FAILURE(rc) ? rc : VERR_PERMISSION_DENIED; 235 221 } 236 222 RT_EXPORT_SYMBOL(RTFileCreateTempSecure);
Note:
See TracChangeset
for help on using the changeset viewer.