diff --git a/open-vm-tools/vmware-user-suid-wrapper/main.c b/open-vm-tools/vmware-user-suid-wrapper/main.c index a34c784ce..7b32b24e3 100644 --- a/open-vm-tools/vmware-user-suid-wrapper/main.c +++ b/open-vm-tools/vmware-user-suid-wrapper/main.c @@ -33,21 +33,15 @@ #endif #include -#include #include #include -#if defined(sun) -# include -#endif - #include #include #include #include #include #include -#include #include "vmware.h" #include "vmblock.h" @@ -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[]); @@ -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); @@ -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 - - /* *----------------------------------------------------------------------------- *