VirtualBox

Changeset 93015 in vbox for trunk/src/VBox/VMM/VMMR3


Ignore:
Timestamp:
Dec 17, 2021 11:44:08 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
149004
Message:

CFGM: bugref:9469 Password data type introduced

Location:
trunk/src/VBox/VMM/VMMR3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/CFGM.cpp

    r82968 r93015  
    681681
    682682            case CFGMVALUETYPE_STRING:
     683            case CFGMVALUETYPE_PASSWORD:
    683684                *pcb = pLeaf->Value.String.cb;
    684685                break;
     
    863864            rc = VERR_CFGM_NOT_BYTES;
    864865    }
     866    return rc;
     867}
     868
     869
     870/**
     871 * Query zero terminated character value.
     872 *
     873 * @returns VBox status code.
     874 * @param   pNode           Which node to search for pszName in.
     875 * @param   pszName         Name of a zero terminate character value.
     876 * @param   pszString       Where to store the string.
     877 * @param   cchString       Size of the string buffer. (Includes terminator.)
     878 */
     879VMMR3DECL(int) CFGMR3QueryPassword(PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString)
     880{
     881    PCFGMLEAF pLeaf;
     882    int rc = cfgmR3ResolveLeaf(pNode, pszName, &pLeaf);
     883    if (RT_SUCCESS(rc))
     884    {
     885        if (pLeaf->enmType == CFGMVALUETYPE_PASSWORD)
     886        {
     887            size_t cbSrc = pLeaf->Value.String.cb;
     888            if (cchString >= cbSrc)
     889            {
     890                memcpy(pszString, pLeaf->Value.String.psz, cbSrc);
     891                memset(pszString + cbSrc, 0, cchString - cbSrc);
     892            }
     893            else
     894                rc = VERR_CFGM_NOT_ENOUGH_SPACE;
     895        }
     896        else
     897            rc = VERR_CFGM_NOT_PASSWORD;
     898    }
     899    return rc;
     900}
     901
     902
     903/**
     904 * Query zero terminated character value with default.
     905 *
     906 * @returns VBox status code.
     907 * @param   pNode           Which node to search for pszName in.
     908 * @param   pszName         Name of a zero terminate character value.
     909 * @param   pszString       Where to store the string. This will not be set on overflow error.
     910 * @param   cchString       Size of the string buffer. (Includes terminator.)
     911 * @param   pszDef          The default value.
     912 */
     913VMMR3DECL(int) CFGMR3QueryPasswordDef(PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString, const char *pszDef)
     914{
     915    PCFGMLEAF pLeaf;
     916    int rc = cfgmR3ResolveLeaf(pNode, pszName, &pLeaf);
     917    if (RT_SUCCESS(rc))
     918    {
     919        if (pLeaf->enmType == CFGMVALUETYPE_PASSWORD)
     920        {
     921            size_t cbSrc = pLeaf->Value.String.cb;
     922            if (cchString >= cbSrc)
     923            {
     924                memcpy(pszString, pLeaf->Value.String.psz, cbSrc);
     925                memset(pszString + cbSrc, 0, cchString - cbSrc);
     926            }
     927            else
     928                rc = VERR_CFGM_NOT_ENOUGH_SPACE;
     929        }
     930        else
     931            rc = VERR_CFGM_NOT_PASSWORD;
     932    }
     933
     934    if (RT_FAILURE(rc) && rc != VERR_CFGM_NOT_ENOUGH_SPACE)
     935    {
     936        size_t cchDef = strlen(pszDef);
     937        if (cchString > cchDef)
     938        {
     939            memcpy(pszString, pszDef, cchDef);
     940            memset(pszString + cchDef, 0, cchString - cchDef);
     941            if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
     942                rc = VINF_SUCCESS;
     943        }
     944        else if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
     945            rc = VERR_CFGM_NOT_ENOUGH_SPACE;
     946    }
     947
    865948    return rc;
    866949}
     
    20332116
    20342117            case CFGMVALUETYPE_STRING:
     2118            case CFGMVALUETYPE_PASSWORD:
    20352119                cfgmR3StrFree(pVM, pLeaf->Value.String.psz);
    20362120                pLeaf->Value.String.psz = NULL;
     
    22922376
    22932377/**
     2378 * Inserts a new password value. This variant expects that the caller know the length
     2379 * of the password string already so we can avoid calling strlen() here.
     2380 *
     2381 * @returns VBox status code.
     2382 * @param   pNode           Parent node.
     2383 * @param   pszName         Value name.
     2384 * @param   pszString       The value. Must not be NULL.
     2385 * @param   cchString       The length of the string excluding the
     2386 *                          terminator.
     2387 */
     2388VMMR3DECL(int) CFGMR3InsertPasswordN(PCFGMNODE pNode, const char *pszName, const char *pszString, size_t cchString)
     2389{
     2390    Assert(RTStrNLen(pszString, cchString) == cchString);
     2391
     2392    int rc;
     2393    if (pNode)
     2394    {
     2395        /*
     2396         * Allocate string object first.
     2397         */
     2398        char *pszStringCopy = (char *)cfgmR3StrAlloc(pNode->pVM, MM_TAG_CFGM_STRING, cchString + 1);
     2399        if (pszStringCopy)
     2400        {
     2401            memcpy(pszStringCopy, pszString, cchString);
     2402            pszStringCopy[cchString] = '\0';
     2403
     2404            /*
     2405             * Create value leaf and set it to string type.
     2406             */
     2407            PCFGMLEAF pLeaf;
     2408            rc = cfgmR3InsertLeaf(pNode, pszName, &pLeaf);
     2409            if (RT_SUCCESS(rc))
     2410            {
     2411                pLeaf->enmType = CFGMVALUETYPE_PASSWORD;
     2412                pLeaf->Value.String.psz = pszStringCopy;
     2413                pLeaf->Value.String.cb  = cchString + 1;
     2414            }
     2415            else
     2416                cfgmR3StrFree(pNode->pVM, pszStringCopy);
     2417        }
     2418        else
     2419            rc = VERR_NO_MEMORY;
     2420    }
     2421    else
     2422        rc = VERR_CFGM_NO_PARENT;
     2423
     2424    return rc;
     2425}
     2426
     2427
     2428/**
     2429 * Inserts a new password value. Calls strlen(pszString) internally; if you know the
     2430 * length of the string, CFGMR3InsertStringLengthKnown() is faster.
     2431 *
     2432 * @returns VBox status code.
     2433 * @param   pNode           Parent node.
     2434 * @param   pszName         Value name.
     2435 * @param   pszString       The value.
     2436 */
     2437VMMR3DECL(int) CFGMR3InsertPassword(PCFGMNODE pNode, const char *pszName, const char *pszString)
     2438{
     2439    return CFGMR3InsertPasswordN(pNode, pszName, pszString, strlen(pszString));
     2440}
     2441
     2442
     2443/**
    22942444 * Make a copy of the specified value under the given node.
    22952445 *
     
    23132463        case CFGMVALUETYPE_STRING:
    23142464            rc = CFGMR3InsertStringN(pNode, pValue->szName, pValue->Value.String.psz, pValue->Value.String.cb - 1);
     2465            break;
     2466
     2467        case CFGMVALUETYPE_PASSWORD:
     2468            rc = CFGMR3InsertPasswordN(pNode, pValue->szName, pValue->Value.String.psz, pValue->Value.String.cb - 1);
    23152469            break;
    23162470
     
    32513405                break;
    32523406
     3407            case CFGMVALUETYPE_PASSWORD:
     3408                pHlp->pfnPrintf(pHlp, "  %-*s <password>= \"***REDACTED***\" (cb=%zu)\n", (int)cchMax, pLeaf->szName, pLeaf->Value.String.cb);
     3409                break;
     3410
    32533411            default:
    32543412                AssertMsgFailed(("bad leaf!\n"));
  • trunk/src/VBox/VMM/VMMR3/PDMDevHlp.cpp

    r92527 r93015  
    49664966    CFGMR3QueryString,
    49674967    CFGMR3QueryStringDef,
     4968    CFGMR3QueryPassword,
     4969    CFGMR3QueryPasswordDef,
    49684970    CFGMR3QueryBytes,
    49694971    CFGMR3QueryU64,
     
    53635365    CFGMR3QueryString,
    53645366    CFGMR3QueryStringDef,
     5367    CFGMR3QueryPassword,
     5368    CFGMR3QueryPasswordDef,
    53655369    CFGMR3QueryBytes,
    53665370    CFGMR3QueryU64,
     
    60836087    CFGMR3QueryString,
    60846088    CFGMR3QueryStringDef,
     6089    CFGMR3QueryPassword,
     6090    CFGMR3QueryPasswordDef,
    60856091    CFGMR3QueryBytes,
    60866092    CFGMR3QueryU64,
  • trunk/src/VBox/VMM/VMMR3/PDMDriver.cpp

    r91955 r93015  
    21672167    CFGMR3QueryString,
    21682168    CFGMR3QueryStringDef,
     2169    CFGMR3QueryPassword,
     2170    CFGMR3QueryPasswordDef,
    21692171    CFGMR3QueryBytes,
    21702172    CFGMR3QueryU64,
  • trunk/src/VBox/VMM/VMMR3/VMMR3.def

    r90549 r93015  
    4141    CFGMR3InsertStringW
    4242    CFGMR3InsertInteger
     43    CFGMR3InsertPasswordN
     44    CFGMR3InsertPassword
    4345    CFGMR3QueryStringAllocDef
    4446    CFGMR3RemoveValue
Note: See TracChangeset for help on using the changeset viewer.

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