VirtualBox

Ignore:
Timestamp:
Nov 6, 2018 4:15:09 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
126398
Message:

add/darwin/VBoxSF: More renaming, header separation and cleaning up.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/darwin/VBoxSF/mount.vboxsf.cpp

    r75292 r75293  
    11/* $Id$ */
    22/** @file
    3  * VBoxVFS - mount tool.
     3 * VBoxSF - Darwin Shared Folders, Mount Utility.
    44 */
    55
    66/*
    7  * Copyright (C) 2013-2017 Oracle Corporation
     7 * Copyright (C) 2013-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
     18
     19/*********************************************************************************************************************************
     20*   Header Files                                                                                                                 *
     21*********************************************************************************************************************************/
     22#include <errno.h>
    1823#include <stdio.h>
     24#include <stdlib.h>
    1925#include <unistd.h>
    20 #include <stdlib.h>
    2126#include <sys/mount.h>
    22 #include <errno.h>
    23 #include <string.h>
    2427
    25 #include "vboxvfs.h"
     28#include "VBoxSFMount.h"
     29#include <iprt/string.h>
    2630
    27 static char *progname;
    2831
    29 static void
    30 usage(void)
     32static RTEXITCODE usage(const char *pszArg0)
    3133{
    32     fprintf(stderr, "usage: %s [OPTIONS] <shared folder name> "
    33                     "<mount point>\n", progname);
    34     exit(1);
     34    fprintf(stderr, "usage: %s [OPTIONS] <shared folder name> <mount point>\n", pszArg0);
     35    return RTEXITCODE_SYNTAX;
    3536}
    3637
    37 int
    38 main(int argc, char *argv[])
     38
     39int main(int argc, char **argv)
    3940{
    40     int                         rc;
    41     int                         c;
    42     char                       *sShareName;
    43     char                       *sMountPoint;
    44     struct vboxvfs_mount_info   mnt_info;
    45 
    46     /* Set program name */
    47     progname = argv[0];
    48 
    49     /* Parse command line */
    50     while((c = getopt(argc, argv, "o:")) != -1)
     41    /*
     42     * Skip past parameters.
     43     */
     44    int c;
     45    while ((c = getopt(argc, argv, "o:")) != -1)
    5146    {
    52         switch(c)
     47        switch (c)
    5348        {
    54             case 'o': break;
    55             default : usage();
     49            case 'o':
     50                break;
     51            default:
     52                return usage(argv[0]);
    5653        }
    5754    }
    5855
    5956    /* Two arguments are rquired: <share name> and <mount point> */
    60     if ((argc - optind) != 2)
    61         usage();
     57    if (argc - optind != 2)
     58        return usage(argv[0]);
     59    const char * const pszFolder     = argv[optind++];
     60    const char * const pszMountPoint = argv[optind];
    6261
    63     sShareName = argv[optind++];
    64     sMountPoint = argv[optind];
    65 
    66     if (strlen(sShareName) > MAXPATHLEN)
     62    /*
     63     * Check that the folder is within bounds and doesn't include any shady characters.
     64     */
     65    size_t cchFolder = strlen(pszFolder);
     66    if (   cchFolder < 1
     67        || cchFolder >= RT_SIZEOFMEMB(VBOXSFDRWNMOUNTINFO, szFolder)
     68        || strpbrk(pszFolder, "\\/") != NULL)
    6769    {
    68         fprintf(stderr, "Specified Shared Folder name too long\n");
    69         return EINVAL;
     70        fprintf(stderr, "Invalid shared folder name '%s'!\n", pszFolder);
     71        return RTEXITCODE_FAILURE;
    7072    }
    7173
    72     mnt_info.magic = VBOXVFS_MOUNTINFO_MAGIC;
    73     strcpy(mnt_info.name, sShareName);
     74    /*
     75     * Do the mounting.
     76     */
     77    VBOXSFDRWNMOUNTINFO MntInfo;
     78    RT_ZERO(MntInfo);
     79    MntInfo.u32Magic = VBOXSFDRWNMOUNTINFO_MAGIC;
     80    memcpy(MntInfo.szFolder, pszFolder, cchFolder);
     81    int rc = mount(VBOXSF_DARWIN_FS_NAME, pszMountPoint, 0, &MntInfo);
     82    if (rc == 0)
     83        return 0;
    7484
    75     rc = mount(VBOXVBFS_NAME, sMountPoint, 0, &mnt_info);
    76     if (rc)
    77     {
    78         fprintf(stderr,
    79                 "Unable to mount shared folder (%s) '%s' to '%s': %s\n",
    80                 VBOXVBFS_NAME,
    81                 mnt_info.name,
    82                 sMountPoint,
    83                 strerror(errno));
    84         return 1;
    85     }
    86 
    87     return 0;
     85    fprintf(stderr, "error mounting '%s' at '%s': %s (%d)\n", pszFolder, pszMountPoint, strerror(errno), errno);
     86    return RTEXITCODE_FAILURE;
    8887}
Note: See TracChangeset for help on using the changeset viewer.

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