1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
3 Copyright (C) 2006-2008 Ben Kibbey <bjk@luxsci.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <sys/socket.h>
35 #include <sys/types.h>
37 #include <sys/select.h>
53 #define N_(msgid) dgettext("libpwmd", msgid)
59 #define xrealloc realloc
60 #define xmalloc malloc
61 #define xstrdup strdup
62 #define xcalloc calloc
69 static int gelapsed
, gtimeout
;
70 static gpg_error_t
pinentry_command(pwm_t
*pwm
, char **result
, const char *cmd
);
71 static gpg_error_t global_error
;
75 const char *pwmd_strerror(gpg_error_t e
)
77 gpg_err_code_t code
= gpg_err_code(e
);
79 if (code
>= GPG_ERR_USER_1
&& code
< gpg_err_code(EPWMD_MAX
)) {
83 return N_("Unknown error");
85 return N_("No cache slots available");
87 return N_("Recursion loop");
89 return N_("No file is open");
91 return N_("General LibXML error");
93 return N_("File modified");
97 return gpg_strerror(e
);
100 gpg_error_t
pwmd_init()
103 bindtextdomain("libpwmd", LOCALEDIR
);
106 assuan_set_malloc_hooks(xmalloc
, xrealloc
, xfree
);
107 assuan_set_assuan_err_source(GPG_ERR_SOURCE_DEFAULT
);
111 pwm_t
*pwmd_connect(const char *path
, gpg_error_t
*error
)
114 char *socketpath
= NULL
;
117 assuan_context_t ctx
;
122 pw
= getpwuid(getuid());
123 socketpath
= (char *)xmalloc(strlen(pw
->pw_dir
) + strlen("/.pwmd/socket") + 1);
124 sprintf(socketpath
, "%s/.pwmd/socket", pw
->pw_dir
);
127 socketpath
= xstrdup(path
);
129 rc
= assuan_socket_connect_ext(&ctx
, socketpath
, -1, 0);
137 n
= assuan_get_active_fds(ctx
, 0, active
, sizeof(active
));
139 if ((pwm
= (pwm_t
*)xcalloc(1, sizeof(pwm_t
))) == NULL
) {
140 *error
= gpg_error_from_errno(errno
);
141 assuan_disconnect(ctx
);
145 pwm
->fd
= n
<= 0 ? -1 : dup(active
[0]);
148 fcntl(pwm
->fd
, F_SETFL
, O_NONBLOCK
);
153 pwm
->pinentry_tries
= 3;
161 gpg_error_t
pwmd_pending_line(pwm_t
*pwm
, char **line
, size_t *len
)
164 return GPG_ERR_INV_ARG
;
166 if (assuan_pending_line(pwm
->ctx
))
167 return assuan_read_line(pwm
->ctx
, line
, len
);
169 return GPG_ERR_NO_DATA
;
172 void pwmd_close(pwm_t
*pwm
)
178 assuan_disconnect(pwm
->ctx
);
181 xfree(pwm
->password
);
192 if (pwm
->pinentry_tty
)
193 xfree(pwm
->pinentry_tty
);
195 if (pwm
->pinentry_display
)
196 xfree(pwm
->pinentry_display
);
198 if (pwm
->pinentry_term
)
199 xfree(pwm
->pinentry_term
);
202 xfree(pwm
->filename
);
207 static int mem_realloc_cb(void *data
, const void *buffer
, size_t len
)
209 membuf_t
*mem
= (membuf_t
*)data
;
215 if ((p
= xrealloc(mem
->buf
, mem
->len
+ len
)) == NULL
)
219 memcpy((char *)mem
->buf
+ mem
->len
, buffer
, len
);
224 void pwmd_free_result(void *data
)
229 static int _inquire_cb(void *data
, const char *keyword
)
231 pwm_t
*pwm
= (pwm_t
*)data
;
233 int flags
= fcntl(pwm
->fd
, F_GETFL
);
235 /* Shouldn't get this far without a callback. */
236 if (!pwm
->inquire_func
)
237 return GPG_ERR_INV_ARG
;
240 * Since the socket file descriptor is probably set to non-blocking, set to
241 * blocking to prevent GPG_ERR_EAGAIN errors. This should be fixes when
242 * asynchronous INQUIRE is supported by either libassuan or a later
245 fcntl(pwm
->fd
, F_SETFL
, 0);
252 rc
= pwm
->inquire_func(pwm
->inquire_data
, keyword
, rc
, &result
, &len
);
253 rc
= gpg_err_code(rc
);
255 if (rc
== GPG_ERR_EOF
|| !rc
) {
256 if (len
<= 0 || !result
|| !*result
) {
261 arc
= assuan_send_data(pwm
->ctx
, result
, len
);
263 if (rc
== GPG_ERR_EOF
) {
274 fcntl(pwm
->fd
, F_SETFL
, flags
);
278 gpg_error_t
pwmd_finalize(pwm_t
*pwm
)
280 if (!pwm
|| pwm
->fd
< 0)
281 return GPG_ERR_INV_ARG
;
283 pwm
->state
= ASYNC_INIT
;
287 static gpg_error_t
do_nb_command(pwm_t
*pwm
, const char *cmd
, const char *arg
)
291 size_t len
= strlen(cmd
) + 2;
293 len
+= arg
? strlen(arg
) : 0;
295 if (pwm
->state
!= ASYNC_INIT
)
296 return GPG_ERR_UNEXPECTED
;
298 buf
= (char *)xmalloc(len
);
301 rc
= gpg_error_from_errno(ENOMEM
);
305 snprintf(buf
, len
, "%s %s", cmd
, arg
? arg
: "");
306 rc
= assuan_write_line(pwm
->ctx
, buf
);
310 pwm
->state
= ASYNC_PROCESS
;
316 gpg_error_t
pwmd_open_async(pwm_t
*pwm
, const char *filename
)
318 if (!pwm
|| !filename
)
319 return GPG_ERR_INV_ARG
;
321 return do_nb_command(pwm
, "OPEN", filename
);
324 gpg_error_t
pwmd_save_async(pwm_t
*pwm
)
327 return GPG_ERR_INV_ARG
;
329 return do_nb_command(pwm
, "SAVE", NULL
);
332 static gpg_error_t
parse_assuan_line(pwm_t
*pwm
)
338 rc
= assuan_read_line(pwm
->ctx
, &line
, &len
);
341 if (line
[0] == 'O' && line
[1] == 'K' &&
342 (line
[2] == 0 || line
[2] == ' ')) {
343 pwm
->state
= ASYNC_DONE
;
345 else if (line
[0] == '#') {
347 else if (line
[0] == 'S' && (line
[1] == 0 || line
[1] == ' ')) {
348 if (pwm
->status_func
) {
349 pwm
->status_func(pwm
->status_data
,
350 line
[1] == 0 ? line
+1 : line
+2);
353 else if (line
[0] == 'E' && line
[1] == 'R' && line
[2] == 'R' &&
354 (line
[3] == 0 || line
[3] == ' ')) {
357 pwm
->state
= ASYNC_DONE
;
364 pwmd_async_t
pwmd_process(pwm_t
*pwm
, gpg_error_t
*rc
)
368 struct timeval tv
= {0, 0};
372 if (!pwm
|| pwm
->fd
< 0) {
373 *rc
= GPG_ERR_INV_ARG
;
376 else if (pwm
->state
== ASYNC_DONE
)
378 else if (pwm
->state
== ASYNC_INIT
) {
379 *rc
= GPG_ERR_UNEXPECTED
;
384 FD_SET(pwm
->fd
, &rfds
);
385 n
= select(pwm
->fd
+1, &rfds
, NULL
, NULL
, &tv
);
388 if (FD_ISSET(pwm
->fd
, &rfds
))
389 *rc
= parse_assuan_line(pwm
);
392 if (!*rc
&& assuan_pending_line(pwm
->ctx
))
393 *rc
= parse_assuan_line(pwm
);
398 static gpg_error_t
assuan_command(pwm_t
*pwm
, assuan_context_t ctx
,
399 char **result
, const char *cmd
)
407 rc
= assuan_transact(ctx
, cmd
, mem_realloc_cb
, &data
, _inquire_cb
, pwm
,
408 pwm
->status_func
, pwm
->status_data
);
418 mem_realloc_cb(&data
, "", 1);
419 *result
= (char *)data
.buf
;
423 return gpg_err_code(rc
);
426 gpg_error_t
pwmd_inquire(pwm_t
*pwm
, const char *cmd
, pwmd_inquire_fn fn
,
429 if (!pwm
|| !cmd
|| !fn
)
430 return GPG_ERR_INV_ARG
;
432 pwm
->inquire_func
= fn
;
433 pwm
->inquire_data
= data
;
434 return assuan_command(pwm
, pwm
->ctx
, NULL
, cmd
);
437 gpg_error_t
pwmd_terminate_pinentry(pwm_t
*pwm
)
440 return GPG_ERR_NOT_IMPLEMENTED
;
442 if (!pwm
|| pwm
->pid
== -1)
443 return GPG_ERR_INV_ARG
;
445 if (kill(pwm
->pid
, 0) == 0) {
446 if (kill(pwm
->pid
, SIGTERM
) == -1) {
447 if (kill(pwm
->pid
, SIGKILL
) == -1)
448 return gpg_error_from_errno(errno
);
451 pwm
->pin_error
= GPG_ERR_TIMEOUT
;
454 return gpg_error_from_errno(errno
);
461 static gpg_error_t
set_pinentry_strings(pwm_t
*pwm
, int which
)
464 char tmp
[ASSUAN_LINELENGTH
];
468 pwm
->title
= xstrdup(N_("LibPWMD"));
471 pwm
->prompt
= xstrdup(N_("Password:"));
473 if (!pwm
->desc
&& !which
)
474 pwm
->desc
= xstrdup(N_("Enter a password."));
477 snprintf(tmp
, sizeof(tmp
), "SETERROR %s", N_("Invalid password, please try again."));
480 else if (which
== 2) {
481 snprintf(tmp
, sizeof(tmp
), "SETERROR %s", N_("Please type the password again for confirmation."));
485 buf
= (char *)xmalloc(strlen("SETERROR ") + strlen(pwm
->desc
) + 1);
486 sprintf(buf
, "SETERROR %s", pwm
->desc
);
489 error
= pinentry_command(pwm
, NULL
, buf
);
495 buf
= (char *)xmalloc(strlen("SETPROMPT ") + strlen(pwm
->prompt
) + 1);
496 sprintf(buf
, "SETPROMPT %s", pwm
->prompt
);
497 error
= pinentry_command(pwm
, NULL
, buf
);
503 buf
= (char *)xmalloc(strlen("SETDESC ") + strlen(pwm
->title
) + 1);
504 sprintf(buf
, "SETDESC %s", pwm
->title
);
505 error
= pinentry_command(pwm
, NULL
, buf
);
510 static void update_pinentry_settings(pwm_t
*pwm
)
514 struct passwd
*pw
= getpwuid(getuid());
517 snprintf(buf
, sizeof(buf
), "%s/.pwmd/pinentry.conf", pw
->pw_dir
);
519 if ((fp
= fopen(buf
, "r")) == NULL
)
522 while ((p
= fgets(buf
, sizeof(buf
), fp
)) != NULL
) {
523 char name
[32], val
[256];
525 if (sscanf(p
, " %31[a-zA-Z] = %255s", name
, val
) != 2)
528 if (strcasecmp(name
, "TTYNAME") == 0) {
529 xfree(pwm
->pinentry_tty
);
530 pwm
->pinentry_tty
= xstrdup(val
);
532 else if (strcasecmp(name
, "TTYTYPE") == 0) {
533 xfree(pwm
->pinentry_term
);
534 pwm
->pinentry_term
= xstrdup(val
);
536 else if (strcasecmp(name
, "DISPLAY") == 0) {
537 xfree(pwm
->pinentry_display
);
538 pwm
->pinentry_display
= xstrdup(val
);
540 else if (strcasecmp(name
, "PATH") == 0) {
541 xfree(pwm
->pinentry_path
);
542 pwm
->pinentry_path
= xstrdup(val
);
549 static gpg_error_t
launch_pinentry(pwm_t
*pwm
)
552 assuan_context_t ctx
;
553 int child_list
[] = {-1};
554 char *display
= getenv("DISPLAY");
556 int have_display
= 0;
559 update_pinentry_settings(pwm
);
561 if (pwm
->pinentry_display
|| display
)
564 tty
= pwm
->pinentry_tty
? pwm
->pinentry_tty
: ttyname(STDOUT_FILENO
);
567 return gpg_error_from_errno(errno
);
570 if (!have_display
&& !tty
)
571 return GPG_ERR_ENOTTY
;
573 argv
[0] = "pinentry";
574 argv
[1] = have_display
? "--display" : "--ttyname";
575 argv
[2] = have_display
? pwm
->pinentry_display
? pwm
->pinentry_display
: display
: tty
;
579 argv
[3] = "--ttytype";
580 argv
[4] = pwm
->pinentry_term
? pwm
->pinentry_term
: getenv("TERM");
584 rc
= assuan_pipe_connect(&ctx
, pwm
->pinentry_path
? pwm
->pinentry_path
: PINENTRY_PATH
, argv
, child_list
);
589 pwm
->pid
= assuan_get_pid(ctx
);
591 return set_pinentry_strings(pwm
, 0);
594 static gpg_error_t
pinentry_command(pwm_t
*pwm
, char **result
, const char *cmd
)
599 n
= launch_pinentry(pwm
);
605 return assuan_command(pwm
, pwm
->pctx
, result
, cmd
);
608 static void pinentry_disconnect(pwm_t
*pwm
)
611 assuan_disconnect(pwm
->pctx
);
618 * Only called from a child process.
620 static void catchsig(int sig
)
624 if (gelapsed
++ >= gtimeout
) {
625 global_error
= pwmd_terminate_pinentry(gpwm
);
628 global_error
= GPG_ERR_TIMEOUT
;
640 static char *percent_escape(const char *atext
)
642 const unsigned char *s
;
643 int len
= strlen(atext
) * 3 + 1;
644 char *buf
= (char *)xmalloc(len
), *p
= buf
;
649 for (s
=(const unsigned char *)atext
; *s
; s
++) {
651 sprintf (p
, "%%%02X", *s
);
663 static gpg_error_t
send_command(pwm_t
*pwm
, char **result
, const char *cmd
)
666 return GPG_ERR_INV_ARG
;
668 return assuan_command(pwm
, pwm
->ctx
, result
, cmd
);
672 * Avoid sending the BYE command here. libassuan will close the file
673 * descriptor and release the assuan context. Use pwmd_close() instead.
675 gpg_error_t
pwmd_command(pwm_t
*pwm
, char **result
, const char *cmd
, ...)
683 return GPG_ERR_INV_ARG
;
690 len
= vsnprintf(NULL
, 0, cmd
, ap
);
691 buf
= (char *)xmalloc(len
+ 1);
692 len
= vsnprintf(buf
, len
+ 1, cmd
, ap
);
694 error
= send_command(pwm
, result
, buf
);
700 static gpg_error_t
do_getpin(pwm_t
*pwm
, char **result
)
703 signal(SIGALRM
, catchsig
);
708 return pinentry_command(pwm
, result
, "GETPIN");
711 static gpg_error_t
getpin(pwm_t
*pwm
, char **result
, int *try_n
, int which
)
713 int pin_try
= *try_n
;
720 error
= set_pinentry_strings(pwm
, which
);
723 pinentry_disconnect(pwm
);
728 if (pwm
->pinentry_tries
-1 != pin_try
) {
729 error
= set_pinentry_strings(pwm
, 1);
732 pinentry_disconnect(pwm
);
738 error
= do_getpin(pwm
, result
);
741 * Since there was input cancel any timeout.
746 if (error
== GPG_ERR_ASS_CANCELED
|| error
== ASSUAN_Canceled
)
747 return GPG_ERR_ASS_CANCELED
;
749 if (pin_try
!= -1 && pin_try
--)
753 pinentry_disconnect(pwm
);
763 gpg_error_t
pwmd_open_nb_finalize(pwm_t
*pwm
, pwmd_nb_status_t
*pw
)
769 return GPG_ERR_NOT_IMPLEMENTED
;
772 if (!pwm
|| !pw
|| !pw
->filename
[0])
773 return GPG_ERR_INV_ARG
;
782 error
= pwmd_command(pwm
, &result
, "ISCACHED %s", pw
->filename
);
788 xfree(pwm
->filename
);
790 pwm
->filename
= xstrdup(pw
->filename
);
791 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
795 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
799 static gpg_error_t
do_open_command(pwm_t
*pwm
, const char *filename
, char *password
)
801 char buf
[ASSUAN_LINELENGTH
];
805 snprintf(buf
, sizeof(buf
), "OPEN %s %s", filename
, password
? password
: "");
806 error
= send_command(pwm
, &result
, buf
);
807 memset(buf
, 0, sizeof(buf
));
815 static int do_pwmd_open(pwm_t
*pwm
, gpg_error_t
*error
, const char *filename
,
819 char *password
= NULL
;
825 if (!pwm
|| !filename
|| !*filename
) {
826 *error
= GPG_ERR_INV_ARG
;
831 pin_try
= pwm
->pinentry_tries
- 1;
835 * Avoid calling pinentry if the password is cached on the server or if
836 * this is a new file.
838 *error
= pwmd_command(pwm
, &result
, "GETCONFIG data_directory");
843 snprintf(path
, sizeof(path
), "%s/%s", result
, filename
);
844 pwmd_free_result(result
);
846 if (access(path
, R_OK
) == -1) {
851 *error
= pwmd_command(pwm
, &result
, "ISCACHED %s", filename
);
853 if (*error
== EPWMD_CACHE_NOT_FOUND
) {
855 password
= pwm
->passfunc(pwm
, pwm
->passdata
);
859 if (*error
== EPWMD_CACHE_NOT_FOUND
) {
862 * Get the password from pinentry.
864 if (pwm
->use_pinentry
) {
866 * Nonblocking is wanted. fork() then return a file descriptor
867 * that the client can use to read() from.
875 *error
= gpg_error_from_syserror();
884 strncpy(pw
.filename
, filename
, sizeof(pw
.filename
));
885 pw
.filename
[sizeof(pw
.filename
)-1] = 0;
895 *error
= getpin(pwm
, &password
, &pin_try
, 0);
900 pinentry_disconnect(pwm
);
902 if (gtimeout
&& gelapsed
>= gtimeout
)
903 *error
= GPG_ERR_TIMEOUT
;
906 write(p
[1], &pw
, sizeof(pw
));
912 * Don't count the time it takes to open the file
913 * which may have many iterations.
915 signal(SIGALRM
, SIG_DFL
);
916 *error
= do_open_command(pwm
, filename
, password
);
919 signal(SIGALRM
, catchsig
);
921 if (pwm
->pctx
&& *error
== EPWMD_BADKEY
) {
923 goto getpin_nb_again
;
928 pinentry_disconnect(pwm
);
930 write(p
[1], &pw
, sizeof(pw
));
935 *error
= gpg_error_from_syserror();
948 *error
= getpin(pwm
, &password
, &pin_try
, 1);
952 pinentry_disconnect(pwm
);
954 if (pwm
->pin_error
) {
955 *error
= pwm
->pin_error
;
965 * Not using pinentry and the file was not found
969 if (pwm
->password
== NULL
) {
975 password
= pwm
->password
;
985 *error
= do_open_command(pwm
, filename
, password
);
988 * Keep the user defined password set with pwmd_setopt(). The password may
989 * be needed later (pwmd_save()) depending on the pwmd file cache settings.
991 if (password
&& password
!= pwm
->password
)
995 if (pwm
->pctx
&& *error
== EPWMD_BADKEY
) {
999 pinentry_disconnect(pwm
);
1003 pinentry_disconnect(pwm
);
1008 xfree(pwm
->filename
);
1010 pwm
->filename
= xstrdup(filename
);
1014 * The file is cached or the file is a new file.
1017 return *error
? -1 : -2;
1019 return *error
? 1 : 0;
1022 gpg_error_t
pwmd_open(pwm_t
*pwm
, const char *filename
)
1026 do_pwmd_open(pwm
, &error
, filename
, 0, 0);
1030 int pwmd_open_nb(pwm_t
*pwm
, gpg_error_t
*error
, const char *filename
,
1033 #ifndef USE_PINENTRY
1034 *error
= GPG_ERR_NOT_IMPLEMENTED
;
1037 return do_pwmd_open(pwm
, error
, filename
, 1, timeout
);
1042 static gpg_error_t
do_save_getpin(pwm_t
*pwm
, char **password
)
1046 char *result
= NULL
;
1050 error
= getpin(pwm
, &result
, &pin_try
, confirm
? 2 : 0);
1054 pinentry_disconnect(pwm
);
1067 if (strcmp(*password
, result
)) {
1070 pinentry_disconnect(pwm
);
1071 error
= EPWMD_BADKEY
;
1076 pinentry_disconnect(pwm
);
1081 static gpg_error_t
do_save_command(pwm_t
*pwm
, char *password
)
1083 char buf
[ASSUAN_LINELENGTH
];
1085 char *result
= NULL
;
1087 snprintf(buf
, sizeof(buf
), "SAVE %s", password
? password
: "");
1088 error
= send_command(pwm
, &result
, buf
);
1089 memset(&buf
, 0, sizeof(buf
));
1091 if (error
&& result
)
1097 gpg_error_t
pwmd_save_nb_finalize(pwm_t
*pwm
, pwmd_nb_status_t
*pw
)
1101 #ifndef USE_PINENTRY
1102 return GPG_ERR_NOT_IMPLEMENTED
;
1105 if (!pwm
|| !pw
|| !pw
->filename
[0])
1106 return GPG_ERR_INV_ARG
;
1112 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
1116 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
1120 static int do_pwmd_save(pwm_t
*pwm
, gpg_error_t
*error
, int nb
)
1122 char *result
= NULL
;
1123 char *password
= NULL
;
1126 *error
= GPG_ERR_INV_ARG
;
1130 if (pwm
->use_pinentry
|| pwm
->passfunc
) {
1131 *error
= pwmd_command(pwm
, &result
, "ISCACHED %s", pwm
->filename
);
1133 if (*error
== EPWMD_CACHE_NOT_FOUND
) {
1135 if (pwm
->use_pinentry
) {
1139 pwmd_nb_status_t pw
;
1141 if (pipe(p
) == -1) {
1142 *error
= gpg_error_from_syserror();
1151 strncpy(pw
.filename
, pwm
->filename
, sizeof(pw
.filename
));
1152 pw
.filename
[sizeof(pw
.filename
)-1] = 0;
1157 *error
= do_save_getpin(pwm
, &password
);
1158 } while (*error
== EPWMD_BADKEY
);
1162 pinentry_disconnect(pwm
);
1165 write(p
[1], &pw
, sizeof(pw
));
1170 *error
= do_save_command(pwm
, password
);
1171 pinentry_disconnect(pwm
);
1173 write(p
[1], &pw
, sizeof(pw
));
1178 *error
= gpg_error_from_syserror();
1190 *error
= do_save_getpin(pwm
, &password
);
1198 password
= (*pwm
->passfunc
)(pwm
, pwm
->passdata
);
1209 password
= pwm
->password
;
1211 *error
= do_save_command(pwm
, password
);
1213 if (password
&& password
!= pwm
->password
)
1217 return *error
? -1 : -2;
1219 return *error
? 1 : 0;
1222 int pwmd_save_nb(pwm_t
*pwm
, gpg_error_t
*error
)
1224 #ifndef USE_PINENTRY
1225 *error
= GPG_ERR_NOT_IMPLEMENTED
;
1228 return do_pwmd_save(pwm
, error
, 1);
1232 gpg_error_t
pwmd_save(pwm_t
*pwm
)
1236 do_pwmd_save(pwm
, &error
, 0);
1240 gpg_error_t
pwmd_setopt(pwm_t
*pwm
, pwmd_option_t opt
, ...)
1244 int n
= va_arg(ap
, int);
1248 gpg_error_t error
= 0;
1251 return GPG_ERR_INV_ARG
;
1256 case PWMD_OPTION_STATUS_FUNC
:
1257 pwm
->status_func
= va_arg(ap
, pwmd_status_fn
);
1259 case PWMD_OPTION_STATUS_DATA
:
1260 pwm
->status_data
= va_arg(ap
, void *);
1262 case PWMD_OPTION_PASSWORD_FUNC
:
1263 pwm
->passfunc
= va_arg(ap
, pwmd_password_fn
);
1265 case PWMD_OPTION_PASSWORD_DATA
:
1266 pwm
->passdata
= va_arg(ap
, void *);
1268 case PWMD_OPTION_PASSWORD
:
1269 arg1
= va_arg(ap
, char *);
1272 xfree(pwm
->password
);
1274 pwm
->password
= xstrdup(arg1
);
1277 case PWMD_OPTION_PINENTRY
:
1278 n
= va_arg(ap
, int);
1280 if (n
!= 0 && n
!= 1) {
1282 error
= GPG_ERR_INV_VALUE
;
1285 pwm
->use_pinentry
= n
;
1286 error
= pwmd_command(pwm
, &result
, "OPTION PINENTRY=%i",
1287 !pwm
->use_pinentry
);
1290 case PWMD_OPTION_PINENTRY_TRIES
:
1291 n
= va_arg(ap
, int);
1295 error
= GPG_ERR_INV_VALUE
;
1298 pwm
->pinentry_tries
= n
;
1300 case PWMD_OPTION_PINENTRY_PATH
:
1301 if (pwm
->pinentry_path
)
1302 xfree(pwm
->pinentry_path
);
1304 pwm
->pinentry_path
= xstrdup(va_arg(ap
, char *));
1306 case PWMD_OPTION_PINENTRY_TTY
:
1307 if (pwm
->pinentry_tty
)
1308 xfree(pwm
->pinentry_tty
);
1310 pwm
->pinentry_tty
= xstrdup(va_arg(ap
, char *));
1312 case PWMD_OPTION_PINENTRY_DISPLAY
:
1313 if (pwm
->pinentry_display
)
1314 xfree(pwm
->pinentry_display
);
1316 pwm
->pinentry_display
= xstrdup(va_arg(ap
, char *));
1318 case PWMD_OPTION_PINENTRY_TERM
:
1319 if (pwm
->pinentry_term
)
1320 xfree(pwm
->pinentry_term
);
1322 pwm
->pinentry_term
= xstrdup(va_arg(ap
, char *));
1324 case PWMD_OPTION_PINENTRY_TITLE
:
1327 pwm
->title
= percent_escape(va_arg(ap
, char *));
1329 case PWMD_OPTION_PINENTRY_PROMPT
:
1332 pwm
->prompt
= percent_escape(va_arg(ap
, char *));
1334 case PWMD_OPTION_PINENTRY_DESC
:
1337 pwm
->desc
= percent_escape(va_arg(ap
, char *));
1340 case PWMD_OPTION_PINENTRY
:
1341 case PWMD_OPTION_PINENTRY_TRIES
:
1342 case PWMD_OPTION_PINENTRY_PATH
:
1343 case PWMD_OPTION_PINENTRY_TTY
:
1344 case PWMD_OPTION_PINENTRY_DISPLAY
:
1345 case PWMD_OPTION_PINENTRY_TERM
:
1346 case PWMD_OPTION_PINENTRY_TITLE
:
1347 case PWMD_OPTION_PINENTRY_PROMPT
:
1348 case PWMD_OPTION_PINENTRY_DESC
:
1349 error
= GPG_ERR_NOT_IMPLEMENTED
;
1353 error
= GPG_ERR_NOT_IMPLEMENTED
;
1361 gpg_error_t
pwmd_assuan_ctx(pwm_t
*pwm
, assuan_context_t
*ctx
, int *fd
)
1364 return GPG_ERR_INV_ARG
;