2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2011-01-25 08:03:51 +05:30
|
|
|
* Copyright (c) 2009-2011 Juan Romero Pardines.
|
2009-08-17 22:37:20 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2010-11-13 07:48:58 +05:30
|
|
|
#include <assert.h>
|
2010-11-19 18:10:13 +05:30
|
|
|
#include <unistd.h>
|
2011-06-01 11:01:38 +05:30
|
|
|
#include <sys/param.h>
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
#include <xbps_api.h>
|
|
|
|
#include "defs.h"
|
|
|
|
|
2011-10-27 20:38:48 +05:30
|
|
|
#define RUN_PKG_CHECK(name) \
|
|
|
|
do { \
|
|
|
|
rv = check_pkg_##name(pkgd, propsd, filesd); \
|
|
|
|
if (rv) \
|
|
|
|
broken = true; \
|
|
|
|
else if (rv == -1) { \
|
|
|
|
xbps_error_printf("%s: the %s test " \
|
|
|
|
"returned error!\n", pkgname, #name); \
|
|
|
|
goto out; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-10-06 04:12:37 +05:30
|
|
|
int
|
2011-07-27 20:43:54 +05:30
|
|
|
check_pkg_integrity_all(void)
|
2009-10-06 04:12:37 +05:30
|
|
|
{
|
2011-06-04 17:07:53 +05:30
|
|
|
const struct xbps_handle *xhp;
|
2009-10-06 04:12:37 +05:30
|
|
|
prop_object_t obj;
|
2009-11-26 07:52:50 +05:30
|
|
|
prop_object_iterator_t iter = NULL;
|
2009-11-01 12:02:06 +05:30
|
|
|
const char *pkgname, *version;
|
2009-10-06 04:12:37 +05:30
|
|
|
size_t npkgs = 0, nbrokenpkgs = 0;
|
|
|
|
|
2011-06-04 17:07:53 +05:30
|
|
|
xhp = xbps_handle_get();
|
|
|
|
iter = xbps_array_iter_from_dict(xhp->regpkgdb_dictionary, "packages");
|
2011-07-28 19:54:16 +05:30
|
|
|
if (iter == NULL)
|
|
|
|
return -1;
|
2009-10-06 04:12:37 +05:30
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
2009-11-01 12:02:06 +05:30
|
|
|
printf("Checking %s-%s ...\n", pkgname, version);
|
2011-07-28 19:54:16 +05:30
|
|
|
if (check_pkg_integrity(pkgname) != 0)
|
2009-10-06 04:12:37 +05:30
|
|
|
nbrokenpkgs++;
|
2011-07-28 19:54:16 +05:30
|
|
|
|
2009-10-06 04:12:37 +05:30
|
|
|
npkgs++;
|
|
|
|
}
|
2011-07-28 19:54:16 +05:30
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
|
2009-10-06 04:12:37 +05:30
|
|
|
printf("%zu package%s processed: %zu broken.\n", npkgs,
|
|
|
|
npkgs == 1 ? "" : "s", nbrokenpkgs);
|
|
|
|
|
2011-07-28 19:54:16 +05:30
|
|
|
return 0;
|
2009-10-06 04:12:37 +05:30
|
|
|
}
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
int
|
2011-07-27 20:43:54 +05:30
|
|
|
check_pkg_integrity(const char *pkgname)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2011-10-27 20:38:48 +05:30
|
|
|
prop_dictionary_t pkgd, propsd, filesd;
|
2009-08-17 22:37:20 +05:30
|
|
|
int rv = 0;
|
2011-10-27 20:38:48 +05:30
|
|
|
bool broken = false;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-10-27 20:38:48 +05:30
|
|
|
/* find real pkg by name */
|
2010-01-21 07:40:19 +05:30
|
|
|
pkgd = xbps_find_pkg_dict_installed(pkgname, false);
|
2011-10-27 14:32:55 +05:30
|
|
|
if (pkgd == NULL) {
|
2011-10-27 20:38:48 +05:30
|
|
|
/* find virtual pkg by name */
|
2011-10-27 14:32:55 +05:30
|
|
|
pkgd = xbps_find_virtualpkg_dict_installed(pkgname, false);
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
if (pkgd == NULL) {
|
|
|
|
printf("Package %s is not installed.\n", pkgname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Check for props.plist metadata file.
|
|
|
|
*/
|
2011-06-01 13:07:32 +05:30
|
|
|
propsd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGPROPS);
|
2011-01-25 08:03:51 +05:30
|
|
|
if (prop_object_type(propsd) != PROP_TYPE_DICTIONARY) {
|
2011-07-28 19:54:16 +05:30
|
|
|
xbps_error_printf("%s: unexistent %s or invalid metadata "
|
|
|
|
"file.\n", pkgname, XBPS_PKGPROPS);
|
|
|
|
broken = true;
|
2009-08-17 22:37:20 +05:30
|
|
|
goto out;
|
|
|
|
} else if (prop_dictionary_count(propsd) == 0) {
|
2011-07-28 19:54:16 +05:30
|
|
|
xbps_error_printf("%s: incomplete %s metadata file.\n",
|
|
|
|
pkgname, XBPS_PKGPROPS);
|
|
|
|
broken = true;
|
2010-01-25 20:45:33 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Check for files.plist metadata file.
|
|
|
|
*/
|
2011-06-01 13:07:32 +05:30
|
|
|
filesd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGFILES);
|
2011-01-25 08:03:51 +05:30
|
|
|
if (prop_object_type(filesd) != PROP_TYPE_DICTIONARY) {
|
2011-07-28 19:54:16 +05:30
|
|
|
xbps_error_printf("%s: unexistent %s or invalid metadata "
|
|
|
|
"file.\n", pkgname, XBPS_PKGFILES);
|
|
|
|
broken = true;
|
2010-01-25 20:45:33 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
} else if (prop_dictionary_count(filesd) == 0) {
|
2011-07-28 19:54:16 +05:30
|
|
|
xbps_error_printf("%s: incomplete %s metadata file.\n",
|
|
|
|
pkgname, XBPS_PKGFILES);
|
|
|
|
broken = true;
|
2010-01-25 20:45:33 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2011-10-27 20:38:48 +05:30
|
|
|
/* Execute pkg checks */
|
|
|
|
RUN_PKG_CHECK(autoinstall);
|
|
|
|
RUN_PKG_CHECK(files);
|
|
|
|
RUN_PKG_CHECK(symlinks);
|
|
|
|
RUN_PKG_CHECK(rundeps);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
out:
|
2011-10-27 20:38:48 +05:30
|
|
|
if (prop_object_type(filesd) == PROP_TYPE_DICTIONARY)
|
2010-01-25 20:45:33 +05:30
|
|
|
prop_object_release(filesd);
|
2011-10-27 20:38:48 +05:30
|
|
|
if (prop_object_type(propsd) == PROP_TYPE_DICTIONARY)
|
2010-01-25 20:45:33 +05:30
|
|
|
prop_object_release(propsd);
|
2011-10-27 20:38:48 +05:30
|
|
|
if (prop_object_type(pkgd) == PROP_TYPE_DICTIONARY)
|
|
|
|
prop_object_release(pkgd);
|
2009-10-06 04:12:37 +05:30
|
|
|
if (broken)
|
2011-10-27 20:38:48 +05:30
|
|
|
return 1;
|
2009-10-06 04:12:37 +05:30
|
|
|
|
2011-07-28 19:54:16 +05:30
|
|
|
return 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|