From: Werner Koch Date: Fri, 8 Jan 2010 19:15:06 +0000 (+0000) Subject: Support gpgme_op_apsswd for GPG. X-Git-Tag: gpgme-1.3.0~2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1b2fb1b737d1a0928cc9f7a210c9dbc5f374adff;p=gpgme.git Support gpgme_op_apsswd for GPG. --- diff --git a/doc/gpgme.texi b/doc/gpgme.texi index b98db55..e530e16 100644 --- a/doc/gpgme.texi +++ b/doc/gpgme.texi @@ -3744,6 +3744,9 @@ private key associated with @var{key}. The only allowed value for to ask for the old and the new passphrase. Thus this function is not useful in a server application (where passphrases are not required anyway). + +Note that old @code{gpg} engines (before version 2.0.15) do not support +this comamnd and will silently ignore it. @end deftypefun @deftypefun gpgme_error_t gpgme_op_passwd_start @ diff --git a/src/ChangeLog b/src/ChangeLog index aee1be0..3292f4c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2010-01-08 Werner Koch + + * engine-gpg.c (gpg_passwd): New. + (_gpgme_engine_ops_gpg): Register. + * passwd.c (parse_error): New. + (passwd_status_handler): Use it. + 2010-01-07 Marcus Brinkmann * gpgme-tool.c (result_xml_write_cb_t, struct result_xml_state): diff --git a/src/context.h b/src/context.h index 6ab0154..19c7194 100644 --- a/src/context.h +++ b/src/context.h @@ -1,6 +1,6 @@ /* context.h - Definitions for a GPGME context. Copyright (C) 2000 Werner Koch (dd9jn) - Copyright (C) 2001, 2002, 2003, 2004, 2005 g10 Code GmbH + Copyright (C) 2001, 2002, 2003, 2004, 2005, 2010 g10 Code GmbH This file is part of GPGME. @@ -15,9 +15,8 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser 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. */ + License along with this program; if not, see . + */ #ifndef CONTEXT_H #define CONTEXT_H diff --git a/src/engine-gpg.c b/src/engine-gpg.c index d4683b6..abfaaa3 100644 --- a/src/engine-gpg.c +++ b/src/engine-gpg.c @@ -1,7 +1,7 @@ /* engine-gpg.c - Gpg Engine. Copyright (C) 2000 Werner Koch (dd9jn) Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, - 2009 g10 Code GmbH + 2009, 2010 g10 Code GmbH This file is part of GPGME. @@ -1436,6 +1436,24 @@ gpg_delete (void *engine, gpgme_key_t key, int allow_secret) } +static gpgme_error_t +gpg_passwd (void *engine, gpgme_key_t key, unsigned int flags) +{ + engine_gpg_t gpg = engine; + gpgme_error_t err; + + if (!key || !key->subkeys || !key->subkeys->fpr) + return gpg_error (GPG_ERR_INV_CERT_OBJ); + + err = add_arg (gpg, "--passwd"); + if (!err) + err = add_arg (gpg, key->subkeys->fpr); + if (!err) + start (gpg); + return err; +} + + static gpgme_error_t append_args_from_signers (engine_gpg_t gpg, gpgme_ctx_t ctx /* FIXME */) { @@ -2370,5 +2388,6 @@ struct engine_ops _gpgme_engine_ops_gpg = gpg_set_io_cbs, gpg_io_event, gpg_cancel, - NULL /* cancel_op */ + NULL, /* cancel_op */ + gpg_passwd }; diff --git a/src/engine-gpgsm.c b/src/engine-gpgsm.c index 2dda733..88039d7 100644 --- a/src/engine-gpgsm.c +++ b/src/engine-gpgsm.c @@ -1908,7 +1908,7 @@ gpgsm_passwd (void *engine, gpgme_key_t key, unsigned int flags) char *line; if (!key || !key->subkeys || !key->subkeys->fpr) - return gpg_error (GPG_ERR_INV_VALUE); + return gpg_error (GPG_ERR_INV_CERT_OBJ); if (asprintf (&line, "PASSWD -- %s", key->subkeys->fpr) < 0) return gpg_error_from_syserror (); diff --git a/src/gpgme-tool.c b/src/gpgme-tool.c index be35514..59d13e5 100644 --- a/src/gpgme-tool.c +++ b/src/gpgme-tool.c @@ -1729,7 +1729,7 @@ gt_passwd (gpgme_tool_t gt, char *fpr) err = gpgme_get_key (gt->ctx, fpr, &key, 0); if (err) - return err; + return gpg_err_code (err) == GPG_ERR_EOF? gpg_error (GPG_ERR_NO_PUBKEY):err; err = gpgme_op_passwd (gt->ctx, key, 0); gpgme_key_unref (key); diff --git a/src/passwd.c b/src/passwd.c index d189814..6766877 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -20,6 +20,7 @@ #if HAVE_CONFIG_H #include #endif +#include #include "gpgme.h" #include "debug.h" @@ -27,16 +28,59 @@ #include "ops.h" +/* Parse an error status line and return the error code. */ static gpgme_error_t -passwd_status_handler (void *priv, gpgme_status_code_t code, char *args) +parse_error (char *args) { - (void)priv; - (void)code; - (void)args; + gpgme_error_t err; + char *where = strchr (args, ' '); + char *which; + + if (where) + { + *where = '\0'; + which = where + 1; + + where = strchr (which, ' '); + if (where) + *where = '\0'; + + where = args; + } + else + return gpg_error (GPG_ERR_INV_ENGINE); + + err = atoi (which); + + if (!strcmp (where, "keyedit.passwd")) + return err; + return 0; } +static gpgme_error_t +passwd_status_handler (void *priv, gpgme_status_code_t code, char *args) +{ + gpgme_ctx_t ctx = (gpgme_ctx_t) priv; + gpgme_error_t err = 0; + + (void)ctx; + + switch (code) + { + case GPGME_STATUS_ERROR: + err = parse_error (args); + break; + + default: + break; + } + + return err; +} + + static gpgme_error_t passwd_start (gpgme_ctx_t ctx, int synchronous, gpgme_key_t key, unsigned int flags)