summaryrefslogtreecommitdiffstats
path: root/g10/card-util.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2009-06-09 21:11:28 +0200
committerWerner Koch <wk@gnupg.org>2009-06-09 21:11:28 +0200
commitbdbeb0ac2bdd3e24f97efb67a3c33e8e08523c46 (patch)
tree750ebce47c26e8093274084bbe30f1dc070130bb /g10/card-util.c
parentTypo fix. Updated German translation. (diff)
downloadgnupg2-bdbeb0ac2bdd3e24f97efb67a3c33e8e08523c46.tar.xz
gnupg2-bdbeb0ac2bdd3e24f97efb67a3c33e8e08523c46.zip
app-openpgp changes
Diffstat (limited to 'g10/card-util.c')
-rw-r--r--g10/card-util.c75
1 files changed, 49 insertions, 26 deletions
diff --git a/g10/card-util.c b/g10/card-util.c
index b696144b0..290e3b784 100644
--- a/g10/card-util.c
+++ b/g10/card-util.c
@@ -48,6 +48,29 @@
#define CONTROL_D ('D' - 'A' + 1)
+static void
+write_sc_op_status (gpg_error_t err)
+{
+ switch (gpg_err_code (err))
+ {
+ case 0:
+ write_status (STATUS_SC_OP_SUCCESS);
+ break;
+#if GNUPG_MAJOR_VERSION != 1
+ case GPG_ERR_CANCELED:
+ write_status_text (STATUS_SC_OP_FAILURE, "1");
+ break;
+ case GPG_ERR_BAD_PIN:
+ write_status_text (STATUS_SC_OP_FAILURE, "2");
+ break;
+ default:
+ write_status (STATUS_SC_OP_FAILURE);
+ break;
+#endif /* GNUPG_MAJOR_VERSION != 1 */
+ }
+}
+
+
/* Change the PIN of a an OpenPGP card. This is an interactive
function. */
void
@@ -86,25 +109,21 @@ change_pin (int unblock_v2, int allow_admin)
else
{
rc = agent_scd_change_pin (2, info.serialno);
+ write_sc_op_status (rc);
if (rc)
tty_printf ("Error changing the PIN: %s\n", gpg_strerror (rc));
else
- {
- write_status (STATUS_SC_OP_SUCCESS);
- tty_printf ("PIN changed.\n");
- }
+ tty_printf ("PIN changed.\n");
}
}
else if (!allow_admin)
{
rc = agent_scd_change_pin (1, info.serialno);
+ write_sc_op_status (rc);
if (rc)
tty_printf ("Error changing the PIN: %s\n", gpg_strerror (rc));
else
- {
- write_status (STATUS_SC_OP_SUCCESS);
- tty_printf ("PIN changed.\n");
- }
+ tty_printf ("PIN changed.\n");
}
else
for (;;)
@@ -129,50 +148,42 @@ change_pin (int unblock_v2, int allow_admin)
{
/* Change PIN. */
rc = agent_scd_change_pin (1, info.serialno);
+ write_sc_op_status (rc);
if (rc)
tty_printf ("Error changing the PIN: %s\n", gpg_strerror (rc));
else
- {
- write_status (STATUS_SC_OP_SUCCESS);
- tty_printf ("PIN changed.\n");
- }
+ tty_printf ("PIN changed.\n");
}
else if (*answer == '2')
{
/* Unblock PIN. */
rc = agent_scd_change_pin (101, info.serialno);
+ write_sc_op_status (rc);
if (rc)
tty_printf ("Error unblocking the PIN: %s\n", gpg_strerror (rc));
else
- {
- write_status (STATUS_SC_OP_SUCCESS);
- tty_printf ("PIN unblocked and new PIN set.\n");
- }
+ tty_printf ("PIN unblocked and new PIN set.\n");
}
else if (*answer == '3')
{
/* Change Admin PIN. */
rc = agent_scd_change_pin (3, info.serialno);
+ write_sc_op_status (rc);
if (rc)
tty_printf ("Error changing the PIN: %s\n", gpg_strerror (rc));
else
- {
- write_status (STATUS_SC_OP_SUCCESS);
- tty_printf ("PIN changed.\n");
- }
+ tty_printf ("PIN changed.\n");
}
else if (*answer == '4')
{
/* Set a new Reset Code. */
rc = agent_scd_change_pin (102, info.serialno);
+ write_sc_op_status (rc);
if (rc)
tty_printf ("Error setting the Reset Code: %s\n",
gpg_strerror (rc));
else
- {
- write_status (STATUS_SC_OP_SUCCESS);
- tty_printf ("Reset Code set.\n");
- }
+ tty_printf ("Reset Code set.\n");
}
else if (*answer == 'q' || *answer == 'Q')
{
@@ -694,6 +705,7 @@ change_url (void)
if (rc)
log_error ("error setting URL: %s\n", gpg_strerror (rc));
xfree (url);
+ write_sc_op_status (rc);
return rc;
}
@@ -744,6 +756,7 @@ fetch_url(void)
return rc;
#else
+ #warning need to implemented fucntion
return 0;
#endif
}
@@ -839,6 +852,7 @@ change_login (const char *args)
if (rc)
log_error ("error setting login data: %s\n", gpg_strerror (rc));
xfree (data);
+ write_sc_op_status (rc);
return rc;
}
@@ -884,6 +898,7 @@ change_private_do (const char *args, int nr)
if (rc)
log_error ("error setting private DO: %s\n", gpg_strerror (rc));
xfree (data);
+ write_sc_op_status (rc);
return rc;
}
@@ -913,6 +928,7 @@ change_cert (const char *args)
if (rc)
log_error ("error writing certificate to card: %s\n", gpg_strerror (rc));
xfree (data);
+ write_sc_op_status (rc);
return rc;
}
@@ -950,6 +966,7 @@ change_lang (void)
if (rc)
log_error ("error setting lang: %s\n", gpg_strerror (rc));
xfree (data);
+ write_sc_op_status (rc);
return rc;
}
@@ -985,6 +1002,7 @@ change_sex (void)
if (rc)
log_error ("error setting sex: %s\n", gpg_strerror (rc));
xfree (data);
+ write_sc_op_status (rc);
return rc;
}
@@ -1029,6 +1047,7 @@ change_cafpr (int fprno)
fprno==3?"CA-FPR-3":"x", fpr, 20, NULL );
if (rc)
log_error ("error setting cafpr: %s\n", gpg_strerror (rc));
+ write_sc_op_status (rc);
return rc;
}
@@ -1054,6 +1073,7 @@ toggle_forcesig (void)
rc = agent_scd_setattr ("CHV-STATUS-1", newstate? "\x01":"", 1, NULL);
if (rc)
log_error ("error toggling signature PIN flag: %s\n", gpg_strerror (rc));
+ write_sc_op_status (rc);
}
@@ -1111,8 +1131,11 @@ check_pin_for_key_operation (struct agent_card_info_s *info, int *forced_chv1)
binding signature. */
rc = agent_scd_checkpin (info->serialno);
if (rc)
- log_error ("error checking the PIN: %s\n", gpg_strerror (rc));
- }
+ {
+ log_error ("error checking the PIN: %s\n", gpg_strerror (rc));
+ write_sc_op_status (rc);
+ }
+ }
return rc;
}