- Timestamp:
- Dec 10, 2010 5:18:57 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ExtPackUtil.cpp
r34893 r34965 746 746 747 747 RTManifestRelease(hTheirManifest); 748 return rc; 749 } 750 751 752 /** 753 * Validates a standard file. 754 * 755 * Generally all files are 756 * 757 * @returns VBox status code, failure message in @a pszError. 758 * @param pszAdjName The adjusted member name. 759 * @param enmType The VFS object type. 760 * @param phVfsObj The pointer to the VFS object handle variable. 761 * This is both input and output. 762 * @param phVfsFile Where to store the handle to the memorized 763 * file. This is NULL for license files. 764 * @param pszError Where to write an error message on failure. 765 * @param cbError The size of the @a pszError buffer. 766 */ 767 static int VBoxExtPackValidateStandardFile(const char *pszAdjName, RTVFSOBJTYPE enmType, 768 PRTVFSOBJ phVfsObj, PRTVFSFILE phVfsFile, char *pszError, size_t cbError) 769 { 770 int rc; 771 772 /* 773 * Make sure it's a file and that it isn't too large. 774 */ 775 if (phVfsFile && *phVfsFile != NIL_RTVFSFILE) 776 rc = vboxExtPackReturnError(VERR_DUPLICATE, pszError, cbError, 777 "There can only be one '%s'", pszAdjName); 778 else if (enmType != RTVFSOBJTYPE_IO_STREAM && enmType != RTVFSOBJTYPE_FILE) 779 rc = vboxExtPackReturnError(VERR_NOT_A_FILE, pszError, cbError, 780 "Standard member '%s' is not a file", pszAdjName); 781 else 782 { 783 RTFSOBJINFO ObjInfo; 784 rc = RTVfsObjQueryInfo(*phVfsObj, &ObjInfo, RTFSOBJATTRADD_NOTHING); 785 if (RT_SUCCESS(rc)) 786 { 787 if (!RTFS_IS_FILE(ObjInfo.Attr.fMode)) 788 rc = vboxExtPackReturnError(VERR_NOT_A_FILE, pszError, cbError, 789 "Standard member '%s' is not a file", pszAdjName); 790 else if (ObjInfo.cbObject >= _1M) 791 rc = vboxExtPackReturnError(VERR_OUT_OF_RANGE, pszError, cbError, 792 "Standard member '%s' is too large: %'RU64 bytes (max 1 MB)", 793 pszAdjName, (uint64_t)ObjInfo.cbObject); 794 else 795 { 796 /* 797 * Make an in memory copy of the stream and check that the file 798 * is UTF-8 clean. 799 */ 800 RTVFSIOSTREAM hVfsIos = RTVfsObjToIoStream(*phVfsObj); 801 RTVFSFILE hVfsFile; 802 rc = RTVfsMemorizeIoStreamAsFile(hVfsIos, RTFILE_O_READ, &hVfsFile); 803 if (RT_SUCCESS(rc)) 804 { 805 rc = RTVfsIoStrmValidateUtf8Encoding(hVfsIos); 806 if (RT_SUCCESS(rc)) 807 { 808 /* 809 * Replace *phVfsObj with the memorized file. 810 */ 811 rc = RTVfsFileSeek(hVfsFile, 0, RTFILE_SEEK_BEGIN, NULL); 812 if (RT_SUCCESS(rc)) 813 { 814 RTVfsObjRelease(*phVfsObj); 815 *phVfsObj = RTVfsObjFromFile(hVfsFile); 816 } 817 else 818 vboxExtPackSetError(pszError, cbError, "RTVfsFileSeek failed on '%s': %Rrc", pszAdjName, rc); 819 } 820 821 if (phVfsFile && RT_SUCCESS(rc)) 822 *phVfsFile = hVfsFile; 823 else 824 RTVfsFileRelease(hVfsFile); 825 } 826 else 827 vboxExtPackSetError(pszError, cbError, "RTVfsMemorizeIoStreamAsFile failed on '%s': %Rrc", pszAdjName, rc); 828 RTVfsIoStrmRelease(hVfsIos); 829 } 830 } 831 else 832 vboxExtPackSetError(pszError, cbError, "RTVfsObjQueryInfo failed on '%s': %Rrc", pszAdjName, rc); 833 } 748 834 return rc; 749 835 } … … 1040 1126 1041 1127 /* 1042 * Check the type & name validity. 1128 * Check the type & name validity, performing special tests on 1129 * standard extension pack member files. 1043 1130 * 1044 1131 * N.B. We will always reach the end of the loop before breaking on … … 1048 1135 if (RT_SUCCESS(rc)) 1049 1136 { 1050 /*1051 * Check if this is one of the standard files.1052 */1053 1137 PRTVFSFILE phVfsFile; 1054 1138 if (!strcmp(pszAdjName, VBOX_EXTPACK_DESCRIPTION_NAME)) … … 1058 1142 else if (!strcmp(pszAdjName, VBOX_EXTPACK_SIGNATURE_NAME)) 1059 1143 phVfsFile = &hSignatureFile; 1144 else if (!strncmp(pszAdjName, VBOX_EXTPACK_LICENSE_NAME_PREFIX, sizeof(VBOX_EXTPACK_LICENSE_NAME_PREFIX) - 1)) 1145 rc = VBoxExtPackValidateStandardFile(pszAdjName, enmType, &hVfsObj, NULL, pszError, cbError); 1060 1146 else 1061 1147 phVfsFile = NULL; 1062 1148 if (phVfsFile) 1063 { 1064 /* 1065 * Make sure it's a file and that it isn't too large. 1066 */ 1067 if (*phVfsFile != NIL_RTVFSFILE) 1068 rc = vboxExtPackReturnError(VERR_DUPLICATE, pszError, cbError, 1069 "There can only be one '%s'", pszAdjName); 1070 else if (enmType != RTVFSOBJTYPE_IO_STREAM && enmType != RTVFSOBJTYPE_FILE) 1071 rc = vboxExtPackReturnError(VERR_NOT_A_FILE, pszError, cbError, 1072 "Standard member '%s' is not a file", pszAdjName); 1073 else 1074 { 1075 RTFSOBJINFO ObjInfo; 1076 rc = RTVfsObjQueryInfo(hVfsObj, &ObjInfo, RTFSOBJATTRADD_NOTHING); 1077 if (RT_SUCCESS(rc)) 1078 { 1079 if (!RTFS_IS_FILE(ObjInfo.Attr.fMode)) 1080 rc = vboxExtPackReturnError(VERR_NOT_A_FILE, pszError, cbError, 1081 "Standard member '%s' is not a file", pszAdjName); 1082 else if (ObjInfo.cbObject >= _1M) 1083 rc = vboxExtPackReturnError(VERR_OUT_OF_RANGE, pszError, cbError, 1084 "Standard member '%s' is too large: %'RU64 bytes (max 1 MB)", 1085 pszAdjName, (uint64_t)ObjInfo.cbObject); 1086 else 1087 { 1088 /* 1089 * Make an in memory copy of the stream. 1090 */ 1091 RTVFSIOSTREAM hVfsIos = RTVfsObjToIoStream(hVfsObj); 1092 rc = RTVfsMemorizeIoStreamAsFile(hVfsIos, RTFILE_O_READ, phVfsFile); 1093 if (RT_SUCCESS(rc)) 1094 { 1095 /* 1096 * To simplify the code below, replace 1097 * hVfsObj with the memorized file. 1098 */ 1099 RTVfsObjRelease(hVfsObj); 1100 hVfsObj = RTVfsObjFromFile(*phVfsFile); 1101 } 1102 else 1103 vboxExtPackSetError(pszError, cbError, "RTVfsMemorizeIoStreamAsFile failed on '%s': %Rrc", pszName, rc); 1104 RTVfsIoStrmRelease(hVfsIos); 1105 } 1106 } 1107 else 1108 vboxExtPackSetError(pszError, cbError, "RTVfsObjQueryInfo failed on '%s': %Rrc", pszName, rc); 1109 } 1110 } 1149 rc = VBoxExtPackValidateStandardFile(pszAdjName, enmType, &hVfsObj, phVfsFile, pszError, cbError); 1111 1150 } 1112 1151
Note:
See TracChangeset
for help on using the changeset viewer.