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/>.
37 /* Delete a certificate or an secret key from a key database. */
39 delete_one (ctrl_t ctrl
, const char *username
)
42 KEYDB_SEARCH_DESC desc
;
43 KEYDB_HANDLE kh
= NULL
;
44 ksba_cert_t cert
= NULL
;
47 rc
= keydb_classify_name (username
, &desc
);
50 log_error (_("certificate `%s' not found: %s\n"),
51 username
, gpg_strerror (rc
));
52 gpgsm_status2 (ctrl
, STATUS_DELETE_PROBLEM
, "1", NULL
);
59 log_error ("keydb_new failed\n");
64 rc
= keydb_search (kh
, &desc
, 1);
66 rc
= keydb_get_cert (kh
, &cert
);
69 unsigned char fpr
[20];
71 gpgsm_get_fingerprint (cert
, 0, fpr
, NULL
);
74 rc
= keydb_search (kh
, &desc
, 1);
79 ksba_cert_t cert2
= NULL
;
80 unsigned char fpr2
[20];
82 /* We ignore all duplicated certificates which might have
83 been inserted due to program bugs. */
84 if (!keydb_get_cert (kh
, &cert2
))
86 gpgsm_get_fingerprint (cert2
, 0, fpr2
, NULL
);
87 ksba_cert_release (cert2
);
88 if (!memcmp (fpr
, fpr2
, 20))
94 rc
= gpg_error (GPG_ERR_AMBIGUOUS_NAME
);
100 rc
= gpg_error (GPG_ERR_NO_PUBKEY
);
101 log_error (_("certificate `%s' not found: %s\n"),
102 username
, gpg_strerror (rc
));
103 gpgsm_status2 (ctrl
, STATUS_DELETE_PROBLEM
, "3", NULL
);
107 /* We need to search again to get back to the right position. */
108 rc
= keydb_lock (kh
);
111 log_error (_("error locking keybox: %s\n"), gpg_strerror (rc
));
117 keydb_search_reset (kh
);
118 rc
= keydb_search (kh
, &desc
, 1);
121 log_error ("problem re-searching certificate: %s\n",
126 rc
= keydb_delete (kh
, duplicates
? 0 : 1);
132 log_info (_("duplicated certificate `%s' deleted\n"), username
);
134 log_info (_("certificate `%s' deleted\n"), username
);
137 while (duplicates
--);
141 ksba_cert_release (cert
);
147 /* Delete the certificates specified by NAMES. */
149 gpgsm_delete (ctrl_t ctrl
, strlist_t names
)
155 log_error ("nothing to delete\n");
156 return gpg_error (GPG_ERR_NO_DATA
);
159 for (; names
; names
=names
->next
)
161 rc
= delete_one (ctrl
, names
->d
);
164 log_error (_("deleting certificate \"%s\" failed: %s\n"),
165 names
->d
, gpg_strerror (rc
) );