[Pkg-privacy-commits] [libotr] 57/225: * src/privkey.h: * src/privkey.c: Add otrl_privkey_generate_cancel to handle the case that the background key generation thread is cancelled or fails.

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:44:53 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository libotr.

commit 7e3eda6844bb6b306e96c7ae587c1d18dcd151b3
Author: cypherpunk <cypherpunk>
Date:   Wed Jul 9 15:08:39 2008 +0000

    	* src/privkey.h:
    	* src/privkey.c: Add otrl_privkey_generate_cancel to handle the
    	case that the background key generation thread is cancelled or
    	fails.
---
 ChangeLog     |  7 +++++++
 src/privkey.c | 28 ++++++++++++++++++++--------
 src/privkey.h |  5 +++++
 3 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0e61469..45298c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-07-09:
+
+	* src/privkey.h:
+	* src/privkey.c: Add otrl_privkey_generate_cancel to handle the
+	case that the background key generation thread is cancelled or
+	fails.
+
 2008-07-06:
 
 	* configure.ac: Update libtool version to match 4.0.0.
diff --git a/src/privkey.c b/src/privkey.c
index 68ee51c..b25cbc0 100644
--- a/src/privkey.c
+++ b/src/privkey.c
@@ -542,6 +542,25 @@ static FILE* privkey_fopen(const char *filename, gcry_error_t *errp)
     return privf;
 }
 
+/* Call this from the main thread only, in the event that the background
+ * thread generating the key is cancelled.  The newkey is deallocated,
+ * and must not be used further. */
+void otrl_privkey_generate_cancel(OtrlUserState us, void *newkey)
+{
+    struct s_pending_privkey_calc *ppc =
+	(struct s_pending_privkey_calc *)newkey;
+
+    if (us) {
+	pending_forget(pending_find(us, ppc->accountname, ppc->protocol));
+    }
+
+    /* Deallocate ppc */
+    free(ppc->accountname);
+    free(ppc->protocol);
+    gcry_sexp_release(ppc->privkey);
+    free(ppc);
+}
+
 /* Call this from the main thread only.  It will write the newly created
  * private key into the given file and store it in the OtrlUserState. */
 gcry_error_t otrl_privkey_generate_finish(OtrlUserState us,
@@ -590,16 +609,9 @@ gcry_error_t otrl_privkey_generate_finish_FILEp(OtrlUserState us,
 	fseek(privf, 0, SEEK_SET);
 
 	ret = otrl_privkey_read_FILEp(us, privf);
-
-	/* Remove our entry from the pending list */
-	pending_forget(pending_find(us, ppc->accountname, ppc->protocol));
     }
 
-    /* Deallocate ppc */
-    free(ppc->accountname);
-    free(ppc->protocol);
-    gcry_sexp_release(ppc->privkey);
-    free(ppc);
+    otrl_privkey_generate_cancel(us, newkey);
 
     return ret;
 }
diff --git a/src/privkey.h b/src/privkey.h
index efe025a..686f04a 100644
--- a/src/privkey.h
+++ b/src/privkey.h
@@ -76,6 +76,11 @@ gcry_error_t otrl_privkey_generate_finish(OtrlUserState us,
 gcry_error_t otrl_privkey_generate_finish_FILEp(OtrlUserState us,
 	void *newkey, FILE *privf);
 
+/* Call this from the main thread only, in the event that the background
+ * thread generating the key is cancelled.  The newkey is deallocated,
+ * and must not be used further. */
+void otrl_privkey_generate_cancel(OtrlUserState us, void *newkey);
+
 /* Generate a private DSA key for a given account, storing it into a
  * file on disk, and loading it into the given OtrlUserState.  Overwrite any
  * previously generated keys for that account in that OtrlUserState. */

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/libotr.git



More information about the Pkg-privacy-commits mailing list