/[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 161 by twoaday, Thu Jan 19 16:10:37 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_user_id_t uid, 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 = uid->signatures; 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 204  get_key_algo (gpgme_key_t key, int keyid Line 189  get_key_algo (gpgme_key_t key, int keyid
189      if (keyidx > 0) {      if (keyidx > 0) {
190          k = get_nth_key (key, keyidx-1);          k = get_nth_key (key, keyidx-1);
191          subalg =  get_key_pubalgo (k->pubkey_algo);          subalg =  get_key_pubalgo (k->pubkey_algo);
192          _snprintf( algo_id, DIM (algo_id)-1, "%s", subalg);          _snprintf (algo_id, DIM (algo_id)-1, "%s", subalg);
193          return algo_id;          return algo_id;
194      }      }
195      strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo));      strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo));
# Line 216  get_key_algo (gpgme_key_t key, int keyid Line 201  get_key_algo (gpgme_key_t key, int keyid
201          return algo_id;          return algo_id;
202      }      }
203      return get_key_pubalgo (key->subkeys->pubkey_algo);      return get_key_pubalgo (key->subkeys->pubkey_algo);
204  } /* get_key_algo */  }
205    
206    
207  const char*  const char*
# Line 224  get_key_created (long timestamp) Line 209  get_key_created (long timestamp)
209  {  {
210      static char timebuf[128];      static char timebuf[128];
211      struct tm *warp;      struct tm *warp;
212        const char *dat;
213    
214      if (timestamp == 0 || timestamp == -1)      if (timestamp < 1)
215          return "????" "-??" "-??";          return "????" "-??" "-??";
216      warp = localtime( &timestamp );      dat = get_locale_date (timestamp, timebuf, sizeof (timebuf)-1);
217      _snprintf( timebuf, sizeof timebuf - 1, "%04d-%02d-%02d",      if (dat)
218                  warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday );          return dat;
219        warp = localtime (&timestamp);
220        _snprintf (timebuf, sizeof timebuf - 1, "%04d-%02d-%02d",
221                   warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday);
222      return timebuf;      return timebuf;
223  } /* get_key_created */  }
224    
225    
226  /* 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 229  get_key_expire_date (long timestamp)
229  {  {
230      static char timebuf[64];      static char timebuf[64];
231      struct tm *warp;      struct tm *warp;
232        const char *dat;
233    
234      if( !timestamp )      if (timestamp == 0)
235          return _("Never");          return _("Never");
236      warp = localtime( &timestamp );      dat = get_locale_date (timestamp, timebuf, sizeof (timebuf)-1);
237        if (dat)
238            return dat;
239        warp = localtime (&timestamp);
240      _snprintf (timebuf, sizeof timebuf -1, "%04d-%02d-%02d",      _snprintf (timebuf, sizeof timebuf -1, "%04d-%02d-%02d",
241                 warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday);                 warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday);
242      return timebuf;      return timebuf;
# Line 260  get_key_type (gpgme_key_t key) Line 253  get_key_type (gpgme_key_t key)
253      else if (type == 2)      else if (type == 2)
254          return _("Key Pair (Card)");          return _("Key Pair (Card)");
255      return _("Public Key");      return _("Public Key");
256  } /* get_key_type */  }
257    
258    
259  const char*  const char*
# Line 281  get_key_size (gpgme_key_t key, int keyid Line 274  get_key_size (gpgme_key_t key, int keyid
274      if (n > 1) {      if (n > 1) {
275          k = get_nth_key (key, n-1);          k = get_nth_key (key, n-1);
276          size_sub = k->length;          size_sub = k->length;
277          _snprintf( size_id, sizeof (size_id) - 1, "%d/%d", size_main, size_sub );          _snprintf (size_id, sizeof (size_id) - 1, "%d/%d",
278                        size_main, size_sub);
279          return size_id;          return size_id;
280      }      }
281      _snprintf( size_id, sizeof (size_id) - 1, "%d", size_main );      _snprintf( size_id, sizeof (size_id) - 1, "%d", size_main );
282      return size_id;      return size_id;
283  } /* get_key_size */  }
284    
285    
286    const char*
287    get_key_pubalgo2 (gpgme_pubkey_algo_t alg)
288    {
289        switch (alg) {
290        case GPGME_PK_DSA: return "D";
291        case GPGME_PK_RSA: return "R";
292        case GPGME_PK_ELG: return "G";
293        default: return "?";
294        }
295        return "?";
296    }
297    
298    
299  const char*  const char*
# Line 302  get_key_pubalgo (gpgme_pubkey_algo_t alg Line 309  get_key_pubalgo (gpgme_pubkey_algo_t alg
309      return "???";      return "???";
310  }  }
311    
312  const char *  const char*
313  get_key_fpr (gpgme_key_t key)  get_key_fpr (gpgme_key_t key)
314  {  {
315      static char fpr_md[64];      static char fpr_md[64];
# Line 331  get_key_fpr (gpgme_key_t key) Line 338  get_key_fpr (gpgme_key_t key)
338          }          }
339      }      }
340      return fpr_md;      return fpr_md;
341  } /* get_key_fpr */  }
342    
343    
344  const char *  const char*
345  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)
346  {  {
347      if (key)      if (key)
# Line 342  get_key_trust2 (gpgme_key_t key, int val Line 349  get_key_trust2 (gpgme_key_t key, int val
349      switch (val) {      switch (val) {
350      case GPGME_VALIDITY_UNKNOWN:      case GPGME_VALIDITY_UNKNOWN:
351      case GPGME_VALIDITY_UNDEFINED:          case GPGME_VALIDITY_UNDEFINED:    
352          return "None";          return _("None");
353      case GPGME_VALIDITY_NEVER:          case GPGME_VALIDITY_NEVER:    
354          return "Never";          return _("Never");
355      case GPGME_VALIDITY_MARGINAL:      case GPGME_VALIDITY_MARGINAL:
356          return "Marginal";          return _("Marginal");
357      case GPGME_VALIDITY_FULL:      case GPGME_VALIDITY_FULL:
358      case GPGME_VALIDITY_ULTIMATE:      case GPGME_VALIDITY_ULTIMATE:
359          return "Full";          return _("Full");
360      }      }
361      return "";      return "";
362  }  }
# Line 380  get_key_status (gpgme_key_t key, int uid Line 387  get_key_status (gpgme_key_t key, int uid
387      if (uididx < 0 || count_userids (key) > uididx)      if (uididx < 0 || count_userids (key) > uididx)
388          uididx = 0;          uididx = 0;
389      if (listmode) {      if (listmode) {
390          const char *s;          const char *s;
         
391          if (key->revoked)          if (key->revoked)
392              s = _("Revoked");              s = _("Revoked");
393          else if (key->expired)          else if (key->expired)
394              s = _("Expired");              s = _("Expired");
395          else if (key->disabled)          else if (key->disabled)
396              s = _("Disabled");              s = _("Disabled");
397          else          else
398            s = "";              s = "";
           
399          /* 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
400             what any user-id validities. */             the user-id validities. */
401          if (*s)          if (*s)
402              return m_strdup (s);              return m_strdup (s);
403      }      }
# Line 424  get_ext_validity (gpgme_key_t k) Line 429  get_ext_validity (gpgme_key_t k)
429          return GPGME_VALIDITY_ULTIMATE+1;          return GPGME_VALIDITY_ULTIMATE+1;
430      else if (k->expired)      else if (k->expired)
431          return GPGME_VALIDITY_ULTIMATE+2;          return GPGME_VALIDITY_ULTIMATE+2;
432        else if (k->disabled)
433            return GPGME_VALIDITY_ULTIMATE+3;
434      return k->uids->validity;      return k->uids->validity;
435  }  }
436    
# Line 491  keylist_cmp_cb (LPARAM first, LPARAM sec Line 498  keylist_cmp_cb (LPARAM first, LPARAM sec
498  }  }
499    
500    
501    #if 0
502  /* Return the validity of the group @grp. */  /* Return the validity of the group @grp. */
503  static const char*  static const char*
504  calc_validity (gpg_group_t grp)  calc_validity (gpg_group_t grp)
505  {  {
506      int valid=0;      int valid = 0;
507      gpg_member_t mbr;      gpg_member_t mbr;
508      gpgme_key_t key;      gpgme_key_t key;
509    
# Line 512  calc_validity (gpg_group_t grp) Line 520  calc_validity (gpg_group_t grp)
520      }      }
521      return _("Full");      return _("Full");
522  }  }
523    #endif
524    
525    
526  int  int
527  keylist_add_groups( listview_ctrl_t lv )  keylist_add_groups (listview_ctrl_t lv)
528  {  {
 #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  
529      return 0;      return 0;
530  } /* keylist_add_groups */  }
531    
532    
533  /* 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 535  keylist_add_groups( listview_ctrl_t lv )
535  static int  static int
536  keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode)  keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode)
537  {  {
538        struct listview_column_s klist_enc[] = {
539        {0, 242, (char *)_("User ID")},
540        {1, 80, (char *)_("Key ID")},
541        {3, 46, (char *)_("Size")},
542        {4, 50, (char *)_("Cipher")},
543        {5, 70, (char *)_("Validity")},
544        {0, 0, NULL}
545        };
546        struct listview_column_s klist[] = {
547        {0, 240, (char *)_("User ID")},
548        {1, 78, (char *)_("Key ID")},
549        {2, 52, (char *)_("Type")},    
550        {3, 66, (char *)_("Size")},
551        {4, 60, (char *)_("Cipher")},
552        {5, 66, (char *)_("Validity")},
553        {6, 58, (char *)_("Trust")},
554        {7, 72, (char *)_("Creation")},
555        {0, 0, NULL}
556        };
557        HICON ico[2];
558      listview_ctrl_t lv;      listview_ctrl_t lv;
559      listview_column_t col;      listview_column_t col;
560      int j, n = 0;      int j, n = 0;
561      int rc = 0;      int rc = 0;
562            
563      rc = listview_new (&lv);      rc = listview_new (&lv);
564      if( rc )      if (rc)
565          return rc;          return rc;
566            
567      lv->ctrl = ctrl;      lv->ctrl = ctrl;
568      if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) {      if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) {
569          col = klist_enc;          col = klist_enc;
570          n = KLIST_ENC_ITEMS;          n = (DIM(klist_enc) -1);
571      }        }  
572      else if ((mode & KEYLIST_SIGN)) {      else if ((mode & KEYLIST_SIGN)) {
573          col = klist_enc;          col = klist_enc;
574          n = KLIST_ENC_ITEMS - 1;          n = (DIM(klist_enc) - 1) - 1;
575      }      }
576      else {      else {
577          col = klist;          col = klist;
578          n = KLIST_ITEMS;          n = (DIM(klist) - 1);
579      }      }
580            
581      for( j = 0; j < n; j++ )          for (j = 0; j < n; j++)
582          listview_add_column( lv, &col[j] );              listview_add_column (lv, &col[j]);
583      listview_set_ext_style( lv );      listview_set_ext_style (lv);
584        ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY);
585        ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR);
586        listview_set_image_list (lv, ico, 2);
587        listview_del_all_items (lv);
588    
589      *r_lv = lv;      *r_lv = lv;
       
590      return 0;      return 0;
591  }  }
592    
# Line 628  keylist_load (HWND ctrl, gpg_keycache_t Line 642  keylist_load (HWND ctrl, gpg_keycache_t
642  int  int
643  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)
644  {  {
645      listview_del_all (lv);      listview_del_all_items (lv);
646      keylist_load_keycache( lv, mode, pubkc, NULL );      keylist_load_keycache (lv, mode, pubkc, NULL);
647      keylist_sort (lv, sortby);      keylist_sort (lv, sortby);
648      return 0;      return 0;
649  }  }
# Line 677  do_addkey (listview_ctrl_t lv, gpgme_key Line 691  do_addkey (listview_ctrl_t lv, gpgme_key
691      /* we check the pubkey algorithm here to make sure that no ElGamal      /* we check the pubkey algorithm here to make sure that no ElGamal
692         sign+encrypt key is used in _any_ mode */         sign+encrypt key is used in _any_ mode */
693      if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) {      if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) {
694          log_debug ("ElGamal (E+S) key found: %s (%s)\n",          log_debug ("ElGamal (E+S) key found: %s (%s)\n",
695                     key->uids->name, key->subkeys->keyid);                     key->uids->name, key->subkeys->keyid);
696          return 0;          return 0;
697      }      }
   
698                    
699      if (listview_add_item2 (lv, " ", (void *)key))            if (listview_add_item2 (lv, " ", (void *)key))
700          return WPTERR_GENERAL;          return WPTERR_GENERAL;
701            
702      attr = key->uids->uid;      attr = key->uids->uid;
703      memset (&lvi, 0, sizeof lvi);      memset (&lvi, 0, sizeof lvi);
704      lvi.mask = LVIF_TEXT | LVIF_PARAM;      lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
705      lvi.pszText = (char *)attr;      lvi.pszText = (char *)attr;
706        lvi.iImage = find_secret_key (key)? 1 : 0;
707      lvi.lParam = (LPARAM )key;      lvi.lParam = (LPARAM )key;
708      if (ListView_SetItem( lv->ctrl, &lvi ) == FALSE)      if (ListView_SetItem (lv->ctrl, &lvi) == FALSE)
709          return WPTERR_GENERAL;          return WPTERR_GENERAL;
710                    
711      if (uididx == -1) { /* request the primary user-id of the key. */      if (uididx == -1) { /* request the primary user-id of the key. */
# Line 701  do_addkey (listview_ctrl_t lv, gpgme_key Line 715  do_addkey (listview_ctrl_t lv, gpgme_key
715      else {      else {
716          u = get_nth_userid (key, uididx);          u = get_nth_userid (key, uididx);
717          if (!u || u->revoked || uididx < 0)          if (!u || u->revoked || uididx < 0)
718              uididx = 0; /* fixme: this happen sometimes but it's illegal! (<0) */              uididx = 0;
719          u = get_nth_userid (key, uididx);          u = get_nth_userid (key, uididx);
         /*attr = key->uids->uid; XXX*/  
720          attr = u->uid;          attr = u->uid;
721      }      }
722      if (attr == NULL || strlen (attr) < 5) { /* normal userids are >= 5 chars */      if (attr == NULL || strlen (attr) < 5) { /* normal userids are > 5 chars */
723          attr = _("Invalid User ID");          attr = _("Invalid User ID");
724          listview_add_sub_item (lv, 0, idx++, attr);          listview_add_sub_item (lv, 0, idx++, attr);
725      }        }  
# Line 764  do_addkey (listview_ctrl_t lv, gpgme_key Line 777  do_addkey (listview_ctrl_t lv, gpgme_key
777  }  }
778    
779    
780    /* Update a single column @col but for each element in the
781       listview @lv. */
782    void
783    keylist_upd_col (listview_ctrl_t lv, int col)
784    {
785        gpgme_key_t key;
786        const char *s;
787        char buf[32];
788        int i;
789    
790        for (i=0; i < listview_count_items (lv, 0); i++) {
791            key = (gpgme_key_t)listview_get_item2 (lv, i);
792            if (!key)
793                continue;
794            switch (col) {
795            case KM_COL_KEYID:
796                _snprintf (buf, sizeof (buf)-1, "0x%s", key->subkeys->keyid+8);
797                listview_add_sub_item (lv, i, col, buf);
798                break;
799    
800            case KM_COL_CIPHER:
801                s = get_key_algo (key, 0);
802                listview_add_sub_item (lv, i, col, s);
803                break;
804    
805            case KM_COL_TYPE:
806                s = find_secret_key (key)? "pub/sec" : "pub";
807                listview_add_sub_item (lv, i, col, s);
808                break;
809    
810            case KM_COL_CREAT:
811                s = get_key_created (key->subkeys->timestamp);
812                listview_add_sub_item (lv, i, col, s);
813                break;
814            }
815        }
816    }
817    
818    
819    /* Update the listview item at position @pos with the data from
820       the key @key. */
821  void  void
822  keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key)  keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key)
823  {  {
824      const char *s;      const char *s;
825        char *uid;
826      char tmp[32];      char tmp[32];
827    
828      listview_set_item2 (lv, pos, (void *)key);      listview_set_item2 (lv, pos, (void *)key);
829      /* the only mode we support is KYLIST_LIST in the Key Manager */      /* the only mode we support is KYLIST_LIST in the Key Manager */
830            
831      s = key->uids->uid;      s = key->uids->uid;
832      if (s)      if (s) {
833          listview_add_sub_item (lv, pos, 0, s);          uid = utf8_to_wincp2 (s);
834            listview_add_sub_item (lv, pos, 0, uid);
835            free (uid);
836        }
837    
838      s = key->subkeys->keyid;      s = key->subkeys->keyid;
839      if (s) {      if (s) {
# Line 816  keylist_add_key (listview_ctrl_t lv, int Line 874  keylist_add_key (listview_ctrl_t lv, int
874      gpgme_subkey_t k;      gpgme_subkey_t k;
875    
876      /* if the entire key is disabled, just return. */      /* if the entire key is disabled, just return. */
877      if (key->disabled)      if (key->disabled && !(mode & KEYLIST_LIST))
878          return 0;          return 0;
879    
880      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 828  keylist_add_key (listview_ctrl_t lv, int Line 886  keylist_add_key (listview_ctrl_t lv, int
886          if (mode & KEYLIST_ALL) {          if (mode & KEYLIST_ALL) {
887              uids = count_userids (key);              uids = count_userids (key);
888              rc = do_addkey (lv, key, uids, i, 0);              rc = do_addkey (lv, key, uids, i, 0);
889              if( rc )              if (rc)
890                  return rc;                  return rc;
891          }          }
892          else if (mode & KEYLIST_LIST)          else if (mode & KEYLIST_LIST)
# Line 841  keylist_add_key (listview_ctrl_t lv, int Line 899  keylist_add_key (listview_ctrl_t lv, int
899                          return rc;                          return rc;
900                  }                  }
901                  else {                  else {
902                      for( uids = 0;  uids < count_userids (key); uids++ ) {                      for (uids = 0;  uids < count_userids (key); uids++) {
903                          rc = do_addkey( lv, key, uids, i, -1 );                          rc = do_addkey (lv, key, uids, i, -1);
904                          if( rc )                          if (rc)
905                              return rc;                              return rc;
906                      }                      }
907                  }                  }
# Line 868  keylist_add_key (listview_ctrl_t lv, int Line 926  keylist_add_key (listview_ctrl_t lv, int
926      }      }
927    
928      return rc;        return rc;  
929  } /* keylist_add_key */  }
930    
931    
932  int  int
933  keylist_sort (listview_ctrl_t lv, int sortby)  keylist_sort (listview_ctrl_t lv, int sortby)
934  {        {
935      return listview_sort_items (lv, sortby, keylist_cmp_cb);      return listview_sort_items (lv, sortby, keylist_cmp_cb);
936  }  }
937    
938    
939  /* Check that the validity @validity is at least >= marginal. */  /* Check that the validity @validity is at least >= marginal. */
940  static int  static int
941  key_check_validity (const char *validity)  key_check_validity (gpgme_key_t key)
942  {      {
943      if (strstr (validity, "Unknown") ||      gpgme_user_id_t u;
944          strstr (validity, "Undefined") ||  
945          strstr (validity, "Never") ||      for (u=key->uids; u; u =u->next) {
946          strstr (validity, "None"))          if (u->validity >= GPGME_VALIDITY_MARGINAL)
947          return 0;                return -1;
948      return 1;      }
949    
950        return 0;
951  }  }
952    
953    
# Line 898  key_check_validity (const char *validity Line 958  key_check_validity (const char *validity
958  gpgme_key_t*  gpgme_key_t*
959  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)
960  {  {
961        key_array_s *ka = NULL;
962        gpgme_key_t *keybuf, key;
963      int count = 0, force_trust = 0;      int count = 0, force_trust = 0;
964      int n, j, ka_pos = 0, rc = 0;      int n, j, ka_pos = 0, rc = 0;
965      int k_pos=0;      int k_pos=0;
     char keyid[32], valid[32], id[100];  
     key_array_s *ka = NULL;  
     gpgme_key_t *keybuf;  
966    
967      n = listview_count_items( lv, 0 );      n = listview_count_items (lv, 0);
968            
969      ka = key_array_new( n );      ka = key_array_new (n);
970      if (!ka)      if (!ka)
971          BUG (NULL);          BUG (NULL);
972    
# Line 915  keylist_get_recipients (listview_ctrl_t Line 974  keylist_get_recipients (listview_ctrl_t
974      if (!keybuf)      if (!keybuf)
975          BUG (NULL);          BUG (NULL);
976                    
977      for( j = 0; j < n; j++ ) {      for (j = 0; j < n; j++) {
978          if( listview_get_item_state (lv, j) || n == 1) {          if (listview_get_item_state (lv, j) || n == 1) {
979              listview_get_item_text (lv, j, 0, id, sizeof id-1);              key = (gpgme_key_t)listview_get_item2 (lv, j);
980              listview_get_item_text (lv, j, 1, keyid, sizeof keyid - 1);                              if (!key)
981              listview_get_item_text (lv, j, 4, valid, sizeof valid -1);                  BUG (0);
982              if( !key_check_validity (valid)              if (!key_check_validity (key) &&
983                   && !key_array_search( ka, ka_pos, keyid )) {                  !key_array_search (ka, ka_pos, key->subkeys->keyid)) {
984                  char *warn = new char[512+strlen (id) + 1];                  char *warn = new char[512+strlen (key->uids->uid) + 1];
985                  if (!warn)                  if (!warn)
986                      BUG (0);                      BUG (0);
987                  sprintf (warn,                  sprintf (warn,
# Line 930  keylist_get_recipients (listview_ctrl_t Line 989  keylist_get_recipients (listview_ctrl_t
989                        "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"
990                        "doing, you may answer the next question with yes\n"                        "doing, you may answer the next question with yes\n"
991                        "\n"                        "\n"
992                        "Use \"%s\" anyway?"), id);                        "Use \"%s\" anyway?"), key->uids->uid);
993                  if (reg_prefs.always_trust)                  if (reg_prefs.always_trust)
994                      rc = IDYES;                      rc = IDYES;
995                  else                  else
996                      rc = msg_box (NULL, warn, _("Recipients"), MB_ERR_ASK);                      rc = msg_box (NULL, warn, _("Recipients"), MB_ERR_ASK);
997                  if (rc == IDYES) {                  if (rc == IDYES) {
998                      gpgme_key_t k;                      keybuf[k_pos++] = key;
                     get_pubkey (keyid, &k);  
                     keybuf[k_pos++] = k;  
999                      force_trust++;                      force_trust++;
1000                      ka[ka_pos].checked = 1;                      ka[ka_pos].checked = 1;
1001                      strcpy (ka[ka_pos++].keyid, keyid);                      strcpy (ka[ka_pos++].keyid, key->subkeys->keyid);
1002                      count++;                      count++;
1003                  }                  }
1004                  free_if_alloc (warn);                  free_if_alloc (warn);
1005              }              }
1006              else {              else {
1007                  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;  
1008                  count++;                          count++;        
1009              }              }
1010          }          }
# Line 965  keylist_get_recipients (listview_ctrl_t Line 1019  keylist_get_recipients (listview_ctrl_t
1019    
1020    
1021  static int  static int
1022  keylist_get_keyflags (const char *buf, size_t buflen)  keylist_get_keyflags (gpgme_key_t key)
1023  {  {
1024      int c = 0, flags = 0;      int flags = KEYFLAG_NONE;
1025    
1026      if( *buf != '[' )      if (key->revoked)
1027          return KEYFLAG_NONE;          flags |= KEYFLAG_REVOKED;
1028      while (buf && c != ']')      if (key->expired)
1029      {          flags |= KEYFLAG_EXPIRED;
1030          c = *buf++;      if (key->disabled)
1031          if (c == 'R')          flags |= KEYFLAG_DISABLED;
             flags |= KEYFLAG_REVOKED;  
         if (c == 'E')  
             flags |= KEYFLAG_EXPIRED;  
         if (c == 'D')  
             flags |= KEYFLAG_DISABLED;  
     }  
1032    
1033      return flags;      return flags;
1034  } /* keylist_get_keyflags */  }
1035    
1036    
1037  gpgme_key_t*  gpgme_key_t*
1038  keylist_enum_recipients (listview_ctrl_t lv,  int listype, int *r_count)  keylist_enum_recipients (listview_ctrl_t lv,  int listype, int *r_count)
1039  {  {
1040      gpgme_key_t* rset;      gpgme_key_t *rset;
1041      gpgme_key_t k;      gpgme_key_t key;
1042      int i, n, id, k_pos=0;      int i, n, id, k_pos=0;
     char keyid[32], t[128], t2[128];  
1043    
1044      n = listview_count_items (lv, 0);      n = listview_count_items (lv, 0);
1045      if (!n)      if (!n)
# Line 1000  keylist_enum_recipients (listview_ctrl_t Line 1047  keylist_enum_recipients (listview_ctrl_t
1047      rset = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t));      rset = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t));
1048      if (!rset)      if (!rset)
1049          BUG (NULL);          BUG (NULL);
1050      for( i = 0; i < n; i++ ) {      for (i = 0; i < n; i++) {
1051          if( !listview_get_item_state( lv, i ) )          if (!listview_get_item_state (lv, i))
1052              continue;              continue;
1053          listview_get_item_text( lv, i, 1, keyid, sizeof keyid - 1 );          key = (gpgme_key_t)listview_get_item2 (lv, i);
1054          switch( listype ) {          if (!key)
1055                BUG (0);
1056            switch (listype) {
1057          case KEYLIST_LIST:          case KEYLIST_LIST:
1058              listview_get_item_text( lv, i, 5, t, sizeof t - 1 );              if (keylist_get_keyflags (key) & KEYFLAG_REVOKED) {
1059              if( keylist_get_keyflags( t, strlen( t ) ) & KEYFLAG_REVOKED ) {                  id = printf_box (_("Recipients"), MB_INFO|MB_YESNO,
1060                  _snprintf( t2, sizeof t2 -1,                  _("KeyID %s.\nDo you really want to export a revoked key?"),
1061                              _("KeyID %s.\nDo you really want to export a revoked key?"), keyid );                                   key->uids->uid);
1062                  id = msg_box( lv->ctrl, t2, _("Recipients"), MB_INFO|MB_YESNO );                  if (id == IDNO)
1063                  if( id == IDNO )                      continue;
                     continue;            
1064              }              }
1065              break;              break;
1066          }          }
1067          get_pubkey (keyid, &k);          rset[k_pos++] = key;
         rset[k_pos++] = k;  
1068      }      }
1069      if (r_count)      if (r_count)
1070          *r_count = k_pos;          *r_count = k_pos;
1071      return rset;      return rset;
1072  } /* keylist_enum_recipients */  }
1073    
1074    
1075  void  void
1076  seclist_destroy (keylist_t * list)  seclist_destroy (keylist_t *list)
1077  {  {
1078      keylist_t l2;      keylist_t l2;
1079      while (*list) {      while (*list) {
# Line 1035  seclist_destroy (keylist_t * list) Line 1082  seclist_destroy (keylist_t * list)
1082          *list = l2;              *list = l2;    
1083      }      }
1084      list = NULL;      list = NULL;
1085  } /* seclist_destroy */  }
1086    
1087    
1088  void  void
# Line 1073  seclist_init (HWND dlg, int ctlid, int f Line 1120  seclist_init (HWND dlg, int ctlid, int f
1120              continue;              continue;
1121    
1122          uid = utf8_to_wincp (id, strlen (id));          uid = utf8_to_wincp (id, strlen (id));
1123          size = strlen( uid ) + strlen( keyid ) + 32;          size = strlen (uid) + strlen (keyid) + 32;
1124          inf = new char[size+1];          inf = new char[size+1];
1125          if( !inf )          if (!inf)
1126              BUG( NULL );              BUG (NULL);
1127          _snprintf (inf, size, "%s (%s/0x%s)", uid,          _snprintf (inf, size, "%s (%s/0x%s)", uid,
1128                     get_key_pubalgo (key->subkeys->pubkey_algo), keyid + 8);                     get_key_pubalgo (key->subkeys->pubkey_algo), keyid + 8);
1129          combox_add_string (kb, inf);          combox_add_string (kb, inf);
1130          free_if_alloc (inf);          free_if_alloc (inf);
# Line 1094  seclist_init (HWND dlg, int ctlid, int f Line 1141  seclist_init (HWND dlg, int ctlid, int f
1141              l2->next = l;              l2->next = l;
1142          }          }
1143      }      }
1144      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);
1145          SendMessage( kb, CB_SETITEMDATA, pos, (LPARAM)(DWORD)l2->key );           pos++, l2=l2->next)
1146      SendMessage( kb, CB_SETCURSEL, 0, 0 );          SendMessage (kb, CB_SETITEMDATA, pos, (LPARAM)(DWORD)l2->key);
1147        SendMessage (kb, CB_SETCURSEL, 0, 0);
1148      *ret_list = list;      *ret_list = list;
1149  }  }
1150                    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26