Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch for 2010.06.16-268169 #5

Open
wants to merge 1 commit into
base: origin-2010.06.16-268169-1733592974
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
255 changes: 0 additions & 255 deletions open-vm-tools/vmware-user-suid-wrapper/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,15 @@
#endif

#include <sys/param.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/stat.h>

#if defined(sun)
# include <sys/systeminfo.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>

#include "vmware.h"
#include "vmblock.h"
Expand All @@ -63,14 +57,6 @@ VM_EMBED_VERSION(WRAPPER_VERSION_STRING);
* Local functions (prototypes)
*/

#ifdef TOGGLE_VMBLOCK
static void ToggleVMBlock(void);
static Bool StartVMBlock(void);
static Bool StopVMBlock(void);
static Bool MakeDirectory(const char *path, mode_t mode, uid_t uid, gid_t gid);
static Bool ChmodChownDirectory(const char *path,
mode_t mode, uid_t uid, gid_t gid);
#endif
static void MaskSignals(void);
static Bool StartVMwareUser(char *const envp[]);

Expand Down Expand Up @@ -110,10 +96,6 @@ main(int argc,
{
MaskSignals();

#ifdef TOGGLE_VMBLOCK
ToggleVMBlock();
#endif

if (!StartVMwareUser(envp)) {
Error("failed to start vmware-user\n");
exit(EXIT_FAILURE);
Expand All @@ -128,243 +110,6 @@ main(int argc,
*/


#ifdef TOGGLE_VMBLOCK
/*
*----------------------------------------------------------------------------
*
* ToggleVMBlock --
*
* Unmounts vmblock and unloads the module, then reloads the module and
* remounts the file system.
*
* Results:
* Vmblock file system "service" is reloaded.
*
* Side effects:
* May exit with EXIT_FAILURE if the vmblock service cannot be stopped.
*
*----------------------------------------------------------------------------
*/

static void
ToggleVMBlock(void)
{
if (!StopVMBlock()) {
Error("failed to stop vmblock\n");
exit(EXIT_FAILURE);
}

if (!StartVMBlock()) {
/*
* There is more to vmware-user than VMBlock, so in case of error,
* only make a little noise. Continue to launch vmware-user.
*/
Error("failed to start vmblock\n");
}
}


/*
*----------------------------------------------------------------------------
*
* StopVMBlock --
*
* Unmounts the vmblock file system and unload the vmblock module.
*
* Results:
* TRUE on success, FALSE on failure.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------------
*/

static Bool
StopVMBlock(void)
{
Bool ret;
int id;

/*
* Default to success whether or not module loaded. Can fail only if
* unload fails.
*/
ret = TRUE;

/*
* The file system may not be mounted and that's okay. If it is mounted and
* this fails, the unloading of the module will fail later.
*/
UnmountVMBlock(VMBLOCK_MOUNT_POINT);

id = GetModuleId(MODULE_NAME);
if (id >= 0) {
/* The module is loaded. */
if (!UnloadModule(id)) {
ret = FALSE;
}
}

return ret;
}


/*
*----------------------------------------------------------------------------
*
* StartVMBlock --
*
* Loads the vmblock module and mounts its file system.
*
* Results:
* TRUE on success and FALSE on failure.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------------
*/

static Bool
StartVMBlock(void)
{
uid_t euid;
gid_t egid;

euid = geteuid();
egid = getegid();

if (!MakeDirectory(TMP_DIR, TMP_DIR_MODE, euid, egid)) {
Error("failed to create %s\n", TMP_DIR);
return FALSE;
}

if (!MakeDirectory(VMBLOCK_MOUNT_POINT, MOUNT_POINT_MODE, euid, egid)) {
Error("failed to create %s\n", VMBLOCK_MOUNT_POINT);
return FALSE;
}

if (!LoadVMBlock()) {
return FALSE;
}

if (!MountVMBlock()) {
/* This will unload the module and ignore the unmount failure. */
StopVMBlock();
return FALSE;
}

return TRUE;
}


/*
*----------------------------------------------------------------------------
*
* MakeDirectory --
*
* Creates a directory with the provided mode, uid, and gid. If the
* provided path already exists, this will ensure that it has the correct
* mode, uid, and gid, or else it will fail.
*
* Results:
* TRUE on success, FALSE on failure.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------------
*/

static Bool
MakeDirectory(const char *path, // IN: path to create
mode_t mode, // IN: mode of new directory
uid_t uid, // IN: owner of new directory
gid_t gid) // IN: group of new directory
{
if (mkdir(path, mode) == 0) {
/*
* We still need to chmod(2) the directory since mkdir(2) takes the umask
* into account.
*/
if (!ChmodChownDirectory(path, mode, uid, gid)) {
return FALSE;
}
return TRUE;
}

/*
* If we couldn't create the directory because the path already exists, we
* need to make sure it's a directory and that it has the correct
* permissions and owner. For any other failure we fail.
*/
if (errno != EEXIST || !ChmodChownDirectory(path, mode, uid, gid)) {
return FALSE;
}

return TRUE;
}


/*
*----------------------------------------------------------------------------
*
* ChmodChownDirectory --
*
* Atomically ensures the provided path is a directory and changes its mode,
* uid, and gid to the provided values.
*
* Results:
* TRUE on success, FALSE on failure.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------------
*/

static Bool
ChmodChownDirectory(const char *path, // IN
mode_t mode, // IN
uid_t uid, // IN
gid_t gid) // IN
{
int fd;
struct stat stat;
int ret = FALSE;

fd = open(path, O_RDONLY);
if (fd < 0) {
return FALSE;
}

if (fstat(fd, &stat) != 0) {
goto out;
}

if (!S_ISDIR(stat.st_mode)) {
goto out;
}

if ((stat.st_uid != uid || stat.st_gid != gid) &&
fchown(fd, uid, gid) != 0) {
goto out;
}

if (stat.st_mode != mode && fchmod(fd, mode) != 0) {
goto out;
}

ret = TRUE;

out:
close(fd);
return ret;
}
#endif // ifdef TOGGLE_VMBLOCK


/*
*-----------------------------------------------------------------------------
*
Expand Down