From 7b49f3b96a2b203f585d67e90edfb8d205ef7da6 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sun, 7 Jul 2013 19:56:38 -0400 Subject: [PATCH] Add pwmd_passwd(). To change a passphrase for a data file. Behaves almost exactly like pwmd_save(). Needed to handle pinentry settings. --- doc/libpwmd.3 | 32 ++++++++++++++++++++++++++++++++ src/libpwmd.c | 20 +++++++++++++++++--- src/libpwmd.h.in | 24 ++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/doc/libpwmd.3 b/doc/libpwmd.3 index 39f10d42..2550ea5e 100644 --- a/doc/libpwmd.3 +++ b/doc/libpwmd.3 @@ -203,6 +203,9 @@ libgpg-error returns an error code as a bitmask of an error source and the error .RI "LIBPWMD_API gpg_error_t \fBpwmd_save\fP (\fBpwm_t\fP *pwm, const char *args, \fBpwmd_inquire_cb_t\fP callback, void *user)" .br .ti -1c +.RI "LIBPWMD_API gpg_error_t \fBpwmd_passwd\fP (\fBpwm_t\fP *pwm, const char *args, \fBpwmd_inquire_cb_t\fP callback, void *user)" +.br +.ti -1c .RI "LIBPWMD_API gpg_error_t \fBpwmd_command\fP (\fBpwm_t\fP *pwm, char **result, size_t *len, \fBpwmd_inquire_cb_t\fP callback, void *user, const char *cmd,\&.\&.\&.)" .br .ti -1c @@ -1014,6 +1017,35 @@ The inquire \fIcallback\fP function should be used when \fBPWMD_OPTION_NO_PINENT .RE .PP +.SS "LIBPWMD_API gpg_error_t pwmd_passwd (\fBpwm_t\fP *pwm, const char *args, \fBpwmd_inquire_cb_t\fPcallback, void *user)" + +.PP +Change the passphrase for a data file\&. This will send the PASSWD command to the server taking care of pinentry settings\&. +.PP +The inquire \fIcallback\fP function should be used when \fBPWMD_OPTION_OVERRIDE_INQUIRE\fP is set\&. This function will disable the pwmd pinentry when \fBPWMD_OPTION_NO_PINENTRY\fP or \fBPWMD_OPTION_LOCAL_PINENTRY\fP is set\&. It will not restore the pwmd pinentry mode that was previously set before calling this function\&. +.PP +\fBParameters:\fP +.RS 4 +\fIpwm\fP A handle\&. +.br +\fIargs\fP Any PASSWD protocol command options or NULL\&. +.br +\fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&. +.br +\fIuser\fP User data passed to the \fIcallback\fP function\&. +.RE +.PP +\fBReturns:\fP +.RS 4 +0 on success or an error code\&. +.RE +.PP +\fBSee Also:\fP +.RS 4 +\fBPWMD_OPTION_OVERRIDE_INQUIRE\fP, \fBPWMD_OPTION_NO_PINENTRY\fP, \fBPWMD_OPTION_LOCAL_PINENTRY\fP, \fBpwmd_command()\fP, \fBPinentry Details\fP +.RE +.PP + .SS "LIBPWMD_API gpg_error_t pwmd_password (\fBpwm_t\fP *pwm, const char *keyword, char **data, size_t *size)" .PP diff --git a/src/libpwmd.c b/src/libpwmd.c index 93689d0e..38178b50 100644 --- a/src/libpwmd.c +++ b/src/libpwmd.c @@ -1271,8 +1271,9 @@ pwmd_open (pwm_t * pwm, const char *filename, pwmd_inquire_cb_t cb, return FINISH (rc); } -gpg_error_t -pwmd_save (pwm_t * pwm, const char *args, pwmd_inquire_cb_t cb, void *data) +static gpg_error_t +do_pwmd_save_passwd (pwm_t * pwm, const char *args, pwmd_inquire_cb_t cb, + void *data, int save) { gpg_error_t rc = 0; @@ -1285,11 +1286,24 @@ pwmd_save (pwm_t * pwm, const char *args, pwmd_inquire_cb_t cb, void *data) rc = pwmd_command (pwm, NULL, NULL, NULL, NULL, "OPTION disable-pinentry"); if (!rc) - rc = pwmd_command (pwm, NULL, NULL, cb, data, "SAVE %s", args ? args : ""); + rc = pwmd_command (pwm, NULL, NULL, cb, data, + save ? "SAVE %s" : "PASSWD %s", args ? args : ""); return FINISH (rc); } +gpg_error_t +pwmd_passwd (pwm_t * pwm, const char *args, pwmd_inquire_cb_t cb, void *data) +{ + return do_pwmd_save_passwd (pwm, args, cb, data, 0); +} + +gpg_error_t +pwmd_save (pwm_t * pwm, const char *args, pwmd_inquire_cb_t cb, void *data) +{ + return do_pwmd_save_passwd (pwm, args, cb, data, 1); +} + static gpg_error_t pwmd_get_set_opt (pwm_t *pwm, pwmd_option_t opt, int get, va_list ap) { diff --git a/src/libpwmd.h.in b/src/libpwmd.h.in index 8f11fa0f..d7e8b441 100644 --- a/src/libpwmd.h.in +++ b/src/libpwmd.h.in @@ -782,6 +782,30 @@ LIBPWMD_API gpg_error_t pwmd_save (pwm_t * pwm, const char *args, pwmd_inquire_cb_t callback, void *user); +/*! \brief Change the passphrase for a data file. + * + * This will send the PASSWD command to the server taking care of pinentry + * settings. + * + * The inquire \a callback function should be used when \ref + * PWMD_OPTION_OVERRIDE_INQUIRE is set. This function will disable the pwmd + * pinentry when \ref PWMD_OPTION_NO_PINENTRY or \ref + * PWMD_OPTION_LOCAL_PINENTRY is set. It will not restore the pwmd pinentry + * mode that was previously set before calling this function. + * + * \param pwm A handle. + * \param args Any PASSWD protocol command options or NULL. + * \param callback A callback function to invoke when pwmd inquires data from + * the client. + * \param user User data passed to the \a callback function. + * \return 0 on success or an error code. + * \see \ref PWMD_OPTION_OVERRIDE_INQUIRE, \ref PWMD_OPTION_NO_PINENTRY, + * \ref PWMD_OPTION_LOCAL_PINENTRY, \ref pwmd_command(), \ref pinentry + */ +LIBPWMD_API gpg_error_t pwmd_passwd (pwm_t * pwm, const char *args, + pwmd_inquire_cb_t callback, void *user); + + /*! \brief Send a command to the pwmd server. * * You should avoid sending the BYE command here because the assuan context -- 2.11.4.GIT