Exemplo n.º 1
0
static int
fg_chmod (const char *path, mode_t mode)
{
  TRACE_CALL ("%s, 0%o", path, mode);

  int r;

  if (read_only) return -EROFS;

  dir_cache_invalidate (path);

  r = guestfs_chmod (g, mode, path);
  if (r == -1)
    return error ();

  return 0;
}
Exemplo n.º 2
0
static int
mount_local_chmod (const char *path, mode_t mode)
{
  int r;
  DECL_G ();
  DEBUG_CALL ("%s, 0%o", path, mode);

  if (g->ml_read_only) return -EROFS;

  dir_cache_invalidate (g, path);

  r = guestfs_chmod (g, mode, path);
  if (r == -1)
    RETURN_ERRNO;

  return 0;
}
Exemplo n.º 3
0
static int
copy_attributes (const char *src, const char *dest)
{
  CLEANUP_FREE_STAT struct guestfs_stat *stat = NULL;
  const char *linuxxattrs[] = { "linuxxattrs", NULL };
  int has_linuxxattrs;
  CLEANUP_FREE char *selinux_context = NULL;
  size_t selinux_context_size;

  has_linuxxattrs = guestfs_feature_available (g, (char **) linuxxattrs);

  /* Get the mode. */
  stat = guestfs_stat (g, src);
  if (stat == NULL)
    return -1;

  /* Get the SELinux context.  XXX Should we copy over other extended
   * attributes too?
   */
  if (has_linuxxattrs) {
    guestfs_push_error_handler (g, NULL, NULL);

    selinux_context = guestfs_getxattr (g, src, "security.selinux",
                                        &selinux_context_size);
    /* selinux_context could be NULL.  This isn't an error. */

    guestfs_pop_error_handler (g);
  }

  /* Set the permissions (inc. sticky and set*id bits), UID, GID. */
  if (guestfs_chmod (g, stat->mode & 07777, dest) == -1)
    return -1;
  if (guestfs_chown (g, stat->uid, stat->gid, dest) == -1)
    return -1;

  /* Set the SELinux context. */
  if (has_linuxxattrs && selinux_context) {
    if (guestfs_setxattr (g, "security.selinux", selinux_context,
                          (int) selinux_context_size, dest) == -1)
      return -1;
  }

  return 0;
}