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 if (!pwm
|| pwm
->fd
< 0)
260 return GPG_ERR_INV_ARG
;
262 pwm
->state
= ASYNC_INIT
;
266 static gpg_error_t
do_nb_command(pwm_t
*pwm
, const char *cmd
, const char *arg
)
270 size_t len
= strlen(cmd
) + 2;
272 len
+= arg
? strlen(arg
) : 0;
274 if (pwm
->state
!= ASYNC_INIT
)
275 return GPG_ERR_UNEXPECTED
;
277 buf
= (char *)xmalloc(len
);
280 rc
= gpg_error_from_errno(ENOMEM
);
284 snprintf(buf
, len
, "%s %s", cmd
, arg
? arg
: "");
285 rc
= assuan_write_line(pwm
->ctx
, buf
);
289 pwm
->state
= ASYNC_PROCESS
;
295 gpg_error_t
pwmd_open_async(pwm_t
*pwm
, const char *filename
)
297 if (!pwm
|| !filename
)
298 return GPG_ERR_INV_ARG
;
300 return do_nb_command(pwm
, "OPEN", filename
);
303 gpg_error_t
pwmd_save_async(pwm_t
*pwm
)
306 return GPG_ERR_INV_ARG
;
308 return do_nb_command(pwm
, "SAVE", NULL
);
311 static gpg_error_t
parse_assuan_line(pwm_t
*pwm
)
318 rc
= assuan_read_line(pwm
->ctx
, &line
, &len
);
321 if (line
[0] == 'O' && line
[1] == 'K' &&
322 (line
[2] == 0 || line
[2] == ' ')) {
323 pwm
->state
= ASYNC_DONE
;
325 else if (line
[0] == '#') {
327 else if (line
[0] == 'S' && (line
[1] == 0 || line
[1] == ' ')) {
328 if (pwm
->status_func
) {
329 pwm
->status_func(pwm
->status_data
,
330 line
[1] == 0 ? line
+1 : line
+2);
335 else if (line
[0] == 'E' && line
[1] == 'R' && line
[2] == 'R' &&
336 (line
[3] == 0 || line
[3] == ' ')) {
339 pwm
->state
= ASYNC_DONE
;
346 pwmd_async_t
pwmd_process(pwm_t
*pwm
, gpg_error_t
*rc
)
350 struct timeval tv
= {0, 0};
354 if (!pwm
|| pwm
->fd
< 0) {
355 *rc
= GPG_ERR_INV_ARG
;
358 else if (pwm
->state
== ASYNC_DONE
)
360 else if (pwm
->state
== ASYNC_INIT
) {
361 *rc
= GPG_ERR_UNEXPECTED
;
366 FD_SET(pwm
->fd
, &rfds
);
367 n
= select(pwm
->fd
+1, &rfds
, NULL
, NULL
, &tv
);
370 if (FD_ISSET(pwm
->fd
, &rfds
))
371 *rc
= parse_assuan_line(pwm
);
377 static gpg_error_t
assuan_command(pwm_t
*pwm
, assuan_context_t ctx
,
378 char **result
, const char *cmd
)
386 rc
= assuan_transact(ctx
, cmd
, mem_realloc_cb
, &data
, _inquire_cb
, pwm
,
387 pwm
->status_func
, pwm
->status_data
);
397 mem_realloc_cb(&data
, "", 1);
398 *result
= (char *)data
.buf
;
402 return gpg_err_code(rc
);
405 gpg_error_t
pwmd_inquire(pwm_t
*pwm
, const char *cmd
, pwmd_inquire_fn fn
,
408 if (!pwm
|| !cmd
|| !fn
)
409 return GPG_ERR_INV_ARG
;
411 pwm
->inquire_func
= fn
;
412 pwm
->inquire_data
= data
;
413 return assuan_command(pwm
, pwm
->ctx
, NULL
, cmd
);
416 gpg_error_t
pwmd_terminate_pinentry(pwm_t
*pwm
)
419 return GPG_ERR_NOT_IMPLEMENTED
;
421 if (!pwm
|| pwm
->pid
== -1)
422 return GPG_ERR_INV_ARG
;
424 if (kill(pwm
->pid
, 0) == 0) {
425 if (kill(pwm
->pid
, SIGTERM
) == -1) {
426 if (kill(pwm
->pid
, SIGKILL
) == -1)
427 return gpg_error_from_errno(errno
);
430 pwm
->pin_error
= GPG_ERR_TIMEOUT
;
433 return gpg_error_from_errno(errno
);
440 static gpg_error_t
set_pinentry_strings(pwm_t
*pwm
, int which
)
443 char tmp
[ASSUAN_LINELENGTH
];
447 pwm
->title
= xstrdup(N_("LibPWMD"));
450 pwm
->prompt
= xstrdup(N_("Password:"));
452 if (!pwm
->desc
&& !which
)
453 pwm
->desc
= xstrdup(N_("Enter a password."));
456 snprintf(tmp
, sizeof(tmp
), "SETERROR %s", N_("Invalid password, please try again."));
459 else if (which
== 2) {
460 snprintf(tmp
, sizeof(tmp
), "SETERROR %s", N_("Please type the password again for confirmation."));
464 buf
= (char *)xmalloc(strlen("SETERROR ") + strlen(pwm
->desc
) + 1);
465 sprintf(buf
, "SETERROR %s", pwm
->desc
);
468 error
= pinentry_command(pwm
, NULL
, buf
);
474 buf
= (char *)xmalloc(strlen("SETPROMPT ") + strlen(pwm
->prompt
) + 1);
475 sprintf(buf
, "SETPROMPT %s", pwm
->prompt
);
476 error
= pinentry_command(pwm
, NULL
, buf
);
482 buf
= (char *)xmalloc(strlen("SETDESC ") + strlen(pwm
->title
) + 1);
483 sprintf(buf
, "SETDESC %s", pwm
->title
);
484 error
= pinentry_command(pwm
, NULL
, buf
);
489 static void update_pinentry_settings(pwm_t
*pwm
)
493 struct passwd
*pw
= getpwuid(getuid());
496 snprintf(buf
, sizeof(buf
), "%s/.pwmd/pinentry.conf", pw
->pw_dir
);
498 if ((fp
= fopen(buf
, "r")) == NULL
)
501 while ((p
= fgets(buf
, sizeof(buf
), fp
)) != NULL
) {
502 char name
[32], val
[256];
504 if (sscanf(p
, " %31[a-zA-Z] = %255s", name
, val
) != 2)
507 if (strcasecmp(name
, "TTYNAME") == 0) {
508 xfree(pwm
->pinentry_tty
);
509 pwm
->pinentry_tty
= xstrdup(val
);
511 else if (strcasecmp(name
, "TTYTYPE") == 0) {
512 xfree(pwm
->pinentry_term
);
513 pwm
->pinentry_term
= xstrdup(val
);
515 else if (strcasecmp(name
, "DISPLAY") == 0) {
516 xfree(pwm
->pinentry_display
);
517 pwm
->pinentry_display
= xstrdup(val
);
519 else if (strcasecmp(name
, "PATH") == 0) {
520 xfree(pwm
->pinentry_path
);
521 pwm
->pinentry_path
= xstrdup(val
);
528 static gpg_error_t
launch_pinentry(pwm_t
*pwm
)
531 assuan_context_t ctx
;
532 int child_list
[] = {-1};
533 char *display
= getenv("DISPLAY");
535 int have_display
= 0;
538 update_pinentry_settings(pwm
);
540 if (pwm
->pinentry_display
|| display
)
543 tty
= pwm
->pinentry_tty
? pwm
->pinentry_tty
: ttyname(STDOUT_FILENO
);
546 return gpg_error_from_errno(errno
);
549 if (!have_display
&& !tty
)
550 return GPG_ERR_ENOTTY
;
552 argv
[0] = "pinentry";
553 argv
[1] = have_display
? "--display" : "--ttyname";
554 argv
[2] = have_display
? pwm
->pinentry_display
? pwm
->pinentry_display
: display
: tty
;
558 argv
[3] = "--ttytype";
559 argv
[4] = pwm
->pinentry_term
? pwm
->pinentry_term
: getenv("TERM");
563 rc
= assuan_pipe_connect(&ctx
, pwm
->pinentry_path
? pwm
->pinentry_path
: PINENTRY_PATH
, argv
, child_list
);
568 pwm
->pid
= assuan_get_pid(ctx
);
570 return set_pinentry_strings(pwm
, 0);
573 static gpg_error_t
pinentry_command(pwm_t
*pwm
, char **result
, const char *cmd
)
578 n
= launch_pinentry(pwm
);
584 return assuan_command(pwm
, pwm
->pctx
, result
, cmd
);
587 static void pinentry_disconnect(pwm_t
*pwm
)
590 assuan_disconnect(pwm
->pctx
);
597 * Only called from a child process.
599 static void catchsig(int sig
)
603 if (gelapsed
++ >= gtimeout
) {
604 global_error
= pwmd_terminate_pinentry(gpwm
);
607 global_error
= GPG_ERR_TIMEOUT
;
619 static char *percent_escape(const char *atext
)
621 const unsigned char *s
;
622 int len
= strlen(atext
) * 3 + 1;
623 char *buf
= (char *)xmalloc(len
), *p
= buf
;
628 for (s
=(const unsigned char *)atext
; *s
; s
++) {
630 sprintf (p
, "%%%02X", *s
);
642 static gpg_error_t
send_command(pwm_t
*pwm
, char **result
, const char *cmd
)
645 return GPG_ERR_INV_ARG
;
647 return assuan_command(pwm
, pwm
->ctx
, result
, cmd
);
651 * Avoid sending the BYE command here. libassuan will close the file
652 * descriptor and release the assuan context. Use pwmd_close() instead.
654 gpg_error_t
pwmd_command(pwm_t
*pwm
, char **result
, const char *cmd
, ...)
662 return GPG_ERR_INV_ARG
;
669 len
= vsnprintf(NULL
, 0, cmd
, ap
);
670 buf
= (char *)xmalloc(len
+ 1);
671 len
= vsnprintf(buf
, len
+ 1, cmd
, ap
);
673 error
= send_command(pwm
, result
, buf
);
679 static gpg_error_t
do_getpin(pwm_t
*pwm
, char **result
)
682 signal(SIGALRM
, catchsig
);
687 return pinentry_command(pwm
, result
, "GETPIN");
690 static gpg_error_t
getpin(pwm_t
*pwm
, char **result
, int *try_n
, int which
)
692 int pin_try
= *try_n
;
699 error
= set_pinentry_strings(pwm
, which
);
702 pinentry_disconnect(pwm
);
707 if (pwm
->pinentry_tries
-1 != pin_try
) {
708 error
= set_pinentry_strings(pwm
, 1);
711 pinentry_disconnect(pwm
);
717 error
= do_getpin(pwm
, result
);
720 * Since there was input cancel any timeout.
725 if (error
== GPG_ERR_ASS_CANCELED
|| error
== ASSUAN_Canceled
)
726 return GPG_ERR_ASS_CANCELED
;
728 if (pin_try
!= -1 && pin_try
--)
732 pinentry_disconnect(pwm
);
742 gpg_error_t
pwmd_open_nb_finalize(pwm_t
*pwm
, pwmd_nb_status_t
*pw
)
748 return GPG_ERR_NOT_IMPLEMENTED
;
751 if (!pwm
|| !pw
|| !pw
->filename
[0])
752 return GPG_ERR_INV_ARG
;
761 error
= pwmd_command(pwm
, &result
, "ISCACHED %s", pw
->filename
);
767 xfree(pwm
->filename
);
769 pwm
->filename
= xstrdup(pw
->filename
);
770 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
774 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
778 static gpg_error_t
do_open_command(pwm_t
*pwm
, const char *filename
, char *password
)
780 char buf
[ASSUAN_LINELENGTH
];
784 snprintf(buf
, sizeof(buf
), "OPEN %s %s", filename
, password
? password
: "");
785 error
= send_command(pwm
, &result
, buf
);
786 memset(buf
, 0, sizeof(buf
));
794 static int do_pwmd_open(pwm_t
*pwm
, gpg_error_t
*error
, const char *filename
,
798 char *password
= NULL
;
804 if (!pwm
|| !filename
|| !*filename
) {
805 *error
= GPG_ERR_INV_ARG
;
810 pin_try
= pwm
->pinentry_tries
- 1;
814 * Avoid calling pinentry if the password is cached on the server or if
815 * this is a new file.
817 *error
= pwmd_command(pwm
, &result
, "GETCONFIG data_directory");
822 snprintf(path
, sizeof(path
), "%s/%s", result
, filename
);
823 pwmd_free_result(result
);
825 if (access(path
, R_OK
) == -1) {
829 *error
= gpg_error_from_errno(errno
);
833 *error
= pwmd_command(pwm
, &result
, "ISCACHED %s", filename
);
835 if (*error
== EPWMD_CACHE_NOT_FOUND
) {
837 password
= pwm
->passfunc(pwm
, pwm
->passdata
);
841 if (*error
== EPWMD_CACHE_NOT_FOUND
) {
844 * Get the password from pinentry.
846 if (pwm
->use_pinentry
) {
848 * Nonblocking is wanted. fork() then return a file descriptor
849 * that the client can use to read() from.
857 *error
= gpg_error_from_syserror();
866 strncpy(pw
.filename
, filename
, sizeof(pw
.filename
));
867 pw
.filename
[sizeof(pw
.filename
)-1] = 0;
877 *error
= getpin(pwm
, &password
, &pin_try
, 0);
882 pinentry_disconnect(pwm
);
884 if (gtimeout
&& gelapsed
>= gtimeout
)
885 *error
= GPG_ERR_TIMEOUT
;
888 write(p
[1], &pw
, sizeof(pw
));
894 * Don't count the time it takes to open the file
895 * which may have many iterations.
897 signal(SIGALRM
, SIG_DFL
);
898 *error
= do_open_command(pwm
, filename
, password
);
901 signal(SIGALRM
, catchsig
);
903 if (pwm
->pctx
&& *error
== EPWMD_BADKEY
) {
905 goto getpin_nb_again
;
910 pinentry_disconnect(pwm
);
912 write(p
[1], &pw
, sizeof(pw
));
917 *error
= gpg_error_from_syserror();
930 *error
= getpin(pwm
, &password
, &pin_try
, 1);
934 pinentry_disconnect(pwm
);
936 if (pwm
->pin_error
) {
937 *error
= pwm
->pin_error
;
947 * Not using pinentry and the file was not found
951 if (pwm
->password
== NULL
) {
957 password
= pwm
->password
;
967 *error
= do_open_command(pwm
, filename
, password
);
970 * Keep the user defined password set with pwmd_setopt(). The password may
971 * be needed later (pwmd_save()) depending on the pwmd file cache settings.
973 if (password
&& password
!= pwm
->password
)
977 if (pwm
->pctx
&& *error
== EPWMD_BADKEY
) {
981 pinentry_disconnect(pwm
);
985 pinentry_disconnect(pwm
);
990 xfree(pwm
->filename
);
992 pwm
->filename
= xstrdup(filename
);
996 * The file is cached or the file is a new file.
999 return *error
? -1 : -2;
1001 return *error
? 1 : 0;
1004 gpg_error_t
pwmd_open(pwm_t
*pwm
, const char *filename
)
1008 do_pwmd_open(pwm
, &error
, filename
, 0, 0);
1012 int pwmd_open_nb(pwm_t
*pwm
, gpg_error_t
*error
, const char *filename
,
1015 #ifndef USE_PINENTRY
1016 *error
= GPG_ERR_NOT_IMPLEMENTED
;
1019 return do_pwmd_open(pwm
, error
, filename
, 1, timeout
);
1024 static gpg_error_t
do_save_getpin(pwm_t
*pwm
, char **password
)
1028 char *result
= NULL
;
1032 error
= getpin(pwm
, &result
, &pin_try
, confirm
? 2 : 0);
1036 pinentry_disconnect(pwm
);
1049 if (strcmp(*password
, result
)) {
1052 pinentry_disconnect(pwm
);
1053 error
= EPWMD_BADKEY
;
1058 pinentry_disconnect(pwm
);
1063 static gpg_error_t
do_save_command(pwm_t
*pwm
, char *password
)
1065 char buf
[ASSUAN_LINELENGTH
];
1067 char *result
= NULL
;
1069 snprintf(buf
, sizeof(buf
), "SAVE %s", password
? password
: "");
1070 error
= send_command(pwm
, &result
, buf
);
1071 memset(&buf
, 0, sizeof(buf
));
1073 if (error
&& result
)
1079 gpg_error_t
pwmd_save_nb_finalize(pwm_t
*pwm
, pwmd_nb_status_t
*pw
)
1083 #ifndef USE_PINENTRY
1084 return GPG_ERR_NOT_IMPLEMENTED
;
1087 if (!pwm
|| !pw
|| !pw
->filename
[0])
1088 return GPG_ERR_INV_ARG
;
1094 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
1098 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
1102 static int do_pwmd_save(pwm_t
*pwm
, gpg_error_t
*error
, int nb
)
1104 char *result
= NULL
;
1105 char *password
= NULL
;
1108 *error
= GPG_ERR_INV_ARG
;
1112 if (pwm
->use_pinentry
|| pwm
->passfunc
) {
1113 *error
= pwmd_command(pwm
, &result
, "ISCACHED %s", pwm
->filename
);
1115 if (*error
== EPWMD_CACHE_NOT_FOUND
) {
1117 if (pwm
->use_pinentry
) {
1121 pwmd_nb_status_t pw
;
1123 if (pipe(p
) == -1) {
1124 *error
= gpg_error_from_syserror();
1133 strncpy(pw
.filename
, pwm
->filename
, sizeof(pw
.filename
));
1134 pw
.filename
[sizeof(pw
.filename
)-1] = 0;
1139 *error
= do_save_getpin(pwm
, &password
);
1140 } while (*error
== EPWMD_BADKEY
);
1144 pinentry_disconnect(pwm
);
1147 write(p
[1], &pw
, sizeof(pw
));
1152 *error
= do_save_command(pwm
, password
);
1153 pinentry_disconnect(pwm
);
1155 write(p
[1], &pw
, sizeof(pw
));
1160 *error
= gpg_error_from_syserror();
1172 *error
= do_save_getpin(pwm
, &password
);
1180 password
= (*pwm
->passfunc
)(pwm
, pwm
->passdata
);
1191 password
= pwm
->password
;
1193 *error
= do_save_command(pwm
, password
);
1195 if (password
&& password
!= pwm
->password
)
1199 return *error
? -1 : -2;
1201 return *error
? 1 : 0;
1204 int pwmd_save_nb(pwm_t
*pwm
, gpg_error_t
*error
)
1206 #ifndef USE_PINENTRY
1207 *error
= GPG_ERR_NOT_IMPLEMENTED
;
1210 return do_pwmd_save(pwm
, error
, 1);
1214 gpg_error_t
pwmd_save(pwm_t
*pwm
)
1218 do_pwmd_save(pwm
, &error
, 0);
1222 gpg_error_t
pwmd_setopt(pwm_t
*pwm
, pwmd_option_t opt
, ...)
1226 int n
= va_arg(ap
, int);
1230 gpg_error_t error
= 0;
1233 return GPG_ERR_INV_ARG
;
1238 case PWMD_OPTION_STATUS_FUNC
:
1239 pwm
->status_func
= va_arg(ap
, pwmd_status_fn
);
1241 case PWMD_OPTION_STATUS_DATA
:
1242 pwm
->status_data
= va_arg(ap
, void *);
1244 case PWMD_OPTION_PASSWORD_FUNC
:
1245 pwm
->passfunc
= va_arg(ap
, pwmd_password_fn
);
1247 case PWMD_OPTION_PASSWORD_DATA
:
1248 pwm
->passdata
= va_arg(ap
, void *);
1250 case PWMD_OPTION_PASSWORD
:
1251 arg1
= va_arg(ap
, char *);
1254 xfree(pwm
->password
);
1256 pwm
->password
= xstrdup(arg1
);
1259 case PWMD_OPTION_PINENTRY
:
1260 n
= va_arg(ap
, int);
1262 if (n
!= 0 && n
!= 1) {
1264 error
= GPG_ERR_INV_VALUE
;
1267 pwm
->use_pinentry
= n
;
1268 error
= pwmd_command(pwm
, &result
, "OPTION PINENTRY=%i",
1269 !pwm
->use_pinentry
);
1272 case PWMD_OPTION_PINENTRY_TRIES
:
1273 n
= va_arg(ap
, int);
1277 error
= GPG_ERR_INV_VALUE
;
1280 pwm
->pinentry_tries
= n
;
1282 case PWMD_OPTION_PINENTRY_PATH
:
1283 if (pwm
->pinentry_path
)
1284 xfree(pwm
->pinentry_path
);
1286 pwm
->pinentry_path
= xstrdup(va_arg(ap
, char *));
1288 case PWMD_OPTION_PINENTRY_TTY
:
1289 if (pwm
->pinentry_tty
)
1290 xfree(pwm
->pinentry_tty
);
1292 pwm
->pinentry_tty
= xstrdup(va_arg(ap
, char *));
1294 case PWMD_OPTION_PINENTRY_DISPLAY
:
1295 if (pwm
->pinentry_display
)
1296 xfree(pwm
->pinentry_display
);
1298 pwm
->pinentry_display
= xstrdup(va_arg(ap
, char *));
1300 case PWMD_OPTION_PINENTRY_TERM
:
1301 if (pwm
->pinentry_term
)
1302 xfree(pwm
->pinentry_term
);
1304 pwm
->pinentry_term
= xstrdup(va_arg(ap
, char *));
1306 case PWMD_OPTION_PINENTRY_TITLE
:
1309 pwm
->title
= percent_escape(va_arg(ap
, char *));
1311 case PWMD_OPTION_PINENTRY_PROMPT
:
1314 pwm
->prompt
= percent_escape(va_arg(ap
, char *));
1316 case PWMD_OPTION_PINENTRY_DESC
:
1319 pwm
->desc
= percent_escape(va_arg(ap
, char *));
1322 case PWMD_OPTION_PINENTRY
:
1323 case PWMD_OPTION_PINENTRY_TRIES
:
1324 case PWMD_OPTION_PINENTRY_PATH
:
1325 case PWMD_OPTION_PINENTRY_TTY
:
1326 case PWMD_OPTION_PINENTRY_DISPLAY
:
1327 case PWMD_OPTION_PINENTRY_TERM
:
1328 case PWMD_OPTION_PINENTRY_TITLE
:
1329 case PWMD_OPTION_PINENTRY_PROMPT
:
1330 case PWMD_OPTION_PINENTRY_DESC
:
1331 error
= GPG_ERR_NOT_IMPLEMENTED
;
1335 error
= GPG_ERR_NOT_IMPLEMENTED
;