Skip to content

Commit

Permalink
inspect: improve UsrMove detection (RHBZ#1186935)
Browse files Browse the repository at this point in the history
In case /usr is a symlink to /usr/bin, then we cannot rely on /usr/bin
to exist, since /usr might be in a different partition.  Thus, in case
/bin is a symlink, check it points to "usr/bin".
  • Loading branch information
ptoscano committed Mar 17, 2016
1 parent b0be4c1 commit 1df34fd
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/inspect-fs.c
Expand Up @@ -43,6 +43,7 @@ static int check_filesystem (guestfs_h *g, const char *mountable,
int whole_device);
static void extend_fses (guestfs_h *g);
static int get_partition_context (guestfs_h *g, const char *partition, int *partnum_ret, int *nr_partitions_ret);
static int is_symlink_to (guestfs_h *g, const char *file, const char *wanted_target);

/* Find out if 'device' contains a filesystem. If it does, add
* another entry in g->fses.
Expand Down Expand Up @@ -215,8 +216,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
/* Linux root? */
else if (is_dir_etc &&
(is_dir_bin ||
(guestfs_is_symlink (g, "/bin") > 0 &&
guestfs_is_dir (g, "/usr/bin") > 0)) &&
is_symlink_to (g, "/bin", "usr/bin") > 0) &&
guestfs_is_file (g, "/etc/fstab") > 0) {
fs->is_root = 1;
fs->format = OS_FORMAT_INSTALLED;
Expand Down Expand Up @@ -366,6 +366,22 @@ get_partition_context (guestfs_h *g, const char *partition,
return 0;
}

static int
is_symlink_to (guestfs_h *g, const char *file, const char *wanted_target)
{
CLEANUP_FREE char *target = NULL;

if (guestfs_is_symlink (g, file) == 0)
return 0;

target = guestfs_readlink (g, file);
/* This should not fail, but play safe. */
if (target == NULL)
return 0;

return STREQ (target, wanted_target);
}

int
guestfs_int_is_file_nocase (guestfs_h *g, const char *path)
{
Expand Down

0 comments on commit 1df34fd

Please sign in to comment.