2001-11-20 06:04:15 +00:00
|
|
|
/* engine.c
|
|
|
|
* Copyright (C) 2000 Werner Koch (dd9jn)
|
|
|
|
* Copyright (C) 2001 g10 Code GmbH
|
|
|
|
*
|
|
|
|
* This file is part of GPGME.
|
|
|
|
*
|
|
|
|
* GPGME is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GPGME is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
2001-12-18 Marcus Brinkmann <marcus@g10code.de>
* rungpg.c (struct reap_s, reap_list, reap_list_lock): Moved to ...
* engine.c (struct reap_s, reap_list, reap_list_lock): ... here.
Include `time.h', `sys/types.h', `assert.h', and `sema.h'.
* rungpg.c (_gpgme_engine_add_child_to_reap_list): New function.
(do_reaping, _gpgme_gpg_housecleaning): Moved to ...
* engine.c (do_reaping, _gpgme_engine_housecleaning): ... here.
* rungpg.c (_gpgme_gpg_release): Replace code that is now in its
own function by call to _gpgme_engine_add_child_to_reap_list().
* wait.c: Include `engine.h'.
(run_idle): Call _gpgme_engine_housecleaning(), not
_gpgme_gpg_housecleaning().
2001-12-18 21:02:35 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <sys/types.h>
|
2001-12-19 17:46:02 +00:00
|
|
|
#include <string.h>
|
2001-12-18 Marcus Brinkmann <marcus@g10code.de>
* rungpg.c (struct reap_s, reap_list, reap_list_lock): Moved to ...
* engine.c (struct reap_s, reap_list, reap_list_lock): ... here.
Include `time.h', `sys/types.h', `assert.h', and `sema.h'.
* rungpg.c (_gpgme_engine_add_child_to_reap_list): New function.
(do_reaping, _gpgme_gpg_housecleaning): Moved to ...
* engine.c (do_reaping, _gpgme_engine_housecleaning): ... here.
* rungpg.c (_gpgme_gpg_release): Replace code that is now in its
own function by call to _gpgme_engine_add_child_to_reap_list().
* wait.c: Include `engine.h'.
(run_idle): Call _gpgme_engine_housecleaning(), not
_gpgme_gpg_housecleaning().
2001-12-18 21:02:35 +00:00
|
|
|
#include <assert.h>
|
2001-11-20 06:04:15 +00:00
|
|
|
|
|
|
|
#include "gpgme.h"
|
|
|
|
#include "util.h"
|
2001-12-18 Marcus Brinkmann <marcus@g10code.de>
* rungpg.c (struct reap_s, reap_list, reap_list_lock): Moved to ...
* engine.c (struct reap_s, reap_list, reap_list_lock): ... here.
Include `time.h', `sys/types.h', `assert.h', and `sema.h'.
* rungpg.c (_gpgme_engine_add_child_to_reap_list): New function.
(do_reaping, _gpgme_gpg_housecleaning): Moved to ...
* engine.c (do_reaping, _gpgme_engine_housecleaning): ... here.
* rungpg.c (_gpgme_gpg_release): Replace code that is now in its
own function by call to _gpgme_engine_add_child_to_reap_list().
* wait.c: Include `engine.h'.
(run_idle): Call _gpgme_engine_housecleaning(), not
_gpgme_gpg_housecleaning().
2001-12-18 21:02:35 +00:00
|
|
|
#include "sema.h"
|
2001-12-18 22:21:06 +00:00
|
|
|
#include "io.h"
|
2001-11-20 06:04:15 +00:00
|
|
|
|
|
|
|
#include "engine.h"
|
|
|
|
#include "rungpg.h"
|
|
|
|
#include "engine-gpgsm.h"
|
|
|
|
|
|
|
|
struct engine_object_s
|
|
|
|
{
|
|
|
|
GpgmeProtocol protocol;
|
|
|
|
|
|
|
|
const char *path;
|
|
|
|
const char *version;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
GpgObject gpg;
|
|
|
|
GpgsmObject gpgsm;
|
|
|
|
} engine;
|
|
|
|
};
|
|
|
|
|
2001-12-18 Marcus Brinkmann <marcus@g10code.de>
* rungpg.c (struct reap_s, reap_list, reap_list_lock): Moved to ...
* engine.c (struct reap_s, reap_list, reap_list_lock): ... here.
Include `time.h', `sys/types.h', `assert.h', and `sema.h'.
* rungpg.c (_gpgme_engine_add_child_to_reap_list): New function.
(do_reaping, _gpgme_gpg_housecleaning): Moved to ...
* engine.c (do_reaping, _gpgme_engine_housecleaning): ... here.
* rungpg.c (_gpgme_gpg_release): Replace code that is now in its
own function by call to _gpgme_engine_add_child_to_reap_list().
* wait.c: Include `engine.h'.
(run_idle): Call _gpgme_engine_housecleaning(), not
_gpgme_gpg_housecleaning().
2001-12-18 21:02:35 +00:00
|
|
|
struct reap_s
|
|
|
|
{
|
|
|
|
struct reap_s *next;
|
|
|
|
int pid;
|
|
|
|
time_t entered;
|
|
|
|
int term_send;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct reap_s *reap_list;
|
|
|
|
DEFINE_STATIC_LOCK (reap_list_lock);
|
|
|
|
|
2001-11-20 06:04:15 +00:00
|
|
|
/* Get the path of the engine for PROTOCOL. */
|
|
|
|
const char *
|
|
|
|
_gpgme_engine_get_path (GpgmeProtocol proto)
|
|
|
|
{
|
|
|
|
switch (proto)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
return _gpgme_get_gpg_path ();
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
|
|
|
return _gpgme_get_gpgsm_path ();
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the version number of the engine for PROTOCOL. */
|
|
|
|
const char *
|
|
|
|
_gpgme_engine_get_version (GpgmeProtocol proto)
|
|
|
|
{
|
|
|
|
switch (proto)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
return _gpgme_gpg_get_version ();
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
|
|
|
return _gpgme_gpgsm_get_version ();
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GpgmeError
|
|
|
|
gpgme_engine_check_version (GpgmeProtocol proto)
|
|
|
|
{
|
|
|
|
switch (proto)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
return _gpgme_gpg_check_version ();
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
|
|
|
return _gpgme_gpgsm_check_version ();
|
|
|
|
default:
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-18 22:21:06 +00:00
|
|
|
const char *
|
|
|
|
_gpgme_engine_get_info (GpgmeProtocol proto)
|
|
|
|
{
|
|
|
|
static const char fmt[] = " <engine>\n"
|
|
|
|
" <protocol>%s</protocol>\n"
|
|
|
|
" <version>%s</version>\n"
|
|
|
|
" <path>%s</path>\n"
|
|
|
|
" </engine>\n";
|
|
|
|
static const char *const strproto[3] = { "OpenPGP", "CMS", NULL };
|
|
|
|
static const char *engine_info[3]; /* FIXME: MAX_PROTO + 1*/
|
|
|
|
const char *path;
|
|
|
|
const char *version;
|
|
|
|
char *info;
|
|
|
|
|
|
|
|
if (proto > 2 /* FIXME MAX_PROTO */ || !strproto[proto])
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* FIXME: Make sure that only one instance does run. */
|
|
|
|
if (engine_info[proto])
|
|
|
|
return engine_info[proto];
|
|
|
|
|
|
|
|
path = _gpgme_engine_get_path (proto);
|
|
|
|
version = _gpgme_engine_get_version (proto);
|
|
|
|
|
|
|
|
if (!path || !version)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
info = xtrymalloc (strlen(fmt) + strlen(strproto[proto]) + strlen(path)
|
|
|
|
+ strlen (version) + 1);
|
|
|
|
if (!info)
|
|
|
|
info = " <engine>\n"
|
|
|
|
" <error>Out of core</error>\n"
|
|
|
|
" </engine>";
|
|
|
|
else
|
|
|
|
sprintf (info, fmt, strproto[proto], version, path);
|
|
|
|
engine_info[proto] = info;
|
|
|
|
|
|
|
|
return engine_info[proto];
|
|
|
|
}
|
|
|
|
|
2001-11-20 06:04:15 +00:00
|
|
|
GpgmeError
|
|
|
|
_gpgme_engine_new (GpgmeProtocol proto, EngineObject *r_engine)
|
|
|
|
{
|
|
|
|
EngineObject engine;
|
|
|
|
GpgmeError err = 0;
|
|
|
|
|
|
|
|
engine = xtrycalloc (1, sizeof *engine);
|
|
|
|
if (!engine)
|
|
|
|
{
|
|
|
|
err = mk_error (Out_Of_Core);
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
engine->protocol = proto;
|
|
|
|
switch (proto)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
err =_gpgme_gpg_new (&engine->engine.gpg);
|
|
|
|
break;
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
|
|
|
err = _gpgme_gpgsm_new (&engine->engine.gpgsm);
|
|
|
|
if (err)
|
|
|
|
goto leave;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = mk_error (Invalid_Value);
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
goto leave;
|
|
|
|
|
|
|
|
engine->path = _gpgme_engine_get_path (proto);
|
|
|
|
engine->version = _gpgme_engine_get_version (proto);
|
|
|
|
|
|
|
|
if (!engine->path || !engine->version)
|
|
|
|
{
|
|
|
|
err = mk_error (Invalid_Engine);
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
leave:
|
|
|
|
if (err)
|
|
|
|
_gpgme_engine_release (engine);
|
|
|
|
else
|
|
|
|
*r_engine = engine;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gpgme_engine_release (EngineObject engine)
|
|
|
|
{
|
|
|
|
if (!engine)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (engine->protocol)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
_gpgme_gpg_release (engine->engine.gpg);
|
|
|
|
break;
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
|
|
|
_gpgme_gpgsm_release (engine->engine.gpgsm);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
xfree (engine);
|
|
|
|
}
|
2001-11-21 03:40:17 +00:00
|
|
|
|
2002-02-02 Marcus Brinkmann <marcus@g10code.de>
This patch has gotten a bit large... mmh. The main thing that
happens here is that error values are now not determined in the
operation function after gpgme_wait completed, but in the status
handler when EOF is received. It should always be the case that
either an error is flagged or EOF is received, so that after a
gpgme_wait you should never have the situation that no error is
flagged and EOF is not received. One problem is that the engine
status handlers don't have access to the context, a horrible
kludge works around this for now. All errors that happen during a
pending operation should be catched and reported in ctx->error,
including out-of-core and cancellation. This rounds up neatly a
couple of loose ends, and makes it possible to pass up any errors
in the communication with the backend as well. As a bonus, there
will be a function to access gpgme->wait, so that the operations
can truly be implemented with their _start function.
* engine-gpgsm.c (gpgsm_status_handler): Horrible kludge to report
error back to the context.
* rungpg.c (gpg_status_handler): Same horrible kludge applied here.
* engine-gpgsm.c (gpgsm_assuan_simple_command): Add error checking.
* wait.c (_gpgme_wait_on_condition): If canceled, set CTX->error
to a value indication that.
* verify.c (add_notation): Set error, not out_of_core.
(finish_sig): Likewise.
(gpgme_op_verify_start): Don't clear out_of_core.
(_gpgme_verify_status_handler): At EOF, clean up the notation data.
(gpgme_op_verify): And don't do it here.
* trustlist.c (trustlist_status_handler): Check error, not out_of_core.
(gpgme_op_trustlist_start): Don't clear out_of_core.
(gpgme_op_trustlist_next): Check error, not out_of_core.
(gpgme_op_trustlist_end): Likewise.
* ops.h (test_and_allocate_result): New macro.
(_gpgme_passphrase_result): Remove prototype.
* delete.c (gpgme_op_delete): Return error from context.
(delete_status_handler): Use macro test_and_allocate_result.
Perform error checking at EOF.
(gpgme_op_delete_start): Release result.
* passphrase.c (_gpgme_passphrase_status_handler): Use macro
test_and_allocate_result, and perform error checking here.
(_gpgme_passphrase_result): Function removed.
* sign.c (gpgme_op_sign_start): Do not set out_of_core to zero.
(gpgme_op_sign): Just return the error value from the context.
(sign_status_handler): Only progress if no error is set yet. If
we process an EOF, set the resulting error value (if any).
* decrypt.c (_gpgme_decrypt_result): Function removed.
(create_result_struct): Function removed.
(_gpgme_decrypt_status_handler): Use macro test_and_allocate_result,
caclulate error on EOF, do not progress with errors.
(_gpgme_decrypt_start): Do not set out_of_core to zero.
(gpgme_op_decrypt): Just return the error value from the context.
* encrypt.c (encrypt_status_handler): Perform the error checking
here.
(gpgme_op_encrypt_start): Do not clear out_of_core.
* export.c (export_status_handler): Return if error is set in context.
(gpgme_op_export_start): Release result.
(gpgme_op_export): Return error from context.
* decrypt-verify.c (gpgme_op_decrypt_verify): Return the error in
the context.
* genkey.c (genkey_status_handler): Use macro
test_and_allocate_result. Perform error checking at EOF.
(gpgme_op_genkey): Just return the error from context.
* import.c (gpgme_op_import): Return the error from context.
(import_status_handler): Use macro test_and_allocate_result.
* keylist.c (gpgme_op_keylist_start): Do not clear out_of_core.
(gpgme_op_keylist_next): Return error of context.
(keylist_colon_handler): Set error instead out_of_code.
(finish_key): Likewise.
* context.h: Remove member out_of_core, add member error.
* gpgme.c (_gpgme_release_result): Clear error flag.
* engine.h (_gpgme_engine_get_error): New prototype.
* engine.c (_gpgme_engine_get_error): New function.
* engine-gpgsm.c (_gpgme_gpgsm_get_error): New function.
* engine-gpgsm.c (map_assuan_error): New function.
(gpgsm_assuan_simple_command): Change return type to GpgmeError,
use the new function to map error values.
(gpgsm_set_fd): Change return type tp GpgmeError.
(_gpgme_gpgsm_op_decrypt): Change type of ERR to GpgmeError.
(gpgsm_set_recipients): Likewise. Change type of return value
equivalently. Adjust error values.
(_gpgme_gpgsm_op_import): Likewise.
(_gpgme_gpgsm_op_sign): Likewise.
(struct gpgsm_object_s): New member error.
(gpgsm_status_handler): Set error if error occurs. Determine
error number from ERR line received. If assuan_read_line fails,
terminate the connection.
2002-02-02 03:52:59 +00:00
|
|
|
|
2001-11-21 03:40:17 +00:00
|
|
|
void
|
|
|
|
_gpgme_engine_set_verbosity (EngineObject engine, int verbosity)
|
|
|
|
{
|
|
|
|
if (!engine)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (engine->protocol)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
while (verbosity-- > 0)
|
|
|
|
_gpgme_gpg_add_arg (engine->engine.gpg, "--verbose");
|
|
|
|
break;
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
|
|
|
/* FIXME */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gpgme_engine_set_status_handler (EngineObject engine,
|
|
|
|
GpgStatusHandler fnc, void *fnc_value)
|
|
|
|
{
|
|
|
|
if (!engine)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (engine->protocol)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
_gpgme_gpg_set_status_handler (engine->engine.gpg, fnc, fnc_value);
|
|
|
|
break;
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
2001-11-22 Marcus Brinkmann <marcus@g10code.de>
* rungpg.c (gpg_inbound_handler, write_mem_data, write_cb_data,
gpg_outbound_handler): Moved to ...
* data.c (_gpgme_data_inbound_handler, write_mem_data,
write_cb_data, _gpgme_data_outbound_handler): ... here. Make the
_gpgme_* ones non-static.
* data.c: Include io.h.
* ops.h (_gpgme_data_inbound_handler): New prototype.
(_gpgme_data_outbound_handler): Likewise.
(_gpgme_gpg_spawn): Use these new functions.
* engine-gpgsm.h (_gpgme_gpgsm_op_decrypt, _gpgme_gpgsm_op_delete,
_gpgme_gpgsm_op_encrypt, _gpgme_gpgsm_op_export,
_gpgme_gpgsm_op_genkey, _gpgme_gpgsm_op_import,
_gpgme_gpgsm_op_keylist, _gpgme_gpgsm_op_sign,
_gpgme_gpgsm_op_trustlist, _gpgme_gpgsm_op_verify,
_gpgme_gpgsm_start, _gpgme_gpgsm_set_status_handler): New prototype.
Include <rungpg.h> for status handler function.
* engine-gpgsm.c (struct gpgsm_object_s): New members input_fd,
input_data, output_fd, output_data, message_fd, message_data, command
and status.
(_gpgme_gpgsm_new): Open input, output and message pipes before
connecting to the client. Close server's ends afterwards.
(_gpgme_gpgsm_release): Close open file descriptors. Remove
server process from wait queue.
(_gpgme_gpgsm_op_verify, _gpgme_gpgsm_start,
_gpgme_gpgsm_set_status_handler, gpgms_status_handler): New function.
* engine.c (_gpgme_engine_start): Implement for GPGME_PROTOCOL_CMS.
(_gpgme_engine_set_status_handler): Likewise.
(_gpgme_engine_op_verify): Likewise.
2001-11-22 03:08:58 +00:00
|
|
|
_gpgme_gpgsm_set_status_handler (engine->engine.gpgsm, fnc, fnc_value);
|
2001-11-21 03:40:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GpgmeError
|
|
|
|
_gpgme_engine_set_command_handler (EngineObject engine,
|
|
|
|
GpgCommandHandler fnc, void *fnc_value)
|
|
|
|
{
|
|
|
|
if (!engine)
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
|
|
|
|
switch (engine->protocol)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
return _gpgme_gpg_set_command_handler (engine->engine.gpg, fnc, fnc_value);
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
|
|
|
/* FIXME */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpgmeError _gpgme_engine_set_colon_line_handler (EngineObject engine,
|
|
|
|
GpgColonLineHandler fnc,
|
|
|
|
void *fnc_value)
|
|
|
|
{
|
|
|
|
if (!engine)
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
|
|
|
|
switch (engine->protocol)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
2001-12-13 17:37:18 +00:00
|
|
|
return _gpgme_gpg_set_colon_line_handler (engine->engine.gpg,
|
|
|
|
fnc, fnc_value);
|
2001-11-21 03:40:17 +00:00
|
|
|
case GPGME_PROTOCOL_CMS:
|
2001-12-13 17:37:18 +00:00
|
|
|
_gpgme_gpgsm_set_colon_line_handler (engine->engine.gpgsm,
|
|
|
|
fnc, fnc_value);
|
2001-11-21 03:40:17 +00:00
|
|
|
break;
|
2001-12-13 17:37:18 +00:00
|
|
|
|
2001-11-21 03:40:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpgmeError
|
|
|
|
_gpgme_engine_op_decrypt (EngineObject engine, GpgmeData ciph, GpgmeData plain)
|
|
|
|
{
|
|
|
|
if (!engine)
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
|
|
|
|
switch (engine->protocol)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
return _gpgme_gpg_op_decrypt (engine->engine.gpg, ciph, plain);
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
2001-11-22 20:48:37 +00:00
|
|
|
return _gpgme_gpgsm_op_decrypt (engine->engine.gpgsm, ciph, plain);
|
2001-11-21 03:40:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpgmeError
|
|
|
|
_gpgme_engine_op_delete (EngineObject engine, GpgmeKey key, int allow_secret)
|
|
|
|
{
|
|
|
|
if (!engine)
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
|
|
|
|
switch (engine->protocol)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
return _gpgme_gpg_op_delete (engine->engine.gpg, key, allow_secret);
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
2001-11-22 20:48:37 +00:00
|
|
|
return _gpgme_gpgsm_op_delete (engine->engine.gpgsm, key, allow_secret);
|
2001-11-21 03:40:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpgmeError
|
|
|
|
_gpgme_engine_op_encrypt (EngineObject engine, GpgmeRecipients recp,
|
|
|
|
GpgmeData plain, GpgmeData ciph, int use_armor)
|
|
|
|
{
|
|
|
|
if (!engine)
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
|
|
|
|
switch (engine->protocol)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
return _gpgme_gpg_op_encrypt (engine->engine.gpg, recp, plain, ciph,
|
|
|
|
use_armor);
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
2001-11-22 20:48:37 +00:00
|
|
|
return _gpgme_gpgsm_op_encrypt (engine->engine.gpgsm, recp, plain, ciph,
|
|
|
|
use_armor);
|
2001-11-21 03:40:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpgmeError
|
|
|
|
_gpgme_engine_op_export (EngineObject engine, GpgmeRecipients recp,
|
|
|
|
GpgmeData keydata, int use_armor)
|
|
|
|
{
|
|
|
|
if (!engine)
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
|
|
|
|
switch (engine->protocol)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
return _gpgme_gpg_op_export (engine->engine.gpg, recp, keydata,
|
|
|
|
use_armor);
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
2001-11-22 20:48:37 +00:00
|
|
|
return _gpgme_gpgsm_op_export (engine->engine.gpgsm, recp, keydata,
|
|
|
|
use_armor);
|
2001-11-21 03:40:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpgmeError
|
2002-02-08 22:43:44 +00:00
|
|
|
_gpgme_engine_op_genkey (EngineObject engine, GpgmeData help_data,
|
|
|
|
int use_armor, GpgmeData pubkey, GpgmeData seckey)
|
2001-11-21 03:40:17 +00:00
|
|
|
{
|
|
|
|
if (!engine)
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
|
|
|
|
switch (engine->protocol)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
2002-02-08 22:43:44 +00:00
|
|
|
return _gpgme_gpg_op_genkey (engine->engine.gpg, help_data, use_armor,
|
|
|
|
pubkey, seckey);
|
2001-11-21 03:40:17 +00:00
|
|
|
case GPGME_PROTOCOL_CMS:
|
2002-02-08 22:43:44 +00:00
|
|
|
return _gpgme_gpgsm_op_genkey (engine->engine.gpgsm, help_data, use_armor,
|
|
|
|
pubkey, seckey);
|
2001-11-21 03:40:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpgmeError
|
|
|
|
_gpgme_engine_op_import (EngineObject engine, GpgmeData keydata)
|
|
|
|
{
|
|
|
|
if (!engine)
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
|
|
|
|
switch (engine->protocol)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
return _gpgme_gpg_op_import (engine->engine.gpg, keydata);
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
2001-11-22 20:48:37 +00:00
|
|
|
return _gpgme_gpgsm_op_import (engine->engine.gpgsm, keydata);
|
2001-11-21 03:40:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpgmeError
|
|
|
|
_gpgme_engine_op_keylist (EngineObject engine, const char *pattern, int secret_only,
|
|
|
|
int keylist_mode)
|
|
|
|
{
|
|
|
|
if (!engine)
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
|
|
|
|
switch (engine->protocol)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
return _gpgme_gpg_op_keylist (engine->engine.gpg, pattern, secret_only,
|
|
|
|
keylist_mode);
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
2001-11-22 20:48:37 +00:00
|
|
|
return _gpgme_gpgsm_op_keylist (engine->engine.gpgsm, pattern, secret_only,
|
|
|
|
keylist_mode);
|
2001-11-21 03:40:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpgmeError
|
|
|
|
_gpgme_engine_op_sign (EngineObject engine, GpgmeData in, GpgmeData out,
|
2002-02-25 18:31:07 +00:00
|
|
|
GpgmeSigMode mode, int use_armor,
|
|
|
|
int use_textmode, int include_certs,
|
|
|
|
GpgmeCtx ctx /* FIXME */)
|
2001-11-21 03:40:17 +00:00
|
|
|
{
|
|
|
|
if (!engine)
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
|
|
|
|
switch (engine->protocol)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
return _gpgme_gpg_op_sign (engine->engine.gpg, in, out, mode, use_armor,
|
|
|
|
use_textmode, ctx);
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
2001-11-22 20:48:37 +00:00
|
|
|
return _gpgme_gpgsm_op_sign (engine->engine.gpgsm, in, out, mode,
|
2002-02-25 18:31:07 +00:00
|
|
|
use_armor, use_textmode, include_certs, ctx);
|
2001-11-21 03:40:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpgmeError
|
|
|
|
_gpgme_engine_op_trustlist (EngineObject engine, const char *pattern)
|
|
|
|
{
|
|
|
|
if (!engine)
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
|
|
|
|
switch (engine->protocol)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
return _gpgme_gpg_op_trustlist (engine->engine.gpg, pattern);
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
2001-11-22 20:48:37 +00:00
|
|
|
return _gpgme_gpgsm_op_trustlist (engine->engine.gpgsm, pattern);
|
2001-11-21 03:40:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpgmeError
|
|
|
|
_gpgme_engine_op_verify (EngineObject engine, GpgmeData sig, GpgmeData text)
|
|
|
|
{
|
|
|
|
if (!engine)
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
|
|
|
|
switch (engine->protocol)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
return _gpgme_gpg_op_verify (engine->engine.gpg, sig, text);
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
2001-11-22 Marcus Brinkmann <marcus@g10code.de>
* rungpg.c (gpg_inbound_handler, write_mem_data, write_cb_data,
gpg_outbound_handler): Moved to ...
* data.c (_gpgme_data_inbound_handler, write_mem_data,
write_cb_data, _gpgme_data_outbound_handler): ... here. Make the
_gpgme_* ones non-static.
* data.c: Include io.h.
* ops.h (_gpgme_data_inbound_handler): New prototype.
(_gpgme_data_outbound_handler): Likewise.
(_gpgme_gpg_spawn): Use these new functions.
* engine-gpgsm.h (_gpgme_gpgsm_op_decrypt, _gpgme_gpgsm_op_delete,
_gpgme_gpgsm_op_encrypt, _gpgme_gpgsm_op_export,
_gpgme_gpgsm_op_genkey, _gpgme_gpgsm_op_import,
_gpgme_gpgsm_op_keylist, _gpgme_gpgsm_op_sign,
_gpgme_gpgsm_op_trustlist, _gpgme_gpgsm_op_verify,
_gpgme_gpgsm_start, _gpgme_gpgsm_set_status_handler): New prototype.
Include <rungpg.h> for status handler function.
* engine-gpgsm.c (struct gpgsm_object_s): New members input_fd,
input_data, output_fd, output_data, message_fd, message_data, command
and status.
(_gpgme_gpgsm_new): Open input, output and message pipes before
connecting to the client. Close server's ends afterwards.
(_gpgme_gpgsm_release): Close open file descriptors. Remove
server process from wait queue.
(_gpgme_gpgsm_op_verify, _gpgme_gpgsm_start,
_gpgme_gpgsm_set_status_handler, gpgms_status_handler): New function.
* engine.c (_gpgme_engine_start): Implement for GPGME_PROTOCOL_CMS.
(_gpgme_engine_set_status_handler): Likewise.
(_gpgme_engine_op_verify): Likewise.
2001-11-22 03:08:58 +00:00
|
|
|
return _gpgme_gpgsm_op_verify (engine->engine.gpgsm, sig, text);
|
2001-11-21 03:40:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-12-18 Marcus Brinkmann <marcus@g10code.de>
* rungpg.c (struct reap_s, reap_list, reap_list_lock): Moved to ...
* engine.c (struct reap_s, reap_list, reap_list_lock): ... here.
Include `time.h', `sys/types.h', `assert.h', and `sema.h'.
* rungpg.c (_gpgme_engine_add_child_to_reap_list): New function.
(do_reaping, _gpgme_gpg_housecleaning): Moved to ...
* engine.c (do_reaping, _gpgme_engine_housecleaning): ... here.
* rungpg.c (_gpgme_gpg_release): Replace code that is now in its
own function by call to _gpgme_engine_add_child_to_reap_list().
* wait.c: Include `engine.h'.
(run_idle): Call _gpgme_engine_housecleaning(), not
_gpgme_gpg_housecleaning().
2001-12-18 21:02:35 +00:00
|
|
|
GpgmeError
|
|
|
|
_gpgme_engine_start (EngineObject engine, void *opaque)
|
2001-11-21 03:40:17 +00:00
|
|
|
{
|
|
|
|
if (!engine)
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
|
|
|
|
switch (engine->protocol)
|
|
|
|
{
|
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
|
|
|
return _gpgme_gpg_spawn (engine->engine.gpg, opaque);
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
2001-11-22 Marcus Brinkmann <marcus@g10code.de>
* rungpg.c (gpg_inbound_handler, write_mem_data, write_cb_data,
gpg_outbound_handler): Moved to ...
* data.c (_gpgme_data_inbound_handler, write_mem_data,
write_cb_data, _gpgme_data_outbound_handler): ... here. Make the
_gpgme_* ones non-static.
* data.c: Include io.h.
* ops.h (_gpgme_data_inbound_handler): New prototype.
(_gpgme_data_outbound_handler): Likewise.
(_gpgme_gpg_spawn): Use these new functions.
* engine-gpgsm.h (_gpgme_gpgsm_op_decrypt, _gpgme_gpgsm_op_delete,
_gpgme_gpgsm_op_encrypt, _gpgme_gpgsm_op_export,
_gpgme_gpgsm_op_genkey, _gpgme_gpgsm_op_import,
_gpgme_gpgsm_op_keylist, _gpgme_gpgsm_op_sign,
_gpgme_gpgsm_op_trustlist, _gpgme_gpgsm_op_verify,
_gpgme_gpgsm_start, _gpgme_gpgsm_set_status_handler): New prototype.
Include <rungpg.h> for status handler function.
* engine-gpgsm.c (struct gpgsm_object_s): New members input_fd,
input_data, output_fd, output_data, message_fd, message_data, command
and status.
(_gpgme_gpgsm_new): Open input, output and message pipes before
connecting to the client. Close server's ends afterwards.
(_gpgme_gpgsm_release): Close open file descriptors. Remove
server process from wait queue.
(_gpgme_gpgsm_op_verify, _gpgme_gpgsm_start,
_gpgme_gpgsm_set_status_handler, gpgms_status_handler): New function.
* engine.c (_gpgme_engine_start): Implement for GPGME_PROTOCOL_CMS.
(_gpgme_engine_set_status_handler): Likewise.
(_gpgme_engine_op_verify): Likewise.
2001-11-22 03:08:58 +00:00
|
|
|
return _gpgme_gpgsm_start (engine->engine.gpgsm, opaque);
|
2001-11-21 03:40:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2001-12-18 Marcus Brinkmann <marcus@g10code.de>
* rungpg.c (struct reap_s, reap_list, reap_list_lock): Moved to ...
* engine.c (struct reap_s, reap_list, reap_list_lock): ... here.
Include `time.h', `sys/types.h', `assert.h', and `sema.h'.
* rungpg.c (_gpgme_engine_add_child_to_reap_list): New function.
(do_reaping, _gpgme_gpg_housecleaning): Moved to ...
* engine.c (do_reaping, _gpgme_engine_housecleaning): ... here.
* rungpg.c (_gpgme_gpg_release): Replace code that is now in its
own function by call to _gpgme_engine_add_child_to_reap_list().
* wait.c: Include `engine.h'.
(run_idle): Call _gpgme_engine_housecleaning(), not
_gpgme_gpg_housecleaning().
2001-12-18 21:02:35 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
_gpgme_engine_add_child_to_reap_list (void *buf, int buflen, pid_t pid)
|
|
|
|
{
|
|
|
|
/* Reuse the memory, so that we don't need to allocate another
|
|
|
|
memory block and to handle errors. */
|
|
|
|
struct reap_s *child = buf;
|
|
|
|
|
|
|
|
assert (buflen >= sizeof *child);
|
|
|
|
memset (child, 0, sizeof *child);
|
|
|
|
child->pid = pid;
|
|
|
|
child->entered = time (NULL);
|
|
|
|
LOCK(reap_list_lock);
|
|
|
|
child->next = reap_list;
|
|
|
|
reap_list = child;
|
|
|
|
UNLOCK(reap_list_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_reaping (void)
|
|
|
|
{
|
|
|
|
struct reap_s *r, *rlast;
|
|
|
|
static time_t last_check;
|
|
|
|
time_t cur_time = time (NULL);
|
|
|
|
|
|
|
|
/* A race does not matter here. */
|
|
|
|
if (!last_check)
|
|
|
|
last_check = time (NULL);
|
|
|
|
|
|
|
|
if (last_check >= cur_time)
|
|
|
|
return; /* We check only every second. */
|
|
|
|
|
|
|
|
/* Fixme: it would be nice if to have a TRYLOCK here. */
|
|
|
|
LOCK (reap_list_lock);
|
|
|
|
for (r = reap_list, rlast = NULL; r; rlast = r, r = r ? r->next : NULL)
|
|
|
|
{
|
|
|
|
int dummy1, dummy2;
|
|
|
|
|
|
|
|
if (_gpgme_io_waitpid (r->pid, 0, &dummy1, &dummy2))
|
|
|
|
{
|
|
|
|
/* The process has terminated - remove it from the queue. */
|
|
|
|
void *p = r;
|
|
|
|
if (!rlast)
|
|
|
|
{
|
|
|
|
reap_list = r->next;
|
|
|
|
r = reap_list;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rlast->next = r->next;
|
|
|
|
r = rlast;
|
|
|
|
}
|
|
|
|
xfree (p);
|
|
|
|
}
|
|
|
|
else if (!r->term_send)
|
|
|
|
{
|
|
|
|
if (r->entered + 1 >= cur_time)
|
|
|
|
{
|
|
|
|
_gpgme_io_kill (r->pid, 0);
|
|
|
|
r->term_send = 1;
|
|
|
|
r->entered = cur_time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Give it 5 second before we are going to send the killer. */
|
|
|
|
if (r->entered + 5 >= cur_time)
|
|
|
|
{
|
|
|
|
_gpgme_io_kill (r->pid, 1);
|
|
|
|
r->entered = cur_time; /* Just in case we have to repeat it. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UNLOCK (reap_list_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gpgme_engine_housecleaning (void)
|
|
|
|
{
|
|
|
|
do_reaping ();
|
|
|
|
}
|