1 /* command.c - gpg-agent command handler
2 * Copyright (C) 2001, 2002, 2003, 2004, 2005,
3 * 2006, 2008, 2009 Free Software Foundation, Inc.
5 * This file is part of GnuPG.
7 * GnuPG is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * GnuPG is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 /* FIXME: we should not use the default assuan buffering but setup
22 some buffering in secure mempory to protect session keys etc. */
33 #include <sys/types.h>
42 /* maximum allowed size of the inquired ciphertext */
43 #define MAXLEN_CIPHERTEXT 4096
44 /* maximum allowed size of the key parameters */
45 #define MAXLEN_KEYPARAM 1024
47 #define set_error(e,t) assuan_set_error (ctx, gpg_error (e), (t))
50 #if MAX_DIGEST_LEN < 20
51 #error MAX_DIGEST_LEN shorter than keygrip
54 /* Data used to associate an Assuan context with local server data */
57 assuan_context_t assuan_ctx
;
59 int use_cache_for_signing
;
60 char *keydesc
; /* Allocated description for the next key
62 int pause_io_logging
; /* Used to suppress I/O logging during a command */
63 #ifdef HAVE_W32_SYSTEM
64 int stopme
; /* If set to true the agent will be terminated after
65 the end of this session. */
67 int allow_pinentry_notify
; /* Set if pinentry notifications should
72 /* An entry for the getval/putval commands. */
75 struct putval_item_s
*next
;
76 size_t off
; /* Offset to the value into DATA. */
77 size_t len
; /* Length of the value. */
78 char d
[1]; /* Key | Nul | value. */
82 /* A list of key value pairs fpr the getval/putval commands. */
83 static struct putval_item_s
*putval_list
;
87 /* To help polling clients, we keep track of the number of certain
88 events. This structure keeps those counters. The counters are
89 integers and there should be no problem if they are overflowing as
90 callers need to check only whether a counter changed. The actual
91 values are not meaningful. */
94 /* Incremented if any of the other counters below changed. */
97 /* Incremented if a key is added or removed from the internal privat
101 /* Incremented if a change of the card readers stati has been
109 /* Local prototypes. */
110 static int command_has_option (const char *cmd
, const char *cmdopt
);
115 /* Release the memory buffer MB but first wipe out the used memory. */
117 clear_outbuf (membuf_t
*mb
)
122 p
= get_membuf (mb
, &n
);
131 /* Write the content of memory buffer MB as assuan data to CTX and
132 wipe the buffer out afterwards. */
134 write_and_clear_outbuf (assuan_context_t ctx
, membuf_t
*mb
)
140 p
= get_membuf (mb
, &n
);
142 return out_of_core ();
143 ae
= assuan_send_data (ctx
, p
, n
);
151 reset_notify (assuan_context_t ctx
)
153 ctrl_t ctrl
= assuan_get_pointer (ctx
);
155 memset (ctrl
->keygrip
, 0, 20);
156 ctrl
->have_keygrip
= 0;
157 ctrl
->digest
.valuelen
= 0;
159 xfree (ctrl
->server_local
->keydesc
);
160 ctrl
->server_local
->keydesc
= NULL
;
164 /* Check whether the option NAME appears in LINE */
166 has_option (const char *line
, const char *name
)
169 int n
= strlen (name
);
171 s
= strstr (line
, name
);
172 return (s
&& (s
== line
|| spacep (s
-1)) && (!s
[n
] || spacep (s
+n
)));
175 /* Same as has_option but does only test for the name of the option
176 and ignores an argument, i.e. with NAME being "--hash" it would
177 return true for "--hash" as well as for "--hash=foo". */
179 has_option_name (const char *line
, const char *name
)
182 int n
= strlen (name
);
184 s
= strstr (line
, name
);
185 return (s
&& (s
== line
|| spacep (s
-1))
186 && (!s
[n
] || spacep (s
+n
) || s
[n
] == '='));
189 /* Return a pointer to the argument of the option with NAME. If such
190 an option is not given, it returns NULL. */
192 option_value (const char *line
, const char *name
)
195 int n
= strlen (name
);
197 s
= strstr (line
, name
);
198 if (s
&& (s
== line
|| spacep (s
-1))
199 && s
[n
] && (spacep (s
+n
) || s
[n
] == '='))
202 s
+= strspn (s
, " ");
203 if (*s
&& !spacep(s
))
210 /* Skip over options. It is assumed that leading spaces have been
211 removed (this is the case for lines passed to a handler from
212 assuan). Blanks after the options are also removed. */
214 skip_options (char *line
)
216 while ( *line
== '-' && line
[1] == '-' )
218 while (*line
&& !spacep (line
))
220 while (spacep (line
))
227 /* Replace all '+' by a blank. */
229 plus_to_blank (char *s
)
239 /* Parse a hex string. Return an Assuan error code or 0 on success and the
240 length of the parsed string in LEN. */
242 parse_hexstring (assuan_context_t ctx
, const char *string
, size_t *len
)
247 /* parse the hash value */
248 for (p
=string
, n
=0; hexdigitp (p
); p
++, n
++)
250 if (*p
!= ' ' && *p
!= '\t' && *p
)
251 return set_error (GPG_ERR_ASS_PARAMETER
, "invalid hexstring");
253 return set_error (GPG_ERR_ASS_PARAMETER
, "odd number of digits");
258 /* Parse the keygrip in STRING into the provided buffer BUF. BUF must
259 provide space for 20 bytes. BUF is not changed if the function
262 parse_keygrip (assuan_context_t ctx
, const char *string
, unsigned char *buf
)
267 rc
= parse_hexstring (ctx
, string
, &n
);
272 return set_error (GPG_ERR_ASS_PARAMETER
, "invalid length of keygrip");
274 if (hex2bin (string
, buf
, 20) < 0)
275 return set_error (GPG_ERR_BUG
, "hex2bin");
281 /* Write an assuan status line. */
283 agent_write_status (ctrl_t ctrl
, const char *keyword
, ...)
288 assuan_context_t ctx
= ctrl
->server_local
->assuan_ctx
;
292 va_start (arg_ptr
, keyword
);
296 while ( (text
= va_arg (arg_ptr
, const char *)) )
303 for ( ; *text
&& n
< DIM (buf
)-3; n
++, text
++)
310 else if (*text
== '\r')
320 err
= assuan_write_status (ctx
, keyword
, buf
);
327 /* Helper to notify the client about a launched Pinentry. Because
328 that might disturb some older clients, this is only done if enabled
329 via an option. Returns an gpg error code. */
331 agent_inq_pinentry_launched (ctrl_t ctrl
, unsigned long pid
)
335 if (!ctrl
|| !ctrl
->server_local
336 || !ctrl
->server_local
->allow_pinentry_notify
)
338 snprintf (line
, DIM(line
)-1, "PINENTRY_LAUNCHED %lu", pid
);
339 return assuan_inquire (ctrl
->server_local
->assuan_ctx
, line
, NULL
, NULL
, 0);
346 Return a a status line named EVENTCOUNTER with the current values
347 of all event counters. The values are decimal numbers in the range
348 0 to UINT_MAX and wrapping around to 0. The actual values should
349 not be relied upon, they shall only be used to detect a change.
351 The currently defined counters are:
353 ANY - Incremented with any change of any of the other counters.
354 KEY - Incremented for added or removed private keys.
355 CARD - Incremented for changes of the card readers stati.
358 cmd_geteventcounter (assuan_context_t ctx
, char *line
)
360 ctrl_t ctrl
= assuan_get_pointer (ctx
);
361 char any_counter
[25];
362 char key_counter
[25];
363 char card_counter
[25];
367 snprintf (any_counter
, sizeof any_counter
, "%u", eventcounter
.any
);
368 snprintf (key_counter
, sizeof key_counter
, "%u", eventcounter
.key
);
369 snprintf (card_counter
, sizeof card_counter
, "%u", eventcounter
.card
);
371 return agent_write_status (ctrl
, "EVENTCOUNTER",
379 /* This function should be called once for all key removals or
380 additions. This function is assured not to do any context
383 bump_key_eventcounter (void)
389 /* This function should be called for all card reader status
390 changes. This function is assured not to do any context
393 bump_card_eventcounter (void)
402 /* ISTRUSTED <hexstring_with_fingerprint>
404 Return OK when we have an entry with this fingerprint in our
407 cmd_istrusted (assuan_context_t ctx
, char *line
)
409 ctrl_t ctrl
= assuan_get_pointer (ctx
);
414 /* Parse the fingerprint value. */
415 for (p
=line
,n
=0; hexdigitp (p
); p
++, n
++)
417 if (*p
|| !(n
== 40 || n
== 32))
418 return set_error (GPG_ERR_ASS_PARAMETER
, "invalid fingerprint");
422 strcpy (fpr
, "00000000");
425 for (p
=line
; i
< 40; p
++, i
++)
426 fpr
[i
] = *p
>= 'a'? (*p
& 0xdf): *p
;
428 rc
= agent_istrusted (ctrl
, fpr
, NULL
);
429 if (!rc
|| gpg_err_code (rc
) == GPG_ERR_NOT_TRUSTED
)
431 else if (rc
== -1 || gpg_err_code (rc
) == GPG_ERR_EOF
)
432 return gpg_error (GPG_ERR_NOT_TRUSTED
);
435 log_error ("command is_trusted failed: %s\n", gpg_strerror (rc
));
442 List all entries from the trustlist */
444 cmd_listtrusted (assuan_context_t ctx
, char *line
)
450 rc
= agent_listtrusted (ctx
);
452 log_error ("command listtrusted failed: %s\n", gpg_strerror (rc
));
457 /* MARKTRUSTED <hexstring_with_fingerprint> <flag> <display_name>
459 Store a new key in into the trustlist*/
461 cmd_marktrusted (assuan_context_t ctx
, char *line
)
463 ctrl_t ctrl
= assuan_get_pointer (ctx
);
469 /* parse the fingerprint value */
470 for (p
=line
,n
=0; hexdigitp (p
); p
++, n
++)
472 if (!spacep (p
) || !(n
== 40 || n
== 32))
473 return set_error (GPG_ERR_ASS_PARAMETER
, "invalid fingerprint");
477 strcpy (fpr
, "00000000");
480 for (p
=line
; i
< 40; p
++, i
++)
481 fpr
[i
] = *p
>= 'a'? (*p
& 0xdf): *p
;
487 if ( (flag
!= 'S' && flag
!= 'P') || !spacep (p
) )
488 return set_error (GPG_ERR_ASS_PARAMETER
, "invalid flag - must be P or S");
492 rc
= agent_marktrusted (ctrl
, p
, fpr
, flag
);
494 log_error ("command marktrusted failed: %s\n", gpg_strerror (rc
));
501 /* HAVEKEY <hexstring_with_keygrip>
503 Return success when the secret key is available */
505 cmd_havekey (assuan_context_t ctx
, char *line
)
508 unsigned char buf
[20];
510 rc
= parse_keygrip (ctx
, line
, buf
);
514 if (agent_key_available (buf
))
515 return gpg_error (GPG_ERR_NO_SECKEY
);
521 /* SIGKEY <hexstring_with_keygrip>
522 SETKEY <hexstring_with_keygrip>
524 Set the key used for a sign or decrypt operation */
526 cmd_sigkey (assuan_context_t ctx
, char *line
)
529 ctrl_t ctrl
= assuan_get_pointer (ctx
);
531 rc
= parse_keygrip (ctx
, line
, ctrl
->keygrip
);
534 ctrl
->have_keygrip
= 1;
539 /* SETKEYDESC plus_percent_escaped_string
541 Set a description to be used for the next PKSIGN or PKDECRYPT
542 operation if this operation requires the entry of a passphrase. If
543 this command is not used a default text will be used. Note, that
544 this description implictly selects the label used for the entry
545 box; if the string contains the string PIN (which in general will
546 not be translated), "PIN" is used, otherwise the translation of
547 "passphrase" is used. The description string should not contain
548 blanks unless they are percent or '+' escaped.
550 The description is only valid for the next PKSIGN or PKDECRYPT
554 cmd_setkeydesc (assuan_context_t ctx
, char *line
)
556 ctrl_t ctrl
= assuan_get_pointer (ctx
);
559 for (p
=line
; *p
== ' '; p
++)
562 p
= strchr (desc
, ' ');
564 *p
= 0; /* We ignore any garbage; we might late use it for other args. */
567 return set_error (GPG_ERR_ASS_PARAMETER
, "no description given");
569 /* Note, that we only need to replace the + characters and should
570 leave the other escaping in place because the escaped string is
571 send verbatim to the pinentry which does the unescaping (but not
573 plus_to_blank (desc
);
575 xfree (ctrl
->server_local
->keydesc
);
576 ctrl
->server_local
->keydesc
= xtrystrdup (desc
);
577 if (!ctrl
->server_local
->keydesc
)
578 return out_of_core ();
583 /* SETHASH --hash=<name>|<algonumber> <hexstring>
585 The client can use this command to tell the server about the data
586 (which usually is a hash) to be signed. */
588 cmd_sethash (assuan_context_t ctx
, char *line
)
593 ctrl_t ctrl
= assuan_get_pointer (ctx
);
598 /* Parse the alternative hash options which may be used instead of
600 if (has_option_name (line
, "--hash"))
602 if (has_option (line
, "--hash=sha1"))
604 else if (has_option (line
, "--hash=sha224"))
605 algo
= GCRY_MD_SHA224
;
606 else if (has_option (line
, "--hash=sha256"))
607 algo
= GCRY_MD_SHA256
;
608 else if (has_option (line
, "--hash=sha384"))
609 algo
= GCRY_MD_SHA384
;
610 else if (has_option (line
, "--hash=sha512"))
611 algo
= GCRY_MD_SHA512
;
612 else if (has_option (line
, "--hash=rmd160"))
613 algo
= GCRY_MD_RMD160
;
614 else if (has_option (line
, "--hash=md5"))
616 else if (has_option (line
, "--hash=tls-md5sha1"))
617 algo
= MD_USER_TLS_MD5SHA1
;
619 return set_error (GPG_ERR_ASS_PARAMETER
, "invalid hash algorithm");
624 line
= skip_options (line
);
628 /* No hash option has been given: require an algo number instead */
629 algo
= (int)strtoul (line
, &endp
, 10);
630 for (line
= endp
; *line
== ' ' || *line
== '\t'; line
++)
632 if (!algo
|| gcry_md_test_algo (algo
))
633 return set_error (GPG_ERR_UNSUPPORTED_ALGORITHM
, NULL
);
635 ctrl
->digest
.algo
= algo
;
637 /* Parse the hash value. */
638 rc
= parse_hexstring (ctx
, line
, &n
);
642 if (algo
== MD_USER_TLS_MD5SHA1
&& n
== 36)
644 else if (n
!= 16 && n
!= 20 && n
!= 24
645 && n
!= 28 && n
!= 32 && n
!= 48 && n
!= 64)
646 return set_error (GPG_ERR_ASS_PARAMETER
, "unsupported length of hash");
648 if (n
> MAX_DIGEST_LEN
)
649 return set_error (GPG_ERR_ASS_PARAMETER
, "hash value to long");
651 buf
= ctrl
->digest
.value
;
652 ctrl
->digest
.valuelen
= n
;
653 for (p
=line
, n
=0; n
< ctrl
->digest
.valuelen
; p
+= 2, n
++)
655 for (; n
< ctrl
->digest
.valuelen
; n
++)
663 Perform the actual sign operation. Neither input nor output are
664 sensitive to eavesdropping. */
666 cmd_pksign (assuan_context_t ctx
, char *line
)
669 cache_mode_t cache_mode
= CACHE_MODE_NORMAL
;
670 ctrl_t ctrl
= assuan_get_pointer (ctx
);
675 if (opt
.ignore_cache_for_signing
)
676 cache_mode
= CACHE_MODE_IGNORE
;
677 else if (!ctrl
->server_local
->use_cache_for_signing
)
678 cache_mode
= CACHE_MODE_IGNORE
;
680 init_membuf (&outbuf
, 512);
682 rc
= agent_pksign (ctrl
, ctrl
->server_local
->keydesc
,
683 &outbuf
, cache_mode
);
685 clear_outbuf (&outbuf
);
687 rc
= write_and_clear_outbuf (ctx
, &outbuf
);
689 log_error ("command pksign failed: %s\n", gpg_strerror (rc
));
690 xfree (ctrl
->server_local
->keydesc
);
691 ctrl
->server_local
->keydesc
= NULL
;
695 /* PKDECRYPT <options>
697 Perform the actual decrypt operation. Input is not
698 sensitive to eavesdropping */
700 cmd_pkdecrypt (assuan_context_t ctx
, char *line
)
703 ctrl_t ctrl
= assuan_get_pointer (ctx
);
704 unsigned char *value
;
710 /* First inquire the data to decrypt */
711 rc
= assuan_inquire (ctx
, "CIPHERTEXT",
712 &value
, &valuelen
, MAXLEN_CIPHERTEXT
);
716 init_membuf (&outbuf
, 512);
718 rc
= agent_pkdecrypt (ctrl
, ctrl
->server_local
->keydesc
,
719 value
, valuelen
, &outbuf
);
722 clear_outbuf (&outbuf
);
724 rc
= write_and_clear_outbuf (ctx
, &outbuf
);
726 log_error ("command pkdecrypt failed: %s\n", gpg_strerror (rc
));
727 xfree (ctrl
->server_local
->keydesc
);
728 ctrl
->server_local
->keydesc
= NULL
;
735 Generate a new key, store the secret part and return the public
736 part. Here is an example transaction:
740 C: D (genkey (rsa (nbits 1024)))
743 S: D (rsa (n 326487324683264) (e 10001)))
748 cmd_genkey (assuan_context_t ctx
, char *line
)
750 ctrl_t ctrl
= assuan_get_pointer (ctx
);
752 unsigned char *value
;
758 /* First inquire the parameters */
759 rc
= assuan_inquire (ctx
, "KEYPARAM", &value
, &valuelen
, MAXLEN_KEYPARAM
);
763 init_membuf (&outbuf
, 512);
765 rc
= agent_genkey (ctrl
, (char*)value
, valuelen
, &outbuf
);
768 clear_outbuf (&outbuf
);
770 rc
= write_and_clear_outbuf (ctx
, &outbuf
);
772 log_error ("command genkey failed: %s\n", gpg_strerror (rc
));
779 /* READKEY <hexstring_with_keygrip>
781 Return the public key for the given keygrip. */
783 cmd_readkey (assuan_context_t ctx
, char *line
)
785 ctrl_t ctrl
= assuan_get_pointer (ctx
);
787 unsigned char grip
[20];
788 gcry_sexp_t s_pkey
= NULL
;
790 rc
= parse_keygrip (ctx
, line
, grip
);
792 return rc
; /* Return immediately as this is already an Assuan error code.*/
794 rc
= agent_public_key_from_file (ctrl
, grip
, &s_pkey
);
800 len
= gcry_sexp_sprint (s_pkey
, GCRYSEXP_FMT_CANON
, NULL
, 0);
802 buf
= xtrymalloc (len
);
804 rc
= gpg_error_from_syserror ();
807 len
= gcry_sexp_sprint (s_pkey
, GCRYSEXP_FMT_CANON
, buf
, len
);
809 rc
= assuan_send_data (ctx
, buf
, len
);
812 gcry_sexp_release (s_pkey
);
816 log_error ("command readkey failed: %s\n", gpg_strerror (rc
));
822 /* KEYINFO [--list] <keygrip>
824 Return information about the key specified by the KEYGRIP. If the
825 key is not available GPG_ERR_NOT_FOUND is returned. If the option
826 --list is given the keygrip is ignored and information about all
827 available keys are returned. The information is returned as a
828 status line with this format:
830 KEYINFO <keygrip> <type> <serialno> <idstr>
832 KEYGRIP is the keygrip.
834 TYPE is describes the type of the key:
835 'D' - Regular key stored on disk,
836 'T' - Key is stored on a smartcard (token).
839 SERIALNO is an ASCII string with the serial number of the
840 smartcard. If the serial number is not known a single
841 dash '-' is used instead.
843 IDSTR is the IDSTR used to distinguish keys on a smartcard. If it
844 is not known a dash is used instead.
846 More information may be added in the future.
849 do_one_keyinfo (ctrl_t ctrl
, const unsigned char *grip
)
854 unsigned char *shadow_info
= NULL
;
855 char *serialno
= NULL
;
857 const char *keytypestr
;
859 err
= agent_key_info_from_file (ctrl
, grip
, &keytype
, &shadow_info
);
863 /* Reformat the grip so that we use uppercase as good style. */
864 bin2hex (grip
, 20, hexgrip
);
866 if (keytype
== PRIVATE_KEY_CLEAR
867 || keytype
== PRIVATE_KEY_PROTECTED
)
869 else if (keytype
== PRIVATE_KEY_SHADOWED
)
876 err
= parse_shadow_info (shadow_info
, &serialno
, &idstr
);
881 err
= agent_write_status (ctrl
, "KEYINFO",
884 serialno
? serialno
: "-",
896 cmd_keyinfo (assuan_context_t ctx
, char *line
)
898 ctrl_t ctrl
= assuan_get_pointer (ctx
);
900 unsigned char grip
[20];
904 list_mode
= has_option (line
, "--list");
905 line
= skip_options (line
);
910 struct dirent
*dir_entry
;
913 dirname
= make_filename_try (opt
.homedir
, GNUPG_PRIVATE_KEYS_DIR
, NULL
);
916 err
= gpg_error_from_syserror ();
919 dir
= opendir (dirname
);
922 err
= gpg_error_from_syserror ();
928 while ( (dir_entry
= readdir (dir
)) )
930 if (strlen (dir_entry
->d_name
) != 44
931 || strcmp (dir_entry
->d_name
+ 40, ".key"))
933 strncpy (hexgrip
, dir_entry
->d_name
, 40);
936 if ( hex2bin (hexgrip
, grip
, 20) < 0 )
937 continue; /* Bad hex string. */
939 err
= do_one_keyinfo (ctrl
, grip
);
947 err
= parse_keygrip (ctx
, line
, grip
);
950 err
= do_one_keyinfo (ctrl
, grip
);
956 if (err
&& gpg_err_code (err
) != GPG_ERR_NOT_FOUND
)
957 log_error ("command keyinfo failed: %s\n", gpg_strerror (err
));
964 send_back_passphrase (assuan_context_t ctx
, int via_data
, const char *pw
)
969 assuan_begin_confidential (ctx
);
972 rc
= assuan_send_data (ctx
, pw
, n
);
975 char *p
= xtrymalloc_secure (n
*2+1);
977 rc
= gpg_error_from_syserror ();
981 rc
= assuan_set_okay_line (ctx
, p
);
989 /* GET_PASSPHRASE [--data] [--check] [--no-ask] [--repeat[=N]]
990 [--qualitybar] <cache_id>
991 [<error_message> <prompt> <description>]
993 This function is usually used to ask for a passphrase to be used
994 for conventional encryption, but may also be used by programs which
995 need specal handling of passphrases. This command uses a syntax
996 which helps clients to use the agent with minimum effort. The
997 agent either returns with an error or with a OK followed by the hex
998 encoded passphrase. Note that the length of the strings is
999 implicitly limited by the maximum length of a command.
1001 If the option "--data" is used the passphrase is returned by usual
1002 data lines and not on the okay line.
1004 If the option "--check" is used the passphrase constraints checks as
1005 implemented by gpg-agent are applied. A check is not done if the
1006 passphrase has been found in the cache.
1008 If the option "--no-ask" is used and the passphrase is not in the
1009 cache the user will not be asked to enter a passphrase but the error
1010 code GPG_ERR_NO_DATA is returned.
1012 If the option "--qualitybar" is used a visual indication of the
1013 entered passphrase quality is shown. (Unless no minimum passphrase
1014 length has been configured.)
1018 cmd_get_passphrase (assuan_context_t ctx
, char *line
)
1020 ctrl_t ctrl
= assuan_get_pointer (ctx
);
1024 char *cacheid
= NULL
, *desc
= NULL
, *prompt
= NULL
, *errtext
= NULL
;
1025 const char *desc2
= _("Please re-enter this passphrase");
1028 int opt_data
, opt_check
, opt_no_ask
, opt_qualbar
;
1030 char *repeat_errtext
= NULL
;
1032 opt_data
= has_option (line
, "--data");
1033 opt_check
= has_option (line
, "--check");
1034 opt_no_ask
= has_option (line
, "--no-ask");
1035 if (has_option_name (line
, "--repeat"))
1037 p
= option_value (line
, "--repeat");
1039 opt_repeat
= atoi (p
);
1043 opt_qualbar
= has_option (line
, "--qualitybar");
1044 line
= skip_options (line
);
1047 p
= strchr (cacheid
, ' ');
1054 p
= strchr (errtext
, ' ');
1061 p
= strchr (prompt
, ' ');
1068 p
= strchr (desc
, ' ');
1070 *p
= 0; /* Ignore trailing garbage. */
1074 if (!cacheid
|| !*cacheid
|| strlen (cacheid
) > 50)
1075 return set_error (GPG_ERR_ASS_PARAMETER
, "invalid length of cacheID");
1077 return set_error (GPG_ERR_ASS_PARAMETER
, "no description given");
1079 if (!strcmp (cacheid
, "X"))
1081 if (!strcmp (errtext
, "X"))
1083 if (!strcmp (prompt
, "X"))
1085 if (!strcmp (desc
, "X"))
1088 pw
= cacheid
? agent_get_cache (cacheid
, CACHE_MODE_NORMAL
, &cache_marker
)
1092 rc
= send_back_passphrase (ctx
, opt_data
, pw
);
1093 agent_unlock_cache_entry (&cache_marker
);
1095 else if (opt_no_ask
)
1096 rc
= gpg_error (GPG_ERR_NO_DATA
);
1099 /* Note, that we only need to replace the + characters and
1100 should leave the other escaping in place because the escaped
1101 string is send verbatim to the pinentry which does the
1102 unescaping (but not the + replacing) */
1104 plus_to_blank (errtext
);
1106 plus_to_blank (prompt
);
1108 plus_to_blank (desc
);
1111 rc
= agent_get_passphrase (ctrl
, &response
, desc
, prompt
,
1112 repeat_errtext
? repeat_errtext
:errtext
,
1114 xfree (repeat_errtext
);
1115 repeat_errtext
= NULL
;
1120 if (opt_check
&& check_passphrase_constraints (ctrl
, response
, 0))
1125 for (i
= 0; i
< opt_repeat
; i
++)
1129 rc
= agent_get_passphrase (ctrl
, &response2
, desc2
, prompt
,
1133 if (strcmp (response2
, response
))
1137 repeat_errtext
= try_percent_escape
1138 (_("does not match - try again"), NULL
);
1139 if (!repeat_errtext
)
1141 rc
= gpg_error_from_syserror ();
1151 agent_put_cache (cacheid
, CACHE_MODE_USER
, response
, 0);
1152 rc
= send_back_passphrase (ctx
, opt_data
, response
);
1159 log_error ("command get_passphrase failed: %s\n", gpg_strerror (rc
));
1164 /* CLEAR_PASSPHRASE <cache_id>
1166 may be used to invalidate the cache entry for a passphrase. The
1167 function returns with OK even when there is no cached passphrase.
1171 cmd_clear_passphrase (assuan_context_t ctx
, char *line
)
1173 char *cacheid
= NULL
;
1176 /* parse the stuff */
1177 for (p
=line
; *p
== ' '; p
++)
1180 p
= strchr (cacheid
, ' ');
1182 *p
= 0; /* ignore garbage */
1183 if (!cacheid
|| !*cacheid
|| strlen (cacheid
) > 50)
1184 return set_error (GPG_ERR_ASS_PARAMETER
, "invalid length of cacheID");
1186 agent_put_cache (cacheid
, CACHE_MODE_USER
, NULL
, 0);
1191 /* GET_CONFIRMATION <description>
1193 This command may be used to ask for a simple confirmation.
1194 DESCRIPTION is displayed along with a Okay and Cancel button. This
1195 command uses a syntax which helps clients to use the agent with
1196 minimum effort. The agent either returns with an error or with a
1197 OK. Note, that the length of DESCRIPTION is implicitly limited by
1198 the maximum length of a command. DESCRIPTION should not contain
1199 any spaces, those must be encoded either percent escaped or simply
1204 cmd_get_confirmation (assuan_context_t ctx
, char *line
)
1206 ctrl_t ctrl
= assuan_get_pointer (ctx
);
1211 /* parse the stuff */
1212 for (p
=line
; *p
== ' '; p
++)
1215 p
= strchr (desc
, ' ');
1217 *p
= 0; /* We ignore any garbage -may be later used for other args. */
1219 if (!desc
|| !*desc
)
1220 return set_error (GPG_ERR_ASS_PARAMETER
, "no description given");
1222 if (!strcmp (desc
, "X"))
1225 /* Note, that we only need to replace the + characters and should
1226 leave the other escaping in place because the escaped string is
1227 send verbatim to the pinentry which does the unescaping (but not
1230 plus_to_blank (desc
);
1232 rc
= agent_get_confirmation (ctrl
, desc
, NULL
, NULL
, 0);
1234 log_error ("command get_confirmation failed: %s\n", gpg_strerror (rc
));
1242 Learn something about the currently inserted smartcard. With
1243 --send the new certificates are send back. */
1245 cmd_learn (assuan_context_t ctx
, char *line
)
1247 ctrl_t ctrl
= assuan_get_pointer (ctx
);
1250 rc
= agent_handle_learn (ctrl
, has_option (line
, "--send")? ctx
: NULL
);
1252 log_error ("command learn failed: %s\n", gpg_strerror (rc
));
1258 /* PASSWD <hexstring_with_keygrip>
1260 Change the passphrase/PIN for the key identified by keygrip in LINE. */
1262 cmd_passwd (assuan_context_t ctx
, char *line
)
1264 ctrl_t ctrl
= assuan_get_pointer (ctx
);
1266 unsigned char grip
[20];
1267 gcry_sexp_t s_skey
= NULL
;
1268 unsigned char *shadow_info
= NULL
;
1270 rc
= parse_keygrip (ctx
, line
, grip
);
1275 rc
= agent_key_from_file (ctrl
, ctrl
->server_local
->keydesc
,
1276 grip
, &shadow_info
, CACHE_MODE_IGNORE
, NULL
,
1282 log_error ("changing a smartcard PIN is not yet supported\n");
1283 rc
= gpg_error (GPG_ERR_NOT_IMPLEMENTED
);
1286 rc
= agent_protect_and_store (ctrl
, s_skey
);
1289 xfree (ctrl
->server_local
->keydesc
);
1290 ctrl
->server_local
->keydesc
= NULL
;
1293 gcry_sexp_release (s_skey
);
1294 xfree (shadow_info
);
1296 log_error ("command passwd failed: %s\n", gpg_strerror (rc
));
1300 /* PRESET_PASSPHRASE <string_or_keygrip> <timeout> <hexstring>
1302 Set the cached passphrase/PIN for the key identified by the keygrip
1303 to passwd for the given time, where -1 means infinite and 0 means
1304 the default (currently only a timeout of -1 is allowed, which means
1305 to never expire it). If passwd is not provided, ask for it via the
1308 cmd_preset_passphrase (assuan_context_t ctx
, char *line
)
1311 char *grip_clear
= NULL
;
1312 char *passphrase
= NULL
;
1316 if (!opt
.allow_preset_passphrase
)
1317 return set_error (GPG_ERR_NOT_SUPPORTED
, "no --allow-preset-passphrase");
1320 while (*line
&& (*line
!= ' ' && *line
!= '\t'))
1323 return gpg_error (GPG_ERR_MISSING_VALUE
);
1326 while (*line
&& (*line
== ' ' || *line
== '\t'))
1329 /* Currently, only infinite timeouts are allowed. */
1331 if (line
[0] != '-' || line
[1] != '1')
1332 return gpg_error (GPG_ERR_NOT_IMPLEMENTED
);
1335 while (!(*line
!= ' ' && *line
!= '\t'))
1338 /* Syntax check the hexstring. */
1339 rc
= parse_hexstring (ctx
, line
, &len
);
1344 /* If there is a passphrase, use it. Currently, a passphrase is
1348 /* Do in-place conversion. */
1350 if (!hex2str (passphrase
, passphrase
, strlen (passphrase
)+1, NULL
))
1351 rc
= set_error (GPG_ERR_ASS_PARAMETER
, "invalid hexstring");
1354 rc
= set_error (GPG_ERR_NOT_IMPLEMENTED
, "passphrase is required");
1357 rc
= agent_put_cache (grip_clear
, CACHE_MODE_ANY
, passphrase
, ttl
);
1360 log_error ("command preset_passphrase failed: %s\n", gpg_strerror (rc
));
1366 /* SCD <commands to pass to the scdaemon>
1368 This is a general quote command to redirect everything to the
1371 cmd_scd (assuan_context_t ctx
, char *line
)
1373 ctrl_t ctrl
= assuan_get_pointer (ctx
);
1376 rc
= divert_generic_cmd (ctrl
, line
, ctx
);
1385 Return the value for KEY from the special environment as created by
1389 cmd_getval (assuan_context_t ctx
, char *line
)
1394 struct putval_item_s
*vl
;
1396 for (p
=line
; *p
== ' '; p
++)
1399 p
= strchr (key
, ' ');
1403 for (; *p
== ' '; p
++)
1406 return set_error (GPG_ERR_ASS_PARAMETER
, "too many arguments");
1409 return set_error (GPG_ERR_ASS_PARAMETER
, "no key given");
1412 for (vl
=putval_list
; vl
; vl
= vl
->next
)
1413 if ( !strcmp (vl
->d
, key
) )
1416 if (vl
) /* Got an entry. */
1417 rc
= assuan_send_data (ctx
, vl
->d
+vl
->off
, vl
->len
);
1419 return gpg_error (GPG_ERR_NO_DATA
);
1422 log_error ("command getval failed: %s\n", gpg_strerror (rc
));
1427 /* PUTVAL <key> [<percent_escaped_value>]
1429 The gpg-agent maintains a kind of environment which may be used to
1430 store key/value pairs in it, so that they can be retrieved later.
1431 This may be used by helper daemons to daemonize themself on
1432 invocation and register them with gpg-agent. Callers of the
1433 daemon's service may now first try connect to get the information
1434 for that service from gpg-agent through the GETVAL command and then
1435 try to connect to that daemon. Only if that fails they may start
1436 an own instance of the service daemon.
1438 KEY is an an arbitrary symbol with the same syntax rules as keys
1439 for shell environment variables. PERCENT_ESCAPED_VALUE is the
1440 corresponsing value; they should be similar to the values of
1441 envronment variables but gpg-agent does not enforce any
1442 restrictions. If that value is not given any value under that KEY
1443 is removed from this special environment.
1446 cmd_putval (assuan_context_t ctx
, char *line
)
1451 size_t valuelen
= 0;
1453 struct putval_item_s
*vl
, *vlprev
;
1455 for (p
=line
; *p
== ' '; p
++)
1458 p
= strchr (key
, ' ');
1462 for (; *p
== ' '; p
++)
1467 p
= strchr (value
, ' ');
1470 valuelen
= percent_plus_unescape_inplace (value
, 0);
1474 return set_error (GPG_ERR_ASS_PARAMETER
, "no key given");
1477 for (vl
=putval_list
,vlprev
=NULL
; vl
; vlprev
=vl
, vl
= vl
->next
)
1478 if ( !strcmp (vl
->d
, key
) )
1481 if (vl
) /* Delete old entry. */
1484 vlprev
->next
= vl
->next
;
1486 putval_list
= vl
->next
;
1490 if (valuelen
) /* Add entry. */
1492 vl
= xtrymalloc (sizeof *vl
+ strlen (key
) + valuelen
);
1494 rc
= gpg_error_from_syserror ();
1498 vl
->off
= strlen (key
) + 1;
1499 strcpy (vl
->d
, key
);
1500 memcpy (vl
->d
+ vl
->off
, value
, valuelen
);
1501 vl
->next
= putval_list
;
1507 log_error ("command putval failed: %s\n", gpg_strerror (rc
));
1516 Set startup TTY and X DISPLAY variables to the values of this
1517 session. This command is useful to pull future pinentries to
1518 another screen. It is only required because there is no way in the
1519 ssh-agent protocol to convey this information. */
1521 cmd_updatestartuptty (assuan_context_t ctx
, char *line
)
1523 ctrl_t ctrl
= assuan_get_pointer (ctx
);
1527 xfree (opt
.startup_display
); opt
.startup_display
= NULL
;
1528 xfree (opt
.startup_ttyname
); opt
.startup_ttyname
= NULL
;
1529 xfree (opt
.startup_ttytype
); opt
.startup_ttytype
= NULL
;
1530 xfree (opt
.startup_lc_ctype
); opt
.startup_lc_ctype
= NULL
;
1531 xfree (opt
.startup_lc_messages
); opt
.startup_lc_messages
= NULL
;
1532 xfree (opt
.startup_xauthority
); opt
.startup_xauthority
= NULL
;
1535 opt
.startup_display
= xtrystrdup (ctrl
->display
);
1537 opt
.startup_ttyname
= xtrystrdup (ctrl
->ttyname
);
1539 opt
.startup_ttytype
= xtrystrdup (ctrl
->ttytype
);
1541 opt
.startup_lc_ctype
= xtrystrdup (ctrl
->lc_ctype
);
1542 if (ctrl
->lc_messages
)
1543 opt
.startup_lc_messages
= xtrystrdup (ctrl
->lc_messages
);
1544 if (ctrl
->xauthority
)
1545 opt
.startup_xauthority
= xtrystrdup (ctrl
->xauthority
);
1546 if (ctrl
->pinentry_user_data
)
1547 opt
.startup_pinentry_user_data
= xtrystrdup (ctrl
->pinentry_user_data
);
1554 #ifdef HAVE_W32_SYSTEM
1557 Under Windows we start the agent on the fly. Thus it also make
1558 sense to allow a client to stop the agent. */
1560 cmd_killagent (assuan_context_t ctx
, char *line
)
1562 ctrl_t ctrl
= assuan_get_pointer (ctx
);
1566 ctrl
->server_local
->stopme
= 1;
1567 return gpg_error (GPG_ERR_EOF
);
1572 As signals are inconvenient under Windows, we provide this command
1573 to allow reloading of the configuration. */
1575 cmd_reloadagent (assuan_context_t ctx
, char *line
)
1580 agent_sighup_action ();
1583 #endif /*HAVE_W32_SYSTEM*/
1589 Multipurpose function to return a variety of information.
1590 Supported values for WHAT are:
1592 version - Return the version of the program.
1593 pid - Return the process id of the server.
1594 socket_name - Return the name of the socket.
1595 ssh_socket_name - Return the name of the ssh socket.
1596 scd_running - Return OK if the SCdaemon is already running.
1598 cmd_has_option CMD OPT
1599 - Returns OK if the command CMD implements the option OPT.
1602 cmd_getinfo (assuan_context_t ctx
, char *line
)
1606 if (!strcmp (line
, "version"))
1608 const char *s
= VERSION
;
1609 rc
= assuan_send_data (ctx
, s
, strlen (s
));
1611 else if (!strcmp (line
, "pid"))
1615 snprintf (numbuf
, sizeof numbuf
, "%lu", (unsigned long)getpid ());
1616 rc
= assuan_send_data (ctx
, numbuf
, strlen (numbuf
));
1618 else if (!strcmp (line
, "socket_name"))
1620 const char *s
= get_agent_socket_name ();
1623 rc
= assuan_send_data (ctx
, s
, strlen (s
));
1625 rc
= gpg_error (GPG_ERR_NO_DATA
);
1627 else if (!strcmp (line
, "ssh_socket_name"))
1629 const char *s
= get_agent_ssh_socket_name ();
1632 rc
= assuan_send_data (ctx
, s
, strlen (s
));
1634 rc
= gpg_error (GPG_ERR_NO_DATA
);
1636 else if (!strcmp (line
, "scd_running"))
1638 rc
= agent_scd_check_running ()? 0 : gpg_error (GPG_ERR_GENERAL
);
1640 else if (!strncmp (line
, "cmd_has_option", 14)
1641 && (line
[14] == ' ' || line
[14] == '\t' || !line
[14]))
1645 while (*line
== ' ' || *line
== '\t')
1648 rc
= gpg_error (GPG_ERR_MISSING_VALUE
);
1652 while (*line
&& (*line
!= ' ' && *line
!= '\t'))
1655 rc
= gpg_error (GPG_ERR_MISSING_VALUE
);
1659 while (*line
== ' ' || *line
== '\t')
1662 rc
= gpg_error (GPG_ERR_MISSING_VALUE
);
1666 if (!command_has_option (cmd
, cmdopt
))
1667 rc
= gpg_error (GPG_ERR_GENERAL
);
1673 rc
= set_error (GPG_ERR_ASS_PARAMETER
, "unknown value for WHAT");
1680 option_handler (assuan_context_t ctx
, const char *key
, const char *value
)
1682 ctrl_t ctrl
= assuan_get_pointer (ctx
);
1684 if (!strcmp (key
, "display"))
1687 xfree (ctrl
->display
);
1688 ctrl
->display
= xtrystrdup (value
);
1690 return out_of_core ();
1692 else if (!strcmp (key
, "ttyname"))
1697 xfree (ctrl
->ttyname
);
1698 ctrl
->ttyname
= xtrystrdup (value
);
1700 return out_of_core ();
1703 else if (!strcmp (key
, "ttytype"))
1708 xfree (ctrl
->ttytype
);
1709 ctrl
->ttytype
= xtrystrdup (value
);
1711 return out_of_core ();
1714 else if (!strcmp (key
, "lc-ctype"))
1717 xfree (ctrl
->lc_ctype
);
1718 ctrl
->lc_ctype
= xtrystrdup (value
);
1719 if (!ctrl
->lc_ctype
)
1720 return out_of_core ();
1722 else if (!strcmp (key
, "lc-messages"))
1724 if (ctrl
->lc_messages
)
1725 xfree (ctrl
->lc_messages
);
1726 ctrl
->lc_messages
= xtrystrdup (value
);
1727 if (!ctrl
->lc_messages
)
1728 return out_of_core ();
1730 else if (!strcmp (key
, "xauthority"))
1732 if (ctrl
->xauthority
)
1733 xfree (ctrl
->xauthority
);
1734 ctrl
->xauthority
= xtrystrdup (value
);
1735 if (!ctrl
->xauthority
)
1736 return out_of_core ();
1738 else if (!strcmp (key
, "pinentry-user-data"))
1740 if (ctrl
->pinentry_user_data
)
1741 xfree (ctrl
->pinentry_user_data
);
1742 ctrl
->pinentry_user_data
= xtrystrdup (value
);
1743 if (!ctrl
->pinentry_user_data
)
1744 return out_of_core ();
1746 else if (!strcmp (key
, "use-cache-for-signing"))
1747 ctrl
->server_local
->use_cache_for_signing
= *value
? atoi (value
) : 0;
1748 else if (!strcmp (key
, "allow-pinentry-notify"))
1749 ctrl
->server_local
->allow_pinentry_notify
= 1;
1751 return gpg_error (GPG_ERR_UNKNOWN_OPTION
);
1759 /* Called by libassuan after all commands. ERR is the error from the
1760 last assuan operation and not the one returned from the command. */
1762 post_cmd_notify (assuan_context_t ctx
, int err
)
1764 ctrl_t ctrl
= assuan_get_pointer (ctx
);
1768 /* Switch off any I/O monitor controlled logging pausing. */
1769 ctrl
->server_local
->pause_io_logging
= 0;
1773 /* This function is called by libassuan for all I/O. We use it here
1774 to disable logging for the GETEVENTCOUNTER commands. This is so
1775 that the debug output won't get cluttered by this primitive
1778 io_monitor (assuan_context_t ctx
, int direction
,
1779 const char *line
, size_t linelen
)
1781 ctrl_t ctrl
= assuan_get_pointer (ctx
);
1783 /* Note that we only check for the uppercase name. This allows to
1784 see the logging for debugging if using a non-upercase command
1786 if (ctx
&& !direction
1788 && !strncmp (line
, "GETEVENTCOUNTER", 15)
1789 && (linelen
== 15 || spacep (line
+15)))
1791 ctrl
->server_local
->pause_io_logging
= 1;
1794 return ctrl
->server_local
->pause_io_logging
? 1:0;
1798 /* Return true if the commznd CMD implements the option OPT. */
1800 command_has_option (const char *cmd
, const char *cmdopt
)
1802 if (!strcmp (cmd
, "GET_PASSPHRASE"))
1804 if (!strcmp (cmdopt
, "repeat"))
1812 /* Tell the assuan library about our commands */
1814 register_commands (assuan_context_t ctx
)
1818 int (*handler
)(assuan_context_t
, char *line
);
1820 { "GETEVENTCOUNTER",cmd_geteventcounter
},
1821 { "ISTRUSTED", cmd_istrusted
},
1822 { "HAVEKEY", cmd_havekey
},
1823 { "KEYINFO", cmd_keyinfo
},
1824 { "SIGKEY", cmd_sigkey
},
1825 { "SETKEY", cmd_sigkey
},
1826 { "SETKEYDESC", cmd_setkeydesc
},
1827 { "SETHASH", cmd_sethash
},
1828 { "PKSIGN", cmd_pksign
},
1829 { "PKDECRYPT", cmd_pkdecrypt
},
1830 { "GENKEY", cmd_genkey
},
1831 { "READKEY", cmd_readkey
},
1832 { "GET_PASSPHRASE", cmd_get_passphrase
},
1833 { "PRESET_PASSPHRASE", cmd_preset_passphrase
},
1834 { "CLEAR_PASSPHRASE", cmd_clear_passphrase
},
1835 { "GET_CONFIRMATION", cmd_get_confirmation
},
1836 { "LISTTRUSTED", cmd_listtrusted
},
1837 { "MARKTRUSTED", cmd_marktrusted
},
1838 { "LEARN", cmd_learn
},
1839 { "PASSWD", cmd_passwd
},
1843 { "GETVAL", cmd_getval
},
1844 { "PUTVAL", cmd_putval
},
1845 { "UPDATESTARTUPTTY", cmd_updatestartuptty
},
1846 #ifdef HAVE_W32_SYSTEM
1847 { "KILLAGENT", cmd_killagent
},
1848 { "RELOADAGENT", cmd_reloadagent
},
1850 { "GETINFO", cmd_getinfo
},
1855 for (i
=0; table
[i
].name
; i
++)
1857 rc
= assuan_register_command (ctx
, table
[i
].name
, table
[i
].handler
);
1861 #ifdef HAVE_ASSUAN_SET_IO_MONITOR
1862 assuan_register_post_cmd_notify (ctx
, post_cmd_notify
);
1864 assuan_register_reset_notify (ctx
, reset_notify
);
1865 assuan_register_option_handler (ctx
, option_handler
);
1870 /* Startup the server. If LISTEN_FD and FD is given as -1, this is a
1871 simple piper server, otherwise it is a regular server. CTRL is the
1872 control structure for this connection; it has only the basic
1875 start_command_handler (ctrl_t ctrl
, gnupg_fd_t listen_fd
, gnupg_fd_t fd
)
1878 assuan_context_t ctx
;
1880 if (listen_fd
== GNUPG_INVALID_FD
&& fd
== GNUPG_INVALID_FD
)
1886 rc
= assuan_init_pipe_server (&ctx
, filedes
);
1888 else if (listen_fd
!= GNUPG_INVALID_FD
)
1890 rc
= assuan_init_socket_server_ext (&ctx
, listen_fd
, 0);
1894 rc
= assuan_init_socket_server_ext (&ctx
, fd
, 2);
1898 log_error ("failed to initialize the server: %s\n",
1902 rc
= register_commands (ctx
);
1905 log_error ("failed to register commands with Assuan: %s\n",
1910 assuan_set_pointer (ctx
, ctrl
);
1911 ctrl
->server_local
= xcalloc (1, sizeof *ctrl
->server_local
);
1912 ctrl
->server_local
->assuan_ctx
= ctx
;
1913 ctrl
->server_local
->message_fd
= -1;
1914 ctrl
->server_local
->use_cache_for_signing
= 1;
1915 ctrl
->digest
.raw_value
= 0;
1918 assuan_set_log_stream (ctx
, log_get_stream ());
1920 #ifdef HAVE_ASSUAN_SET_IO_MONITOR
1921 assuan_set_io_monitor (ctx
, io_monitor
);
1926 rc
= assuan_accept (ctx
);
1927 if (gpg_err_code (rc
) == GPG_ERR_EOF
|| rc
== -1)
1933 log_info ("Assuan accept problem: %s\n", gpg_strerror (rc
));
1937 rc
= assuan_process (ctx
);
1940 log_info ("Assuan processing failed: %s\n", gpg_strerror (rc
));
1945 /* Reset the SCD if needed. */
1946 agent_reset_scd (ctrl
);
1948 /* Reset the pinentry (in case of popup messages). */
1949 agent_reset_query (ctrl
);
1952 assuan_deinit_server (ctx
);
1953 #ifdef HAVE_W32_SYSTEM
1954 if (ctrl
->server_local
->stopme
)
1957 xfree (ctrl
->server_local
);
1958 ctrl
->server_local
= NULL
;