/* There are several sources we might use: * - /ProgramData/Microsoft/Windows Live/WLive48x48.png * - w-brand.png (in a very long directory name) * - /Windows/System32/slui.exe --type=14 group icon #2 */ static char * icon_windows_8 (guestfs_h *g, struct inspect_fs *fs, size_t *size_r) { char *filename_case = NULL; char *filename_downloaded = NULL; char *ret; filename_case = guestfs___case_sensitive_path_silently (g, "/ProgramData/Microsoft/Windows Live/WLive48x48.png"); if (filename_case == NULL) goto not_found; filename_downloaded = guestfs___download_to_tmp (g, fs, filename_case, "wlive48x48.png", 8192); if (filename_downloaded == NULL) goto not_found; if (read_whole_file (g, filename_downloaded, &ret, size_r) == -1) goto error; free (filename_case); free (filename_downloaded); return ret; error: free (filename_case); free (filename_downloaded); return NULL; not_found: free (filename_case); free (filename_downloaded); return NOT_FOUND; }
/* There are several sources we might use: * - /ProgramData/Microsoft/Windows Live/WLive48x48.png * - w-brand.png (in a very long directory name) * - /Windows/System32/slui.exe --type=14 group icon #2 */ static char * icon_windows_8 (guestfs_h *g, struct inspect_fs *fs, size_t *size_r) { CLEANUP_FREE char *filename_case = NULL; CLEANUP_FREE char *filename_downloaded = NULL; int r; char *ret; filename_case = guestfs___case_sensitive_path_silently (g, "/ProgramData/Microsoft/Windows Live/WLive48x48.png"); if (filename_case == NULL) return NOT_FOUND; /* Not an error since a parent dir might not exist. */ guestfs_push_error_handler (g, NULL, NULL); r = guestfs_is_file (g, filename_case); guestfs_pop_error_handler (g); if (r == -1) return NULL; if (r == 0) return NOT_FOUND; filename_downloaded = guestfs___download_to_tmp (g, fs, filename_case, "wlive48x48.png", 8192); if (filename_downloaded == NULL) return NOT_FOUND; if (read_whole_file (g, filename_downloaded, &ret, size_r) == -1) return NULL; return ret; }
static char * icon_cirros (guestfs_h *g, struct inspect_fs *fs, size_t *size_r) { char *ret = NOT_FOUND; char *type = NULL; char *local = NULL; char *pngfile = NULL; struct command *cmd; int r; r = guestfs_exists (g, CIRROS_LOGO); if (r == -1) { ret = NULL; /* a real error */ goto out; } if (r == 0) goto out; /* Check the file type and geometry. */ type = guestfs_file (g, CIRROS_LOGO); if (!type) goto out; if (!STRPREFIX (type, "ASCII text")) goto out; local = guestfs___download_to_tmp (g, fs, CIRROS_LOGO, "icon", 1024); if (!local) goto out; /* Use pbmtext to render it. */ pngfile = safe_asprintf (g, "%s/cirros.png", g->tmpdir); cmd = guestfs___new_command (g); guestfs___cmd_add_string_unquoted (cmd, PBMTEXT " < "); guestfs___cmd_add_string_quoted (cmd, local); guestfs___cmd_add_string_unquoted (cmd, " | " PNMTOPNG " > "); guestfs___cmd_add_string_quoted (cmd, pngfile); r = guestfs___cmd_run (cmd); guestfs___cmd_close (cmd); if (r == -1) goto out; if (!WIFEXITED (r) || WEXITSTATUS (r) != 0) goto out; /* Read it into memory. */ if (read_whole_file (g, pngfile, &ret, size_r) == -1) { ret = NULL; goto out; } out: free (pngfile); free (local); free (type); return ret; }
/* Check that the named file 'filename' is a PNG file and is reasonable. * If it is, download and return it. */ static char * get_png (guestfs_h *g, struct inspect_fs *fs, const char *filename, size_t *size_r, size_t max_size) { char *ret; CLEANUP_FREE char *real = NULL; CLEANUP_FREE char *type = NULL; CLEANUP_FREE char *local = NULL; int r, w, h; r = guestfs_is_file_opts (g, filename, GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1); if (r == -1) return NULL; /* a real error */ if (r == 0) return NOT_FOUND; /* Resolve the path, in case it's a symbolic link (as in RHEL 7). */ guestfs_push_error_handler (g, NULL, NULL); real = guestfs_realpath (g, filename); guestfs_pop_error_handler (g); if (real == NULL) return NOT_FOUND; /* could just be a broken link */ /* Check the file type and geometry. */ type = guestfs_file (g, real); if (!type) return NOT_FOUND; if (!STRPREFIX (type, "PNG image data, ")) return NOT_FOUND; if (sscanf (&type[16], "%d x %d", &w, &h) != 2) return NOT_FOUND; if (w < 16 || h < 16 || w > 1024 || h > 1024) return NOT_FOUND; /* Define a maximum reasonable size based on the geometry. This * also limits the maximum we allocate below to around 4 MB. */ if (max_size == 0) max_size = 4 * w * h; local = guestfs___download_to_tmp (g, fs, real, "icon", max_size); if (!local) return NOT_FOUND; /* Successfully passed checks and downloaded. Read it into memory. */ if (read_whole_file (g, local, &ret, size_r) == -1) return NULL; return ret; }
static char * icon_windows_7 (guestfs_h *g, struct inspect_fs *fs, size_t *size_r) { CLEANUP_FREE char *filename = NULL; CLEANUP_FREE char *filename_case = NULL; CLEANUP_FREE char *filename_downloaded = NULL; CLEANUP_FREE char *pngfile = NULL; CLEANUP_CMD_CLOSE struct command *cmd = guestfs___new_command (g); int r; char *ret; /* Download %systemroot%\explorer.exe */ filename = safe_asprintf (g, "%s/explorer.exe", fs->windows_systemroot); filename_case = guestfs_case_sensitive_path (g, filename); if (filename_case == NULL) return NULL; guestfs_push_error_handler (g, NULL, NULL); r = guestfs_is_file (g, filename_case); guestfs_pop_error_handler (g); if (r == -1) return NULL; if (r == 0) return NOT_FOUND; filename_downloaded = guestfs___download_to_tmp (g, fs, filename_case, "explorer.exe", MAX_WINDOWS_EXPLORER_SIZE); if (filename_downloaded == NULL) return NOT_FOUND; pngfile = safe_asprintf (g, "%s/windows-7-icon.png", g->tmpdir); guestfs___cmd_add_string_unquoted (cmd, WRESTOOL " -x --type=2 --name=6801 "); guestfs___cmd_add_string_quoted (cmd, filename_downloaded); guestfs___cmd_add_string_unquoted (cmd, " | " BMPTOPNM " | " PAMCUT " -bottom 54 | " PNMTOPNG " > "); guestfs___cmd_add_string_quoted (cmd, pngfile); r = guestfs___cmd_run (cmd); if (r == -1) return NULL; if (!WIFEXITED (r) || WEXITSTATUS (r) != 0) return NOT_FOUND; if (read_whole_file (g, pngfile, &ret, size_r) == -1) return NULL; return ret; }
static char * icon_cirros (guestfs_h *g, struct inspect_fs *fs, size_t *size_r) { char *ret; CLEANUP_FREE char *type = NULL; CLEANUP_FREE char *local = NULL; CLEANUP_FREE char *pngfile = NULL; CLEANUP_CMD_CLOSE struct command *cmd = guestfs___new_command (g); int r; r = guestfs_is_file_opts (g, CIRROS_LOGO, GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1); if (r == -1) return NULL; /* a real error */ if (r == 0) return NOT_FOUND; /* Check the file type and geometry. */ type = guestfs_file (g, CIRROS_LOGO); if (!type) return NOT_FOUND; if (!STRPREFIX (type, "ASCII text")) return NOT_FOUND; local = guestfs___download_to_tmp (g, fs, CIRROS_LOGO, "icon", 1024); if (!local) return NOT_FOUND; /* Use pbmtext to render it. */ pngfile = safe_asprintf (g, "%s/cirros.png", g->tmpdir); guestfs___cmd_add_string_unquoted (cmd, PBMTEXT " < "); guestfs___cmd_add_string_quoted (cmd, local); guestfs___cmd_add_string_unquoted (cmd, " | " PNMTOPNG " > "); guestfs___cmd_add_string_quoted (cmd, pngfile); r = guestfs___cmd_run (cmd); if (r == -1) return NOT_FOUND; if (!WIFEXITED (r) || WEXITSTATUS (r) != 0) return NOT_FOUND; /* Read it into memory. */ if (read_whole_file (g, pngfile, &ret, size_r) == -1) return NULL; return ret; }
/* Check that the named file 'filename' is a PNG file and is reasonable. * If it is, download and return it. */ static char * get_png (guestfs_h *g, struct inspect_fs *fs, const char *filename, size_t *size_r, size_t max_size) { char *ret = NOT_FOUND; char *type = NULL; char *local = NULL; int r, w, h; r = guestfs_exists (g, filename); if (r == -1) { ret = NULL; /* a real error */ goto out; } if (r == 0) goto out; /* Check the file type and geometry. */ type = guestfs_file (g, filename); if (!type) goto out; if (!STRPREFIX (type, "PNG image data, ")) goto out; if (sscanf (&type[16], "%d x %d", &w, &h) != 2) goto out; if (w < 16 || h < 16 || w > 1024 || h > 1024) goto out; /* Define a maximum reasonable size based on the geometry. This * also limits the maximum we allocate below to around 4 MB. */ if (max_size == 0) max_size = 4 * w * h; local = guestfs___download_to_tmp (g, fs, filename, "icon", max_size); if (!local) goto out; /* Successfully passed checks and downloaded. Read it into memory. */ if (read_whole_file (g, local, &ret, size_r) == -1) { ret = NULL; goto out; } out: free (local); free (type); return ret; }
static char * icon_windows_7 (guestfs_h *g, struct inspect_fs *fs, size_t *size_r) { char *filename = NULL; char *filename_case = NULL; char *filename_downloaded = NULL; char *pngfile = NULL; char *ret; struct command *cmd; int r; /* Download %systemroot%\explorer.exe */ filename = safe_asprintf (g, "%s/explorer.exe", fs->windows_systemroot); filename_case = guestfs___case_sensitive_path_silently (g, filename); if (filename_case == NULL) goto not_found; filename_downloaded = guestfs___download_to_tmp (g, fs, filename_case, "explorer.exe", MAX_WINDOWS_EXPLORER_SIZE); if (filename_downloaded == NULL) goto not_found; pngfile = safe_asprintf (g, "%s/windows-7-icon.png", g->tmpdir); cmd = guestfs___new_command (g); guestfs___cmd_add_string_unquoted (cmd, WRESTOOL " -x --type=2 --name=6801 "); guestfs___cmd_add_string_quoted (cmd, filename_downloaded); guestfs___cmd_add_string_unquoted (cmd, " | " BMPTOPNM " | " PAMCUT " -bottom 54 | " PNMTOPNG " > "); guestfs___cmd_add_string_quoted (cmd, pngfile); r = guestfs___cmd_run (cmd); guestfs___cmd_close (cmd); if (r == -1) goto error; if (!WIFEXITED (r) || WEXITSTATUS (r) != 0) goto not_found; if (read_whole_file (g, pngfile, &ret, size_r) == -1) goto error; free (filename); free (filename_case); free (filename_downloaded); free (pngfile); return ret; error: free (filename); free (filename_case); free (filename_downloaded); free (pngfile); return NULL; not_found: free (filename); free (filename_case); free (filename_downloaded); free (pngfile); return NOT_FOUND; }