/[winpt]/trunk/Src/wptKeylist.cpp
ViewVC logotype

Diff of /trunk/Src/wptKeylist.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 73 by twoaday, Tue Nov 8 07:15:13 2005 UTC revision 214 by twoaday, Sun May 14 18:40:36 2006 UTC
# Line 1  Line 1 
1  /* wptKeylist.cpp - Keylist element  /* wptKeylist.cpp - Keylist element
2   *      Copyright (C) 2001-2005 Timo Schulz   *      Copyright (C) 2001-2006 Timo Schulz
3   *      Copyright (C) 2004 Andreas Jobs   *      Copyright (C) 2004 Andreas Jobs
4   *   *
5   * This file is part of WinPT.   * This file is part of WinPT.
# Line 18  Line 18 
18   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
19   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20   */   */
21    
22  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
23  #include <config.h>  #include <config.h>
24  #endif  #endif
# Line 37  Line 38 
38  #include "wptUTF8.h"  #include "wptUTF8.h"
39  #include "wptRegistry.h"  #include "wptRegistry.h"
40  #include "wptContext.h"  #include "wptContext.h"
41    #include "wptVersion.h"
42    #include "resource.h"
43    
44  #define key_is_useable(key) (!(key)->revoked && !(key)->expired && !(key)->disabled)  #define key_is_useable(key) (!(key)->revoked && !(key)->expired && !(key)->disabled)
45    
 static struct listview_column_s klist_enc[] = {  
     {0, 242, (char *)_("User ID")},  
     {1, 80, (char *)_("Key ID")},  
     {3, 46, (char *)_("Size")},  
     {4, 50, (char *)_("Cipher")},  
     {5, 70, (char *)_("Validity")},  
     {0, 0, NULL}  
 };  
 #define KLIST_ENC_ITEMS (DIM(klist_enc) -1)  
   
 static struct listview_column_s klist[] = {  
     {0, 242, (char *)_("User ID")},  
     {1, 78, (char *)_("Key ID")},  
     {2, 52, (char *)_("Type")},      
     {3, 68, (char *)_("Size")},  
     {4, 66, (char *)_("Cipher")},  
     {5, 70, (char *)_("Validity")},  
     {6, 40, (char *)_("Trust")},  
     {7, 72, (char *)_("Creation")},  
     {0, 0, NULL}  
 };  
 #define KLIST_ITEMS (DIM(klist) - 1)  
   
46  struct key_array_s {  struct key_array_s {
47      char keyid[32];      char keyid[32];
48      int checked;      int checked;
# Line 73  static int find_secret_key (gpgme_key_t Line 52  static int find_secret_key (gpgme_key_t
52    
53    
54  static key_array_s*  static key_array_s*
55  key_array_new( size_t items )  key_array_new (int items)
56  {  {
57      key_array_s *ka;      key_array_s *ka;
58      size_t j;      int j;
59            
60      if( items == 0 )      if (items == 0)
61          return NULL;          return NULL;
62      ka = new key_array_s[items + 1];      ka = new key_array_s[items + 1];
63      if( ka == NULL )      if (!ka)
64          return NULL;              BUG (NULL);
65      for ( j = 0; j < items; j++ )      for (j = 0; j < items; j++)
66          ka[j].checked = 0;          ka[j].checked = 0;
67      return ka;      return ka;
68  } /* key_array_new */  }
69    
70    
71  static void  static void
72  key_array_release( key_array_s *ka )  key_array_release (key_array_s *ka)
73  {  {
74      free_if_alloc( ka );      free_if_alloc (ka);
75  } /* key_array_release */  }
76    
77    
78    /* Check if the keyid @keyid is in the key array @ka.
79       Return value: 1 if it exists, 0 otherwise. */
80  static int  static int
81  key_array_search( key_array_s *ka, size_t items, const char *keyid )  key_array_search (key_array_s *ka, int items, const char *keyid)
82  {  {
83      size_t j;      int j;
84            
85      /* fixme: we need a faster search method */      for (j = 0; j < items; j++) {
86      for( j = 0; j < items; j++ ) {          if (!strcmp (keyid, ka[j].keyid ))
         if( !strcmp( keyid, ka[j].keyid ) )  
87              return 1;                return 1;  
88      }      }
       
89      return 0;      return 0;
90  } /* key_array_search */  }
91    
92    
93  gpgme_user_id_t  gpgme_user_id_t
# Line 173  count_subkeys (gpgme_key_t key) Line 152  count_subkeys (gpgme_key_t key)
152  }  }
153    
154    
155    /* Return the self signature of the key @keyid.
156       If first is set, the first self sig will be returned. */
157  gpgme_key_sig_t  gpgme_key_sig_t
158  get_selfsig (gpgme_user_id_t uid, const char *keyid, int first)  get_selfsig (gpgme_key_sig_t sigs, const char *keyid, int first)
159  {  {
160      gpgme_key_sig_t s, self_sig=NULL;      gpgme_key_sig_t s, self_sig=NULL;
161      long timestamp=0;      long timestamp=0;
162        int off = 0;
163    
164        if (strlen (keyid) == 8)
165            off = 8;
166    
167      for (s = uid->signatures; s; s = s->next) {      for (s = sigs; s; s = s->next) {
168          if (!strcmp (s->keyid+8, keyid) && s->timestamp > timestamp) {          if (!strcmp (s->keyid+off, keyid) && s->timestamp > timestamp) {
169              self_sig = s;              self_sig = s;
170              timestamp = s->timestamp;              timestamp = s->timestamp;
171              if (first)              if (first)
# Line 191  get_selfsig (gpgme_user_id_t uid, const Line 176  get_selfsig (gpgme_user_id_t uid, const
176  }  }
177    
178    
   
179  const char*  const char*
180  get_key_algo (gpgme_key_t key, int keyidx)  get_key_algo (gpgme_key_t key, int keyidx)
181  {  {
# Line 204  get_key_algo (gpgme_key_t key, int keyid Line 188  get_key_algo (gpgme_key_t key, int keyid
188      if (keyidx > 0) {      if (keyidx > 0) {
189          k = get_nth_key (key, keyidx-1);          k = get_nth_key (key, keyidx-1);
190          subalg =  get_key_pubalgo (k->pubkey_algo);          subalg =  get_key_pubalgo (k->pubkey_algo);
191          _snprintf( algo_id, DIM (algo_id)-1, "%s", subalg);          _snprintf (algo_id, DIM (algo_id)-1, "%s", subalg);
192          return algo_id;          return algo_id;
193      }      }
194      strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo));      strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo));
195      n = count_subkeys (key);      n = count_subkeys (key);
196      if (n > 1) {      if (n > 1) {
197          k = get_nth_key (key, n-1);          do {
198                k = get_nth_key (key, --n);
199                if (k->revoked || k->expired)
200                    continue;
201                else
202                    break;
203            } while (n > 0);
204          subalg = get_key_pubalgo (k->pubkey_algo);          subalg = get_key_pubalgo (k->pubkey_algo);
205          _snprintf (algo_id, DIM (algo_id)-1, "%s/%s", alg, subalg);          if (k == key->subkeys)
206                _snprintf (algo_id, DIM (algo_id)-1, "%s", subalg);
207            else
208                _snprintf (algo_id, DIM (algo_id)-1, "%s/%s", alg, subalg);
209          return algo_id;          return algo_id;
210      }      }
211      return get_key_pubalgo (key->subkeys->pubkey_algo);      return get_key_pubalgo (key->subkeys->pubkey_algo);
212  } /* get_key_algo */  }
213    
214    
215  const char*  const char*
# Line 224  get_key_created (long timestamp) Line 217  get_key_created (long timestamp)
217  {  {
218      static char timebuf[128];      static char timebuf[128];
219      struct tm *warp;      struct tm *warp;
220        const char *dat;
221    
222      if (timestamp == 0 || timestamp == -1)      if (timestamp < 1)
223          return "????" "-??" "-??";          return "????" "-??" "-??";
224      warp = localtime( &timestamp );      dat = get_locale_date (timestamp, timebuf, sizeof (timebuf)-1);
225      _snprintf( timebuf, sizeof timebuf - 1, "%04d-%02d-%02d",      if (dat)
226                  warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday );          return dat;
227        warp = localtime (&timestamp);
228        _snprintf (timebuf, sizeof timebuf - 1, "%04d-%02d-%02d",
229                   warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday);
230      return timebuf;      return timebuf;
231  } /* get_key_created */  }
232    
233    
234  /* Return a string presentation of the time @timestamp. */  /* Return a string presentation of the time @timestamp. */
# Line 240  get_key_expire_date (long timestamp) Line 237  get_key_expire_date (long timestamp)
237  {  {
238      static char timebuf[64];      static char timebuf[64];
239      struct tm *warp;      struct tm *warp;
240        const char *dat;
241    
242      if( !timestamp )      if (timestamp == 0)
243          return _("Never");          return _("Never");
244      warp = localtime( &timestamp );      dat = get_locale_date (timestamp, timebuf, sizeof (timebuf)-1);
245        if (dat)
246            return dat;
247        warp = localtime (&timestamp);
248      _snprintf (timebuf, sizeof timebuf -1, "%04d-%02d-%02d",      _snprintf (timebuf, sizeof timebuf -1, "%04d-%02d-%02d",
249                 warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday);                 warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday);
250      return timebuf;      return timebuf;
# Line 260  get_key_type (gpgme_key_t key) Line 261  get_key_type (gpgme_key_t key)
261      else if (type == 2)      else if (type == 2)
262          return _("Key Pair (Card)");          return _("Key Pair (Card)");
263      return _("Public Key");      return _("Public Key");
264  } /* get_key_type */  }
265    
266    
267  const char*  const char*
# Line 281  get_key_size (gpgme_key_t key, int keyid Line 282  get_key_size (gpgme_key_t key, int keyid
282      if (n > 1) {      if (n > 1) {
283          k = get_nth_key (key, n-1);          k = get_nth_key (key, n-1);
284          size_sub = k->length;          size_sub = k->length;
285          _snprintf( size_id, sizeof (size_id) - 1, "%d/%d", size_main, size_sub );          _snprintf (size_id, sizeof (size_id) - 1, "%d/%d",
286                        size_main, size_sub);
287          return size_id;          return size_id;
288      }      }
289      _snprintf( size_id, sizeof (size_id) - 1, "%d", size_main );      _snprintf( size_id, sizeof (size_id) - 1, "%d", size_main );
290      return size_id;      return size_id;
291  } /* get_key_size */  }
292    
293    
294    const char*
295    get_key_pubalgo2 (gpgme_pubkey_algo_t alg)
296    {
297        switch (alg) {
298        case GPGME_PK_DSA: return "D";
299        case GPGME_PK_RSA: return "R";
300        case GPGME_PK_ELG: return "G";
301        default: return "?";
302        }
303        return "?";
304    }
305    
306    
307  const char*  const char*
# Line 296  get_key_pubalgo (gpgme_pubkey_algo_t alg Line 311  get_key_pubalgo (gpgme_pubkey_algo_t alg
311      case GPGME_PK_DSA: return "DSA";      case GPGME_PK_DSA: return "DSA";
312      case GPGME_PK_ELG:      case GPGME_PK_ELG:
313      case GPGME_PK_ELG_E: return "ELG";      case GPGME_PK_ELG_E: return "ELG";
314        case 0: /* XXX: gpgme returned pubkey algo 0 for a RSA made sig. */
315      case GPGME_PK_RSA: return "RSA";      case GPGME_PK_RSA: return "RSA";
316      default: return "???";      default: return "???";
317      }      }
318      return "???";      return "???";
319  }  }
320    
321  const char *  const char*
322  get_key_fpr (gpgme_key_t key)  get_key_fpr (gpgme_key_t key)
323  {  {
324      static char fpr_md[64];      static char fpr_md[64];
# Line 331  get_key_fpr (gpgme_key_t key) Line 347  get_key_fpr (gpgme_key_t key)
347          }          }
348      }      }
349      return fpr_md;      return fpr_md;
350  } /* get_key_fpr */  }
351    
352    
353  const char *  /* Extract the key ID from the fingerprint.
354       A long ID will be converted into a short ID. */
355    const char*
356    get_keyid_from_fpr (const char *fpr)
357    {
358        if (!fpr)
359            return "????????";
360        if (strlen (fpr) == 40)
361            fpr += 32;
362        else if (strlen (fpr) == 32)
363            fpr += 24;
364        else if (strlen (fpr) == 16)
365            fpr += 8;
366        else
367            return "????????";
368        return fpr;
369    }
370    
371    
372    const char*
373  get_key_trust2 (gpgme_key_t key, int val, int uididx, int listmode)  get_key_trust2 (gpgme_key_t key, int val, int uididx, int listmode)
374  {  {
375      if (key)      if (key)
# Line 342  get_key_trust2 (gpgme_key_t key, int val Line 377  get_key_trust2 (gpgme_key_t key, int val
377      switch (val) {      switch (val) {
378      case GPGME_VALIDITY_UNKNOWN:      case GPGME_VALIDITY_UNKNOWN:
379      case GPGME_VALIDITY_UNDEFINED:          case GPGME_VALIDITY_UNDEFINED:    
380          return "None";          return _("None");
381      case GPGME_VALIDITY_NEVER:          case GPGME_VALIDITY_NEVER:    
382          return "Never";          return _("Never");
383      case GPGME_VALIDITY_MARGINAL:      case GPGME_VALIDITY_MARGINAL:
384          return "Marginal";          return _("Marginal");
385      case GPGME_VALIDITY_FULL:      case GPGME_VALIDITY_FULL:
386            return _("Full");
387      case GPGME_VALIDITY_ULTIMATE:      case GPGME_VALIDITY_ULTIMATE:
388          return "Full";          return _("Ultimate");
389      }      }
390      return "";      return "";
391  }  }
392    
393    
394  const char *  const char*
395  get_key_trust (gpgme_key_t key, int uididx, int listmode)  get_key_trust (gpgme_key_t key, int uididx, int listmode)
396  {  {
397      return get_key_trust2 (key, 0, uididx, listmode);      return get_key_trust2 (key, 0, uididx, listmode);
398  }  }
399    
400    
401  const char *  const char*
402  get_key_trust_str (int val)  get_key_trust_str (int val)
403  {  {
404      return get_key_trust2 (NULL, val, 0, 0);      return get_key_trust2 (NULL, val, 0, 0);
# Line 380  get_key_status (gpgme_key_t key, int uid Line 416  get_key_status (gpgme_key_t key, int uid
416      if (uididx < 0 || count_userids (key) > uididx)      if (uididx < 0 || count_userids (key) > uididx)
417          uididx = 0;          uididx = 0;
418      if (listmode) {      if (listmode) {
419          const char *s;          const char *s;
         
420          if (key->revoked)          if (key->revoked)
421              s = _("Revoked");              s = _("Revoked");
422          else if (key->expired)          else if (key->expired)
423              s = _("Expired");              s = _("Expired");
424          else if (key->disabled)          else if (key->disabled)
425              s = _("Disabled");              s = _("Disabled");
426          else          else
427            s = "";              s = "";
           
428          /* if the key has a special status, we don't continue to figure out          /* if the key has a special status, we don't continue to figure out
429             what any user-id validities. */             the user-id validities. */
430          if (*s)          if (*s)
431              return m_strdup (s);              return m_strdup (s);
432      }      }
# Line 403  get_key_status (gpgme_key_t key, int uid Line 437  get_key_status (gpgme_key_t key, int uid
437  }  }
438    
439    
440    /* Return human readable description of the key @key. */
441    char*
442    get_key_desc (gpgme_key_t key)
443    {
444        gpgme_key_t sk;
445        const char *state, *alg, *type;
446        char *p;
447    
448        /* XXX: problems with the German translation. */
449        state = "";
450        if (key->disabled)
451            state = _("Disabled");
452        if (key->expired)
453            state = _("Expired");
454        if (key->revoked)
455            state = _("Revoked");
456        alg = "OpenPGP";
457        if (strlen (key->subkeys->fpr) == 32)
458            alg = "RSA Legacy";
459        type = _("public key");
460        if (!get_seckey (key->subkeys->keyid+8, &sk))
461            type = _("key pair");
462        p = new char[strlen (state) + strlen (alg) + strlen (type) + 4 + 1];
463        if (!p)
464            BUG (0);
465        sprintf (p, "%s %s %s", state, alg, type);
466        return p;
467    }
468    
469    
470  /* Integer comparsion of @a and @b.  /* Integer comparsion of @a and @b.
471     Return values: same as in strcmp. */     Return values: same as in strcmp. */
472  static inline int  static inline int
# Line 424  get_ext_validity (gpgme_key_t k) Line 488  get_ext_validity (gpgme_key_t k)
488          return GPGME_VALIDITY_ULTIMATE+1;          return GPGME_VALIDITY_ULTIMATE+1;
489      else if (k->expired)      else if (k->expired)
490          return GPGME_VALIDITY_ULTIMATE+2;          return GPGME_VALIDITY_ULTIMATE+2;
491        else if (k->disabled)
492            return GPGME_VALIDITY_ULTIMATE+3;
493      return k->uids->validity;      return k->uids->validity;
494  }  }
495    
# Line 432  get_ext_validity (gpgme_key_t k) Line 498  get_ext_validity (gpgme_key_t k)
498  static int CALLBACK  static int CALLBACK
499  keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby)  keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby)
500  {  {
501        struct keycache_s *aa, *bb;
502      gpgme_key_t a, b;      gpgme_key_t a, b;
503      int cmpresult = 0;      int cmpresult = 0;
504            
505      a = (gpgme_key_t)first;      aa = (struct keycache_s *)first;
506      b = (gpgme_key_t)second;      bb = (struct keycache_s *)second;
507      if (!a || !b)      if (!aa || !bb)
508          BUG (NULL);          BUG (NULL);
509        a = aa->key;
510        b = bb->key;
511            
512      switch (sortby & ~KEYLIST_SORT_DESC) {      switch (sortby & ~KEYLIST_SORT_DESC) {
513      case KEY_SORT_USERID:      case KEY_SORT_USERID:
# Line 491  keylist_cmp_cb (LPARAM first, LPARAM sec Line 560  keylist_cmp_cb (LPARAM first, LPARAM sec
560  }  }
561    
562    
 /* Return the validity of the group @grp. */  
 static const char*  
 calc_validity (gpg_group_t grp)  
 {  
     int valid=0;  
     gpg_member_t mbr;  
     gpgme_key_t key;  
   
     for (mbr = grp->list; mbr; mbr = mbr->next) {  
         if (get_pubkey (mbr->name, &key))  
             continue;  
         valid = key->uids->validity;  
         switch (valid) {  
         case GPGME_VALIDITY_MARGINAL:  
         case GPGME_VALIDITY_NEVER:  
         case GPGME_VALIDITY_UNDEFINED:  
             return get_key_trust2 (NULL, valid, 0, 0);  
         }  
     }  
     return _("Full");  
 }  
   
   
563  int  int
564  keylist_add_groups( listview_ctrl_t lv )  keylist_add_groups (listview_ctrl_t lv)
565  {  {
 #if 0  
     gpg_optfile_t gh;  
     gpg_group_t grp;  
     const char *valid;  
   
     gh = km_groupdb_open( );      
     if( !gh )    
         return WPTERR_FILE_OPEN;  
   
     for( grp = gh->grp; grp; grp = grp->next ) {  
         valid = calc_validity( grp );  
         listview_add_item( lv, " " );    
         listview_add_sub_item( lv, 0, 0, grp->name );    
         listview_add_sub_item( lv, 0, 1, "gpg_group_t" );        
         listview_add_sub_item( lv, 0, 2, "" );    
         listview_add_sub_item( lv, 0, 3, "Unknown" );  
         listview_add_sub_item( lv, 0, 4, valid?valid : "Unknown" );  
     }  
 #endif  
566      return 0;      return 0;
567  } /* keylist_add_groups */  }
568    
569    
570  /* Create a listview for listing keys. Use the mode given in @mode  /* Create a listview for listing keys. Use the mode given in @mode
# Line 545  keylist_add_groups( listview_ctrl_t lv ) Line 572  keylist_add_groups( listview_ctrl_t lv )
572  static int  static int
573  keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode)  keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode)
574  {  {
575        struct listview_column_s klist_enc[] = {
576        {0, 242, (char *)_("User ID")},
577        {1, 80, (char *)_("Key ID")},
578        {3, 46, (char *)_("Size")},
579        {4, 50, (char *)_("Cipher")},
580        {5, 70, (char *)_("Validity")},
581        {0, 0, NULL}
582        };
583        struct listview_column_s klist[] = {
584        {0, 240, (char *)_("User ID")},
585        {1, 78, (char *)_("Key ID")},
586        {2, 52, (char *)_("Type")},    
587        {3, 66, (char *)_("Size")},
588        {4, 60, (char *)_("Cipher")},
589        {5, 66, (char *)_("Validity")},
590        {6, 58, (char *)_("Trust")},
591        {7, 72, (char *)_("Creation")},
592        {0, 0, NULL}
593        };
594        HICON ico[2];
595      listview_ctrl_t lv;      listview_ctrl_t lv;
596      listview_column_t col;      listview_column_t col;
597      int j, n = 0;      int j, n = 0, ext_chk = 0;
     int rc = 0;  
598            
599      rc = listview_new (&lv);      listview_new (&lv, ctrl);
600      if( rc )      if (mode & KEYLIST_ENCRYPT_MIN) {
         return rc;  
       
     lv->ctrl = ctrl;  
     if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) {  
601          col = klist_enc;          col = klist_enc;
602          n = KLIST_ENC_ITEMS;          n = (DIM(klist_enc) -1);
603            ext_chk = 1;
604      }        }  
605      else if ((mode & KEYLIST_SIGN)) {      else if ((mode & KEYLIST_SIGN)) {
606          col = klist_enc;          col = klist_enc;
607          n = KLIST_ENC_ITEMS - 1;          n = (DIM(klist_enc) - 1) - 1;
608            ext_chk = 1;
609      }      }
610      else {      else {
611          col = klist;          col = klist;
612          n = KLIST_ITEMS;          n = (DIM(klist) - 1);
613      }      }
614            
615      for( j = 0; j < n; j++ )          for (j = 0; j < n; j++)
616          listview_add_column( lv, &col[j] );              listview_add_column (lv, &col[j]);    
617      listview_set_ext_style( lv );      listview_set_ext_style (lv);
618        if (ext_chk)
619            listview_set_chkbox_style (lv);
620        ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY);
621        ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR);
622        listview_set_image_list (lv, 22, 14, ico, 2);
623        listview_del_all_items (lv);
624    
625      *r_lv = lv;      *r_lv = lv;
       
626      return 0;      return 0;
627  }  }
628    
# Line 583  keylist_load_keycache (listview_ctrl_t l Line 633  keylist_load_keycache (listview_ctrl_t l
633  {  {
634      gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);      gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
635      gpgme_key_t key, skey;      gpgme_key_t key, skey;
636      const char * keyid;      struct keycache_s *c;
637        const char *keyid;
638    
639      if (pubkc && seckc) {      if (pubkc && seckc) {
640          gpg_keycache_rewind (pubkc);          gpg_keycache_rewind (pubkc);
641          while (!gpg_keycache_next_key (pubkc, 0, &key)) {          while (!gpg_keycache_next_key2 (pubkc, 0, &c, &key)) {
642              keyid = key->subkeys->keyid;              keyid = key->subkeys->keyid;
643              if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey))              if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey))
644                  keylist_add_key (lv, mode, key);                  keylist_add_key (lv, mode, c, key);
645          }                }      
646      }      }
647      else if (pubkc) {      else if (pubkc) {
648          gpg_keycache_rewind (pubkc);          gpg_keycache_rewind (pubkc);
649          while (!err) {              while (!err) {    
650              err = gpg_keycache_next_key (pubkc, 0, &key);              err = gpg_keycache_next_key2 (pubkc, 0, &c, &key);
651              if (!err)              if (!err)
652                  keylist_add_key (lv, mode, key);                  keylist_add_key (lv, mode, c, key);
653          }          }
654      }      }
655  }  }
# Line 618  keylist_load (HWND ctrl, gpg_keycache_t Line 669  keylist_load (HWND ctrl, gpg_keycache_t
669          return NULL;                      return NULL;            
670      keylist_load_keycache (lv, mode, pubkc, seckc);      keylist_load_keycache (lv, mode, pubkc, seckc);
671      keylist_sort (lv, sortby);      keylist_sort (lv, sortby);
672      if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN))      if (mode & KEYLIST_ENCRYPT_MIN)
673          keylist_add_groups (lv);          keylist_add_groups (lv);
674      return lv;      return lv;
675  }  }
# Line 628  keylist_load (HWND ctrl, gpg_keycache_t Line 679  keylist_load (HWND ctrl, gpg_keycache_t
679  int  int
680  keylist_reload (listview_ctrl_t lv, gpg_keycache_t pubkc, int mode, int sortby)  keylist_reload (listview_ctrl_t lv, gpg_keycache_t pubkc, int mode, int sortby)
681  {  {
682      listview_del_all (lv);      listview_del_all_items (lv);
683      keylist_load_keycache( lv, mode, pubkc, NULL );      keylist_load_keycache (lv, mode, pubkc, NULL);
684      keylist_sort (lv, sortby);      keylist_sort (lv, sortby);
685      return 0;      return 0;
686  }  }
# Line 664  find_secret_key (gpgme_key_t key) Line 715  find_secret_key (gpgme_key_t key)
715    
716    
717  static int  static int
718  do_addkey (listview_ctrl_t lv, gpgme_key_t key, int uididx, int keyidx, int list)  do_addkey (listview_ctrl_t lv, struct keycache_s *ctx, gpgme_key_t key,
719               int uididx, int keyidx, int list)
720  {      {    
721      LV_ITEM lvi;      LV_ITEM lvi;
722      gpgme_user_id_t u;      gpgme_user_id_t u;
# Line 677  do_addkey (listview_ctrl_t lv, gpgme_key Line 729  do_addkey (listview_ctrl_t lv, gpgme_key
729      /* we check the pubkey algorithm here to make sure that no ElGamal      /* we check the pubkey algorithm here to make sure that no ElGamal
730         sign+encrypt key is used in _any_ mode */         sign+encrypt key is used in _any_ mode */
731      if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) {      if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) {
732          log_debug ("ElGamal (E+S) key found: %s (%s)\n",          log_debug ("ElGamal (E+S) key found: %s (%s)\n",
733                     key->uids->name, key->subkeys->keyid);                     key->uids->name, key->subkeys->keyid);
734          return 0;          return 0;
735      }      }
736    
737                if (listview_add_item2 (lv, " ", (void *)ctx))
     if (listview_add_item2 (lv, " ", (void *)key))        
738          return WPTERR_GENERAL;          return WPTERR_GENERAL;
739            
740      attr = key->uids->uid;      attr = ctx->uids->uid;
741      memset (&lvi, 0, sizeof lvi);      memset (&lvi, 0, sizeof lvi);
742      lvi.mask = LVIF_TEXT | LVIF_PARAM;      lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
743      lvi.pszText = (char *)attr;      lvi.pszText = (char *)attr;
744      lvi.lParam = (LPARAM )key;      lvi.iImage = find_secret_key (key)? 1 : 0;
745      if (ListView_SetItem( lv->ctrl, &lvi ) == FALSE)      lvi.lParam = (LPARAM )ctx;
746        if (ListView_SetItem (lv->ctrl, &lvi) == FALSE)
747          return WPTERR_GENERAL;          return WPTERR_GENERAL;
748                    
749      if (uididx == -1) { /* request the primary user-id of the key. */      if (uididx == -1) { /* request the primary user-id of the key. */
750          attr = key->uids->uid;          attr = ctx->uids->uid;
751          uididx = 0;          uididx = 0;
752      }      }
753      else {      else {
754          u = get_nth_userid (key, uididx);          u = get_nth_userid (key, uididx);
755          if (!u || u->revoked || uididx < 0)          if (!u || u->revoked || uididx < 0)
756              uididx = 0; /* fixme: this happen sometimes but it's illegal! (<0) */              uididx = 0;
757          u = get_nth_userid (key, uididx);          u = get_nth_userid (key, uididx);
         /*attr = key->uids->uid; XXX*/  
758          attr = u->uid;          attr = u->uid;
759      }      }
760      if (attr == NULL || strlen (attr) < 5) { /* normal userids are >= 5 chars */      if (attr == NULL || strlen (attr) < 5) { /* normal userids are > 5 chars */
761          attr = _("Invalid User ID");          attr = _("Invalid User ID");
762          listview_add_sub_item (lv, 0, idx++, attr);          listview_add_sub_item (lv, 0, idx++, attr);
763      }        }  
764      else {      else        
765          char *uid = utf8_to_wincp (attr, strlen (attr));          listview_add_sub_item (lv, 0, idx++, attr);
         if (uid) {  
             listview_add_sub_item (lv, 0, idx++, uid);  
             free (uid);  
         }  
     }  
766      k = get_nth_key (key, keyidx);      k = get_nth_key (key, keyidx);
767      if (k && k->keyid) {      if (k && k->keyid) {
768          _snprintf (fmt, sizeof fmt -1, "0x%s", k->keyid + 8);          _snprintf (fmt, sizeof fmt -1, "0x%s", k->keyid + 8);
769          listview_add_sub_item( lv, 0, idx++, fmt );          listview_add_sub_item (lv, 0, idx++, fmt);
770      }      }
771      if (list > 0) {      if (list > 0) {
772          key_attr = find_secret_key (key);          key_attr = find_secret_key (key);
# Line 740  do_addkey (listview_ctrl_t lv, gpgme_key Line 786  do_addkey (listview_ctrl_t lv, gpgme_key
786          if (attr)          if (attr)
787              listview_add_sub_item( lv, 0, idx++, attr);              listview_add_sub_item( lv, 0, idx++, attr);
788      }      }
789      if( lv->cols >= 4 ) {      if (lv->cols >= 4) {
790          p = get_key_status( key, uididx, list > 0? 1 : 0 );          p = get_key_status( key, uididx, list > 0? 1 : 0 );
791          if (!p)          if (!p)
792              return WPTERR_GENERAL;              return WPTERR_GENERAL;
# Line 764  do_addkey (listview_ctrl_t lv, gpgme_key Line 810  do_addkey (listview_ctrl_t lv, gpgme_key
810  }  }
811    
812    
813    /* Update a single column @col but for each element in the
814       listview @lv. */
815  void  void
816  keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key)  keylist_upd_col (listview_ctrl_t lv, int col)
817  {  {
818        gpgme_key_t key;
819      const char *s;      const char *s;
820        char buf[32], *p;
821        int i;
822    
823        for (i=0; i < listview_count_items (lv, 0); i++) {
824            key = km_get_key_ptr (lv, i, NULL);
825            if (!key)
826                continue;
827            switch (col) {
828            case KM_COL_KEYID:
829                _snprintf (buf, sizeof (buf)-1, "0x%s", key->subkeys->keyid+8);
830                listview_add_sub_item (lv, i, col, buf);
831                break;
832    
833            case KM_COL_CIPHER:
834                s = get_key_algo (key, 0);
835                listview_add_sub_item (lv, i, col, s);
836                break;
837    
838            case KM_COL_TYPE:
839                s = find_secret_key (key)? "pub/sec" : "pub";
840                listview_add_sub_item (lv, i, col, s);
841                break;
842    
843            case KM_COL_CREAT:
844                s = get_key_created (key->subkeys->timestamp);
845                listview_add_sub_item (lv, i, col, s);
846                break;
847    
848            case KM_COL_DESC:
849                p = get_key_desc (key);
850                listview_add_sub_item (lv, i, col, p);
851                free_if_alloc (p);
852                break;
853            }
854        }
855    }
856    
857    
858    /* Update the listview item at position @pos with the data from
859       the key @key. */
860    void
861    keylist_upd_key (listview_ctrl_t lv, int pos,
862                     struct keycache_s *ctx, gpgme_key_t key)
863    {
864        const char *s;
865        char *p;
866      char tmp[32];      char tmp[32];
867    
868      listview_set_item2 (lv, pos, (void *)key);      listview_set_item2 (lv, pos, (void *)ctx);
869      /* the only mode we support is KYLIST_LIST in the Key Manager */      /* the only mode we support is KEYLIST_LIST in the Key Manager */
870            
871      s = key->uids->uid;      s = ctx->uids->uid;
872      if (s)      if (s)
873          listview_add_sub_item (lv, pos, 0, s);          listview_add_sub_item (lv, pos, KM_COL_UID, s);
874    
875      s = key->subkeys->keyid;      s = key->subkeys->keyid;
876      if (s) {      if (s) {
877          sprintf (tmp, "0x%s", s+8);          sprintf (tmp, "0x%s", s+8);
878          listview_add_sub_item (lv, pos, 1, tmp);          listview_add_sub_item (lv, pos, KM_COL_KEYID, tmp);
879      }      }
880    
881      s = find_secret_key (key)? "pub/sec" : "pub";      s = find_secret_key (key)? "pub/sec" : "pub";
882      listview_add_sub_item (lv, pos, 2, s);      listview_add_sub_item (lv, pos, KM_COL_TYPE, s);
883    
884      s = get_key_size (key, 0);      s = get_key_size (key, 0);
885      if (s)      if (s)
886          listview_add_sub_item (lv, pos, 3, s);          listview_add_sub_item (lv, pos, KM_COL_SIZE, s);
887    
888      s = get_key_algo (key, 0);      s = get_key_algo (key, 0);
889      if (s)      if (s)
890          listview_add_sub_item (lv, pos, 4, s);          listview_add_sub_item (lv, pos, KM_COL_CIPHER, s);
891    
892      s = get_key_status (key, 0, 1);      p = get_key_status (key, 0, 1);
893      if (s)      if (p) {
894          listview_add_sub_item (lv, pos, 5, s);          listview_add_sub_item (lv, pos, KM_COL_VALID, p);
895            free_if_alloc (p);
896        }
897    
898      s = get_key_trust (key, 0, 1);      s = get_key_trust (key, 0, 1);
899      if (s)      if (s)
900          listview_add_sub_item (lv, pos, 6, s);          listview_add_sub_item (lv, pos, KM_COL_TRUST, s);
901    
902      long t = key->subkeys->timestamp;      long t = key->subkeys->timestamp;
903      s = get_key_created (t);      s = get_key_created (t);
904      if (s)      if (s)
905          listview_add_sub_item (lv, pos, 7, s);          listview_add_sub_item (lv, pos, KM_COL_CREAT, s);
906  }  }
907    
908    
909  int  int
910  keylist_add_key (listview_ctrl_t lv, int mode, gpgme_key_t key)  keylist_add_key (listview_ctrl_t lv, int mode,
911                     struct keycache_s *ctx, gpgme_key_t key)
912  {  {
913      int uids, rc = 0, i;      int uids, rc = 0, i;
914      gpgme_subkey_t k;      gpgme_subkey_t k;
915    
916      /* if the entire key is disabled, just return. */      /* if the entire key is disabled, just return. */
917      if (key->disabled)      if (key->disabled && !(mode & KEYLIST_LIST))
918          return 0;          return 0;
919    
920      for (k=key->subkeys, i = 0; i < count_subkeys (key); i++, k=k->next) {      for (k=key->subkeys, i = 0; i < count_subkeys (key); i++, k=k->next) {
# Line 827  keylist_add_key (listview_ctrl_t lv, int Line 925  keylist_add_key (listview_ctrl_t lv, int
925    
926          if (mode & KEYLIST_ALL) {          if (mode & KEYLIST_ALL) {
927              uids = count_userids (key);              uids = count_userids (key);
928              rc = do_addkey (lv, key, uids, i, 0);              rc = do_addkey (lv, ctx, key, uids, i, 0);
929              if( rc )              if (rc)
930                  return rc;                  return rc;
931          }          }
932          else if (mode & KEYLIST_LIST)          else if (mode & KEYLIST_LIST)
933              return do_addkey (lv, key, -1, i, 1);              return do_addkey (lv, ctx, key, -1, i, 1);
934          else if (mode & KEYLIST_ENCRYPT) {          else if (mode & KEYLIST_ENCRYPT) {
935              if (k->can_encrypt && key_is_useable (k)) {              if (k->can_encrypt && key_is_useable (k)) {
936                  if (mode & KEYLIST_FLAG_FILE) {                  if (mode & KEYLIST_FLAG_FILE) {
937                      rc = do_addkey (lv, key, -1, i, -1);                      rc = do_addkey (lv, ctx, key, -1, i, -1);
938                      if (rc)                      if (rc)
939                          return rc;                          return rc;
940                  }                  }
941                  else {                  else {
942                      for( uids = 0;  uids < count_userids (key); uids++ ) {                      for (uids = 0;  uids < count_userids (key); uids++) {
943                          rc = do_addkey( lv, key, uids, i, -1 );                          rc = do_addkey (lv, ctx, key, uids, i, -1);
944                          if( rc )                          if (rc)
945                              return rc;                              return rc;
946                      }                      }
947                  }                  }
# Line 852  keylist_add_key (listview_ctrl_t lv, int Line 950  keylist_add_key (listview_ctrl_t lv, int
950          else if (mode & KEYLIST_ENCRYPT_MIN) {          else if (mode & KEYLIST_ENCRYPT_MIN) {
951              if( k->can_encrypt && key_is_useable (k))              if( k->can_encrypt && key_is_useable (k))
952              {              {
953                  rc = do_addkey (lv, key, -1, i, -1);                  rc = do_addkey (lv, ctx, key, -1, i, -1);
954                  return rc;                  return rc;
955              }              }
956          }                }      
# Line 860  keylist_add_key (listview_ctrl_t lv, int Line 958  keylist_add_key (listview_ctrl_t lv, int
958              if (k->can_sign              if (k->can_sign
959                  && find_secret_key (key)                  && find_secret_key (key)
960                  && key_is_useable (k)) {                  && key_is_useable (k)) {
961                  rc = do_addkey (lv, key, -1, i, -1);                  rc = do_addkey (lv, ctx, key, -1, i, -1);
962                  if (rc)                  if (rc)
963                      return rc;                        return rc;  
964              }              }
# Line 868  keylist_add_key (listview_ctrl_t lv, int Line 966  keylist_add_key (listview_ctrl_t lv, int
966      }      }
967    
968      return rc;        return rc;  
969  } /* keylist_add_key */  }
970    
971    
972  int  int
973  keylist_sort (listview_ctrl_t lv, int sortby)  keylist_sort (listview_ctrl_t lv, int sortby)
974  {        {
975      return listview_sort_items (lv, sortby, keylist_cmp_cb);      return listview_sort_items (lv, sortby, keylist_cmp_cb);
976  }  }
977    
978    
979  /* Check that the validity @validity is at least >= marginal. */  /* Check that the validity @validity is at least >= marginal. */
980  static int  static int
981  key_check_validity (const char *validity)  key_check_validity (gpgme_key_t key)
982  {      {
983      if (strstr (validity, "Unknown") ||      gpgme_user_id_t u;
984          strstr (validity, "Undefined") ||  
985          strstr (validity, "Never") ||      for (u=key->uids; u; u =u->next) {
986          strstr (validity, "None"))          if (u->validity >= GPGME_VALIDITY_MARGINAL)
987          return 0;                return -1;
988      return 1;      }
989    
990        return 0;
991  }  }
992    
993    
# Line 898  key_check_validity (const char *validity Line 998  key_check_validity (const char *validity
998  gpgme_key_t*  gpgme_key_t*
999  keylist_get_recipients (listview_ctrl_t lv, int *r_force_trust, int *r_count)  keylist_get_recipients (listview_ctrl_t lv, int *r_force_trust, int *r_count)
1000  {  {
1001        key_array_s *ka = NULL;
1002        keycache_s *c;
1003        gpgme_key_t *keybuf, key;
1004      int count = 0, force_trust = 0;      int count = 0, force_trust = 0;
1005      int n, j, ka_pos = 0, rc = 0;      int n, j, ka_pos = 0, rc = 0;
1006      int k_pos=0;      int k_pos=0;
     char keyid[32], valid[32], id[100];  
     key_array_s *ka = NULL;  
     gpgme_key_t *keybuf;  
1007    
1008      n = listview_count_items( lv, 0 );      n = listview_count_items (lv, 0);
1009            
1010      ka = key_array_new( n );      ka = key_array_new (n);
1011      if (!ka)      if (!ka)
1012          BUG (NULL);          BUG (NULL);
1013    
1014      keybuf = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t));      keybuf = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t));
1015      if (!keybuf)      if (!keybuf)
1016          BUG (NULL);          BUG (NULL);
1017                    
1018      for( j = 0; j < n; j++ ) {      for (j = 0; j < n; j++) {
1019          if( listview_get_item_state (lv, j) || n == 1) {          if (listview_get_item_state (lv, j) || n == 1) {
1020              listview_get_item_text (lv, j, 0, id, sizeof id-1);              key = km_get_key_ptr (lv, j, &c);
1021              listview_get_item_text (lv, j, 1, keyid, sizeof keyid - 1);                              if (!key)
1022              listview_get_item_text (lv, j, 4, valid, sizeof valid -1);                  BUG (0);
1023              if( !key_check_validity (valid)              if (!key_check_validity (key) &&
1024                   && !key_array_search( ka, ka_pos, keyid )) {                  !key_array_search (ka, ka_pos, key->subkeys->keyid)) {
1025                  char *warn = new char[512+strlen (id) + 1];                  char *warn = new char[512+strlen (c->uids->uid) + 1];
1026                  if (!warn)                  if (!warn)
1027                      BUG (0);                      BUG (0);
1028                  sprintf (warn,                  sprintf (warn,
# Line 930  keylist_get_recipients (listview_ctrl_t Line 1030  keylist_get_recipients (listview_ctrl_t
1030                        "named in the user ID.  If you *really* know what you are\n"                        "named in the user ID.  If you *really* know what you are\n"
1031                        "doing, you may answer the next question with yes\n"                        "doing, you may answer the next question with yes\n"
1032                        "\n"                        "\n"
1033                        "Use \"%s\" anyway?"), id);                        "Use \"%s\" anyway?"), c->uids->uid);
1034                  if (reg_prefs.always_trust)                  if (reg_prefs.always_trust)
1035                      rc = IDYES;                      rc = IDYES;
1036                  else                  else
1037                      rc = msg_box (NULL, warn, _("Recipients"), MB_ERR_ASK);                      rc = msg_box (NULL, warn, _("Recipients"), MB_ERR_ASK);
1038                  if (rc == IDYES) {                  if (rc == IDYES) {
1039                      gpgme_key_t k;                      keybuf[k_pos++] = key;
                     get_pubkey (keyid, &k);  
                     keybuf[k_pos++] = k;  
1040                      force_trust++;                      force_trust++;
1041                      ka[ka_pos].checked = 1;                      ka[ka_pos].checked = 1;
1042                      strcpy (ka[ka_pos++].keyid, keyid);                      strcpy (ka[ka_pos++].keyid, key->subkeys->keyid);
1043                      count++;                      count++;
1044                  }                  }
1045                  free_if_alloc (warn);                  free_if_alloc (warn);
1046              }              }
1047              else {              else {
1048                  gpgme_key_t k;                  keybuf[k_pos++] = key;
                 listview_get_item_text( lv, j, 1, keyid, sizeof keyid -1 );  
                 get_pubkey (keyid, &k);  
                 keybuf[k_pos++] = k;  
1049                  count++;                          count++;        
1050              }              }
1051          }          }
# Line 965  keylist_get_recipients (listview_ctrl_t Line 1060  keylist_get_recipients (listview_ctrl_t
1060    
1061    
1062  static int  static int
1063  keylist_get_keyflags (const char *buf, size_t buflen)  keylist_get_keyflags (gpgme_key_t key)
1064  {  {
1065      int c = 0, flags = 0;      int flags = KEYFLAG_NONE;
1066    
1067      if( *buf != '[' )      if (key->revoked)
1068          return KEYFLAG_NONE;          flags |= KEYFLAG_REVOKED;
1069      while (buf && c != ']')      if (key->expired)
1070      {          flags |= KEYFLAG_EXPIRED;
1071          c = *buf++;      if (key->disabled)
1072          if (c == 'R')          flags |= KEYFLAG_DISABLED;
             flags |= KEYFLAG_REVOKED;  
         if (c == 'E')  
             flags |= KEYFLAG_EXPIRED;  
         if (c == 'D')  
             flags |= KEYFLAG_DISABLED;  
     }  
1073    
1074      return flags;      return flags;
1075  } /* keylist_get_keyflags */  }
1076    
1077    
1078  gpgme_key_t*  gpgme_key_t*
1079  keylist_enum_recipients (listview_ctrl_t lv,  int listype, int *r_count)  keylist_enum_recipients (listview_ctrl_t lv,  int listype, int *r_count)
1080  {  {
1081      gpgme_key_t* rset;      struct keycache_s *c;
1082      gpgme_key_t k;      gpgme_key_t *rset;
1083        gpgme_key_t key;
1084      int i, n, id, k_pos=0;      int i, n, id, k_pos=0;
     char keyid[32], t[128], t2[128];  
1085    
1086      n = listview_count_items (lv, 0);      n = listview_count_items (lv, 0);
1087      if (!n)      if (!n)
1088          return 0;          return 0;
1089      rset = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t));      rset = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t));
1090      if (!rset)      if (!rset)
1091          BUG (NULL);          BUG (NULL);
1092      for( i = 0; i < n; i++ ) {      for (i = 0; i < n; i++) {
1093          if( !listview_get_item_state( lv, i ) )          if (!listview_get_item_state (lv, i))
1094              continue;              continue;
1095          listview_get_item_text( lv, i, 1, keyid, sizeof keyid - 1 );          key = km_get_key_ptr (lv, i, &c);
1096          switch( listype ) {          switch (listype) {
1097          case KEYLIST_LIST:          case KEYLIST_LIST:
1098              listview_get_item_text( lv, i, 5, t, sizeof t - 1 );              if (keylist_get_keyflags (key) & KEYFLAG_REVOKED) {
1099              if( keylist_get_keyflags( t, strlen( t ) ) & KEYFLAG_REVOKED ) {                  id = printf_box (_("Recipients"), MB_INFO|MB_YESNO,
1100                  _snprintf( t2, sizeof t2 -1,                  _("KeyID %s.\nDo you really want to export a revoked key?"),
1101                              _("KeyID %s.\nDo you really want to export a revoked key?"), keyid );                                   c->uids->uid);
1102                  id = msg_box( lv->ctrl, t2, _("Recipients"), MB_INFO|MB_YESNO );                  if (id == IDNO)
1103                  if( id == IDNO )                      continue;
                     continue;            
1104              }              }
1105              break;              break;
1106          }          }
1107          get_pubkey (keyid, &k);          rset[k_pos++] = key;
         rset[k_pos++] = k;  
1108      }      }
1109      if (r_count)      if (r_count)
1110          *r_count = k_pos;          *r_count = k_pos;
1111      return rset;      return rset;
1112  } /* keylist_enum_recipients */  }
1113    
1114    
1115  void  void
1116  seclist_destroy (keylist_t * list)  seclist_destroy (keylist_t *list)
1117  {  {
1118      keylist_t l2;      keylist_t l2;
1119      while (*list) {      while (*list) {
# Line 1035  seclist_destroy (keylist_t * list) Line 1122  seclist_destroy (keylist_t * list)
1122          *list = l2;              *list = l2;    
1123      }      }
1124      list = NULL;      list = NULL;
1125  } /* seclist_destroy */  }
1126    
1127    
1128  void  void
# Line 1072  seclist_init (HWND dlg, int ctlid, int f Line 1159  seclist_init (HWND dlg, int ctlid, int f
1159          if (key->disabled || !key_is_useable (key->subkeys))          if (key->disabled || !key_is_useable (key->subkeys))
1160              continue;              continue;
1161    
1162          uid = utf8_to_wincp (id, strlen (id));          uid = utf8_to_native (id);
1163          size = strlen( uid ) + strlen( keyid ) + 32;          size = strlen (uid) + strlen (keyid) + 32;
1164          inf = new char[size+1];          inf = new char[size+1];
1165          if( !inf )          if (!inf)
1166              BUG( NULL );              BUG (NULL);
1167          _snprintf (inf, size, "%s (%s/0x%s)", uid,          _snprintf (inf, size, "%s (%s/0x%s)", uid,
1168                     get_key_pubalgo (key->subkeys->pubkey_algo), keyid + 8);                     get_key_pubalgo (key->subkeys->pubkey_algo), keyid + 8);
1169          combox_add_string (kb, inf);          combox_add_string (kb, inf);
1170          free_if_alloc (inf);          free_if_alloc (inf);
# Line 1094  seclist_init (HWND dlg, int ctlid, int f Line 1181  seclist_init (HWND dlg, int ctlid, int f
1181              l2->next = l;              l2->next = l;
1182          }          }
1183      }      }
1184      for( pos = 0, l2=list; pos < SendMessage( kb, CB_GETCOUNT, 0, 0 ); pos++, l2=l2->next )      for (pos = 0, l2=list; pos < SendMessage (kb, CB_GETCOUNT, 0, 0);
1185          SendMessage( kb, CB_SETITEMDATA, pos, (LPARAM)(DWORD)l2->key );           pos++, l2=l2->next)
1186      SendMessage( kb, CB_SETCURSEL, 0, 0 );          SendMessage (kb, CB_SETITEMDATA, pos, (LPARAM)(DWORD)l2->key);
1187        SendMessage (kb, CB_SETCURSEL, 0, 0);
1188      *ret_list = list;      *ret_list = list;
1189  }  }
1190                    

Legend:
Removed from v.73  
changed lines
  Added in v.214

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26