VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxService/VBoxServiceToolBox.cpp

最後變更 在這個檔案是 107687,由 vboxsync 提交於 2 月 前

src/VBox/Additions/common/VBoxService/VBoxServiceToolBox.cpp: Fixed warnings found by Parfait (unused assignment). jiraref:VBP-1424

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 60.1 KB
 
1/* $Id: VBoxServiceToolBox.cpp 107687 2025-01-10 16:36:22Z vboxsync $ */
2/** @file
3 * VBoxServiceToolbox - Internal (BusyBox-like) toolbox.
4 */
5
6/*
7 * Copyright (C) 2012-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.alldomusa.eu.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#include <iprt/assert.h>
33#include <iprt/buildconfig.h>
34#include <iprt/dir.h>
35#include <iprt/file.h>
36#include <iprt/getopt.h>
37#include <iprt/list.h>
38#include <iprt/mem.h>
39#include <iprt/message.h>
40#include <iprt/path.h>
41#include <iprt/string.h>
42#include <iprt/stream.h>
43#include <iprt/symlink.h>
44
45#ifndef RT_OS_WINDOWS
46# include <sys/stat.h> /* need umask */
47#endif
48
49#include <VBox/VBoxGuestLib.h>
50#include <VBox/version.h>
51
52#include <VBox/GuestHost/GuestControl.h>
53
54#include "VBoxServiceInternal.h"
55#include "VBoxServiceToolBox.h"
56#include "VBoxServiceUtils.h"
57
58using namespace guestControl;
59
60
61/*********************************************************************************************************************************
62* Defined Constants And Macros *
63*********************************************************************************************************************************/
64
65/** Generic option indices for commands. */
66enum
67{
68 VBOXSERVICETOOLBOXOPT_MACHINE_READABLE = 1000,
69 VBOXSERVICETOOLBOXOPT_VERBOSE
70};
71
72/** Options indices for "vbox_cat". */
73typedef enum VBOXSERVICETOOLBOXCATOPT
74{
75 VBOXSERVICETOOLBOXCATOPT_NO_CONTENT_INDEXED = 1000
76} VBOXSERVICETOOLBOXCATOPT;
77
78/** Flags for "vbox_ls". */
79typedef enum VBOXSERVICETOOLBOXLSFLAG
80{
81 VBOXSERVICETOOLBOXLSFLAG_NONE,
82 VBOXSERVICETOOLBOXLSFLAG_RECURSIVE,
83 VBOXSERVICETOOLBOXLSFLAG_SYMLINKS
84} VBOXSERVICETOOLBOXLSFLAG;
85
86/** Flags for fs object output. */
87typedef enum VBOXSERVICETOOLBOXOUTPUTFLAG
88{
89 VBOXSERVICETOOLBOXOUTPUTFLAG_NONE,
90 VBOXSERVICETOOLBOXOUTPUTFLAG_LONG,
91 VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE
92} VBOXSERVICETOOLBOXOUTPUTFLAG;
93
94/** The size of the directory entry buffer we're using. */
95#define VBOXSERVICETOOLBOX_DIRENTRY_BUF_SIZE (sizeof(RTDIRENTRYEX) + RTPATH_MAX)
96
97
98/*********************************************************************************************************************************
99* Structures and Typedefs *
100*********************************************************************************************************************************/
101/** Pointer to a tool handler function. */
102typedef RTEXITCODE (*PFNHANDLER)(int , char **);
103
104/** Definition for a specific toolbox tool. */
105typedef struct VBOXSERVICETOOLBOXTOOL
106{
107 /** Friendly name of the tool. */
108 const char *pszName;
109 /** Main handler to be invoked to use the tool. */
110 RTEXITCODE (*pfnHandler)(int argc, char **argv);
111 /** Conversion routine to convert the tool's exit code back to an IPRT rc. Optional.
112 *
113 * @todo r=bird: You better revert this, i.e. having pfnHandler return a VBox
114 * status code and have a routine for converting it to RTEXITCODE.
115 * Unless, what you really want to do here is to get a cached status, in
116 * which case you better call it what it is.
117 */
118 int (*pfnExitCodeConvertToRc)(RTEXITCODE rcExit);
119} VBOXSERVICETOOLBOXTOOL;
120/** Pointer to a const tool definition. */
121typedef VBOXSERVICETOOLBOXTOOL const *PCVBOXSERVICETOOLBOXTOOL;
122
123/**
124 * An file/directory entry. Used to cache
125 * file names/paths for later processing.
126 */
127typedef struct VBOXSERVICETOOLBOXPATHENTRY
128{
129 /** Our node. */
130 RTLISTNODE Node;
131 /** Name of the entry. */
132 char *pszName;
133} VBOXSERVICETOOLBOXPATHENTRY, *PVBOXSERVICETOOLBOXPATHENTRY;
134
135
136/*********************************************************************************************************************************
137* Internal Functions *
138*********************************************************************************************************************************/
139static RTEXITCODE vgsvcToolboxCat(int argc, char **argv);
140static RTEXITCODE vgsvcToolboxLs(int argc, char **argv);
141static RTEXITCODE vgsvcToolboxRm(int argc, char **argv);
142static RTEXITCODE vgsvcToolboxMkTemp(int argc, char **argv);
143static RTEXITCODE vgsvcToolboxMkDir(int argc, char **argv);
144static RTEXITCODE vgsvcToolboxStat(int argc, char **argv);
145
146
147/*********************************************************************************************************************************
148* Global Variables *
149*********************************************************************************************************************************/
150/** Tool definitions. */
151static VBOXSERVICETOOLBOXTOOL const g_aTools[] =
152{
153 { VBOXSERVICE_TOOL_CAT, vgsvcToolboxCat , NULL },
154 { VBOXSERVICE_TOOL_LS, vgsvcToolboxLs , NULL },
155 { VBOXSERVICE_TOOL_RM, vgsvcToolboxRm , NULL },
156 { VBOXSERVICE_TOOL_MKTEMP, vgsvcToolboxMkTemp, NULL },
157 { VBOXSERVICE_TOOL_MKDIR, vgsvcToolboxMkDir , NULL },
158 { VBOXSERVICE_TOOL_STAT, vgsvcToolboxStat , NULL }
159};
160
161
162
163
164/**
165 * Displays a common header for all help text to stdout.
166 */
167static void vgsvcToolboxShowUsageHeader(void)
168{
169 RTPrintf(VBOX_PRODUCT " Guest Toolbox Version "
170 VBOX_VERSION_STRING "\n"
171 "Copyright (C) " VBOX_C_YEAR " " VBOX_VENDOR "\n\n");
172 RTPrintf("Usage:\n\n");
173}
174
175
176/**
177 * Displays a help text to stdout.
178 */
179static void vgsvcToolboxShowUsage(void)
180{
181 vgsvcToolboxShowUsageHeader();
182 RTPrintf(" VBoxService [--use-toolbox] vbox_<command> [<general options>] <parameters>\n\n"
183 "General options:\n\n"
184 " --machinereadable produce all output in machine-readable form\n"
185 " -V print version number and exit\n"
186 "\n"
187 "Commands:\n\n"
188 " vbox_cat [<general options>] <file>...\n"
189 " vbox_ls [<general options>] [--dereference|-L] [-l] [-R]\n"
190 " [--verbose|-v] [<file>...]\n"
191 " vbox_rm [<general options>] [-r|-R] <file>...\n"
192 " vbox_mktemp [<general options>] [--directory|-d] [--mode|-m <mode>]\n"
193 " [--secure|-s] [--tmpdir|-t <path>] <template>\n"
194 " vbox_mkdir [<general options>] [--mode|-m <mode>] [--parents|-p]\n"
195 " [--verbose|-v] <directory>...\n"
196 " vbox_stat [<general options>] [--file-system|-f]\n"
197 " [--dereference|-L] [--terse|-t] [--verbose|-v] <file>...\n"
198 "\n");
199}
200
201
202/**
203 * Displays the program's version number.
204 */
205static void vgsvcToolboxShowVersion(void)
206{
207 RTPrintf("%sr%d\n", VBOX_VERSION_STRING, RTBldCfgRevision());
208}
209
210
211/**
212 * Initializes the parseable stream(s).
213 *
214 * @return IPRT status code.
215 */
216static int vgsvcToolboxStrmInit(void)
217{
218 /* Set stdout's mode to binary. This is required for outputting all the machine-readable
219 * data correctly. */
220 int rc = RTStrmSetMode(g_pStdOut, true /* Binary mode */, -1 /* Current code set, not changed */);
221 if (RT_FAILURE(rc))
222 RTMsgError("Unable to set stdout to binary mode, rc=%Rrc\n", rc);
223
224 return rc;
225}
226
227
228/**
229 * Prints a parseable stream header which contains the actual tool
230 * which was called/used along with its stream version.
231 *
232 * @param pszToolName Name of the tool being used, e.g. "vbt_ls".
233 * @param uVersion Stream version name. Handy for distinguishing
234 * different stream versions later.
235 */
236static void vgsvcToolboxPrintStrmHeader(const char *pszToolName, uint32_t uVersion)
237{
238 AssertPtrReturnVoid(pszToolName);
239 RTPrintf("hdr_id=%s%chdr_ver=%u%c", pszToolName, 0, uVersion, 0);
240}
241
242
243/**
244 * Prints a standardized termination sequence indicating that the
245 * parseable stream just ended.
246 */
247static void vgsvcToolboxPrintStrmTermination()
248{
249 RTPrintf("%c%c%c%c", 0, 0, 0, 0);
250}
251
252
253/**
254 * Parse a file mode string from the command line (currently octal only)
255 * and print an error message and return an error if necessary.
256 */
257static int vgsvcToolboxParseMode(const char *pcszMode, RTFMODE *pfMode)
258{
259 int rc = RTStrToUInt32Ex(pcszMode, NULL, 8 /* Base */, pfMode);
260 if (RT_FAILURE(rc)) /* Only octet based values supported right now! */
261 RTMsgError("Mode flag strings not implemented yet! Use octal numbers instead. (%s)\n", pcszMode);
262 return rc;
263}
264
265
266/**
267 * Destroys a path buffer list.
268 *
269 * @param pList Pointer to list to destroy.
270 */
271static void vgsvcToolboxPathBufDestroy(PRTLISTNODE pList)
272{
273 if (!pList)
274 return;
275
276 PVBOXSERVICETOOLBOXPATHENTRY pEntry, pEntryNext;
277 RTListForEachSafe(pList, pEntry, pEntryNext, VBOXSERVICETOOLBOXPATHENTRY, Node)
278 {
279 RTListNodeRemove(&pEntry->Node);
280
281 RTStrFree(pEntry->pszName);
282 RTMemFree(pEntry);
283 }
284}
285
286
287/**
288 * Adds a path entry (file/directory/whatever) to a given path buffer list.
289 *
290 * @return IPRT status code.
291 * @param pList Pointer to list to add entry to.
292 * @param pszName Name of entry to add.
293 */
294static int vgsvcToolboxPathBufAddPathEntry(PRTLISTNODE pList, const char *pszName)
295{
296 AssertPtrReturn(pList, VERR_INVALID_PARAMETER);
297
298 int rc = VINF_SUCCESS;
299 PVBOXSERVICETOOLBOXPATHENTRY pNode = (PVBOXSERVICETOOLBOXPATHENTRY)RTMemAlloc(sizeof(VBOXSERVICETOOLBOXPATHENTRY));
300 if (pNode)
301 {
302 pNode->pszName = RTStrDup(pszName);
303 AssertPtr(pNode->pszName);
304
305 RTListAppend(pList, &pNode->Node);
306 }
307 else
308 rc = VERR_NO_MEMORY;
309 return rc;
310}
311
312
313/**
314 * Performs the actual output operation of "vbox_cat".
315 *
316 * @return IPRT status code.
317 * @param hInput Handle of input file (if any) to use;
318 * else stdin will be used.
319 * @param hOutput Handle of output file (if any) to use;
320 * else stdout will be used.
321 */
322static int vgsvcToolboxCatOutput(RTFILE hInput, RTFILE hOutput)
323{
324 int rc = VINF_SUCCESS;
325 if (hInput == NIL_RTFILE)
326 {
327 rc = RTFileFromNative(&hInput, RTFILE_NATIVE_STDIN);
328 if (RT_FAILURE(rc))
329 RTMsgError("Could not translate input file to native handle, rc=%Rrc\n", rc);
330 }
331
332 if (hOutput == NIL_RTFILE)
333 {
334 rc = RTFileFromNative(&hOutput, RTFILE_NATIVE_STDOUT);
335 if (RT_FAILURE(rc))
336 RTMsgError("Could not translate output file to native handle, rc=%Rrc\n", rc);
337 }
338
339 if (RT_SUCCESS(rc))
340 {
341 uint8_t abBuf[_64K];
342 size_t cbRead;
343 for (;;)
344 {
345 rc = RTFileRead(hInput, abBuf, sizeof(abBuf), &cbRead);
346 if (RT_SUCCESS(rc) && cbRead > 0)
347 {
348 rc = RTFileWrite(hOutput, abBuf, cbRead, NULL /* Try to write all at once! */);
349 if (RT_FAILURE(rc))
350 {
351 RTMsgError("Error while writing output, rc=%Rrc\n", rc);
352 break;
353 }
354 }
355 else
356 {
357 if (rc == VERR_BROKEN_PIPE)
358 rc = VINF_SUCCESS;
359 else if (RT_FAILURE(rc))
360 RTMsgError("Error while reading input, rc=%Rrc\n", rc);
361 break;
362 }
363 }
364 }
365 return rc;
366}
367
368
369/** @todo Document options! */
370static char g_paszCatHelp[] =
371 " VBoxService [--use-toolbox] vbox_cat [<general options>] <file>...\n\n"
372 "Concatenate files, or standard input, to standard output.\n"
373 "\n";
374
375
376/**
377 * Main function for tool "vbox_cat".
378 *
379 * @return RTEXITCODE.
380 * @param argc Number of arguments.
381 * @param argv Pointer to argument array.
382 */
383static RTEXITCODE vgsvcToolboxCat(int argc, char **argv)
384{
385 static const RTGETOPTDEF s_aOptions[] =
386 {
387 /* Sorted by short ops. */
388 { "--show-all", 'a', RTGETOPT_REQ_NOTHING },
389 { "--number-nonblank", 'b', RTGETOPT_REQ_NOTHING},
390 { NULL, 'e', RTGETOPT_REQ_NOTHING},
391 { NULL, 'E', RTGETOPT_REQ_NOTHING},
392 { "--flags", 'f', RTGETOPT_REQ_STRING},
393 { "--no-content-indexed", VBOXSERVICETOOLBOXCATOPT_NO_CONTENT_INDEXED, RTGETOPT_REQ_NOTHING},
394 { "--number", 'n', RTGETOPT_REQ_NOTHING},
395 { "--output", 'o', RTGETOPT_REQ_STRING},
396 { "--squeeze-blank", 's', RTGETOPT_REQ_NOTHING},
397 { NULL, 't', RTGETOPT_REQ_NOTHING},
398 { "--show-tabs", 'T', RTGETOPT_REQ_NOTHING},
399 { NULL, 'u', RTGETOPT_REQ_NOTHING},
400 { "--show-noneprinting", 'v', RTGETOPT_REQ_NOTHING}
401 };
402
403 int ch;
404 RTGETOPTUNION ValueUnion;
405 RTGETOPTSTATE GetState;
406
407 RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1 /*iFirst*/, 0 /*fFlags*/);
408
409 int rc = VINF_SUCCESS;
410
411 const char *pszOutput = NULL;
412 RTFILE hOutput = NIL_RTFILE;
413 uint32_t fFlags = RTFILE_O_CREATE_REPLACE /* Output file flags. */
414 | RTFILE_O_WRITE
415 | RTFILE_O_DENY_WRITE;
416
417 /* Init directory list. */
418 RTLISTANCHOR inputList;
419 RTListInit(&inputList);
420
421 while ( (ch = RTGetOpt(&GetState, &ValueUnion))
422 && RT_SUCCESS(rc))
423 {
424 /* For options that require an argument, ValueUnion has received the value. */
425 switch (ch)
426 {
427 case 'a':
428 case 'b':
429 case 'e':
430 case 'E':
431 case 'n':
432 case 's':
433 case 't':
434 case 'T':
435 case 'v':
436 RTMsgError("Sorry, option '%s' is not implemented yet!\n",
437 ValueUnion.pDef->pszLong);
438 rc = VERR_INVALID_PARAMETER;
439 break;
440
441 case 'h':
442 vgsvcToolboxShowUsageHeader();
443 RTPrintf("%s", g_paszCatHelp);
444 return RTEXITCODE_SUCCESS;
445
446 case 'o':
447 pszOutput = ValueUnion.psz;
448 break;
449
450 case 'u':
451 /* Ignored. */
452 break;
453
454 case 'V':
455 vgsvcToolboxShowVersion();
456 return RTEXITCODE_SUCCESS;
457
458 case VBOXSERVICETOOLBOXCATOPT_NO_CONTENT_INDEXED:
459 fFlags |= RTFILE_O_NOT_CONTENT_INDEXED;
460 break;
461
462 case VINF_GETOPT_NOT_OPTION:
463 /* Add file(s) to buffer. This enables processing multiple paths
464 * at once.
465 *
466 * Since the non-options (RTGETOPTINIT_FLAGS_OPTS_FIRST) come last when
467 * processing this loop it's safe to immediately exit on syntax errors
468 * or showing the help text (see above). */
469 rc = vgsvcToolboxPathBufAddPathEntry(&inputList, ValueUnion.psz);
470 break;
471
472 default:
473 return RTGetOptPrintError(ch, &ValueUnion);
474 }
475 }
476
477 if (RT_SUCCESS(rc))
478 {
479 if (pszOutput)
480 {
481 rc = RTFileOpen(&hOutput, pszOutput, fFlags);
482 if (RT_FAILURE(rc))
483 RTMsgError("Could not create output file '%s', rc=%Rrc\n", pszOutput, rc);
484 }
485
486 if (RT_SUCCESS(rc))
487 {
488 /* Process each input file. */
489 RTFILE hInput = NIL_RTFILE;
490 PVBOXSERVICETOOLBOXPATHENTRY pNodeIt;
491 RTListForEach(&inputList, pNodeIt, VBOXSERVICETOOLBOXPATHENTRY, Node)
492 {
493 rc = RTFileOpen(&hInput, pNodeIt->pszName,
494 RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
495 if (RT_SUCCESS(rc))
496 {
497 rc = vgsvcToolboxCatOutput(hInput, hOutput);
498 RTFileClose(hInput);
499 }
500 else
501 RTMsgError("Could not open input file '%s': %Rrc\n", pNodeIt->pszName, rc);
502 if (RT_FAILURE(rc))
503 break;
504 }
505
506 /* If no input files were defined, process stdin. */
507 if (RTListNodeIsFirst(&inputList, &inputList))
508 rc = vgsvcToolboxCatOutput(hInput, hOutput);
509 }
510 }
511
512 if (hOutput != NIL_RTFILE)
513 RTFileClose(hOutput);
514 vgsvcToolboxPathBufDestroy(&inputList);
515
516 if (RT_FAILURE(rc))
517 {
518 switch (rc)
519 {
520 case VERR_ACCESS_DENIED:
521 return (RTEXITCODE)VBOXSERVICETOOLBOX_CAT_EXITCODE_ACCESS_DENIED;
522
523 case VERR_FILE_NOT_FOUND:
524 return (RTEXITCODE)VBOXSERVICETOOLBOX_CAT_EXITCODE_FILE_NOT_FOUND;
525
526 case VERR_PATH_NOT_FOUND:
527 return (RTEXITCODE)VBOXSERVICETOOLBOX_CAT_EXITCODE_PATH_NOT_FOUND;
528
529 case VERR_SHARING_VIOLATION:
530 return (RTEXITCODE)VBOXSERVICETOOLBOX_CAT_EXITCODE_SHARING_VIOLATION;
531
532 case VERR_IS_A_DIRECTORY:
533 return (RTEXITCODE)VBOXSERVICETOOLBOX_CAT_EXITCODE_IS_A_DIRECTORY;
534
535 default:
536#ifdef DEBUG_andy
537 AssertMsgFailed(("Exit code for %Rrc not implemented\n", rc));
538#endif
539 break;
540 }
541
542 return RTEXITCODE_FAILURE;
543 }
544
545 return RTEXITCODE_SUCCESS;
546}
547
548
549/**
550 * Prints information (based on given flags) of a file system object (file/directory/...)
551 * to stdout.
552 *
553 * @return IPRT status code.
554 * @param pszName Object name.
555 * @param cchName Length of pszName.
556 * @param fOutputFlags Output / handling flags of type
557 * VBOXSERVICETOOLBOXOUTPUTFLAG.
558 * @param pszRelativeTo What pszName is relative to.
559 * @param pIdCache The ID cache.
560 * @param pObjInfo Pointer to object information.
561 */
562static int vgsvcToolboxPrintFsInfo(const char *pszName, size_t cchName, uint32_t fOutputFlags, const char *pszRelativeTo,
563 PVGSVCIDCACHE pIdCache, PRTFSOBJINFO pObjInfo)
564{
565 AssertPtrReturn(pszName, VERR_INVALID_POINTER);
566 AssertReturn(cchName, VERR_INVALID_PARAMETER);
567 AssertPtrReturn(pObjInfo, VERR_INVALID_POINTER);
568
569 RTFMODE fMode = pObjInfo->Attr.fMode;
570 char chFileType;
571 switch (fMode & RTFS_TYPE_MASK)
572 {
573 case RTFS_TYPE_FIFO: chFileType = 'f'; break;
574 case RTFS_TYPE_DEV_CHAR: chFileType = 'c'; break;
575 case RTFS_TYPE_DIRECTORY: chFileType = 'd'; break;
576 case RTFS_TYPE_DEV_BLOCK: chFileType = 'b'; break;
577 case RTFS_TYPE_FILE: chFileType = '-'; break;
578 case RTFS_TYPE_SYMLINK: chFileType = 'l'; break;
579 case RTFS_TYPE_SOCKET: chFileType = 's'; break;
580 case RTFS_TYPE_WHITEOUT: chFileType = 'w'; break;
581 default: chFileType = '?'; break;
582 }
583 /** @todo sticy bits++ */
584
585/** @todo r=bird: turns out the host doesn't use or need cname_len, so perhaps we could drop it? */
586 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_LONG))
587 {
588 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)
589 {
590 RTPrintf("ftype=%c%cnode_id=%RU64%cinode_dev=%RU32%ccname_len=%zu%cname=%s%c",
591 chFileType, 0, (uint64_t)pObjInfo->Attr.u.Unix.INodeId, 0,
592 (uint32_t)pObjInfo->Attr.u.Unix.INodeIdDevice, 0, cchName, 0, pszName, 0);
593 RTPrintf("%c%c", 0, 0);
594 }
595 else
596 RTPrintf("%c %#18llx %3zu %s\n", chFileType, (uint64_t)pObjInfo->Attr.u.Unix.INodeId, cchName, pszName);
597 }
598 else
599 {
600 char szTimeBirth[RTTIME_STR_LEN];
601 char szTimeChange[RTTIME_STR_LEN];
602 char szTimeModification[RTTIME_STR_LEN];
603 char szTimeAccess[RTTIME_STR_LEN];
604
605 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)
606 {
607 RTPrintf("ftype=%c%c", chFileType, 0);
608 if (pObjInfo->Attr.u.Unix.INodeId || pObjInfo->Attr.u.Unix.INodeIdDevice)
609 RTPrintf("node_id=%RU64%cinode_dev=%RU32%c", (uint64_t)pObjInfo->Attr.u.Unix.INodeId, 0,
610 (uint32_t)pObjInfo->Attr.u.Unix.INodeIdDevice, 0);
611 RTPrintf("owner_mask=%c%c%c%c",
612 fMode & RTFS_UNIX_IRUSR ? 'r' : '-',
613 fMode & RTFS_UNIX_IWUSR ? 'w' : '-',
614 fMode & RTFS_UNIX_IXUSR ? 'x' : '-', 0);
615 RTPrintf("group_mask=%c%c%c%c",
616 fMode & RTFS_UNIX_IRGRP ? 'r' : '-',
617 fMode & RTFS_UNIX_IWGRP ? 'w' : '-',
618 fMode & RTFS_UNIX_IXGRP ? 'x' : '-', 0);
619 RTPrintf("other_mask=%c%c%c%c",
620 fMode & RTFS_UNIX_IROTH ? 'r' : '-',
621 fMode & RTFS_UNIX_IWOTH ? 'w' : '-',
622 fMode & RTFS_UNIX_IXOTH ? 'x' : '-', 0);
623 /** @todo sticky bits. */
624 RTPrintf("dos_mask=%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
625 fMode & RTFS_DOS_READONLY ? 'R' : '-',
626 fMode & RTFS_DOS_HIDDEN ? 'H' : '-',
627 fMode & RTFS_DOS_SYSTEM ? 'S' : '-',
628 fMode & RTFS_DOS_DIRECTORY ? 'D' : '-',
629 fMode & RTFS_DOS_ARCHIVED ? 'A' : '-',
630 fMode & RTFS_DOS_NT_DEVICE ? 'd' : '-',
631 fMode & RTFS_DOS_NT_NORMAL ? 'N' : '-',
632 fMode & RTFS_DOS_NT_TEMPORARY ? 'T' : '-',
633 fMode & RTFS_DOS_NT_SPARSE_FILE ? 'P' : '-',
634 fMode & RTFS_DOS_NT_REPARSE_POINT ? 'J' : '-',
635 fMode & RTFS_DOS_NT_COMPRESSED ? 'C' : '-',
636 fMode & RTFS_DOS_NT_OFFLINE ? 'O' : '-',
637 fMode & RTFS_DOS_NT_NOT_CONTENT_INDEXED ? 'I' : '-',
638 fMode & RTFS_DOS_NT_ENCRYPTED ? 'E' : '-', 0);
639 RTPrintf("hlinks=%RU32%cst_size=%RI64%calloc=%RI64%c",
640 pObjInfo->Attr.u.Unix.cHardlinks, 0,
641 pObjInfo->cbObject, 0,
642 pObjInfo->cbAllocated, 0);
643 RTPrintf("st_birthtime=%s%cst_ctime=%s%cst_mtime=%s%cst_atime=%s%c",
644 RTTimeSpecToString(&pObjInfo->BirthTime, szTimeBirth, sizeof(szTimeBirth)), 0,
645 RTTimeSpecToString(&pObjInfo->ChangeTime, szTimeChange, sizeof(szTimeChange)), 0,
646 RTTimeSpecToString(&pObjInfo->ModificationTime, szTimeModification, sizeof(szTimeModification)), 0,
647 RTTimeSpecToString(&pObjInfo->AccessTime, szTimeAccess, sizeof(szTimeAccess)), 0);
648 if (pObjInfo->Attr.u.Unix.uid != NIL_RTUID)
649 RTPrintf("uid=%RU32%cusername=%s%c", pObjInfo->Attr.u.Unix.uid, 0,
650 VGSvcIdCacheGetUidName(pIdCache, pObjInfo->Attr.u.Unix.uid, pszName, pszRelativeTo), 0);
651 if (pObjInfo->Attr.u.Unix.gid != NIL_RTGID)
652 RTPrintf("gid=%RU32%cgroupname=%s%c", pObjInfo->Attr.u.Unix.gid, 0,
653 VGSvcIdCacheGetGidName(pIdCache, pObjInfo->Attr.u.Unix.gid, pszName, pszRelativeTo), 0);
654 if ( (RTFS_IS_DEV_BLOCK(pObjInfo->Attr.fMode) || RTFS_IS_DEV_CHAR(pObjInfo->Attr.fMode))
655 && pObjInfo->Attr.u.Unix.Device)
656 RTPrintf("st_rdev=%RU32%c", pObjInfo->Attr.u.Unix.Device, 0);
657 if (pObjInfo->Attr.u.Unix.GenerationId)
658 RTPrintf("st_gen=%RU32%c", pObjInfo->Attr.u.Unix.GenerationId, 0);
659 if (pObjInfo->Attr.u.Unix.fFlags)
660 RTPrintf("st_flags=%RU32%c", pObjInfo->Attr.u.Unix.fFlags, 0);
661 RTPrintf("cname_len=%zu%cname=%s%c", cchName, 0, pszName, 0);
662 RTPrintf("%c%c", 0, 0); /* End of data block. */
663 }
664 else
665 {
666 RTPrintf("%c", chFileType);
667 RTPrintf("%c%c%c",
668 fMode & RTFS_UNIX_IRUSR ? 'r' : '-',
669 fMode & RTFS_UNIX_IWUSR ? 'w' : '-',
670 fMode & RTFS_UNIX_IXUSR ? 'x' : '-');
671 RTPrintf("%c%c%c",
672 fMode & RTFS_UNIX_IRGRP ? 'r' : '-',
673 fMode & RTFS_UNIX_IWGRP ? 'w' : '-',
674 fMode & RTFS_UNIX_IXGRP ? 'x' : '-');
675 RTPrintf("%c%c%c",
676 fMode & RTFS_UNIX_IROTH ? 'r' : '-',
677 fMode & RTFS_UNIX_IWOTH ? 'w' : '-',
678 fMode & RTFS_UNIX_IXOTH ? 'x' : '-');
679 RTPrintf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c",
680 fMode & RTFS_DOS_READONLY ? 'R' : '-',
681 fMode & RTFS_DOS_HIDDEN ? 'H' : '-',
682 fMode & RTFS_DOS_SYSTEM ? 'S' : '-',
683 fMode & RTFS_DOS_DIRECTORY ? 'D' : '-',
684 fMode & RTFS_DOS_ARCHIVED ? 'A' : '-',
685 fMode & RTFS_DOS_NT_DEVICE ? 'd' : '-',
686 fMode & RTFS_DOS_NT_NORMAL ? 'N' : '-',
687 fMode & RTFS_DOS_NT_TEMPORARY ? 'T' : '-',
688 fMode & RTFS_DOS_NT_SPARSE_FILE ? 'P' : '-',
689 fMode & RTFS_DOS_NT_REPARSE_POINT ? 'J' : '-',
690 fMode & RTFS_DOS_NT_COMPRESSED ? 'C' : '-',
691 fMode & RTFS_DOS_NT_OFFLINE ? 'O' : '-',
692 fMode & RTFS_DOS_NT_NOT_CONTENT_INDEXED ? 'I' : '-',
693 fMode & RTFS_DOS_NT_ENCRYPTED ? 'E' : '-');
694 RTPrintf(" %d %4d %4d %10lld %10lld",
695 pObjInfo->Attr.u.Unix.cHardlinks,
696 pObjInfo->Attr.u.Unix.uid,
697 pObjInfo->Attr.u.Unix.gid,
698 pObjInfo->cbObject,
699 pObjInfo->cbAllocated);
700 RTPrintf(" %s %s %s %s",
701 RTTimeSpecToString(&pObjInfo->BirthTime, szTimeBirth, sizeof(szTimeBirth)),
702 RTTimeSpecToString(&pObjInfo->ChangeTime, szTimeChange, sizeof(szTimeChange)),
703 RTTimeSpecToString(&pObjInfo->ModificationTime, szTimeModification, sizeof(szTimeModification)),
704 RTTimeSpecToString(&pObjInfo->AccessTime, szTimeAccess, sizeof(szTimeAccess)) );
705 RTPrintf(" %2zu %s\n", cchName, pszName);
706 }
707 }
708
709 return VINF_SUCCESS;
710}
711
712/**
713 * Helper routine for ls tool for handling sub directories.
714 *
715 * @return IPRT status code.
716 * @param pszDir Pointer to the directory buffer.
717 * @param cchDir The length of pszDir in pszDir.
718 * @param pDirEntry Pointer to the directory entry.
719 * @param fFlags Flags of type VBOXSERVICETOOLBOXLSFLAG.
720 * @param fOutputFlags Flags of type VBOXSERVICETOOLBOXOUTPUTFLAG.
721 * @param pIdCache The ID cache.
722 */
723static int vgsvcToolboxLsHandleDirSub(char *pszDir, size_t cchDir, PRTDIRENTRYEX pDirEntry,
724 uint32_t fFlags, uint32_t fOutputFlags, PVGSVCIDCACHE pIdCache)
725{
726 Assert(cchDir > 0); Assert(pszDir[cchDir] == '\0');
727
728 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)
729 RTPrintf("dname=%s%c", pszDir, 0);
730 else if (fFlags & VBOXSERVICETOOLBOXLSFLAG_RECURSIVE)
731 RTPrintf("%s:\n", pszDir);
732
733 /* Make sure we've got some room in the path, to save us extra work further down. */
734 if (cchDir + 3 >= RTPATH_MAX)
735 {
736 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE))
737 RTMsgError("Path too long: '%s'\n", pszDir);
738 return VERR_BUFFER_OVERFLOW;
739 }
740
741 /* Open directory. */
742 RTDIR hDir;
743 int rc = RTDirOpen(&hDir, pszDir);
744 if (RT_FAILURE(rc))
745 {
746 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE))
747 RTMsgError("Failed to open directory '%s', rc=%Rrc\n", pszDir, rc);
748 return rc;
749 }
750
751 /* Ensure we've got a trailing slash (there is space for it see above). */
752 if (!RTPATH_IS_SEP(pszDir[cchDir - 1]))
753 {
754 pszDir[cchDir++] = RTPATH_SLASH;
755 pszDir[cchDir] = '\0';
756 }
757
758 /*
759 * Process the files and subdirs.
760 */
761 for (;;)
762 {
763 /* Get the next directory. */
764 size_t cbDirEntry = VBOXSERVICETOOLBOX_DIRENTRY_BUF_SIZE;
765 rc = RTDirReadEx(hDir, pDirEntry, &cbDirEntry, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK);
766 if (RT_FAILURE(rc))
767 break;
768
769 /* Check length. */
770 if (pDirEntry->cbName + cchDir + 3 >= RTPATH_MAX)
771 {
772 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE))
773 RTMsgError("Path too long: '%s' in '%.*s'\n", pDirEntry->szName, cchDir, pszDir);
774 rc = VERR_BUFFER_OVERFLOW;
775 break;
776 }
777
778 switch (pDirEntry->Info.Attr.fMode & RTFS_TYPE_MASK)
779 {
780 case RTFS_TYPE_SYMLINK:
781 {
782 if (!(fFlags & VBOXSERVICETOOLBOXLSFLAG_SYMLINKS))
783 break;
784 RT_FALL_THRU();
785 }
786 case RTFS_TYPE_DIRECTORY:
787 {
788 rc = vgsvcToolboxPrintFsInfo(pDirEntry->szName, pDirEntry->cbName, fOutputFlags, pszDir,
789 pIdCache, &pDirEntry->Info);
790 if (RT_FAILURE(rc))
791 break;
792
793 if (RTDirEntryExIsStdDotLink(pDirEntry))
794 continue;
795
796 if (!(fFlags & VBOXSERVICETOOLBOXLSFLAG_RECURSIVE))
797 continue;
798
799 memcpy(&pszDir[cchDir], pDirEntry->szName, pDirEntry->cbName + 1);
800 int rc2 = vgsvcToolboxLsHandleDirSub(pszDir, cchDir + pDirEntry->cbName, pDirEntry, fFlags, fOutputFlags, pIdCache);
801 if (RT_SUCCESS(rc))
802 rc = rc2;
803 break;
804 }
805
806 case RTFS_TYPE_FILE:
807 {
808 rc = vgsvcToolboxPrintFsInfo(pDirEntry->szName, pDirEntry->cbName, fOutputFlags, pszDir,
809 pIdCache, &pDirEntry->Info);
810 break;
811 }
812
813 default:
814 {
815 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE))
816 RTMsgError("Entry '%.*s%s' of mode %#x not supported, skipping",
817 cchDir, pszDir, pDirEntry->szName, pDirEntry->Info.Attr.fMode & RTFS_TYPE_MASK);
818 break;
819 }
820 }
821
822 if (RT_FAILURE(rc))
823 break;
824 } /* for */
825
826 if (rc != VERR_NO_MORE_FILES)
827 {
828 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE))
829 RTMsgError("RTDirReadEx failed: %Rrc\npszDir=%.*s", rc, cchDir, pszDir);
830 }
831
832 int rc2 = RTDirClose(hDir);
833 if (RT_FAILURE(rc2))
834 {
835 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE))
836 RTMsgError("RTDirClose failed: %Rrc\npszDir=%.*s", rc2, cchDir, pszDir);
837 }
838
839 if (RT_SUCCESS(rc))
840 rc = rc2;
841
842 return rc;
843}
844
845/**
846 * Helper routine for ls tool doing the actual parsing and output of
847 * a specified directory.
848 *
849 * @return IPRT status code.
850 * @param pszDir Absolute path to directory to ouptut.
851 * @param fFlags Flags of type VBOXSERVICETOOLBOXLSFLAG.
852 * @param fOutputFlags Flags of type VBOXSERVICETOOLBOXOUTPUTFLAG.
853 * @param pIdCache The ID cache.
854 */
855static int vgsvcToolboxLsHandleDir(const char *pszDir, uint32_t fFlags, uint32_t fOutputFlags, PVGSVCIDCACHE pIdCache)
856{
857 AssertPtrReturn(pszDir, VERR_INVALID_PARAMETER);
858 AssertPtrReturn(pIdCache, VERR_INVALID_PARAMETER);
859
860 char szPath[RTPATH_MAX];
861 int rc = RTPathAbs(pszDir, szPath, sizeof(szPath));
862 if (RT_FAILURE(rc))
863 {
864 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE))
865 RTMsgError("RTPathAbs failed on '%s': %Rrc\n", pszDir, rc);
866 return rc;
867 }
868
869 union
870 {
871 uint8_t abPadding[VBOXSERVICETOOLBOX_DIRENTRY_BUF_SIZE];
872 RTDIRENTRYEX DirEntry;
873 } uBuf;
874 return vgsvcToolboxLsHandleDirSub(szPath, strlen(szPath), &uBuf.DirEntry, fFlags, fOutputFlags, pIdCache);
875}
876
877
878/** @todo Document options! */
879static char g_paszLsHelp[] =
880 " VBoxService [--use-toolbox] vbox_ls [<general options>] [option]...\n"
881 " [<file>...]\n\n"
882 "List information about files (the current directory by default).\n\n"
883 "Options:\n\n"
884 " [--dereference|-L]\n"
885 " [-l][-R]\n"
886 " [--verbose|-v]\n"
887 " [<file>...]\n"
888 "\n";
889
890
891/**
892 * Main function for tool "vbox_ls".
893 *
894 * @return RTEXITCODE.
895 * @param argc Number of arguments.
896 * @param argv Pointer to argument array.
897 */
898static RTEXITCODE vgsvcToolboxLs(int argc, char **argv)
899{
900 static const RTGETOPTDEF s_aOptions[] =
901 {
902 { "--machinereadable", VBOXSERVICETOOLBOXOPT_MACHINE_READABLE, RTGETOPT_REQ_NOTHING },
903 { "--dereference", 'L', RTGETOPT_REQ_NOTHING },
904 { NULL, 'l', RTGETOPT_REQ_NOTHING },
905 { NULL, 'R', RTGETOPT_REQ_NOTHING },
906 { "--verbose", VBOXSERVICETOOLBOXOPT_VERBOSE, RTGETOPT_REQ_NOTHING}
907 };
908
909 int ch;
910 RTGETOPTUNION ValueUnion;
911 RTGETOPTSTATE GetState;
912 int rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions),
913 1 /*iFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST);
914 AssertRCReturn(rc, RTEXITCODE_INIT);
915
916 uint32_t fFlags = VBOXSERVICETOOLBOXLSFLAG_NONE;
917 uint32_t fOutputFlags = VBOXSERVICETOOLBOXOUTPUTFLAG_NONE;
918
919 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
920 {
921 /* For options that require an argument, ValueUnion has received the value. */
922 switch (ch)
923 {
924 case 'h':
925 vgsvcToolboxShowUsageHeader();
926 RTPrintf("%s", g_paszLsHelp);
927 return RTEXITCODE_SUCCESS;
928
929 case 'L': /* Dereference symlinks. */
930 fFlags |= VBOXSERVICETOOLBOXLSFLAG_SYMLINKS;
931 break;
932
933 case 'l': /* Print long format. */
934 fOutputFlags |= VBOXSERVICETOOLBOXOUTPUTFLAG_LONG;
935 break;
936
937 case VBOXSERVICETOOLBOXOPT_MACHINE_READABLE:
938 fOutputFlags |= VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE;
939 break;
940
941 case 'R': /* Recursive processing. */
942 fFlags |= VBOXSERVICETOOLBOXLSFLAG_RECURSIVE;
943 break;
944
945 case VBOXSERVICETOOLBOXOPT_VERBOSE:
946 /* Not implemented, ignore. */
947 break;
948
949 case 'V':
950 vgsvcToolboxShowVersion();
951 return RTEXITCODE_SUCCESS;
952
953 case VINF_GETOPT_NOT_OPTION:
954 Assert(GetState.iNext);
955 GetState.iNext--;
956 break;
957
958 default:
959 return RTGetOptPrintError(ch, &ValueUnion);
960 }
961
962 /* All flags / options processed? Bail out here.
963 * Processing the file / directory list comes down below. */
964 if (ch == VINF_GETOPT_NOT_OPTION)
965 break;
966 }
967
968 /* Print magic/version. */
969 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)
970 {
971 rc = vgsvcToolboxStrmInit();
972 if (RT_FAILURE(rc))
973 RTMsgError("Error while initializing parseable streams, rc=%Rrc\n", rc);
974 vgsvcToolboxPrintStrmHeader("vbt_ls", 1 /* Stream version */);
975 }
976
977 VGSVCIDCACHE IdCache;
978 RT_ZERO(IdCache);
979
980 char szDirCur[RTPATH_MAX];
981 rc = RTPathGetCurrent(szDirCur, sizeof(szDirCur));
982 if (RT_FAILURE(rc))
983 {
984 RTMsgError("Getting current directory failed, rc=%Rrc\n", rc);
985 return RTEXITCODE_FAILURE;
986 }
987
988 ch = RTGetOpt(&GetState, &ValueUnion);
989 do
990 {
991 char const *pszPath;
992
993 if (ch == 0) /* Use current directory if no element specified. */
994 pszPath = szDirCur;
995 else
996 pszPath = ValueUnion.psz;
997
998 RTFSOBJINFO objInfo;
999 int rc2 = RTPathQueryInfoEx(pszPath, &objInfo,
1000 RTFSOBJATTRADD_UNIX,
1001 fFlags & VBOXSERVICETOOLBOXLSFLAG_SYMLINKS ? RTPATH_F_FOLLOW_LINK : RTPATH_F_ON_LINK);
1002 if (RT_SUCCESS(rc2))
1003 {
1004 if ( RTFS_IS_FILE(objInfo.Attr.fMode)
1005 || RTFS_IS_SYMLINK(objInfo.Attr.fMode))
1006 rc2 = vgsvcToolboxPrintFsInfo(pszPath, strlen(pszPath), fOutputFlags, NULL, &IdCache, &objInfo);
1007 else if (RTFS_IS_DIRECTORY(objInfo.Attr.fMode))
1008 rc2 = vgsvcToolboxLsHandleDir(pszPath, fFlags, fOutputFlags, &IdCache);
1009 if (RT_SUCCESS(rc)) /* Keep initial failing rc. */
1010 rc = rc2;
1011 }
1012 else
1013 {
1014 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE))
1015 RTMsgError("Cannot access '%s': No such file or directory\n", pszPath);
1016 if (RT_SUCCESS(rc))
1017 rc = VERR_FILE_NOT_FOUND;
1018 /* Do not break here -- process every element in the list
1019 * and keep failing rc. */
1020 }
1021
1022 } while ((ch = RTGetOpt(&GetState, &ValueUnion)) != 0);
1023
1024 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) /* Output termination. */
1025 vgsvcToolboxPrintStrmTermination();
1026
1027 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
1028}
1029
1030
1031/* Try using RTPathRmCmd. */
1032static RTEXITCODE vgsvcToolboxRm(int argc, char **argv)
1033{
1034 return RTPathRmCmd(argc, argv);
1035}
1036
1037
1038static char g_paszMkTempHelp[] =
1039 " VBoxService [--use-toolbox] vbox_mktemp [<general options>] [<options>]\n"
1040 " <template>\n\n"
1041 "Create a temporary directory based on the template supplied. The first string\n"
1042 "of consecutive 'X' characters in the template will be replaced to form a unique\n"
1043 "name for the directory. The template may not contain a path. The default\n"
1044 "creation mode is 0600 for files and 0700 for directories. If no path is\n"
1045 "specified the default temporary directory will be used.\n"
1046 "Options:\n\n"
1047 " [--directory|-d] Create a directory instead of a file.\n"
1048 " [--mode|-m <mode>] Create the object with mode <mode>.\n"
1049 " [--secure|-s] Fail if the object cannot be created securely.\n"
1050 " [--tmpdir|-t <path>] Create the object with the absolute path <path>.\n"
1051 "\n";
1052
1053
1054/**
1055 * Report the result of a vbox_mktemp operation.
1056 *
1057 * Either errors to stderr (not machine-readable) or everything to stdout as
1058 * {name}\0{rc}\0 (machine- readable format). The message may optionally
1059 * contain a '%s' for the file name and an %Rrc for the result code in that
1060 * order. In future a "verbose" flag may be added, without which nothing will
1061 * be output in non-machine- readable mode. Sets prc if rc is a non-success
1062 * code.
1063 */
1064static void toolboxMkTempReport(const char *pcszMessage, const char *pcszFile,
1065 bool fActive, int rc, uint32_t fOutputFlags, int *prc)
1066{
1067 if (!fActive)
1068 return;
1069 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE))
1070 if (RT_SUCCESS(rc))
1071 RTPrintf(pcszMessage, pcszFile, rc);
1072 else
1073 RTMsgError(pcszMessage, pcszFile, rc);
1074 else
1075 RTPrintf("name=%s%crc=%d%c", pcszFile, 0, rc, 0);
1076 if (prc && RT_FAILURE(rc))
1077 *prc = rc;
1078}
1079
1080
1081/**
1082 * Main function for tool "vbox_mktemp".
1083 *
1084 * @return RTEXITCODE.
1085 * @param argc Number of arguments.
1086 * @param argv Pointer to argument array.
1087 */
1088static RTEXITCODE vgsvcToolboxMkTemp(int argc, char **argv)
1089{
1090 static const RTGETOPTDEF s_aOptions[] =
1091 {
1092 { "--machinereadable", VBOXSERVICETOOLBOXOPT_MACHINE_READABLE,
1093 RTGETOPT_REQ_NOTHING },
1094 { "--directory", 'd', RTGETOPT_REQ_NOTHING },
1095 { "--mode", 'm', RTGETOPT_REQ_STRING },
1096 { "--secure", 's', RTGETOPT_REQ_NOTHING },
1097 { "--tmpdir", 't', RTGETOPT_REQ_STRING },
1098 };
1099
1100 enum
1101 {
1102 /* Isn't that a bit long? s/VBOXSERVICETOOLBOX/VSTB/ ? */
1103 /** Create a temporary directory instead of a temporary file. */
1104 VBOXSERVICETOOLBOXMKTEMPFLAG_DIRECTORY = RT_BIT_32(0),
1105 /** Only create the temporary object if the operation is expected
1106 * to be secure. Not guaranteed to be supported on a particular
1107 * set-up. */
1108 VBOXSERVICETOOLBOXMKTEMPFLAG_SECURE = RT_BIT_32(1)
1109 };
1110
1111 int ch, rc;
1112 RTGETOPTUNION ValueUnion;
1113 RTGETOPTSTATE GetState;
1114 rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1 /*iFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST);
1115 AssertRCReturn(rc, RTEXITCODE_INIT);
1116
1117 uint32_t fFlags = 0;
1118 uint32_t fOutputFlags = 0;
1119 int cNonOptions = 0;
1120 RTFMODE fMode = 0700;
1121 bool fModeSet = false;
1122 const char *pcszPath = NULL;
1123 const char *pcszTemplate;
1124 char szTemplateWithPath[RTPATH_MAX] = "";
1125
1126 while ( (ch = RTGetOpt(&GetState, &ValueUnion))
1127 && RT_SUCCESS(rc))
1128 {
1129 /* For options that require an argument, ValueUnion has received the value. */
1130 switch (ch)
1131 {
1132 case 'h':
1133 vgsvcToolboxShowUsageHeader();
1134 RTPrintf("%s", g_paszMkTempHelp);
1135 return RTEXITCODE_SUCCESS;
1136
1137 case 'V':
1138 vgsvcToolboxShowVersion();
1139 return RTEXITCODE_SUCCESS;
1140
1141 case VBOXSERVICETOOLBOXOPT_MACHINE_READABLE:
1142 fOutputFlags |= VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE;
1143 break;
1144
1145 case 'd':
1146 fFlags |= VBOXSERVICETOOLBOXMKTEMPFLAG_DIRECTORY;
1147 break;
1148
1149 case 'm':
1150 rc = vgsvcToolboxParseMode(ValueUnion.psz, &fMode);
1151 if (RT_FAILURE(rc))
1152 return RTEXITCODE_SYNTAX;
1153 fModeSet = true;
1154#ifndef RT_OS_WINDOWS
1155 umask(0); /* RTDirCreate workaround */
1156#endif
1157 break;
1158 case 's':
1159 fFlags |= VBOXSERVICETOOLBOXMKTEMPFLAG_SECURE;
1160 break;
1161
1162 case 't':
1163 pcszPath = ValueUnion.psz;
1164 break;
1165
1166 case VINF_GETOPT_NOT_OPTION:
1167 /* RTGetOpt will sort these to the end of the argv vector so
1168 * that we will deal with them afterwards. */
1169 ++cNonOptions;
1170 break;
1171
1172 default:
1173 return RTGetOptPrintError(ch, &ValueUnion);
1174 }
1175 }
1176
1177 /* Print magic/version. */
1178 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)
1179 {
1180 rc = vgsvcToolboxStrmInit();
1181 if (RT_FAILURE(rc))
1182 RTMsgError("Error while initializing parseable streams, rc=%Rrc\n", rc);
1183 vgsvcToolboxPrintStrmHeader("vbt_mktemp", 1 /* Stream version */);
1184 }
1185
1186 if (fFlags & VBOXSERVICETOOLBOXMKTEMPFLAG_SECURE && fModeSet)
1187 {
1188 toolboxMkTempReport("'-s' and '-m' parameters cannot be used together.\n", "",
1189 true, VERR_INVALID_PARAMETER, fOutputFlags, &rc);
1190 return RTEXITCODE_SYNTAX;
1191 }
1192
1193 /* We need exactly one template, containing at least one 'X'. */
1194 if (cNonOptions != 1)
1195 {
1196 toolboxMkTempReport("Please specify exactly one template.\n", "", true, VERR_INVALID_PARAMETER, fOutputFlags, &rc);
1197 return RTEXITCODE_SYNTAX;
1198 }
1199 pcszTemplate = argv[argc - 1];
1200
1201 /* Validate that the template is as IPRT requires (asserted by IPRT). */
1202 if ( RTPathHasPath(pcszTemplate)
1203 || ( !strstr(pcszTemplate, "XXX")
1204 && pcszTemplate[strlen(pcszTemplate) - 1] != 'X'))
1205 {
1206 toolboxMkTempReport("Template '%s' should contain a file name with no path and at least three consecutive 'X' characters or ending in 'X'.\n",
1207 pcszTemplate, true, VERR_INVALID_PARAMETER, fOutputFlags, &rc);
1208 return RTEXITCODE_FAILURE;
1209 }
1210 if (pcszPath && !RTPathStartsWithRoot(pcszPath))
1211 {
1212 toolboxMkTempReport("Path '%s' should be absolute.\n", pcszPath, true, VERR_INVALID_PARAMETER, fOutputFlags, &rc);
1213 return RTEXITCODE_FAILURE;
1214 }
1215 if (pcszPath)
1216 {
1217 rc = RTStrCopy(szTemplateWithPath, sizeof(szTemplateWithPath), pcszPath);
1218 if (RT_FAILURE(rc))
1219 {
1220 toolboxMkTempReport("Path '%s' too long.\n", pcszPath, true, VERR_INVALID_PARAMETER, fOutputFlags, &rc);
1221 return RTEXITCODE_FAILURE;
1222 }
1223 }
1224 else
1225 {
1226 rc = RTPathTemp(szTemplateWithPath, sizeof(szTemplateWithPath));
1227 if (RT_FAILURE(rc))
1228 {
1229 toolboxMkTempReport("Failed to get the temporary directory.\n", "", true, VERR_INVALID_PARAMETER, fOutputFlags, &rc);
1230 return RTEXITCODE_FAILURE;
1231 }
1232 }
1233 rc = RTPathAppend(szTemplateWithPath, sizeof(szTemplateWithPath), pcszTemplate);
1234 if (RT_FAILURE(rc))
1235 {
1236 toolboxMkTempReport("Template '%s' too long for path.\n", pcszTemplate, true, VERR_INVALID_PARAMETER, fOutputFlags, &rc);
1237 return RTEXITCODE_FAILURE;
1238 }
1239
1240 if (fFlags & VBOXSERVICETOOLBOXMKTEMPFLAG_DIRECTORY)
1241 {
1242 rc = fFlags & VBOXSERVICETOOLBOXMKTEMPFLAG_SECURE
1243 ? RTDirCreateTempSecure(szTemplateWithPath)
1244 : RTDirCreateTemp(szTemplateWithPath, fMode);
1245 toolboxMkTempReport("Created temporary directory '%s'.\n",
1246 szTemplateWithPath, RT_SUCCESS(rc), rc,
1247 fOutputFlags, NULL);
1248 /* RTDirCreateTemp[Secure] sets the template to "" on failure. */
1249 toolboxMkTempReport("The following error occurred while creating a temporary directory from template '%s': %Rrc.\n",
1250 pcszTemplate, RT_FAILURE(rc), rc, fOutputFlags, NULL /*prc*/);
1251 }
1252 else
1253 {
1254 rc = fFlags & VBOXSERVICETOOLBOXMKTEMPFLAG_SECURE
1255 ? RTFileCreateTempSecure(szTemplateWithPath)
1256 : RTFileCreateTemp(szTemplateWithPath, fMode);
1257 toolboxMkTempReport("Created temporary file '%s'.\n",
1258 szTemplateWithPath, RT_SUCCESS(rc), rc,
1259 fOutputFlags, NULL);
1260 /* RTFileCreateTemp[Secure] sets the template to "" on failure. */
1261 toolboxMkTempReport("The following error occurred while creating a temporary file from template '%s': %Rrc.\n",
1262 pcszTemplate, RT_FAILURE(rc), rc, fOutputFlags, NULL /*prc*/);
1263 }
1264 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) /* Output termination. */
1265 vgsvcToolboxPrintStrmTermination();
1266 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
1267}
1268
1269
1270/** @todo Document options! */
1271static char g_paszMkDirHelp[] =
1272 " VBoxService [--use-toolbox] vbox_mkdir [<general options>] [<options>]\n"
1273 " <directory>...\n\n"
1274 "Options:\n\n"
1275 " [--mode|-m <mode>] The file mode to set (chmod) on the created\n"
1276 " directories. Default: a=rwx & umask.\n"
1277 " [--parents|-p] Create parent directories as needed, no\n"
1278 " error if the directory already exists.\n"
1279 " [--verbose|-v] Display a message for each created directory.\n"
1280 "\n";
1281
1282
1283/**
1284 * Main function for tool "vbox_mkdir".
1285 *
1286 * @return RTEXITCODE.
1287 * @param argc Number of arguments.
1288 * @param argv Pointer to argument array.
1289 */
1290static RTEXITCODE vgsvcToolboxMkDir(int argc, char **argv)
1291{
1292 static const RTGETOPTDEF s_aOptions[] =
1293 {
1294 { "--mode", 'm', RTGETOPT_REQ_STRING },
1295 { "--parents", 'p', RTGETOPT_REQ_NOTHING},
1296 { "--verbose", 'v', RTGETOPT_REQ_NOTHING}
1297 };
1298
1299 int ch;
1300 RTGETOPTUNION ValueUnion;
1301 RTGETOPTSTATE GetState;
1302 int rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions),
1303 1 /*iFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST);
1304 AssertRCReturn(rc, RTEXITCODE_INIT);
1305
1306 bool fMakeParentDirs = false;
1307 bool fVerbose = false;
1308 RTFMODE fDirMode = RTFS_UNIX_IRWXU | RTFS_UNIX_IRWXG | RTFS_UNIX_IRWXO;
1309 int cDirsCreated = 0;
1310
1311 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
1312 {
1313 /* For options that require an argument, ValueUnion has received the value. */
1314 switch (ch)
1315 {
1316 case 'p':
1317 fMakeParentDirs = true;
1318 break;
1319
1320 case 'm':
1321 rc = vgsvcToolboxParseMode(ValueUnion.psz, &fDirMode);
1322 if (RT_FAILURE(rc))
1323 return RTEXITCODE_SYNTAX;
1324#ifndef RT_OS_WINDOWS
1325 umask(0); /* RTDirCreate workaround */
1326#endif
1327 break;
1328
1329 case 'v':
1330 fVerbose = true;
1331 break;
1332
1333 case 'h':
1334 vgsvcToolboxShowUsageHeader();
1335 RTPrintf("%s", g_paszMkDirHelp);
1336 return RTEXITCODE_SUCCESS;
1337
1338 case 'V':
1339 vgsvcToolboxShowVersion();
1340 return RTEXITCODE_SUCCESS;
1341
1342 case VINF_GETOPT_NOT_OPTION:
1343 if (fMakeParentDirs)
1344 /** @todo r=bird: If fVerbose is set, we should also show
1345 * which directories that get created, parents as well as
1346 * omitting existing final dirs. Annoying, but check any
1347 * mkdir implementation (try "mkdir -pv asdf/1/2/3/4"
1348 * twice). */
1349 rc = RTDirCreateFullPath(ValueUnion.psz, fDirMode);
1350 else
1351 rc = RTDirCreate(ValueUnion.psz, fDirMode, 0);
1352 if (RT_FAILURE(rc))
1353 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Could not create directory '%s': %Rra\n",
1354 ValueUnion.psz, rc);
1355 if (fVerbose)
1356 RTMsgInfo("Created directory '%s', mode %#RTfmode\n", ValueUnion.psz, fDirMode);
1357 cDirsCreated++;
1358 break;
1359
1360 default:
1361 return RTGetOptPrintError(ch, &ValueUnion);
1362 }
1363 }
1364 AssertRC(rc);
1365
1366 if (cDirsCreated == 0)
1367 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "No directory argument.");
1368
1369 return RTEXITCODE_SUCCESS;
1370}
1371
1372
1373/** @todo Document options! */
1374static char g_paszStatHelp[] =
1375 " VBoxService [--use-toolbox] vbox_stat [<general options>] [<options>]\n"
1376 " <file>...\n\n"
1377 "Display file or file system status.\n\n"
1378 "Options:\n\n"
1379 " [--file-system|-f]\n"
1380 " [--dereference|-L]\n"
1381 " [--terse|-t]\n"
1382 " [--verbose|-v]\n"
1383 "\n";
1384
1385
1386/**
1387 * Main function for tool "vbox_stat".
1388 *
1389 * @return RTEXITCODE.
1390 * @param argc Number of arguments.
1391 * @param argv Pointer to argument array.
1392 */
1393static RTEXITCODE vgsvcToolboxStat(int argc, char **argv)
1394{
1395 static const RTGETOPTDEF s_aOptions[] =
1396 {
1397 { "--file-system", 'f', RTGETOPT_REQ_NOTHING },
1398 { "--dereference", 'L', RTGETOPT_REQ_NOTHING },
1399 { "--machinereadable", VBOXSERVICETOOLBOXOPT_MACHINE_READABLE, RTGETOPT_REQ_NOTHING },
1400 { "--terse", 't', RTGETOPT_REQ_NOTHING },
1401 { "--verbose", 'v', RTGETOPT_REQ_NOTHING }
1402 };
1403
1404 int ch;
1405 RTGETOPTUNION ValueUnion;
1406 RTGETOPTSTATE GetState;
1407 RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1 /*iFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST);
1408
1409 int rc = VINF_SUCCESS;
1410 uint32_t fOutputFlags = VBOXSERVICETOOLBOXOUTPUTFLAG_LONG; /* Use long mode by default. */
1411 uint32_t fQueryInfoFlags = RTPATH_F_ON_LINK;
1412
1413 while ( (ch = RTGetOpt(&GetState, &ValueUnion))
1414 && RT_SUCCESS(rc))
1415 {
1416 /* For options that require an argument, ValueUnion has received the value. */
1417 switch (ch)
1418 {
1419 case 'f':
1420 RTMsgError("Sorry, option '%s' is not implemented yet!\n", ValueUnion.pDef->pszLong);
1421 rc = VERR_INVALID_PARAMETER;
1422 break;
1423
1424 case 'L':
1425 fQueryInfoFlags &= ~RTPATH_F_ON_LINK;
1426 fQueryInfoFlags |= RTPATH_F_FOLLOW_LINK;
1427 break;
1428
1429 case VBOXSERVICETOOLBOXOPT_MACHINE_READABLE:
1430 fOutputFlags |= VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE;
1431 break;
1432
1433 case 'h':
1434 vgsvcToolboxShowUsageHeader();
1435 RTPrintf("%s", g_paszStatHelp);
1436 return RTEXITCODE_SUCCESS;
1437
1438 case 'V':
1439 vgsvcToolboxShowVersion();
1440 return RTEXITCODE_SUCCESS;
1441
1442 case VINF_GETOPT_NOT_OPTION:
1443 {
1444 Assert(GetState.iNext);
1445 GetState.iNext--;
1446 break;
1447 }
1448
1449 default:
1450 return RTGetOptPrintError(ch, &ValueUnion);
1451 }
1452
1453 /* All flags / options processed? Bail out here.
1454 * Processing the file / directory list comes down below. */
1455 if (ch == VINF_GETOPT_NOT_OPTION)
1456 break;
1457 }
1458
1459 if (RT_SUCCESS(rc))
1460 {
1461 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) /* Output termination. */
1462 {
1463 rc = vgsvcToolboxStrmInit();
1464 if (RT_FAILURE(rc))
1465 RTMsgError("Error while initializing parseable streams, rc=%Rrc\n", rc);
1466 vgsvcToolboxPrintStrmHeader("vbt_stat", 1 /* Stream version */);
1467 }
1468
1469 VGSVCIDCACHE IdCache;
1470 RT_ZERO(IdCache);
1471
1472 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
1473 {
1474 RTFSOBJINFO objInfo;
1475 int rc2 = RTPathQueryInfoEx(ValueUnion.psz, &objInfo, RTFSOBJATTRADD_UNIX, fQueryInfoFlags);
1476 if (RT_FAILURE(rc2))
1477 {
1478 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE))
1479 RTMsgError("Cannot stat for '%s': %Rrc\n", ValueUnion.psz, rc2);
1480 }
1481 else
1482 rc2 = vgsvcToolboxPrintFsInfo(ValueUnion.psz, strlen(ValueUnion.psz), fOutputFlags, NULL, &IdCache, &objInfo);
1483
1484 if (RT_SUCCESS(rc))
1485 rc = rc2;
1486 /* Do not break here -- process every element in the list
1487 * and keep (initial) failing rc. */
1488 }
1489
1490 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) /* Output termination. */
1491 vgsvcToolboxPrintStrmTermination();
1492
1493 /* At this point the overall result (success/failure) should be in rc. */
1494 }
1495 else
1496 RTMsgError("Failed with rc=%Rrc\n", rc);
1497
1498 if (RT_FAILURE(rc))
1499 {
1500 switch (rc)
1501 {
1502 case VERR_ACCESS_DENIED:
1503 return (RTEXITCODE)VBOXSERVICETOOLBOX_STAT_EXITCODE_ACCESS_DENIED;
1504
1505 case VERR_FILE_NOT_FOUND:
1506 return (RTEXITCODE)VBOXSERVICETOOLBOX_STAT_EXITCODE_FILE_NOT_FOUND;
1507
1508 case VERR_PATH_NOT_FOUND:
1509 return (RTEXITCODE)VBOXSERVICETOOLBOX_STAT_EXITCODE_PATH_NOT_FOUND;
1510
1511 case VERR_NET_PATH_NOT_FOUND:
1512 return (RTEXITCODE)VBOXSERVICETOOLBOX_STAT_EXITCODE_NET_PATH_NOT_FOUND;
1513
1514 case VERR_INVALID_NAME:
1515 return (RTEXITCODE)VBOXSERVICETOOLBOX_STAT_EXITCODE_INVALID_NAME;
1516
1517 default:
1518#ifdef DEBUG_andy
1519 AssertMsgFailed(("Exit code for %Rrc not implemented\n", rc));
1520#endif
1521 break;
1522 }
1523
1524 return RTEXITCODE_FAILURE;
1525 }
1526
1527 return RTEXITCODE_SUCCESS;
1528}
1529
1530
1531/**
1532 * Looks up the tool definition entry for the tool give by @a pszTool.
1533 *
1534 * @returns Pointer to the tool definition. NULL if not found.
1535 * @param pszTool The name of the tool.
1536 */
1537static PCVBOXSERVICETOOLBOXTOOL vgsvcToolboxLookUp(const char *pszTool)
1538{
1539 AssertPtrReturn(pszTool, NULL);
1540
1541 /* Do a linear search, since we don't have that much stuff in the table. */
1542 for (unsigned i = 0; i < RT_ELEMENTS(g_aTools); i++)
1543 if (!strcmp(g_aTools[i].pszName, pszTool))
1544 return &g_aTools[i];
1545
1546 return NULL;
1547}
1548
1549
1550/**
1551 * Converts a tool's exit code back to an IPRT error code.
1552 *
1553 * @return Converted IPRT status code.
1554 * @param pszTool Name of the toolbox tool to convert exit code for.
1555 * @param rcExit The tool's exit code to convert.
1556 */
1557int VGSvcToolboxExitCodeConvertToRc(const char *pszTool, RTEXITCODE rcExit)
1558{
1559 AssertPtrReturn(pszTool, VERR_INVALID_POINTER);
1560
1561 PCVBOXSERVICETOOLBOXTOOL pTool = vgsvcToolboxLookUp(pszTool);
1562 if (pTool)
1563 return pTool->pfnExitCodeConvertToRc(rcExit);
1564
1565 AssertMsgFailed(("Tool '%s' not found\n", pszTool));
1566 return VERR_GENERAL_FAILURE; /* Lookup failed, should not happen. */
1567}
1568
1569
1570/**
1571 * Entry point for internal toolbox.
1572 *
1573 * @return True if an internal tool was handled, false if not.
1574 * @param argc Number of arguments.
1575 * @param argv Pointer to argument array.
1576 * @param prcExit Where to store the exit code when an
1577 * internal toolbox command was handled.
1578 */
1579bool VGSvcToolboxMain(int argc, char **argv, RTEXITCODE *prcExit)
1580{
1581
1582 /*
1583 * Check if the file named in argv[0] is one of the toolbox programs.
1584 */
1585 AssertReturn(argc > 0, false);
1586 const char *pszTool = RTPathFilename(argv[0]);
1587 PCVBOXSERVICETOOLBOXTOOL pTool = vgsvcToolboxLookUp(pszTool);
1588 if (!pTool)
1589 {
1590 /*
1591 * For debugging and testing purposes we also allow toolbox program access
1592 * when the first VBoxService argument is --use-toolbox.
1593 */
1594 if (argc < 2 || strcmp(argv[1], "--use-toolbox"))
1595 {
1596 /* We must match vgsvcGstCtrlProcessCreateProcess here and claim
1597 everything starting with "vbox_". */
1598 if (!RTStrStartsWith(pszTool, "vbox_"))
1599 return false;
1600 RTMsgError("Unknown tool: %s\n", pszTool);
1601 *prcExit = RTEXITCODE_SYNTAX;
1602 return true;
1603 }
1604
1605 /* No tool specified? Show toolbox help. */
1606 if (argc < 3)
1607 {
1608 RTMsgError("No tool following --use-toolbox\n");
1609 *prcExit = RTEXITCODE_SYNTAX;
1610 return true;
1611 }
1612
1613 argc -= 2;
1614 argv += 2;
1615 pszTool = argv[0];
1616 pTool = vgsvcToolboxLookUp(pszTool);
1617 if (!pTool)
1618 {
1619 *prcExit = RTEXITCODE_SUCCESS;
1620 if ( !strcmp(pszTool, "-V")
1621 || !strcmp(pszTool, "version"))
1622 vgsvcToolboxShowVersion();
1623 else if ( !strcmp(pszTool, "help")
1624 || !strcmp(pszTool, "--help")
1625 || !strcmp(pszTool, "-h"))
1626 vgsvcToolboxShowUsage();
1627 else
1628 {
1629 RTMsgError("Unknown tool: %s\n", pszTool);
1630 *prcExit = RTEXITCODE_SYNTAX;
1631 }
1632 return true;
1633 }
1634 }
1635
1636 /*
1637 * Invoke the handler.
1638 */
1639 RTMsgSetProgName("VBoxService/%s", pszTool);
1640 AssertPtr(pTool);
1641 *prcExit = pTool->pfnHandler(argc, argv);
1642
1643 return true;
1644}
1645
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette