generator: Make documentation inside guestfish match man page.
[libguestfs.git] / src / guestfs.c
index 0e4cb73..85a042a 100644 (file)
@@ -183,6 +183,8 @@ struct guestfs_h
   void *                     subprocess_quit_cb_data;
   guestfs_launch_done_cb     launch_done_cb;
   void *                     launch_done_cb_data;
+  guestfs_close_cb           close_cb;
+  void *                     close_cb_data;
 
   int msg_next_serial;
 };
@@ -294,6 +296,10 @@ guestfs_close (guestfs_h *g)
   if (g->verbose)
     fprintf (stderr, "closing guestfs handle %p (state %d)\n", g, g->state);
 
+  /* Run user close callback before anything else. */
+  if (g->close_cb)
+    g->close_cb (g, g->close_cb_data);
+
   /* Try to sync if autosync flag is set. */
   if (g->autosync && g->state == READY) {
     guestfs_umount_all (g);
@@ -976,6 +982,14 @@ guestfs__launch (guestfs_h *g)
     }
   }
 
+  /* Allow anyone to read the temporary directory.  There are no
+   * secrets in the kernel or initrd files.  The socket in this
+   * directory won't be readable but anyone can see it exists if they
+   * want. (RHBZ#610880).
+   */
+  if (chmod (g->tmpdir, 0755) == -1)
+    fprintf (stderr, "chmod: %s: %m (ignored)\n", g->tmpdir);
+
   /* First search g->path for the supermin appliance, and try to
    * synthesize a kernel and initrd from that.  If it fails, we
    * try the path search again looking for a backup ordinary
@@ -1584,7 +1598,11 @@ build_supermin_appliance (guestfs_h *g, const char *path,
   *initrd = safe_malloc (g, len + 8);
   snprintf (*initrd, len+8, "%s/initrd", g->tmpdir);
 
+  /* Set a sensible umask in the subprocess, so kernel and initrd
+   * output files are world-readable (RHBZ#610880).
+   */
   snprintf (cmd, sizeof cmd,
+            "umask 0002; "
             "febootstrap-supermin-helper%s "
             "-k '%s/kmod.whitelist' "
             "'%s/supermin.d' "
@@ -1927,6 +1945,14 @@ guestfs_set_launch_done_callback (guestfs_h *g,
   g->launch_done_cb_data = opaque;
 }
 
+void
+guestfs_set_close_callback (guestfs_h *g,
+                            guestfs_close_cb cb, void *opaque)
+{
+  g->close_cb = cb;
+  g->close_cb_data = opaque;
+}
+
 /*----------------------------------------------------------------------*/
 
 /* This is the code used to send and receive RPC messages and (for