Changeset 42125 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Jul 12, 2012 10:39:18 AM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 79075
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
r41100 r42125 37 37 #include <iprt/asm.h> 38 38 #include <iprt/buildconfig.h> 39 #include <iprt/ctype.h> 39 40 #include <iprt/initterm.h> 40 41 #include <iprt/path.h> … … 245 246 246 247 248 #ifndef VBOX_ONLY_DOCS 249 static RTEXITCODE settingsPasswordFile(ComPtr<IVirtualBox> virtualBox, const char *pszFile) 250 { 251 size_t cbFile; 252 char szPasswd[512]; 253 int vrc = VINF_SUCCESS; 254 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 255 bool fStdIn = !strcmp(pszFile, "stdin"); 256 PRTSTREAM pStrm; 257 if (!fStdIn) 258 vrc = RTStrmOpen(pszFile, "r", &pStrm); 259 else 260 pStrm = g_pStdIn; 261 if (RT_SUCCESS(vrc)) 262 { 263 vrc = RTStrmReadEx(pStrm, szPasswd, sizeof(szPasswd)-1, &cbFile); 264 if (RT_SUCCESS(vrc)) 265 { 266 if (cbFile >= sizeof(szPasswd)-1) 267 rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Provided password too long"); 268 else 269 { 270 unsigned i; 271 for (i = 0; i < cbFile && !RT_C_IS_CNTRL(szPasswd[i]); i++) 272 ; 273 szPasswd[i] = '\0'; 274 int rc; 275 CHECK_ERROR(virtualBox, SetSettingsSecret(com::Bstr(szPasswd).raw())); 276 if (FAILED(rc)) 277 rcExit = RTEXITCODE_FAILURE; 278 } 279 } 280 if (!fStdIn) 281 RTStrmClose(pStrm); 282 } 283 else 284 rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Cannot open password file '%s' (%Rrc)", pszFile); 285 286 return rcExit; 287 } 288 #endif 289 247 290 int main(int argc, char *argv[]) 248 291 { … … 260 303 int iCmd = 1; 261 304 int iCmdArg; 305 const char *g_pszSettingsPw = NULL; 306 const char *g_pszSettingsPwFile = NULL; 262 307 263 308 for (int i = 1; i < argc || argc <= iCmd; i++) … … 316 361 iCmd++; 317 362 } 363 else if (!strcmp(argv[i], "--settingspw")) 364 { 365 if (i >= argc-1) 366 return RTMsgErrorExit(RTEXITCODE_FAILURE, 367 "Password expected"); 368 /* password for certain settings */ 369 g_pszSettingsPw = argv[i+1]; 370 iCmd += 2; 371 } 372 else if (!strcmp(argv[i], "--settingspwfile")) 373 { 374 if (i >= argc-1) 375 return RTMsgErrorExit(RTEXITCODE_FAILURE, 376 "No password file specified"); 377 g_pszSettingsPwFile = argv[i+1]; 378 iCmd += 2; 379 } 318 380 else 319 {320 381 break; 321 }322 382 } 323 383 … … 447 507 }; 448 508 509 if (g_pszSettingsPw) 510 { 511 int rc; 512 CHECK_ERROR(virtualBox, SetSettingsSecret(Bstr(g_pszSettingsPw).raw())); 513 if (FAILED(rc)) 514 { 515 rcExit = RTEXITCODE_FAILURE; 516 break; 517 } 518 } 519 else if (g_pszSettingsPwFile) 520 { 521 rcExit = settingsPasswordFile(virtualBox, g_pszSettingsPwFile); 522 if (rcExit != RTEXITCODE_SUCCESS) 523 break; 524 } 525 449 526 HandlerArg handlerArg = { 0, NULL, virtualBox, session }; 450 527 int commandIndex; -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r41925 r42125 99 99 if (u64Cmd == USAGE_ALL) 100 100 RTStrmPrintf(pStrm, 101 "VBoxManage [-v|--version] print version number and exit\n" 102 "VBoxManage [-q|--nologo] ... suppress the logo\n" 101 "VBoxManage [-v|--version] print version number and exit\n" 102 "VBoxManage [-q|--nologo] ... suppress the logo\n" 103 "VBoxManage [--settingspw <pw>] ...\n" 104 "VBoxManage [--settingspwfile] ... provide the settings password\n" 103 105 "\n"); 104 106
Note:
See TracChangeset
for help on using the changeset viewer.