2 * dpkg - main program for package management
3 * verify.c - verify package integrity
5 * Copyright © 2012-2015 Guillem Jover <guillem@debian.org>
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 #include <dpkg/i18n.h>
29 #include <dpkg/dpkg.h>
30 #include <dpkg/dpkg-db.h>
31 #include <dpkg/options.h>
44 struct verify_checks {
45 enum verify_result md5sum;
48 typedef void verify_output_func(struct filenamenode *, struct verify_checks *);
51 verify_result_rpm(enum verify_result result, int check)
65 verify_output_rpm(struct filenamenode *namenode, struct verify_checks *checks)
70 memset(result, '?', sizeof(result));
72 result[2] = verify_result_rpm(checks->md5sum, '5');
74 if (namenode->flags & fnnf_old_conff)
79 printf("%.9s %c %s\n", result, attr, namenode->name);
82 static verify_output_func *verify_output = verify_output_rpm;
85 verify_set_output(const char *name)
87 if (strcmp(name, "rpm") == 0)
88 verify_output = verify_output_rpm;
96 verify_package(struct pkginfo *pkg)
98 struct fileinlist *file;
99 struct varbuf filename = VARBUF_INIT;
101 ensure_packagefiles_available(pkg);
102 parse_filehash(pkg, &pkg->installed);
103 pkg_conffiles_mark_old(pkg);
105 for (file = pkg->clientdata->files; file; file = file->next) {
106 struct verify_checks checks;
107 struct filenamenode *fnn;
108 char hash[MD5HASHLEN + 1];
111 fnn = namenodetouse(file->namenode, pkg, &pkg->installed);
113 if (strcmp(fnn->newhash, EMPTYHASHFLAG) == 0) {
114 if (fnn->oldhash == NULL)
117 fnn->newhash = fnn->oldhash;
120 varbuf_reset(&filename);
121 varbuf_add_str(&filename, instdir);
122 varbuf_add_str(&filename, fnn->name);
123 varbuf_end_str(&filename);
125 memset(&checks, 0, sizeof(checks));
127 md5hash(pkg, hash, filename.buf);
128 if (strcmp(hash, fnn->newhash) != 0) {
129 checks.md5sum = VERIFY_FAIL;
134 verify_output(fnn, &checks);
137 varbuf_destroy(&filename);
141 verify(const char *const *argv)
146 modstatdb_open(msdbrw_readonly);
150 struct pkgiterator *iter;
152 iter = pkg_db_iter_new();
153 while ((pkg = pkg_db_iter_next_pkg(iter)))
155 pkg_db_iter_free(iter);
159 while ((thisarg = *argv++)) {
160 pkg = dpkg_options_parse_pkgname(cipaction, thisarg);
161 if (pkg->status == PKG_STAT_NOTINSTALLED) {
162 notice(_("package '%s' is not installed"),
163 pkg_name(pkg, pnaw_nonambig));
172 modstatdb_shutdown();
174 m_output(stdout, _("<standard output>"));