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
;
74 const char *pwmd_strerror(gpg_error_t e
)
76 gpg_err_code_t code
= gpg_err_code(e
);
78 if (code
>= GPG_ERR_USER_1
&& code
< gpg_err_code(EPWMD_MAX
)) {
82 return N_("Unknown error");
84 return N_("No cache slots available");
86 return N_("Recursion loop");
88 return N_("No file is open");
90 return N_("General LibXML error");
92 return N_("File modified");
96 return gpg_strerror(e
);
99 gpg_error_t
pwmd_init()
102 bindtextdomain("libpwmd", LOCALEDIR
);
105 assuan_set_malloc_hooks(xmalloc
, xrealloc
, xfree
);
106 assuan_set_assuan_err_source(GPG_ERR_SOURCE_DEFAULT
);
110 pwm_t
*pwmd_connect(const char *path
, gpg_error_t
*error
)
113 char *socketpath
= NULL
;
116 assuan_context_t ctx
;
121 pw
= getpwuid(getuid());
122 socketpath
= (char *)xmalloc(strlen(pw
->pw_dir
) + strlen("/.pwmd/socket") + 1);
123 sprintf(socketpath
, "%s/.pwmd/socket", pw
->pw_dir
);
126 socketpath
= xstrdup(path
);
128 rc
= assuan_socket_connect_ext(&ctx
, socketpath
, -1, 0);
136 n
= assuan_get_active_fds(ctx
, 0, active
, sizeof(active
));
138 if ((pwm
= (pwm_t
*)xcalloc(1, sizeof(pwm_t
))) == NULL
) {
139 *error
= gpg_error_from_errno(errno
);
140 assuan_disconnect(ctx
);
144 pwm
->fd
= n
<= 0 ? -1 : dup(active
[0]);
147 fcntl(pwm
->fd
, F_SETFL
, O_NONBLOCK
);
152 pwm
->pinentry_tries
= 3;
160 gpg_error_t
pwmd_pending_line(pwm_t
*pwm
, char **line
, size_t *len
)
163 return GPG_ERR_INV_ARG
;
165 if (assuan_pending_line(pwm
->ctx
))
166 return assuan_read_line(pwm
->ctx
, line
, len
);
168 return GPG_ERR_NO_DATA
;
171 void pwmd_close(pwm_t
*pwm
)
177 assuan_disconnect(pwm
->ctx
);
180 xfree(pwm
->password
);
191 if (pwm
->pinentry_tty
)
192 xfree(pwm
->pinentry_tty
);
194 if (pwm
->pinentry_display
)
195 xfree(pwm
->pinentry_display
);
197 if (pwm
->pinentry_term
)
198 xfree(pwm
->pinentry_term
);
201 xfree(pwm
->filename
);
206 static int mem_realloc_cb(void *data
, const void *buffer
, size_t len
)
208 membuf_t
*mem
= (membuf_t
*)data
;
214 if ((p
= xrealloc(mem
->buf
, mem
->len
+ len
)) == NULL
)
218 memcpy((char *)mem
->buf
+ mem
->len
, buffer
, len
);
223 void pwmd_free_result(void *data
)
228 static int _inquire_cb(void *data
, const char *keyword
)
230 pwm_t
*pwm
= (pwm_t
*)data
;
232 int flags
= fcntl(pwm
->fd
, F_GETFL
);
234 /* Shouldn't get this far without a callback. */
235 if (!pwm
->inquire_func
)
236 return GPG_ERR_INV_ARG
;
239 * Since the socket file descriptor is probably set to non-blocking, set to
240 * blocking to prevent GPG_ERR_EAGAIN errors. This should be fixes when
241 * asynchronous INQUIRE is supported by either libassuan or a later
244 fcntl(pwm
->fd
, F_SETFL
, 0);
251 rc
= pwm
->inquire_func(pwm
->inquire_data
, keyword
, rc
, &result
, &len
);
252 rc
= gpg_err_code(rc
);
254 if (rc
== GPG_ERR_EOF
|| !rc
) {
255 if (len
<= 0 || !result
|| !*result
) {
260 arc
= assuan_send_data(pwm
->ctx
, result
, len
);
262 if (rc
== GPG_ERR_EOF
) {
273 fcntl(pwm
->fd
, F_SETFL
, flags
);
277 gpg_error_t
pwmd_finalize(pwm_t
*pwm
)
279 if (!pwm
|| pwm
->fd
< 0)
280 return GPG_ERR_INV_ARG
;
282 pwm
->state
= ASYNC_INIT
;
286 static gpg_error_t
do_nb_command(pwm_t
*pwm
, const char *cmd
, const char *arg
)
290 size_t len
= strlen(cmd
) + 2;
292 len
+= arg
? strlen(arg
) : 0;
294 if (pwm
->state
!= ASYNC_INIT
)
295 return GPG_ERR_UNEXPECTED
;
297 buf
= (char *)xmalloc(len
);
300 rc
= gpg_error_from_errno(ENOMEM
);
304 snprintf(buf
, len
, "%s %s", cmd
, arg
? arg
: "");
305 rc
= assuan_write_line(pwm
->ctx
, buf
);
309 pwm
->state
= ASYNC_PROCESS
;
315 gpg_error_t
pwmd_open_async(pwm_t
*pwm
, const char *filename
)
317 if (!pwm
|| !filename
)
318 return GPG_ERR_INV_ARG
;
320 return do_nb_command(pwm
, "OPEN", filename
);
323 gpg_error_t
pwmd_save_async(pwm_t
*pwm
)
326 return GPG_ERR_INV_ARG
;
328 return do_nb_command(pwm
, "SAVE", NULL
);
331 static gpg_error_t
parse_assuan_line(pwm_t
*pwm
)
337 rc
= assuan_read_line(pwm
->ctx
, &line
, &len
);
340 if (line
[0] == 'O' && line
[1] == 'K' &&
341 (line
[2] == 0 || line
[2] == ' ')) {
342 pwm
->state
= ASYNC_DONE
;
344 else if (line
[0] == '#') {
346 else if (line
[0] == 'S' && (line
[1] == 0 || line
[1] == ' ')) {
347 if (pwm
->status_func
) {
348 pwm
->status_func(pwm
->status_data
,
349 line
[1] == 0 ? line
+1 : line
+2);
352 else if (line
[0] == 'E' && line
[1] == 'R' && line
[2] == 'R' &&
353 (line
[3] == 0 || line
[3] == ' ')) {
356 pwm
->state
= ASYNC_DONE
;
363 pwmd_async_t
pwmd_process(pwm_t
*pwm
, gpg_error_t
*rc
)
367 struct timeval tv
= {0, 0};
371 if (!pwm
|| pwm
->fd
< 0) {
372 *rc
= GPG_ERR_INV_ARG
;
375 else if (pwm
->state
== ASYNC_DONE
)
377 else if (pwm
->state
== ASYNC_INIT
) {
378 *rc
= GPG_ERR_UNEXPECTED
;
383 FD_SET(pwm
->fd
, &rfds
);
384 n
= select(pwm
->fd
+1, &rfds
, NULL
, NULL
, &tv
);
387 if (FD_ISSET(pwm
->fd
, &rfds
))
388 *rc
= parse_assuan_line(pwm
);
391 while (!*rc
&& assuan_pending_line(pwm
->ctx
))
392 *rc
= parse_assuan_line(pwm
);
397 static gpg_error_t
assuan_command(pwm_t
*pwm
, assuan_context_t ctx
,
398 char **result
, const char *cmd
)
406 rc
= assuan_transact(ctx
, cmd
, mem_realloc_cb
, &data
, _inquire_cb
, pwm
,
407 pwm
->status_func
, pwm
->status_data
);
417 mem_realloc_cb(&data
, "", 1);
418 *result
= (char *)data
.buf
;
422 return gpg_err_code(rc
);
425 gpg_error_t
pwmd_inquire(pwm_t
*pwm
, const char *cmd
, pwmd_inquire_fn fn
,
428 if (!pwm
|| !cmd
|| !fn
)
429 return GPG_ERR_INV_ARG
;
431 pwm
->inquire_func
= fn
;
432 pwm
->inquire_data
= data
;
433 return assuan_command(pwm
, pwm
->ctx
, NULL
, cmd
);
436 gpg_error_t
pwmd_terminate_pinentry(pwm_t
*pwm
)
439 return GPG_ERR_NOT_IMPLEMENTED
;
441 if (!pwm
|| pwm
->pid
== -1)
442 return GPG_ERR_INV_ARG
;
444 if (kill(pwm
->pid
, 0) == 0) {
445 if (kill(pwm
->pid
, SIGTERM
) == -1) {
446 if (kill(pwm
->pid
, SIGKILL
) == -1)
447 return gpg_error_from_errno(errno
);
450 pwm
->pin_error
= GPG_ERR_TIMEOUT
;
453 return gpg_error_from_errno(errno
);
460 static gpg_error_t
set_pinentry_strings(pwm_t
*pwm
, int which
)
463 char tmp
[ASSUAN_LINELENGTH
];
467 pwm
->title
= xstrdup(N_("LibPWMD"));
470 pwm
->prompt
= xstrdup(N_("Password:"));
472 if (!pwm
->desc
&& !which
)
473 pwm
->desc
= xstrdup(N_("Enter a password."));
476 snprintf(tmp
, sizeof(tmp
), "SETERROR %s", N_("Invalid password, please try again."));
479 else if (which
== 2) {
480 snprintf(tmp
, sizeof(tmp
), "SETERROR %s", N_("Please type the password again for confirmation."));
484 buf
= (char *)xmalloc(strlen("SETERROR ") + strlen(pwm
->desc
) + 1);
485 sprintf(buf
, "SETERROR %s", pwm
->desc
);
488 error
= pinentry_command(pwm
, NULL
, buf
);
494 buf
= (char *)xmalloc(strlen("SETPROMPT ") + strlen(pwm
->prompt
) + 1);
495 sprintf(buf
, "SETPROMPT %s", pwm
->prompt
);
496 error
= pinentry_command(pwm
, NULL
, buf
);
502 buf
= (char *)xmalloc(strlen("SETDESC ") + strlen(pwm
->title
) + 1);
503 sprintf(buf
, "SETDESC %s", pwm
->title
);
504 error
= pinentry_command(pwm
, NULL
, buf
);
509 static void update_pinentry_settings(pwm_t
*pwm
)
513 struct passwd
*pw
= getpwuid(getuid());
516 snprintf(buf
, sizeof(buf
), "%s/.pwmd/pinentry.conf", pw
->pw_dir
);
518 if ((fp
= fopen(buf
, "r")) == NULL
)
521 while ((p
= fgets(buf
, sizeof(buf
), fp
)) != NULL
) {
522 char name
[32], val
[256];
524 if (sscanf(p
, " %31[a-zA-Z] = %255s", name
, val
) != 2)
527 if (strcasecmp(name
, "TTYNAME") == 0) {
528 xfree(pwm
->pinentry_tty
);
529 pwm
->pinentry_tty
= xstrdup(val
);
531 else if (strcasecmp(name
, "TTYTYPE") == 0) {
532 xfree(pwm
->pinentry_term
);
533 pwm
->pinentry_term
= xstrdup(val
);
535 else if (strcasecmp(name
, "DISPLAY") == 0) {
536 xfree(pwm
->pinentry_display
);
537 pwm
->pinentry_display
= xstrdup(val
);
539 else if (strcasecmp(name
, "PATH") == 0) {
540 xfree(pwm
->pinentry_path
);
541 pwm
->pinentry_path
= xstrdup(val
);
548 static gpg_error_t
launch_pinentry(pwm_t
*pwm
)
551 assuan_context_t ctx
;
552 int child_list
[] = {-1};
553 char *display
= getenv("DISPLAY");
555 int have_display
= 0;
558 update_pinentry_settings(pwm
);
560 if (pwm
->pinentry_display
|| display
)
563 tty
= pwm
->pinentry_tty
? pwm
->pinentry_tty
: ttyname(STDOUT_FILENO
);
566 return gpg_error_from_errno(errno
);
569 if (!have_display
&& !tty
)
570 return GPG_ERR_ENOTTY
;
572 argv
[0] = "pinentry";
573 argv
[1] = have_display
? "--display" : "--ttyname";
574 argv
[2] = have_display
? pwm
->pinentry_display
? pwm
->pinentry_display
: display
: tty
;
578 argv
[3] = "--ttytype";
579 argv
[4] = pwm
->pinentry_term
? pwm
->pinentry_term
: getenv("TERM");
583 rc
= assuan_pipe_connect(&ctx
, pwm
->pinentry_path
? pwm
->pinentry_path
: PINENTRY_PATH
, argv
, child_list
);
588 pwm
->pid
= assuan_get_pid(ctx
);
590 return set_pinentry_strings(pwm
, 0);
593 static gpg_error_t
pinentry_command(pwm_t
*pwm
, char **result
, const char *cmd
)
598 n
= launch_pinentry(pwm
);
604 return assuan_command(pwm
, pwm
->pctx
, result
, cmd
);
607 static void pinentry_disconnect(pwm_t
*pwm
)
610 assuan_disconnect(pwm
->pctx
);
617 * Only called from a child process.
619 static void catchsig(int sig
)
623 if (gelapsed
++ >= gtimeout
) {
624 global_error
= pwmd_terminate_pinentry(gpwm
);
627 global_error
= GPG_ERR_TIMEOUT
;
640 * Borrowed from libassuan.
642 static char *percent_escape(const char *atext
)
644 const unsigned char *s
;
645 int len
= strlen(atext
) * 3 + 1;
646 char *buf
= (char *)xmalloc(len
), *p
= buf
;
651 for (s
=(const unsigned char *)atext
; *s
; s
++) {
653 sprintf (p
, "%%%02X", *s
);
665 static gpg_error_t
send_command(pwm_t
*pwm
, char **result
, const char *cmd
)
668 return GPG_ERR_INV_ARG
;
670 return assuan_command(pwm
, pwm
->ctx
, result
, cmd
);
674 * Avoid sending the BYE command here. libassuan will close the file
675 * descriptor and release the assuan context. Use pwmd_close() instead.
677 gpg_error_t
pwmd_command(pwm_t
*pwm
, char **result
, const char *cmd
, ...)
685 return GPG_ERR_INV_ARG
;
690 * C99 allows the dst pointer to be null which will calculate the length
691 * of the result and return it.
693 len
= vsnprintf(NULL
, 0, cmd
, ap
);
694 buf
= (char *)xmalloc(len
+ 1);
695 len
= vsnprintf(buf
, len
+ 1, cmd
, ap
);
697 error
= send_command(pwm
, result
, buf
);
703 static gpg_error_t
do_getpin(pwm_t
*pwm
, char **result
)
706 signal(SIGALRM
, catchsig
);
711 return pinentry_command(pwm
, result
, "GETPIN");
714 static gpg_error_t
getpin(pwm_t
*pwm
, char **result
, int *try_n
, int which
)
716 int pin_try
= *try_n
;
723 error
= set_pinentry_strings(pwm
, which
);
726 pinentry_disconnect(pwm
);
731 if (pwm
->pinentry_tries
-1 != pin_try
) {
732 error
= set_pinentry_strings(pwm
, 1);
735 pinentry_disconnect(pwm
);
741 error
= do_getpin(pwm
, result
);
744 * Since there was input cancel any timeout setting.
749 if (error
== GPG_ERR_CANCELED
)
750 return GPG_ERR_CANCELED
;
752 if (pin_try
!= -1 && pin_try
--)
756 pinentry_disconnect(pwm
);
766 gpg_error_t
pwmd_open_nb_finalize(pwm_t
*pwm
, pwmd_nb_status_t
*pw
)
771 return GPG_ERR_NOT_IMPLEMENTED
;
774 if (!pwm
|| !pw
|| !pw
->filename
[0])
775 return GPG_ERR_INV_ARG
;
785 xfree(pwm
->filename
);
787 pwm
->filename
= xstrdup(pw
->filename
);
788 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
792 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
796 static gpg_error_t
do_open_command(pwm_t
*pwm
, const char *filename
, char *password
)
798 char buf
[ASSUAN_LINELENGTH
];
802 snprintf(buf
, sizeof(buf
), "OPEN %s %s", filename
, password
? password
: "");
803 error
= send_command(pwm
, &result
, buf
);
804 memset(buf
, 0, sizeof(buf
));
812 static int do_pwmd_open(pwm_t
*pwm
, gpg_error_t
*error
, const char *filename
,
816 char *password
= NULL
;
822 if (!pwm
|| !filename
|| !*filename
) {
823 *error
= GPG_ERR_INV_ARG
;
828 pin_try
= pwm
->pinentry_tries
- 1;
832 * Avoid calling pinentry if the password is cached on the server or if
833 * this is a new file.
835 *error
= pwmd_command(pwm
, &result
, "GETCONFIG data_directory");
840 snprintf(path
, sizeof(path
), "%s/%s", result
, filename
);
841 pwmd_free_result(result
);
843 if (access(path
, R_OK
) == -1) {
848 *error
= pwmd_command(pwm
, &result
, "ISCACHED %s", filename
);
850 if (*error
== EPWMD_CACHE_NOT_FOUND
) {
852 password
= pwm
->passfunc(pwm
, pwm
->passdata
);
858 * Get the password from pinentry.
860 if (pwm
->use_pinentry
) {
862 * Nonblocking is wanted. fork() then return a file descriptor
863 * that the client can use to read() from.
871 *error
= gpg_error_from_syserror();
880 strncpy(pw
.filename
, filename
, sizeof(pw
.filename
));
881 pw
.filename
[sizeof(pw
.filename
)-1] = 0;
891 *error
= getpin(pwm
, &password
, &pin_try
, 0);
896 pinentry_disconnect(pwm
);
898 if (gtimeout
&& gelapsed
>= gtimeout
)
899 *error
= GPG_ERR_TIMEOUT
;
902 write(p
[1], &pw
, sizeof(pw
));
908 * Don't count the time it takes to open the file
909 * which may have many iterations.
911 signal(SIGALRM
, SIG_DFL
);
912 *error
= do_open_command(pwm
, filename
, password
);
915 signal(SIGALRM
, catchsig
);
917 if (pwm
->pctx
&& *error
== EPWMD_BADKEY
) {
919 goto getpin_nb_again
;
924 pinentry_disconnect(pwm
);
926 write(p
[1], &pw
, sizeof(pw
));
931 *error
= gpg_error_from_syserror();
946 * Not using pinentry and the file was not found
949 password
= pwm
->password
;
958 *error
= do_open_command(pwm
, filename
, password
);
961 * Keep the user defined password set with pwmd_setopt(). The password may
962 * be needed later (pwmd_save()) depending on the pwmd file cache settings.
964 if (password
&& password
!= pwm
->password
)
968 if (*error
== EPWMD_BADKEY
) {
973 pinentry_disconnect(pwm
);
981 xfree(pwm
->filename
);
983 pwm
->filename
= xstrdup(filename
);
987 * The file is cached or the file is a new file.
990 return *error
? -1 : -2;
992 return *error
? 1 : 0;
995 gpg_error_t
pwmd_open(pwm_t
*pwm
, const char *filename
)
999 do_pwmd_open(pwm
, &error
, filename
, 0, 0);
1003 int pwmd_open_nb(pwm_t
*pwm
, gpg_error_t
*error
, const char *filename
,
1006 #ifndef USE_PINENTRY
1007 *error
= GPG_ERR_NOT_IMPLEMENTED
;
1010 return do_pwmd_open(pwm
, error
, filename
, 1, timeout
);
1015 static gpg_error_t
do_save_getpin(pwm_t
*pwm
, char **password
)
1019 char *result
= NULL
;
1023 error
= getpin(pwm
, &result
, &pin_try
, confirm
? 2 : 0);
1027 pinentry_disconnect(pwm
);
1040 if (strcmp(*password
, result
)) {
1043 pinentry_disconnect(pwm
);
1044 error
= EPWMD_BADKEY
;
1049 pinentry_disconnect(pwm
);
1054 static gpg_error_t
do_save_command(pwm_t
*pwm
, char *password
)
1056 char buf
[ASSUAN_LINELENGTH
];
1058 char *result
= NULL
;
1060 snprintf(buf
, sizeof(buf
), "SAVE %s", password
? password
: "");
1061 error
= send_command(pwm
, &result
, buf
);
1062 memset(&buf
, 0, sizeof(buf
));
1064 if (error
&& result
)
1070 gpg_error_t
pwmd_save_nb_finalize(pwm_t
*pwm
, pwmd_nb_status_t
*pw
)
1074 #ifndef USE_PINENTRY
1075 return GPG_ERR_NOT_IMPLEMENTED
;
1078 if (!pwm
|| !pw
|| !pw
->filename
[0])
1079 return GPG_ERR_INV_ARG
;
1083 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
1087 static int do_pwmd_save(pwm_t
*pwm
, gpg_error_t
*error
, int nb
)
1089 char *result
= NULL
;
1090 char *password
= NULL
;
1093 *error
= GPG_ERR_INV_ARG
;
1097 if (pwm
->use_pinentry
|| pwm
->passfunc
) {
1098 *error
= pwmd_command(pwm
, &result
, "ISCACHED %s", pwm
->filename
);
1100 if (*error
== EPWMD_CACHE_NOT_FOUND
) {
1102 if (pwm
->use_pinentry
) {
1106 pwmd_nb_status_t pw
;
1108 if (pipe(p
) == -1) {
1109 *error
= gpg_error_from_syserror();
1118 strncpy(pw
.filename
, pwm
->filename
, sizeof(pw
.filename
));
1119 pw
.filename
[sizeof(pw
.filename
)-1] = 0;
1124 *error
= do_save_getpin(pwm
, &password
);
1125 } while (*error
== EPWMD_BADKEY
);
1129 pinentry_disconnect(pwm
);
1132 write(p
[1], &pw
, sizeof(pw
));
1137 *error
= do_save_command(pwm
, password
);
1138 pinentry_disconnect(pwm
);
1140 write(p
[1], &pw
, sizeof(pw
));
1145 *error
= gpg_error_from_syserror();
1157 *error
= do_save_getpin(pwm
, &password
);
1165 password
= (*pwm
->passfunc
)(pwm
, pwm
->passdata
);
1176 password
= pwm
->password
;
1178 *error
= do_save_command(pwm
, password
);
1180 if (password
&& password
!= pwm
->password
)
1184 return *error
? -1 : -2;
1186 return *error
? 1 : 0;
1189 int pwmd_save_nb(pwm_t
*pwm
, gpg_error_t
*error
)
1191 #ifndef USE_PINENTRY
1192 *error
= GPG_ERR_NOT_IMPLEMENTED
;
1195 return do_pwmd_save(pwm
, error
, 1);
1199 gpg_error_t
pwmd_save(pwm_t
*pwm
)
1203 do_pwmd_save(pwm
, &error
, 0);
1207 gpg_error_t
pwmd_setopt(pwm_t
*pwm
, pwmd_option_t opt
, ...)
1211 int n
= va_arg(ap
, int);
1215 gpg_error_t error
= 0;
1218 return GPG_ERR_INV_ARG
;
1223 case PWMD_OPTION_STATUS_FUNC
:
1224 pwm
->status_func
= va_arg(ap
, pwmd_status_fn
);
1226 case PWMD_OPTION_STATUS_DATA
:
1227 pwm
->status_data
= va_arg(ap
, void *);
1229 case PWMD_OPTION_PASSWORD_FUNC
:
1230 pwm
->passfunc
= va_arg(ap
, pwmd_password_fn
);
1232 case PWMD_OPTION_PASSWORD_DATA
:
1233 pwm
->passdata
= va_arg(ap
, void *);
1235 case PWMD_OPTION_PASSWORD
:
1236 arg1
= va_arg(ap
, char *);
1239 xfree(pwm
->password
);
1241 pwm
->password
= xstrdup(arg1
);
1244 case PWMD_OPTION_PINENTRY
:
1245 n
= va_arg(ap
, int);
1247 if (n
!= 0 && n
!= 1) {
1249 error
= GPG_ERR_INV_VALUE
;
1252 pwm
->use_pinentry
= n
;
1253 error
= pwmd_command(pwm
, &result
, "OPTION PINENTRY=%i",
1254 !pwm
->use_pinentry
);
1257 case PWMD_OPTION_PINENTRY_TRIES
:
1258 n
= va_arg(ap
, int);
1262 error
= GPG_ERR_INV_VALUE
;
1265 pwm
->pinentry_tries
= n
;
1267 case PWMD_OPTION_PINENTRY_PATH
:
1268 if (pwm
->pinentry_path
)
1269 xfree(pwm
->pinentry_path
);
1271 pwm
->pinentry_path
= xstrdup(va_arg(ap
, char *));
1273 case PWMD_OPTION_PINENTRY_TTY
:
1274 if (pwm
->pinentry_tty
)
1275 xfree(pwm
->pinentry_tty
);
1277 pwm
->pinentry_tty
= xstrdup(va_arg(ap
, char *));
1279 case PWMD_OPTION_PINENTRY_DISPLAY
:
1280 if (pwm
->pinentry_display
)
1281 xfree(pwm
->pinentry_display
);
1283 pwm
->pinentry_display
= xstrdup(va_arg(ap
, char *));
1285 case PWMD_OPTION_PINENTRY_TERM
:
1286 if (pwm
->pinentry_term
)
1287 xfree(pwm
->pinentry_term
);
1289 pwm
->pinentry_term
= xstrdup(va_arg(ap
, char *));
1291 case PWMD_OPTION_PINENTRY_TITLE
:
1294 pwm
->title
= percent_escape(va_arg(ap
, char *));
1296 case PWMD_OPTION_PINENTRY_PROMPT
:
1299 pwm
->prompt
= percent_escape(va_arg(ap
, char *));
1301 case PWMD_OPTION_PINENTRY_DESC
:
1304 pwm
->desc
= percent_escape(va_arg(ap
, char *));
1307 case PWMD_OPTION_PINENTRY
:
1308 case PWMD_OPTION_PINENTRY_TRIES
:
1309 case PWMD_OPTION_PINENTRY_PATH
:
1310 case PWMD_OPTION_PINENTRY_TTY
:
1311 case PWMD_OPTION_PINENTRY_DISPLAY
:
1312 case PWMD_OPTION_PINENTRY_TERM
:
1313 case PWMD_OPTION_PINENTRY_TITLE
:
1314 case PWMD_OPTION_PINENTRY_PROMPT
:
1315 case PWMD_OPTION_PINENTRY_DESC
:
1316 error
= GPG_ERR_NOT_IMPLEMENTED
;
1320 error
= GPG_ERR_NOT_IMPLEMENTED
;
1328 gpg_error_t
pwmd_assuan_ctx(pwm_t
*pwm
, assuan_context_t
*ctx
, int *fd
)
1331 return GPG_ERR_INV_ARG
;