- Timestamp:
- Aug 22, 2012 7:00:28 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp
r42810 r42929 2193 2193 } 2194 2194 2195 static int handleCtrlCreateTemp(ComPtr<IGuest> pGuest, HandlerArg *pArg) 2196 { 2197 AssertPtrReturn(pArg, VERR_INVALID_PARAMETER); 2198 2199 /* 2200 * Parse arguments. 2201 * 2202 * Note! No direct returns here, everyone must go thru the cleanup at the 2203 * end of this function. 2204 */ 2205 static const RTGETOPTDEF s_aOptions[] = 2206 { 2207 { "--mode", 'm', RTGETOPT_REQ_UINT32 }, 2208 { "--directory", 'D', RTGETOPT_REQ_NOTHING }, 2209 { "--secure", 's', RTGETOPT_REQ_NOTHING }, 2210 { "--tmpdir", 't', RTGETOPT_REQ_STRING }, 2211 { "--username", 'u', RTGETOPT_REQ_STRING }, 2212 { "--passwordfile", 'p', RTGETOPT_REQ_STRING }, 2213 { "--password", GETOPTDEF_MKDIR_PASSWORD, RTGETOPT_REQ_STRING }, 2214 { "--domain", 'd', RTGETOPT_REQ_STRING }, 2215 { "--verbose", 'v', RTGETOPT_REQ_NOTHING } 2216 }; 2217 2218 int ch; 2219 RTGETOPTUNION ValueUnion; 2220 RTGETOPTSTATE GetState; 2221 RTGetOptInit(&GetState, pArg->argc, pArg->argv, 2222 s_aOptions, RT_ELEMENTS(s_aOptions), 0, RTGETOPTINIT_FLAGS_OPTS_FIRST); 2223 2224 Utf8Str strUsername; 2225 Utf8Str strPassword; 2226 Utf8Str strDomain; 2227 Utf8Str strTemplate; 2228 uint32_t fMode = 0; /* Default mode. */ 2229 bool fDirectory = false; 2230 bool fSecure = false; 2231 Utf8Str strTempDir; 2232 bool fVerbose = false; 2233 2234 DESTDIRMAP mapDirs; 2235 2236 while ((ch = RTGetOpt(&GetState, &ValueUnion))) 2237 { 2238 /* For options that require an argument, ValueUnion has received the value. */ 2239 switch (ch) 2240 { 2241 case 'm': /* Mode */ 2242 fMode = ValueUnion.u32; 2243 break; 2244 2245 case 'D': /* Create directory */ 2246 fDirectory = true; 2247 break; 2248 2249 case 's': /* Secure */ 2250 fSecure = true; 2251 break; 2252 2253 case 't': /* Temp directory */ 2254 strTempDir = ValueUnion.psz; 2255 break; 2256 2257 case 'u': /* User name */ 2258 strUsername = ValueUnion.psz; 2259 break; 2260 2261 case GETOPTDEF_MKDIR_PASSWORD: /* Password */ 2262 strPassword = ValueUnion.psz; 2263 break; 2264 2265 case 'p': /* Password file */ 2266 { 2267 RTEXITCODE rcExit = readPasswordFile(ValueUnion.psz, &strPassword); 2268 if (rcExit != RTEXITCODE_SUCCESS) 2269 return rcExit; 2270 break; 2271 } 2272 2273 case 'd': /* domain */ 2274 strDomain = ValueUnion.psz; 2275 break; 2276 2277 case 'v': /* Verbose */ 2278 fVerbose = true; 2279 break; 2280 2281 case VINF_GETOPT_NOT_OPTION: 2282 { 2283 if (strTemplate.isEmpty()) 2284 strTemplate = ValueUnion.psz; 2285 else 2286 return errorSyntax(USAGE_GUESTCONTROL, 2287 "More than one template specified!\n"); 2288 break; 2289 } 2290 2291 default: 2292 return RTGetOptPrintError(ch, &ValueUnion); 2293 } 2294 } 2295 2296 if (strTemplate.isEmpty()) 2297 return errorSyntax(USAGE_GUESTCONTROL, "No template specified!"); 2298 2299 if (strUsername.isEmpty()) 2300 return errorSyntax(USAGE_GUESTCONTROL, "No user name specified!"); 2301 2302 if (!fDirectory) 2303 return errorSyntax(USAGE_GUESTCONTROL, "Creating temporary files is currently not supported!"); 2304 2305 /* 2306 * Create the directories. 2307 */ 2308 HRESULT hrc = S_OK; 2309 if (fVerbose) 2310 { 2311 if (fDirectory && !strTempDir.isEmpty()) 2312 RTPrintf("Creating temporary directory from template '%s' in directory '%s' ...\n", 2313 strTemplate.c_str(), strTempDir.c_str()); 2314 else if (fDirectory) 2315 RTPrintf("Creating temporary directory from template '%s' in default temporary directory ...\n", 2316 strTemplate.c_str()); 2317 else if (!fDirectory && !strTempDir.isEmpty()) 2318 RTPrintf("Creating temporary file from template '%s' in directory '%s' ...\n", 2319 strTemplate.c_str(), strTempDir.c_str()); 2320 else if (!fDirectory) 2321 RTPrintf("Creating temporary file from template '%s' in default temporary directory ...\n", 2322 strTemplate.c_str()); 2323 } 2324 2325 ComPtr<IGuestSession> pGuestSession; 2326 hrc = pGuest->CreateSession(Bstr(strUsername).raw(), 2327 Bstr(strPassword).raw(), 2328 Bstr(strDomain).raw(), 2329 Bstr("VBoxManage Guest Control MkTemp").raw(), 2330 pGuestSession.asOutParam()); 2331 if (FAILED(hrc)) 2332 return ctrlPrintError(pGuest, COM_IIDOF(IGuest)); 2333 2334 if (fDirectory) 2335 { 2336 Bstr directory; 2337 hrc = pGuestSession->DirectoryCreateTemp(Bstr(strTemplate).raw(), 2338 fMode, Bstr(strTempDir).raw(), 2339 fSecure, 2340 directory.asOutParam()); 2341 if (SUCCEEDED(hrc)) 2342 RTPrintf("Directory name: %ls\n", directory.raw()); 2343 } 2344 // else - temporary file not yet implemented 2345 if (FAILED(hrc)) 2346 ctrlPrintError(pGuest, COM_IIDOF(IGuestSession)); /* Return code ignored, save original rc. */ 2347 2348 if (!pGuestSession.isNull()) 2349 pGuestSession->Close(); 2350 2351 return FAILED(hrc) ? RTEXITCODE_FAILURE : RTEXITCODE_SUCCESS; 2352 } 2353 2195 2354 static int handleCtrlStat(ComPtr<IGuest> pGuest, HandlerArg *pArg) 2196 2355 { … … 2501 2660 || !strcmp(pArg->argv[1], "md")) 2502 2661 rcExit = handleCtrlCreateDirectory(guest, &arg); 2662 else if ( !strcmp(pArg->argv[1], "createtemporary") 2663 || !strcmp(pArg->argv[1], "createtemp") 2664 || !strcmp(pArg->argv[1], "mktemp")) 2665 rcExit = handleCtrlCreateTemp(guest, &arg); 2503 2666 else if ( !strcmp(pArg->argv[1], "stat")) 2504 2667 rcExit = handleCtrlStat(guest, &arg);
Note:
See TracChangeset
for help on using the changeset viewer.