2 * dpkg - main program for package management
3 * configure.c - configure packages
5 * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 1999, 2002 Wichert Akkerman <wichert@deephackmode.org>
7 * Copyright © 2007-2015 Guillem Jover <guillem@debian.org>
8 * Copyright © 2011 Linaro Limited
9 * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
11 * This is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 #include <sys/types.h>
45 #include <dpkg/macros.h>
46 #include <dpkg/i18n.h>
47 #include <dpkg/dpkg.h>
48 #include <dpkg/dpkg-db.h>
50 #include <dpkg/string.h>
51 #include <dpkg/buffer.h>
52 #include <dpkg/file.h>
53 #include <dpkg/path.h>
54 #include <dpkg/subproc.h>
55 #include <dpkg/command.h>
56 #include <dpkg/triglib.h>
62 CFOF_PROMPT = DPKG_BIT(0),
63 CFOF_KEEP = DPKG_BIT(1),
64 CFOF_INSTALL = DPKG_BIT(2),
65 CFOF_BACKUP = DPKG_BIT(3),
66 CFOF_NEW_CONFF = DPKG_BIT(4),
67 CFOF_IS_NEW = DPKG_BIT(5),
68 CFOF_IS_OLD = DPKG_BIT(6),
69 CFOF_USER_DEL = DPKG_BIT(7),
72 CFO_IDENTICAL = CFOF_KEEP,
73 CFO_INSTALL = CFOF_INSTALL,
74 CFO_NEW_CONFF = CFOF_NEW_CONFF | CFOF_INSTALL,
75 CFO_PROMPT = CFOF_PROMPT,
76 CFO_PROMPT_KEEP = CFOF_PROMPT | CFOF_KEEP,
77 CFO_PROMPT_INSTALL = CFOF_PROMPT | CFOF_INSTALL,
80 static int conffoptcells[2][2] = {
81 /* Distro !edited. */ /* Distro edited. */
82 { CFO_KEEP, CFO_INSTALL }, /* User !edited. */
83 { CFO_KEEP, CFO_PROMPT_KEEP }, /* User edited. */
87 show_prompt(const char *cfgfile, const char *realold, const char *realnew,
88 int useredited, int distedited, enum conffopt what)
93 /* Flush the terminal's input in case the user involuntarily
94 * typed some characters. */
95 tcflush(STDIN_FILENO, TCIFLUSH);
98 if (strcmp(cfgfile, realold) == 0)
99 fprintf(stderr, _("Configuration file '%s'\n"), cfgfile);
101 fprintf(stderr, _("Configuration file '%s' (actually '%s')\n"),
104 if (what & CFOF_IS_NEW) {
106 _(" ==> File on system created by you or by a script.\n"
107 " ==> File also in package provided by package maintainer.\n"));
109 fprintf(stderr, !useredited ?
110 _(" Not modified since installation.\n") :
111 !(what & CFOF_USER_DEL) ?
112 _(" ==> Modified (by you or by a script) since installation.\n") :
113 _(" ==> Deleted (by you or by a script) since installation.\n"));
115 fprintf(stderr, distedited ?
116 _(" ==> Package distributor has shipped an updated version.\n") :
117 _(" Version in package is the same as at last installation.\n"));
120 /* No --force-confdef but a forcible situation. */
121 /* TODO: check if this condition can not be simplified to
122 * just !fc_conff_def */
123 if (!(fc_conff_def && (what & (CFOF_INSTALL | CFOF_KEEP)))) {
126 _(" ==> Using new file as you requested.\n"));
128 } else if (fc_conff_old) {
130 _(" ==> Using current old file as you requested.\n"));
135 /* Force the default action (if there is one. */
137 if (what & CFOF_KEEP) {
139 _(" ==> Keeping old config file as default.\n"));
141 } else if (what & CFOF_INSTALL) {
143 _(" ==> Using new config file as default.\n"));
149 _(" What would you like to do about it ? Your options are:\n"
150 " Y or I : install the package maintainer's version\n"
151 " N or O : keep your currently-installed version\n"
152 " D : show the differences between the versions\n"
153 " Z : start a shell to examine the situation\n"));
155 if (what & CFOF_KEEP)
157 _(" The default action is to keep your current version.\n"));
158 else if (what & CFOF_INSTALL)
160 _(" The default action is to install the new version.\n"));
162 s = path_basename(cfgfile);
163 fprintf(stderr, "*** %s (Y/I/N/O/D/Z) %s ? ", s,
164 (what & CFOF_KEEP) ? _("[default=N]") :
165 (what & CFOF_INSTALL) ? _("[default=Y]") :
169 ohshite(_("error writing to stderr, discovered before conffile prompt"));
172 while ((c = getchar()) != EOF && c != '\n')
173 if (!isspace(c) && !cc)
178 ohshite(_("read error on stdin at conffile prompt"));
179 ohshit(_("end of file on stdin at conffile prompt"));
183 if (what & CFOF_KEEP)
185 else if (what & CFOF_INSTALL)
193 * Show a diff between two files.
195 * @param old The path to the old file.
196 * @param new The path to the new file.
199 show_diff(const char *old, const char *new)
203 pid = subproc_fork();
208 sprintf(cmdbuf, DIFF " -Nu %.250s %.250s | %.250s",
209 str_quote_meta(old), str_quote_meta(new),
210 command_get_pager());
212 command_shell(cmdbuf, _("conffile difference visualizer"));
215 /* Parent process. */
216 subproc_reap(pid, _("conffile difference visualizer"), SUBPROC_NOCHECK);
222 * Create a subprocess and execute a shell to allow the user to manually
223 * solve the conffile conflict.
225 * @param confold The path to the old conffile.
226 * @param confnew The path to the new conffile.
229 spawn_shell(const char *confold, const char *confnew)
233 fputs(_("Type 'exit' when you're done.\n"), stderr);
235 pid = subproc_fork();
237 /* Set useful variables for the user. */
238 setenv("DPKG_SHELL_REASON", "conffile-prompt", 1);
239 setenv("DPKG_CONFFILE_OLD", confold, 1);
240 setenv("DPKG_CONFFILE_NEW", confnew, 1);
242 command_shell(NULL, _("conffile shell"));
245 /* Parent process. */
246 subproc_reap(pid, _("conffile shell"), SUBPROC_NOCHECK);
250 * Prompt the user for how to resolve a conffile conflict.
252 * When encountering a conffile conflict during configuration, the user will
253 * normally be presented with a textual menu of possible actions. This
254 * behavior is modified via various --force flags and perhaps on whether
255 * or not a terminal is available to do the prompting.
257 * @param pkg The package owning the conffile.
258 * @param cfgfile The path to the old conffile.
259 * @param realold The path to the old conffile, dereferenced in case of a
260 * symlink, otherwise equal to cfgfile.
261 * @param realnew The path to the new conffile, dereferenced in case of a
263 * @param useredited A flag to indicate whether the file has been edited
264 * locally. Set to nonzero to indicate that the file has been modified.
265 * @param distedited A flag to indicate whether the file has been updated
266 * between package versions. Set to nonzero to indicate that the file
268 * @param what Hints on what action should be taken by default.
270 * @return The action which should be taken based on user input and/or the
271 * default actions as configured by cmdline/configuration options.
274 promptconfaction(struct pkginfo *pkg, const char *cfgfile,
275 const char *realold, const char *realnew,
276 int useredited, int distedited, enum conffopt what)
280 if (!(what & CFOF_PROMPT))
283 statusfd_send("status: %s : %s : '%s' '%s' %i %i ",
284 cfgfile, "conffile-prompt",
285 realold, realnew, useredited, distedited);
288 cc = show_prompt(cfgfile, realold, realnew,
289 useredited, distedited, what);
291 /* FIXME: Say something if silently not install. */
293 show_diff(realold, realnew);
296 spawn_shell(realold, realnew);
297 } while (!strchr("yino", cc));
299 log_message("conffile %s %s", cfgfile,
300 (cc == 'i' || cc == 'y') ? "install" : "keep");
302 what &= CFOF_USER_DEL;
307 what |= CFOF_INSTALL | CFOF_BACKUP;
312 what |= CFOF_KEEP | CFOF_BACKUP;
316 internerr("unknown response '%d'", cc);
323 * Configure the ghost conffile instance.
325 * When the first instance of a package set is configured, the *.dpkg-new
326 * files gets installed into their destination, which makes configuration of
327 * conffiles from subsequent package instances be skipped along with updates
328 * to the Conffiles field hash.
330 * In case the conffile has already been processed, sync the hash from an
331 * already configured package instance conffile.
333 * @param pkg The current package being configured.
334 * @param conff The current conffile being configured.
337 deferred_configure_ghost_conffile(struct pkginfo *pkg, struct conffile *conff)
339 struct pkginfo *otherpkg;
340 struct conffile *otherconff;
342 for (otherpkg = &pkg->set->pkg; otherpkg; otherpkg = otherpkg->arch_next) {
345 if (otherpkg->status <= PKG_STAT_HALFCONFIGURED)
348 for (otherconff = otherpkg->installed.conffiles; otherconff;
349 otherconff = otherconff->next) {
350 if (otherconff->obsolete)
353 /* Check if we need to propagate the new hash from
354 * an already processed conffile in another package
356 if (strcmp(otherconff->name, conff->name) == 0) {
357 conff->hash = otherconff->hash;
366 deferred_configure_conffile(struct pkginfo *pkg, struct conffile *conff)
368 struct filenamenode *usenode;
369 char currenthash[MD5HASHLEN + 1], newdisthash[MD5HASHLEN + 1];
370 int useredited, distedited;
373 struct varbuf cdr = VARBUF_INIT, cdr2 = VARBUF_INIT;
377 usenode = namenodetouse(findnamenode(conff->name, fnn_nocopy),
378 pkg, &pkg->installed);
380 rc = conffderef(pkg, &cdr, usenode->name);
382 conff->hash = EMPTYHASHFLAG;
385 md5hash(pkg, currenthash, cdr.buf);
388 varbuf_add_str(&cdr2, cdr.buf);
389 varbuf_end_str(&cdr2);
390 /* XXX: Make sure there's enough room for extensions. */
391 varbuf_grow(&cdr2, 50);
392 cdr2rest = cdr2.buf + strlen(cdr.buf);
393 /* From now on we can just strcpy(cdr2rest, extension); */
395 strcpy(cdr2rest, DPKGNEWEXT);
396 /* If the .dpkg-new file is no longer there, ignore this one. */
397 if (lstat(cdr2.buf, &stab)) {
398 if (errno == ENOENT) {
399 /* But, sync the conffile hash value from another
400 * package set instance. */
401 deferred_configure_ghost_conffile(pkg, conff);
404 ohshite(_("unable to stat new distributed conffile '%.250s'"),
407 md5hash(pkg, newdisthash, cdr2.buf);
409 /* Copy the permissions from the installed version to the new
410 * distributed version. */
411 if (!stat(cdr.buf, &stab))
412 file_copy_perms(cdr.buf, cdr2.buf);
413 else if (errno != ENOENT)
414 ohshite(_("unable to stat current installed conffile '%.250s'"),
417 /* Select what to do. */
418 if (strcmp(currenthash, newdisthash) == 0) {
419 /* They're both the same so there's no point asking silly
423 what = CFO_IDENTICAL;
424 } else if (strcmp(currenthash, NONEXISTENTFLAG) == 0 && fc_conff_miss) {
427 "Configuration file '%s', does not exist on system.\n"
428 "Installing new config file as you requested.\n"),
430 what = CFO_NEW_CONFF;
433 } else if (strcmp(conff->hash, NEWCONFFILEFLAG) == 0) {
434 if (strcmp(currenthash, NONEXISTENTFLAG) == 0) {
435 what = CFO_NEW_CONFF;
441 what = conffoptcells[useredited][distedited] |
445 useredited = strcmp(conff->hash, currenthash) != 0;
446 distedited = strcmp(conff->hash, newdisthash) != 0;
448 if (fc_conff_ask && useredited)
449 what = CFO_PROMPT_KEEP;
451 what = conffoptcells[useredited][distedited];
453 if (strcmp(currenthash, NONEXISTENTFLAG) == 0)
454 what |= CFOF_USER_DEL;
458 "deferred_configure '%s' (= '%s') useredited=%d distedited=%d what=%o",
459 usenode->name, cdr.buf, useredited, distedited, what);
461 what = promptconfaction(pkg, usenode->name, cdr.buf, cdr2.buf,
462 useredited, distedited, what);
464 switch (what & ~(CFOF_IS_NEW | CFOF_USER_DEL)) {
465 case CFO_KEEP | CFOF_BACKUP:
466 strcpy(cdr2rest, DPKGOLDEXT);
467 if (unlink(cdr2.buf) && errno != ENOENT)
468 warning(_("%s: failed to remove old backup '%.250s': %s"),
469 pkg_name(pkg, pnaw_nonambig), cdr2.buf,
472 varbuf_add_str(&cdr, DPKGDISTEXT);
473 varbuf_end_str(&cdr);
474 strcpy(cdr2rest, DPKGNEWEXT);
475 trig_path_activate(usenode, pkg);
476 if (rename(cdr2.buf, cdr.buf))
477 warning(_("%s: failed to rename '%.250s' to '%.250s': %s"),
478 pkg_name(pkg, pnaw_nonambig), cdr2.buf, cdr.buf,
482 strcpy(cdr2rest, DPKGNEWEXT);
483 if (unlink(cdr2.buf))
484 warning(_("%s: failed to remove '%.250s': %s"),
485 pkg_name(pkg, pnaw_nonambig), cdr2.buf,
488 case CFO_INSTALL | CFOF_BACKUP:
489 strcpy(cdr2rest, DPKGDISTEXT);
490 if (unlink(cdr2.buf) && errno != ENOENT)
491 warning(_("%s: failed to remove old distributed version '%.250s': %s"),
492 pkg_name(pkg, pnaw_nonambig), cdr2.buf,
494 strcpy(cdr2rest, DPKGOLDEXT);
495 if (unlink(cdr2.buf) && errno != ENOENT)
496 warning(_("%s: failed to remove '%.250s' (before overwrite): %s"),
497 pkg_name(pkg, pnaw_nonambig), cdr2.buf,
499 if (!(what & CFOF_USER_DEL))
500 if (link(cdr.buf, cdr2.buf))
501 warning(_("%s: failed to link '%.250s' to '%.250s': %s"),
502 pkg_name(pkg, pnaw_nonambig), cdr.buf,
503 cdr2.buf, strerror(errno));
506 printf(_("Installing new version of config file %s ...\n"),
510 strcpy(cdr2rest, DPKGNEWEXT);
511 trig_path_activate(usenode, pkg);
512 if (rename(cdr2.buf, cdr.buf))
513 ohshite(_("unable to install '%.250s' as '%.250s'"),
517 internerr("unknown conffopt '%d'", what);
520 conff->hash = nfstrsave(newdisthash);
523 varbuf_destroy(&cdr);
524 varbuf_destroy(&cdr2);
528 * Process the deferred configure package.
530 * The algorithm for deciding what to configure first is as follows:
531 * Loop through all packages doing a ‘try 1’ until we've been round
532 * and nothing has been done, then do ‘try 2’ and ‘try 3’ likewise.
533 * The incrementing of ‘dependtry’ is done by process_queue().
536 * Are all dependencies of this package done? If so, do it.
537 * Are any of the dependencies missing or the wrong version?
538 * If so, abort (unless --force-depends, in which case defer).
539 * Will we need to configure a package we weren't given as an
540 * argument? If so, abort ─ except if --force-configure-any,
541 * in which case we add the package to the argument list.
542 * If none of the above, defer the package.
545 * Find a cycle and break it (see above).
548 * Try 3 (only if --force-depends-version):
549 * Same as for try 2, but don't mind version number in dependencies.
551 * Try 4 (only if --force-depends):
554 * @param pkg The package to act on.
557 deferred_configure(struct pkginfo *pkg)
559 struct varbuf aemsgs = VARBUF_INIT;
560 struct conffile *conff;
561 struct pkginfo *otherpkg;
564 if (pkg->status == PKG_STAT_NOTINSTALLED)
565 ohshit(_("no package named '%s' is installed, cannot configure"),
566 pkg_name(pkg, pnaw_nonambig));
567 if (pkg->status == PKG_STAT_INSTALLED)
568 ohshit(_("package %.250s is already installed and configured"),
569 pkg_name(pkg, pnaw_nonambig));
570 if (pkg->status != PKG_STAT_UNPACKED &&
571 pkg->status != PKG_STAT_HALFCONFIGURED)
572 ohshit(_("package %.250s is not ready for configuration\n"
573 " cannot configure (current status '%.250s')"),
574 pkg_name(pkg, pnaw_nonambig),
575 pkg_status_name(pkg));
577 for (otherpkg = &pkg->set->pkg; otherpkg; otherpkg = otherpkg->arch_next) {
580 if (otherpkg->status <= PKG_STAT_CONFIGFILES)
583 if (otherpkg->status < PKG_STAT_UNPACKED)
584 ohshit(_("package %s cannot be configured because "
585 "%s is not ready (current status '%s')"),
586 pkg_name(pkg, pnaw_always),
587 pkg_name(otherpkg, pnaw_always),
588 pkg_status_name(otherpkg));
590 if (dpkg_version_compare(&pkg->installed.version,
591 &otherpkg->installed.version))
592 ohshit(_("package %s %s cannot be configured because "
593 "%s is at a different version (%s)"),
594 pkg_name(pkg, pnaw_always),
595 versiondescribe(&pkg->installed.version,
597 pkg_name(otherpkg, pnaw_always),
598 versiondescribe(&otherpkg->installed.version,
603 if (findbreakcycle(pkg))
606 ok = dependencies_ok(pkg, NULL, &aemsgs);
607 if (ok == DEP_CHECK_DEFER) {
608 varbuf_destroy(&aemsgs);
609 pkg->clientdata->istobe = PKG_ISTOBE_INSTALLNEW;
610 enqueue_package(pkg);
614 trigproc_reset_cycle();
617 * At this point removal from the queue is confirmed. This
618 * represents irreversible progress wrt trigger cycles. Only
619 * packages in PKG_STAT_UNPACKED are automatically added to the
620 * configuration queue, and during configuration and trigger
621 * processing new packages can't enter into unpacked.
624 ok = breakses_ok(pkg, &aemsgs) ? ok : DEP_CHECK_HALT;
625 if (ok == DEP_CHECK_HALT) {
627 varbuf_end_str(&aemsgs);
628 notice(_("dependency problems prevent configuration of %s:\n%s"),
629 pkg_name(pkg, pnaw_nonambig), aemsgs.buf);
630 varbuf_destroy(&aemsgs);
631 ohshit(_("dependency problems - leaving unconfigured"));
632 } else if (aemsgs.used) {
633 varbuf_end_str(&aemsgs);
634 notice(_("%s: dependency problems, but configuring anyway as you requested:\n%s"),
635 pkg_name(pkg, pnaw_nonambig), aemsgs.buf);
637 varbuf_destroy(&aemsgs);
640 if (pkg->eflag & PKG_EFLAG_REINSTREQ)
641 forcibleerr(fc_removereinstreq,
642 _("package is in a very bad inconsistent state; you should\n"
643 " reinstall it before attempting configuration"));
645 printf(_("Setting up %s (%s) ...\n"), pkg_name(pkg, pnaw_nonambig),
646 versiondescribe(&pkg->installed.version, vdew_nonambig));
647 log_action("configure", pkg, &pkg->installed);
649 trig_activate_packageprocessing(pkg);
652 pkg_set_status(pkg, PKG_STAT_INSTALLED);
653 pkg->clientdata->istobe = PKG_ISTOBE_NORMAL;
657 if (pkg->status == PKG_STAT_UNPACKED) {
658 debug(dbg_general, "deferred_configure updating conffiles");
659 /* This will not do at all the right thing with overridden
660 * conffiles or conffiles that are the ‘target’ of an override;
661 * all the references here would be to the ‘contested’
662 * filename, and in any case there'd only be one hash for both
663 * ‘versions’ of the conffile.
665 * Overriding conffiles is a silly thing to do anyway :-). */
669 /* On entry, the ‘new’ version of each conffile has been
670 * unpacked as ‘*.dpkg-new’, and the ‘installed’ version is
671 * as-yet untouched in ‘*’. The hash of the ‘old distributed’
672 * version is in the conffiles data for the package. If
673 * ‘*.dpkg-new’ no longer exists we assume that we've
674 * already processed this one. */
675 for (conff = pkg->installed.conffiles; conff; conff = conff->next) {
678 deferred_configure_conffile(pkg, conff);
681 pkg_set_status(pkg, PKG_STAT_HALFCONFIGURED);
684 assert(pkg->status == PKG_STAT_HALFCONFIGURED);
688 maintscript_postinst(pkg, "configure",
689 dpkg_version_is_informative(&pkg->configversion) ?
690 versiondescribe(&pkg->configversion,
694 pkg_reset_eflags(pkg);
695 pkg->trigpend_head = NULL;
696 post_postinst_tasks(pkg, PKG_STAT_INSTALLED);
700 * Dereference a file by following all possibly used symlinks.
702 * @param[in] pkg The package to act on.
703 * @param[out] result The dereference conffile path.
704 * @param[in] in The conffile path to dereference.
706 * @return An error code for the operation.
707 * @retval 0 Everything went ok.
708 * @retval -1 Otherwise.
711 conffderef(struct pkginfo *pkg, struct varbuf *result, const char *in)
713 static struct varbuf target = VARBUF_INIT;
718 varbuf_reset(result);
719 varbuf_add_str(result, instdir);
720 varbuf_add_str(result, in);
721 varbuf_end_str(result);
726 debug(dbg_conffdetail, "conffderef in='%s' current working='%s'",
728 if (lstat(result->buf, &stab)) {
730 warning(_("%s: unable to stat config file '%s'\n"
732 pkg_name(pkg, pnaw_nonambig), in,
733 result->buf, strerror(errno));
734 debug(dbg_conffdetail, "conffderef nonexistent");
736 } else if (S_ISREG(stab.st_mode)) {
737 debug(dbg_conff, "conffderef in='%s' result='%s'",
740 } else if (S_ISLNK(stab.st_mode)) {
741 debug(dbg_conffdetail, "conffderef symlink loopprotect=%d",
743 if (loopprotect++ >= 25) {
744 warning(_("%s: config file '%s' is a circular link\n"
746 pkg_name(pkg, pnaw_nonambig), in,
751 varbuf_reset(&target);
752 varbuf_grow(&target, stab.st_size + 1);
753 r = readlink(result->buf, target.buf, target.size);
755 warning(_("%s: unable to readlink conffile '%s'\n"
757 pkg_name(pkg, pnaw_nonambig), in,
758 result->buf, strerror(errno));
760 } else if (r != stab.st_size) {
761 warning(_("symbolic link '%.250s' size has "
762 "changed from %jd to %zd"),
763 result->buf, (intmax_t)stab.st_size, r);
764 /* If the returned size is smaller, let's
765 * proceed, otherwise error out. */
766 if (r > stab.st_size)
769 varbuf_trunc(&target, r);
770 varbuf_end_str(&target);
772 debug(dbg_conffdetail,
773 "conffderef readlink gave %zd, '%s'",
776 if (target.buf[0] == '/') {
777 varbuf_reset(result);
778 varbuf_add_str(result, instdir);
779 debug(dbg_conffdetail,
780 "conffderef readlink absolute");
782 for (r = result->used - 1; r > 0 && result->buf[r] != '/'; r--)
785 warning(_("%s: conffile '%.250s' resolves to degenerate filename\n"
786 " ('%s' is a symlink to '%s')"),
787 pkg_name(pkg, pnaw_nonambig),
788 in, result->buf, target.buf);
791 if (result->buf[r] == '/')
793 varbuf_trunc(result, r);
794 debug(dbg_conffdetail,
795 "conffderef readlink relative to '%.*s'",
796 (int)result->used, result->buf);
798 varbuf_add_buf(result, target.buf, target.used);
799 varbuf_end_str(result);
801 warning(_("%s: conffile '%.250s' is not a plain file or symlink (= '%s')"),
802 pkg_name(pkg, pnaw_nonambig), in, result->buf);
809 * Generate a file contents MD5 hash.
811 * The caller is responsible for providing a buffer for the hash result
812 * at least MD5HASHLEN + 1 characters long.
814 * @param[in] pkg The package to act on.
815 * @param[out] hashbuf The buffer to store the generated hash.
816 * @param[in] fn The filename.
819 md5hash(struct pkginfo *pkg, char *hashbuf, const char *fn)
821 struct dpkg_error err;
824 fd = open(fn, O_RDONLY);
827 push_cleanup(cu_closefd, ehflag_bombout, NULL, 0, 1, &fd);
828 if (fd_md5(fd, hashbuf, -1, &err) < 0)
829 ohshit(_("cannot compute MD5 hash for file '%s': %s"),
831 pop_cleanup(ehflag_normaltidy); /* fd = open(cdr.buf) */
833 } else if (errno == ENOENT) {
834 strcpy(hashbuf, NONEXISTENTFLAG);
836 warning(_("%s: unable to open %s for hash: %s"),
837 pkg_name(pkg, pnaw_nonambig), fn, strerror(errno));
838 strcpy(hashbuf, EMPTYHASHFLAG);