|
Hans de Goede |
32e434 |
From 369dd2ee3c82c4417fee04aeec933c74fd198e78 Mon Sep 17 00:00:00 2001
|
|
Hans de Goede |
32e434 |
From: Hans de Goede <hdegoede@redhat.com>
|
|
Hans de Goede |
32e434 |
Date: Tue, 23 Jan 2018 15:09:20 +0100
|
|
Hans de Goede |
32e434 |
Subject: [PATCH resend] VBoxServiceAutoMount: Change Linux mount code to use
|
|
Hans de Goede |
32e434 |
an options string
|
|
Hans de Goede |
32e434 |
|
|
Hans de Goede |
32e434 |
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
|
|
Hans de Goede |
32e434 |
---
|
|
Hans de Goede |
32e434 |
.../common/VBoxService/VBoxServiceAutoMount.cpp | 62 +++-------------------
|
|
Hans de Goede |
32e434 |
1 file changed, 8 insertions(+), 54 deletions(-)
|
|
Hans de Goede |
32e434 |
|
|
Hans de Goede |
32e434 |
diff --git a/src/VBox/Additions/common/VBoxService/VBoxServiceAutoMount.cpp b/src/VBox/Additions/common/VBoxService/VBoxServiceAutoMount.cpp
|
|
|
b22ed6 |
--- ./src/VBox/Additions/common/VBoxService/VBoxServiceAutoMount.cpp.orig 2019-04-16 11:09:11.000000000 +0100
|
|
|
b22ed6 |
+++ ./src/VBox/Additions/common/VBoxService/VBoxServiceAutoMount.cpp 2019-04-26 17:10:47.178485356 +0100
|
|
|
8c7d23 |
@@ -40,6 +40,7 @@
|
|
|
8c7d23 |
#include <iprt/ctype.h>
|
|
Hans de Goede |
32e434 |
#include <iprt/dir.h>
|
|
Hans de Goede |
32e434 |
#include <iprt/mem.h>
|
|
Hans de Goede |
32e434 |
+#include <iprt/param.h>
|
|
Hans de Goede |
32e434 |
#include <iprt/path.h>
|
|
Hans de Goede |
32e434 |
#include <iprt/semaphore.h>
|
|
|
8c7d23 |
#include <iprt/sort.h>
|
|
|
b22ed6 |
@@ -114,6 +115,9 @@ RT_C_DECLS_END
|
|
|
8c7d23 |
# define VBOXSERVICE_AUTOMOUNT_MIQF SHFL_MIQF_PATH
|
|
Hans de Goede |
32e434 |
#endif
|
|
Hans de Goede |
32e434 |
|
|
Hans de Goede |
32e434 |
+#ifndef MAX_MNTOPT_STR
|
|
Hans de Goede |
32e434 |
+#define MAX_MNTOPT_STR PAGE_SIZE
|
|
Hans de Goede |
32e434 |
+#endif
|
|
Hans de Goede |
32e434 |
|
|
Hans de Goede |
32e434 |
/*********************************************************************************************************************************
|
|
|
8c7d23 |
* Structures and Typedefs *
|
|
|
b22ed6 |
@@ -400,13 +399,13 @@ static int vbsvcAutoMountSharedFolderOld
|
|
|
8c7d23 |
int rc = vbsvcAutoMountPrepareMountPointOld(pszMountPoint, pszShareName, &Opts);
|
|
|
8c7d23 |
if (RT_SUCCESS(rc))
|
|
Hans de Goede |
32e434 |
{
|
|
|
8c7d23 |
+ char szOptBuf[MAX_MNTOPT_STR] = { '\0', };
|
|
Hans de Goede |
32e434 |
+ RTStrPrintf(szOptBuf, sizeof(szOptBuf), "uid=%d,gid=%d,dmode=%0o,fmode=%0o,dmask=%0o,fmask=%0o",
|
|
|
8c7d23 |
+ Opts.uid, Opts.gid, Opts.dmode, Opts.fmode, Opts.dmask, Opts.fmask);
|
|
|
8c7d23 |
# ifdef RT_OS_SOLARIS
|
|
Hans de Goede |
32e434 |
int fFlags = 0;
|
|
|
8c7d23 |
if (Opts.ronly)
|
|
Hans de Goede |
32e434 |
fFlags |= MS_RDONLY;
|
|
|
8c7d23 |
- char szOptBuf[MAX_MNTOPT_STR] = { '\0', };
|
|
Hans de Goede |
32e434 |
- RTStrPrintf(szOptBuf, sizeof(szOptBuf), "uid=%d,gid=%d,dmode=%0o,fmode=%0o,dmask=%0o,fmask=%0o",
|
|
|
8c7d23 |
- Opts.uid, Opts.gid, Opts.dmode, Opts.fmode, Opts.dmask, Opts.fmask);
|
|
Hans de Goede |
32e434 |
int r = mount(pszShareName,
|
|
Hans de Goede |
32e434 |
pszMountPoint,
|
|
Hans de Goede |
32e434 |
fFlags | MS_OPTIONSTR,
|
|
|
b22ed6 |
@@ -423,35 +422,11 @@ static int vbsvcAutoMountSharedFolderOld
|
|
Hans de Goede |
32e434 |
|
|
|
8c7d23 |
# else /* RT_OS_LINUX */
|
|
Hans de Goede |
32e434 |
unsigned long fFlags = MS_NODEV;
|
|
Hans de Goede |
32e434 |
-
|
|
Hans de Goede |
32e434 |
- /*const char *szOptions = { "rw" }; - ??? */
|
|
Hans de Goede |
32e434 |
- struct vbsf_mount_info_new mntinf;
|
|
|
8c7d23 |
- RT_ZERO(mntinf);
|
|
Hans de Goede |
32e434 |
-
|
|
Hans de Goede |
32e434 |
- mntinf.nullchar = '\0';
|
|
Hans de Goede |
32e434 |
- mntinf.signature[0] = VBSF_MOUNT_SIGNATURE_BYTE_0;
|
|
Hans de Goede |
32e434 |
- mntinf.signature[1] = VBSF_MOUNT_SIGNATURE_BYTE_1;
|
|
Hans de Goede |
32e434 |
- mntinf.signature[2] = VBSF_MOUNT_SIGNATURE_BYTE_2;
|
|
Hans de Goede |
32e434 |
- mntinf.length = sizeof(mntinf);
|
|
Hans de Goede |
32e434 |
-
|
|
|
8c7d23 |
- mntinf.uid = Opts.uid;
|
|
|
8c7d23 |
- mntinf.gid = Opts.gid;
|
|
|
8c7d23 |
- mntinf.ttl = Opts.ttl;
|
|
|
8c7d23 |
- mntinf.dmode = Opts.dmode;
|
|
|
8c7d23 |
- mntinf.fmode = Opts.fmode;
|
|
|
8c7d23 |
- mntinf.dmask = Opts.dmask;
|
|
|
8c7d23 |
- mntinf.fmask = Opts.fmask;
|
|
|
b22ed6 |
- mntinf.cMaxIoPages = Opts.cMaxIoPages;
|
|
|
b22ed6 |
- mntinf.szTag[0] = '\0';
|
|
Hans de Goede |
32e434 |
-
|
|
Hans de Goede |
32e434 |
- strcpy(mntinf.name, pszShareName);
|
|
Hans de Goede |
32e434 |
- strcpy(mntinf.nls_name, "\0");
|
|
Hans de Goede |
32e434 |
-
|
|
Hans de Goede |
32e434 |
int r = mount(pszShareName,
|
|
Hans de Goede |
32e434 |
pszMountPoint,
|
|
Hans de Goede |
32e434 |
"vboxsf",
|
|
Hans de Goede |
32e434 |
fFlags,
|
|
Hans de Goede |
32e434 |
- &mntinf);
|
|
Hans de Goede |
32e434 |
+ szOptBuf);
|
|
Hans de Goede |
32e434 |
if (r == 0)
|
|
Hans de Goede |
32e434 |
{
|
|
Hans de Goede |
32e434 |
VGSvcVerbose(0, "vbsvcAutoMountWorker: Shared folder '%s' was mounted to '%s'\n", pszShareName, pszMountPoint);
|
|
|
b22ed6 |
@@ -484,34 +459,6 @@ static int vbsvcAutoMountSharedFolderOld
|
|
Hans de Goede |
32e434 |
}
|
|
Hans de Goede |
32e434 |
else /* r == -1, we got some error in errno. */
|
|
Hans de Goede |
32e434 |
{
|
|
Hans de Goede |
32e434 |
- if (errno == EPROTO)
|
|
Hans de Goede |
32e434 |
- {
|
|
Hans de Goede |
32e434 |
- VGSvcVerbose(3, "vbsvcAutoMountWorker: Messed up share name, re-trying ...\n");
|
|
Hans de Goede |
32e434 |
-
|
|
Hans de Goede |
32e434 |
- /** @todo r=bird: What on earth is going on here????? Why can't you
|
|
Hans de Goede |
32e434 |
- * strcpy(mntinf.name, pszShareName) to fix it again? */
|
|
Hans de Goede |
32e434 |
-
|
|
Hans de Goede |
32e434 |
- /* Sometimes the mount utility messes up the share name. Try to
|
|
Hans de Goede |
32e434 |
- * un-mangle it again. */
|
|
Hans de Goede |
32e434 |
- char szCWD[RTPATH_MAX];
|
|
Hans de Goede |
32e434 |
- size_t cchCWD;
|
|
Hans de Goede |
32e434 |
- if (!getcwd(szCWD, sizeof(szCWD)))
|
|
Hans de Goede |
32e434 |
- {
|
|
Hans de Goede |
32e434 |
- VGSvcError("vbsvcAutoMountWorker: Failed to get the current working directory\n");
|
|
Hans de Goede |
32e434 |
- szCWD[0] = '\0';
|
|
Hans de Goede |
32e434 |
- }
|
|
Hans de Goede |
32e434 |
- cchCWD = strlen(szCWD);
|
|
Hans de Goede |
32e434 |
- if (!strncmp(pszMountPoint, szCWD, cchCWD))
|
|
Hans de Goede |
32e434 |
- {
|
|
Hans de Goede |
32e434 |
- while (pszMountPoint[cchCWD] == '/')
|
|
Hans de Goede |
32e434 |
- ++cchCWD;
|
|
Hans de Goede |
32e434 |
- /* We checked before that we have enough space */
|
|
Hans de Goede |
32e434 |
- strcpy(mntinf.name, pszMountPoint + cchCWD);
|
|
Hans de Goede |
32e434 |
- }
|
|
Hans de Goede |
32e434 |
- r = mount(mntinf.name, pszMountPoint, "vboxsf", fFlags, &mntinf);
|
|
Hans de Goede |
32e434 |
- }
|
|
Hans de Goede |
32e434 |
- if (r == -1) /* Was there some error from one of the tries above? */
|
|
Hans de Goede |
32e434 |
- {
|
|
Hans de Goede |
32e434 |
switch (errno)
|
|
Hans de Goede |
32e434 |
{
|
|
Hans de Goede |
32e434 |
/* If we get EINVAL here, the system already has mounted the Shared Folder to another
|
|
|
b22ed6 |
@@ -530,7 +477,6 @@ static int vbsvcAutoMountSharedFolderOld
|
|
Hans de Goede |
32e434 |
rc = RTErrConvertFromErrno(errno);
|
|
Hans de Goede |
32e434 |
break;
|
|
Hans de Goede |
32e434 |
}
|
|
Hans de Goede |
32e434 |
- }
|
|
Hans de Goede |
32e434 |
}
|
|
|
8c7d23 |
# endif
|
|
|
8c7d23 |
}
|
|
|
b22ed6 |
@@ -1464,51 +1410,21 @@ static int vbsvcAutomounterMountIt(PVBSV
|
|
Hans de Goede |
cfa360 |
}
|
|
Hans de Goede |
cfa360 |
|
|
Hans de Goede |
cfa360 |
# if defined(RT_OS_LINUX)
|
|
Hans de Goede |
cfa360 |
- /*
|
|
Hans de Goede |
cfa360 |
- * Linux a bit more work...
|
|
Hans de Goede |
cfa360 |
- */
|
|
Hans de Goede |
cfa360 |
- struct vbsf_mount_info_new MntInfo;
|
|
Hans de Goede |
cfa360 |
- RT_ZERO(MntInfo);
|
|
Hans de Goede |
cfa360 |
- struct vbsf_mount_opts MntOpts;
|
|
Hans de Goede |
cfa360 |
- RT_ZERO(MntOpts);
|
|
Hans de Goede |
cfa360 |
- MntInfo.nullchar = '\0';
|
|
Hans de Goede |
cfa360 |
- MntInfo.signature[0] = VBSF_MOUNT_SIGNATURE_BYTE_0;
|
|
Hans de Goede |
cfa360 |
- MntInfo.signature[1] = VBSF_MOUNT_SIGNATURE_BYTE_1;
|
|
Hans de Goede |
cfa360 |
- MntInfo.signature[2] = VBSF_MOUNT_SIGNATURE_BYTE_2;
|
|
Hans de Goede |
cfa360 |
- MntInfo.length = sizeof(MntInfo);
|
|
|
b22ed6 |
- MntInfo.ttl = MntOpts.uid = -1 /*default*/;
|
|
|
b22ed6 |
- MntInfo.msDirCacheTTL= MntOpts.msDirCacheTTL = -1 /*default*/;
|
|
|
b22ed6 |
- MntInfo.msInodeTTL = MntOpts.msInodeTTL = -1 /*default*/;
|
|
|
b22ed6 |
- MntInfo.cMaxIoPages = MntOpts.cMaxIoPages = 0 /*default*/;
|
|
|
b22ed6 |
- MntInfo.cbDirBuf = MntOpts.cbDirBuf = 0 /*default*/;
|
|
|
b22ed6 |
- MntInfo.enmCacheMode = MntOpts.enmCacheMode = kVbsfCacheMode_Default;
|
|
Hans de Goede |
cfa360 |
- MntInfo.uid = MntOpts.uid = 0;
|
|
Hans de Goede |
cfa360 |
- MntInfo.gid = MntOpts.gid = gidMount;
|
|
Hans de Goede |
cfa360 |
- MntInfo.dmode = MntOpts.dmode = 0770;
|
|
Hans de Goede |
cfa360 |
- MntInfo.fmode = MntOpts.fmode = 0770;
|
|
Hans de Goede |
cfa360 |
- MntInfo.dmask = MntOpts.dmask = 0000;
|
|
Hans de Goede |
cfa360 |
- MntInfo.fmask = MntOpts.fmask = 0000;
|
|
|
b22ed6 |
- memcpy(MntInfo.szTag, g_szTag, sizeof(g_szTag)); AssertCompile(sizeof(MntInfo.szTag) >= sizeof(g_szTag));
|
|
Hans de Goede |
cfa360 |
- rc = RTStrCopy(MntInfo.name, sizeof(MntInfo.name), pEntry->pszName);
|
|
Hans de Goede |
cfa360 |
- if (RT_FAILURE(rc))
|
|
Hans de Goede |
cfa360 |
+ unsigned long fFlags = MS_NODEV;
|
|
Hans de Goede |
cfa360 |
+ char szOpts[MAX_MNTOPT_STR] = { '\0', };
|
|
Hans de Goede |
cfa360 |
+ ssize_t cchOpts = RTStrPrintf2(szOpts, sizeof(szOpts),
|
|
Hans de Goede |
cfa360 |
+ "uid=0,gid=%d,dmode=0770,fmode=0770,dmask=0000,fmask=0000", gidMount);
|
|
Hans de Goede |
cfa360 |
+ if (cchOpts <= 0)
|
|
Hans de Goede |
cfa360 |
{
|
|
Hans de Goede |
cfa360 |
- VGSvcError("vbsvcAutomounterMountIt: Share name '%s' is too long for the MntInfo.name field!\n", pEntry->pszName);
|
|
Hans de Goede |
cfa360 |
- return rc;
|
|
Hans de Goede |
cfa360 |
+ VGSvcError("vbsvcAutomounterMountIt: szOpts overflow! %zd\n", cchOpts);
|
|
Hans de Goede |
cfa360 |
+ return VERR_BUFFER_OVERFLOW;
|
|
Hans de Goede |
cfa360 |
}
|
|
Hans de Goede |
cfa360 |
|
|
Hans de Goede |
cfa360 |
- errno = 0;
|
|
Hans de Goede |
cfa360 |
- unsigned long fFlags = MS_NODEV;
|
|
Hans de Goede |
cfa360 |
- rc = mount(pEntry->pszName, pEntry->pszActualMountPoint, "vboxsf", fFlags, &MntInfo);
|
|
Hans de Goede |
cfa360 |
+ rc = mount(pEntry->pszName, pEntry->pszActualMountPoint, "vboxsf", fFlags, szOpts);
|
|
Hans de Goede |
cfa360 |
if (rc == 0)
|
|
Hans de Goede |
cfa360 |
{
|
|
Hans de Goede |
cfa360 |
VGSvcVerbose(0, "vbsvcAutomounterMountIt: Successfully mounted '%s' on '%s'\n",
|
|
Hans de Goede |
cfa360 |
pEntry->pszName, pEntry->pszActualMountPoint);
|
|
Hans de Goede |
cfa360 |
-
|
|
Hans de Goede |
cfa360 |
- errno = 0;
|
|
Hans de Goede |
cfa360 |
- rc = vbsfmount_complete(pEntry->pszName, pEntry->pszActualMountPoint, fFlags, &MntOpts);
|
|
Hans de Goede |
cfa360 |
- if (rc != 0) /* Ignorable. /etc/mtab is probably a link to /proc/mounts. */
|
|
Hans de Goede |
cfa360 |
- VGSvcVerbose(1, "vbsvcAutomounterMountIt: vbsfmount_complete failed: %s (%d/%d)\n",
|
|
Hans de Goede |
cfa360 |
- rc == 1 ? "open_memstream" : rc == 2 ? "setmntent" : rc == 3 ? "addmntent" : "unknown", rc, errno);
|
|
Hans de Goede |
cfa360 |
return VINF_SUCCESS;
|
|
Hans de Goede |
cfa360 |
}
|
|
Hans de Goede |
cfa360 |
else if (errno == EINVAL)
|