Browse Source

dpkg: Generate md5sums info files if none were present in the binary package

This is the first step in allowing to verify installed package files
consistency. Next step will be to track file metadata and then add
options to verify the requested packages.

Closes: #155676, #155799
Guillem Jover 14 years ago
parent
commit
0e8bcc32c9
5 changed files with 83 additions and 1 deletions
  1. 2 0
      debian/changelog
  2. 1 0
      src/Makefile.am
  3. 73 0
      src/filesdb-hash.c
  4. 4 1
      src/filesdb.h
  5. 3 0
      src/processarc.c

+ 2 - 0
debian/changelog

@@ -40,6 +40,8 @@ dpkg (1.16.3) UNRELEASED; urgency=low
   * Compute the md5sum hash on unpack for empty files too, so that these
     can be checked correctly for matching content when installing multiple
     package instances.
+  * Generate md5sums files automatically at unpack time if missing from the
+    binary package. Closes: #155676, #155799
 
   [ Helge Kreutzmann ]
   * Fix a typo in man/dpkg-buildflags.1.

+ 1 - 0
src/Makefile.am

@@ -37,6 +37,7 @@ dpkg_SOURCES = \
 	enquiry.c \
 	errors.c \
 	filesdb.c \
+	filesdb-hash.c \
 	file-match.c file-match.h \
 	filters.c filters.h \
 	infodb-access.c \

+ 73 - 0
src/filesdb-hash.c

@@ -0,0 +1,73 @@
+/*
+ * dpkg - main program for package management
+ * filesdb-hash.c - management of database of files installed on system
+ *
+ * Copyright © 2012 Guillem Jover <guillem@debian.org>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <compat.h>
+
+#include <string.h>
+#include <stdio.h>
+
+#include <dpkg/dpkg.h>
+#include <dpkg/dpkg-db.h>
+#include <dpkg/debug.h>
+#include <dpkg/dir.h>
+
+#include "filesdb.h"
+#include "infodb.h"
+
+/*
+ * If mask is nonzero, will not write any file whose filenamenode
+ * has any flag bits set in mask.
+ */
+void
+write_filehash_except(struct pkginfo *pkg, struct pkgbin *pkgbin,
+                      struct fileinlist *list, enum fnnflags mask)
+{
+  struct atomic_file *file;
+  const char *hashfile;
+
+  debug(dbg_general, "generating infodb hashfile");
+
+  if (pkg_infodb_has_file(pkg, &pkg->available, HASHFILE))
+    return;
+
+  hashfile = pkg_infodb_get_file(pkg, pkgbin, HASHFILE);
+
+  file = atomic_file_new(hashfile, 0);
+  atomic_file_open(file);
+
+  for (; list; list = list->next) {
+    struct filenamenode *namenode = list->namenode;
+
+    if (mask && (namenode->flags & mask))
+      continue;
+    if (strcmp(namenode->newhash, EMPTYHASHFLAG) == 0)
+      continue;
+
+    fprintf(file->fp, "%s  %s\n", namenode->newhash, namenode->name + 1);
+  }
+
+  atomic_file_sync(file);
+  atomic_file_close(file);
+  atomic_file_commit(file);
+  atomic_file_free(file);
+
+  dir_sync_path(pkg_infodb_get_dir());
+}

+ 4 - 1
src/filesdb.h

@@ -3,7 +3,7 @@
  * filesdb.h - management of database of files installed on system
  *
  * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
- * Copyright © 2008-2010 Guillem Jover <guillem@debian.org>
+ * Copyright © 2008-2012 Guillem Jover <guillem@debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -159,6 +159,7 @@ mode_t statdb_parse_mode(const char *str);
 void ensure_statoverrides(void);
 
 #define LISTFILE           "list"
+#define HASHFILE           "md5sums"
 
 void ensure_packagefiles_available(struct pkginfo *pkg);
 void ensure_allinstfiles_available(void);
@@ -167,6 +168,8 @@ void note_must_reread_files_inpackage(struct pkginfo *pkg);
 struct filenamenode *findnamenode(const char *filename, enum fnnflags flags);
 void write_filelist_except(struct pkginfo *pkg, struct pkgbin *pkgbin,
                            struct fileinlist *list, enum fnnflags mask);
+void write_filehash_except(struct pkginfo *pkg, struct pkgbin *pkgbin,
+                           struct fileinlist *list, enum fnnflags mask);
 
 struct reversefilelistiter { struct fileinlist *todo; };
 

+ 3 - 0
src/processarc.c

@@ -1118,6 +1118,9 @@ void process_archive(const char *filename) {
   debug(dbg_general, "process_archive updating info directory");
   pkg_infodb_update(pkg, cidir, cidirrest);
 
+  /* We store now the checksums dynamically computed while unpacking. */
+  write_filehash_except(pkg, &pkg->available, newfileslist, 0);
+
   /*
    * Update the status database.
    *