Changeset 42727 in vbox
- Timestamp:
- Aug 9, 2012 7:15:02 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 79936
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceToolBox.cpp
r42717 r42727 136 136 " [--verbose|-v] [<file>...]\n" 137 137 " rm <general options> [-r|-R] <file>...\n" 138 " mktemp <general options> <template>\n" 138 " mktemp <general options> [--directory|-d] [--secure|-s]\n" 139 " [--mode|-m <mode>] <template>\n" 139 140 " mkdir <general options> [--mode|-m] [--parents|-p]\n" 140 141 " [--verbose|-v] <directory>...\n" … … 195 196 { 196 197 RTPrintf("%c%c%c%c", 0, 0, 0, 0); 198 } 199 200 201 /** 202 * Parse a file mode string from the command line (currently octal only) 203 * and print an error message and return an error if necessary. 204 */ 205 static int vboxServiceToolboxParseMode(const char *pcszMode, RTFMODE *pfMode) 206 { 207 int rc = RTStrToUInt32Ex(pcszMode, NULL, 8 /* Base */, pfMode); 208 if (RT_FAILURE(rc)) /* Only octet based values supported right now! */ 209 RTMsgError("Mode flag strings not implemented yet! Use octal numbers instead. (%s)\n", 210 pcszMode); 211 return rc; 197 212 } 198 213 … … 1118 1133 static char g_paszMkTempHelp[] = 1119 1134 " VBoxService [--use-toolbox] vbox_mktemp <general options> <template>\n\n" 1120 "Create a temporary directory based on the template supplied. The last string\n"1135 "Create a temporary directory based on the template supplied. The first string\n" 1121 1136 "of consecutive 'X' characters in the template will be replaced to form a unique\n" 1122 "name for the directory.\n" 1137 "name for the directory. The template must contain an absolute path. The\n" 1138 "default creation mode is 0600 for files and 0700 for directories.\n" 1139 "Options:\n\n" 1140 " [--directory|-d] Create a directory instead of a file.\n" 1141 " [--mode|-m <mode>] Create the object with mode <mode>.\n" 1142 " [--secure|-s] Fail if the object cannot be created securely.\n" 1123 1143 "\n"; 1124 1144 … … 1163 1183 { "--machinereadable", VBOXSERVICETOOLBOXOPT_MACHINE_READABLE, 1164 1184 RTGETOPT_REQ_NOTHING }, 1185 { "--directory", 'd', RTGETOPT_REQ_NOTHING }, 1186 { "--mode", 'm', RTGETOPT_REQ_STRING }, 1187 { "--secure", 's', RTGETOPT_REQ_NOTHING }, 1188 }; 1189 1190 enum 1191 { 1192 /* Isn't that a bit long? s/VBOXSERVICETOOLBOX/VSTB/ ? */ 1193 /** Create a temporary directory instead of a temporary file. */ 1194 VBOXSERVICETOOLBOXMKTEMPFLAG_DIRECTORY = RT_BIT_32(0), 1195 /** Only create the temporary object if the operation is expected 1196 * to be secure. Not guaranteed to be supported on a particular 1197 * set-up. */ 1198 VBOXSERVICETOOLBOXMKTEMPFLAG_SECURE = RT_BIT_32(1) 1165 1199 }; 1166 1200 … … 1176 1210 uint32_t fFlags = 0; 1177 1211 uint32_t fOutputFlags = 0; 1178 int cNonOptions = 0; 1179 char *pszName; 1212 int cNonOptions = 0; 1213 RTFMODE fMode = 0700; 1214 bool fModeSet = false; 1215 char *pszName; 1180 1216 1181 1217 while ( (ch = RTGetOpt(&GetState, &ValueUnion)) … … 1198 1234 break; 1199 1235 1236 case 'd': 1237 fFlags |= VBOXSERVICETOOLBOXMKTEMPFLAG_DIRECTORY; 1238 break; 1239 1240 case 'm': 1241 rc = vboxServiceToolboxParseMode(ValueUnion.psz, &fMode); 1242 if (RT_FAILURE(rc)) 1243 return RTEXITCODE_SYNTAX; 1244 fModeSet = true; 1245 #ifndef RT_OS_WINDOWS 1246 umask(0); /* RTDirCreate workaround */ 1247 #endif 1248 break; 1249 case 's': 1250 fFlags |= VBOXSERVICETOOLBOXMKTEMPFLAG_SECURE; 1251 break; 1252 1200 1253 case VINF_GETOPT_NOT_OPTION: 1201 1254 /* RTGetOpt will sort these to the end of the argv vector so … … 1220 1273 } 1221 1274 1275 if (fFlags & VBOXSERVICETOOLBOXMKTEMPFLAG_SECURE && fModeSet) 1276 { 1277 toolboxMkTempReport("'-s' and '-m' parameters cannot be used together.\n", "", 1278 true, VERR_INVALID_PARAMETER, fOutputFlags, &rc); 1279 return RTEXITCODE_SYNTAX; 1280 } 1222 1281 /* We need exactly one template, containing at least one 'X'. */ 1223 1282 if (RT_SUCCESS(rc) && cNonOptions != 1) … … 1225 1284 toolboxMkTempReport("Please specify exactly one template.\n", "", 1226 1285 true, VERR_INVALID_PARAMETER, fOutputFlags, &rc); 1227 return RTEXITCODE_ FAILURE;1286 return RTEXITCODE_SYNTAX; 1228 1287 } 1229 1288 pszName = argv[argc - 1]; … … 1238 1297 if (RT_SUCCESS(rc)) 1239 1298 { 1240 rc = RTDirCreateTemp(pszName, 0700); 1241 toolboxMkTempReport("Created temporary directory '%s'.\n", 1242 pszName, RT_SUCCESS(rc), rc, fOutputFlags, NULL); 1243 toolboxMkTempReport("The following error occurred while creating a temporary directory with template '%s': %Rrc.\n", 1244 pszName, RT_FAILURE(rc), rc, fOutputFlags, NULL); 1299 if (fFlags & VBOXSERVICETOOLBOXMKTEMPFLAG_DIRECTORY) 1300 { 1301 rc = fFlags & VBOXSERVICETOOLBOXMKTEMPFLAG_SECURE 1302 ? RTDirCreateTempSecure(pszName) 1303 : RTDirCreateTemp(pszName, fMode); 1304 toolboxMkTempReport("Created temporary directory '%s'.\n", 1305 pszName, RT_SUCCESS(rc), rc, fOutputFlags, NULL); 1306 /* RTDirCreateTemp[Secure] sets the template to "" on failure. */ 1307 toolboxMkTempReport("The following error occurred while creating the temporary directory%s: %Rrc.\n", 1308 pszName, RT_FAILURE(rc), rc, fOutputFlags, NULL); 1309 } 1310 else 1311 { 1312 rc = fFlags & VBOXSERVICETOOLBOXMKTEMPFLAG_SECURE 1313 ? RTFileCreateTempSecure(pszName) 1314 : RTFileCreateTemp(pszName, fMode); 1315 toolboxMkTempReport("Created temporary file '%s'.\n", 1316 pszName, RT_SUCCESS(rc), rc, fOutputFlags, NULL); 1317 /* RTFileCreateTemp[Secure] sets the template to "" on failure. */ 1318 toolboxMkTempReport("The following error occurred while creating the temporary file%s: %Rrc.\n", 1319 pszName, RT_FAILURE(rc), rc, fOutputFlags, NULL); 1320 } 1245 1321 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) /* Output termination. */ 1246 1322 VBoxServiceToolboxPrintStrmTermination();
Note:
See TracChangeset
for help on using the changeset viewer.