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

Diff of /trunk/Src/wptKeyEditDlgs.cpp

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

revision 220 by twoaday, Tue May 30 15:31:49 2006 UTC revision 225 by twoaday, Tue Jun 6 13:37:59 2006 UTC
# Line 151  static subclass_s keyedit_subkey_proc; Line 151  static subclass_s keyedit_subkey_proc;
151  static subclass_s keyedit_uid_proc;  static subclass_s keyedit_uid_proc;
152    
153  int keygen_check_date (SYSTEMTIME *st);  int keygen_check_date (SYSTEMTIME *st);
154  void get_userid_preflist (char **r_prefs, int * r_flags);  void get_userid_preflist (char **r_prefs, int *r_flags);
155  char* get_subkey_keyid (const char *keyid);  char* get_subkey_keyid (const char *keyid);
   
156  void ComboBox_AddString_utf8 (HWND cb, const char *txt);  void ComboBox_AddString_utf8 (HWND cb, const char *txt);
157    
158    
159    /* Safe wrapper for allocation. */
160  static GpgKeyEdit*  static GpgKeyEdit*
161  create_GpgKeyEdit (const char *keyid)  create_GpgKeyEdit (const char *keyid)
162  {  {
# Line 179  do_init_keylist (HWND dlg, const char *k Line 180  do_init_keylist (HWND dlg, const char *k
180      int i, n;      int i, n;
181    
182      pub = keycache_get_ctx (1);      pub = keycache_get_ctx (1);
     if (!pub)  
         BUG (0);  
   
183      gpg_keycache_rewind (pub);      gpg_keycache_rewind (pub);
184      while( !gpg_keycache_next_key (pub, 0, &key)) {      while (!gpg_keycache_next_key (pub, 0, &key)) {
185          if (key->expired || key->revoked ||          if (key->expired || key->revoked ||
186              key->disabled || key->invalid)              key->disabled || key->invalid)
187              continue;              continue;
# Line 282  do_find_userid (const char *keyid, const Line 280  do_find_userid (const char *keyid, const
280      delete ke;      delete ke;
281      if (err) {      if (err) {
282          log_box (_("user ID"), MB_ERR,          log_box (_("user ID"), MB_ERR,
283                  _("Could not get key information for: \"%s\":\n%s"),                   _("Could not get key information for: \"%s\":\n%s"),
284                  name, gpgme_strerror (err));                   name, gpgme_strerror (err));
285          return -1;          return -1;
286      }      }
287    
# Line 362  keyedit_addphoto_dlg_proc (HWND dlg, UIN Line 360  keyedit_addphoto_dlg_proc (HWND dlg, UIN
360          SetForegroundWindow (dlg);          SetForegroundWindow (dlg);
361          break;          break;
362    
     case WM_DESTROY:  
         break;  
   
     case WM_SYSCOMMAND:  
         if (LOWORD (wparam) == SC_CLOSE)  
             EndDialog (dlg, TRUE);  
         break;  
   
363      case WM_COMMAND:      case WM_COMMAND:
364          switch( LOWORD (wparam)) {          switch( LOWORD (wparam)) {
365          case IDC_ADDPHOTO_SELFILE:          case IDC_ADDPHOTO_SELFILE:
# Line 387  keyedit_addphoto_dlg_proc (HWND dlg, UIN Line 377  keyedit_addphoto_dlg_proc (HWND dlg, UIN
377    
378          case IDOK:          case IDOK:
379              if (!GetDlgItemText (dlg, IDC_ADDPHOTO_FILE, file, sizeof (file)-1)){              if (!GetDlgItemText (dlg, IDC_ADDPHOTO_FILE, file, sizeof (file)-1)){
380                  msg_box( dlg, _("Please enter a file name."), _("Add Photo"), MB_ERR);                  msg_box (dlg, _("Please enter a file name."),
381                             _("Add Photo"), MB_ERR);
382                  return FALSE;                  return FALSE;
383              }              }
384              if (get_file_size (file) == 0 || get_file_size (file) > 6144) {              if (get_file_size (file) == 0 || get_file_size (file) > 6144) {
# Line 451  keyedit_addrevoker_dlg_proc (HWND dlg, U Line 442  keyedit_addrevoker_dlg_proc (HWND dlg, U
442          center_window (dlg, cb->parent);          center_window (dlg, cb->parent);
443          break;          break;
444    
     case WM_SYSCOMMAND:  
         if (LOWORD (wparam) == SC_CLOSE)  
             EndDialog (dlg, FALSE);  
         break;  
   
445      case WM_COMMAND:      case WM_COMMAND:
446          switch (LOWORD (wparam)) {          switch (LOWORD (wparam)) {
447          case IDOK:          case IDOK:
# Line 521  keyedit_adduid_dlg_proc (HWND dlg, UINT Line 507  keyedit_adduid_dlg_proc (HWND dlg, UINT
507          center_window (dlg, ctx->parent);          center_window (dlg, ctx->parent);
508          return FALSE;          return FALSE;
509                    
     case WM_SYSCOMMAND:  
         if (LOWORD (wparam) == SC_CLOSE)  
             EndDialog(dlg, TRUE);  
         return FALSE;  
           
510      case WM_COMMAND:      case WM_COMMAND:
511          switch ( LOWORD( wparam ) )  {          switch ( LOWORD( wparam ) )  {
512          case IDOK:          case IDOK:
# Line 540  keyedit_adduid_dlg_proc (HWND dlg, UINT Line 521  keyedit_adduid_dlg_proc (HWND dlg, UINT
521              if (strchr (utf8_name, '@')) {              if (strchr (utf8_name, '@')) {
522                  msg_box (dlg, _("Please enter the email address in the email field and not in the name field"),                  msg_box (dlg, _("Please enter the email address in the email field and not in the name field"),
523                           _("UserID"), MB_INFO);                           _("UserID"), MB_INFO);
524                    free_if_alloc (utf8_name);
525                  return FALSE;                  return FALSE;
526              }              }
527    
528              if( !GetDlgItemText (dlg, IDC_ADDUID_EMAIL, email, sizeof (email) -1)) {              if( !GetDlgItemText (dlg, IDC_ADDUID_EMAIL, email, sizeof (email) -1)) {
529                  msg_box( dlg, _("Please enter an email address."), _("UserID"), MB_ERR );                  msg_box (dlg, _("Please enter an email address."), _("UserID"), MB_ERR);
530                    free_if_alloc (utf8_name);
531                  return FALSE;                  return FALSE;
532              }              }
533              if (check_email_address (email)) {              if (check_email_address (email)) {
534                  msg_box (dlg, _("Invalid email address."), _("UserID"), MB_ERR);                  msg_box (dlg, _("Invalid email address."), _("UserID"), MB_ERR);
535                    free_if_alloc (utf8_name);
536                  return FALSE;                  return FALSE;
537              }              }
538                            
# Line 565  keyedit_adduid_dlg_proc (HWND dlg, UINT Line 549  keyedit_adduid_dlg_proc (HWND dlg, UINT
549              else {              else {
550                  msg_box (dlg, _("user ID successfully added."), _("GnuPG Status"), MB_OK);                  msg_box (dlg, _("user ID successfully added."), _("GnuPG Status"), MB_OK);
551                  ctx->finished = 1;                  ctx->finished = 1;
552                    /* The caller releases this items later. */
553                  keygen->name = utf8_name;                  keygen->name = utf8_name;
554                  keygen->comment = utf8_comment;                  keygen->comment = utf8_comment;
555                  keygen->email = m_strdup (email);                  keygen->email = m_strdup (email);
# Line 584  keyedit_adduid_dlg_proc (HWND dlg, UINT Line 569  keyedit_adduid_dlg_proc (HWND dlg, UINT
569  }  }
570    
571    
572    /* Initalize a combo box with default key sizes (1024-4096). */
573  static void  static void
574  init_keysize_box (HWND dlg, int ctlid)  init_keysize_box (HWND dlg, int ctlid)
575  {  {
# Line 644  keyedit_addsubkey_dlg_proc (HWND dlg, UI Line 630  keyedit_addsubkey_dlg_proc (HWND dlg, UI
630      switch (msg) {      switch (msg) {
631      case WM_INITDIALOG:      case WM_INITDIALOG:
632          ctx = (keyedit_cb_t)lparam;          ctx = (keyedit_cb_t)lparam;
633          if (!ctx)          if (!ctx)
634              dlg_fatal_error (dlg, "Could not get dialog param!");              BUG (0);
   
635          SetWindowText (dlg, _("Add new Subkey"));          SetWindowText (dlg, _("Add new Subkey"));
636          SetDlgItemText (dlg, IDC_ADDSUBKEY_INFALGO, _("Key type"));          SetDlgItemText (dlg, IDC_ADDSUBKEY_INFALGO, _("Key type"));
637          SetDlgItemText (dlg, IDC_ADDSUBKEY_INFSIZE, _("Size in bits"));          SetDlgItemText (dlg, IDC_ADDSUBKEY_INFSIZE, _("Size in bits"));
# Line 666  keyedit_addsubkey_dlg_proc (HWND dlg, UI Line 651  keyedit_addsubkey_dlg_proc (HWND dlg, UI
651          center_window (dlg, ctx->parent);          center_window (dlg, ctx->parent);
652          return FALSE;          return FALSE;
653                    
     case WM_SYSCOMMAND:  
         if (LOWORD (wparam) == SC_CLOSE)  
             EndDialog (dlg, TRUE);  
         return FALSE;  
           
654      case WM_COMMAND:      case WM_COMMAND:
655          if (HIWORD (wparam) == BN_CLICKED &&          if (HIWORD (wparam) == BN_CLICKED &&
656              LOWORD (wparam) == IDC_ADDSUBKEY_EXPIRE) {              LOWORD (wparam) == IDC_ADDSUBKEY_EXPIRE) {
# Line 771  keyedit_add_userid (winpt_key_t k, HWND Line 751  keyedit_add_userid (winpt_key_t k, HWND
751      }      }
752    
753      if (k->is_protected) {      if (k->is_protected) {
754          pass = request_passphrase (_("Key Edit"), 1, &cancel);          pass = request_key_passphrase (k->ctx, _("Key Edit"), &cancel);
755          if (cancel)          if (cancel)
756              return FALSE;              return FALSE;
757      }      }
# Line 839  keyedit_add_subkey (winpt_key_t k, HWND Line 819  keyedit_add_subkey (winpt_key_t k, HWND
819          return FALSE;          return FALSE;
820      }      }
821      if (k->is_protected) {      if (k->is_protected) {
822          pass = request_passphrase (_("Key Edit"), 1, &cancel);          pass = request_key_passphrase (k->ctx, _("Key Edit"), &cancel);
823          if (cancel)          if (cancel)
824              return FALSE;              return FALSE;
825      }      }
# Line 865  keyedit_add_subkey (winpt_key_t k, HWND Line 845  keyedit_add_subkey (winpt_key_t k, HWND
845  }  }
846    
847    
848    /* Set the preferred keyserver of the given key @k. */
849  BOOL  BOOL
850  keyedit_set_pref_keyserver (winpt_key_t k, HWND dlg)  keyedit_set_pref_keyserver (winpt_key_t k, HWND dlg)
851  {  {
# Line 879  keyedit_set_pref_keyserver (winpt_key_t Line 860  keyedit_set_pref_keyserver (winpt_key_t
860          return FALSE;          return FALSE;
861      }      }
862    
863      pass = request_passphrase (_("Key Edit"), 1, &url->cancel);      pass = request_key_passphrase (k->ctx, _("Key Edit"), &url->cancel);
864      if (url->cancel) {      if (url->cancel) {
865          delete url;          delete url;
866          return FALSE;          return FALSE;
# Line 920  keyedit_add_photo (winpt_key_t k, HWND d Line 901  keyedit_add_photo (winpt_key_t k, HWND d
901    
902      memset (&cb, 0, sizeof (cb));      memset (&cb, 0, sizeof (cb));
903      if (k->is_protected) {      if (k->is_protected) {
904          pass = request_passphrase (_("Key Edit"), 1, &cancel);          pass = request_key_passphrase (k->ctx, _("Key Edit"), &cancel);
905          if (cancel)          if (cancel)
906              return FALSE;              return FALSE;
907      }      }
908      cb.parent = dlg;      cb.parent = dlg;
909      cb.pass = pass;      cb.pass = pass;
910      cb.keyid = k->keyid;      cb.keyid = k->keyid;
   
911      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDPHOTO, dlg,      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDPHOTO, dlg,
912                      keyedit_addphoto_dlg_proc, (LPARAM)&cb);                      keyedit_addphoto_dlg_proc, (LPARAM)&cb);
913    
# Line 951  keyedit_add_revoker (winpt_key_t k, HWND Line 931  keyedit_add_revoker (winpt_key_t k, HWND
931      }      }
932    
933      if (k->is_protected) {      if (k->is_protected) {
934          pass = request_passphrase (_("Key Edit"), 1, &cancel);          pass = request_key_passphrase (k->ctx, _("Key Edit"), &cancel);
935          if (cancel)          if (cancel)
936              return FALSE;              return FALSE;
937      }      }
# Line 1111  subkey_list_init (HWND dlg, winpt_key_t Line 1091  subkey_list_init (HWND dlg, winpt_key_t
1091      int nkeys = 0, i, bits;      int nkeys = 0, i, bits;
1092    
1093      nkeys = count_subkeys (k->ctx);      nkeys = count_subkeys (k->ctx);
1094      if( !nkeys ) {      if (!nkeys)
1095          msg_box (dlg, _("No subkey(s) found."), _("Key Edit"), MB_ERR);          BUG (0); /* should never happen. */
         return NULL;  
     }  
1096                    
1097      listview_new (&lv, GetDlgItem (dlg, IDC_KEYEDIT_KEYLIST));      listview_new (&lv, GetDlgItem (dlg, IDC_KEYEDIT_KEYLIST));
1098      for (i = 0; cols[i].fieldname != NULL; i++)      for (i = 0; cols[i].fieldname != NULL; i++)
# Line 1126  subkey_list_init (HWND dlg, winpt_key_t Line 1104  subkey_list_init (HWND dlg, winpt_key_t
1104          memset (&lvi, 0, sizeof (lvi));          memset (&lvi, 0, sizeof (lvi));
1105          lvi.mask = LVIF_PARAM;            lvi.mask = LVIF_PARAM;  
1106          lvi.lParam = (LPARAM)k->ext;          lvi.lParam = (LPARAM)k->ext;
1107          if( ListView_SetItem (lv->ctrl, &lvi) == FALSE)          if (ListView_SetItem (lv->ctrl, &lvi) == FALSE)
1108              return NULL;              BUG (0);
1109      }      }
1110                    
1111      listview_set_ext_style( lv );      listview_set_ext_style( lv );
# Line 1198  userid_list_init (HWND dlg, winpt_key_t Line 1176  userid_list_init (HWND dlg, winpt_key_t
1176      const char *attr;      const char *attr;
1177            
1178      nuids = count_userids (k->ctx);      nuids = count_userids (k->ctx);
1179      if (!nuids) {      if (!nuids)
1180          msg_box (dlg, _("No user ID(s) found."), _("Key Edit"), MB_ERR);          BUG (0); /* should never happen. */
         return NULL;  
     }  
1181                    
1182      listview_new (&lv, GetDlgItem (dlg, IDC_KEYEDIT_UIDLIST));      listview_new (&lv, GetDlgItem (dlg, IDC_KEYEDIT_UIDLIST));
1183      for( j = 0; cols[j].fieldname != NULL; j++ )      for (j = 0; cols[j].fieldname != NULL; j++)
1184          listview_add_column (lv, &cols[j]);          listview_add_column (lv, &cols[j]);
1185                    
1186      for (j = 0; j < nuids; j++) {      for (j = 0; j < nuids; j++) {
# Line 1232  userid_list_init (HWND dlg, winpt_key_t Line 1208  userid_list_init (HWND dlg, winpt_key_t
1208              listview_add_sub_item (lv, j, UID_COL_CREATION,              listview_add_sub_item (lv, j, UID_COL_CREATION,
1209                                     get_key_created (ks->timestamp));                                     get_key_created (ks->timestamp));
1210      }      }
1211      if( !k->key_pair ) {      if (!k->key_pair) {
1212          CheckDlgButton (dlg, IDC_KEYUID_ADD, BST_INDETERMINATE);          CheckDlgButton (dlg, IDC_KEYUID_ADD, BST_INDETERMINATE);
1213          CheckDlgButton (dlg, IDC_KEYUID_REVOKE, BST_INDETERMINATE);          CheckDlgButton (dlg, IDC_KEYUID_REVOKE, BST_INDETERMINATE);
1214      }      }
# Line 1312  do_editkey_delkey (winpt_key_t k, HWND d Line 1288  do_editkey_delkey (winpt_key_t k, HWND d
1288  {  {
1289      gpgme_error_t err;      gpgme_error_t err;
1290      GpgKeyEdit *ke;      GpgKeyEdit *ke;
1291      int j, id;      int pos, id;
1292      char tmp[64];      char tmp[64];
1293    
1294      if (!k->key_pair)      if (!k->key_pair)
1295          return FALSE; /* XXX: shall we allow to modify non-secret keys?? */          return FALSE;
1296    
1297      if( listview_count_items( lv, 0 ) == 1 ) {      if (listview_count_items (lv, 0) == 1) {
1298          msg_box( dlg, _("Primary key can not be deleted!"), _("Key Edit"), MB_ERR);          msg_box (dlg, _("Primary key can not be deleted!"), _("Key Edit"), MB_ERR);
1299          return FALSE;          return FALSE;
1300      }      }
1301      if( (j = listview_get_curr_pos( lv )) == -1 ) {      pos = listview_get_curr_pos (lv);
1302          msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR );      if (pos == -1) {
1303            msg_box (dlg, _("Please select a key."), _("Key Edit"), MB_ERR);
1304          return FALSE;          return FALSE;
1305      }      }
1306      if( j == 0 ) {      if (pos == 0) {
1307          msg_box( dlg, _("Primary subkey can not be deleted!"), _("Key Edit"), MB_ERR );          msg_box (dlg, _("Primary key can not be deleted!"), _("Key Edit"), MB_ERR);
1308          return FALSE;          return FALSE;
1309      }      }
1310            
1311      /* XXX: change the warning to make clear that verification won't work      /* XXX: change the warning to make clear that verification won't work
1312              any longer if this is a sign-only key. */              any longer if this is a sign-only key. */
1313      listview_get_item_text (lv, j, 0, tmp, sizeof (tmp) -1);      listview_get_item_text (lv, pos, 0, tmp, sizeof (tmp) -1);
1314      id = log_box (_("Key Edit"), MB_YESNO|MB_ICONWARNING,      id = log_box (_("Key Edit"), MB_YESNO|MB_ICONWARNING,
1315                      _("\"Subkey %s.\"\n\n"                      _("\"Subkey %s.\"\n\n"
1316                        "Anything encrypted to the selected subkey will no longer\n"                        "Anything encrypted to the selected subkey will no longer\n"
# Line 1342  do_editkey_delkey (winpt_key_t k, HWND d Line 1319  do_editkey_delkey (winpt_key_t k, HWND d
1319      if (id == IDNO)      if (id == IDNO)
1320          return FALSE;          return FALSE;
1321    
1322      ke = new GpgKeyEdit (k->keyid);      ke = create_GpgKeyEdit (k->keyid);
1323      if (!ke)      err = ke->delKey (pos);
         BUG (NULL);  
     err = ke->delKey (j);  
1324      if (err)      if (err)
1325          msg_box (dlg, gpgme_strerror (err), _("Delete Subkey"), MB_ERR);          msg_box (dlg, gpgme_strerror (err), _("Delete Subkey"), MB_ERR);
1326      else {      else {
1327          listview_del_item (lv, j);          listview_del_item (lv, pos);
1328          k->update = 1;          k->update = 1;
1329          status_box (dlg, _("Subkey successfully deleted."), _("GnuPG status"));          status_box (dlg, _("Subkey successfully deleted."), _("GnuPG status"));
1330      }      }
# Line 1367  do_editkey_expire (winpt_key_t k, HWND d Line 1342  do_editkey_expire (winpt_key_t k, HWND d
1342      GpgKeyEdit *ke;      GpgKeyEdit *ke;
1343      date_s udd = {0};      date_s udd = {0};
1344      char buf[256], * pass = NULL;      char buf[256], * pass = NULL;
1345      int j, cancel = 0;      int pos, cancel = 0;
1346    
1347      if (!k->key_pair) {      if (!k->key_pair) {
1348          msg_box (dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR);          msg_box (dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR);
1349          return FALSE;          return FALSE;
1350      }      }
1351      if ((j = listview_get_curr_pos (lv)) == -1) {      pos = listview_get_curr_pos (lv);
1352          msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR );      if (pos == -1) {
1353            msg_box (dlg, _("Please select a key."), _("Key Edit"), MB_ERR);
1354          return FALSE;          return FALSE;
1355      }      }
1356    
1357      /* If a key already expired, it is possible the user wants to      /* If a key already expired, it is possible the user wants to
1358         set a new expiration date.. */           set a new expiration date.. */
1359      listview_get_item_text (lv, j, SUBK_COL_STATUS, buf, sizeof buf -1);      listview_get_item_text (lv, pos, SUBK_COL_STATUS, buf, sizeof (buf)-1);
1360      if (!strcmp (buf, _("Expired"))) {      if (!strcmp (buf, _("Expired"))) {
1361          cancel = msg_box (dlg, _("Key already expired.\n\n"          cancel = msg_box (dlg, _("Key already expired.\n\n"
1362                            "Do you want to change the expiration date?"),                            "Do you want to change the expiration date?"),
# Line 1402  do_editkey_expire (winpt_key_t k, HWND d Line 1378  do_editkey_expire (winpt_key_t k, HWND d
1378                   _("Key Edit"), MB_ERR);                   _("Key Edit"), MB_ERR);
1379          return FALSE;          return FALSE;
1380      }      }
1381      if( k->is_protected ) {      if (k->is_protected) {
1382          pass = request_passphrase (_("Key Edit"), 1, &cancel);          pass = request_key_passphrase (k->ctx, _("Key Edit"), &cancel);
1383          if (cancel)          if (cancel)
1384              return FALSE;              return FALSE;
1385      }      }
1386    
1387      ke = new GpgKeyEdit (k->keyid);      ke = create_GpgKeyEdit (k->keyid);
     if (!ke)  
         BUG (NULL);  
1388      if (k->is_protected)      if (k->is_protected)
1389          ke->setPassphrase (pass);          ke->setPassphrase (pass);
1390      else      else
1391          ke->setNoPassphrase (true);          ke->setNoPassphrase (true);
1392      err = ke->setKeyExpireDate (j, w32_mktime (&udd.st), false);      err = ke->setKeyExpireDate (pos, w32_mktime (&udd.st), false);
1393      if (err)      if (err)
1394          msg_box (dlg, gpgme_strerror (err), _("Expire Subkey"), MB_ERR);          msg_box (dlg, gpgme_strerror (err), _("Expire Subkey"), MB_ERR);
1395      else {      else {
1396          _snprintf (buf, sizeof buf - 1, "%04d-%02d-%02d",                _snprintf (buf, sizeof (buf)-1, "%04d-%02d-%02d",
1397                     udd.st.wYear, udd.st.wMonth, udd.st.wDay);                     udd.st.wYear, udd.st.wMonth, udd.st.wDay);
1398          listview_add_sub_item (lv, j, SUBK_COL_EXPIRES, buf);          listview_add_sub_item (lv, pos, SUBK_COL_EXPIRES, buf);
1399          k->update = 1;          k->update = 1;
1400          msg_box (dlg, _("Subkey expire date successfully set."),          msg_box (dlg, _("Subkey expire date successfully set."),
1401                   _("GnuPG status"), MB_OK);                   _("GnuPG status"), MB_OK);
# Line 1468  do_editkey_revoke (winpt_key_t k, HWND d Line 1442  do_editkey_revoke (winpt_key_t k, HWND d
1442      }      }
1443            
1444      if (k->is_protected) {      if (k->is_protected) {
1445          pass = request_passphrase (_("Key Edit"), 1, &cancel);          pass = request_key_passphrase (k->ctx, _("Key Edit"), &cancel);
1446          if (cancel)          if (cancel)
1447              return FALSE;                        return FALSE;          
1448      }      }
1449    
1450      ke = new GpgKeyEdit (k->keyid);      ke = create_GpgKeyEdit (k->keyid);
     if (!ke)  
         BUG (NULL);  
1451      if (k->is_protected)      if (k->is_protected)
1452          ke->setPassphrase (pass);          ke->setPassphrase (pass);
1453      else      else
# Line 1535  do_editkey_revuid (winpt_key_t k, HWND d Line 1507  do_editkey_revuid (winpt_key_t k, HWND d
1507      if (msg_box (dlg, inf, _("Key Edit"), MB_WARN_ASK) == IDNO)      if (msg_box (dlg, inf, _("Key Edit"), MB_WARN_ASK) == IDNO)
1508          return FALSE;          return FALSE;
1509      if (k->is_protected) {      if (k->is_protected) {
1510          pass = request_passphrase (_("Key Edit"), 1, &cancel);          pass = request_key_passphrase (k->ctx, _("Key Edit"), &cancel);
1511          if (cancel)          if (cancel)
1512              return FALSE;                        return FALSE;          
1513      }      }
# Line 1545  do_editkey_revuid (winpt_key_t k, HWND d Line 1517  do_editkey_revuid (winpt_key_t k, HWND d
1517      if (id == -1)      if (id == -1)
1518          BUG (NULL);          BUG (NULL);
1519    
1520      ke = new GpgKeyEdit (k->keyid);      ke = create_GpgKeyEdit (k->keyid);
     if (!ke)  
         BUG (NULL);  
1521      if (k->is_protected)      if (k->is_protected)
1522          ke->setPassphrase (pass);          ke->setPassphrase (pass);
1523      else      else
# Line 1581  do_editkey_setpref (winpt_key_t k, HWND Line 1551  do_editkey_setpref (winpt_key_t k, HWND
1551      listview_get_item_text (lv, j, 2, buf, sizeof buf-1);      listview_get_item_text (lv, j, 2, buf, sizeof buf-1);
1552      id = do_find_userid (k->keyid, buf, NULL, NULL);      id = do_find_userid (k->keyid, buf, NULL, NULL);
1553      if (id == -1)      if (id == -1)
1554          BUG (dlg);          BUG (NULL);
1555      if (k->is_protected) {      if (k->is_protected) {
1556          pass = request_passphrase (_("Key Edit"), 1, &cancel);          pass = request_key_passphrase (k->ctx, _("Key Edit"), &cancel);
1557          if (cancel)          if (cancel)
1558              return FALSE;              return FALSE;
1559      }      }
1560    
1561      ke = new GpgKeyEdit (k->keyid);      ke = create_GpgKeyEdit (k->keyid);
     if (!ke)  
         BUG (NULL);  
1562      if (k->is_protected)      if (k->is_protected)
1563          ke->setPassphrase (pass);          ke->setPassphrase (pass);
1564      else      else
# Line 1615  do_editkey_primary (winpt_key_t k, HWND Line 1583  do_editkey_primary (winpt_key_t k, HWND
1583      gpgme_error_t err;      gpgme_error_t err;
1584      GpgKeyEdit *ke;      GpgKeyEdit *ke;
1585      int j, id, cancel=0;      int j, id, cancel=0;
1586        char valid[32];
1587      char buf[256], *pass = NULL;      char buf[256], *pass = NULL;
1588    
1589      if (listview_count_items (lv, 0) == 1)      if (listview_count_items (lv, 0) == 1)
1590          return TRUE;          return TRUE;
1591      if ((j = listview_get_curr_pos (lv)) == -1) {      if ((j = listview_get_curr_pos (lv)) == -1) {
1592          msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );          msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
1593          return FALSE;          return FALSE;
1594      }      }
1595      listview_get_item_text (lv, j, 2, buf, sizeof buf-1);      listview_get_item_text (lv, j, UID_COL_VALID, valid, sizeof (valid)-1);
1596        if (!strcmp (valid, _("Revoked")))
1597            return FALSE;
1598        listview_get_item_text (lv, j, UID_COL_EMAIL, buf, sizeof (buf)-1);
1599      id = do_find_userid (k->keyid, buf, NULL, NULL);      id = do_find_userid (k->keyid, buf, NULL, NULL);
1600      if (id == -1)      if (id == -1)
1601          BUG (0);          BUG (0);
1602      if (k->is_protected) {      if (k->is_protected) {
1603          pass = request_passphrase (_("Key Edit"), 1, &cancel);          pass = request_key_passphrase (k->ctx, _("Key Edit"), &cancel);
1604          if (cancel)          if (cancel)
1605              return FALSE;              return FALSE;
1606      }      }
1607    
1608      ke = new GpgKeyEdit (k->keyid);      ke = create_GpgKeyEdit (k->keyid);
1609      if (k->is_protected)      if (k->is_protected)
1610          ke->setPassphrase (pass);          ke->setPassphrase (pass);
1611      else      else
# Line 1803  do_editkey_deluid (winpt_key_t k, HWND d Line 1775  do_editkey_deluid (winpt_key_t k, HWND d
1775      GpgKeyEdit *ke;      GpgKeyEdit *ke;
1776      char email[128], name[128];      char email[128], name[128];
1777      char inf[384];      char inf[384];
1778      int j, id = 0;      int pos, id = 0;
1779    
1780      if (!k->key_pair)      if (!k->key_pair)
1781          return FALSE; /* XXX: see do_editkey_delsubkey */          return FALSE;
1782    
1783      if (listview_count_items (lv, 0) == 1) {      if (listview_count_items (lv, 0) == 1) {
1784          msg_box (dlg, _("Primary user ID can not be deleted!"),          msg_box (dlg, _("Primary user ID can not be deleted!"),
1785                   _("Key Edit"), MB_ERR);                   _("Key Edit"), MB_ERR);
1786          return FALSE;          return FALSE;
1787      }      }
1788      if ((j = listview_get_curr_pos (lv)) == -1) {      pos = listview_get_curr_pos (lv);
1789        if (pos == -1) {
1790          msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);          msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
1791          return FALSE;          return FALSE;
1792      }      }
1793            
1794      /* XXX: add a hint that also all signatures will be deleted? */      listview_get_item_text (lv, pos, UID_COL_NAME, name, DIM(name) -1);
     listview_get_item_text (lv, j, UID_COL_NAME, name, DIM(name) -1);  
1795      _snprintf (inf, DIM (inf)-1, _("user ID \"%s\".\n\n"      _snprintf (inf, DIM (inf)-1, _("user ID \"%s\".\n\n"
1796                                     "All signatures on this user ID will be also deleted."                                     "All signatures on this user ID will be also deleted."
1797                                     "\n\n"                                     "\n\n"
# Line 1828  do_editkey_deluid (winpt_key_t k, HWND d Line 1800  do_editkey_deluid (winpt_key_t k, HWND d
1800      if (msg_box (dlg, inf, _("Key Edit"), MB_YESNO|MB_ICONWARNING) == IDNO)      if (msg_box (dlg, inf, _("Key Edit"), MB_YESNO|MB_ICONWARNING) == IDNO)
1801          return FALSE;          return FALSE;
1802            
1803      listview_get_item_text (lv, j, UID_COL_EMAIL, email, DIM (email)-1);      listview_get_item_text (lv, pos, UID_COL_EMAIL, email, DIM (email)-1);
1804      listview_get_item_text (lv, j, UID_COL_NAME, name, DIM (name)-1);      listview_get_item_text (lv, pos, UID_COL_NAME, name, DIM (name)-1);
1805      id = do_find_userid (k->keyid, email, name, NULL);      id = do_find_userid (k->keyid, email, name, NULL);
1806      if (id == -1)      if (id == -1)
1807          BUG (dlg);          BUG (0);
   
     ke = new GpgKeyEdit (k->keyid);  
     if (!ke)  
         BUG (NULL);  
1808    
1809        ke = create_GpgKeyEdit (k->keyid);
1810      err = ke->delUserid (id);      err = ke->delUserid (id);
1811      if (err)      if (err)
1812          msg_box (dlg, gpgme_strerror (err), _("Delete user ID"), MB_ERR);          msg_box (dlg, gpgme_strerror (err), _("Delete User ID"), MB_ERR);
1813      else {      else {
1814          listview_del_item (lv, j);          listview_del_item (lv, pos);
1815          k->update = 1;          k->update = 1;
1816          status_box (dlg, _("User ID successfully deleted"), _("GnuPG Status"));          status_box (dlg, _("User ID successfully deleted"), _("GnuPG Status"));
1817      }      }
# Line 1924  do_editkey_enable_disable (winpt_key_t k Line 1893  do_editkey_enable_disable (winpt_key_t k
1893  }  }
1894    
1895    
 /* Return default secret key. */  
 static gpgme_key_t  
 get_default_key (void)  
 {  
     gpgme_key_t def_sk;  
     char *keyid = get_gnupg_default_key ();  
   
     get_seckey (keyid, &def_sk);  
     free_if_alloc (keyid);  
     return def_sk;  
 }  
   
   
   
1896  static void  static void
1897  do_editkey_minimize (winpt_key_t k, HWND dlg)  do_editkey_minimize (winpt_key_t k, HWND dlg)
1898  {  {
# Line 1992  static int Line 1947  static int
1947  do_editkey_sign_userid (winpt_key_t k, HWND dlg, listview_ctrl_t lv, int mode)  do_editkey_sign_userid (winpt_key_t k, HWND dlg, listview_ctrl_t lv, int mode)
1948  {  {
1949      gpgme_error_t err;      gpgme_error_t err;
1950        winpt_key_s signer;
1951      GpgKeyEdit *ke;      GpgKeyEdit *ke;
1952      char *pass = NULL;      char *pass = NULL;
1953      char email[64], name[128];      char *defkey;
1954        char email[64], name[128], valid[32];
1955      int uid_index;      int uid_index;
1956      int cancel = 0;      int cancel = 0;
1957    
# Line 2003  do_editkey_sign_userid (winpt_key_t k, H Line 1960  do_editkey_sign_userid (winpt_key_t k, H
1960          msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);          msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
1961          return FALSE;          return FALSE;
1962      }      }
1963        listview_get_item_text (lv, uid_index, UID_COL_VALID, valid, sizeof (valid)-1);
1964        if (!strcmp (valid, _("Revoked")))
1965            return TRUE;
1966      if (mode == CMD_SIGN) {      if (mode == CMD_SIGN) {
1967          cancel = msg_box (dlg, _("Do you really want to make this sig exportable?"),          cancel = msg_box (dlg, _("Do you really want to make this sig exportable?"),
1968                            _("Key Edit"), MB_QUEST_ASK);                            _("Key Edit"), MB_QUEST_ASK);
1969          if (cancel == IDNO)          if (cancel == IDNO)
1970              return FALSE;              return FALSE;
1971      }      }
   
1972      listview_get_item_text (lv, uid_index, UID_COL_EMAIL, email, sizeof (email)-1);      listview_get_item_text (lv, uid_index, UID_COL_EMAIL, email, sizeof (email)-1);
1973      listview_get_item_text (lv, uid_index, UID_COL_NAME, name, sizeof (name)-1);      listview_get_item_text (lv, uid_index, UID_COL_NAME, name, sizeof (name)-1);
1974      uid_index = do_find_userid (k->keyid, email, name, NULL);      uid_index = do_find_userid (k->keyid, email, name, NULL);
1975      if (k->is_protected) {  
1976          pass = request_passphrase (_("Key Edit"), 1, &cancel);      defkey = get_gnupg_default_key ();
1977        memset (&signer, 0, sizeof (signer));
1978        if (winpt_get_seckey (defkey, &signer)) {
1979            log_debug ("do_editkey_sign_userid: no default secret key.\r\n");
1980            free_if_alloc (defkey);
1981            return FALSE;
1982        }
1983        if (signer.is_protected) {
1984            pass = request_key_passphrase (signer.ctx, _("Key Edit"), &cancel);
1985          if (cancel)          if (cancel)
1986              return FALSE;              return FALSE;
1987      }      }
1988      ke = create_GpgKeyEdit (k->keyid);      ke = create_GpgKeyEdit (k->keyid);
1989      if (k->is_protected)      if (signer.is_protected)
1990          ke->setPassphrase (pass);          ke->setPassphrase (pass);
1991      else      else
1992          ke->setNoPassphrase (true);          ke->setNoPassphrase (true);
1993      ke->setLocalUser (get_default_key ());      ke->setLocalUser (signer.ctx);
1994      err = ke->signUserid (uid_index,      err = ke->signUserid (uid_index,
1995                            mode == CMD_SIGN? GPG_EDITKEY_SIGN : GPG_EDITKEY_LSIGN,                            mode == CMD_SIGN? GPG_EDITKEY_SIGN : GPG_EDITKEY_LSIGN,
1996                            0, NULL);                            0, NULL);
# Line 2126  keyedit_main_dlg_proc (HWND dlg, UINT ms Line 2093  keyedit_main_dlg_proc (HWND dlg, UINT ms
2093              BUG (NULL);              BUG (NULL);
2094          do_init_cmdlist (dlg, k->key_pair);          do_init_cmdlist (dlg, k->key_pair);
2095          lvsub = subkey_list_init (dlg, k);          lvsub = subkey_list_init (dlg, k);
         if (!lvsub)  
             BUG (0);  
2096          lvuid = userid_list_init (dlg, k);          lvuid = userid_list_init (dlg, k);
         if (!lvuid)  
             BUG (0);  
2097          item = GetDlgItem (dlg, IDC_KEYEDIT_KEYLIST);          item = GetDlgItem (dlg, IDC_KEYEDIT_KEYLIST);
2098          keyedit_subkey_proc.opaque = (void*)k;          keyedit_subkey_proc.opaque = (void*)k;
2099          keyedit_subkey_proc.dlg = dlg;          keyedit_subkey_proc.dlg = dlg;

Legend:
Removed from v.220  
changed lines
  Added in v.225

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26