+ return ar_handle->dpkg__sub_archive->dpkg__buffer;
+}
+
+static void append_control_file_to_llist(const char *package_name, const char *control_name, llist_t **ll)
+{
+ FILE *fp;
+ char *filename, *line;
+
+ filename = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, control_name);
+ fp = fopen_for_read(filename);
+ free(filename);
+ if (fp != NULL) {
+ while ((line = xmalloc_fgetline(fp)) != NULL)
+ llist_add_to(ll, line);
+ fclose(fp);
+ }
+}
+
+static char FAST_FUNC filter_rename_config(archive_handle_t *archive_handle)
+{
+ int fd;
+ char *name_ptr = archive_handle->file_header->name + 1;
+
+ /* Is this file marked as config file? */
+ if (!find_list_entry(archive_handle->accept, name_ptr))
+ return EXIT_SUCCESS; /* no */
+
+ fd = open(name_ptr, O_RDONLY);
+ if (fd >= 0) {
+ md5_ctx_t md5;
+ char *md5line, *buf;
+ int count;
+
+ /* Calculate MD5 of existing file */
+ buf = xmalloc(4096);
+ md5_begin(&md5);
+ while ((count = safe_read(fd, buf, 4096)) > 0)
+ md5_hash(&md5, buf, count);
+ md5_end(&md5, buf); /* using buf as result storage */
+ close(fd);
+
+ md5line = xmalloc(16 * 2 + 2 + strlen(name_ptr) + 1);
+ sprintf(bin2hex(md5line, buf, 16), " %s", name_ptr);
+ free(buf);
+
+ /* Is it changed after install? */
+ if (find_list_entry(archive_handle->accept, md5line) == NULL) {
+ printf("Warning: Creating %s as %s.dpkg-new\n", name_ptr, name_ptr);
+ archive_handle->file_header->name = xasprintf("%s.dpkg-new", archive_handle->file_header->name);
+ }
+ free(md5line);
+ }
+ return EXIT_SUCCESS;