From 27b0c30862b56feccb120c896e1354b501681e2a Mon Sep 17 00:00:00 2001 From: Eduardo Chappa Date: Sun, 28 Feb 2016 14:36:21 -0700 Subject: * Protection against deleting new key and certificate when replacing key that encrypts password file in case that the new key/certificate pairs have the same name as the old key/certificate. --- pith/smime.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'pith') diff --git a/pith/smime.c b/pith/smime.c index d32a97c9..da3cd253 100644 --- a/pith/smime.c +++ b/pith/smime.c @@ -781,11 +781,15 @@ import_certificate(WhichCerts ctype) build_path(buf, PATHCERTDIR(ctype), pwdcert->name, sizeof(buf)); strncat(buf, EXTCERT(Private), 4); buf[sizeof(buf)-1] = '\0'; - if(unlink(buf) < 0) - q_status_message(SM_ORDER, 1, 3, _("Failed to remove old key")); + if(strcmp(PrivateKeyPath, buf)){ + if (unlink(buf) < 0) + q_status_message(SM_ORDER, 1, 3, _("Failed to remove old key")); + } build_path(buf, PATHCERTDIR(ctype), pwdcert->cname, sizeof(buf)); - if(unlink(buf) < 0) - q_status_message(SM_ORDER, 1, 3, _("Failed to remove old certificate")); + if(strcmp(PublicCertPath, buf)){ + if(unlink(buf) < 0) + q_status_message(SM_ORDER, 1, 3, _("Failed to remove old certificate")); + } free_personal_certs((PERSONAL_CERT **)&ps_global->pwdcert); ps_global->pwdcert = pc; rc = 1; -- cgit v1.2.3-70-g09d2