manifest.cpp revision c40afa339b10a23d6fffcbeb7d4572bb494685f0
/* $Id$ */
/** @file
* IPRT - Manifest file handling.
*/
/*
* Copyright (C) 2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include "iprt/manifest.h"
#include <stdlib.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
typedef struct RTFILELISTINT
{
char *pszManifestFile;
char *pszManifestDigest;
typedef RTFILELISTINT* PRTFILELISTINT;
/*******************************************************************************
* Public RTManifest interface *
*******************************************************************************/
RTR3DECL(int) RTManifestVerify(const char *pszManifestFile, PRTMANIFESTTEST pTestList, size_t cTests, size_t *pcFileIndexOnFailure)
{
/* Validate input */
if (!pszManifestFile || !pTestList)
{
AssertMsgFailed(("Must supply pszManifestFile and pTestList!\n"));
return VERR_INVALID_PARAMETER;
}
/* Open the manifest file */
if (RT_FAILURE(rc))
return rc;
if (!pFileList)
return VERR_NO_MEMORY;
/* Fill our compare list */
/* Parse the manifest file line by line */
char pszLine[1024];
do
{
if (RT_FAILURE(rc))
break;
/* Skip empty lines */
if (cbCount == 0)
continue;
/* Check for the digest algorithm */
if (cbCount < 4 ||
!(pszLine[0] == 'S' &&
{
/* Digest unsupported */
break;
}
/* Try to find the filename */
if (!pszNameStart)
{
break;
}
if (!pszNameEnd)
{
break;
}
/* Copy the filename part */
if (!pszName)
{
rc = VERR_NO_MEMORY;
break;
}
/* Try to find the digest sum */
if (!pszDigestStart)
{
break;
}
char *pszDigest = pszDigestStart;
/* Check our file list against the extracted data */
bool fFound = false;
{
{
/* Add the data of the manifest file to the file list */
fFound = true;
break;
}
}
if (!fFound)
{
/* There have to be an entry in the file list */
break;
}
}
while (1);
if (rc == VINF_SUCCESS ||
{
rc = VINF_SUCCESS;
{
/* If there is an entry in the file list, which hasn't an
* equivalent in the manifest file, its an error. */
if (!pFileList[i].pszManifestFile ||
{
break;
}
/* Do the manifest SHA1 digest match against the actual digest? */
{
if (pcFileIndexOnFailure)
*pcFileIndexOnFailure = i;
break;
}
}
}
/* Cleanup */
{
if (pFileList[i].pszManifestFile)
if (pFileList[i].pszManifestDigest)
}
return rc;
}
RTR3DECL(int) RTManifestVerifyFiles(const char *pszManifestFile, const char **ppszFiles, size_t cFiles, size_t *pcFileIndexOnFailure)
{
/* Validate input */
if (!pszManifestFile || !ppszFiles)
{
AssertMsgFailed(("Must supply pszManifestFile and ppszFiles!\n"));
return VERR_INVALID_PARAMETER;
}
/* Create our compare list */
if (!pFileList)
return VERR_NO_MEMORY;
int rc = VINF_SUCCESS;
/* Fill our compare list */
{
char *pszDigest;
if (RT_FAILURE(rc))
break;
}
/* Do the verify */
if (RT_SUCCESS(rc))
/* Cleanup */
{
if (pFileList[i].pszTestDigest)
}
return rc;
}
RTR3DECL(int) RTManifestWriteFiles(const char *pszManifestFile, const char **ppszFiles, size_t cFiles)
{
/* Validate input */
if (!pszManifestFile || !ppszFiles)
{
AssertMsgFailed(("Must supply pszManifestFile and ppszFiles!\n"));
return VERR_INVALID_PARAMETER;
}
/* Open a file to stream in */
if (RT_FAILURE(rc))
return rc;
{
/* Calculate the SHA1 digest of every file */
char *pszDigest;
if (RT_FAILURE(rc))
break;
/* Add the entry to the manifest file */
if (cbRet < 0)
{
break;
}
}
/* Delete the manifest file on failure */
if (RT_FAILURE(rc))
return rc;
}