/* The container is automatically uncreateed when the context is reset
   or destroyed.  This is a synchronous convenience interface, which
   automatically returns an operation error if there is no
   transmission error.  */
static gpgme_error_t
_gpgme_op_vfs_create (gpgme_ctx_t ctx, gpgme_key_t recp[],
		      const char *container_file, unsigned int flags,
		      gpgme_error_t *op_err)
{
  gpg_error_t err;
  char *cmd;
  char *container_file_esc = NULL;
  int i;

  /* We want to encourage people to check error values, so not getting
     them is discouraged here.  Also makes our code easier.  */
  if (! op_err)
    return gpg_error (GPG_ERR_INV_VALUE);

  err = _gpgme_encode_percent_string (container_file, &container_file_esc, 0);
  if (err)
    return err;

  i = 0;
  while (!err && recp[i])
    {
      if (!recp[i]->subkeys || !recp[i]->subkeys->fpr)
	{
	  free (container_file_esc);
	  return gpg_error (GPG_ERR_UNUSABLE_PUBKEY);
	}

      if (asprintf (&cmd, "RECIPIENT %s", recp[i]->subkeys->fpr) < 0)
	{
	  err = gpg_error_from_syserror ();
	  free (container_file_esc);
	  return err;
	}
      
      err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL,
				   NULL, NULL, op_err);
      free (cmd);
      if (err || *op_err)
	{
	  free (container_file_esc);
	  return err;
	}
      recp++;
    }

  if (asprintf (&cmd, "CREATE -- %s", container_file_esc) < 0)
    {
      err = gpg_error_from_syserror ();
      free (container_file_esc);
      return err;
    }
  free (container_file_esc);
    
  err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL,
			       NULL, NULL, op_err);
  free (cmd);

  return err;
}
Exemple #2
0
/* The container is automatically unmounted when the context is reset
   or destroyed.  This is a synchronous convenience interface, which
   automatically returns an operation error if there is no
   transmission error.  */
static gpgme_error_t
_gpgme_op_vfs_mount (gpgme_ctx_t ctx, const char *container_file,
		     const char *mount_dir, int flags, gpgme_error_t *op_err)
{
  gpg_error_t err;
  char *cmd;
  char *container_file_esc = NULL;

  /* We want to encourage people to check error values, so not getting
     them is discouraged here.  Also makes our code easier.  */
  if (! op_err)
    return gpg_error (GPG_ERR_INV_VALUE);

  err = _gpgme_encode_percent_string (container_file, &container_file_esc, 0);
  if (err)
    return err;

  if (asprintf (&cmd, "OPEN -- %s", container_file_esc) < 0)
    {
      err = gpg_error_from_syserror ();
      free (container_file_esc);
      return err;
    }
  free (container_file_esc);

  err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL,
			       NULL, NULL, op_err);
  free (cmd);
  if (err || *op_err)
    return err;

  if (mount_dir)
    {
      char *mount_dir_esc = NULL;

      err = _gpgme_encode_percent_string (mount_dir, &mount_dir_esc, 0);
      if (err)
	return err;

      if (asprintf (&cmd, "MOUNT -- %s", mount_dir_esc) < 0)
	{
	  err = gpg_error_from_syserror ();
	  free (mount_dir_esc);
	  return err;
	}
      free (mount_dir_esc);
    }
  else
    {
      if (asprintf (&cmd, "MOUNT") < 0)
	return gpg_error_from_syserror ();
    }

  err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL,
			       _gpgme_vfs_mount_status_handler, ctx, op_err);
  free (cmd);

  return err;
}