[Winpt-commits] r217 - in trunk: . Include Src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon May 22 16:21:43 CEST 2006


Author: twoaday
Date: 2006-05-22 16:21:39 +0200 (Mon, 22 May 2006)
New Revision: 217

Modified:
   trunk/Include/wptContext.h
   trunk/Include/wptGPG.h
   trunk/Include/wptKeyCache.h
   trunk/Include/wptUtil.h
   trunk/NEWS
   trunk/Src/ChangeLog
   trunk/Src/WinPT.cpp
   trunk/Src/wptClipDecryptDlg.cpp
   trunk/Src/wptFileManager.cpp
   trunk/Src/wptGPGME.cpp
   trunk/Src/wptKeyCache.cpp
   trunk/Src/wptKeyCacheDlg.cpp
   trunk/Src/wptKeyManagerDlg.cpp
   trunk/Src/wptKeyPropsDlg.cpp
   trunk/Src/wptKeyserverDlg.cpp
   trunk/Src/wptPassphraseCB.cpp
   trunk/Src/wptUtil.cpp
Log:
2005-05-20  Timo Schulz  <ts at g10code.de>
                                                                                
        * wptKeyPropsDlg.cpp (keyprops_load_photo): avoid expensive
        process call when no photo is available.
        (keyprops_dlg_proc): avoid static data.
        * wptFileManager.cpp (fm_add_sig_stat): Free memory in case
        of on demand key requests.
        (show_verify_result): Likewise.
        (secret_key_available): Likewise.
        (fm_decrypt, fm_sign): Handle the new on demand key request
        mode and free all memory.



Modified: trunk/Include/wptContext.h
===================================================================
--- trunk/Include/wptContext.h	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/Include/wptContext.h	2006-05-22 14:21:39 UTC (rev 217)
@@ -1,5 +1,5 @@
 /* wptContext.h - Internal file to store private contexts
- *	Copyright (C) 2001-2005 Timo Schulz
+ *	Copyright (C) 2001-2006 Timo Schulz
  *
  * This file is part of WinPT.
  *
@@ -47,7 +47,8 @@
 	int new_val;		    /* new value */
     } callback;
     char tmp_keyid[8+1];
-    int internal;		    
+    int internal;
+    unsigned int allocated:1;
 };
 typedef struct winpt_key_s * winpt_key_t;
 

Modified: trunk/Include/wptGPG.h
===================================================================
--- trunk/Include/wptGPG.h	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/Include/wptGPG.h	2006-05-22 14:21:39 UTC (rev 217)
@@ -153,21 +153,18 @@
 
 /*-- wptGPGME.cpp --*/
 const char * get_signature_status( gpgme_sigsum_t sigstat );
-void keycache_reload( HWND dlg );
 
 gpgme_error_t get_pubkey (const char *keyid, gpgme_key_t *ret_key);
 gpgme_error_t winpt_get_pubkey (const char *keyid, struct winpt_key_s *k);
+void	      winpt_release_pubkey (winpt_key_s *k);
 gpgme_error_t get_seckey (const char *keyid, gpgme_key_t *ret_skey);
 gpgme_error_t winpt_get_seckey (const char *keyid, struct winpt_key_s *k);
 
-void keycache_reload( HWND dlg );
 void keycache_release (int cleanup);
 gpgme_error_t keycache_update (int is_sec, const char *keyid);
 gpgme_error_t keycache_init (const char *pubring, const char * secring);
 gpg_keycache_t keycache_get_ctx (int _pub);
 
-int count_insecure_elgkeys (void);
-
 int gpg_encrypt_symmetric (void);
 const char *get_gpg_sigstat (gpgme_sigsum_t sum);
 int check_ultimate_trusted_key (void);

Modified: trunk/Include/wptKeyCache.h
===================================================================
--- trunk/Include/wptKeyCache.h	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/Include/wptKeyCache.h	2006-05-22 14:21:39 UTC (rev 217)
@@ -93,11 +93,14 @@
 
 gpgme_error_t gpg_keycache_new (gpg_keycache_t * r_ctx);
 void gpg_keycache_release (gpg_keycache_t ctx);
+void gpg_keycache_item_release (struct keycache_s *c);
 void gpg_keycache_set_cb (gpg_keycache_t ctx,
 			    void (*cb)(void *, const char *, int, int, int),
 			    void* cb_value1, int cb_value2);
 void gpg_keycache_rewind (gpg_keycache_t ctx);
 int gpg_keycache_get_size (gpg_keycache_t ctx);
+gpgme_error_t gpg_keycache_fetch_key (const char *keyid, int is_sec, 
+			gpgme_key_t *r_key, struct keycache_s **r_c);
 gpgme_error_t gpg_keycache_add_key (gpg_keycache_t ctx, gpgme_key_t key, 
 				      void **opaque);
 gpgme_error_t gpg_keycache_update_key (gpg_keycache_t ctx, int is_sec, 

Modified: trunk/Include/wptUtil.h
===================================================================
--- trunk/Include/wptUtil.h	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/Include/wptUtil.h	2006-05-22 14:21:39 UTC (rev 217)
@@ -6,5 +6,6 @@
 const char *stristr (const char *buf, const char *sub);
 int check_email_address (const char *email);
 char* substr (const char *str, unsigned int begin, unsigned int end);
+void unhexify_buffer (const char *in, char **out);
 
 #endif

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/NEWS	2006-05-22 14:21:39 UTC (rev 217)
@@ -824,3 +824,7 @@
 * Fix a re-introduced problem in the HTTP code.
 
 (0.12.2)
+* Fix double-click code for the Explorer.
+* Avoid problem in the key property dialog when a key
+  has designated revokers.
+  
\ No newline at end of file

Modified: trunk/Src/ChangeLog
===================================================================
--- trunk/Src/ChangeLog	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/Src/ChangeLog	2006-05-22 14:21:39 UTC (rev 217)
@@ -1,3 +1,15 @@
+2005-05-20  Timo Schulz  <ts at g10code.de>
+
+	* wptKeyPropsDlg.cpp (keyprops_load_photo): avoid expensive
+	process call when no photo is available.
+	(keyprops_dlg_proc): avoid static data.
+	* wptFileManager.cpp (fm_add_sig_stat): Free memory in case
+	of on demand key requests.
+	(show_verify_result): Likewise.
+	(secret_key_available): Likewise.
+	(fm_decrypt, fm_sign): Handle the new on demand key request
+	mode and free all memory.
+	
 2006-05-15  Timo Schulz  <ts at g10code.de>
 
 	* wptKeyEditDlgs.cpp (userid_list_init): Forgot to

Modified: trunk/Src/WinPT.cpp
===================================================================
--- trunk/Src/WinPT.cpp	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/Src/WinPT.cpp	2006-05-22 14:21:39 UTC (rev 217)
@@ -218,7 +218,7 @@
 	err = gpg_keycache_find_key (kc, defkey, 0, &key);
     else
 	msg_box (NULL, _("No useable secret key found."), 
-		 _("WinPT Error"), MB_ERR);
+		 _("WinPT Warning"), MB_WARN);
     free_if_alloc (defkey);
     return err? -1 : 0;
 }
@@ -422,8 +422,25 @@
 }
 
 
-#include "wptKeyManager.h"
+/* Search for insecure ElGamal keys and return the
+   number of founded keys. */
+static int
+count_insecure_elgkeys (void)
+{
+    gpg_keycache_t pc;
+    gpgme_key_t key;
+    int n = 0;
 
+    pc = keycache_get_ctx (1);
+    while (!gpg_keycache_next_key (pc, 0, &key)) {
+	if (key->subkeys->pubkey_algo == GPGME_PK_ELG)
+	    n++;
+    }
+    gpg_keycache_rewind (pc);
+    return n;
+}
+
+
 /* Main entry point. */
 int WINAPI
 WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd)

Modified: trunk/Src/wptClipDecryptDlg.cpp
===================================================================
--- trunk/Src/wptClipDecryptDlg.cpp	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/Src/wptClipDecryptDlg.cpp	2006-05-22 14:21:39 UTC (rev 217)
@@ -39,7 +39,7 @@
 #include "wptUTF8.h"
 #include "resource.h"
 
-bool secret_key_available (gpgme_recipient_t rset);
+bool is_seckey_available (gpgme_recipient_t rset);
 
 /* Return the primary user-ID of the key with the keyid @keyid. 
    Caller must free string. */
@@ -56,6 +56,7 @@
     if (!uid)
 	BUG (NULL);
     sprintf (uid, "\n    \"%s\"", key.ext->uids->uid);
+    winpt_release_pubkey (&key);
     return uid;
 }
 
@@ -126,7 +127,7 @@
 	agent_del_cache (pwd.keyid);
 
     res = gpgme_op_decrypt_result (ctx);
-    if (err && res->recipients && !secret_key_available (res->recipients)) {
+    if (err && res->recipients && !is_seckey_available (res->recipients)) {
 	gpgme_recipient_t r = res->recipients;
 	char *u = get_key_userid (r->keyid+8);
 	log_box (_("Decryption"), MB_ERR, 

Modified: trunk/Src/wptFileManager.cpp
===================================================================
--- trunk/Src/wptFileManager.cpp	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/Src/wptFileManager.cpp	2006-05-22 14:21:39 UTC (rev 217)
@@ -1233,23 +1233,28 @@
 		keyid, s, uid, pka_info? pka_info : "");
     msg_box (NULL, buf, _("Decrypt Verify"), sigok? MB_OK: MB_ICONWARNING|MB_OK);
     free_if_alloc (pka_info);
+    winpt_release_pubkey (&key);
 }
 
 
 /* Check the recipients if we have at least one secret key. */
 bool
-secret_key_available (gpgme_recipient_t rset)
+is_seckey_available (gpgme_recipient_t rset)
 {
     gpgme_recipient_t r;
-    gpgme_key_t key;
+    winpt_key_s key;
 
     for (r=rset; r; r = r->next) {
 	if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY)
 	    continue;
 	else {
+	    memset (&key, 0, sizeof (key));
 	    /* extra check to make sure the key is available right now. */
-	    if (!get_seckey (r->keyid, &key))
+	    if (!winpt_get_seckey (r->keyid, &key)) {
+		winpt_release_pubkey (&key);
 		return true;
+	    }
+	    winpt_release_pubkey (&key);
 	}
     }
     return false;
@@ -1346,7 +1351,7 @@
     }
 
     res = gpgme_op_decrypt_result (ctx);
-    if (res && res->recipients && !secret_key_available (res->recipients)) {
+    if (res && res->recipients && !is_seckey_available (res->recipients)) {
 	const char *keyid = res->recipients->keyid;
 	char *p = get_key_userid (keyid+8);
 	gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo;
@@ -1372,16 +1377,17 @@
     }
     else if (res && res->file_name) {
 	char *file;
-	int id;
+	int id = IDNO;
 
 	file = strrchr (c->output, '\\');
 	if (!file)
 	    file = c->output;
 	else
 	    file++;
-	id = log_box (_("Decrypt"), MB_QUEST_ASK,
-		      _("The original file name is '%s'.\n\n"
-		        "Do you want to use this instead of '%s'?"),
+	if (strcmp (res->file_name, file))
+	    id = log_box (_("Decrypt"), MB_QUEST_ASK,
+			  _("The original file name is '%s'.\n\n"
+			    "Do you want to use this instead of '%s'?"),
 		      res->file_name, file);
 	if (id == IDYES) {
 	    /* before we can move the file, it needs to be closed first. */
@@ -1392,7 +1398,7 @@
     }
     sigres = gpgme_op_verify_result (ctx);
     if (sigres && sigres->signatures)
-	show_verify_result (sigres);    
+	show_verify_result (sigres);
     
 leave:
     if (in)
@@ -1478,6 +1484,7 @@
 	log->user_id = key.ext->uids->uid;
 	log->use_uid = 1;
     }
+    winpt_release_pubkey (&key);
     file_verify_add_state (log);
 }
 

Modified: trunk/Src/wptGPGME.cpp
===================================================================
--- trunk/Src/wptGPGME.cpp	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/Src/wptGPGME.cpp	2006-05-22 14:21:39 UTC (rev 217)
@@ -1,5 +1,5 @@
 /* wptGPGME.cpp - WinPT GPGME interface
- *	Copyright (C) 2001-2005 Timo Schulz
+ *	Copyright (C) 2001-2006 Timo Schulz
  *
  * This file is part of WinPT.
  *
@@ -47,20 +47,12 @@
 static char *gpg_secring = NULL;
 
 
-/* Reload the key cache. */
-void
-keycache_reload (HWND dlg) 
-{	
-    refresh_cache_s rcs;
-
-    memset (&rcs, 0, sizeof rcs);
-    rcs.kr_reload = rcs.kr_update = 1;
-    rcs.tr_update = 0;
-    DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,					
-		    keycache_dlg_proc, (LPARAM)&rcs);
+int
+keycache_not_available (void)
+{
+    return pub == NULL;
 }
 
-
 /* Release both key cache objects. If @cleanup is 1,
    also release other global structs. */
 void
@@ -125,8 +117,7 @@
     }
 
     memset (&pfx, 0, sizeof (pfx));
-    /* Release old contexts first. */
-    keycache_release (0);
+    keycache_release (0); /* Release old contexts first. */
 
     err = gpg_keycache_new (&pub);
     if (err)
@@ -167,8 +158,8 @@
 /* Get the GPG key with keyid @keyid from the cache. Return it 
    in @r_key on success. */
 static gpgme_error_t
-get_key_from_cache (const char *keyid, gpgme_key_t *r_key, 
-		    struct keycache_s **c, int secret)
+get_key_from_cache (const char *keyid, int secret, gpgme_key_t *r_key, 
+		    struct keycache_s **c)
 {
     gpg_keycache_t cache;
     gpgme_error_t err;
@@ -187,20 +178,17 @@
 }
 
 
-/* Get GPG key with keyid @keyid directly from GPG and return
-   it in @r_key on success. */
-static gpgme_error_t
-get_key_directly (const char *keyid, gpgme_key_t *r_key, int secret)
+/* Release the internal key structure.
+   If allocated is 0, assume fixed cache item. */
+void
+winpt_release_pubkey (winpt_key_s *k)
 {
-    gpgme_ctx_t ctx;
-    gpgme_error_t err;
-
-    err = gpgme_new (&ctx);
-    if (err)
-	return err;
-    err = gpgme_get_key (ctx, keyid, r_key, secret);
-    gpgme_release (ctx);
-    return err;
+    /*log_box ("debug", 0, "alloc %d", k->allocated);*/
+    if (!k->allocated)
+	return;
+    gpg_keycache_item_release (k->ext);
+    k->ext = NULL;
+    k->allocated = 0;
 }
 
 
@@ -209,9 +197,12 @@
 gpgme_error_t
 winpt_get_pubkey (const char *keyid, winpt_key_s *k)
 {
-    gpgme_error_t err;
+    gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
     
-    err = get_key_from_cache (keyid, &k->ctx, &k->ext, 0);
+    if (pub)
+	err = get_key_from_cache (keyid, 0, &k->ctx, &k->ext);
+    else
+	err = gpg_keycache_fetch_key (keyid, 0, &k->ctx, &k->ext);
     if (err)
 	return err;
     k->is_v3 = k->ctx->subkeys->pubkey_algo == GPGME_PK_RSA && 
@@ -219,6 +210,7 @@
     k->is_protected = k->ext->gloflags.is_protected;
     k->keyid = k->ctx->subkeys->keyid+8;
     k->uid = k->ext->uids->uid;
+    k->allocated = pub? 0 : 1;
     return 0;
 }
 
@@ -228,7 +220,10 @@
 {
     gpgme_error_t err;
 
-    err = get_key_from_cache (keyid, &k->ctx, &k->ext, 1);
+    if (sec)
+	err = get_key_from_cache (keyid, 1, &k->ctx, &k->ext);
+    else
+	err = gpg_keycache_fetch_key (keyid, 1, &k->ctx, &k->ext);
     if (err)
 	return err;
     k->is_v3 = k->ctx->subkeys->pubkey_algo == GPGME_PK_RSA && 
@@ -236,6 +231,7 @@
     k->is_protected = k->ext->gloflags.is_protected;
     k->keyid = k->ctx->subkeys->keyid+8;
     k->uid = k->ext->uids->uid;
+    k->allocated = sec? 1 : 0;
     return 0;
 }
 
@@ -243,49 +239,18 @@
 gpgme_error_t
 get_pubkey (const char *keyid, gpgme_key_t *ret_key)
 {
-    gpgme_error_t rc;
-
-    if (pub && sec)
-	rc = get_key_from_cache (keyid, ret_key, NULL, 0);
-    else
-	rc = get_key_directly (keyid, ret_key, 0);
-    return rc;
+    return get_key_from_cache (keyid, 0, ret_key, NULL);
 }
 
 
 gpgme_error_t
 get_seckey (const char *keyid, gpgme_key_t *ret_skey)
 {
-    gpgme_error_t rc;
-
-    if (pub && sec)
-	rc = get_key_from_cache (keyid, ret_skey, NULL, 1);
-    else
-	rc = get_key_directly (keyid, ret_skey, 1);
-    return rc;
+    return get_key_from_cache (keyid, 1, ret_skey, NULL);
 }
 
 
-/* Search for insecure ElGamal keys and return the
-   number of founded keys. */
-int
-count_insecure_elgkeys (void)
-{
-    gpg_keycache_t pc;
-    gpgme_key_t key;
-    int n=0;
 
-    pc = keycache_get_ctx (1);
-    while (!gpg_keycache_next_key (pc, 0, &key)) {
-	if (key->subkeys->pubkey_algo == GPGME_PK_ELG)
-	    n++;
-    }
-    gpg_keycache_rewind (pc);
-    return n;
-}
-
-
-
 /* Map the signature summary in @sum to signature status table index. 
    Return value: index to table. */
 static int
@@ -326,34 +291,10 @@
 }
 
 
-/* Check if the secret keyring contains at least one 
-   key with ultimate trust.
-   Return value: 0 on success. */
-int
-check_ultimate_trusted_key (void)
-{
-    struct keycache_s *n;
-    int nkeys = 0;
-
-    for (n = sec->item; n; n = n->next) {
-	if (n->pubpart && 
-	    n->pubpart->key->owner_trust == GPGME_VALIDITY_ULTIMATE)
-	return 0;
-	nkeys++;
-    }
-
-    /* if we do not have any secret keys, it does not make sense
-       to return an error. */
-    if (nkeys == 0)
-	return 0;
-    return -1;
-}
-
-
 bool
 secret_key_available (void)
 {
-    gpg_keycache_t _sec = keycache_get_ctx (0);
+    gpg_keycache_t _sec = sec;
     if (!_sec || gpg_keycache_get_size (_sec) == 0)
 	return false;
     return true;

Modified: trunk/Src/wptKeyCache.cpp
===================================================================
--- trunk/Src/wptKeyCache.cpp	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/Src/wptKeyCache.cpp	2006-05-22 14:21:39 UTC (rev 217)
@@ -25,7 +25,6 @@
 #include <windows.h>
 #include <stdio.h>
 #include <string.h>
-#include <malloc.h>
 #include <ctype.h>
 #include <assert.h>
 #include <gpgme.h>
@@ -61,10 +60,12 @@
 free_attr_list (attr_list_t ctx)
 {
     attr_list_t n;
+
     while (ctx) {
 	n = ctx->next;
-	safe_free (ctx->fpr);
-	safe_free (ctx->d);
+	free_if_alloc (ctx->fpr);
+	free_if_alloc (ctx->d);
+	free_if_alloc (ctx);
 	ctx = n;
     }
 }
@@ -88,14 +89,16 @@
 	    continue;
 	buffer = buf+9+10;
 	pos = 0;
-	c = (attr_list_t)calloc (1, sizeof *c);
+	c = new attr_list_s;
 	if (!c)
 	    BUG (0);
+	memset (c, 0, sizeof *c);
+
 	p = strtok (buffer, " ");
 	while (p != NULL) {
 	    switch (pos) {
 	    case 0: 
-		c->fpr = strdup (p);
+		c->fpr = m_strdup (p);
 		break;
 		
 	    case 1:
@@ -119,7 +122,7 @@
 		;
 	    t->next = c;
 	}
-	c->d = (unsigned char*)malloc (c->octets);
+	c->d = new unsigned char[c->octets];
 	if (!c->d)
 	    BUG (0);
 	memcpy (c->d, data, c->octets);
@@ -200,8 +203,8 @@
 		goto next;
 	    c->gloflags.is_protected = sk->is_protected;
 	    c->gloflags.divert_to_card = sk->protect.s2k.mode==1002? 1 : 0;
-	    if (c->pubpart != NULL) {    
-		c->pubpart->gloflags.is_protected = sk->is_protected;    
+	    if (c->pubpart != NULL) {
+		c->pubpart->gloflags.is_protected = sk->is_protected;
 		c->pubpart->gloflags.divert_to_card = sk->protect.s2k.mode==1002? 1 : 0;
 	    }
 	}
@@ -225,10 +228,10 @@
     gpg_keycache_find_key2 (ctx, fpr, 0, &key, &fnd);
     if (!fnd)
 	return gpg_error (GPG_ERR_NOT_FOUND);
-    safe_free (fnd->attrib.d);
+    free_if_alloc (fnd->attrib.d);
     fnd->attrib.flags = dat->flags;
     fnd->attrib.len = dat->octets;
-    fnd->attrib.d = (unsigned char*)malloc (dat->octets);
+    fnd->attrib.d = new unsigned char[dat->octets];
     if (!fnd->attrib.d)
 	BUG (0);
     memcpy (fnd->attrib.d, dat->d, dat->octets);
@@ -256,23 +259,24 @@
 }
 
 
-static void
+void
 keycache_decode_uid (struct keycache_s *ctx)
 {
     gpgme_user_id_t u;
     struct native_uid_s *n, *t;
 
     for (u = ctx->key->uids; u; u = u->next) {
-	n = (struct native_uid_s*)calloc (1, sizeof *n);
+	n = new native_uid_s;
 	if (!n)
 	    BUG (0);
+	memset (n, 0, sizeof *n);
 	if (is_8bit_string (u->uid)) {
 	    n->malloced = 1;
 	    n->uid = utf8_to_native (u->uid);
 	    if (u->name != NULL)
 		n->name = utf8_to_native (u->name);
 	    if (u->email != NULL)
-		n->email = strdup (u->email);
+		n->email = m_strdup (u->email);
 	    if (u->comment != NULL)
 		n->comment = utf8_to_native (u->comment);
 	}
@@ -317,13 +321,12 @@
     while (n != NULL) {
 	t = n->next;
 	if (n->malloced) {
-	    safe_free (n->uid);
-	    safe_free (n->name);
-	    safe_free (n->comment);
-	    safe_free (n->email);
-	    safe_free (n->uid);
+	    free_if_alloc (n->uid);
+	    free_if_alloc (n->name);
+	    free_if_alloc (n->comment);
+	    free_if_alloc (n->email);
 	}
-	safe_free (n);
+	free_if_alloc (n);
 	n = t;
     }
     *r_n = NULL;
@@ -378,7 +381,7 @@
 		goto next;
 	    c->gloflags.has_desig_rev = 1;
 	}
-	if (pkt->pkttype == PKT_SIGNATURE && key_seen == 1) {
+	if (pkt->pkttype == PKT_SIGNATURE && key_seen == 1 && c != NULL) {
 	    sym_prefs = gpg_parse_sig_subpkt (pkt->pkt.signature->hashed,
 				              SIGSUBPKT_PREF_SYM, &nsym);
 	    if (!sym_prefs)
@@ -393,9 +396,10 @@
 	    if (c->sym_prefs) /* only use the prefs from the primary uid. */
 		goto next;
 	    else if (nsym > 0) {
-		c->sym_prefs = (unsigned char*)calloc (1, nsym+1);
+		c->sym_prefs = new unsigned char[nsym+1];
 		if (!c->sym_prefs)
 		    BUG (0);
+		memset (c->sym_prefs, 0, nsym+1);
 		memcpy (c->sym_prefs, sym_prefs, nsym);
 	    }
 	}
@@ -435,9 +439,10 @@
     
     if (!r_ctx)
 	return gpg_error (GPG_ERR_INV_ARG);
-    ctx = (gpg_keycache_t)calloc (1, sizeof *ctx);
+    ctx = new gpg_keycache_s;    
     if (!ctx)
         BUG (0);
+    memset (ctx, 0, sizeof *ctx);
     ctx->secret = 0;
     ctx->pos = 0;
     *r_ctx = ctx;
@@ -445,6 +450,24 @@
 }
 
 
+void
+gpg_keycache_item_release (struct keycache_s *c)
+{
+    if (c->key)
+	gpgme_key_release (c->key);	
+    c->key = NULL;	
+    if (c->rev != NULL)    
+	gpg_desig_rev_release (c->rev);
+    c->rev = NULL;
+    free_if_alloc (c->pref_keyserver);
+    free_if_alloc (c->sym_prefs);
+    free_if_alloc (c->attrib.d);
+    free_if_alloc (c->card_type);
+    free_native_uids (&c->uids);
+    free_if_alloc (c);
+}
+
+
 /* Release keycache object @ctx. */
 void
 gpg_keycache_release (gpg_keycache_t ctx)
@@ -456,19 +479,9 @@
 
     for (c = ctx->item; c; c = c2) {
         c2 = c->next;
-	gpgme_key_release (c->key);
-	c->key = NULL;
-	if (c->rev != NULL)
-	    gpg_desig_rev_release (c->rev);
-	c->rev = NULL;
-	safe_free (c->pref_keyserver);
-	safe_free (c->sym_prefs);
-	safe_free (c->attrib.d);
-	safe_free (c->card_type);
-	free_native_uids (&c->uids);
-	safe_free (c);
+	gpg_keycache_item_release (c);
     }
-    safe_free (ctx);
+    free_if_alloc (ctx);
 }
 
 
@@ -500,9 +513,10 @@
     if (!ctx)
         return gpg_error (GPG_ERR_INV_ARG);
     
-    c = (struct keycache_s*)calloc (1, sizeof *c);
+    c = new keycache_s;
     if (!c)
         BUG (0);
+    memset (c, 0, sizeof *c);
     c->gloflags.is_protected = 1; /*default: assume protection. */
     c->key = key;
     if (!ctx->item)
@@ -616,7 +630,7 @@
 	if (c->flags != 0) {
 	    *r_status = c->flags;
 	    *r_obj = c;
-	    c->flags = 0;
+	    c->flags = 0; /* reset update flag. */
 	    return 0;
 	}
     }
@@ -624,25 +638,66 @@
 }
 
 
+static gpgme_error_t
+get_gpg_key (const char *keyid, int is_sec, gpgme_key_t *r_key)
+{
+    gpgme_ctx_t ctx;
+    gpgme_error_t err;
 
+    err = gpgme_new (&ctx);
+    if (err)
+	return err;
+    gpgme_set_keylist_mode  (ctx, GPGME_KEYLIST_MODE_SIGS);
+    err = gpgme_get_key (ctx, keyid, r_key, is_sec);
+    gpgme_release (ctx);
+    return err;
+}
+
+
+/* Fetch a key directly from gpg but without adding
+   it to the key cache. Caller must free @r_ctx. */
 gpgme_error_t
+gpg_keycache_fetch_key (const char *keyid, int is_sec, 
+			gpgme_key_t *r_key, struct keycache_s **r_c)
+{
+    gpgme_error_t err;
+    gpgme_key_t key;
+    struct keycache_s *c;
+
+    *r_key = NULL;
+    *r_c = NULL;
+    err = get_gpg_key (keyid, is_sec, &key);
+    if (err)
+	return err;
+
+    c = new keycache_s;
+    if (!c)
+        BUG (0);
+    memset (c, 0, sizeof *c);
+    c->gloflags.is_protected = 1; /*default: assume protection. */
+    c->key = key;    
+    keycache_decode_uid (c);
+    *r_key = key;
+    *r_c = c;
+    return 0;
+}
+
+
+/* Update the key with the keyid @key in the key cache.
+   If the key does not exist, it is added otherwise all
+   parts are first freed and then replaced with the updated data. */
+gpgme_error_t
 gpg_keycache_update_key (gpg_keycache_t ctx, int is_sec, 
 			 void *opaque, const char *keyid)
-{
-    struct keycache_s *c = NULL, *c_new=NULL;
+{    
     gpgme_key_t key=NULL, fndkey=NULL;
     gpgme_error_t err;
-    gpgme_ctx_t gctx;
+    struct keycache_s *c = NULL, *c_new=NULL;
     gpg_keycache_t pub = (gpg_keycache_t)opaque;
 
-    err = gpgme_new (&gctx);
+    err = get_gpg_key (keyid, is_sec, &key);
     if (err)
 	return err;
-    gpgme_set_keylist_mode  (gctx, GPGME_KEYLIST_MODE_SIGS/*|GPGME_KEYLIST_MODE_SIG_NOTATIONS*/);
-    err = gpgme_get_key (gctx, keyid, &key, is_sec);
-    gpgme_release (gctx);
-    if (err)
-	return err;
     err = gpg_keycache_find_key2 (ctx, keyid, 0, &fndkey, &c);
     if (!err && c != NULL) {
 	log_debug ("keycache update: keyid=%s %p\r\n", keyid, pub);
@@ -671,13 +726,12 @@
 		c->gloflags.divert_to_card = c_new->gloflags.divert_to_card;
 	    }
 	}
-	if (c)
+	if (c != NULL)
 	    c->flags = KC_FLAG_ADD;
-
     }
 
     /* refresh utf8 user ID list. */
-    if (c != NULL) {
+    if (c != NULL && c->key) {
 	free_native_uids (&c->uids);
 	keycache_decode_uid (c);
     }
@@ -703,9 +757,10 @@
     
     c = ctx->item;
     if (c->next == NULL) {
-	gpgme_key_release (itm->key);
-	safe_free (itm);
-	ctx->item = NULL;
+	if (itm->key)
+	    gpgme_key_release (itm->key);
+	itm->key = NULL;
+	free_if_alloc (itm);
     }
     else {
 	for (; c != NULL; c = c->next) {
@@ -714,8 +769,10 @@
 	}
 	assert (c != NULL); /* XXX: sometimes access violation. */
 	c->next = c->next->next;
-	gpgme_key_release (itm->key);
-	safe_free (itm);
+	if (itm->key)
+	    gpgme_key_release (itm->key);
+	itm->key = NULL;
+	free_if_alloc (itm);
     }
     return 0;
 }
@@ -740,7 +797,7 @@
 	return err;
 
     /* XXX: GPGME_KEYLIST_MODE_SIG_NOTATIONS causes an internal error! */
-    gpgme_set_keylist_mode  (c, GPGME_KEYLIST_MODE_SIGS/*|GPGME_KEYLIST_MODE_SIG_NOTATIONS*/);
+    gpgme_set_keylist_mode  (c, GPGME_KEYLIST_MODE_SIGS);
     err = gpgme_op_keylist_start (c, pattern, secret);
     while(!err) {
 	err = gpgme_op_keylist_next (c, &key);
@@ -754,7 +811,6 @@
 	err = gpg_error (GPG_ERR_NO_ERROR);
     keycache_update_photos (ctx);
     keycache_decode_uids (ctx);
-    /* XXX: make sure the progress dialog is closed. */
     gpgme_op_keylist_end (c);
     gpgme_release (c);
     return err;
@@ -789,14 +845,16 @@
 
     while (prefs[pos] != 0)
 	pos++;
-    p = (unsigned char*)calloc (1, pos+1);
+    p = new unsigned char[pos+1];
     if (!p)
 	BUG (0);
+    memset (p, 0, pos+1);
     memcpy (p, prefs, pos);
     return p;
 }
 
 
+/* Sync the secret and the public key cache information. */
 gpgme_error_t
 gpg_keycache_sync (gpg_keycache_t pub, gpg_keycache_t sec)
 {
@@ -806,7 +864,7 @@
     if (!pub || !sec)
 	return gpg_error (GPG_ERR_INV_ARG);
     
-    for (c=sec->item; c; c=c->next) {	
+    for (c=sec->item; c; c=c->next) {
 	if (!gpg_keycache_find_key2 (pub, c->key->subkeys->keyid, 0, &key, &c_sec)) {
 	    c_sec->gloflags.is_protected = c->gloflags.is_protected;
 	    c_sec->gloflags.divert_to_card = c->gloflags.divert_to_card;
@@ -864,12 +922,13 @@
     }
     if (ctx->tmp->flags != 0)
 	ctx->tmp->flags = 0; /* reset the 'updated' status. */
+
     /* it might be possible there is no public key. */
     if (flags && ctx->tmp->pubpart == NULL)
 	flags = 0;
     *r_key = flags? ctx->tmp->pubpart->key : ctx->tmp->key;
     *c = ctx->tmp;
-    ctx->tmp = ctx->tmp->next;    
+    ctx->tmp = ctx->tmp->next;
     ctx->pos++;
 
     return 0;
@@ -889,6 +948,7 @@
     return err;
 }
 
+
 gpgme_error_t
 gpg_keycache_next_key2 (gpg_keycache_t ctx, int flags, 
 			struct keycache_s **c, gpgme_key_t *r_key)
@@ -944,8 +1004,8 @@
 		  char **out, WORD *outlen)
 {
     char tmp[128], *val;
-    char *enc = NULL;
-    size_t pos = 0, i=0;
+    char *enc = NULL;      
+    size_t pos = 0;
 
     /* example: spk:24:1:21:http%3A//subkeys.pgp.de */
     *outlen = 0;
@@ -954,7 +1014,8 @@
     if (strncmp (subpkt_data, "spk:", 4))
 	return gpg_error (GPG_ERR_NO_DATA);
 
-    strncpy (tmp, subpkt_data, 62);
+    /* XXX: do not use static buffer sizes. */
+    strncpy (tmp, subpkt_data, DIM (tmp)-4);
     val = strtok (tmp, ":");
     while (val != NULL) {
 	switch (pos++) {
@@ -974,31 +1035,15 @@
 	    break;
 
 	case 4:
-	    enc = strdup (val);
+	    enc = m_strdup (val);
 	    break;
 	}
 	val = strtok (NULL, ":");
     }
     if (!enc)
-	return gpg_error (GPG_ERR_NO_DATA);;
-    *out = (char*)calloc (1, strlen (enc)+1);
-    if (!*out)
-	BUG (0);
-    for (pos = 0; pos < strlen (enc); pos++) {
-	if (enc[pos] == '%' && enc[pos+1] == '%')
-	    (*out)[i++] = '%';
-	else if (enc[pos] == '%') {
-	    char temp[3];
-	    temp[0] = enc[++pos];
-	    temp[1] = enc[++pos];
-	    temp[2] = 0;
-	    (*out)[i++] = (char)strtoul (temp, NULL, 16);
-	}
-	else
-	    (*out)[i++] = enc[pos];
-    }
-    (*out)[i] = 0;
-    safe_free (enc);
+	return gpg_error (GPG_ERR_NO_DATA);
+    unhexify_buffer (enc, out);
+    free_if_alloc (enc);
     return 0;
 }
 
@@ -1017,7 +1062,7 @@
     case KC_ATTR_PREFSYM:
 	if (!force && item->sym_prefs)
 	    break;
-	safe_free (item->sym_prefs);
+	free_if_alloc (item->sym_prefs);
 	err = gpg_find_key_subpacket (item->key->subkeys->keyid+8, attr, &val);
 	if (!err && val != NULL)
 	    err = decode_subpacket (val, NULL, (char**)&item->sym_prefs, &n);
@@ -1026,7 +1071,7 @@
     case KC_ATTR_PREFKSERV:
 	if (!force && item->pref_keyserver)
 	    break;
-	safe_free (item->pref_keyserver);
+	free_if_alloc (item->pref_keyserver);
 	err = gpg_find_key_subpacket (item->key->subkeys->keyid+8, attr, &val);
 	if (!err && val != NULL)
 	    err = decode_subpacket (val, NULL, &item->pref_keyserver, &n);

Modified: trunk/Src/wptKeyCacheDlg.cpp
===================================================================
--- trunk/Src/wptKeyCacheDlg.cpp	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/Src/wptKeyCacheDlg.cpp	2006-05-22 14:21:39 UTC (rev 217)
@@ -31,6 +31,8 @@
 #include "wptW32API.h"
 #include "wptVersion.h"
 
+
+
 /* Dialog box procedure for starting the key cache procedure.
    Actually this dialog is hidden and just kick off the real
    caching process. */

Modified: trunk/Src/wptKeyManagerDlg.cpp
===================================================================
--- trunk/Src/wptKeyManagerDlg.cpp	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/Src/wptKeyManagerDlg.cpp	2006-05-22 14:21:39 UTC (rev 217)
@@ -1068,7 +1068,45 @@
 }
 
 
+/* Reload the key cache. */
 static void
+keycache_reload (HWND dlg) 
+{	
+    refresh_cache_s rcs;
+
+    memset (&rcs, 0, sizeof rcs);
+    rcs.kr_reload = rcs.kr_update = 1;
+    rcs.tr_update = 0;
+    DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,					
+		    keycache_dlg_proc, (LPARAM)&rcs);
+}
+
+
+/* Check if the secret keyring contains at least one 
+   key with ultimate trust.
+   Return value: 0 on success. */
+int
+check_ultimate_trusted_key (gpg_keycache_t _sec)
+{
+    struct keycache_s *n;
+    int nkeys = 0;
+
+    for (n = _sec->item; n; n = n->next) {
+	if (n->pubpart && 
+	    n->pubpart->key->owner_trust == GPGME_VALIDITY_ULTIMATE)
+	    return 0;
+	nkeys++;
+    }
+
+    /* if we do not have any secret keys, it does not make sense
+       to return an error. */
+    if (nkeys == 0)
+	return 0;
+    return -1;
+}
+
+
+static void
 reload_keylist (struct km_info_s *kmi)
 {
     gpg_keycache_t c;
@@ -1186,7 +1224,7 @@
         Header_SetImageList(ListView_GetHeader (kl), glob_imagelist);
         kmi->lv = keylist_load (GetDlgItem (dlg, IDC_KEYMISC_KEYLIST), c, 
 				NULL, KEYLIST_LIST, kmi->keylist_sortby);
-	if (check_ultimate_trusted_key ()) {
+	if (check_ultimate_trusted_key (keycache_get_ctx (0))) {
 	    msg_box (dlg, _("No ultimately trusted key found.\n"
 			    "Please set at least one secret key to ultimate trust."),
 			    _("Key Manager"), MB_WARN);
@@ -1960,9 +1998,11 @@
 	    /* XXX: Implement group manager. */
             return TRUE;
 
+	    /*
 	case IDCANCEL:
 	    EndDialog (dlg, TRUE);
 	    return TRUE;
+	    */
         }
 	
         break;

Modified: trunk/Src/wptKeyPropsDlg.cpp
===================================================================
--- trunk/Src/wptKeyPropsDlg.cpp	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/Src/wptKeyPropsDlg.cpp	2006-05-22 14:21:39 UTC (rev 217)
@@ -22,6 +22,7 @@
 #endif
 
 #include <windows.h>
+#include <assert.h>
 
 #include "resource.h"
 #include "wptErrors.h"
@@ -41,11 +42,12 @@
 static int
 do_check_key (gpgme_key_t key)
 {
-    int okay = 0;
-    okay = key->expired;
-    if (!okay)
-	okay = key->revoked;
-    return okay;
+    int invalid = 0;
+
+    invalid = key->expired;
+    if (!invalid)
+	invalid = key->revoked;
+    return invalid;
 }
 
 
@@ -111,7 +113,7 @@
 	BUG (0);
     img = k.ext->attrib.d;
     imglen = k.ext->attrib.len;
-    if (!k.ext->attrib.validity)
+    if (img && !k.ext->attrib.validity)
 	get_uat_validity (key->subkeys->keyid, &k.ext->attrib.validity);
     *r_valid = k.ext->attrib.validity;
 
@@ -189,10 +191,11 @@
 static bool
 check_for_desig_rev (gpgme_key_t key)
 {
-    winpt_key_s k;
-    memset (&k, 0, sizeof (k));
-    if (!winpt_get_pubkey (key->subkeys->keyid, &k))
-	return k.ext->gloflags.has_desig_rev? true : false;
+    winpt_key_s kk;
+
+    memset (&kk, 0, sizeof (kk));
+    if (!winpt_get_pubkey (key->subkeys->keyid, &kk))
+	return kk.ext->gloflags.has_desig_rev? true : false;
     return false;
 }
 
@@ -205,18 +208,18 @@
 
     if (!k->ext || !k->ext->card_type)
 	return "";
-    _snprintf (buf, sizeof (buf)-1, _("Card-Type: %s\r\n"), k->ext->card_type);
+    _snprintf (buf, DIM (buf)-1, _("Card-Type: %s\r\n"), k->ext->card_type);
     return buf;
 }
 
 
 /* Return 1 if at least one user-ID is valid. */
 static int
-key_is_valid (gpgme_key_t k)
+key_is_valid (gpgme_key_t key)
 {
     gpgme_user_id_t u;
 
-    for (u=k->uids; u; u=u->next) {
+    for (u=key->uids; u; u=u->next) {
 	if (u->validity >= GPGME_VALIDITY_MARGINAL)
 	    return 1;
     }
@@ -237,7 +240,7 @@
     DWORD created, expires;
 
     gpg_keycache_update_attr (k->ext, KC_ATTR_PREFSYM, 0);
-    memset (&sk, 0, sizeof (sk));	
+    memset (&sk, 0, sizeof (sk));
     if (k->key_pair && !winpt_get_seckey (k->keyid, &sk))
 	k->is_protected = sk.is_protected;
     key = k->ext->key;
@@ -270,57 +273,72 @@
 }
 
 
+/* Context to store associated data of the dialog. */
+struct prop_info_s {
+    winpt_key_t key;
+};
+
+
+static void
+on_init_dialog (HWND dlg, WPARAM wparam, LPARAM lparam)
+{
+    gpgme_validity_t valid;
+
+    winpt_key_t k = (winpt_key_t)lparam;
+    SetWindowText (dlg, _("Key Properties"));
+    SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change"));
+    SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers"));
+    SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Password"));
+    SetDlgItemText (dlg, IDC_KEYPROPS_OTINF, _("Ownertrust"));	
+    
+    display_key_info (dlg, k);
+    if (!keyprops_load_photo (dlg, k->ctx, &valid)) {
+	k->has_photo = 1;
+	if (valid < GPGME_VALIDITY_MARGINAL)
+	    SetDlgItemText (dlg, IDC_KEYPROPS_IMGINF, _("Photo-ID not validated."));
+    }    
+    if (k->key_pair)
+        EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE);
+    if (check_for_desig_rev (k->ctx))
+	EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_REVOKERS), TRUE);
+    if (do_check_key (k->ctx))
+	EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_OT_CHANGE), FALSE);
+    center_window (dlg, NULL);  
+    SetForegroundWindow (dlg);
+}
+
+
 /* Dialog box procedure to show the key properties. */
 BOOL CALLBACK
 keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
 {
-    static winpt_key_t k = NULL;
-    gpgme_validity_t valid;
+    struct prop_info_s *prop = NULL;
     const char *inf;
     int rc;
     
-    /* XXX: static variable (k) prevent that the dialog can 
-	    be opened twice. */
+    if (msg != WM_INITDIALOG &&
+	(prop = (prop_info_s*)GetWindowLong (dlg, GWL_USERDATA)) == NULL)
+	return FALSE;
+
     switch (msg) {
     case WM_INITDIALOG:
-        if (!lparam)
-            dlg_fatal_error (dlg, "Could not get dialog param!");
-        k = (winpt_key_t)lparam;
-        SetWindowText (dlg, _("Key Properties"));
-	SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change"));
-	SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers"));
-	SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Password"));
-	SetDlgItemText (dlg, IDC_KEYPROPS_OTINF, _("Ownertrust"));
-	
-	display_key_info (dlg, k);
-	if (!keyprops_load_photo (dlg, k->ctx, &valid)) {
-	    k->has_photo = 1;	
-	    if (valid < GPGME_VALIDITY_MARGINAL)
-		SetDlgItemText (dlg, IDC_KEYPROPS_IMGINF, _("Photo-ID not validated."));
-	}
-        if (k->key_pair)
-            EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE);
-	if (check_for_desig_rev (k->ctx))
-	    EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_REVOKERS), TRUE);
-	if (k->ctx->revoked || k->ctx->expired)
-	    EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_OT_CHANGE), FALSE);
-	center_window (dlg, NULL);
-        SetForegroundWindow (dlg);	
+	assert (lparam != NULL);
+	prop = new struct prop_info_s;
+	prop->key = (winpt_key_t)lparam;
+        SetWindowLong (dlg, GWL_USERDATA, (LONG)prop);
+        on_init_dialog (dlg, wparam, lparam);
         return TRUE;
 
     case WM_DESTROY:
 	remove (get_photo_tmpname (dlg));
+	delete prop;prop=NULL;
+	SetWindowLong (dlg, GWL_USERDATA, 0);
 	break;
       
     case WM_PAINT:
-	if (k->has_photo)
+	if (prop->key->has_photo)
 	    keyprops_show_photo (dlg);
 	break;
-
-    case WM_SYSCOMMAND:
-        if (LOWORD (wparam) == SC_CLOSE)
-            EndDialog (dlg, FALSE);
-        return FALSE;
         
     case WM_COMMAND:
         switch (LOWORD (wparam)) {
@@ -333,13 +351,13 @@
 	    return TRUE;
             
         case IDC_KEYPROPS_OT_CHANGE:
-	    if (do_check_key (k->ctx)) {
+	    if (do_check_key (prop->key->ctx)) {
 		msg_box (dlg, _("The status of this key is 'revoked' or 'expired'.\n"
 				"You cannot change the ownertrust of such keys."),
 				_("WinPT Warning"), MB_ERR);
 		return TRUE;
 	    }
-	    if (!k->key_pair && !key_is_valid (k->ctx)) {
+	    if (!prop->key->key_pair && !key_is_valid (prop->key->ctx)) {
 		rc = msg_box (dlg, _("This is a non-valid key.\n"
 				     "Modifying the ownertrust has no effect on such keys.\n\n"
 			             "Do you really want to continue?"), 
@@ -350,27 +368,30 @@
             rc = dialog_box_param (glob_hinst, 
 				   (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST,
 				    dlg, keyedit_ownertrust_dlg_proc,
-				   (LPARAM)k, _("Change Ownertrust"),
+				   (LPARAM)prop->key, _("Change Ownertrust"),
 				    IDS_WINPT_KEYEDIT_OWNERTRUST);
 	    if (rc == FALSE) /* Cancel */
 		return TRUE;
 
-	    inf = ownertrust_to_string (k->callback.new_val, k->key_pair);
+	    inf = ownertrust_to_string (prop->key->callback.new_val, 
+					prop->key->key_pair);
             SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);
             msg_box (dlg, _("Ownertrust successfully changed."), 
 		     _("GnuPG Status"), MB_OK);
-	    k->update = 1;
+	    prop->key->update = 1;
             return TRUE;
             
         case IDC_KEYPROPS_CHANGE_PWD:
-            keyedit_change_passwd (k, dlg);	    
+            keyedit_change_passwd (prop->key, dlg);	    
             return TRUE;
 
 	case IDC_KEYPROPS_REVOKERS:
-	    k->update = dialog_box_param (
-		glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,
-		key_revokers_dlg_proc, (LPARAM)k, 
-		_("Key Revokers"), IDS_WINPT_KEY_REVOKERS);
+	    prop->key->update = dialog_box_param (glob_hinst, 
+					  (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,
+					  key_revokers_dlg_proc, (LPARAM)prop->key,
+					  _("Key Revokers"), 
+					  IDS_WINPT_KEY_REVOKERS);
+	    UpdateWindow (dlg);
 	    break;
         }
     }

Modified: trunk/Src/wptKeyserverDlg.cpp
===================================================================
--- trunk/Src/wptKeyserverDlg.cpp	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/Src/wptKeyserverDlg.cpp	2006-05-22 14:21:39 UTC (rev 217)
@@ -604,7 +604,10 @@
 	    DestroyMenu (hm);
 	    DestroyMenu (pop);
 	}
-
+	else if (notify->code == LVN_ITEMCHANGED &&
+		 ((LPNMLISTVIEW)lparam)->uNewState) {
+	    /* XXX: disable search for ldap servers. */
+	}
         return TRUE;
         
     case WM_DESTROY:
@@ -618,8 +621,8 @@
     case WM_SYSCOMMAND:
         if (LOWORD (wparam) == SC_CLOSE)
             EndDialog (dlg, TRUE);
-        return FALSE;
-        
+        return FALSE;	
+
     case WM_COMMAND:
         switch (LOWORD (wparam)) {
         case IDC_KEYSERVER_PROXSETT:

Modified: trunk/Src/wptPassphraseCB.cpp
===================================================================
--- trunk/Src/wptPassphraseCB.cpp	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/Src/wptPassphraseCB.cpp	2006-05-22 14:21:39 UTC (rev 217)
@@ -70,8 +70,8 @@
     static passphrase_cb_s *c;
     gpgme_decrypt_result_t res=NULL;
     gpgme_sign_result_t res_sig=NULL;
-    gpgme_key_t key;
     gpgme_recipient_t recip=NULL, r;
+    winpt_key_s key;
     void *item;
     const char *id;
     char *info;
@@ -115,9 +115,9 @@
 	}
 	if (recip != NULL && c->gpg_cmd == GPG_CMD_DECRYPT) {
 	    for (r = recip; r; r = r->next) {
-		get_pubkey (r->keyid, &key);
-		if (key) {
-		    gpgme_user_id_t u = key->uids;
+		memset (&key, 0, sizeof (key));
+		if (!winpt_get_pubkey (r->keyid, &key)) {
+		    gpgme_user_id_t u = key.ctx->uids;
 
 		    id = u->name;
 		    if (!id)
@@ -144,6 +144,7 @@
 		}
 		ListBox_AddString_utf8 (GetDlgItem (dlg, IDC_DECRYPT_LIST), info);
 		free_if_alloc (info);
+		winpt_release_pubkey (&key);
 	    }
 	}
 	else if (c->gpg_cmd == GPG_CMD_DECRYPT)

Modified: trunk/Src/wptUtil.cpp
===================================================================
--- trunk/Src/wptUtil.cpp	2006-05-17 07:13:17 UTC (rev 216)
+++ trunk/Src/wptUtil.cpp	2006-05-22 14:21:39 UTC (rev 217)
@@ -55,7 +55,7 @@
     }
     else /* Find the end of the token.  */
         end = strpbrk (begin, delim);
-    if ( end ){
+    if (end) {
         /* Terminate the token and set *STRINGP past NUL character.  */
         *end++ = '\0';
         *stringp = end;
@@ -132,3 +132,30 @@
     p[pos] = '\0';
     return p;
 }
+
+
+/* Remove %AB sequences from the input buffer @in
+   and store the raw data in @out. */
+void
+unhexify_buffer (const char *in, char **out)
+{
+    char temp[3];
+    size_t pos, i=0;
+
+    *out = (char*)calloc (1, strlen (in)+1);
+    if (!*out)
+	abort ();
+    for (pos = 0; pos < strlen (in); pos++) {
+	if (in[pos] == '%' && in[pos+1] == '%')
+	    (*out)[i++] = '%';
+	else if (in[pos] == '%') {
+	    temp[0] = in[++pos];
+	    temp[1] = in[++pos];
+	    temp[2] = 0;
+	    (*out)[i++] = (char)strtoul (temp, NULL, 16);
+	}
+	else
+	    (*out)[i++] = in[pos];
+    }
+    (*out)[i] = 0;
+}



More information about the Winpt-commits mailing list