Exemplo n.º 1
0
/* Set the engine info for the context CTX, protocol PROTO, to the
   file name FILE_NAME and the home directory HOME_DIR.  */
gpgme_error_t
gpgme_ctx_set_engine_info (gpgme_ctx_t ctx, gpgme_protocol_t proto,
			   const char *file_name, const char *home_dir)
{
  gpgme_error_t err;
  TRACE_BEG4 (DEBUG_CTX, "gpgme_ctx_set_engine_info", ctx,
	      "protocol=%i (%s), file_name=%s, home_dir=%s",
	      proto, gpgme_get_protocol_name (proto)
	      ? gpgme_get_protocol_name (proto) : "unknown",
	      file_name ? file_name : "(default)",
	      home_dir ? home_dir : "(default)");

  if (!ctx)
    return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));

  /* Shut down the engine when changing engine info.  */
  if (ctx->engine)
    {
      TRACE_LOG1 ("releasing ctx->engine=%p", ctx->engine);
      _gpgme_engine_release (ctx->engine);
      ctx->engine = NULL;
    }
  err = _gpgme_set_engine_info (ctx->engine_info, proto,
				file_name, home_dir);
  return TRACE_ERR (err);
}
Exemplo n.º 2
0
Arquivo: data-mem.c Projeto: gpg/gpgme
/* Create a new data buffer filled with SIZE bytes starting from
   BUFFER.  If COPY is zero, copying is delayed until necessary, and
   the data is taken from the original location when needed.  */
gpgme_error_t
gpgme_data_new_from_mem (gpgme_data_t *r_dh, const char *buffer,
			 size_t size, int copy)
{
  gpgme_error_t err;
  TRACE_BEG4 (DEBUG_DATA, "gpgme_data_new_from_mem", r_dh,
	      "buffer=%p, size=%u, copy=%i (%s)", buffer, size,
	      copy, copy ? "yes" : "no");

  err = _gpgme_data_new (r_dh, &mem_cbs);
  if (err)
    return TRACE_ERR (err);

  if (copy)
    {
      char *bufcpy = malloc (size);
      if (!bufcpy)
	{
	  int saved_err = gpg_error_from_syserror ();
	  _gpgme_data_release (*r_dh);
	  return TRACE_ERR (saved_err);
	}
      memcpy (bufcpy, buffer, size);
      (*r_dh)->data.mem.buffer = bufcpy;
    }
  else
    (*r_dh)->data.mem.orig_buffer = buffer;

  (*r_dh)->data.mem.size = size;
  (*r_dh)->data.mem.length = size;
  return TRACE_SUC1 ("dh=%p", *r_dh);
}
Exemplo n.º 3
0
gpgme_error_t
gpgme_op_vfs_mount (gpgme_ctx_t ctx, const char *container_file,
		    const char *mount_dir, unsigned int flags,
		    gpgme_error_t *op_err)
{
  gpg_error_t err;

  TRACE_BEG4 (DEBUG_CTX, "gpgme_op_vfs_mount", ctx,
	      "container=%s, mount_dir=%s, flags=0x%x, op_err=%p",
	      container_file, mount_dir, flags, op_err);

  if (!ctx)
    return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));

  err = _gpgme_op_vfs_mount (ctx, container_file, mount_dir, flags, op_err);
  return TRACE_ERR (err);
}
Exemplo n.º 4
0
/* Create a new data buffer filled with LENGTH bytes starting from
   OFFSET within the file FNAME or stream STREAM (exactly one must be
   non-zero).  */
gpgme_error_t
gpgme_data_new_from_filepart (gpgme_data_t *r_dh, const char *fname,
			      FILE *stream, off_t offset, size_t length)
{
  gpgme_error_t err;
  char *buf = NULL;
  int res;

  TRACE_BEG4 (DEBUG_DATA, "gpgme_data_new_from_filepart", r_dh,
	      "file_name=%s, stream=%p, offset=%lli, length=%u",
	      fname, stream, offset, length);

  if (stream && fname)
    return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));

  if (fname)
    stream = fopen (fname, "rb");
  if (!stream)
    return TRACE_ERR (gpg_error_from_errno (errno));

#ifdef HAVE_FSEEKO
  res = fseeko (stream, offset, SEEK_SET);
#else
  /* FIXME: Check for overflow, or at least bail at compilation.  */
  res = fseek (stream, offset, SEEK_SET);
#endif

  if (res)
    {
      int saved_errno = errno;
      if (fname)
	fclose (stream);
      return TRACE_ERR (gpg_error_from_errno (saved_errno));
    }

  buf = malloc (length);
  if (!buf)
    {
      int saved_errno = errno;
      if (fname)
	fclose (stream);
      return TRACE_ERR (gpg_error_from_errno (saved_errno));
    }

  while (fread (buf, length, 1, stream) < 1
	 && ferror (stream) && errno == EINTR);
  if (ferror (stream))
    {
      int saved_errno = errno;
      if (buf)
	free (buf);
      if (fname)
	fclose (stream);
      return TRACE_ERR (gpg_error_from_errno (saved_errno));
    }

  if (fname)
    fclose (stream);

  err = gpgme_data_new (r_dh);
  if (err)
    {
      if (buf)
	free (buf);
      return err;
    }

  (*r_dh)->data.mem.buffer = buf;
  (*r_dh)->data.mem.size = length;
  (*r_dh)->data.mem.length = length;

  return TRACE_SUC1 ("r_dh=%p", *r_dh);
}