summaryrefslogtreecommitdiff
path: root/src/common.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2014-07-02 13:37:04 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2014-07-02 13:38:42 +0200
commit56fef6bece4153e5bcf623bc0148b5adefaa443e (patch)
tree2061fda155e8c9a9d46802bedbaa2fd312a22e46 /src/common.c
parentb57521106297f57cb4c6bb7c98edbce407845860 (diff)
downloadgnutls-56fef6bece4153e5bcf623bc0148b5adefaa443e.tar.gz
tools: PIN callback will respect batch mode and will not ask for PIN.
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/common.c b/src/common.c
index 070d06df12..db9d18829e 100644
--- a/src/common.c
+++ b/src/common.c
@@ -978,6 +978,7 @@ pin_callback(void *user, int attempt, const char *token_url,
size_t pin_max)
{
const char *password = NULL;
+ common_info_st *info = user;
const char *desc;
int cache = MAX_CACHE_TRIES;
unsigned len;
@@ -1027,12 +1028,12 @@ pin_callback(void *user, int attempt, const char *token_url,
printf("Token '%s' with URL '%s' ", token_label, token_url);
printf("requires %s PIN\n", desc);
-
+
password = getenv(env);
if (env == NULL) /* compatibility */
password = getenv("GNUTLS_PIN");
- if (password == NULL) {
+ if (password == NULL && (info == NULL || info->batch == 0)) {
password = getpass("Enter PIN: ");
} else {
if (flags & GNUTLS_PIN_WRONG) {
@@ -1074,8 +1075,9 @@ static int
token_callback(void *user, const char *label, const unsigned retry)
{
char buf[32];
+ common_info_st *info = user;
- if (retry > 0) {
+ if (retry > 0 || (info != NULL && info->batch != 0)) {
fprintf(stderr, "Could not find token %s\n", label);
return -1;
}
@@ -1086,11 +1088,11 @@ token_callback(void *user, const char *label, const unsigned retry)
return 0;
}
-void pkcs11_common(void)
+void pkcs11_common(common_info_st *c)
{
- gnutls_pkcs11_set_pin_function(pin_callback, NULL);
- gnutls_pkcs11_set_token_function(token_callback, NULL);
+ gnutls_pkcs11_set_pin_function(pin_callback, c);
+ gnutls_pkcs11_set_token_function(token_callback, c);
}