VirtualBox

Changeset 104275 in vbox


Ignore:
Timestamp:
Apr 10, 2024 1:22:11 PM (8 months ago)
Author:
vboxsync
Message:

VBoxSDS: Better check for log directory locations. bugref:10632

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-global/win/VBoxSDS.cpp

    r104152 r104275  
    105105#include <iprt/dir.h>
    106106#include <iprt/env.h>
     107#include <iprt/err.h>
    107108#include <iprt/getopt.h>
    108109#include <iprt/initterm.h>
     
    961962
    962963    /*
    963      * Default log location is %ProgramData%\VirtualBox\VBoxSDS.log, falling back
    964      * on %_CWD%\VBoxSDS.log (where _CWD typicaly is 'C:\Windows\System32').
     964     * Default log location (LOGDIR) is %APPDATA%\VirtualBox\VBoxSDS.log.
    965965     *
    966      * We change the current directory to %ProgramData%\VirtualBox\ if possible.
     966     * When running VBoxSDS as a regular user, LOGDIR typically will be 'C:\Users\<User>\AppData\Roaming\VirtualBox\'.
     967     * When running VBoxSDS as a service (via SCM), LOGDIR typically will be 'C:\Windows\System32\config\systemprofile\AppData\Roaming\VirtualBox\'.
     968     *
     969     * We change the current directory to LOGDIR if possible.
     970     *
     971     * See @bugref{10632}.
    967972     *
    968973     * We only create the log file when running VBoxSDS normally, but not
     
    974979        if (!pszLogFile || !*pszLogFile)
    975980        {
    976             WCHAR wszAppData[MAX_PATH + 16];
    977             if (SHGetSpecialFolderPathW(NULL, wszAppData, CSIDL_COMMON_APPDATA, TRUE /*fCreate*/))
     981            WCHAR wszSpecialFolder[MAX_PATH + 16];
     982            if (SHGetSpecialFolderPathW(NULL, wszSpecialFolder, CSIDL_APPDATA, TRUE /*fCreate*/))
    978983            {
    979984                char *pszConv = szLogFile;
    980                 vrc = RTUtf16ToUtf8Ex(wszAppData, RTSTR_MAX, &pszConv, sizeof(szLogFile) - 12, NULL);
    981             }
    982             else
    983                 vrc = RTEnvGetUtf8("ProgramData", szLogFile, sizeof(szLogFile) - sizeof("VBoxSDS.log"), NULL);
     985                vrc = RTUtf16ToUtf8Ex(wszSpecialFolder, RTSTR_MAX, &pszConv, sizeof(szLogFile) - 12, NULL);
     986            }
     987            else if (SHGetSpecialFolderPathW(NULL, wszSpecialFolder, CSIDL_SYSTEM, TRUE /*fCreate*/))
     988            {
     989                char *pszConv = szLogFile;
     990                vrc = RTUtf16ToUtf8Ex(wszSpecialFolder, RTSTR_MAX, &pszConv, sizeof(szLogFile) - 12, NULL);
     991            }
     992            else /* Note! No fallback to environment variables or such. See @bugref{10632}. */
     993                vrc = VERR_PATH_NOT_FOUND;
    984994            if (RT_SUCCESS(vrc))
    985995            {
     
    9921002                    if (RT_SUCCESS(vrc))
    9931003                    {
    994                         /* Change into it. */
    995                         RTPathSetCurrent(szLogFile);
     1004                        /* Change into it.
     1005                         * If this fails, better don't continue, as there might be something fishy. */
     1006                        vrc = RTPathSetCurrent(szLogFile);
     1007                        if (RT_SUCCESS(vrc))
     1008                            vrc = RTStrCat(szLogFile, sizeof(szLogFile), "VBoxSDS.log");
    9961009                    }
    9971010                }
    9981011            }
    999             if (RT_FAILURE(vrc))     /* ignore any failure above */
    1000                 szLogFile[0] = '\0';
    1001             vrc = RTStrCat(szLogFile, sizeof(szLogFile), "VBoxSDS.log");
    10021012            if (RT_FAILURE(vrc))
    10031013                return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to construct release log filename: %Rrc", vrc);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette