Better reset the PIN verification stati after changing the key attributes.
[gnupg.git] / common / simple-pwquery.h
blob8de9b1bd20a75a8e07338bc18d776184787edcf6
1 /* simple-pwquery.c - A simple password query cleint for gpg-agent
2 * Copyright (C) 2002 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef SIMPLE_PWQUERY_H
21 #define SIMPLE_PWQUERY_H
23 #ifdef SIMPLE_PWQUERY_IMPLEMENTATION /* Begin configuration stuff. */
25 /* Include whatever files you need. */
26 #include <gcrypt.h>
27 #include "../jnlib/logging.h"
29 /* Try to write error message using the standard log mechanism. The
30 current implementation requires that the HAVE_JNLIB_LOGGING is also
31 defined. */
32 #define SPWQ_USE_LOGGING 1
34 /* Memory allocation functions used by the implementation. Note, that
35 the returned value is expected to be freed with
36 spwq_secure_free. */
37 #define spwq_malloc(a) gcry_malloc (a)
38 #define spwq_free(a) gcry_free (a)
39 #define spwq_secure_malloc(a) gcry_malloc_secure (a)
40 #define spwq_secure_free(a) gcry_free (a)
42 #endif /*SIMPLE_PWQUERY_IMPLEMENTATION*/ /* End configuration stuff. */
45 /* Ask the gpg-agent for a passphrase and present the user with a
46 DESCRIPTION, a PROMPT and optiaonlly with a TRYAGAIN extra text.
47 If a CACHEID is not NULL it is used to locate the passphrase in in
48 the cache and store it under this ID. If OPT_CHECK is true
49 gpg-agent is asked to apply some checks on the passphrase security.
50 If ERRORCODE is not NULL it should point a variable receiving an
51 errorcode; this errocode might be 0 if the user canceled the
52 operation. The function returns NULL to indicate an error. */
53 char *simple_pwquery (const char *cacheid,
54 const char *tryagain,
55 const char *prompt,
56 const char *description,
57 int opt_check,
58 int *errorcode);
60 /* Ask the gpg-agent to clear the passphrase for the cache ID CACHEID. */
61 int simple_pwclear (const char *cacheid);
63 /* Perform the simple query QUERY (which must be new-line and 0
64 terminated) and return the error code. */
65 int simple_query (const char *query);
67 /* Set the name of the standard socket to be used if GPG_AGENT_INFO is
68 not defined. The use of this function is optional but if it needs
69 to be called before any other function. Returns 0 on success. */
70 int simple_pw_set_socket (const char *name);
72 #define SPWQ_OUT_OF_CORE 1
73 #define SPWQ_IO_ERROR 2
74 #define SPWQ_PROTOCOL_ERROR 3
75 #define SPWQ_ERR_RESPONSE 4
76 #define SPWQ_NO_AGENT 5
77 #define SPWQ_SYS_ERROR 6
78 #define SPWQ_GENERAL_ERROR 7
79 #define SPWQ_NO_PIN_ENTRY 8
82 /* We often need to map error codes to gpg-error style error codes.
83 To have a consistent mapping this macro may be used to implemt the
84 mapping function. */
85 #define MAP_SPWQ_ERROR_IMPL \
86 static gpg_error_t \
87 map_spwq_error (int err) \
88 { \
89 switch (err) \
90 { \
91 case 0: \
92 return 0; \
93 case SPWQ_OUT_OF_CORE: \
94 return gpg_error_from_errno (ENOMEM); \
95 case SPWQ_IO_ERROR: \
96 return gpg_error_from_errno (EIO); \
97 case SPWQ_PROTOCOL_ERROR: \
98 return gpg_error (GPG_ERR_PROTOCOL_VIOLATION); \
99 case SPWQ_ERR_RESPONSE: \
100 return gpg_error (GPG_ERR_INV_RESPONSE); \
101 case SPWQ_NO_AGENT: \
102 return gpg_error (GPG_ERR_NO_AGENT); \
103 case SPWQ_SYS_ERROR: \
104 return gpg_error_from_syserror (); \
105 case SPWQ_NO_PIN_ENTRY: \
106 return gpg_error (GPG_ERR_NO_PIN_ENTRY); \
107 case SPWQ_GENERAL_ERROR: \
108 default: \
109 return gpg_error (GPG_ERR_GENERAL); \
112 /* End of MAP_SPWQ_ERROR_IMPL. */
115 #endif /*SIMPLE_PWQUERY_H*/