LCOV - code coverage report
Current view: top level - src/main - help.c (source / functions) Hit Total Coverage
Test: dpkg 1.21.11 C code coverage Lines: 0 134 0.0 %
Date: 2022-12-03 00:40:01 Functions: 0 15 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 88 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * dpkg - main program for package management
       3                 :            :  * help.c - various helper routines
       4                 :            :  *
       5                 :            :  * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
       6                 :            :  * Copyright © 2007-2015 Guillem Jover <guillem@debian.org>
       7                 :            :  *
       8                 :            :  * This is free software; you can redistribute it and/or modify
       9                 :            :  * it under the terms of the GNU General Public License as published by
      10                 :            :  * the Free Software Foundation; either version 2 of the License, or
      11                 :            :  * (at your option) any later version.
      12                 :            :  *
      13                 :            :  * This is distributed in the hope that it will be useful,
      14                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16                 :            :  * GNU General Public License for more details.
      17                 :            :  *
      18                 :            :  * You should have received a copy of the GNU General Public License
      19                 :            :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      20                 :            :  */
      21                 :            : 
      22                 :            : #include <config.h>
      23                 :            : #include <compat.h>
      24                 :            : 
      25                 :            : #include <sys/types.h>
      26                 :            : #include <sys/stat.h>
      27                 :            : 
      28                 :            : #include <errno.h>
      29                 :            : #include <string.h>
      30                 :            : #include <unistd.h>
      31                 :            : #include <stdlib.h>
      32                 :            : 
      33                 :            : #include <dpkg/i18n.h>
      34                 :            : #include <dpkg/dpkg.h>
      35                 :            : #include <dpkg/dpkg-db.h>
      36                 :            : #include <dpkg/path.h>
      37                 :            : #include <dpkg/file.h>
      38                 :            : #include <dpkg/db-fsys.h>
      39                 :            : 
      40                 :            : #include "main.h"
      41                 :            : 
      42                 :            : const char *const statusstrings[]= {
      43                 :            :   [PKG_STAT_NOTINSTALLED]    = N_("not installed"),
      44                 :            :   [PKG_STAT_CONFIGFILES]     = N_("not installed but configs remain"),
      45                 :            :   [PKG_STAT_HALFINSTALLED]   = N_("broken due to failed removal or installation"),
      46                 :            :   [PKG_STAT_UNPACKED]        = N_("unpacked but not configured"),
      47                 :            :   [PKG_STAT_HALFCONFIGURED]  = N_("broken due to postinst failure"),
      48                 :            :   [PKG_STAT_TRIGGERSAWAITED] = N_("awaiting trigger processing by another package"),
      49                 :            :   [PKG_STAT_TRIGGERSPENDING] = N_("triggered"),
      50                 :            :   [PKG_STAT_INSTALLED]       = N_("installed")
      51                 :            : };
      52                 :            : 
      53                 :            : struct fsys_namenode *
      54                 :          0 : namenodetouse(struct fsys_namenode *namenode, struct pkginfo *pkg,
      55                 :            :               struct pkgbin *pkgbin)
      56                 :            : {
      57                 :            :   struct fsys_namenode *fnn;
      58                 :            : 
      59         [ #  # ]:          0 :   if (!namenode->divert)
      60                 :          0 :     return namenode;
      61                 :            : 
      62                 :          0 :   debug(dbg_eachfile, "namenodetouse namenode='%s' pkg=%s",
      63                 :            :         namenode->name, pkgbin_name(pkg, pkgbin, pnaw_always));
      64                 :            : 
      65         [ #  # ]:          0 :   fnn = (namenode->divert->useinstead && namenode->divert->pkgset != pkg->set)
      66         [ #  # ]:          0 :         ? namenode->divert->useinstead : namenode;
      67                 :            : 
      68                 :          0 :   debug(dbg_eachfile,
      69                 :            :         "namenodetouse ... useinstead=%s camefrom=%s pkg=%s return %s",
      70         [ #  # ]:          0 :         namenode->divert->useinstead ? namenode->divert->useinstead->name : "<none>",
      71         [ #  # ]:          0 :         namenode->divert->camefrom ? namenode->divert->camefrom->name : "<none>",
      72         [ #  # ]:          0 :         namenode->divert->pkgset ? namenode->divert->pkgset->name : "<none>",
      73                 :            :         fnn->name);
      74                 :            : 
      75                 :          0 :   return fnn;
      76                 :            : }
      77                 :            : 
      78                 :            : bool
      79                 :          0 : find_command(const char *prog)
      80                 :            : {
      81                 :          0 :   struct varbuf filename = VARBUF_INIT;
      82                 :            :   const char *path_list;
      83                 :            :   const char *path, *path_end;
      84                 :            :   size_t path_len;
      85                 :            : 
      86         [ #  # ]:          0 :   if (prog[0] == '/')
      87                 :          0 :     return file_is_exec(prog);
      88                 :            : 
      89                 :          0 :   path_list = getenv("PATH");
      90         [ #  # ]:          0 :   if (!path_list)
      91                 :          0 :     ohshit(_("PATH is not set"));
      92                 :            : 
      93   [ #  #  #  # ]:          0 :   for (path = path_list; path; path = *path_end ? path_end + 1 : NULL) {
      94                 :          0 :     path_end = strchrnul(path, ':');
      95                 :          0 :     path_len = (size_t)(path_end - path);
      96                 :            : 
      97                 :          0 :     varbuf_reset(&filename);
      98                 :          0 :     varbuf_add_buf(&filename, path, path_len);
      99         [ #  # ]:          0 :     if (path_len)
     100                 :          0 :       varbuf_add_char(&filename, '/');
     101                 :          0 :     varbuf_add_str(&filename, prog);
     102                 :          0 :     varbuf_end_str(&filename);
     103                 :            : 
     104         [ #  # ]:          0 :     if (file_is_exec(filename.buf)) {
     105                 :          0 :       varbuf_destroy(&filename);
     106                 :          0 :       return true;
     107                 :            :     }
     108                 :            :   }
     109                 :            : 
     110                 :          0 :   varbuf_destroy(&filename);
     111                 :          0 :   return false;
     112                 :            : }
     113                 :            : 
     114                 :            : /**
     115                 :            :  * Verify that some programs can be found in the PATH.
     116                 :            :  */
     117                 :          0 : void checkpath(void) {
     118                 :            :   static const char *const prog_list[] = {
     119                 :            :     DEFAULTSHELL,
     120                 :            :     RM,
     121                 :            :     TAR,
     122                 :            :     DIFF,
     123                 :            :     BACKEND,
     124                 :            :     /* Mac OS X uses dyld (Mach-O) instead of ld.so (ELF), and does not have
     125                 :            :      * an ldconfig. */
     126                 :            : #if defined(__APPLE__) && defined(__MACH__)
     127                 :            :     "update_dyld_shared_cache",
     128                 :            : #elif defined(__GLIBC__) || defined(__UCLIBC__) || \
     129                 :            :       defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
     130                 :            :     "ldconfig",
     131                 :            : #endif
     132                 :            : #if BUILD_START_STOP_DAEMON
     133                 :            :     "start-stop-daemon",
     134                 :            : #endif
     135                 :            :     NULL
     136                 :            :   };
     137                 :            : 
     138                 :            :   const char *const *prog;
     139                 :          0 :   int warned= 0;
     140                 :            : 
     141         [ #  # ]:          0 :   for (prog = prog_list; *prog; prog++) {
     142         [ #  # ]:          0 :     if (!find_command(*prog)) {
     143                 :          0 :       warning(_("'%s' not found in PATH or not executable"), *prog);
     144                 :          0 :       warned++;
     145                 :            :     }
     146                 :            :   }
     147                 :            : 
     148         [ #  # ]:          0 :   if (warned)
     149                 :          0 :     forcibleerr(FORCE_BAD_PATH,
     150                 :          0 :                 P_("%d expected program not found in PATH or not executable\n%s",
     151                 :            :                    "%d expected programs not found in PATH or not executable\n%s",
     152                 :            :                    warned),
     153                 :            :                 warned, _("Note: root's PATH should usually contain "
     154                 :            :                           "/usr/local/sbin, /usr/sbin and /sbin"));
     155                 :          0 : }
     156                 :            : 
     157                 :            : bool
     158                 :          0 : ignore_depends(const struct pkginfo *pkg)
     159                 :            : {
     160                 :            :   struct pkg_list *id;
     161         [ #  # ]:          0 :   for (id= ignoredependss; id; id= id->next)
     162         [ #  # ]:          0 :     if (id->pkg == pkg)
     163                 :          0 :       return true;
     164                 :          0 :   return false;
     165                 :            : }
     166                 :            : 
     167                 :            : static bool
     168                 :          0 : ignore_depends_possi(struct deppossi *possi)
     169                 :            : {
     170                 :            :   struct deppossi_pkg_iterator *possi_iter;
     171                 :            :   struct pkginfo *pkg;
     172                 :            : 
     173                 :          0 :   possi_iter = deppossi_pkg_iter_new(possi, wpb_installed);
     174         [ #  # ]:          0 :   while ((pkg = deppossi_pkg_iter_next(possi_iter))) {
     175         [ #  # ]:          0 :     if (ignore_depends(pkg)) {
     176                 :          0 :       deppossi_pkg_iter_free(possi_iter);
     177                 :          0 :       return true;
     178                 :            :     }
     179                 :            :   }
     180                 :          0 :   deppossi_pkg_iter_free(possi_iter);
     181                 :            : 
     182                 :          0 :   return false;
     183                 :            : }
     184                 :            : 
     185                 :            : bool
     186                 :          0 : force_depends(struct deppossi *possi)
     187                 :            : {
     188         [ #  # ]:          0 :   return in_force(FORCE_DEPENDS) ||
     189   [ #  #  #  # ]:          0 :          ignore_depends_possi(possi) ||
     190                 :          0 :          ignore_depends(possi->up->up);
     191                 :            : }
     192                 :            : 
     193                 :            : bool
     194                 :          0 : force_breaks(struct deppossi *possi)
     195                 :            : {
     196         [ #  # ]:          0 :   return in_force(FORCE_BREAKS) ||
     197   [ #  #  #  # ]:          0 :          ignore_depends_possi(possi) ||
     198                 :          0 :          ignore_depends(possi->up->up);
     199                 :            : }
     200                 :            : 
     201                 :            : bool
     202                 :          0 : force_conflicts(struct deppossi *possi)
     203                 :            : {
     204                 :          0 :   return in_force(FORCE_CONFLICTS);
     205                 :            : }
     206                 :            : 
     207                 :          0 : void clear_istobes(void) {
     208                 :            :   struct pkg_hash_iter *iter;
     209                 :            :   struct pkginfo *pkg;
     210                 :            : 
     211                 :          0 :   iter = pkg_hash_iter_new();
     212         [ #  # ]:          0 :   while ((pkg = pkg_hash_iter_next_pkg(iter)) != NULL) {
     213                 :          0 :     ensure_package_clientdata(pkg);
     214                 :          0 :     pkg->clientdata->istobe = PKG_ISTOBE_NORMAL;
     215                 :          0 :     pkg->clientdata->replacingfilesandsaid= 0;
     216                 :            :   }
     217                 :          0 :   pkg_hash_iter_free(iter);
     218                 :          0 : }
     219                 :            : 
     220                 :            : /*
     221                 :            :  * Returns true if the directory contains conffiles belonging to pkg,
     222                 :            :  * false otherwise.
     223                 :            :  */
     224                 :            : bool
     225                 :          0 : dir_has_conffiles(struct fsys_namenode *file, struct pkginfo *pkg)
     226                 :            : {
     227                 :            :   struct conffile *conff;
     228                 :            :   size_t namelen;
     229                 :            : 
     230                 :          0 :   debug(dbg_veryverbose, "dir_has_conffiles '%s' (from %s)", file->name,
     231                 :            :         pkg_name(pkg, pnaw_always));
     232                 :          0 :   namelen = strlen(file->name);
     233         [ #  # ]:          0 :   for (conff= pkg->installed.conffiles; conff; conff= conff->next) {
     234   [ #  #  #  # ]:          0 :       if (conff->obsolete || conff->remove_on_upgrade)
     235                 :          0 :         continue;
     236         [ #  # ]:          0 :       if (strncmp(file->name, conff->name, namelen) == 0 &&
     237   [ #  #  #  # ]:          0 :           strlen(conff->name) > namelen && conff->name[namelen] == '/') {
     238                 :          0 :         debug(dbg_veryverbose, "directory %s has conffile %s from %s",
     239                 :            :               file->name, conff->name, pkg_name(pkg, pnaw_always));
     240                 :          0 :         return true;
     241                 :            :       }
     242                 :            :   }
     243                 :          0 :   debug(dbg_veryverbose, "dir_has_conffiles no");
     244                 :          0 :   return false;
     245                 :            : }
     246                 :            : 
     247                 :            : /*
     248                 :            :  * Returns true if the file is used by packages other than pkg,
     249                 :            :  * false otherwise.
     250                 :            :  */
     251                 :            : bool
     252                 :          0 : dir_is_used_by_others(struct fsys_namenode *file, struct pkginfo *pkg)
     253                 :            : {
     254                 :            :   struct fsys_node_pkgs_iter *iter;
     255                 :            :   struct pkginfo *other_pkg;
     256                 :            : 
     257         [ #  # ]:          0 :   debug(dbg_veryverbose, "dir_is_used_by_others '%s' (except %s)", file->name,
     258                 :          0 :         pkg ? pkg_name(pkg, pnaw_always) : "<none>");
     259                 :            : 
     260                 :          0 :   iter = fsys_node_pkgs_iter_new(file);
     261         [ #  # ]:          0 :   while ((other_pkg = fsys_node_pkgs_iter_next(iter))) {
     262                 :          0 :     debug(dbg_veryverbose, "dir_is_used_by_others considering %s ...",
     263                 :            :           pkg_name(other_pkg, pnaw_always));
     264         [ #  # ]:          0 :     if (other_pkg == pkg)
     265                 :          0 :       continue;
     266                 :            : 
     267                 :          0 :     fsys_node_pkgs_iter_free(iter);
     268                 :          0 :     debug(dbg_veryverbose, "dir_is_used_by_others yes");
     269                 :          0 :     return true;
     270                 :            :   }
     271                 :          0 :   fsys_node_pkgs_iter_free(iter);
     272                 :            : 
     273                 :          0 :   debug(dbg_veryverbose, "dir_is_used_by_others no");
     274                 :          0 :   return false;
     275                 :            : }
     276                 :            : 
     277                 :            : /*
     278                 :            :  * Returns true if the file is used by pkg, false otherwise.
     279                 :            :  */
     280                 :            : bool
     281                 :          0 : dir_is_used_by_pkg(struct fsys_namenode *file, struct pkginfo *pkg,
     282                 :            :                    struct fsys_namenode_list *list)
     283                 :            : {
     284                 :            :   struct fsys_namenode_list *node;
     285                 :            :   size_t namelen;
     286                 :            : 
     287         [ #  # ]:          0 :   debug(dbg_veryverbose, "dir_is_used_by_pkg '%s' (by %s)",
     288                 :          0 :         file->name, pkg ? pkg_name(pkg, pnaw_always) : "<none>");
     289                 :            : 
     290                 :          0 :   namelen = strlen(file->name);
     291                 :            : 
     292         [ #  # ]:          0 :   for (node = list; node; node = node->next) {
     293                 :          0 :     debug(dbg_veryverbose, "dir_is_used_by_pkg considering %s ...",
     294                 :          0 :           node->namenode->name);
     295                 :            : 
     296         [ #  # ]:          0 :     if (strncmp(file->name, node->namenode->name, namelen) == 0 &&
     297         [ #  # ]:          0 :         strlen(node->namenode->name) > namelen &&
     298         [ #  # ]:          0 :         node->namenode->name[namelen] == '/') {
     299                 :          0 :       debug(dbg_veryverbose, "dir_is_used_by_pkg yes");
     300                 :          0 :       return true;
     301                 :            :     }
     302                 :            :   }
     303                 :            : 
     304                 :          0 :   debug(dbg_veryverbose, "dir_is_used_by_pkg no");
     305                 :            : 
     306                 :          0 :   return false;
     307                 :            : }
     308                 :            : 
     309                 :            : /**
     310                 :            :  * Mark a conffile as obsolete.
     311                 :            :  *
     312                 :            :  * @param pkg           The package owning the conffile.
     313                 :            :  * @param namenode      The namenode for the obsolete conffile.
     314                 :            :  */
     315                 :            : void
     316                 :          0 : conffile_mark_obsolete(struct pkginfo *pkg, struct fsys_namenode *namenode)
     317                 :            : {
     318                 :            :   struct conffile *conff;
     319                 :            : 
     320         [ #  # ]:          0 :   for (conff = pkg->installed.conffiles; conff; conff = conff->next) {
     321         [ #  # ]:          0 :     if (strcmp(conff->name, namenode->name) == 0) {
     322                 :          0 :       debug(dbg_conff, "marking %s conffile %s as obsolete",
     323                 :            :             pkg_name(pkg, pnaw_always), conff->name);
     324                 :          0 :       conff->obsolete = true;
     325                 :          0 :       return;
     326                 :            :     }
     327                 :            :   }
     328                 :            : }
     329                 :            : 
     330                 :            : /**
     331                 :            :  * Mark all package conffiles as old.
     332                 :            :  *
     333                 :            :  * @param pkg           The package owning the conffiles.
     334                 :            :  */
     335                 :            : void
     336                 :          0 : pkg_conffiles_mark_old(struct pkginfo *pkg)
     337                 :            : {
     338                 :            :   const struct conffile *conff;
     339                 :            :   struct fsys_namenode *namenode;
     340                 :            : 
     341         [ #  # ]:          0 :   for (conff = pkg->installed.conffiles; conff; conff = conff->next) {
     342                 :          0 :     namenode = fsys_hash_find_node(conff->name, 0); /* XXX */
     343                 :          0 :     namenode->flags |= FNNF_OLD_CONFF;
     344         [ #  # ]:          0 :     if (!namenode->oldhash)
     345                 :          0 :       namenode->oldhash = conff->hash;
     346                 :          0 :     debug(dbg_conffdetail, "%s '%s' namenode '%s' flags %o", __func__,
     347                 :          0 :           conff->name, namenode->name, namenode->flags);
     348                 :            :   }
     349                 :          0 : }
     350                 :            : 
     351                 :            : void
     352                 :          0 : log_action(const char *action, struct pkginfo *pkg, struct pkgbin *pkgbin)
     353                 :            : {
     354                 :          0 :   log_message("%s %s %s %s", action, pkgbin_name(pkg, pkgbin, pnaw_always),
     355                 :          0 :               versiondescribe_c(&pkg->installed.version, vdew_nonambig),
     356                 :          0 :               versiondescribe_c(&pkg->available.version, vdew_nonambig));
     357                 :          0 :   statusfd_send("processing: %s: %s", action,
     358                 :            :                 pkgbin_name(pkg, pkgbin, pnaw_nonambig));
     359                 :          0 : }

Generated by: LCOV version 1.16