/* Try several methods to determine the hostname from a Linux or * FreeBSD guest. Note that type and distro have been set, so we can * use that information to direct the search. */ static int check_hostname_unix (guestfs_h *g, struct inspect_fs *fs) { switch (fs->type) { case OS_TYPE_LINUX: case OS_TYPE_HURD: /* Red Hat-derived would be in /etc/sysconfig/network or * /etc/hostname (RHEL 7+, F18+). Debian-derived in the file * /etc/hostname. Very old Debian and SUSE use /etc/HOSTNAME. * It's best to just look for each of these files in turn, rather * than try anything clever based on distro. */ if (guestfs_is_file (g, "/etc/HOSTNAME")) { fs->hostname = guestfs___first_line_of_file (g, "/etc/HOSTNAME"); if (fs->hostname == NULL) return -1; if (STREQ (fs->hostname, "")) { free (fs->hostname); fs->hostname = NULL; } } if (!fs->hostname && guestfs_is_file (g, "/etc/hostname")) { fs->hostname = guestfs___first_line_of_file (g, "/etc/hostname"); if (fs->hostname == NULL) return -1; if (STREQ (fs->hostname, "")) { free (fs->hostname); fs->hostname = NULL; } } if (!fs->hostname && guestfs_is_file (g, "/etc/sysconfig/network")) { const char *configfiles[] = { "/etc/sysconfig/network", NULL }; if (inspect_with_augeas (g, fs, configfiles, check_hostname_redhat) == -1) return -1; } break; case OS_TYPE_FREEBSD: case OS_TYPE_NETBSD: /* /etc/rc.conf contains the hostname, but there is no Augeas lens * for this file. */ if (guestfs_is_file (g, "/etc/rc.conf")) { if (check_hostname_freebsd (g, fs) == -1) return -1; } break; case OS_TYPE_WINDOWS: /* not here, see check_windows_system_registry */ case OS_TYPE_DOS: case OS_TYPE_OPENBSD: case OS_TYPE_UNKNOWN: /* nothing */; } return 0; }
/* Debian/Ubuntu install disks are easy ... * * These files are added by the debian-cd program, and it is worth * looking at the source code to determine exact values, in * particular '/usr/share/debian-cd/tools/start_new_disc' * * XXX Architecture? We could parse it out of the product name * string, but that seems quite hairy. We could look for the names * of packages. Also note that some Debian install disks are * multiarch. */ static int check_debian_installer_root (guestfs_h *g, struct inspect_fs *fs) { fs->product_name = guestfs___first_line_of_file (g, "/.disk/info"); if (!fs->product_name) return -1; fs->type = OS_TYPE_LINUX; if (STRPREFIX (fs->product_name, "Ubuntu")) fs->distro = OS_DISTRO_UBUNTU; else if (STRPREFIX (fs->product_name, "Debian")) fs->distro = OS_DISTRO_DEBIAN; (void) guestfs___parse_major_minor (g, fs); if (guestfs_is_file (g, "/.disk/cd_type") > 0) { char *cd_type = guestfs___first_line_of_file (g, "/.disk/cd_type"); if (!cd_type) return -1; if (STRPREFIX (cd_type, "dvd/single") || STRPREFIX (cd_type, "full_cd/single")) { fs->is_multipart_disk = 0; fs->is_netinst_disk = 0; } else if (STRPREFIX (cd_type, "dvd") || STRPREFIX (cd_type, "full_cd")) { fs->is_multipart_disk = 1; fs->is_netinst_disk = 0; } else if (STRPREFIX (cd_type, "not_complete")) { fs->is_multipart_disk = 0; fs->is_netinst_disk = 1; } free (cd_type); } return 0; }
/* Set fs->product_name to the first line of the release file. */ static int parse_release_file (guestfs_h *g, struct inspect_fs *fs, const char *release_filename) { fs->product_name = guestfs___first_line_of_file (g, release_filename); if (fs->product_name == NULL) return -1; if (STREQ (fs->product_name, "")) { free (fs->product_name); fs->product_name = NULL; error (g, _("release file %s is empty or malformed"), release_filename); return -1; } return 0; }