/[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 88 by twoaday, Mon Nov 21 12:06:59 2005 UTC revision 278 by twoaday, Mon Jan 15 22:02:04 2007 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 13  Line 13 
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * General Public License for more details.   * General Public License for more details.
  *  
  * You should have received a copy of the GNU General Public License  
  * along with WinPT; if not, write to the Free Software Foundation,  
  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
16   */   */
17  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
18  #include <config.h>  #include <config.h>
# Line 37  Line 33 
33  #include "wptUTF8.h"  #include "wptUTF8.h"
34  #include "wptRegistry.h"  #include "wptRegistry.h"
35  #include "wptContext.h"  #include "wptContext.h"
36    #include "wptVersion.h"
37    #include "resource.h"
38    #include "StringBuffer.h"
39    
40    
 #define key_is_useable(key) (!(key)->revoked && !(key)->expired && !(key)->disabled)  
   
 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)  
   
41  struct key_array_s {  struct key_array_s {
42      char keyid[32];      char keyid[32];
43      int checked;      int checked;
# Line 73  static int find_secret_key (gpgme_key_t Line 47  static int find_secret_key (gpgme_key_t
47    
48    
49  static key_array_s*  static key_array_s*
50  key_array_new( size_t items )  key_array_new (DWORD items)
51  {  {
52      key_array_s *ka;      key_array_s *ka;
53      size_t j;      DWORD i;
54            
55      if( items == 0 )      if (items == 0)
56          return NULL;          return NULL;
57      ka = new key_array_s[items + 1];      ka = new key_array_s[items + 1];
58      if( ka == NULL )      if (!ka)
59          return NULL;              BUG (NULL);
60      for ( j = 0; j < items; j++ )      for (i = 0; i < items; i++)
61          ka[j].checked = 0;          ka[i].checked = 0;
62      return ka;      return ka;
63  } /* key_array_new */  }
64    
65    
66  static void  static void
67  key_array_release( key_array_s *ka )  key_array_release (key_array_s *ka)
68  {  {
69      free_if_alloc( ka );      free_if_alloc (ka);
70  } /* key_array_release */  }
71    
72    
73    /* Check if the keyid @keyid is in the key array @ka.
74       Return value: 1 if it exists, 0 otherwise. */
75  static int  static int
76  key_array_search( key_array_s *ka, size_t items, const char *keyid )  key_array_search (key_array_s *ka, DWORD items, const char *keyid)
77  {  {
78      size_t j;      DWORD i;
79            
80      /* fixme: we need a faster search method */      for (i = 0; i < items; i++) {
81      for( j = 0; j < items; j++ ) {          if (!strcmp (keyid, ka[i].keyid))
         if( !strcmp( keyid, ka[j].keyid ) )  
82              return 1;                return 1;  
83      }      }
       
84      return 0;      return 0;
85  } /* key_array_search */  }
86    
87    
88  gpgme_user_id_t  gpgme_user_id_t
# Line 173  count_subkeys (gpgme_key_t key) Line 147  count_subkeys (gpgme_key_t key)
147  }  }
148    
149    
150    /* Return the self signature of the key @keyid.
151       If first is set, the first self sig will be returned. */
152  gpgme_key_sig_t  gpgme_key_sig_t
153  get_selfsig (gpgme_user_id_t uid, const char *keyid, int first)  get_selfsig (gpgme_key_sig_t sigs, const char *keyid, int first)
154  {  {
155      gpgme_key_sig_t s, self_sig=NULL;      gpgme_key_sig_t s, self_sig=NULL;
156      long timestamp=0;      long timestamp=0;
157        int off = 0;
158    
159      for (s = uid->signatures; s; s = s->next) {      if (strlen (keyid) == 8)
160          if (!strcmp (s->keyid+8, keyid) && s->timestamp > timestamp) {          off = 8;
161    
162        for (s = sigs; s; s = s->next) {
163            if (!strcmp (s->keyid+off, keyid) && s->timestamp > timestamp) {
164              self_sig = s;              self_sig = s;
165              timestamp = s->timestamp;              timestamp = s->timestamp;
166              if (first)              if (first) /* do not search for later self sigs. */
167                  break;                  break;
168          }          }
169      }      }
# Line 191  get_selfsig (gpgme_user_id_t uid, const Line 171  get_selfsig (gpgme_user_id_t uid, const
171  }  }
172    
173    
   
174  const char*  const char*
175  get_key_algo (gpgme_key_t key, int keyidx)  get_key_algo (gpgme_key_t key, int keyidx)
176  {  {
# Line 204  get_key_algo (gpgme_key_t key, int keyid Line 183  get_key_algo (gpgme_key_t key, int keyid
183      if (keyidx > 0) {      if (keyidx > 0) {
184          k = get_nth_key (key, keyidx-1);          k = get_nth_key (key, keyidx-1);
185          subalg =  get_key_pubalgo (k->pubkey_algo);          subalg =  get_key_pubalgo (k->pubkey_algo);
186          _snprintf( algo_id, DIM (algo_id)-1, "%s", subalg);          _snprintf (algo_id, DIM (algo_id)-1, "%s", subalg);
187          return algo_id;          return algo_id;
188      }      }
189      strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo));      strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo));
190      n = count_subkeys (key);      n = count_subkeys (key);
191      if (n > 1) {      if (n > 1) {
192          k = get_nth_key (key, n-1);          do {
193                k = get_nth_key (key, --n);
194                if (k->revoked || k->expired)
195                    continue;
196                else
197                    break;
198            } while (n > 0);
199          subalg = get_key_pubalgo (k->pubkey_algo);          subalg = get_key_pubalgo (k->pubkey_algo);
200          _snprintf (algo_id, DIM (algo_id)-1, "%s/%s", alg, subalg);          if (k == key->subkeys)
201                _snprintf (algo_id, DIM (algo_id)-1, "%s", subalg);
202            else
203                _snprintf (algo_id, DIM (algo_id)-1, "%s/%s", alg, subalg);
204          return algo_id;          return algo_id;
205      }      }
206      return get_key_pubalgo (key->subkeys->pubkey_algo);      return get_key_pubalgo (key->subkeys->pubkey_algo);
207  } /* get_key_algo */  }
208    
209    
210  const char*  const char*
211  get_key_created (long timestamp)  get_key_created (long timestamp)
212  {  {
213      static char timebuf[128];      static char timebuf[128];  
     struct tm *warp;  
214    
215      if (timestamp == 0 || timestamp == -1)      if (timestamp < 1)
216            return "????" "-??" "-??";
217        if (!get_locale_date (timestamp, timebuf, DIM (timebuf)-1))
218          return "????" "-??" "-??";          return "????" "-??" "-??";
     warp = localtime( &timestamp );  
     _snprintf( timebuf, sizeof timebuf - 1, "%04d-%02d-%02d",  
                 warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday );  
219      return timebuf;      return timebuf;
220  } /* get_key_created */  }
221    
222    
223  /* Return a string presentation of the time @timestamp. */  /* Return a string presentation of the time @timestamp. */
# Line 239  const char* Line 225  const char*
225  get_key_expire_date (long timestamp)  get_key_expire_date (long timestamp)
226  {  {
227      static char timebuf[64];      static char timebuf[64];
     struct tm *warp;  
228    
229      if( !timestamp )      if (timestamp == 0)
230          return _("Never");          return _("Never");
231      warp = localtime( &timestamp );      if (!get_locale_date (timestamp, timebuf, DIM (timebuf)-1))
232      _snprintf (timebuf, sizeof timebuf -1, "%04d-%02d-%02d",          return "????" "-??" "-??";
                warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday);  
233      return timebuf;      return timebuf;
234  }  }
235    
# Line 260  get_key_type (gpgme_key_t key) Line 244  get_key_type (gpgme_key_t key)
244      else if (type == 2)      else if (type == 2)
245          return _("Key Pair (Card)");          return _("Key Pair (Card)");
246      return _("Public Key");      return _("Public Key");
247  } /* get_key_type */  }
248    
249    
250  const char*  const char*
# Line 281  get_key_size (gpgme_key_t key, int keyid Line 265  get_key_size (gpgme_key_t key, int keyid
265      if (n > 1) {      if (n > 1) {
266          k = get_nth_key (key, n-1);          k = get_nth_key (key, n-1);
267          size_sub = k->length;          size_sub = k->length;
268          _snprintf( size_id, sizeof (size_id) - 1, "%d/%d", size_main, size_sub );          _snprintf (size_id, DIM (size_id) - 1, "%d/%d",
269                        size_main, size_sub);
270          return size_id;          return size_id;
271      }      }
272      _snprintf( size_id, sizeof (size_id) - 1, "%d", size_main );      _snprintf (size_id, DIM (size_id) - 1, "%d", size_main);
273      return size_id;      return size_id;
274  } /* get_key_size */  }
275    
276    
277    const char*
278    get_key_pubalgo2 (gpgme_pubkey_algo_t alg)
279    {
280        switch (alg) {
281        case GPGME_PK_DSA: return "D";
282        case GPGME_PK_RSA: return "R";
283        case GPGME_PK_ELG: return "G";
284        default: return "?";
285        }
286        return "?";
287    }
288    
289    
290  const char*  const char*
# Line 296  get_key_pubalgo (gpgme_pubkey_algo_t alg Line 294  get_key_pubalgo (gpgme_pubkey_algo_t alg
294      case GPGME_PK_DSA: return "DSA";      case GPGME_PK_DSA: return "DSA";
295      case GPGME_PK_ELG:      case GPGME_PK_ELG:
296      case GPGME_PK_ELG_E: return "ELG";      case GPGME_PK_ELG_E: return "ELG";
297      case GPGME_PK_RSA: return "RSA";      case 0: /* XXX: do we still need this?? */
298        case GPGME_PK_RSA:
299        case GPGME_PK_RSA_S:
300        case GPGME_PK_RSA_E: return "RSA";
301      default: return "???";      default: return "???";
302      }      }
303      return "???";      return "???";
304  }  }
305    
306  const char *  
307    const char*
308  get_key_fpr (gpgme_key_t key)  get_key_fpr (gpgme_key_t key)
309  {  {
310      static char fpr_md[64];      static char fpr_md[64];
# Line 331  get_key_fpr (gpgme_key_t key) Line 333  get_key_fpr (gpgme_key_t key)
333          }          }
334      }      }
335      return fpr_md;      return fpr_md;
336  } /* get_key_fpr */  }
337    
338    
339  const char *  /* Extract the key ID from the fingerprint.
340       A long ID will be converted into a short ID. */
341    const char*
342    get_keyid_from_fpr (const char *fpr)
343    {
344        if (!fpr)
345            return "????????";
346        if (strlen (fpr) == 40)
347            fpr += 32;
348        else if (strlen (fpr) == 32)
349            fpr += 24;
350        else if (strlen (fpr) == 16)
351            fpr += 8;
352        else
353            return "????????";
354        return fpr;
355    }
356    
357    
358    const char*
359  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)
360  {  {
361      if (key)      if (key)
# Line 348  get_key_trust2 (gpgme_key_t key, int val Line 369  get_key_trust2 (gpgme_key_t key, int val
369      case GPGME_VALIDITY_MARGINAL:      case GPGME_VALIDITY_MARGINAL:
370          return _("Marginal");          return _("Marginal");
371      case GPGME_VALIDITY_FULL:      case GPGME_VALIDITY_FULL:
     case GPGME_VALIDITY_ULTIMATE:  
372          return _("Full");          return _("Full");
373        case GPGME_VALIDITY_ULTIMATE:
374            return _("Ultimate");
375      }      }
376      return "";      return "";
377  }  }
378    
379    
380  const char *  const char*
381  get_key_trust (gpgme_key_t key, int uididx, int listmode)  get_key_trust (gpgme_key_t key, int uididx, int listmode)
382  {  {
383      return get_key_trust2 (key, 0, uididx, listmode);      return get_key_trust2 (key, 0, uididx, listmode);
384  }  }
385    
386    
387  const char *  const char*
388  get_key_trust_str (int val)  get_key_trust_str (int val)
389  {  {
390      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 402  get_key_status (gpgme_key_t key, int uid
402      if (uididx < 0 || count_userids (key) > uididx)      if (uididx < 0 || count_userids (key) > uididx)
403          uididx = 0;          uididx = 0;
404      if (listmode) {      if (listmode) {
405          const char *s;          const char *s;
         
406          if (key->revoked)          if (key->revoked)
407              s = _("Revoked");              s = _("Revoked");
408          else if (key->expired)          else if (key->expired)
409              s = _("Expired");              s = _("Expired");
410          else if (key->disabled)          else if (key->disabled)
411              s = _("Disabled");              s = _("Disabled");
412          else          else
413            s = "";              s = "";
           
414          /* 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
415             what any user-id validities. */             the user-id validities. */
416          if (*s)          if (*s)
417              return m_strdup (s);              return m_strdup (s);
418      }      }
# Line 403  get_key_status (gpgme_key_t key, int uid Line 423  get_key_status (gpgme_key_t key, int uid
423  }  }
424    
425    
426    /* Return human readable description of the key @key. */
427    char*
428    get_key_desc (gpgme_key_t key)
429    {
430        gpgme_key_t sk;
431        const char *state, *alg, *type;
432        char *desc;
433        StringBuffer p;
434    
435        state = "";
436        if (key->disabled)
437            state = _("Disabled");
438        if (key->expired)
439            state = _("Expired");
440        if (key->revoked)
441            state = _("Revoked");
442    
443        /* If the fingerprint has 32 octets, we assume MD5 and thus
444           an old, version 3, RSA key which is called 'Legacy' by other
445           OpenPGP programs. */
446        if (strlen (key->subkeys->fpr) == 32)
447            alg = "RSA Legacy";
448        else
449            alg = "OpenPGP";
450        type = _("public key");
451        if (!get_seckey (key->subkeys->keyid+8, &sk))
452            type = _("key pair");
453        p = state;
454        p = p + " " + alg + " " + type;
455        desc = m_strdup (p.getBuffer ());
456        return desc;
457    }
458    
459    
460  /* Integer comparsion of @a and @b.  /* Integer comparsion of @a and @b.
461     Return values: same as in strcmp. */     Return values: same as in strcmp. */
462  static inline int  static inline int
# Line 424  get_ext_validity (gpgme_key_t k) Line 478  get_ext_validity (gpgme_key_t k)
478          return GPGME_VALIDITY_ULTIMATE+1;          return GPGME_VALIDITY_ULTIMATE+1;
479      else if (k->expired)      else if (k->expired)
480          return GPGME_VALIDITY_ULTIMATE+2;          return GPGME_VALIDITY_ULTIMATE+2;
481        else if (k->disabled)
482            return GPGME_VALIDITY_ULTIMATE+3;
483      return k->uids->validity;      return k->uids->validity;
484  }  }
485    
# Line 432  get_ext_validity (gpgme_key_t k) Line 488  get_ext_validity (gpgme_key_t k)
488  static int CALLBACK  static int CALLBACK
489  keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby)  keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby)
490  {  {
491        struct keycache_s *aa, *bb;
492      gpgme_key_t a, b;      gpgme_key_t a, b;
493      int cmpresult = 0;      int cmpresult = 0;
494            
495      a = (gpgme_key_t)first;      aa = (struct keycache_s *)first;
496      b = (gpgme_key_t)second;      bb = (struct keycache_s *)second;
497      if (!a || !b)      if (!aa || !bb)
498          BUG (NULL);          BUG (NULL);
499        a = aa->key;
500        b = bb->key;
501            
502      switch (sortby & ~KEYLIST_SORT_DESC) {      switch (sortby & ~KEYLIST_SORT_DESC) {
503      case KEY_SORT_USERID:      case KEY_SORT_USERID:
# Line 491  keylist_cmp_cb (LPARAM first, LPARAM sec Line 550  keylist_cmp_cb (LPARAM first, LPARAM sec
550  }  }
551    
552    
 /* 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");  
 }  
   
   
553  int  int
554  keylist_add_groups( listview_ctrl_t lv )  keylist_add_groups (listview_ctrl_t lv)
555  {  {
 #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  
556      return 0;      return 0;
557  } /* keylist_add_groups */  }
558    
559    
560  /* Create a listview for listing keys. Use the mode given in @mode  /* Create a listview for listing keys. Use the mode given in @mode
561     and the control is given in @ctrl. */     and the control is given in @ctrl. */
562  static int  static void
563  keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode)  keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode)
564  {  {
565        struct listview_column_s klist_enc[] = {
566        {0, 242, (char *)_("User ID")},
567        {1, 80, (char *)_("Key ID")},
568        {3, 46, (char *)_("Size")},
569        {4, 50, (char *)_("Cipher")},
570        {5, 70, (char *)_("Validity")},
571        {0, 0, NULL}
572        };
573        struct listview_column_s klist[] = {
574        {0, 240, (char *)_("User ID")},
575        {1, 78, (char *)_("Key ID")},
576        {2, 52, (char *)_("Type")},    
577        {3, 66, (char *)_("Size")},
578        {4, 60, (char *)_("Cipher")},
579        {5, 66, (char *)_("Validity")},
580        {6, 58, (char *)_("Trust")},
581        {7, 72, (char *)_("Creation")},
582        {0, 0, NULL}
583        };
584        HICON ico[6];
585      listview_ctrl_t lv;      listview_ctrl_t lv;
586      listview_column_t col;      listview_column_t col;
587      int j, n = 0;      int j, n = 0, ext_chk = 0;
     int rc = 0;  
       
     rc = listview_new (&lv);  
     if( rc )  
         return rc;  
588            
589      lv->ctrl = ctrl;      listview_new (&lv, ctrl);
590      if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) {      if (mode & KEYLIST_ENCRYPT_MIN) {
591          col = klist_enc;          col = klist_enc;
592          n = KLIST_ENC_ITEMS;          n = (DIM (klist_enc) -1);
593            ext_chk = 1;
594      }        }  
595      else if ((mode & KEYLIST_SIGN)) {      else if ((mode & KEYLIST_SIGN)) {
596          col = klist_enc;          col = klist_enc;
597          n = KLIST_ENC_ITEMS - 1;          n = (DIM (klist_enc) - 1) - 1;
598            ext_chk = 1;
599      }      }
600      else {      else {
601          col = klist;          col = klist;
602          n = KLIST_ITEMS;          n = (DIM (klist) - 1);
603      }      }
604            
605      for( j = 0; j < n; j++ )          for (j = 0; j < n; j++)
606          listview_add_column( lv, &col[j] );              listview_add_column (lv, &col[j]);
607      listview_set_ext_style( lv );      listview_set_ext_style (lv);
608        if (ext_chk)
609            listview_set_chkbox_style (lv);
610        ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY);
611        ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR);
612        ico[2] = LoadIcon (glob_hinst, (LPCTSTR)IDI_REV_KEYPAIR);
613        ico[3] = LoadIcon (glob_hinst, (LPCTSTR)IDI_REV_PUBKEY);
614        ico[4] = LoadIcon (glob_hinst, (LPCTSTR)IDI_SORT_DOWNARROW);
615        ico[5] = LoadIcon (glob_hinst, (LPCTSTR)IDI_SORT_UPARROW);
616        listview_set_image_list (lv, 22, 14, ico, DIM (ico));
617        listview_del_all_items (lv);
618    
619      *r_lv = lv;      *r_lv = lv;
       
     return 0;  
620  }  }
621    
622    
# Line 583  keylist_load_keycache (listview_ctrl_t l Line 626  keylist_load_keycache (listview_ctrl_t l
626  {  {
627      gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);      gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
628      gpgme_key_t key, skey;      gpgme_key_t key, skey;
629      const char * keyid;      struct keycache_s *c;
630        const char *keyid;
631    
632      if (pubkc && seckc) {      if (pubkc && seckc) {
633          gpg_keycache_rewind (pubkc);          gpg_keycache_rewind (pubkc);
634          while (!gpg_keycache_next_key (pubkc, 0, &key)) {          while (!gpg_keycache_next_key2 (pubkc, 0, &c, &key)) {
635              keyid = key->subkeys->keyid;              keyid = key->subkeys->keyid;
636              if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey))              if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey))
637                  keylist_add_key (lv, mode, key);                  keylist_add_key (lv, mode, c, key);
638          }                }      
639      }      }
640      else if (pubkc) {      else if (pubkc) {
641          gpg_keycache_rewind (pubkc);          gpg_keycache_rewind (pubkc);
642          while (!err) {              while (!err) {    
643              err = gpg_keycache_next_key (pubkc, 0, &key);              err = gpg_keycache_next_key2 (pubkc, 0, &c, &key);
644              if (!err)              if (!err)
645                  keylist_add_key (lv, mode, key);                  keylist_add_key (lv, mode, c, key);
646          }          }
647      }      }
648  }  }
# Line 611  keylist_load (HWND ctrl, gpg_keycache_t Line 655  keylist_load (HWND ctrl, gpg_keycache_t
655                int mode, int sortby)                int mode, int sortby)
656  {      {    
657      listview_ctrl_t lv;      listview_ctrl_t lv;
     int rc = 0;      
658    
659      rc = keylist_build (&lv, ctrl, mode);      keylist_build (&lv, ctrl, mode);  
     if (rc)  
         return NULL;              
660      keylist_load_keycache (lv, mode, pubkc, seckc);      keylist_load_keycache (lv, mode, pubkc, seckc);
661      keylist_sort (lv, sortby);      keylist_sort (lv, sortby);
662      if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN))      if (mode & KEYLIST_ENCRYPT_MIN)
663          keylist_add_groups (lv);          keylist_add_groups (lv);
664      return lv;      return lv;
665  }  }
# Line 628  keylist_load (HWND ctrl, gpg_keycache_t Line 669  keylist_load (HWND ctrl, gpg_keycache_t
669  int  int
670  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)
671  {  {
672      listview_del_all (lv);      listview_del_all_items (lv);
673      keylist_load_keycache( lv, mode, pubkc, NULL );      keylist_load_keycache (lv, mode, pubkc, NULL);
674      keylist_sort (lv, sortby);      keylist_sort (lv, sortby);
675      return 0;      return 0;
676  }  }
# Line 649  keylist_delete (listview_ctrl_t lv) Line 690  keylist_delete (listview_ctrl_t lv)
690  static int  static int
691  find_secret_key (gpgme_key_t key)  find_secret_key (gpgme_key_t key)
692  {  {
     const char *keyid;  
693      winpt_key_s skey;      winpt_key_s skey;
694            
695      memset (&skey, 0, sizeof (skey));      if (!key->subkeys->keyid)
     keyid = key->subkeys->keyid;  
     if (!keyid)  
696          return 0;          return 0;
697      winpt_get_seckey (keyid, &skey);      memset (&skey, 0, sizeof (skey));
698        winpt_get_seckey (key->subkeys->keyid, &skey);
699      if (skey.ext && skey.ext->gloflags.divert_to_card)      if (skey.ext && skey.ext->gloflags.divert_to_card)
700          return 2;          return 2;
701      return skey.ctx? 1 : 0;      return skey.ctx? 1 : 0;
702  }  }
703    
704    
705    /* Enumeration for possible key icons. */
706    enum key_icontype_t {
707        IMG_KEY_PUB = 0,
708        IMG_KEY_PAIR = 1,
709        IMG_KEY_PAIR_REV = 2,
710        IMG_KEY_PUB_REV = 3
711    };
712    
713    
714    static int
715    key_get_image_id (gpgme_key_t key)
716    {
717        if (find_secret_key (key))    
718            return key->revoked ? IMG_KEY_PAIR_REV :IMG_KEY_PAIR;
719        if (key->revoked)
720            return IMG_KEY_PUB_REV;
721        return IMG_KEY_PUB;
722    }
723    
724    
725  static int  static int
726  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,
727               int uididx, int keyidx, int list)
728  {      {    
729      LV_ITEM lvi;      LV_ITEM lvi;
730      gpgme_user_id_t u;      gpgme_user_id_t u;
731      gpgme_subkey_t k;      gpgme_subkey_t k;
732      char fmt[128], *p;      char *p;
733      const char *attr;      const char *attr;
734      u32 key_attr;      int idx = 0;
     int idx = 0;      
735    
736      /* we check the pubkey algorithm here to make sure that no ElGamal      /* we check the pubkey algorithm here to make sure that no ElGamal
737         sign+encrypt key is used in _any_ mode */         sign+encrypt key is used in _any_ mode */
738      if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) {      if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) {
739          log_debug ("ElGamal (E+S) key found: %s (%s)\n",          log_debug ("ElGamal (E+S) key found: %s (%s)\n",
740                     key->uids->name, key->subkeys->keyid);                     key->uids->name, key->subkeys->keyid);
741          return 0;          return 0;
742      }      }
743    
744                if (listview_add_item2 (lv, " ", (void *)ctx))
     if (listview_add_item2 (lv, " ", (void *)key))        
745          return WPTERR_GENERAL;          return WPTERR_GENERAL;
746            
747      attr = key->uids->uid;      attr = ctx->uids->uid;
748      memset (&lvi, 0, sizeof lvi);      memset (&lvi, 0, sizeof lvi);
749      lvi.mask = LVIF_TEXT | LVIF_PARAM;      lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
750      lvi.pszText = (char *)attr;      lvi.pszText = (char *)attr;
751      lvi.lParam = (LPARAM )key;      lvi.iImage = key_get_image_id (key);
752      if (ListView_SetItem( lv->ctrl, &lvi ) == FALSE)      lvi.lParam = (LPARAM )ctx;
753        if (ListView_SetItem (lv->ctrl, &lvi) == FALSE)
754          return WPTERR_GENERAL;          return WPTERR_GENERAL;
755                    
756      if (uididx == -1) { /* request the primary user-id of the key. */      if (uididx == -1) { /* request the primary user-id of the key. */
757          attr = key->uids->uid;          attr = ctx->uids->uid;
758          uididx = 0;          uididx = 0;
759      }      }
760      else {      else {
761          u = get_nth_userid (key, uididx);          u = get_nth_userid (key, uididx);
762          if (!u || u->revoked || uididx < 0)          if (!u || u->revoked || uididx < 0)
763              uididx = 0; /* fixme: this happen sometimes but it's illegal! (<0) */              uididx = 0;
764          u = get_nth_userid (key, uididx);          u = get_nth_userid (key, uididx);
         /*attr = key->uids->uid; XXX*/  
765          attr = u->uid;          attr = u->uid;
766      }      }
767      if (attr == NULL || strlen (attr) < 5) { /* normal userids are >= 5 chars */      if (attr == NULL || strlen (attr) < 5) { /* normal userids are > 5 chars */
768          attr = _("Invalid User ID");          attr = _("Invalid User ID");
769          listview_add_sub_item (lv, 0, idx++, attr);          listview_add_sub_item (lv, 0, idx++, attr);
770      }        }  
771      else {      else        
772          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);  
         }  
     }  
773      k = get_nth_key (key, keyidx);      k = get_nth_key (key, keyidx);
774      if (k && k->keyid) {      if (k && k->keyid != NULL) {
775          _snprintf (fmt, sizeof fmt -1, "0x%s", k->keyid + 8);          char keyid[16+1];
776          listview_add_sub_item( lv, 0, idx++, fmt );  
777            _snprintf (keyid, DIM (keyid) -1, "0x%s", k->keyid + 8);
778            listview_add_sub_item (lv, 0, idx++, keyid);
779      }      }
780      if (list > 0) {      if (list > 0) {
781          key_attr = find_secret_key (key);          DWORD key_attr = find_secret_key (key);
782          if (!key_attr)          if (!key_attr)
783              attr = "pub";              attr = "pub";
784          else          else
# Line 732  do_addkey (listview_ctrl_t lv, gpgme_key Line 787  do_addkey (listview_ctrl_t lv, gpgme_key
787      }      }
788      if (lv->cols >= 2) {      if (lv->cols >= 2) {
789          attr = get_key_size (key, list == -1? keyidx+1 : 0);          attr = get_key_size (key, list == -1? keyidx+1 : 0);
790          if (attr)          if (attr != NULL)
791              listview_add_sub_item (lv, 0, idx++, attr);              listview_add_sub_item (lv, 0, idx++, attr);
792      }      }
793      if (lv->cols >= 3) {      if (lv->cols >= 3) {
794          attr = get_key_algo (key, list == -1? keyidx+1 : 0);          attr = get_key_algo (key, list == -1? keyidx+1 : 0);
795          if (attr)          if (attr != NULL)
796              listview_add_sub_item( lv, 0, idx++, attr);              listview_add_sub_item( lv, 0, idx++, attr);
797      }      }
798      if( lv->cols >= 4 ) {      if (lv->cols >= 4) {
799          p = get_key_status( key, uididx, list > 0? 1 : 0 );          p = get_key_status (key, uididx, list > 0? 1 : 0);
800          if (!p)          if (p != NULL)
801              return WPTERR_GENERAL;              listview_add_sub_item (lv, 0, idx++, p);
         listview_add_sub_item (lv, 0, idx++, p);  
802          free_if_alloc (p);          free_if_alloc (p);
803      }      }
804      if (lv->cols >= 5) {      if (lv->cols >= 5) {
805          attr = get_key_trust (key, uididx, list > 0? 1 : 0);          attr = get_key_trust (key, uididx, list > 0? 1 : 0);
806          listview_add_sub_item (lv, 0, idx++, attr);          listview_add_sub_item (lv, 0, idx++, attr);
807      }      }
808      if( lv->cols >= 6 ) {      if (lv->cols >= 6) {
809          k = get_nth_key (key, keyidx);          k = get_nth_key (key, keyidx);
810          key_attr = k->timestamp;          if (k->timestamp > 0) {
811          if( key_attr ) {              attr = get_key_created (k->timestamp);
812              attr = get_key_created (key_attr);              listview_add_sub_item (lv, 0, idx++, attr);
813              listview_add_sub_item( lv, 0, idx++, attr );          }
         }        
814      }      }
815    
816      return 0;      return 0;
817  }  }
818    
819    
820    /* Update a single column @col but for each element in the
821       listview @lv. */
822  void  void
823  keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key)  keylist_upd_col (listview_ctrl_t lv, int col)
824  {  {
825        gpgme_key_t key;
826      const char *s;      const char *s;
827        char buf[32], *p;
828        int i;
829    
830        for (i=0; i < listview_count_items (lv, 0); i++) {
831            key = km_get_key_ptr (lv, i, NULL);
832            if (!key)
833                continue;
834            switch (col) {
835            case KM_COL_KEYID:
836                _snprintf (buf, DIM (buf)-1, "0x%s", key->subkeys->keyid+8);
837                listview_add_sub_item (lv, i, col, buf);
838                break;
839    
840            case KM_COL_CIPHER:
841                s = get_key_algo (key, 0);
842                listview_add_sub_item (lv, i, col, s);
843                break;
844    
845            case KM_COL_TYPE:
846                s = find_secret_key (key)? "pub/sec" : "pub";
847                listview_add_sub_item (lv, i, col, s);
848                break;
849    
850            case KM_COL_CREAT:
851                s = get_key_created (key->subkeys->timestamp);
852                listview_add_sub_item (lv, i, col, s);
853                break;
854    
855            case KM_COL_DESC:
856                p = get_key_desc (key);
857                listview_add_sub_item (lv, i, col, p);
858                free_if_alloc (p);
859                break;
860            }
861        }
862    }
863    
864    
865    /* Update the listview item at position @pos with the data from
866       the key @key. */
867    void
868    keylist_upd_key (listview_ctrl_t lv, int pos,
869                     struct keycache_s *ctx, gpgme_key_t key)
870    {
871        const char *s;
872        char *p;
873      char tmp[32];      char tmp[32];
874    
875      listview_set_item2 (lv, pos, (void *)key);      listview_set_item2 (lv, pos, (void *)ctx);
876      /* the only mode we support is KYLIST_LIST in the Key Manager */      /* the only mode we support is KEYLIST_LIST in the Key Manager */
877            
878      s = key->uids->uid;      s = ctx->uids->uid;
879      if (s)      if (s)
880          listview_add_sub_item (lv, pos, 0, s);          listview_add_sub_item (lv, pos, KM_COL_UID, s);
881    
882      s = key->subkeys->keyid;      s = key->subkeys->keyid;
883      if (s) {      if (s) {
884          sprintf (tmp, "0x%s", s+8);          sprintf (tmp, "0x%s", s+8);
885          listview_add_sub_item (lv, pos, 1, tmp);          listview_add_sub_item (lv, pos, KM_COL_KEYID, tmp);
886      }      }
887    
888      s = find_secret_key (key)? "pub/sec" : "pub";      s = find_secret_key (key)? "pub/sec" : "pub";
889      listview_add_sub_item (lv, pos, 2, s);      listview_add_sub_item (lv, pos, KM_COL_TYPE, s);
890    
891      s = get_key_size (key, 0);      s = get_key_size (key, 0);
892      if (s)      if (s)
893          listview_add_sub_item (lv, pos, 3, s);          listview_add_sub_item (lv, pos, KM_COL_SIZE, s);
894    
895      s = get_key_algo (key, 0);      s = get_key_algo (key, 0);
896      if (s)      if (s)
897          listview_add_sub_item (lv, pos, 4, s);          listview_add_sub_item (lv, pos, KM_COL_CIPHER, s);
898    
899      s = get_key_status (key, 0, 1);      p = get_key_status (key, 0, 1);
900      if (s)      if (p) {
901          listview_add_sub_item (lv, pos, 5, s);          listview_add_sub_item (lv, pos, KM_COL_VALID, p);
902            free_if_alloc (p);
903        }
904    
905      s = get_key_trust (key, 0, 1);      s = get_key_trust (key, 0, 1);
906      if (s)      if (s)
907          listview_add_sub_item (lv, pos, 6, s);          listview_add_sub_item (lv, pos, KM_COL_TRUST, s);
908    
909      long t = key->subkeys->timestamp;      long t = key->subkeys->timestamp;
910      s = get_key_created (t);      s = get_key_created (t);
911      if (s)      if (s)
912          listview_add_sub_item (lv, pos, 7, s);          listview_add_sub_item (lv, pos, KM_COL_CREAT, s);
913  }  }
914    
915    
916  int  int
917  keylist_add_key (listview_ctrl_t lv, int mode, gpgme_key_t key)  keylist_add_key (listview_ctrl_t lv, int mode,
918                     struct keycache_s *ctx, gpgme_key_t key)
919  {  {
920      int uids, rc = 0, i;      int uids, rc = 0, i;
921      gpgme_subkey_t k;      gpgme_subkey_t k;
# Line 827  keylist_add_key (listview_ctrl_t lv, int Line 932  keylist_add_key (listview_ctrl_t lv, int
932    
933          if (mode & KEYLIST_ALL) {          if (mode & KEYLIST_ALL) {
934              uids = count_userids (key);              uids = count_userids (key);
935              rc = do_addkey (lv, key, uids, i, 0);              rc = do_addkey (lv, ctx, key, uids, i, 0);
936              if( rc )              if (rc)
937                  return rc;                  return rc;
938          }          }
939          else if (mode & KEYLIST_LIST)          else if (mode & KEYLIST_LIST)
940              return do_addkey (lv, key, -1, i, 1);              return do_addkey (lv, ctx, key, -1, i, 1);
941          else if (mode & KEYLIST_ENCRYPT) {          else if (mode & KEYLIST_ENCRYPT) {
942              if (k->can_encrypt && key_is_useable (k)) {              if (k->can_encrypt && key_is_useable (k)) {
943                  if (mode & KEYLIST_FLAG_FILE) {                  if (mode & KEYLIST_FLAG_FILE) {
944                      rc = do_addkey (lv, key, -1, i, -1);                      rc = do_addkey (lv, ctx, key, -1, i, -1);
945                      if (rc)                      if (rc)
946                          return rc;                          return rc;
947                  }                  }
948                  else {                  else {
949                      for( uids = 0;  uids < count_userids (key); uids++ ) {                      for (uids = 0;  uids < count_userids (key); uids++) {
950                          rc = do_addkey( lv, key, uids, i, -1 );                          rc = do_addkey (lv, ctx, key, uids, i, -1);
951                          if( rc )                          if (rc)
952                              return rc;                              return rc;
953                      }                      }
954                  }                  }
955              }              }
956          }          }
957          else if (mode & KEYLIST_ENCRYPT_MIN) {          else if (mode & KEYLIST_ENCRYPT_MIN) {
958              if( k->can_encrypt && key_is_useable (k))              if(k->can_encrypt && key_is_useable (k)) {
959              {                  rc = do_addkey (lv, ctx, key, -1, i, -1);
                 rc = do_addkey (lv, key, -1, i, -1);  
960                  return rc;                  return rc;
961              }              }
962          }                }      
# Line 860  keylist_add_key (listview_ctrl_t lv, int Line 964  keylist_add_key (listview_ctrl_t lv, int
964              if (k->can_sign              if (k->can_sign
965                  && find_secret_key (key)                  && find_secret_key (key)
966                  && key_is_useable (k)) {                  && key_is_useable (k)) {
967                  rc = do_addkey (lv, key, -1, i, -1);                  rc = do_addkey (lv, ctx, key, -1, i, -1);
968                  if (rc)                  if (rc)
969                      return rc;                        return rc;  
970              }              }
# Line 868  keylist_add_key (listview_ctrl_t lv, int Line 972  keylist_add_key (listview_ctrl_t lv, int
972      }      }
973    
974      return rc;        return rc;  
975  } /* keylist_add_key */  }
976    
977    
978  int  int
979  keylist_sort (listview_ctrl_t lv, int sortby)  keylist_sort (listview_ctrl_t lv, int sortby)
980  {        {
981      return listview_sort_items (lv, sortby, keylist_cmp_cb);      return listview_sort_items (lv, sortby, keylist_cmp_cb);
982  }  }
983    
984    
985  /* Check that the validity @validity is at least >= marginal. */  /* Check that the validity @validity is at least >= marginal. */
986  static int  static int
987  key_check_validity (const char *validity)  key_check_validity (gpgme_key_t key)
988  {      {
989      if (strstr (validity, "Unknown") ||      gpgme_user_id_t u;
990          strstr (validity, "Undefined") ||  
991          strstr (validity, "Never") ||      for (u=key->uids; u; u =u->next) {
992          strstr (validity, "None"))          if (u->validity >= GPGME_VALIDITY_MARGINAL)
993          return 0;                return -1;
994      return 1;      }
995    
996        return 0;
997  }  }
998    
999    
# Line 896  key_check_validity (const char *validity Line 1002  key_check_validity (const char *validity
1002     fully trusted. @r_count returns the number of selected keys.     fully trusted. @r_count returns the number of selected keys.
1003     Return value: the key list on success, NULL otherwise. */     Return value: the key list on success, NULL otherwise. */
1004  gpgme_key_t*  gpgme_key_t*
1005  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, size_t *r_count)
1006  {  {
1007      int count = 0, force_trust = 0;      key_array_s *ka = NULL;
1008        keycache_s *c;
1009        gpgme_key_t *keybuf, key;
1010        size_t count = 0;
1011        int force_trust = 0;
1012      int n, j, ka_pos = 0, rc = 0;      int n, j, ka_pos = 0, rc = 0;
1013      int k_pos=0;      int k_pos=0;
     char keyid[32], valid[32], id[100];  
     key_array_s *ka = NULL;  
     gpgme_key_t *keybuf;  
1014    
1015      n = listview_count_items( lv, 0 );      n = listview_count_items (lv, 0);
1016            
1017      ka = key_array_new( n );      ka = key_array_new (n);
1018      if (!ka)      keybuf = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t));
         BUG (NULL);  
   
     keybuf = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t));  
1019      if (!keybuf)      if (!keybuf)
1020          BUG (NULL);          BUG (NULL);
1021                    
1022      for( j = 0; j < n; j++ ) {      for (j = 0; j < n; j++) {
1023          if( listview_get_item_state (lv, j) || n == 1) {          if (listview_get_item_state (lv, j) || n == 1) {
1024              listview_get_item_text (lv, j, 0, id, sizeof id-1);              key = km_get_key_ptr (lv, j, &c);
1025              listview_get_item_text (lv, j, 1, keyid, sizeof keyid - 1);                              if (!key)
1026              listview_get_item_text (lv, j, 4, valid, sizeof valid -1);                  BUG (0);
1027              if( !key_check_validity (valid)              if (!key_check_validity (key) &&
1028                   && !key_array_search( ka, ka_pos, keyid )) {                  !key_array_search (ka, ka_pos, key->subkeys->keyid)) {
1029                  char *warn = new char[512+strlen (id) + 1];                  StringBuffer warn;
1030                  if (!warn)  
1031                      BUG (0);                  warn = warn + _("It is NOT certain that the key belongs to the person\n"
1032                  sprintf (warn,                           "named in the user ID.  If you *really* know what you are\n"
1033                      _("It is NOT certain that the key belongs to the person\n"                           "doing, you may answer the next question with yes\n"
1034                        "named in the user ID.  If you *really* know what you are\n"                           "\nStill proceed?");
                       "doing, you may answer the next question with yes\n"  
                       "\n"  
                       "Use \"%s\" anyway?"), id);  
1035                  if (reg_prefs.always_trust)                  if (reg_prefs.always_trust)
1036                      rc = IDYES;                      rc = IDYES;
1037                  else                  else
1038                      rc = msg_box (NULL, warn, _("Recipients"), MB_ERR_ASK);                      rc = msg_box (NULL, warn.getBuffer (), c->uids->uid, MB_ERR_ASK);
1039                  if (rc == IDYES) {                  if (rc == IDYES) {
1040                      gpgme_key_t k;                      keybuf[k_pos++] = key;
                     get_pubkey (keyid, &k);  
                     keybuf[k_pos++] = k;  
1041                      force_trust++;                      force_trust++;
1042                      ka[ka_pos].checked = 1;                      ka[ka_pos].checked = 1;
1043                      strcpy (ka[ka_pos++].keyid, keyid);                      strcpy (ka[ka_pos++].keyid, key->subkeys->keyid);
1044                      count++;                      count++;
1045                  }                  }
                 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, size_t *r_count)
1080  {  {
1081      gpgme_key_t* rset;      struct keycache_s *c;
1082      gpgme_key_t k;      gpgme_key_t *rset;
1083      int i, n, id, k_pos=0;      gpgme_key_t key;
1084      char keyid[32], t[128], t2[128];      size_t k_pos = 0;
1085        int i, n, id;
1086    
1087      n = listview_count_items (lv, 0);      n = listview_count_items (lv, 0);
1088      if (!n)      if (!n)
1089          return 0;          return 0;
1090      rset = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t));      rset = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t));
1091      if (!rset)      if (!rset)
1092          BUG (NULL);          BUG (NULL);
1093      for( i = 0; i < n; i++ ) {      for (i = 0; i < n; i++) {
1094          if( !listview_get_item_state( lv, i ) )          if (!listview_get_item_state (lv, i))
1095              continue;              continue;
1096          listview_get_item_text( lv, i, 1, keyid, sizeof keyid - 1 );          key = km_get_key_ptr (lv, i, &c);
1097          switch( listype ) {          switch (listype) {
1098          case KEYLIST_LIST:          case KEYLIST_LIST:
1099              listview_get_item_text( lv, i, 5, t, sizeof t - 1 );              if (keylist_get_keyflags (key) & KEYFLAG_REVOKED) {
1100              if( keylist_get_keyflags( t, strlen( t ) ) & KEYFLAG_REVOKED ) {                  id = printf_box (_("Recipients"), MB_INFO|MB_YESNO,
1101                  _snprintf( t2, sizeof t2 -1,                  _("KeyID %s.\nDo you really want to export a revoked key?"),
1102                              _("KeyID %s.\nDo you really want to export a revoked key?"), keyid );                                   c->uids->uid);
1103                  id = msg_box( lv->ctrl, t2, _("Recipients"), MB_INFO|MB_YESNO );                  if (id == IDNO)
1104                  if( id == IDNO )                      continue;
                     continue;            
1105              }              }
1106              break;              break;
1107          }          }
1108          get_pubkey (keyid, &k);          rset[k_pos++] = key;
         rset[k_pos++] = k;  
1109      }      }
1110      if (r_count)      if (r_count)
1111          *r_count = k_pos;          *r_count = k_pos;
1112      return rset;      return rset;
1113  } /* keylist_enum_recipients */  }
1114    
1115    
1116  void  void
1117  seclist_destroy (keylist_t * list)  seclist_destroy (keylist_t *list)
1118  {  {
1119      keylist_t l2;      keylist_t l2;
1120    
1121      while (*list) {      while (*list) {
1122          l2 = (*list)->next;          l2 = (*list)->next;
1123          safe_free (*list);          safe_free (*list);
1124          *list = l2;              *list = l2;    
1125      }      }
1126      list = NULL;      list = NULL;
1127  } /* seclist_destroy */  }
1128    
1129    
1130  void  void
# Line 1055  seclist_init (HWND dlg, int ctlid, int f Line 1144  seclist_init (HWND dlg, int ctlid, int f
1144      gpg_keycache_rewind (kc);      gpg_keycache_rewind (kc);
1145            
1146      while (!gpg_keycache_next_key (kc, 1, &key)) {      while (!gpg_keycache_next_key (kc, 1, &key)) {
1147          char *inf = NULL, *uid = NULL;          StringBuffer inf;
1148            char *uid;
1149          const char *id;          const char *id;
1150          const char *keyid;  
1151          int algo;          if (key->disabled || !key_is_useable (key->subkeys))
1152          size_t size = 0;              continue;
1153    
1154          if (flags & KEYLIST_FLAG_SHORT)          if (flags & KEYLIST_FLAG_SHORT)
1155              id = key->uids->name;              id = key->uids->name;
1156          else          else
1157              id = key->uids->uid;              id = key->uids->uid;
1158          keyid = key->subkeys->keyid;          if (!id || !key->subkeys->keyid)
1159          algo = key->subkeys->pubkey_algo;              continue;  
1160          if (!id || !keyid)  
1161              continue;          uid = utf8_to_native (id);
1162          if (key->disabled || !key_is_useable (key->subkeys))          inf = uid;
1163              continue;          inf = inf + " (" + get_key_pubalgo (key->subkeys->pubkey_algo) + "/";
1164            inf = inf + "0x" + (key->subkeys->keyid+8) + ")";
1165    
1166          uid = utf8_to_wincp (id, strlen (id));          combox_add_string (kb, inf.getBuffer ());
1167          size = strlen( uid ) + strlen( keyid ) + 32;          safe_free (uid);
         inf = new char[size+1];  
         if( !inf )  
             BUG( NULL );  
         _snprintf (inf, size, "%s (%s/0x%s)", uid,  
                    get_key_pubalgo (key->subkeys->pubkey_algo), keyid + 8);  
         combox_add_string (kb, inf);  
         free_if_alloc (inf);  
         free (uid);  
1168          l = (struct keylist_s *)calloc (1, sizeof * l);          l = (struct keylist_s *)calloc (1, sizeof * l);
1169          if (!l)          if (!l)
1170              BUG (0);              BUG (0);
# Line 1094  seclist_init (HWND dlg, int ctlid, int f Line 1177  seclist_init (HWND dlg, int ctlid, int f
1177              l2->next = l;              l2->next = l;
1178          }          }
1179      }      }
1180      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);
1181          SendMessage( kb, CB_SETITEMDATA, pos, (LPARAM)(DWORD)l2->key );           pos++, l2=l2->next)
1182      SendMessage( kb, CB_SETCURSEL, 0, 0 );          SendMessage (kb, CB_SETITEMDATA, pos, (LPARAM)(DWORD)l2->key);
1183        SendMessage (kb, CB_SETCURSEL, 0, 0);
1184      *ret_list = list;      *ret_list = list;
1185  }  }
1186                    

Legend:
Removed from v.88  
changed lines
  Added in v.278

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26