290
288
static HashTable *userEnvironmentTable = NULL;
292
#if !defined(__FreeBSD__)
293
290
static HgfsServerMgrData gVixHgfsBkdrConn;
292
#define SECONDS_BETWEEN_INVALIDATING_HGFS_SESSIONS 120
296
294
static VixError VixToolsGetFileInfo(VixCommandRequestHeader *requestMsg,
301
299
static gboolean VixToolsMonitorAsyncProc(void *clientData);
302
300
static gboolean VixToolsMonitorStartProgram(void *clientData);
301
static void VixToolsRegisterHgfsSessionInvalidator(void *clientData);
302
static gboolean VixToolsInvalidateInactiveHGFSSessions(void *clientData);
304
static GSource *gHgfsSessionInvalidatorTimer = NULL;
305
static guint gHgfsSessionInvalidatorTimerId;
304
307
static void VixToolsPrintFileInfo(const char *filePathName,
496
500
char const *obfuscatedNamePassword,
497
501
void **userToken);
499
#if defined(_WIN32) || defined(linux) || defined(sun)
500
503
static VixError VixToolsDoesUsernameMatchCurrentUser(const char *username);
503
505
static Bool VixToolsPidRefersToThisProcess(ProcMgr_Pid pid);
564
566
VixToolsInitSspiSessionList(VIX_TOOLS_MAX_SSPI_SESSIONS);
565
567
VixToolsInitTicketedSessionList(VIX_TOOLS_MAX_TICKETED_SESSIONS);
567
#if !defined(__FreeBSD__)
568
569
/* Register a straight through connection with the Hgfs server. */
569
570
HgfsServerManager_DataInit(&gVixHgfsBkdrConn,
570
571
VIX_BACKDOORCOMMAND_COMMAND,
571
572
NULL, // no RPC registration
572
573
NULL); // rpc callback
573
574
HgfsServerManager_Register(&gVixHgfsBkdrConn);
576
576
listProcessesResultsTable = g_hash_table_new_full(g_int_hash, g_int_equal,
578
578
VixToolsFreeCachedResult);
601
601
VixTools_Uninitialize(void) // IN
603
#if !defined(__FreeBSD__)
603
if (NULL != gHgfsSessionInvalidatorTimer) {
604
g_source_remove(gHgfsSessionInvalidatorTimerId);
605
g_source_unref(gHgfsSessionInvalidatorTimer);
606
gHgfsSessionInvalidatorTimer = NULL;
607
gHgfsSessionInvalidatorTimerId = 0;
608
Log("%s: HGFS session Invalidator detached\n",
604
612
HgfsServerManager_Unregister(&gVixHgfsBkdrConn);
820
827
* VixTools_SetRunProgramCallback --
822
829
* Register a callback that reports when a program has completed.
823
* Different clients of this library will use different IPC mechanisms for
830
* Different clients of this library will use different IPC mechanisms for
824
831
* sending this message. For example, it may use the backdoor or a socket.
825
832
* Different sockets may use different message protocols, such as the backdoor-on-a-socket
826
833
* or the Foundry network message.
907
914
if (runProgramRequest->runProgramOptions & VIX_RUNPROGRAM_RUN_AS_LOCAL_SYSTEM) {
908
915
if (!VixToolsUserIsMemberOfAdministratorGroup(requestMsg)) {
909
916
err = VIX_E_GUEST_USER_PERMISSIONS;
912
919
userToken = PROCESS_CREATOR_USER_TOKEN;
916
923
if (NULL == userToken) {
917
924
err = VixToolsImpersonateUser(requestMsg, &userToken);
918
925
if (VIX_OK != err) {
1196
1203
* On linux, we run the program by exec'ing /bin/sh, and that does not
1197
1204
* return a clear error code indicating that the program does not exist
1198
1205
* or cannot be executed.
1199
* This is a common and user-correctable error, however, so we want to
1206
* This is a common and user-correctable error, however, so we want to
1200
1207
* check for it and return a specific error code in this case.
1204
1211
programExists = File_Exists(startProgramFileName);
1205
programIsExecutable =
1206
(FileIO_Access(startProgramFileName, FILEIO_ACCESS_EXEC) ==
1212
programIsExecutable =
1213
(FileIO_Access(startProgramFileName, FILEIO_ACCESS_EXEC) ==
1207
1214
FILEIO_SUCCESS);
1209
1216
free(tempCommandLine);
1275
1282
si.dwFlags = STARTF_USESHOWWINDOW;
1276
1283
si.wShowWindow = (VIX_RUNPROGRAM_ACTIVATE_WINDOW & runProgramOptions)
1277
1284
? SW_SHOWNORMAL : SW_MINIMIZE;
1285
#elif !defined(__FreeBSD__)
1279
1286
procArgs.envp = VixToolsEnvironmentTableToEnvp(userEnvironmentTable);
1438
1445
* For non-Windows, we use the user's $HOME if workingDir isn't supplied.
1440
1447
if (NULL == workingDir) {
1441
#if defined(linux) || defined(sun)
1448
#if defined(linux) || defined(sun) || defined(__FreeBSD__) || defined(__APPLE__)
1442
1449
char *username = NULL;
1444
1451
if (!ProcMgr_GetImpersonatedUserInfo(&username, &workingDirectory)) {
1685
*----------------------------------------------------------------------------
1687
* VixToolsInvalidateInactiveHGFSSessions --
1689
* Send a request to HGFS server to invalidate inactive sessions.
1690
* Registers a timer to call the invalidator.
1693
* TRUE if the timer needs to be re-registerd.
1694
* FALSE if the timer needs to be deleted.
1699
*----------------------------------------------------------------------------
1703
VixToolsInvalidateInactiveHGFSSessions(void *clientData) // IN:
1705
if (HgfsServerManager_InvalidateInactiveSessions(&gVixHgfsBkdrConn) > 0) {
1707
* There are still active sessions, so keep the periodic timer
1713
Log("%s: HGFS session Invalidator is successfully detached\n",
1716
g_source_unref(gHgfsSessionInvalidatorTimer);
1717
gHgfsSessionInvalidatorTimer = NULL;
1718
gHgfsSessionInvalidatorTimerId = 0;
1725
*----------------------------------------------------------------------------
1727
* VixToolsRegisterHgfsSessionInvalidator --
1729
* Check bug 783263 for more details. This function is designed to
1730
* cleanup any hgfs state left by remote clients that got
1731
* disconnected abruptly during a file copy process.
1733
* If there is a timer already registered, then this function doesn't
1742
*----------------------------------------------------------------------------
1746
VixToolsRegisterHgfsSessionInvalidator(void *clientData) // IN:
1750
if (NULL != gHgfsSessionInvalidatorTimer) {
1754
gHgfsSessionInvalidatorTimer =
1755
g_timeout_source_new(SECONDS_BETWEEN_INVALIDATING_HGFS_SESSIONS * 1000);
1757
g_source_set_callback(gHgfsSessionInvalidatorTimer,
1758
VixToolsInvalidateInactiveHGFSSessions,
1762
gHgfsSessionInvalidatorTimerId =
1763
g_source_attach(gHgfsSessionInvalidatorTimer,
1764
g_main_loop_get_context((GMainLoop *) clientData));
1766
Log("%s: HGFS session Invalidator registered\n",
1678
1772
*-----------------------------------------------------------------------------
1680
1774
* VixToolsMonitorStartProgram --
1988
2082
const char *powerOnScript = NULL;
1989
2083
const char *resumeScript = NULL;
1990
2084
const char *suspendScript = NULL;
1991
char osNameFull[GUESTINFO_MAX_VALUE_SIZE];
1992
char osName[GUESTINFO_MAX_VALUE_SIZE];
2085
char *osName = NULL;
2086
char *osNameFull = NULL;
1993
2087
Bool foundHostName;
1994
2088
char *tempDir = NULL;
1995
2089
int wordSize = 32;
1998
2092
VixPropertyList_Initialize(&propList);
2001
2095
* Collect some values about the host.
2024
2118
osFamily = GUEST_OS_FAMILY_LINUX;
2026
if (!(Hostinfo_GetOSName(sizeof osNameFull, sizeof osName, osNameFull,
2121
osNameFull = Hostinfo_GetOSName();
2122
if (osNameFull == NULL) {
2123
osNameFull = Util_SafeStrdup("");
2126
osName = Hostinfo_GetOSGuestString();
2127
if (osName == NULL) {
2128
osName = Util_SafeStrdup("");
2031
2131
wordSize = Hostinfo_GetSystemBitness();
2032
2132
if (wordSize <= 0) {
2039
2139
packageList = "";
2041
2141
if (confDictRef != NULL) {
2042
powerOffScript = g_key_file_get_string(confDictRef, "powerops",
2142
powerOffScript = g_key_file_get_string(confDictRef, "powerops",
2043
2143
CONFNAME_POWEROFFSCRIPT, NULL);
2044
2144
powerOnScript = g_key_file_get_string(confDictRef, "powerops",
2045
2145
CONFNAME_POWERONSCRIPT, NULL);
2180
2280
free(guestName);
2181
2281
free(serializedBuffer);
2185
* FreeBSD. Return an empty serialized property list.
2287
* FreeBSD. We do not require all the properties above.
2288
* We only Support VMODL Guest Ops for now (Bug 228398).
2188
2291
VixPropertyList_Initialize(&propList);
2293
/* InitiateFileTransfer(From|To)Guest operations require this */
2294
err = VixPropertyList_SetInteger(&propList,
2295
VIX_PROPERTY_GUEST_OS_FAMILY,
2296
GUEST_OS_FAMILY_LINUX);
2297
if (VIX_OK != err) {
2190
2300
/* Retrieve the share folders UNC root path. */
2191
2301
err = VixToolsSetSharedFoldersProperties(&propList);
2302
if (VIX_OK != err) {
2194
2306
* Set up the API status properties.
2195
* This is done even though none are currently supported, so
2196
* that the client side can tell the difference between OutOfDate
2197
* tools and NotSupported.
2307
* This is done so that the client side can tell the
2308
* difference between OutOfDate tools and NotSupported.
2199
2310
err = VixToolsSetAPIEnabledProperties(&propList, confDictRef);
2200
2311
if (VIX_OK != err) {
2355
2466
VixToolsComputeEnabledProperty(GKeyFile *confDictRef, // IN
2356
2467
const char *varName) // IN
2358
#if defined(_WIN32) || defined(linux) || defined(sun)
2359
2469
return VixToolsGetAPIDisabledFromConf(confDictRef, varName);
2829
2936
* if pathName is an invalid symbolic link, we still want to delete it.
2831
2938
if (FALSE == File_IsSymLink(pathName)) {
2832
if (!(File_Exists(pathName))) {
2939
if (!(File_Exists(pathName))) {
2833
2940
err = VIX_E_FILE_NOT_FOUND;
3458
3564
char *resultLocal = Util_SafeStrdup(""); // makes the loop cleaner.
3459
3565
VixToolsUserEnvironment *env;
3568
if (NULL == userEnvironmentTable) {
3461
3575
err = VixToolsNewUserEnvironment(userToken, &env);
3462
3576
if (VIX_FAILED(err)) {
3467
3581
for (i = 0; i < numNames; i++) {
3586
* We should check the original envp for all vars except
3587
* a few whitelisted ones that we set/unset on impersonate
3588
* user start/stop. for them we need to do getenv()
3590
if (!strcmp(names, "USER") ||
3591
!strcmp(names, "HOME") ||
3592
!strcmp(names, "SHELL")) {
3593
value = VixToolsGetEnvFromUserEnvironment(env, names);
3596
if (HashTable_Lookup(userEnvironmentTable,
3597
names, (void **) &value)) {
3598
value = Util_SafeStrdup(value);
3600
value = Util_SafeStrdup("");
3470
3604
value = VixToolsGetEnvFromUserEnvironment(env, names);
3471
3607
if (NULL != value) {
3472
3608
char *tmp = resultLocal;
3553
3697
resultLocal = Util_SafeStrdup(""); // makes the loop cleaner.
3700
err = VixToolsNewEnvIterator(userToken, envp, &itr);
3555
3702
err = VixToolsNewEnvIterator(userToken, &itr);
3556
3704
if (VIX_FAILED(err)) {
3560
3708
while ((envVar = VixToolsGetNextEnvVar(itr)) != NULL) {
3561
3709
char *tmp = resultLocal;
3713
* For variables we change during Impersonatation of user,
3714
* we need to fetch from getenv() system call, all else
3715
* can be read from the hash table of the original envp.
3717
if (StrUtil_StartsWith(envVar, "USER=") ||
3718
StrUtil_StartsWith(envVar, "HOME=") ||
3719
StrUtil_StartsWith(envVar, "SHELL=")) {
3721
char *escapedName = NULL;
3725
whereToSplit = strchr(envVar, '=');
3726
if (NULL == whereToSplit) {
3727
/* Our code generated this list, so this shouldn't happen. */
3732
nameLen = whereToSplit - envVar;
3733
name = Util_SafeMalloc(nameLen + 1);
3734
memcpy(name, envVar, nameLen);
3735
name[nameLen] = '\0';
3737
escapedName = VixToolsEscapeXMLString(name);
3740
envVar = Str_SafeAsprintf(NULL, "%s=%s",
3741
escapedName, Posix_Getenv(name));
3564
3747
tmpVal = VixToolsEscapeXMLString(envVar);
3566
3749
if (NULL == tmpVal) {
4277
4465
VIX_XML_ESCAPED_TAG);
4280
for (i = 0; i < procList->procCount; i++) {
4468
procCount = ProcMgrProcInfoArray_Count(procList);
4469
for (i = 0; i < procCount; i++) {
4281
4470
const char *name;
4282
4471
const char *user;
4473
procInfo = ProcMgrProcInfoArray_AddressOf(procList, i);
4284
4475
if (escapeStrs) {
4285
4476
name = escapedName =
4286
VixToolsEscapeXMLString(procList->procCmdList[i]);
4477
VixToolsEscapeXMLString(procInfo->procCmd);
4287
4478
if (NULL == escapedName) {
4288
4479
err = VIX_E_OUT_OF_MEMORY;
4292
name = procList->procCmdList[i];
4483
name = procInfo->procCmd;
4295
if ((NULL != procList->procOwnerList) &&
4296
(NULL != procList->procOwnerList[i])) {
4486
if (NULL != procInfo->procOwner) {
4297
4487
if (escapeStrs) {
4298
4488
user = escapedUser =
4299
VixToolsEscapeXMLString(procList->procOwnerList[i]);
4489
VixToolsEscapeXMLString(procInfo->procOwner);
4300
4490
if (NULL == escapedUser) {
4301
4491
err = VIX_E_OUT_OF_MEMORY;
4305
user = procList->procOwnerList[i];
4495
user = procInfo->procOwner;
4316
4506
"<user>%s</user><start>%d</start></proc>",
4318
(int) procList->procIdList[i],
4508
(int) procInfo->procId,
4319
4509
#if defined(_WIN32)
4320
(int) procList->procDebugged[i],
4510
(int) procInfo->procDebugged,
4323
(NULL == procList->startTime)
4325
: (int) procList->startTime[i]);
4513
(int) procInfo->procStartTime);
4326
4514
if (NULL == procBufPtr) {
4327
4515
err = VIX_E_OUT_OF_MEMORY;
4406
4594
static gboolean
4407
4595
VixToolsListProcCacheCleanup(void *clientData) // IN
4409
int32 *key = (int32 *)clientData;
4597
int key = (int)(intptr_t)clientData;
4412
ret = g_hash_table_remove(listProcessesResultsTable, key);
4600
ret = g_hash_table_remove(listProcessesResultsTable, &key);
4413
4601
Debug("%s: list proc cache timed out, purged key %d (found? %d)\n",
4414
__FUNCTION__, *key, ret);
4602
__FUNCTION__, key, ret);
4441
4628
char **resultBuffer) // OUT
4443
4630
VixError err = VIX_OK;
4444
ProcMgr_ProcList *procList = NULL;
4631
ProcMgrProcInfoArray *procList = NULL;
4632
ProcMgrProcInfo *procInfo;
4445
4633
DynBuf dynBuffer;
4446
4634
VixToolsExitedProgramState *epList;
4451
4640
DynBuf_Init(&dynBuffer);
4510
4700
* the Vix side with GetNthProperty, and can have a mix of live and
4511
4701
* dead processes.
4703
procCount = ProcMgrProcInfoArray_Count(procList);
4513
4704
if (numPids > 0) {
4514
4705
for (i = 0; i < numPids; i++) {
4515
for (j = 0; j < procList->procCount; j++) {
4516
// ignore it if its on the exited list -- we added it above
4517
if (VixToolsFindExitedProgramState(pids[i])) {
4520
if (pids[i] == procList->procIdList[j]) {
4706
// ignore it if its on the exited list -- we added it above
4707
if (VixToolsFindExitedProgramState(pids[i])) {
4710
for (j = 0; j < procCount; j++) {
4711
procInfo = ProcMgrProcInfoArray_AddressOf(procList, j);
4712
if (pids[i] == procInfo->procId) {
4521
4713
err = VixToolsPrintProcInfoEx(&dynBuffer,
4522
procList->procCmdList[i],
4523
procList->procIdList[i],
4524
(NULL == procList->procOwnerList
4525
|| NULL == procList->procOwnerList[i])
4526
? "" : procList->procOwnerList[i],
4527
(NULL == procList->startTime)
4528
? 0 : (int) procList->startTime[i],
4716
(NULL == procInfo->procOwner)
4717
? "" : procInfo->procOwner,
4718
(int) procInfo->procStartTime,
4530
4720
if (VIX_OK != err) {
4537
for (i = 0; i < procList->procCount; i++) {
4727
for (i = 0; i < procCount; i++) {
4728
procInfo = ProcMgrProcInfoArray_AddressOf(procList, i);
4538
4729
// ignore it if its on the exited list -- we added it above
4539
if (VixToolsFindExitedProgramState(procList->procIdList[i])) {
4730
if (VixToolsFindExitedProgramState(procInfo->procId)) {
4542
4733
err = VixToolsPrintProcInfoEx(&dynBuffer,
4543
procList->procCmdList[i],
4544
procList->procIdList[i],
4545
(NULL == procList->procOwnerList
4546
|| NULL == procList->procOwnerList[i])
4547
? "" : procList->procOwnerList[i],
4548
(NULL == procList->startTime)
4549
? 0 : (int) procList->startTime[i],
4736
(NULL == procInfo->procOwner)
4737
? "" : procInfo->procOwner,
4738
(int) procInfo->procStartTime,
4551
4740
if (VIX_OK != err) {
4680
4867
impersonatingVMWareUser = TRUE;
4869
#if defined(__APPLE__)
4871
* On MacOS, to fetch info on processes owned by others
4872
* we need to be root. Even /bin/ps and /bin/top in
4873
* MacOS have the setuid bit set to allow any user
4874
* list all processes. For linux & FreeBSD, this API
4875
* does return info on all processes by all users. So
4876
* to keep the result consistent on MacOS, we need to
4877
* stop impersonating user for this API.
4879
* NOTE: We still do the impersonation before this
4880
* to authenticate the user as usual.
4882
VixToolsUnimpersonateUser(userToken);
4883
impersonatingVMWareUser = FALSE;
4682
4886
key = listRequest->key;
4683
4887
offset = listRequest->offset;
4691
4895
// find the cached data
4692
4896
cachedResult = g_hash_table_lookup(listProcessesResultsTable,
4694
4898
if (NULL == cachedResult) {
4695
4899
Debug("%s: failed to find cached data with key %d\n", __FUNCTION__, key);
4696
4900
err = VIX_E_FAIL;
4763
4967
* Save it off in the hashtable.
4765
keyBuf = Util_SafeMalloc(sizeof(uint32));
4766
4969
key = listProcessesResultsKey++;
4768
cachedResult = Util_SafeMalloc(sizeof(VixToolsCachedListProcessesResult));
4970
cachedResult = Util_SafeMalloc(sizeof(*cachedResult));
4769
4971
cachedResult->resultBufferLen = fullResultSize;
4770
4972
cachedResult->resultBuffer = fullResultBuffer;
4973
cachedResult->key = key;
4772
4975
bRet = VixToolsGetUserName(&cachedResult->userName);
4778
4981
cachedResult->euid = Id_GetEUid();
4781
g_hash_table_insert(listProcessesResultsTable, keyBuf, cachedResult);
4984
g_hash_table_replace(listProcessesResultsTable, &cachedResult->key,
4784
4988
* Set timer callback to clean this up in case the Vix side
4785
4989
* never finishes
4787
timerData = Util_SafeMalloc(sizeof(int32));
4788
*timerData = *keyBuf;
4789
4991
timer = g_timeout_source_new(SECONDS_UNTIL_LISTPROC_CACHE_CLEANUP * 1000);
4790
g_source_set_callback(timer, VixToolsListProcCacheCleanup, timerData, NULL);
4992
g_source_set_callback(timer, VixToolsListProcCacheCleanup,
4993
(void *)(intptr_t) key, NULL);
4791
4994
g_source_attach(timer, g_main_loop_get_context(eventQueue));
4792
4995
g_source_unref(timer);
5689
5892
fileExtendedInfoBufferSize += 10 + 20 + (20 * 2); // properties + size + times
5691
5894
fileExtendedInfoBufferSize += 20; // createTime
5692
#elif defined(linux) || defined(sun)
5693
5896
fileExtendedInfoBufferSize += 10 * 3; // uid, gid, perms
5696
#if defined(linux) || defined(sun)
5899
#if defined(linux) || defined(sun) || defined(__FreeBSD__)
5697
5900
if (File_IsSymLink(filePathName)) {
5698
5901
char *symlinkTarget;
5699
5902
symlinkTarget = Posix_ReadLink(filePathName);
6188
6386
if (Posix_Stat(filePathName, &statbuf) != -1) {
6189
#if defined(linux) || defined(sun)
6387
#if !defined(_WIN32)
6190
6388
ownerId = statbuf.st_uid;
6191
6389
groupId = statbuf.st_gid;
6192
6390
permissions = statbuf.st_mode;
6446
6643
if (PROCESS_CREATOR_USER_TOKEN != userToken) {
6447
6644
err = VixToolsGetUserTmpDir(userToken, &tempDirPath);
6450
6647
* Don't give up if VixToolsGetUserTmpDir() failed. It might just
6451
6648
* have failed to load DLLs, so we might be running on Win 9x.
6452
6649
* Just fall through to use the old fashioned File_GetSafeTmpDir().
6466
6663
for (var = 0; var <= 0xFFFFFFFF; var++) {
6467
6664
free(tempScriptFilePath);
6468
tempScriptFilePath = Str_Asprintf(NULL,
6469
"%s"DIRSEPS"%s%d%s",
6665
tempScriptFilePath = Str_Asprintf(NULL,
6666
"%s"DIRSEPS"%s%d%s",
6474
6671
if (NULL == tempScriptFilePath) {
6475
6672
err = VIX_E_OUT_OF_MEMORY;
6479
6676
fd = Posix_Open(tempScriptFilePath, // UTF-8
6480
6677
O_CREAT | O_EXCL
6481
6678
#if defined(_WIN32)
6531
6728
if (writeResult < 0) {
6533
* Yes, I'm duplicating code by running this check before the call to
6730
* Yes, I'm duplicating code by running this check before the call to
6534
6731
* close(), but if close() succeeds it will clobber the errno, causing
6535
6732
* something confusing to be reported to the user.
6694
6891
credentialType = requestMsg->userCredentialType;
6696
if (VIX_USER_CREDENTIAL_TICKETED_SESSION == credentialType) {
6893
switch (credentialType) {
6894
case VIX_USER_CREDENTIAL_TICKETED_SESSION:
6697
6896
VixCommandTicketedSession *commandTicketedSession = (VixCommandTicketedSession *) credentialField;
6698
6897
size_t ticketLength = commandTicketedSession->ticketLength;
6708
6907
credentialType,
6709
6908
credentialField,
6712
} else if (VIX_USER_CREDENTIAL_SSPI == credentialType) {
6714
* SSPI currently only supported in ticketed sessions
6716
err = VIX_E_NOT_SUPPORTED;
6719
VixCommandNamePassword *namePasswordStruct = (VixCommandNamePassword *) credentialField;
6912
case VIX_USER_CREDENTIAL_ROOT:
6913
case VIX_USER_CREDENTIAL_CONSOLE_USER:
6914
err = VixToolsImpersonateUserImplEx(NULL,
6919
case VIX_USER_CREDENTIAL_NAME_PASSWORD:
6920
case VIX_USER_CREDENTIAL_NAME_PASSWORD_OBFUSCATED:
6921
case VIX_USER_CREDENTIAL_NAMED_INTERACTIVE_USER:
6923
VixCommandNamePassword *namePasswordStruct =
6924
(VixCommandNamePassword *) credentialField;
6720
6925
credentialField += sizeof(*namePasswordStruct);
6722
6927
err = VixToolsImpersonateUserImplEx(NULL,
6724
6929
credentialField,
6726
6931
if ((VIX_OK != err)
6727
&& ((VIX_USER_CREDENTIAL_NAME_PASSWORD_OBFUSCATED == credentialType)
6728
|| (VIX_USER_CREDENTIAL_NAME_PASSWORD == credentialType))) {
6932
&& ((VIX_USER_CREDENTIAL_NAME_PASSWORD_OBFUSCATED == credentialType)
6933
|| (VIX_USER_CREDENTIAL_NAME_PASSWORD == credentialType))) {
6730
6935
* Windows does not allow you to login with an empty password. Only
6731
6936
* the console allows this login, which means the console does not
6951
case VIX_USER_CREDENTIAL_SSPI:
6953
* SSPI currently only supported in ticketed sessions
6956
Debug("%s: credentialType = %d\n", __FUNCTION__, credentialType);
6957
err = VIX_E_NOT_SUPPORTED;
6746
6960
Debug("<%s\n", __FUNCTION__);
6785
6999
* VixToolsImpersonateUserImplEx --
6788
* To retrieve the security context of another user
6789
* call LogonUser to log the user whom you want to impersonate on to the
6790
* local computer, specifying the name of the user account, the user's
6791
* domain, and the user's password. This function returns a pointer to
7002
* To retrieve the security context of another user
7003
* call LogonUser to log the user whom you want to impersonate on to the
7004
* local computer, specifying the name of the user account, the user's
7005
* domain, and the user's password. This function returns a pointer to
6792
7006
* a handle to the access token of the logged-on user as an out parameter.
6793
* Call ImpersonateLoggedOnUser using the handle to the access token obtained
7007
* Call ImpersonateLoggedOnUser using the handle to the access token obtained
6794
7008
* in the call to LogonUser.
6795
* Run RegEdt32 to load the registry hive of the impersonated user manually.
7009
* Run RegEdt32 to load the registry hive of the impersonated user manually.
6797
7011
* Return value:
6798
7012
* VIX_OK on success, or an appropriate error code on failure.
6819
7033
*userToken = NULL;
6821
7035
///////////////////////////////////////////////////////////////////////
6822
#if defined(__FreeBSD__)
6823
err = VIX_E_NOT_SUPPORTED;
7036
// NOTE: The following lines need to be uncommented to disable either
7037
// FreeBSD and/or MacOS support for VMODL Guest Operations completely.
7038
//#if defined(__FreeBSD__)
7039
// return VIX_E_NOT_SUPPORTED;
7041
//#if defined(__APPLE__)
7042
// return VIX_E_NOT_SUPPORTED;
6824
7044
///////////////////////////////////////////////////////////////////////
6825
#elif defined(_WIN32) || defined(linux) || defined(sun)
6827
7046
AuthToken authToken;
6828
7047
char *unobfuscatedUserName = NULL;
7488
7698
hgfsReplyPacketSize = sizeof hgfsReplyPacket;
7490
#if !defined(__FreeBSD__)
7492
7701
* Impersonation was okay, so let's give our packet to
7493
7702
* the HGFS server and forward the reply packet back.
7497
7706
requestMsg->hgfsPacketSize, // packet in size
7498
7707
hgfsReplyPacket, // packet out buf
7499
7708
&hgfsReplyPacketSize); // in/out size
7710
if (eventQueue != NULL) {
7712
* Register a timer to periodically invalidate any inactive
7715
VixToolsRegisterHgfsSessionInvalidator(eventQueue);
7502
7718
if (NULL != resultValueResult) {
7503
7719
*resultValueResult = hgfsReplyPacketSize;
7901
8117
#if defined(__linux__) || defined(_WIN32)
7903
8119
VixToolsGetGuestNetworkingConfig(VixCommandRequestHeader *requestMsg, // IN
7904
8120
char **resultBuffer, // OUT
7905
8121
size_t *resultBufferLength) // OUT
8007
8223
VixPropertyListImpl propList;
8008
8224
VixPropertyValue *propertyPtr = NULL;
8009
8225
char *messageBody = NULL;
8010
char ipAddr[IP_ADDR_SIZE];
8226
char ipAddr[IP_ADDR_SIZE];
8011
8227
char subnetMask[IP_ADDR_SIZE];
8012
8228
Bool dhcpEnabled = FALSE;
8015
8231
ASSERT(NULL != requestMsg);
8018
8234
subnetMask[0] = '\0';
8020
8236
err = VixToolsImpersonateUser(requestMsg, &userToken);
8021
8237
if (VIX_OK != err) {
8027
8243
messageBody = (char *) requestMsg + sizeof(*setGuestNetworkingConfigRequest);
8029
8245
VixPropertyList_Initialize(&propList);
8030
err = VixPropertyList_Deserialize(&propList,
8246
err = VixPropertyList_Deserialize(&propList,
8032
8248
setGuestNetworkingConfigRequest -> bufferSize,
8033
8249
VIX_PROPERTY_LIST_BAD_ENCODING_ERROR);
8034
8250
if (VIX_OK != err) {
8040
8256
switch (propertyPtr->propertyID) {
8041
8257
///////////////////////////////////////////
8042
8258
case VIX_PROPERTY_VM_DHCP_ENABLED:
8043
if (propertyPtr->value.boolValue) {
8259
if (propertyPtr->value.boolValue) {
8044
8260
dhcpEnabled = TRUE;
8048
///////////////////////////////////////////
8264
///////////////////////////////////////////
8049
8265
case VIX_PROPERTY_VM_IP_ADDRESS:
8050
8266
if (strlen(propertyPtr->value.strValue) < sizeof ipAddr) {
8051
8267
Str_Strcpy(ipAddr,
8052
propertyPtr->value.strValue,
8268
propertyPtr->value.strValue,
8053
8269
sizeof ipAddr);
8055
8271
err = VIX_E_INVALID_ARG;
8060
8276
///////////////////////////////////////////
8061
8277
case VIX_PROPERTY_VM_SUBNET_MASK:
8062
8278
if (strlen(propertyPtr->value.strValue) < sizeof subnetMask) {
8063
Str_Strcpy(subnetMask,
8279
Str_Strcpy(subnetMask,
8064
8280
propertyPtr->value.strValue,
8067
8283
err = VIX_E_INVALID_ARG;
8072
8288
///////////////////////////////////////////
8075
8291
* Be more tolerant. Igonore unknown properties.
8080
8296
propertyPtr = propertyPtr->next;
8081
8297
} // while {propList.properties != NULL)
8084
8300
hrErr = VixToolsEnableDHCPOnPrimary();
8086
8302
if (('\0' != ipAddr[0]) ||
8087
('\0' != subnetMask[0])) {
8303
('\0' != subnetMask[0])) {
8088
8304
hrErr = VixToolsEnableStaticOnPrimary(ipAddr, subnetMask);
8275
8490
struct passwd *ppwd = &pwd;
8276
8491
char *buffer = NULL; // a pool of memory for Posix_Getpwnam_r() to use.
8277
8492
size_t bufferSize;
8280
8495
* For POSIX systems, look up the uid of 'username', and compare
8281
8496
* it to the uid of the owner of this process. This handles systems
8282
8497
* where multiple usernames map to the name user.
8286
8501
* Get the maximum size buffer needed by getpwuid_r.
8287
8502
* Multiply by 4 to compensate for the conversion to UTF-8 by
8294
8509
if (Posix_Getpwnam_r(username, &pwd, buffer, bufferSize, &ppwd) != 0 ||
8295
8510
NULL == ppwd) {
8297
8512
* This username should exist, since it should have already
8298
8513
* been validated by guestd. Assume it is a system error.
8746
8960
///////////////////////////////////
8747
8961
case VMXI_HGFS_SEND_PACKET_COMMAND:
8748
8962
err = VixToolsProcessHgfsPacket((VixCommandHgfsSendPacket *) requestMsg,
8750
8965
&resultValueLength);
8751
8966
deleteResultValue = FALSE; // TRUE;
8760
8975
&resultValueLength);
8761
8976
if (VIX_FAILED(err)) {
8763
* VixToolsGetGuestNetworkingConfig() failed, so resultVal is still NULL,
8764
* so let it get replaced with the empty string at the abort label.
8978
* VixToolsGetGuestNetworkingConfig() failed, so resultVal is still NULL,
8979
* so let it get replaced with the empty string at the abort label.
9014
9229
*-----------------------------------------------------------------------------
9016
9231
* VixToolsEnableDHCPOnPrimary --
9018
9233
* Enable DHCP on primary NIC. A primary NIC is the
9019
9234
* first interface you get using ipconfig. You can change the order
9020
9235
* of NIC cards on a computer via Windows GUI.
9051
9266
*-----------------------------------------------------------------------------
9053
9268
* VixToolsEnableStaticOnPrimary --
9055
* Set the IP address and/or subnet mask of the primary NIC. A primary NIC
9270
* Set the IP address and/or subnet mask of the primary NIC. A primary NIC
9056
9271
* is the first interface you get using ipconfig. You can change the order
9057
* of NIC cards on a computer via Windows GUI.
9272
* of NIC cards on a computer via Windows GUI.
9060
9275
* S_OK on success. COM error codes on failure.
9062
9277
* Side effects:
9065
9280
*-----------------------------------------------------------------------------
9110
9325
if ('\0' != subnetMask[0]) {
9111
9326
Str_Strcpy(actualSubnetMask,
9113
9328
sizeof actualSubnetMask);
9115
9330
Str_Strcpy(actualSubnetMask,
9117
9332
sizeof actualSubnetMask);
9120
ret = WMI_EnableStatic(primaryNic->macAddress,
9335
ret = WMI_EnableStatic(primaryNic->macAddress,
9122
9337
actualSubnetMask);
9124
9339
VMX_XDR_FREE(xdr_GuestNic, primaryNic);