From: VMware, Inc <> Date: Mon, 26 Jul 2010 18:44:28 +0000 (-0700) Subject: . add API enabled properties for VI guest ops X-Git-Tag: 2010.07.25-280253~63 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b0f20b26f8d556d2e6887b2b05ee33986e8081e2;p=thirdparty%2Fopen-vm-tools.git . add API enabled properties for VI guest ops . changes in shared code that don't affect open-vm-tools functionality. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/foundryMsg/foundryMsg.c b/open-vm-tools/lib/foundryMsg/foundryMsg.c index 9b13a8fc4..8e20c33d3 100644 --- a/open-vm-tools/lib/foundryMsg/foundryMsg.c +++ b/open-vm-tools/lib/foundryMsg/foundryMsg.c @@ -444,6 +444,12 @@ static const VixCommandInfo vixCommandInfoTable[] = { VIX_DEFINE_COMMAND_INFO(VIX_COMMAND_CREATE_TEMPORARY_DIRECTORY, VIX_COMMAND_CATEGORY_ALWAYS_ALLOWED), + + VIX_DEFINE_COMMAND_INFO(VIX_COMMAND_SET_GUEST_FILE_ATTRIBUTES, + VIX_COMMAND_CATEGORY_ALWAYS_ALLOWED), + + VIX_DEFINE_COMMAND_INFO(VIX_COMMAND_COPY_FILE_FROM_GUEST_TO_READER, + VIX_COMMAND_CATEGORY_ALWAYS_ALLOWED), }; diff --git a/open-vm-tools/lib/include/timeutil.h b/open-vm-tools/lib/include/timeutil.h index 410712fb7..fbda5db83 100644 --- a/open-vm-tools/lib/include/timeutil.h +++ b/open-vm-tools/lib/include/timeutil.h @@ -39,6 +39,12 @@ struct timeval; +#ifdef _WIN32 +struct timespec { + time_t tv_sec; + long tv_nsec; +}; +#endif /* Similar to a struct tm but with slightly less weird semantics. */ typedef struct TimeUtil_Date { @@ -113,7 +119,7 @@ EXTERN char * TimeUtil_GetTimeFormat(int64 utcTime, // IN Bool showDate, // IN Bool showTime); // IN -#if !defined _WIN32 && !defined N_PLAT_NLM +#if !defined N_PLAT_NLM EXTERN int TimeUtil_NtTimeToUnixTime(struct timespec *unixTime, // OUT VmTimeType ntTime); // IN EXTERN VmTimeType TimeUtil_UnixTimeToNtTime(struct timespec unixTime); // IN diff --git a/open-vm-tools/lib/include/vixCommands.h b/open-vm-tools/lib/include/vixCommands.h index 13725b5d6..0662e1ad8 100644 --- a/open-vm-tools/lib/include/vixCommands.h +++ b/open-vm-tools/lib/include/vixCommands.h @@ -689,6 +689,25 @@ struct VixCommandHgfsSendPacket { #include "vmware_pack_end.h" VixCommandHgfsSendPacket; +typedef +#include "vmware_pack_begin.h" +struct VixMsgSetGuestFileAttributesRequest { + VixCommandRequestHeader header; + + int32 fileOptions; + int64 createTime; + int64 accessTime; + int64 modificationTime; + int32 ownerId; + int32 groupId; + int32 permissions; + Bool hidden; + Bool readOnly; + uint32 guestPathNameLength; +} +#include "vmware_pack_end.h" +VixMsgSetGuestFileAttributesRequest; + /* * ********************************************************** @@ -2253,6 +2272,9 @@ enum { VIX_COMMAND_CREATE_TEMPORARY_DIRECTORY = 182, + VIX_COMMAND_SET_GUEST_FILE_ATTRIBUTES = 183, + + VIX_COMMAND_COPY_FILE_FROM_GUEST_TO_READER = 184, /* * HOWTO: Adding a new Vix Command. Step 2a. * @@ -2263,7 +2285,7 @@ enum { * Once a new command is added here, a command info field needs to be added * in bora/lib/foundryMsg. as well. */ - VIX_COMMAND_LAST_NORMAL_COMMAND = 183, + VIX_COMMAND_LAST_NORMAL_COMMAND = 185, VIX_TEST_UNSUPPORTED_TOOLS_OPCODE_COMMAND = 998, VIX_TEST_UNSUPPORTED_VMX_OPCODE_COMMAND = 999, diff --git a/open-vm-tools/lib/include/vixOpenSource.h b/open-vm-tools/lib/include/vixOpenSource.h index c467e5aea..c3ac456db 100644 --- a/open-vm-tools/lib/include/vixOpenSource.h +++ b/open-vm-tools/lib/include/vixOpenSource.h @@ -148,6 +148,28 @@ enum { VIX_PROPERTY_VM_DNS_SERVER = 4518, VIX_PROPERTY_GUEST_TOOLS_WORD_SIZE = 4519, VIX_PROPERTY_GUEST_OS_VERSION_SHORT = 4520, + + /* VI guest operation status */ + VIX_PROPERTY_GUEST_START_PROGRAM_ENABLED = 4540, + VIX_PROPERTY_GUEST_LIST_PROCESSES_ENABLED = 4541, + VIX_PROPERTY_GUEST_TERMINATE_PROCESS_ENABLED = 4542, + VIX_PROPERTY_GUEST_READ_ENVIRONMENT_VARIABLE_ENABLED = 4543, + + VIX_PROPERTY_GUEST_VALIDATE_CREDENTIALS_ENABLED = 4544, + VIX_PROPERTY_GUEST_ACQUIRE_CREDENTIALS_ENABLED = 4545, + VIX_PROPERTY_GUEST_RELEASE_CREDENTIALS_ENABLED = 4546, + + VIX_PROPERTY_GUEST_MAKE_DIRECTORY_ENABLED = 4547, + VIX_PROPERTY_GUEST_DELETE_FILE_ENABLED = 4548, + VIX_PROPERTY_GUEST_DELETE_DIRECTORY_ENABLED = 4549, + VIX_PROPERTY_GUEST_MOVE_DIRECTORY_ENABLED = 4550, + VIX_PROPERTY_GUEST_MOVE_FILE_ENABLED = 4551, + VIX_PROPERTY_GUEST_CREATE_TEMP_FILE_ENABLED = 4552, + VIX_PROPERTY_GUEST_CREATE_TEMP_DIRECTORY_ENABLED = 4553, + VIX_PROPERTY_GUEST_LIST_FILES_ENABLED = 4554, + VIX_PROPERTY_GUEST_CHANGE_FILE_ATTRIBUTES_ENABLED = 4555, + VIX_PROPERTY_GUEST_INITIATE_FILE_TRANSFER_FROM_GUEST_ENABLED = 4556, + VIX_PROPERTY_GUEST_INITIATE_FILE_TRANSFER_TO_GUEST_ENABLED = 4557, }; diff --git a/open-vm-tools/lib/misc/timeutil.c b/open-vm-tools/lib/misc/timeutil.c index 4d9779751..72c68dffe 100644 --- a/open-vm-tools/lib/misc/timeutil.c +++ b/open-vm-tools/lib/misc/timeutil.c @@ -872,7 +872,8 @@ TimeUtil_GetTimeFormat(int64 utcTime, // IN #endif // _WIN32 } -#if !defined _WIN32 && !defined N_PLAT_NLM + +#if !defined N_PLAT_NLM /* *----------------------------------------------------------------------------- * @@ -958,7 +959,7 @@ TimeUtil_UnixTimeToNtTime(struct timespec unixTime) // IN: Time in Unix format return (VmTimeType)unixTime.tv_sec * 10000000 + unixTime.tv_nsec / 100 + UNIX_EPOCH; } -#endif // _WIN32 && N_PLAT_NLM +#endif // N_PLAT_NLM #ifdef _WIN32 /* diff --git a/open-vm-tools/lib/vixTools/vixTools.c b/open-vm-tools/lib/vixTools/vixTools.c index 74c5d99a3..e67d813ca 100644 --- a/open-vm-tools/lib/vixTools/vixTools.c +++ b/open-vm-tools/lib/vixTools/vixTools.c @@ -22,6 +22,17 @@ * VIX commands that run in the guest OS. */ +/* + * When adding new functions, be sure to update + * VixToolsSetAPIEnabledProperties() (adding a property and associated code + * in apps/lib/foundry/foundryVM.c if necessary). The enabled properties + * provide hints to an API developer as to which APIs are available, + * and can be affected to guest OS attributes or guest-side conifguration. + * + * See Vim.Vm.Guest.QueryDisabledMethods() + * + */ + #include #include #include @@ -35,6 +46,7 @@ #include "wminic.h" #include "win32u.h" #include +#include #else #include #endif @@ -47,6 +59,7 @@ #include "vmware.h" #include "procMgr.h" +#include "timeutil.h" #include "vm_version.h" #include "message.h" @@ -170,6 +183,8 @@ static HashTable *userEnvironmentTable = NULL; static VixError VixToolsGetFileInfo(VixCommandRequestHeader *requestMsg, char **result); +static VixError VixToolsSetFileAttributes(VixCommandRequestHeader *requestMsg); + #if defined(VMTOOLS_USE_GLIB) static gboolean VixToolsMonitorAsyncProc(void *clientData); #else @@ -284,6 +299,10 @@ static VixError VixTools_Base64EncodeBuffer(char **resultValuePtr, size_t *resul static VixError VixToolsSetSharedFoldersProperties(VixPropertyListImpl *propList); +#if !defined(__FreeBSD__) && !defined(sun) +static VixError VixToolsSetAPIEnabledProperties(VixPropertyListImpl *propList); +#endif + #if defined(_WIN32) static HRESULT VixToolsEnableDHCPOnPrimary(void); @@ -1213,6 +1232,15 @@ VixTools_GetToolsPropertiesImpl(GuestApp_Dict **confDictRef, // IN /* Retrieve the share folders UNC root path. */ err = VixToolsSetSharedFoldersProperties(&propList); + if (VIX_OK != err) { + goto abort; + } + + /* Set up the API status properties */ + err = VixToolsSetAPIEnabledProperties(&propList); + if (VIX_OK != err) { + goto abort; + } /* * Serialize the property list to buffer then encode it. @@ -1315,6 +1343,170 @@ exit: } +#if !defined(__FreeBSD__) && !defined(sun) +/* + *----------------------------------------------------------------------------- + * + * VixToolsSetAPIEnabledProperties -- + * + * Set information about the state of APIs. + * + * Return value: + * VixError + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +static VixError +VixToolsSetAPIEnabledProperties(VixPropertyListImpl *propList) // IN +{ + VixError err = VIX_OK; + + /* + * XXX TODO + * + * These values need to be adjusted as each API is implemented. + * + * They will also need guest-side configuration checks at some point. + */ + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_START_PROGRAM_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_LIST_PROCESSES_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + + // XXX not strictly true -- some error code work is still TBD + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_TERMINATE_PROCESS_ENABLED, + TRUE); + if (VIX_OK != err) { + goto exit; + } + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_READ_ENVIRONMENT_VARIABLE_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_VALIDATE_CREDENTIALS_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_ACQUIRE_CREDENTIALS_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_RELEASE_CREDENTIALS_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_MAKE_DIRECTORY_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_DELETE_FILE_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_DELETE_DIRECTORY_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_MOVE_DIRECTORY_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_MOVE_FILE_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_CREATE_TEMP_FILE_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_CREATE_TEMP_DIRECTORY_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_LIST_FILES_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_CHANGE_FILE_ATTRIBUTES_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_INITIATE_FILE_TRANSFER_FROM_GUEST_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + + err = VixPropertyList_SetBool(propList, + VIX_PROPERTY_GUEST_INITIATE_FILE_TRANSFER_TO_GUEST_ENABLED, + FALSE); + if (VIX_OK != err) { + goto exit; + } + +exit: + Debug("finished %s, err %"FMT64"d\n", __FUNCTION__, err); + return err; +} // VixToolsSetAPIEnabledProperties +#endif // !defined(__FreeBSD__) && !defined(sun) + + /* *----------------------------------------------------------------------------- * @@ -2843,6 +3035,156 @@ abort: } // VixToolsGetFileInfo +/* + *----------------------------------------------------------------------------- + * + * VixToolsSetFileAttributes -- + * + * Set the file attributes for a specified file. + * + * Return value: + * VixError + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +VixError +VixToolsSetFileAttributes(VixCommandRequestHeader *requestMsg) // IN +{ +#if (defined(_WIN32) || defined(__linux__)) + VixError err = VIX_OK; + Bool impersonatingVMWareUser = FALSE; + void *userToken = NULL; + char *filePathName; + VixMsgSetGuestFileAttributesRequest *setGuestFileAttributesRequest = NULL; + struct timespec timeBuf; + Bool success = FALSE; + int64 createTime; + int64 accessTime; + int64 modificationTime; + +#ifdef _WIN32 + DWORD fileAttr = 0; +#endif + + setGuestFileAttributesRequest = + (VixMsgSetGuestFileAttributesRequest *) requestMsg; + + if ((requestMsg->commonHeader.bodyLength + + requestMsg->commonHeader.headerLength) != + (((uint64) sizeof(*setGuestFileAttributesRequest)) + + setGuestFileAttributesRequest->guestPathNameLength + 1)) { + ASSERT(0); + Debug("%s: Invalid request message received\n", __FUNCTION__); + err = VIX_E_INVALID_MESSAGE_BODY; + goto abort; + } + + filePathName = ((char *) requestMsg) + + sizeof(*setGuestFileAttributesRequest); + if ('\0' == *filePathName) { + err = VIX_E_INVALID_ARG; + goto abort; + } + + if ('\0' != *(filePathName + + setGuestFileAttributesRequest->guestPathNameLength)) { + ASSERT(0); + Debug("%s: Invalid request message received.\n", __FUNCTION__); + err = VIX_E_INVALID_MESSAGE_BODY; + goto abort; + } + + err = VixToolsImpersonateUser(requestMsg, &userToken); + if (VIX_OK != err) { + goto abort; + } + impersonatingVMWareUser = TRUE; + + if (!(File_Exists(filePathName))) { + err = VIX_E_FILE_NOT_FOUND; + goto abort; + } + + /* + * User specifies the time in Unix Time Format. File_SetTimes() + * accepts times in Windows NT Format. We should convert the time + * from Unix Format to Windows NT Format. + */ + timeBuf.tv_sec = setGuestFileAttributesRequest->createTime; + timeBuf.tv_nsec = 0; + createTime = TimeUtil_UnixTimeToNtTime(timeBuf); + + timeBuf.tv_sec = setGuestFileAttributesRequest->accessTime; + timeBuf.tv_nsec = 0; + accessTime = TimeUtil_UnixTimeToNtTime(timeBuf); + + timeBuf.tv_sec = setGuestFileAttributesRequest->modificationTime; + timeBuf.tv_nsec = 0; + modificationTime = TimeUtil_UnixTimeToNtTime(timeBuf); + + success = File_SetTimes(filePathName, + createTime, + accessTime, + modificationTime, + modificationTime); + if (!success) { + Debug("%s: Failed to set the times.\n", __FUNCTION__); + err = FoundryToolsDaemon_TranslateSystemErr(); + goto abort; + } + +#if defined(_WIN32) + fileAttr = Win32U_GetFileAttributes(filePathName); + if (fileAttr != INVALID_FILE_ATTRIBUTES) { + if (setGuestFileAttributesRequest->hidden) { + fileAttr |= FILE_ATTRIBUTE_HIDDEN; + } else { + fileAttr &= (~FILE_ATTRIBUTE_HIDDEN); + } + + if (setGuestFileAttributesRequest->readOnly) { + fileAttr |= FILE_ATTRIBUTE_READONLY; + } else { + fileAttr &= (~FILE_ATTRIBUTE_READONLY); + } + + Win32U_SetFileAttributes(filePathName, fileAttr); + } +#else + success = File_SetFilePermissions(filePathName, + setGuestFileAttributesRequest->permissions); + if (!success) { + Debug("%s: Failed to set the file permissions\n", __FUNCTION__); + err = FoundryToolsDaemon_TranslateSystemErr(); + goto abort; + } + + if (Posix_Chown(filePathName, + setGuestFileAttributesRequest->ownerId, + setGuestFileAttributesRequest->groupId)) { + Debug("%s: Failed to set the owner/group Id\n", __FUNCTION__); + err = FoundryToolsDaemon_TranslateSystemErr(); + goto abort; + } +#endif + +abort: + if (impersonatingVMWareUser) { + VixToolsUnimpersonateUser(userToken); + } + VixToolsLogoutUser(userToken); + + return err; +#else + return VIX_E_NOT_SUPPORTED; +#endif +} // VixToolsSetGuestFileAttributes + + /* *----------------------------------------------------------------------------- * @@ -4858,6 +5200,11 @@ VixTools_ProcessVixCommand(VixCommandRequestHeader *requestMsg, // IN deleteResultValue = TRUE; break; + /////////////////////////////////// + case VIX_COMMAND_SET_GUEST_FILE_ATTRIBUTES: + err = VixToolsSetFileAttributes(requestMsg); + break; + /////////////////////////////////// case VMXI_HGFS_SEND_PACKET_COMMAND: err = VixToolsProcessHgfsPacket((VixCommandHgfsSendPacket *) requestMsg,