Changeset 42712 in vbox for trunk/src/VBox/Runtime/generic
- Timestamp:
- Aug 9, 2012 2:36:02 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 79919
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/generic/createtemp-generic.cpp
r42709 r42712 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - RTDirCreateTemp, generic implementation.3 * IPRT - temporary file and directory creation, generic implementation. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2009 Oracle Corporation7 * Copyright (C) 2009-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 34 34 #include <iprt/assert.h> 35 35 #include <iprt/err.h> 36 #include <iprt/file.h> 36 37 #include <iprt/path.h> 37 38 #include <iprt/rand.h> … … 108 109 RTDECL(int) RTDirCreateTemp(char *pszTemplate, RTFMODE fMode) 109 110 { 110 char *pszX = NULL; /* Initialise to make gcc happy. */111 char *pszX = NULL; 111 112 unsigned cXes = 0; 112 113 int rc = rtCreateTempValidateTemplate(pszTemplate, &pszX, &cXes); … … 139 140 RT_EXPORT_SYMBOL(RTDirCreateTemp); 140 141 142 143 /** @todo Test case for this once it is implemented. */ 144 RTDECL(int) RTDirCreateTempSecure(char *pszTemplate) 145 { 146 size_t cchDir; 147 char chOld; 148 int rc; 149 /* bool fSafe; */ 150 151 /* Temporarily convert pszTemplate to a path. */ 152 RTPathParse(pszTemplate, &cchDir, NULL, NULL); 153 chOld = pszTemplate[cchDir]; 154 pszTemplate[cchDir] = '\0'; 155 /** @todo Implement this. */ 156 rc = /* RTPathIsSecure(pszTemplate, &fSafe) */ VERR_NOT_SUPPORTED; 157 pszTemplate[cchDir] = chOld; 158 if (RT_SUCCESS(rc) /* && fSafe */) 159 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 } 166 } 167 RT_EXPORT_SYMBOL(RTDirCreateTempSecure); 168 169 170 RTDECL(int) RTFileCreateTemp(char *pszTemplate, RTFMODE fMode) 171 { 172 char *pszX = NULL; 173 unsigned cXes = 0; 174 RTFILE hFile; 175 int rc = rtCreateTempValidateTemplate(pszTemplate, &pszX, &cXes); 176 if (RT_FAILURE(rc)) 177 { 178 *pszTemplate = '\0'; 179 return rc; 180 } 181 /* 182 * Try ten thousand times. 183 */ 184 int i = 10000; 185 while (i-- > 0) 186 { 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; 190 rtCreateTempFillTemplate(pszX, cXes); 191 rc = RTFileOpen(&hFile, pszTemplate, fOpen); 192 if (RT_SUCCESS(rc)) 193 { 194 RTFileClose(hFile); 195 return rc; 196 } 197 /** @todo Anything else to consider? */ 198 if (rc != VERR_ALREADY_EXISTS) 199 { 200 *pszTemplate = '\0'; 201 return rc; 202 } 203 } 204 205 /* we've given up. */ 206 *pszTemplate = '\0'; 207 return VERR_ALREADY_EXISTS; 208 } 209 RT_EXPORT_SYMBOL(RTFileCreateTemp); 210 211 212 /** @todo Test case for this once it is implemented. */ 213 RTDECL(int) RTFileCreateTempSecure(char *pszTemplate) 214 { 215 size_t cchDir; 216 char chOld; 217 int rc; 218 /* bool fSafe; */ 219 220 /* Temporarily convert pszTemplate to a path. */ 221 RTPathParse(pszTemplate, &cchDir, NULL, NULL); 222 chOld = pszTemplate[cchDir]; 223 pszTemplate[cchDir] = '\0'; 224 /** @todo Implement this. */ 225 rc = /* RTPathIsSecure(pszTemplate, &fSafe) */ VERR_NOT_SUPPORTED; 226 pszTemplate[cchDir] = chOld; 227 if (RT_SUCCESS(rc) /* && fSafe */) 228 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 } 235 } 236 RT_EXPORT_SYMBOL(RTFileCreateTempSecure);
Note:
See TracChangeset
for help on using the changeset viewer.