|
Packit Service |
672cf4 |
/* export.c - Export a key.
|
|
Packit Service |
0ef63b |
* Copyright (C) 2000 Werner Koch (dd9jn)
|
|
Packit Service |
0ef63b |
* Copyright (C) 2001-2004, 2010, 2014 g10 Code GmbH
|
|
Packit Service |
0ef63b |
*
|
|
Packit Service |
0ef63b |
* This file is part of GPGME.
|
|
Packit Service |
0ef63b |
*
|
|
Packit Service |
0ef63b |
* GPGME is free software; you can redistribute it and/or modify it
|
|
Packit Service |
0ef63b |
* under the terms of the GNU Lesser General Public License as
|
|
Packit Service |
0ef63b |
* published by the Free Software Foundation; either version 2.1 of
|
|
Packit Service |
0ef63b |
* the License, or (at your option) any later version.
|
|
Packit Service |
0ef63b |
*
|
|
Packit Service |
0ef63b |
* GPGME is distributed in the hope that it will be useful, but
|
|
Packit Service |
0ef63b |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
0ef63b |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
0ef63b |
* Lesser General Public License for more details.
|
|
Packit Service |
0ef63b |
*
|
|
Packit Service |
0ef63b |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
0ef63b |
* License along with this program; if not, see <https://gnu.org/licenses/>.
|
|
Packit Service |
0ef63b |
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
Packit Service |
672cf4 |
*/
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
#if HAVE_CONFIG_H
|
|
Packit Service |
672cf4 |
#include <config.h>
|
|
Packit Service |
672cf4 |
#endif
|
|
Packit Service |
672cf4 |
#include <stdlib.h>
|
|
Packit Service |
672cf4 |
#include <string.h>
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
#include "gpgme.h"
|
|
Packit Service |
672cf4 |
#include "util.h"
|
|
Packit Service |
672cf4 |
#include "debug.h"
|
|
Packit Service |
672cf4 |
#include "context.h"
|
|
Packit Service |
672cf4 |
#include "ops.h"
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
/* Local operation data. */
|
|
Packit Service |
672cf4 |
typedef struct
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
gpg_error_t err; /* Error encountered during the export. */
|
|
Packit Service |
672cf4 |
} *op_data_t;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
static void
|
|
Packit Service |
672cf4 |
release_op_data (void *hook)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
op_data_t opd = (op_data_t) hook;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
(void)opd; /* Nothing to release here. */
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
/* Parse an error status line. Return the error location and the
|
|
Packit Service |
672cf4 |
error code. The function may modify ARGS. */
|
|
Packit Service |
672cf4 |
static char *
|
|
Packit Service |
672cf4 |
parse_error (char *args, gpg_error_t *r_err)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
char *where = strchr (args, ' ');
|
|
Packit Service |
672cf4 |
char *which;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if (where)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
*where = '\0';
|
|
Packit Service |
672cf4 |
which = where + 1;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
where = strchr (which, ' ');
|
|
Packit Service |
672cf4 |
if (where)
|
|
Packit Service |
672cf4 |
*where = '\0';
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
where = args;
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
else
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
*r_err = trace_gpg_error (GPG_ERR_INV_ENGINE);
|
|
Packit Service |
672cf4 |
return NULL;
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
*r_err = atoi (which);
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
return where;
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
static gpgme_error_t
|
|
Packit Service |
672cf4 |
export_status_handler (void *priv, gpgme_status_code_t code, char *args)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
gpgme_ctx_t ctx = (gpgme_ctx_t) priv;
|
|
Packit Service |
672cf4 |
gpgme_error_t err;
|
|
Packit Service |
672cf4 |
void *hook;
|
|
Packit Service |
672cf4 |
op_data_t opd;
|
|
Packit Service |
672cf4 |
const char *loc;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
err = _gpgme_op_data_lookup (ctx, OPDATA_EXPORT, &hook, -1, NULL);
|
|
Packit Service |
672cf4 |
opd = hook;
|
|
Packit Service |
672cf4 |
if (err)
|
|
Packit Service |
672cf4 |
return err;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
switch (code)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
case GPGME_STATUS_ERROR:
|
|
Packit Service |
672cf4 |
loc = parse_error (args, &err;;
|
|
Packit Service |
672cf4 |
if (!loc)
|
|
Packit Service |
672cf4 |
return err;
|
|
Packit Service |
672cf4 |
else if (opd->err)
|
|
Packit Service |
672cf4 |
; /* We only want to report the first error. */
|
|
Packit Service |
672cf4 |
else if (!strcmp (loc, "keyserver_send"))
|
|
Packit Service |
672cf4 |
opd->err = err;
|
|
Packit Service |
672cf4 |
break;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
default:
|
|
Packit Service |
672cf4 |
break;
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
return 0;
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
static gpgme_error_t
|
|
Packit Service |
672cf4 |
export_start (gpgme_ctx_t ctx, int synchronous, const char *pattern,
|
|
Packit Service |
672cf4 |
gpgme_export_mode_t mode, gpgme_data_t keydata)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
gpgme_error_t err;
|
|
Packit Service |
672cf4 |
void *hook;
|
|
Packit Service |
672cf4 |
op_data_t opd;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if ((mode & ~(GPGME_EXPORT_MODE_EXTERN
|
|
Packit Service |
672cf4 |
|GPGME_EXPORT_MODE_MINIMAL
|
|
Packit Service |
672cf4 |
|GPGME_EXPORT_MODE_SECRET
|
|
Packit Service |
672cf4 |
|GPGME_EXPORT_MODE_RAW
|
|
Packit Service |
0ef63b |
|GPGME_EXPORT_MODE_NOUID
|
|
Packit Service |
672cf4 |
|GPGME_EXPORT_MODE_PKCS12)))
|
|
Packit Service |
672cf4 |
return gpg_error (GPG_ERR_INV_VALUE); /* Invalid flags in MODE. */
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if ((mode & GPGME_EXPORT_MODE_SECRET))
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
if ((mode & GPGME_EXPORT_MODE_EXTERN))
|
|
Packit Service |
672cf4 |
return gpg_error (GPG_ERR_INV_FLAG); /* Combination not allowed. */
|
|
Packit Service |
672cf4 |
if ((mode & GPGME_EXPORT_MODE_RAW)
|
|
Packit Service |
672cf4 |
&& (mode & GPGME_EXPORT_MODE_PKCS12))
|
|
Packit Service |
672cf4 |
return gpg_error (GPG_ERR_INV_FLAG); /* Combination not allowed. */
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if (ctx->protocol != GPGME_PROTOCOL_CMS
|
|
Packit Service |
672cf4 |
&& (mode & (GPGME_EXPORT_MODE_RAW|GPGME_EXPORT_MODE_PKCS12)))
|
|
Packit Service |
672cf4 |
return gpg_error (GPG_ERR_INV_FLAG); /* Only supported for X.509. */
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if ((mode & GPGME_EXPORT_MODE_EXTERN))
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
if (keydata)
|
|
Packit Service |
672cf4 |
return gpg_error (GPG_ERR_INV_VALUE);
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
else
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
if (!keydata)
|
|
Packit Service |
672cf4 |
return gpg_error (GPG_ERR_INV_VALUE);
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
err = _gpgme_op_reset (ctx, synchronous);
|
|
Packit Service |
672cf4 |
if (err)
|
|
Packit Service |
672cf4 |
return err;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
err = _gpgme_op_data_lookup (ctx, OPDATA_EXPORT, &hook,
|
|
Packit Service |
672cf4 |
sizeof (*opd), release_op_data);
|
|
Packit Service |
672cf4 |
opd = hook;
|
|
Packit Service |
672cf4 |
if (err)
|
|
Packit Service |
672cf4 |
return err;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
_gpgme_engine_set_status_handler (ctx->engine, export_status_handler, ctx);
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
return _gpgme_engine_op_export (ctx->engine, pattern, mode, keydata,
|
|
Packit Service |
672cf4 |
ctx->use_armor);
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
/* Export the keys listed in PATTERN into KEYDATA. */
|
|
Packit Service |
672cf4 |
gpgme_error_t
|
|
Packit Service |
672cf4 |
gpgme_op_export_start (gpgme_ctx_t ctx, const char *pattern,
|
|
Packit Service |
672cf4 |
gpgme_export_mode_t mode, gpgme_data_t keydata)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
gpgme_error_t err;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
0ef63b |
TRACE_BEG (DEBUG_CTX, "gpgme_op_export_start", ctx,
|
|
Packit Service |
672cf4 |
"pattern=%s, mode=0x%x, keydata=%p", pattern, mode, keydata);
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if (!ctx)
|
|
Packit Service |
672cf4 |
return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
err = export_start (ctx, 0, pattern, mode, keydata);
|
|
Packit Service |
672cf4 |
return TRACE_ERR (err);
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
/* Export the keys listed in PATTERN into KEYDATA. */
|
|
Packit Service |
672cf4 |
gpgme_error_t
|
|
Packit Service |
672cf4 |
gpgme_op_export (gpgme_ctx_t ctx, const char *pattern,
|
|
Packit Service |
672cf4 |
gpgme_export_mode_t mode, gpgme_data_t keydata)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
gpgme_error_t err;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
0ef63b |
TRACE_BEG (DEBUG_CTX, "gpgme_op_export", ctx,
|
|
Packit Service |
672cf4 |
"pattern=%s, mode=0x%x, keydata=%p", pattern, mode, keydata);
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if (!ctx)
|
|
Packit Service |
672cf4 |
return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
err = export_start (ctx, 1, pattern, mode, keydata);
|
|
Packit Service |
672cf4 |
if (!err)
|
|
Packit Service |
672cf4 |
err = _gpgme_wait_one (ctx);
|
|
Packit Service |
672cf4 |
return err;
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
static gpgme_error_t
|
|
Packit Service |
672cf4 |
export_ext_start (gpgme_ctx_t ctx, int synchronous, const char *pattern[],
|
|
Packit Service |
672cf4 |
gpgme_export_mode_t mode, gpgme_data_t keydata)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
gpgme_error_t err;
|
|
Packit Service |
672cf4 |
void *hook;
|
|
Packit Service |
672cf4 |
op_data_t opd;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if ((mode & ~(GPGME_EXPORT_MODE_EXTERN
|
|
Packit Service |
672cf4 |
|GPGME_EXPORT_MODE_MINIMAL
|
|
Packit Service |
672cf4 |
|GPGME_EXPORT_MODE_SECRET
|
|
Packit Service |
672cf4 |
|GPGME_EXPORT_MODE_RAW
|
|
Packit Service |
672cf4 |
|GPGME_EXPORT_MODE_PKCS12)))
|
|
Packit Service |
672cf4 |
return gpg_error (GPG_ERR_INV_VALUE); /* Invalid flags in MODE. */
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if ((mode & GPGME_EXPORT_MODE_SECRET))
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
if ((mode & GPGME_EXPORT_MODE_EXTERN))
|
|
Packit Service |
672cf4 |
return gpg_error (GPG_ERR_INV_FLAG); /* Combination not allowed. */
|
|
Packit Service |
672cf4 |
if ((mode & GPGME_EXPORT_MODE_RAW)
|
|
Packit Service |
672cf4 |
&& (mode & GPGME_EXPORT_MODE_PKCS12))
|
|
Packit Service |
672cf4 |
return gpg_error (GPG_ERR_INV_FLAG); /* Combination not allowed. */
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if (ctx->protocol != GPGME_PROTOCOL_CMS
|
|
Packit Service |
672cf4 |
&& (mode & (GPGME_EXPORT_MODE_RAW|GPGME_EXPORT_MODE_PKCS12)))
|
|
Packit Service |
672cf4 |
return gpg_error (GPG_ERR_INV_FLAG); /* Only supported for X.509. */
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if ((mode & GPGME_EXPORT_MODE_EXTERN))
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
if (keydata)
|
|
Packit Service |
672cf4 |
return gpg_error (GPG_ERR_INV_VALUE);
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
else
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
if (!keydata)
|
|
Packit Service |
672cf4 |
return gpg_error (GPG_ERR_INV_VALUE);
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
err = _gpgme_op_reset (ctx, synchronous);
|
|
Packit Service |
672cf4 |
if (err)
|
|
Packit Service |
672cf4 |
return err;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
err = _gpgme_op_data_lookup (ctx, OPDATA_EXPORT, &hook,
|
|
Packit Service |
672cf4 |
sizeof (*opd), release_op_data);
|
|
Packit Service |
672cf4 |
opd = hook;
|
|
Packit Service |
672cf4 |
if (err)
|
|
Packit Service |
672cf4 |
return err;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
_gpgme_engine_set_status_handler (ctx->engine, export_status_handler, ctx);
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
return _gpgme_engine_op_export_ext (ctx->engine, pattern, mode, keydata,
|
|
Packit Service |
672cf4 |
ctx->use_armor);
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
/* Export the keys listed in PATTERN into KEYDATA. */
|
|
Packit Service |
672cf4 |
gpgme_error_t
|
|
Packit Service |
672cf4 |
gpgme_op_export_ext_start (gpgme_ctx_t ctx, const char *pattern[],
|
|
Packit Service |
672cf4 |
gpgme_export_mode_t mode, gpgme_data_t keydata)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
gpgme_error_t err;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
0ef63b |
TRACE_BEG (DEBUG_CTX, "gpgme_op_export_ext_start", ctx,
|
|
Packit Service |
672cf4 |
"mode=0x%x, keydata=%p", mode, keydata);
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if (!ctx)
|
|
Packit Service |
672cf4 |
return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if (_gpgme_debug_trace () && pattern)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
int i = 0;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
while (pattern[i])
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
0ef63b |
TRACE_LOG ("pattern[%i] = %s", i, pattern[i]);
|
|
Packit Service |
672cf4 |
i++;
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
err = export_ext_start (ctx, 0, pattern, mode, keydata);
|
|
Packit Service |
672cf4 |
return TRACE_ERR (err);
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
/* Export the keys listed in PATTERN into KEYDATA. */
|
|
Packit Service |
672cf4 |
gpgme_error_t
|
|
Packit Service |
672cf4 |
gpgme_op_export_ext (gpgme_ctx_t ctx, const char *pattern[],
|
|
Packit Service |
672cf4 |
gpgme_export_mode_t mode, gpgme_data_t keydata)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
gpgme_error_t err;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
0ef63b |
TRACE_BEG (DEBUG_CTX, "gpgme_op_export_ext_start", ctx,
|
|
Packit Service |
672cf4 |
"mode=0x%x, keydata=%p", mode, keydata);
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if (!ctx)
|
|
Packit Service |
672cf4 |
return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if (_gpgme_debug_trace () && pattern)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
int i = 0;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
while (pattern[i])
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
0ef63b |
TRACE_LOG ("pattern[%i] = %s", i, pattern[i]);
|
|
Packit Service |
672cf4 |
i++;
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
err = export_ext_start (ctx, 1, pattern, mode, keydata);
|
|
Packit Service |
672cf4 |
if (!err)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
err = _gpgme_wait_one (ctx);
|
|
Packit Service |
672cf4 |
if (!err)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
/* For this synchronous operation we check for operational
|
|
Packit Service |
672cf4 |
errors and return them. For asynchronous operations
|
|
Packit Service |
672cf4 |
there is currently no way to do this - we need to add a
|
|
Packit Service |
672cf4 |
gpgme_op_export_result function to fix that. */
|
|
Packit Service |
672cf4 |
void *hook;
|
|
Packit Service |
672cf4 |
op_data_t opd;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
err = _gpgme_op_data_lookup (ctx, OPDATA_EXPORT, &hook, -1, NULL);
|
|
Packit Service |
672cf4 |
opd = hook;
|
|
Packit Service |
672cf4 |
if (!err)
|
|
Packit Service |
672cf4 |
err = opd->err;
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
return TRACE_ERR (err);
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
static gpgme_error_t
|
|
Packit Service |
672cf4 |
export_keys_start (gpgme_ctx_t ctx, int synchronous, gpgme_key_t keys[],
|
|
Packit Service |
672cf4 |
gpgme_export_mode_t mode, gpgme_data_t keydata)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
gpgme_error_t err;
|
|
Packit Service |
672cf4 |
int nkeys, idx;
|
|
Packit Service |
672cf4 |
char **pattern;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if (!keys)
|
|
Packit Service |
672cf4 |
return gpg_error (GPG_ERR_INV_VALUE);
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
/* Create a list of pattern from the keys. */
|
|
Packit Service |
672cf4 |
for (idx=nkeys=0; keys[idx]; idx++)
|
|
Packit Service |
672cf4 |
if (keys[idx]->protocol == ctx->protocol)
|
|
Packit Service |
672cf4 |
nkeys++;
|
|
Packit Service |
672cf4 |
if (!nkeys)
|
|
Packit Service |
672cf4 |
return gpg_error (GPG_ERR_NO_DATA);
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
pattern = calloc (nkeys+1, sizeof *pattern);
|
|
Packit Service |
672cf4 |
if (!pattern)
|
|
Packit Service |
672cf4 |
return gpg_error_from_syserror ();
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
for (idx=nkeys=0; keys[idx]; idx++)
|
|
Packit Service |
672cf4 |
if (keys[idx]->protocol == ctx->protocol
|
|
Packit Service |
672cf4 |
&& keys[idx]->subkeys
|
|
Packit Service |
672cf4 |
&& keys[idx]->subkeys->fpr
|
|
Packit Service |
672cf4 |
&& *keys[idx]->subkeys->fpr)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
pattern[nkeys] = strdup (keys[idx]->subkeys->fpr);
|
|
Packit Service |
672cf4 |
if (!pattern[nkeys])
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
err = gpg_error_from_syserror ();
|
|
Packit Service |
672cf4 |
goto leave;
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
nkeys++;
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
/* Pass on to the regular function. */
|
|
Packit Service |
672cf4 |
err = export_ext_start (ctx, synchronous, (const char**)pattern,
|
|
Packit Service |
672cf4 |
mode, keydata);
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
leave:
|
|
Packit Service |
672cf4 |
for (idx=0; pattern[idx]; idx++)
|
|
Packit Service |
672cf4 |
free (pattern[idx]);
|
|
Packit Service |
672cf4 |
free (pattern);
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
return err;
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
/* Export the keys from the array KEYS into KEYDATA. Only keys of the
|
|
Packit Service |
672cf4 |
current protocol are exported and only those which have a
|
|
Packit Service |
672cf4 |
fingerprint set; that is keys received with some external search
|
|
Packit Service |
672cf4 |
methods are silently skipped. */
|
|
Packit Service |
672cf4 |
gpgme_error_t
|
|
Packit Service |
672cf4 |
gpgme_op_export_keys_start (gpgme_ctx_t ctx,
|
|
Packit Service |
672cf4 |
gpgme_key_t keys[],
|
|
Packit Service |
672cf4 |
gpgme_export_mode_t mode,
|
|
Packit Service |
672cf4 |
gpgme_data_t keydata)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
gpg_error_t err;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
0ef63b |
TRACE_BEG (DEBUG_CTX, "gpgme_op_export_keys_start", ctx,
|
|
Packit Service |
672cf4 |
"mode=0x%x, keydata=%p", mode, keydata);
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if (!ctx)
|
|
Packit Service |
672cf4 |
return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if (_gpgme_debug_trace () && keys)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
int i = 0;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
while (keys[i])
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
0ef63b |
TRACE_LOG ("keys[%i] = %p (%s)", i, keys[i],
|
|
Packit Service |
672cf4 |
(keys[i]->subkeys && keys[i]->subkeys->fpr) ?
|
|
Packit Service |
672cf4 |
keys[i]->subkeys->fpr : "invalid");
|
|
Packit Service |
672cf4 |
i++;
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
err = export_keys_start (ctx, 0, keys, mode, keydata);
|
|
Packit Service |
672cf4 |
return TRACE_ERR (err);
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
gpgme_error_t
|
|
Packit Service |
672cf4 |
gpgme_op_export_keys (gpgme_ctx_t ctx,
|
|
Packit Service |
672cf4 |
gpgme_key_t keys[],
|
|
Packit Service |
672cf4 |
gpgme_export_mode_t mode,
|
|
Packit Service |
672cf4 |
gpgme_data_t keydata)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
gpgme_error_t err;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
0ef63b |
TRACE_BEG (DEBUG_CTX, "gpgme_op_export_keys", ctx,
|
|
Packit Service |
672cf4 |
"mode=0x%x, keydata=%p", mode, keydata);
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if (!ctx)
|
|
Packit Service |
672cf4 |
return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if (_gpgme_debug_trace () && keys)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
int i = 0;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
while (keys[i])
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
0ef63b |
TRACE_LOG ("keys[%i] = %p (%s)", i, keys[i],
|
|
Packit Service |
672cf4 |
(keys[i]->subkeys && keys[i]->subkeys->fpr) ?
|
|
Packit Service |
672cf4 |
keys[i]->subkeys->fpr : "invalid");
|
|
Packit Service |
672cf4 |
i++;
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
err = export_keys_start (ctx, 1, keys, mode, keydata);
|
|
Packit Service |
672cf4 |
if (!err)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
err = _gpgme_wait_one (ctx);
|
|
Packit Service |
672cf4 |
if (!err)
|
|
Packit Service |
672cf4 |
{
|
|
Packit Service |
672cf4 |
/* For this synchronous operation we check for operational
|
|
Packit Service |
672cf4 |
errors and return them. For asynchronous operations
|
|
Packit Service |
672cf4 |
there is currently no way to do this - we need to add a
|
|
Packit Service |
672cf4 |
gpgme_op_export_result function to fix that. */
|
|
Packit Service |
672cf4 |
void *hook;
|
|
Packit Service |
672cf4 |
op_data_t opd;
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
err = _gpgme_op_data_lookup (ctx, OPDATA_EXPORT, &hook, -1, NULL);
|
|
Packit Service |
672cf4 |
opd = hook;
|
|
Packit Service |
672cf4 |
if (!err)
|
|
Packit Service |
672cf4 |
err = opd->err;
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
return TRACE_ERR (err);
|
|
Packit Service |
672cf4 |
}
|
|
Packit Service |
672cf4 |
|