~n-muench/ubuntu/oneiric/open-vm-tools/open-vm-tools-august.merge

« back to all changes in this revision

Viewing changes to lib/guestApp/guestApp.c

  • Committer: Bazaar Package Importer
  • Author(s): Nate Muench
  • Date: 2010-09-06 21:06:01 UTC
  • mfrom: (2.4.19 sid)
  • Revision ID: james.westby@ubuntu.com-20100906210601-gxxy30e5roil4srt
Tags: 2010.06.16-268169-3ubuntu1
* Merge from Debian testing (LP: #632101), remaining changes:
  - Recommend open-vm-toolbox in open-vm-tools.
  - Rediffing vsock.patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
 * is the hardcoded value below. For Windows, it is
67
67
 * determined dynamically in GuestApp_GetInstallPath(),
68
68
 * so the empty string here is just for completeness.
69
 
 * XXX. Whoever does the Mac port should do something
70
 
 * intelligent for that platform as well.
71
69
 */
72
70
 
73
 
#if defined(_WIN32)
74
 
#define GUESTAPP_TOOLS_INSTALL_PATH ""
 
71
#if defined _WIN32
 
72
#   define GUESTAPP_TOOLS_INSTALL_PATH ""
 
73
#elif defined __APPLE__
 
74
#   define GUESTAPP_TOOLS_INSTALL_PATH "/Library/Application Support/VMware Tools"
75
75
#else
76
 
#define GUESTAPP_TOOLS_INSTALL_PATH "/etc/vmware-tools"
 
76
#   define GUESTAPP_TOOLS_INSTALL_PATH "/etc/vmware-tools"
77
77
#endif
78
78
 
79
79
/*
869
869
   return value;
870
870
}
871
871
 
 
872
#ifdef _WIN32
 
873
 
 
874
/*
 
875
 *------------------------------------------------------------------------------
 
876
 *
 
877
 * GuestApp_GetInstallPathW --
 
878
 *
 
879
 *    Returns the tools installation path as a UTF-16 encoded string, or NULL on
 
880
 *    error. The caller must deallocate the returned string using free.
 
881
 *
 
882
 * Results:
 
883
 *    See above.
 
884
 *
 
885
 * Side effects:
 
886
 *    None.
 
887
 *------------------------------------------------------------------------------
 
888
 */
 
889
 
 
890
LPWSTR
 
891
GuestApp_GetInstallPathW(void)
 
892
{
 
893
   static LPCWSTR TOOLS_KEY_NAME = L"Software\\VMware, Inc.\\VMware Tools";
 
894
   static LPCWSTR INSTALLPATH_VALUE_NAME = L"InstallPath";
 
895
 
 
896
   HKEY   key    = NULL;
 
897
   LONG   rc     = ERROR_SUCCESS;
 
898
   DWORD  cbData = 0;
 
899
   DWORD  temp   = 0;
 
900
   PWCHAR data   = NULL;
 
901
 
 
902
   rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, TOOLS_KEY_NAME, 0, KEY_READ, &key);
 
903
   if (ERROR_SUCCESS != rc) {
 
904
      Debug("%s: Couldn't open key \"%S\".\n", __FUNCTION__, TOOLS_KEY_NAME);
 
905
      Debug("%s: RegOpenKeyExW error 0x%x.\n", __FUNCTION__, GetLastError());
 
906
      goto exit;
 
907
   }
 
908
 
 
909
   rc = RegQueryValueExW(key, INSTALLPATH_VALUE_NAME, 0, NULL, NULL, &cbData);
 
910
   if (ERROR_SUCCESS != rc) {
 
911
      Debug("%s: Couldn't get length of value \"%S\".\n", __FUNCTION__,
 
912
            INSTALLPATH_VALUE_NAME);
 
913
      Debug("%s: RegQueryValueExW error 0x%x.\n", __FUNCTION__, GetLastError());
 
914
      goto exit;
 
915
   }
 
916
 
 
917
   /*
 
918
    * The data in the registry may not be null terminated. So allocate enough
 
919
    * space for one extra WCHAR and use that space to write our own NULL.
 
920
    */
 
921
   data = (LPWSTR) malloc(cbData + sizeof(WCHAR));
 
922
   if (NULL == data) {
 
923
      Debug("%s: Couldn't allocate %d bytes.\n", __FUNCTION__, cbData);
 
924
      goto exit;
 
925
   }
 
926
 
 
927
   temp = cbData;
 
928
   rc = RegQueryValueExW(key, INSTALLPATH_VALUE_NAME, 0, NULL, (LPBYTE) data,
 
929
                         &temp);
 
930
   if (ERROR_SUCCESS != rc) {
 
931
      Debug("%s: Couldn't get data for value \"%S\".\n", __FUNCTION__,
 
932
            INSTALLPATH_VALUE_NAME);
 
933
      Debug("%s: RegQueryValueExW error 0x%x.\n", __FUNCTION__, GetLastError());
 
934
      goto exit;
 
935
   }
 
936
 
 
937
   data[cbData / sizeof(WCHAR)] = L'\0';
 
938
 
 
939
exit:
 
940
   if (NULL != key) {
 
941
      RegCloseKey(key);
 
942
   }
 
943
 
 
944
   return data;
 
945
}
 
946
 
 
947
#endif
872
948
 
873
949
/*
874
950
 *----------------------------------------------------------------------
936
1012
 *      lib/user/win32util.c because we can't use that file inside guest
937
1013
 *      code. If we do, we'll break Win95 Tools.
938
1014
 *
939
 
 *      XXX: For Windows, this function will only fail on pre-2k/Me systems 
940
 
 *      that haven't installed IE4 _and_ haven't ever used our installer 
941
 
 *      (it is thought that the installer will copy shfolder.dll if the 
 
1015
 *      XXX: For Windows, this function will only fail on pre-2k/Me systems
 
1016
 *      that haven't installed IE4 _and_ haven't ever used our installer
 
1017
 *      (it is thought that the installer will copy shfolder.dll if the
942
1018
 *      system needs it).
943
1019
 *
944
1020
 *      However, the function will also return NULL if we fail to create
948
1024
 *      a non-root user process calls this function, the directory exists.
949
1025
 *
950
1026
 * Results:
951
 
 *      The path in UTF-8, or NULL on failure. 
 
1027
 *      The path in UTF-8, or NULL on failure.
952
1028
 *
953
1029
 * Side effects:
954
1030
 *      Allocates memory.
974
1050
   if (!pfnSHGetFolderPath) {
975
1051
      HMODULE h = LoadLibraryW(L"shfolder.dll");
976
1052
      if (h) {
977
 
         pfnSHGetFolderPath = (PSHGETFOLDERPATH) 
 
1053
         pfnSHGetFolderPath = (PSHGETFOLDERPATH)
978
1054
            GetProcAddress(h, "SHGetFolderPathW");
979
1055
      }
980
 
         
 
1056
 
981
1057
      /* win32util.c avoids calling FreeLibrary() so we will too. */
982
1058
   }
983
1059
 
984
 
   /* 
985
 
    * Get the Common Application data folder - create if it doesn't 
 
1060
   /*
 
1061
    * Get the Common Application data folder - create if it doesn't
986
1062
    * exist.
987
1063
    */
988
1064
 
1084
1160
   /* We should log to %TEMP%. */
1085
1161
   LPWSTR buffer = NULL;
1086
1162
   DWORD bufferSize = 0, neededSize;
1087
 
   
 
1163
 
1088
1164
   if ((neededSize = GetEnvironmentVariableW(L"TEMP", buffer, bufferSize)) == 0) {
1089
1165
      return NULL;
1090
1166
   }
1231
1307
/*
1232
1308
 *-----------------------------------------------------------------------------
1233
1309
 *
1234
 
 * GuestApp_DiskShrink --
1235
 
 *
1236
 
 *      Shrink disk
1237
 
 *
1238
 
 * Results:
1239
 
 *      TRUE if the shrinking is successful
1240
 
 *      FALSE if disk shrinking is not successful
1241
 
 * Side effects:
1242
 
 *      None
1243
 
 *
1244
 
 *-----------------------------------------------------------------------------
1245
 
 */
1246
 
 
1247
 
Bool
1248
 
GuestApp_DiskShrink(void) {
1249
 
   return RpcOut_sendOne(NULL, NULL, "disk.shrink");
1250
 
}
1251
 
 
1252
 
 
1253
 
/*
1254
 
 *-----------------------------------------------------------------------------
1255
 
 *
1256
1310
 * GuestApp_GetPos --
1257
1311
 *
1258
1312
 *      Retrieve the host notion of the guest pointer location. --hpreg
1620
1674
 *
1621
1675
 * GuestApp_RpcSendOneArgCPName --
1622
1676
 *
1623
 
 *    Wrapper for GuestApp_RpcSendOneCPName with an extra argument. Sends a 
 
1677
 *    Wrapper for GuestApp_RpcSendOneCPName with an extra argument. Sends a
1624
1678
 *    single RPCI command with arg and cpNameArg both in UTF-8 encodeding.
1625
1679
 *
1626
1680
 *    The UTF-8 encoded arg is optional so that one can send a single UTF-8