Changeset 93015 in vbox for trunk/src/VBox/VMM/VMMR3
- Timestamp:
- Dec 17, 2021 11:44:08 AM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 149004
- Location:
- trunk/src/VBox/VMM/VMMR3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR3/CFGM.cpp
r82968 r93015 681 681 682 682 case CFGMVALUETYPE_STRING: 683 case CFGMVALUETYPE_PASSWORD: 683 684 *pcb = pLeaf->Value.String.cb; 684 685 break; … … 863 864 rc = VERR_CFGM_NOT_BYTES; 864 865 } 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 */ 879 VMMR3DECL(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 */ 913 VMMR3DECL(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 865 948 return rc; 866 949 } … … 2033 2116 2034 2117 case CFGMVALUETYPE_STRING: 2118 case CFGMVALUETYPE_PASSWORD: 2035 2119 cfgmR3StrFree(pVM, pLeaf->Value.String.psz); 2036 2120 pLeaf->Value.String.psz = NULL; … … 2292 2376 2293 2377 /** 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 */ 2388 VMMR3DECL(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 */ 2437 VMMR3DECL(int) CFGMR3InsertPassword(PCFGMNODE pNode, const char *pszName, const char *pszString) 2438 { 2439 return CFGMR3InsertPasswordN(pNode, pszName, pszString, strlen(pszString)); 2440 } 2441 2442 2443 /** 2294 2444 * Make a copy of the specified value under the given node. 2295 2445 * … … 2313 2463 case CFGMVALUETYPE_STRING: 2314 2464 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); 2315 2469 break; 2316 2470 … … 3251 3405 break; 3252 3406 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 3253 3411 default: 3254 3412 AssertMsgFailed(("bad leaf!\n")); -
trunk/src/VBox/VMM/VMMR3/PDMDevHlp.cpp
r92527 r93015 4966 4966 CFGMR3QueryString, 4967 4967 CFGMR3QueryStringDef, 4968 CFGMR3QueryPassword, 4969 CFGMR3QueryPasswordDef, 4968 4970 CFGMR3QueryBytes, 4969 4971 CFGMR3QueryU64, … … 5363 5365 CFGMR3QueryString, 5364 5366 CFGMR3QueryStringDef, 5367 CFGMR3QueryPassword, 5368 CFGMR3QueryPasswordDef, 5365 5369 CFGMR3QueryBytes, 5366 5370 CFGMR3QueryU64, … … 6083 6087 CFGMR3QueryString, 6084 6088 CFGMR3QueryStringDef, 6089 CFGMR3QueryPassword, 6090 CFGMR3QueryPasswordDef, 6085 6091 CFGMR3QueryBytes, 6086 6092 CFGMR3QueryU64, -
trunk/src/VBox/VMM/VMMR3/PDMDriver.cpp
r91955 r93015 2167 2167 CFGMR3QueryString, 2168 2168 CFGMR3QueryStringDef, 2169 CFGMR3QueryPassword, 2170 CFGMR3QueryPasswordDef, 2169 2171 CFGMR3QueryBytes, 2170 2172 CFGMR3QueryU64, -
trunk/src/VBox/VMM/VMMR3/VMMR3.def
r90549 r93015 41 41 CFGMR3InsertStringW 42 42 CFGMR3InsertInteger 43 CFGMR3InsertPasswordN 44 CFGMR3InsertPassword 43 45 CFGMR3QueryStringAllocDef 44 46 CFGMR3RemoveValue
Note:
See TracChangeset
for help on using the changeset viewer.