X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=src%2Finspect_apps.c;h=dad5d0bb5c0f1ad7fd7043a6da76954106efd2a7;hb=d0c7e1d994f1b6ee64cc131d87cd652a2afba0d6;hp=df99df9fdddec7f39983b99457e76a5d060bb764;hpb=8e6e547af32116accfe4aa9cae36d3cd073f1c66;p=libguestfs.git diff --git a/src/inspect_apps.c b/src/inspect_apps.c index df99df9..dad5d0b 100644 --- a/src/inspect_apps.c +++ b/src/inspect_apps.c @@ -126,6 +126,28 @@ guestfs__inspect_list_applications (guestfs_h *g, const char *root) } #ifdef DB_DUMP + +static int +read_rpm_name (guestfs_h *g, + const unsigned char *key, size_t keylen, + const unsigned char *value, size_t valuelen, + void *appsv) +{ + struct guestfs_application_list *apps = appsv; + char *name; + + /* The name (key) field won't be NUL-terminated, so we must do that. */ + name = safe_malloc (g, keylen+1); + memcpy (name, key, keylen); + name[keylen] = '\0'; + + add_application (g, apps, name, "", 0, "", "", "", "", "", ""); + + free (name); + + return 0; +} + static struct guestfs_application_list * list_applications_rpm (guestfs_h *g, struct inspect_fs *fs) { @@ -138,95 +160,20 @@ list_applications_rpm (guestfs_h *g, struct inspect_fs *fs) MAX_PKG_DB_SIZE) == -1) return NULL; - struct guestfs_application_list *apps = NULL, *ret = NULL; -#define cmd_len (strlen (tmpdir_basename) + 64) - char cmd[cmd_len]; - FILE *pp = NULL; - char line[1024]; - size_t len; - - snprintf (cmd, cmd_len, DB_DUMP " -p '%s'", tmpdir_basename); - - debug (g, "list_applications_rpm: %s", cmd); - - pp = popen (cmd, "r"); - if (pp == NULL) { - perrorf (g, "popen: %s", cmd); - goto out; - } - - /* Ignore everything to end-of-header marker. */ - for (;;) { - if (fgets (line, sizeof line, pp) == NULL) { - error (g, _("unexpected end of output from db_dump command")); - goto out; - } - - len = strlen (line); - if (len > 0 && line[len-1] == '\n') { - line[len-1] = '\0'; - len--; - } - - if (STREQ (line, "HEADER=END")) - break; - } - /* Allocate 'apps' list. */ + struct guestfs_application_list *apps; apps = safe_malloc (g, sizeof *apps); apps->len = 0; apps->val = NULL; - /* Read alternate lines until end of data marker. */ - for (;;) { - if (fgets (line, sizeof line, pp) == NULL) { - error (g, _("unexpected end of output from db_dump command")); - goto out; - } - - len = strlen (line); - if (len > 0 && line[len-1] == '\n') { - line[len-1] = '\0'; - len--; - } - - if (STREQ (line, "DATA=END")) - break; - - char *p = line; - if (len > 0 && line[0] == ' ') - p = line+1; - /* Ignore any application name that contains non-printable chars. - * In the db_dump output these would be escaped with backslash, so - * we can just ignore any such line. - */ - if (strchr (p, '\\') == NULL) - add_application (g, apps, p, "", 0, "", "", "", "", "", ""); - - /* Discard next line. */ - if (fgets (line, sizeof line, pp) == NULL) { - error (g, _("unexpected end of output from db_dump command")); - goto out; - } - } - - /* Catch errors from the db_dump command. */ - if (pclose (pp) == -1) { - perrorf (g, "pclose: %s", cmd); - goto out; - } - pp = NULL; - - ret = apps; - - out: - if (ret == NULL && apps != NULL) + if (guestfs___read_db_dump (g, tmpdir_basename, apps, read_rpm_name) == -1) { guestfs_free_application_list (apps); - if (pp) - pclose (pp); + return NULL; + } - return ret; + return apps; } + #endif /* defined DB_DUMP */ static struct guestfs_application_list * @@ -340,11 +287,11 @@ list_applications_windows (guestfs_h *g, struct inspect_fs *fs) fs->windows_systemroot); char *software_path = guestfs___case_sensitive_path_silently (g, software); - if (!software_path) - /* If the software hive doesn't exist, just accept that we cannot - * list windows apps. - */ - return 0; + if (!software_path) { + /* Missing software hive is a problem. */ + error (g, "no HKLM\\SOFTWARE hive found in the guest"); + return NULL; + } struct guestfs_application_list *ret = NULL; hive_h *h = NULL;