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 void pwmd_close(pwm_t
*pwm
)
167 assuan_disconnect(pwm
->ctx
);
170 xfree(pwm
->password
);
181 if (pwm
->pinentry_tty
)
182 xfree(pwm
->pinentry_tty
);
184 if (pwm
->pinentry_display
)
185 xfree(pwm
->pinentry_display
);
187 if (pwm
->pinentry_term
)
188 xfree(pwm
->pinentry_term
);
191 xfree(pwm
->filename
);
196 static int mem_realloc_cb(void *data
, const void *buffer
, size_t len
)
198 membuf_t
*mem
= (membuf_t
*)data
;
204 if ((p
= xrealloc(mem
->buf
, mem
->len
+ len
)) == NULL
)
208 memcpy((char *)mem
->buf
+ mem
->len
, buffer
, len
);
213 void pwmd_free_result(void *data
)
218 static int _inquire_cb(void *data
, const char *keyword
)
220 pwm_t
*pwm
= (pwm_t
*)data
;
223 /* Shouldn't get this far without a callback. */
224 if (!pwm
->inquire_func
)
225 return GPG_ERR_INV_ARG
;
232 rc
= pwm
->inquire_func(pwm
->inquire_data
, keyword
, rc
, &result
, &len
);
233 rc
= gpg_err_code(rc
);
235 if (rc
== GPG_ERR_EOF
|| !rc
) {
236 if (len
<= 0 || !result
|| !*result
) {
241 arc
= assuan_send_data(pwm
->ctx
, result
, len
);
243 if (rc
== GPG_ERR_EOF
) {
257 gpg_error_t
pwmd_finalize(pwm_t
*pwm
)
259 pwm
->state
= ASYNC_INIT
;
263 gpg_error_t
do_nb_command(pwm_t
*pwm
, const char *cmd
, const char *arg
)
268 if (pwm
->state
!= ASYNC_INIT
)
269 return GPG_ERR_UNEXPECTED
;
271 if (asprintf(&buf
, "%s %s", cmd
, arg
? arg
: "") == -1) {
272 rc
= gpg_error_from_errno(ENOMEM
);
276 rc
= assuan_write_line(pwm
->ctx
, buf
);
280 pwm
->state
= ASYNC_PROCESS
;
286 gpg_error_t
pwmd_open_async(pwm_t
*pwm
, const char *filename
)
288 if (!pwm
|| !filename
)
289 return GPG_ERR_INV_ARG
;
291 return do_nb_command(pwm
, "OPEN", filename
);
294 gpg_error_t
pwmd_save_async(pwm_t
*pwm
)
297 return GPG_ERR_INV_ARG
;
299 return do_nb_command(pwm
, "SAVE", NULL
);
302 static gpg_error_t
parse_assuan_line(pwm_t
*pwm
)
309 rc
= assuan_read_line(pwm
->ctx
, &line
, &len
);
312 if (line
[0] == 'O' && line
[1] == 'K' &&
313 (line
[2] == 0 || line
[2] == ' ')) {
314 pwm
->state
= ASYNC_DONE
;
316 else if (line
[0] == '#') {
318 else if (line
[0] == 'S' && (line
[1] == 0 || line
[1] == ' ')) {
319 if (pwm
->status_func
) {
320 pwm
->status_func(pwm
->status_data
,
321 line
[1] == 0 ? line
+1 : line
+2);
326 else if (line
[0] == 'E' && line
[1] == 'R' && line
[2] == 'R' &&
327 (line
[3] == 0 || line
[3] == ' ')) {
330 pwm
->state
= ASYNC_DONE
;
337 pwmd_async_t
pwmd_process(pwm_t
*pwm
, gpg_error_t
*rc
)
341 struct timeval tv
= {0, 0};
345 if (!pwm
|| pwm
->fd
< 0) {
346 *rc
= GPG_ERR_INV_ARG
;
349 else if (pwm
->state
== ASYNC_DONE
)
351 else if (pwm
->state
== ASYNC_INIT
) {
352 *rc
= GPG_ERR_UNEXPECTED
;
357 FD_SET(pwm
->fd
, &rfds
);
358 n
= select(pwm
->fd
+1, &rfds
, NULL
, NULL
, &tv
);
361 if (FD_ISSET(pwm
->fd
, &rfds
))
362 *rc
= parse_assuan_line(pwm
);
368 static gpg_error_t
assuan_command(pwm_t
*pwm
, assuan_context_t ctx
,
369 char **result
, const char *cmd
)
377 rc
= assuan_transact(ctx
, cmd
, mem_realloc_cb
, &data
, _inquire_cb
, pwm
,
378 pwm
->status_func
, pwm
->status_data
);
388 mem_realloc_cb(&data
, "", 1);
389 *result
= (char *)data
.buf
;
393 return gpg_err_code(rc
);
396 gpg_error_t
pwmd_inquire(pwm_t
*pwm
, const char *cmd
, pwmd_inquire_fn fn
,
399 if (!pwm
|| !cmd
|| !fn
)
400 return GPG_ERR_INV_ARG
;
402 pwm
->inquire_func
= fn
;
403 pwm
->inquire_data
= data
;
404 return assuan_command(pwm
, pwm
->ctx
, NULL
, cmd
);
407 gpg_error_t
pwmd_terminate_pinentry(pwm_t
*pwm
)
410 return GPG_ERR_NOT_IMPLEMENTED
;
412 if (!pwm
|| pwm
->pid
== -1)
413 return GPG_ERR_INV_ARG
;
415 if (kill(pwm
->pid
, 0) == 0) {
416 if (kill(pwm
->pid
, SIGTERM
) == -1) {
417 if (kill(pwm
->pid
, SIGKILL
) == -1)
418 return gpg_error_from_errno(errno
);
421 pwm
->pin_error
= GPG_ERR_TIMEOUT
;
424 return gpg_error_from_errno(errno
);
431 static gpg_error_t
set_pinentry_strings(pwm_t
*pwm
, int which
)
434 char tmp
[ASSUAN_LINELENGTH
];
438 pwm
->title
= xstrdup(N_("LibPWMD"));
441 pwm
->prompt
= xstrdup(N_("Password:"));
443 if (!pwm
->desc
&& !which
)
444 pwm
->desc
= xstrdup(N_("Enter a password."));
447 snprintf(tmp
, sizeof(tmp
), "SETERROR %s", N_("Invalid password, please try again."));
450 else if (which
== 2) {
451 snprintf(tmp
, sizeof(tmp
), "SETERROR %s", N_("Please type the password again for confirmation."));
455 buf
= (char *)xmalloc(strlen("SETERROR ") + strlen(pwm
->desc
) + 1);
456 sprintf(buf
, "SETERROR %s", pwm
->desc
);
459 error
= pinentry_command(pwm
, NULL
, buf
);
465 buf
= (char *)xmalloc(strlen("SETPROMPT ") + strlen(pwm
->prompt
) + 1);
466 sprintf(buf
, "SETPROMPT %s", pwm
->prompt
);
467 error
= pinentry_command(pwm
, NULL
, buf
);
473 buf
= (char *)xmalloc(strlen("SETDESC ") + strlen(pwm
->title
) + 1);
474 sprintf(buf
, "SETDESC %s", pwm
->title
);
475 error
= pinentry_command(pwm
, NULL
, buf
);
480 static void update_pinentry_settings(pwm_t
*pwm
)
484 struct passwd
*pw
= getpwuid(getuid());
487 snprintf(buf
, sizeof(buf
), "%s/.pwmd/pinentry.conf", pw
->pw_dir
);
489 if ((fp
= fopen(buf
, "r")) == NULL
)
492 while ((p
= fgets(buf
, sizeof(buf
), fp
)) != NULL
) {
493 char name
[32], val
[256];
495 if (sscanf(p
, " %31[a-zA-Z] = %255s", name
, val
) != 2)
498 if (strcasecmp(name
, "TTYNAME") == 0) {
499 xfree(pwm
->pinentry_tty
);
500 pwm
->pinentry_tty
= xstrdup(val
);
502 else if (strcasecmp(name
, "TTYTYPE") == 0) {
503 xfree(pwm
->pinentry_term
);
504 pwm
->pinentry_term
= xstrdup(val
);
506 else if (strcasecmp(name
, "DISPLAY") == 0) {
507 xfree(pwm
->pinentry_display
);
508 pwm
->pinentry_display
= xstrdup(val
);
510 else if (strcasecmp(name
, "PATH") == 0) {
511 xfree(pwm
->pinentry_path
);
512 pwm
->pinentry_path
= xstrdup(val
);
519 static gpg_error_t
launch_pinentry(pwm_t
*pwm
)
522 assuan_context_t ctx
;
523 int child_list
[] = {-1};
524 char *display
= getenv("DISPLAY");
526 int have_display
= 0;
529 update_pinentry_settings(pwm
);
531 if (pwm
->pinentry_display
|| display
)
534 tty
= pwm
->pinentry_tty
? pwm
->pinentry_tty
: ttyname(STDOUT_FILENO
);
537 return gpg_error_from_errno(errno
);
540 if (!have_display
&& !tty
)
541 return GPG_ERR_ENOTTY
;
543 argv
[0] = "pinentry";
544 argv
[1] = have_display
? "--display" : "--ttyname";
545 argv
[2] = have_display
? pwm
->pinentry_display
? pwm
->pinentry_display
: display
: tty
;
549 argv
[3] = "--ttytype";
550 argv
[4] = pwm
->pinentry_term
? pwm
->pinentry_term
: getenv("TERM");
554 rc
= assuan_pipe_connect(&ctx
, pwm
->pinentry_path
? pwm
->pinentry_path
: PINENTRY_PATH
, argv
, child_list
);
559 pwm
->pid
= assuan_get_pid(ctx
);
561 return set_pinentry_strings(pwm
, 0);
564 static gpg_error_t
pinentry_command(pwm_t
*pwm
, char **result
, const char *cmd
)
569 n
= launch_pinentry(pwm
);
575 return assuan_command(pwm
, pwm
->pctx
, result
, cmd
);
578 static void pinentry_disconnect(pwm_t
*pwm
)
581 assuan_disconnect(pwm
->pctx
);
588 * Only called from a child process.
590 static void catchsig(int sig
)
594 if (gelapsed
++ >= gtimeout
) {
595 global_error
= pwmd_terminate_pinentry(gpwm
);
598 global_error
= GPG_ERR_TIMEOUT
;
610 static char *percent_escape(const char *atext
)
612 const unsigned char *s
;
613 int len
= strlen(atext
) * 3 + 1;
614 char *buf
= (char *)xmalloc(len
), *p
= buf
;
619 for (s
=(const unsigned char *)atext
; *s
; s
++) {
621 sprintf (p
, "%%%02X", *s
);
633 static gpg_error_t
send_command(pwm_t
*pwm
, char **result
, const char *cmd
)
636 return GPG_ERR_INV_ARG
;
638 return assuan_command(pwm
, pwm
->ctx
, result
, cmd
);
642 * Avoid sending the BYE command here. libassuan will close the file
643 * descriptor and release the assuan context. Use pwmd_close() instead.
645 gpg_error_t
pwmd_command(pwm_t
*pwm
, char **result
, const char *cmd
, ...)
653 return GPG_ERR_INV_ARG
;
660 len
= vsnprintf(NULL
, 0, cmd
, ap
);
661 buf
= (char *)xmalloc(len
+ 1);
662 len
= vsnprintf(buf
, len
+ 1, cmd
, ap
);
664 error
= send_command(pwm
, result
, buf
);
670 static gpg_error_t
do_getpin(pwm_t
*pwm
, char **result
)
673 signal(SIGALRM
, catchsig
);
678 return pinentry_command(pwm
, result
, "GETPIN");
681 static gpg_error_t
getpin(pwm_t
*pwm
, char **result
, int *try_n
, int which
)
683 int pin_try
= *try_n
;
690 error
= set_pinentry_strings(pwm
, which
);
693 pinentry_disconnect(pwm
);
698 if (pwm
->pinentry_tries
-1 != pin_try
) {
699 error
= set_pinentry_strings(pwm
, 1);
702 pinentry_disconnect(pwm
);
708 error
= do_getpin(pwm
, result
);
711 * Since there was input cancel any timeout.
716 if (error
== GPG_ERR_ASS_CANCELED
|| error
== ASSUAN_Canceled
)
717 return GPG_ERR_ASS_CANCELED
;
719 if (pin_try
!= -1 && pin_try
--)
723 pinentry_disconnect(pwm
);
733 gpg_error_t
pwmd_open_nb_finalize(pwm_t
*pwm
, pwmd_nb_status_t
*pw
)
739 return GPG_ERR_NOT_IMPLEMENTED
;
742 if (!pwm
|| !pw
|| !pw
->filename
[0])
743 return GPG_ERR_INV_ARG
;
752 error
= pwmd_command(pwm
, &result
, "ISCACHED %s", pw
->filename
);
758 xfree(pwm
->filename
);
760 pwm
->filename
= xstrdup(pw
->filename
);
761 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
765 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
769 static gpg_error_t
do_open_command(pwm_t
*pwm
, const char *filename
, char *password
)
771 char buf
[ASSUAN_LINELENGTH
];
775 snprintf(buf
, sizeof(buf
), "OPEN %s %s", filename
, password
? password
: "");
776 error
= send_command(pwm
, &result
, buf
);
777 memset(buf
, 0, sizeof(buf
));
785 static int do_pwmd_open(pwm_t
*pwm
, gpg_error_t
*error
, const char *filename
,
789 char *password
= NULL
;
795 if (!pwm
|| !filename
|| !*filename
) {
796 *error
= GPG_ERR_INV_ARG
;
801 pin_try
= pwm
->pinentry_tries
- 1;
805 * Avoid calling pinentry if the password is cached on the server or if
806 * this is a new file.
808 *error
= pwmd_command(pwm
, &result
, "GETCONFIG data_directory");
813 snprintf(path
, sizeof(path
), "%s/%s", result
, filename
);
814 pwmd_free_result(result
);
816 if (access(path
, R_OK
) == -1) {
820 *error
= gpg_error_from_errno(errno
);
824 *error
= pwmd_command(pwm
, &result
, "ISCACHED %s", filename
);
826 if (*error
== EPWMD_CACHE_NOT_FOUND
) {
828 password
= pwm
->passfunc(pwm
, pwm
->passdata
);
832 if (*error
== EPWMD_CACHE_NOT_FOUND
) {
835 * Get the password from pinentry.
837 if (pwm
->use_pinentry
) {
839 * Nonblocking is wanted. fork() then return a file descriptor
840 * that the client can use to read() from.
848 *error
= gpg_error_from_syserror();
857 strncpy(pw
.filename
, filename
, sizeof(pw
.filename
));
858 pw
.filename
[sizeof(pw
.filename
)-1] = 0;
868 *error
= getpin(pwm
, &password
, &pin_try
, 0);
873 pinentry_disconnect(pwm
);
875 if (gtimeout
&& gelapsed
>= gtimeout
)
876 *error
= GPG_ERR_TIMEOUT
;
879 write(p
[1], &pw
, sizeof(pw
));
885 * Don't count the time it takes to open the file
886 * which may have many iterations.
888 signal(SIGALRM
, SIG_DFL
);
889 *error
= do_open_command(pwm
, filename
, password
);
892 signal(SIGALRM
, catchsig
);
894 if (pwm
->pctx
&& *error
== EPWMD_BADKEY
) {
896 goto getpin_nb_again
;
901 pinentry_disconnect(pwm
);
903 write(p
[1], &pw
, sizeof(pw
));
908 *error
= gpg_error_from_syserror();
921 *error
= getpin(pwm
, &password
, &pin_try
, 1);
925 pinentry_disconnect(pwm
);
927 if (pwm
->pin_error
) {
928 *error
= pwm
->pin_error
;
938 * Not using pinentry and the file was not found
942 if (pwm
->password
== NULL
) {
948 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 (pwm
->pctx
&& *error
== EPWMD_BADKEY
) {
972 pinentry_disconnect(pwm
);
976 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
;
1085 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
1089 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
1093 static int do_pwmd_save(pwm_t
*pwm
, gpg_error_t
*error
, int nb
)
1095 char *result
= NULL
;
1096 char *password
= NULL
;
1099 *error
= GPG_ERR_INV_ARG
;
1103 if (pwm
->use_pinentry
|| pwm
->passfunc
) {
1104 *error
= pwmd_command(pwm
, &result
, "ISCACHED %s", pwm
->filename
);
1106 if (*error
== EPWMD_CACHE_NOT_FOUND
) {
1108 if (pwm
->use_pinentry
) {
1112 pwmd_nb_status_t pw
;
1114 if (pipe(p
) == -1) {
1115 *error
= gpg_error_from_syserror();
1124 strncpy(pw
.filename
, pwm
->filename
, sizeof(pw
.filename
));
1125 pw
.filename
[sizeof(pw
.filename
)-1] = 0;
1130 *error
= do_save_getpin(pwm
, &password
);
1131 } while (*error
== EPWMD_BADKEY
);
1135 pinentry_disconnect(pwm
);
1138 write(p
[1], &pw
, sizeof(pw
));
1143 *error
= do_save_command(pwm
, password
);
1144 pinentry_disconnect(pwm
);
1146 write(p
[1], &pw
, sizeof(pw
));
1151 *error
= gpg_error_from_syserror();
1163 *error
= do_save_getpin(pwm
, &password
);
1171 password
= (*pwm
->passfunc
)(pwm
, pwm
->passdata
);
1182 password
= pwm
->password
;
1184 *error
= do_save_command(pwm
, password
);
1186 if (password
&& password
!= pwm
->password
)
1190 return *error
? -1 : -2;
1192 return *error
? 1 : 0;
1195 int pwmd_save_nb(pwm_t
*pwm
, gpg_error_t
*error
)
1197 #ifndef USE_PINENTRY
1198 *error
= GPG_ERR_NOT_IMPLEMENTED
;
1201 return do_pwmd_save(pwm
, error
, 1);
1205 gpg_error_t
pwmd_save(pwm_t
*pwm
)
1209 do_pwmd_save(pwm
, &error
, 0);
1213 gpg_error_t
pwmd_setopt(pwm_t
*pwm
, pwmd_option_t opt
, ...)
1217 int n
= va_arg(ap
, int);
1221 gpg_error_t error
= 0;
1224 return GPG_ERR_INV_ARG
;
1229 case PWMD_OPTION_STATUS_FUNC
:
1230 pwm
->status_func
= va_arg(ap
, pwmd_status_fn
);
1232 case PWMD_OPTION_STATUS_DATA
:
1233 pwm
->status_data
= va_arg(ap
, void *);
1235 case PWMD_OPTION_PASSWORD_FUNC
:
1236 pwm
->passfunc
= va_arg(ap
, pwmd_password_fn
);
1238 case PWMD_OPTION_PASSWORD_DATA
:
1239 pwm
->passdata
= va_arg(ap
, void *);
1241 case PWMD_OPTION_PASSWORD
:
1242 arg1
= va_arg(ap
, char *);
1245 xfree(pwm
->password
);
1247 pwm
->password
= xstrdup(arg1
);
1250 case PWMD_OPTION_PINENTRY
:
1251 n
= va_arg(ap
, int);
1253 if (n
!= 0 && n
!= 1) {
1255 error
= GPG_ERR_INV_VALUE
;
1258 pwm
->use_pinentry
= n
;
1259 error
= pwmd_command(pwm
, &result
, "OPTION PINENTRY=%i",
1260 !pwm
->use_pinentry
);
1263 case PWMD_OPTION_PINENTRY_TRIES
:
1264 n
= va_arg(ap
, int);
1268 error
= GPG_ERR_INV_VALUE
;
1271 pwm
->pinentry_tries
= n
;
1273 case PWMD_OPTION_PINENTRY_PATH
:
1274 if (pwm
->pinentry_path
)
1275 xfree(pwm
->pinentry_path
);
1277 pwm
->pinentry_path
= xstrdup(va_arg(ap
, char *));
1279 case PWMD_OPTION_PINENTRY_TTY
:
1280 if (pwm
->pinentry_tty
)
1281 xfree(pwm
->pinentry_tty
);
1283 pwm
->pinentry_tty
= xstrdup(va_arg(ap
, char *));
1285 case PWMD_OPTION_PINENTRY_DISPLAY
:
1286 if (pwm
->pinentry_display
)
1287 xfree(pwm
->pinentry_display
);
1289 pwm
->pinentry_display
= xstrdup(va_arg(ap
, char *));
1291 case PWMD_OPTION_PINENTRY_TERM
:
1292 if (pwm
->pinentry_term
)
1293 xfree(pwm
->pinentry_term
);
1295 pwm
->pinentry_term
= xstrdup(va_arg(ap
, char *));
1297 case PWMD_OPTION_PINENTRY_TITLE
:
1300 pwm
->title
= percent_escape(va_arg(ap
, char *));
1302 case PWMD_OPTION_PINENTRY_PROMPT
:
1305 pwm
->prompt
= percent_escape(va_arg(ap
, char *));
1307 case PWMD_OPTION_PINENTRY_DESC
:
1310 pwm
->desc
= percent_escape(va_arg(ap
, char *));
1313 case PWMD_OPTION_PINENTRY
:
1314 case PWMD_OPTION_PINENTRY_TRIES
:
1315 case PWMD_OPTION_PINENTRY_PATH
:
1316 case PWMD_OPTION_PINENTRY_TTY
:
1317 case PWMD_OPTION_PINENTRY_DISPLAY
:
1318 case PWMD_OPTION_PINENTRY_TERM
:
1319 case PWMD_OPTION_PINENTRY_TITLE
:
1320 case PWMD_OPTION_PINENTRY_PROMPT
:
1321 case PWMD_OPTION_PINENTRY_DESC
:
1322 error
= GPG_ERR_NOT_IMPLEMENTED
;
1326 error
= GPG_ERR_NOT_IMPLEMENTED
;