Changeset 34381 in vbox
- Timestamp:
- Nov 25, 2010 3:49:11 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/manifest.h
r33289 r34381 36 36 * @{ 37 37 */ 38 39 /** @name Manifest attribute types. 40 * The types can be ORed together to form a set. 41 * @{ */ 42 /** For use with other attributes. Representation unknown. */ 43 #define RTMANIFEST_ATTR_UNKNOWN 0 44 /** The size of the content. Represented as a decimal number. */ 45 #define RTMANIFEST_ATTR_SIZE RT_BIT_32(0) 46 /** The MD5 of the content. Represented as a hex string. */ 47 #define RTMANIFEST_ATTR_MD5 RT_BIT_32(1) 48 /** The SHA-1 of the content. Represented as a hex string. */ 49 #define RTMANIFEST_ATTR_SHA1 RT_BIT_32(2) 50 /** The SHA-256 of the content. Represented as a hex string. */ 51 #define RTMANIFEST_ATTR_SHA256 RT_BIT_32(3) 52 /** The SHA-512 of the content. Represented as a hex string. */ 53 #define RTMANIFEST_ATTR_SHA512 RT_BIT_32(4) 54 /** The end of the valid values. */ 55 #define RTMANIFEST_ATTR_END RT_BIT_32(5) 56 /** @} */ 57 58 59 /** 60 * Creates an empty manifest. 61 * 62 * @returns IPRT status code. 63 * @param fFlags Flags, MBZ. 64 * @param phManifest Where to return the handle to the manifest. 65 */ 66 RTDECL(int) RTManifestCreate(uint32_t fFlags, PRTMANIFEST phManifest); 67 68 /** 69 * Retains a reference to the manifest handle. 70 * 71 * @returns The new reference count, UINT32_MAX if the handle is invalid. 72 * @param hManifest The handle to retain. 73 */ 74 RTDECL(uint32_t) RTManifestRetain(RTMANIFEST hManifest); 75 76 /** 77 * Releases a reference to the manifest handle. 78 * 79 * @returns The new reference count, 0 if free. UINT32_MAX is returned if the 80 * handle is invalid. 81 * @param hManifest The handle to release. 82 * NIL is quietly ignored (returns 0). 83 */ 84 RTDECL(uint32_t) RTManifestRelease(RTMANIFEST hManifest); 85 86 /** 87 * Creates a duplicate of the specified manifest. 88 * 89 * @returns IPRT status code 90 * @param hManifestSrc The manifest to clone. 91 * @param phManifestDst Where to store the handle to the duplicate. 92 */ 93 RTDECL(int) RTManifestDup(RTMANIFEST hManifestSrc, PRTMANIFEST phManifestDst); 94 95 /** 96 * Compares two manifests for equality. 97 * 98 * @returns true if equals, false if not. 99 * @param hManifest1 The first manifest. 100 * @param hManifest2 The second manifest. 101 * @param papszIgnoreEntries Entries to ignore. Ends with a NULL entry. 102 * @param papszIgnoreAttrs Attributes to ignore. Ends with a NULL entry. 103 */ 104 RTDECL(int) RTManifestEqualsEx(RTMANIFEST hManifest1, RTMANIFEST hManifest2, const char * const *papszIgnoreEntries, 105 const char * const *papszIgnoreAttr); 106 107 /** 108 * Compares two manifests for equality. 109 * 110 * @returns true if equals, false if not. 111 * @param hManifest1 The first manifest. 112 * @param hManifest2 The second manifest. 113 */ 114 RTDECL(int) RTManifestEquals(RTMANIFEST hManifest1, RTMANIFEST hManifest2); 115 116 /** 117 * Sets a manifest attribute. 118 * 119 * @returns IPRT status code. 120 * @param hManifest The manifest handle. 121 * @param pszAttr The attribute name. If this already exists, 122 * its value will be replaced. 123 * @param pszValue The value string. 124 * @param fType The attribute type, pass 125 * RTMANIFEST_ATTR_UNKNOWN if not known. 126 */ 127 RTDECL(int) RTManifestSetAttr(RTMANIFEST hManifest, const char *pszAttr, const char *pszValue, uint32_t fType); 128 129 /** 130 * Unsets (removes) a manifest attribute if it exists. 131 * 132 * @returns IPRT status code. 133 * @retval VWRN_NOT_FOUND if not found. 134 * 135 * @param hManifest The manifest handle. 136 * @param pszAttr The attribute name. 137 */ 138 RTDECL(int) RTManifestUnsetAttr(RTMANIFEST hManifest, const char *pszAttr); 139 140 /** 141 * Sets an attribute of a manifest entry. 142 * 143 * @returns IPRT status code. 144 * @param hManifest The manifest handle. 145 * @param pszEntry The entry name. This will automatically be 146 * added if there was no previous call to 147 * RTManifestEntryAdd for this name. See 148 * RTManifestEntryAdd for the entry name rules. 149 * @param pszAttr The attribute name. If this already exists, 150 * its value will be replaced. 151 * @param pszValue The value string. 152 * @param fType The attribute type, pass 153 * RTMANIFEST_ATTR_UNKNOWN if not known. 154 */ 155 RTDECL(int) RTManifestEntrySetAttr(RTMANIFEST hManifest, const char *pszEntry, const char *pszAttr, 156 const char *pszValue, uint32_t fType); 157 158 /** 159 * Unsets (removes) an attribute of a manifest entry if they both exist. 160 * 161 * @returns IPRT status code. 162 * @retval VWRN_NOT_FOUND if not found. 163 * 164 * @param hManifest The manifest handle. 165 * @param pszEntry The entry name. 166 * @param pszAttr The attribute name. 167 */ 168 RTDECL(int) RTManifestEntryUnsetAttr(RTMANIFEST hManifest, const char *pszEntry, const char *pszAttr); 169 170 /** 171 * Adds a new entry to a manifest. 172 * 173 * The entry name rules: 174 * - The entry name can contain any character defined by unicode, except 175 * control characters, ':', '(' and ')'. The exceptions are mainly there 176 * because of uncertainty around how various formats handles these. 177 * - It is considered case sensitive. 178 * - Forward (unix) and backward (dos) slashes are considered path 179 * separators and converted to forward slashes. 180 * 181 * @returns IPRT status code. 182 * @retval VWRN_ALREADY_EXISTS if the entry already exists. 183 * 184 * @param hManifest The manifest handle. 185 * @param pszEntry The entry name (UTF-8). 186 * 187 * @remarks Some manifest formats will not be able to store an entry without 188 * any attributes. So, this is just here in case it comes in handy 189 * when dealing with formats which can. 190 */ 191 RTDECL(int) RTManifestEntryAdd(RTMANIFEST hManifest, const char *pszEntry); 192 193 /** 194 * Removes an entry. 195 * 196 * @returns IPRT status code. 197 * @param hManifest The manifest handle. 198 * @param pszEntry The entry name. 199 */ 200 RTDECL(int) RTManifestEntryRemove(RTMANIFEST hManifest, const char *pszEntry); 201 202 203 /** 204 * Adds an entry for a file with the specified set of attributes. 205 * 206 * @returns IPRT status code. 207 * 208 * @param hManifest The manifest handle. 209 * @param hVfsIos The I/O stream handle of the entry. This will 210 * be processed to its end on successful return. 211 * (Must be positioned at the start to get 212 * the expected results.) 213 * @param pszEntry The entry name. 214 * @param fAttrs The attributes to create for this stream. 215 */ 216 RTDECL(int) RTManifestEntryAddIoStream(RTMANIFEST hManifest, RTVFSIOSTREAM hVfsIos, const char *pszEntry, uint32_t fAttrs); 217 218 /** 219 * Reads in a "standard" manifest. 220 * 221 * This reads the format used by OVF, the distinfo in FreeBSD ports, and 222 * others. 223 * 224 * @returns IPRT status code. 225 * @param hManifest The handle to the manifest where to add the 226 * manifest that's read in. 227 * @param hVfsIos The I/O stream to read the manifest from. 228 */ 229 RTDECL(int) RTManifestReadStandard(RTMANIFEST hManifest, RTVFSIOSTREAM hVfsIos); 230 231 /** 232 * Writes a "standard" manifest. 233 * 234 * This writes the format used by OVF, the distinfo in FreeBSD ports, and 235 * others. 236 * 237 * @returns IPRT status code. 238 * @param hManifest The handle to the manifest where to add the 239 * manifest that's read in. 240 * @param hVfsIos The I/O stream to read the manifest from. 241 */ 242 RTDECL(int) RTManifestWriteStandard(RTMANIFEST hManifest, RTVFSIOSTREAM hVfsIos); 243 244 245 246 38 247 39 248 /** -
trunk/include/iprt/types.h
r34232 r34381 1487 1487 #define NIL_RTDBGMOD ((RTDBGMOD)0) 1488 1488 1489 /** Manifest handle. */ 1490 typedef struct RTMANIFESTINT *RTMANIFEST; 1491 /** Pointer to a manifest handle. */ 1492 typedef RTMANIFEST *PRTMANIFEST; 1493 /** NIL manifest handle. */ 1494 #define NIL_RTMANIFEST ((RTMANIFEST)~(uintptr_t)0) 1495 1489 1496 /** Memory pool handle. */ 1490 1497 typedef R3R0PTRTYPE(struct RTMEMPOOLINT *) RTMEMPOOL; -
trunk/src/VBox/Main/VBoxExtPackHelperApp.cpp
r34307 r34381 30 30 #include <iprt/getopt.h> 31 31 #include <iprt/initterm.h> 32 #include <iprt/manifest.h> 32 33 #include <iprt/message.h> 33 34 #include <iprt/param.h> … … 37 38 #include <iprt/string.h> 38 39 #include <iprt/stream.h> 40 #include <iprt/vfs.h> 41 #include <iprt/zip.h> 39 42 40 43 #include <VBox/log.h> … … 51 54 } 52 55 #endif 56 53 57 54 58 … … 77 81 " --tarball <tarball> --tarball-fd <fd>\n" 78 82 " uninstall --base-dir <dir> --name <name>\n" 83 " cleanup --base-dir <dir>\n" 79 84 , RTProcShortName()); 80 85 return RTEXITCODE_SUCCESS; … … 135 140 return RTPathCompare(szCorrect, pszBaseDir) == 0; 136 141 } 142 137 143 138 144 /** … … 156 162 fTemporary ? "temporary " : "", rc, pszDir); 157 163 return RTEXITCODE_SUCCESS; 164 } 165 166 167 /** 168 * Rewinds the tarball file handle and creates a gunzip | tar chain that 169 * results in a filesystem stream. 170 * 171 * @returns success or failure, message displayed on failure. 172 * @param hTarballFile The handle to the tarball file. 173 * @param phTarFss Where to return the filesystem stream handle. 174 */ 175 static RTEXITCODE OpenTarFss(RTFILE hTarballFile, PRTVFSFSSTREAM phTarFss) 176 { 177 /* 178 * Rewind the file and set up a VFS chain for it. 179 */ 180 int rc = RTFileSeek(hTarballFile, 0, RTFILE_SEEK_BEGIN, NULL); 181 if (RT_FAILURE(rc)) 182 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed seeking to the start of the tarball: %Rrc\n", rc); 183 184 RTVFSIOSTREAM hTarballIos; 185 rc = RTVfsIoStrmFromRTFile(hTarballFile, RTFILE_O_READ | RTFILE_O_DENY_WRITE | RTFILE_O_OPEN, true /*fLeaveOpen*/, 186 &hTarballIos); 187 if (RT_FAILURE(rc)) 188 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTVfsIoStrmFromRTFile failed: %Rrc\n", rc); 189 190 RTVFSIOSTREAM hGunzipIos; 191 rc = RTZipGzipDecompressIoStream(hTarballIos, 0 /*fFlags*/, &hGunzipIos); 192 if (RT_SUCCESS(rc)) 193 { 194 RTVFSFSSTREAM hTarFss; 195 rc = RTZipTarFsStreamFromIoStream(hGunzipIos, 0 /*fFlags*/, &hTarFss); 196 if (RT_SUCCESS(rc)) 197 { 198 RTVfsIoStrmRelease(hGunzipIos); 199 RTVfsIoStrmRelease(hTarballIos); 200 *phTarFss = hTarFss; 201 return RTEXITCODE_SUCCESS; 202 } 203 RTMsgError("RTZipTarFsStreamFromIoStream failed: %Rrc\n", rc); 204 RTVfsIoStrmRelease(hGunzipIos); 205 } 206 else 207 RTMsgError("RTZipGzipDecompressIoStream failed: %Rrc\n", rc); 208 RTVfsIoStrmRelease(hTarballIos); 209 return RTEXITCODE_FAILURE; 158 210 } 159 211 … … 183 235 184 236 /** 185 * Validates the extension pack .237 * Validates the extension pack tarball prior to unpacking. 186 238 * 187 239 * Operations performed: 188 * - Manifest seal check. 189 * - Manifest check. 190 * - Recursive hardening check. 240 * - Hardening checks. 191 241 * - XML validity check. 192 242 * - Name check (against XML). … … 199 249 * complain about something. 200 250 */ 201 static RTEXITCODE Validate ExtPack(const char *pszDir, const char *pszTarball, const char *pszName)251 static RTEXITCODE ValidateUnpackedExtPack(const char *pszDir, const char *pszTarball, const char *pszName) 202 252 { 203 253 /** @todo */ … … 217 267 * @param pszTarball The name of the tarball in case we have to 218 268 * complain about something. 269 * @todo Needs to take the previous verified manifest as input. 219 270 */ 220 271 static RTEXITCODE UnpackExtPack(RTFILE hTarballFile, const char *pszDirDst, const char *pszTarball) … … 222 273 /** @todo */ 223 274 return RTEXITCODE_SUCCESS; 275 } 276 277 278 /** 279 * Validates the extension pack tarball prior to unpacking. 280 * 281 * Operations performed: 282 * - Manifest check. 283 * - Manifest seal check. 284 * - Mandatory files. 285 * 286 * @returns The program exit code. 287 * @param hTarballFile The handle to open the @a pszTarball file. 288 * @param pszTarball The name of the tarball in case we have to 289 * complain about something. 290 * 291 * @todo Should validate the XML and name. 292 * @todo Needs to return a manifest. 293 */ 294 static RTEXITCODE ValidateExtPackTarball(RTFILE hTarballFile, const char *pszTarball) 295 { 296 /* 297 * Open the tar.gz filesystem stream and set up an manifest in-memory file. 298 */ 299 RTVFSFSSTREAM hTarFss; 300 RTEXITCODE rcExit = OpenTarFss(hTarballFile, &hTarFss); 301 if (rcExit != RTEXITCODE_SUCCESS) 302 return rcExit; 303 304 RTMANIFEST hManifest; 305 int rc = RTManifestCreate(0 /*fFlags*/, &hManifest); 306 307 /** @todo continue coding here! */ 308 AssertRC(rc); 309 310 return RTEXITCODE_FAILURE; 224 311 } 225 312 … … 305 392 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to create temporary directory: %Rrc ('%s')", rc, szTmpPath); 306 393 307 RTEXITCODE rcExit = UnpackExtPack(hTarballFile, szTmpPath, pszTarball);394 RTEXITCODE rcExit = ValidateExtPackTarball(hTarballFile, pszTarball); 308 395 if (rcExit == RTEXITCODE_SUCCESS) 309 rcExit = ValidateExtPack(szTmpPath, pszTarball, pszName); 396 rcExit = UnpackExtPack(hTarballFile, szTmpPath, pszTarball); 397 if (rcExit == RTEXITCODE_SUCCESS) 398 rcExit = ValidateUnpackedExtPack(szTmpPath, pszTarball, pszName); 310 399 if (rcExit == RTEXITCODE_SUCCESS) 311 400 rcExit = SetExtPackPermissions(szTmpPath); -
trunk/src/VBox/Runtime/Makefile.kmk
r34218 r34381 1112 1112 common/checksum/crc32-zlib.cpp \ 1113 1113 common/checksum/manifest.cpp \ 1114 common/checksum/manifest2.cpp \ 1115 common/checksum/manifest3.cpp \ 1116 common/checksum/manifest-file.cpp \ 1114 1117 common/checksum/sha1.cpp \ 1115 1118 common/checksum/sha1str.cpp \
Note:
See TracChangeset
for help on using the changeset viewer.