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

Diff of /trunk/Src/wptKeyEdit.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 328 by twoaday, Fri Sep 25 16:07:38 2009 UTC
# Line 22  Line 22 
22  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
23  #include <config.h>  #include <config.h>
24  #endif  #endif
25  #include <time.h>  
26  #include <windows.h>  #include <windows.h>
27    #include <time.h>
28    
29  #include "gpgme.h"  #include "gpgme.h"
30  #include "wptCommonCtl.h"  #include "wptCommonCtl.h"
# Line 74  rev_key_colon_handler (gpg_desig_rev_t * Line 75  rev_key_colon_handler (gpg_desig_rev_t *
75          if (pend == NULL)          if (pend == NULL)
76              break;              break;
77          switch (field) {          switch (field) {
78          case  4: r->pubkey_algo = (gpgme_pubkey_algo_t)atol (pend); break;          case  4:
79          case 10: strncpy (r->fpr, pend, 40); r->fpr[40] = 0; break;              r->pubkey_algo = (gpgme_pubkey_algo_t)atol (pend);
80                break;
81    
82            case 10:
83                strncpy (r->fpr, pend, 40);
84                r->fpr[40] = 0;
85                break;
86          }                }      
87      }      }
88      if (p)      free (p);
         free (p);  
89      return 0;      return 0;
90  }  }
91    
# Line 141  uid_inf_colon_handler (gpg_uid_info_t *i Line 147  uid_inf_colon_handler (gpg_uid_info_t *i
147    
148          case 13: /* preferences */          case 13: /* preferences */
149              if (strstr (pend, "mdc")) {              if (strstr (pend, "mdc")) {
150                    const char *s = "no-ks-modify";
151                  len = strlen (pend) - 4; /* ,mdc */                  len = strlen (pend) - 4; /* ,mdc */
152                  if (strstr (pend, "no-ks-modify")) {                  if (strstr (pend, s)) {
153                      i->flags.no_ks_modify = 1;                      i->flags.no_ks_modify = 1;
154                      len -= 13; /* ,no-ks-modify */                      len -= strlen (s)+1; /* ',' + s */
155                  }                  }
156                  i->prefs = (char*)calloc (1, len+1);                  i->prefs = (char*)calloc (1, len+1);
157                  if (!i->prefs)                  if (!i->prefs)
# Line 162  uid_inf_colon_handler (gpg_uid_info_t *i Line 169  uid_inf_colon_handler (gpg_uid_info_t *i
169              break;              break;
170    
171          case 14: /* index/flags */          case 14: /* index/flags */
172              i->index = atol (pend);              i->index = atoi (pend);
173              if (strchr (pend, 'r'))              if (strchr (pend, 'r'))
174                  i->flags.revoked = 1;                  i->flags.revoked = 1;
175              if (strchr (pend, 'p'))              if (strchr (pend, 'p'))
# Line 170  uid_inf_colon_handler (gpg_uid_info_t *i Line 177  uid_inf_colon_handler (gpg_uid_info_t *i
177              break;              break;
178          }          }
179      }      }
180      if (p)      free (p);
         free (p);  
181      return 0;      return 0;
182  }  }
183    
# Line 232  list2_handler (void *opaque, gpgme_statu Line 238  list2_handler (void *opaque, gpgme_statu
238  static gpgme_error_t  static gpgme_error_t
239  list_handler (void *opaque, gpgme_status_code_t code, const char *key, int fd)  list_handler (void *opaque, gpgme_status_code_t code, const char *key, int fd)
240  {  {
241      static int step=0;      static int step = 0;
242      const char *s="";      const char *s = "";
243      DWORD n;      DWORD n;
244    
245      if (!strcmp (key, "keyedit.prompt") && step == 0) {      if (!strcmp (key, "keyedit.prompt") && step == 0) {
# Line 268  GpgKeyEdit::getDesignatedRevoker (gpg_de Line 274  GpgKeyEdit::getDesignatedRevoker (gpg_de
274      err = gpgme_data_new (&out);      err = gpgme_data_new (&out);
275      if (err)      if (err)
276          goto leave;          goto leave;
   
277      err = gpgme_op_edit (ctx, key, list2_handler, NULL, out);      err = gpgme_op_edit (ctx, key, list2_handler, NULL, out);
278      if (err)      if (err)
279          goto leave;          goto leave;
280            
281      gpgme_data_rewind (out);      gpgme_data_rewind (out);
282      while (gpg_data_readline (out, buf, sizeof (buf)-1) > 0)      while (gpg_data_readline (out, buf, DIM (buf)-1) > 0)
283          rev_key_colon_handler (&rev, buf);          rev_key_colon_handler (&rev, buf);
284      *r_rev = rev;      *r_rev = rev;
285    
# Line 306  GpgKeyEdit::getUseridInfo (gpg_uid_info_ Line 311  GpgKeyEdit::getUseridInfo (gpg_uid_info_
311      err = gpgme_data_new (&out);      err = gpgme_data_new (&out);
312      if (err)      if (err)
313          goto leave;          goto leave;
   
314      err = gpgme_op_edit (ctx, key, list_handler, NULL, out);      err = gpgme_op_edit (ctx, key, list_handler, NULL, out);
315      if (err)      if (err)
316          goto leave;          goto leave;
317            
318      gpgme_data_rewind (out);      gpgme_data_rewind (out);
319      while (gpg_data_readline (out, buf, sizeof (buf) -1) > 0)      while (gpg_data_readline (out, buf, DIM (buf) -1) > 0)
320          uid_inf_colon_handler (&inf, buf);          uid_inf_colon_handler (&inf, buf);
321    
322      *r_uinf = inf;      *r_uinf = inf;
# Line 332  leave: Line 336  leave:
336  void  void
337  GpgKeyEdit::clear (void)  GpgKeyEdit::clear (void)
338  {  {
339      pass = NULL;          pass = NULL;
340      name = NULL;      name = NULL;
341      cmt = NULL;      cmt = NULL;
342      email = NULL;      email = NULL;
# Line 340  GpgKeyEdit::clear (void) Line 344  GpgKeyEdit::clear (void)
344      cnt = 0;      cnt = 0;
345      cmd_sent = 0;      cmd_sent = 0;
346      resval = 0;      resval = 0;
347      uid_index = sig_index = key_index = -1;      uid_index = -1;
348        sig_index = -1;
349        key_index = -1;
350      key_has_passwd = true;      key_has_passwd = true;
351  }  }
352    
353    
354    GpgKeyEdit::GpgKeyEdit (void)
355    {    
356        clear ();
357        key = NULL;
358        gpgme_new (&ctx); /*FIXME */
359        
360    }
361    
362    
363  /* Construct an object with the given key in @key. */  /* Construct an object with the given key in @key. */
364  GpgKeyEdit::GpgKeyEdit (gpgme_key_t _key)  GpgKeyEdit::GpgKeyEdit (gpgme_key_t _key)
365  {  {
# Line 357  GpgKeyEdit::GpgKeyEdit (gpgme_key_t _key Line 372  GpgKeyEdit::GpgKeyEdit (gpgme_key_t _key
372  GpgKeyEdit::GpgKeyEdit (const char *_keyid)  GpgKeyEdit::GpgKeyEdit (const char *_keyid)
373  {  {
374      clear ();      clear ();
375      get_pubkey (_keyid, &this->key);      get_pubkey (_keyid, &this->key); /*FIXME: check return code*/
376      gpgme_new (&ctx); /* FIXME */          gpgme_new (&ctx); /* FIXME */
377  }  }
378    
379  /* Delete the given object. */  /* Delete the given object. */
# Line 366  GpgKeyEdit::~GpgKeyEdit (void) Line 381  GpgKeyEdit::~GpgKeyEdit (void)
381  {  {
382      free_if_alloc (name);      free_if_alloc (name);
383      free_if_alloc (cmt);      free_if_alloc (cmt);
384      free_if_alloc (email);      free_if_alloc (email);    
385      gpgme_release (ctx);      gpgme_release (ctx);
386  }  }
387    
# Line 422  GpgKeyEdit::setNoPassphrase (bool val) Line 437  GpgKeyEdit::setNoPassphrase (bool val)
437      key_has_passwd = !val;      key_has_passwd = !val;
438  }  }
439    
440    
441    void
442    GpgKeyEdit::setPassphraseCallback (gpgme_passphrase_cb_t cb, void *cb_value)
443    {    
444        key_has_passwd = false;
445        gpgme_set_passphrase_cb (ctx, cb, cb_value);
446    }
447    
448    
449    bool
450    GpgKeyEdit::usePassphraseCallback (void)
451    {
452        gpgme_passphrase_cb_t cb_ptr;
453        void *cb_value;
454    
455        gpgme_get_passphrase_cb (ctx, &cb_ptr, &cb_value);
456        if (cb_ptr)
457            return true;
458        return false;
459    }
460    
461  /* Set the passphrase to @pass. */  /* Set the passphrase to @pass. */
462  void  void
463  GpgKeyEdit::setPassphrase (const char *_pass)  GpgKeyEdit::setPassphrase (const char *_pass)
# Line 429  GpgKeyEdit::setPassphrase (const char *_ Line 465  GpgKeyEdit::setPassphrase (const char *_
465      this->pass = _pass;      this->pass = _pass;
466  }  }
467    
468    
469    /* Kludge to allow to handle admin and user PINs. */
470    void
471    GpgKeyEdit::setPassphrase2 (const char *_pass2)
472    {
473        this->new_pass = _pass2;
474    }
475    
476  /* Set the current key to @key. */  /* Set the current key to @key. */
477  void  void
478  GpgKeyEdit::setKey (gpgme_key_t _key)  GpgKeyEdit::setKey (gpgme_key_t _key)
# Line 442  GpgKeyEdit::setKeyID (const char *_keyid Line 486  GpgKeyEdit::setKeyID (const char *_keyid
486  {  {
487      if (!_keyid)      if (!_keyid)
488          return;          return;
489      get_pubkey (_keyid, &this->key);      get_pubkey (_keyid, &this->key); /* FIXME: check return code */
490  }  }
491    
492    
# Line 605  GpgKeyEdit::delKey (int _key_index) Line 649  GpgKeyEdit::delKey (int _key_index)
649      return gpg_editkey (this->ctx, this->key, this);      return gpg_editkey (this->ctx, this->key, this);
650  }  }
651    
652    
653    /* Add a new key on a smart card.
654       The type is given in @type. */
655    gpgme_error_t
656    GpgKeyEdit::addCardKey (int _type)
657    {
658        if (!this->key)
659            return gpg_error (GPG_ERR_INV_OBJ);
660        if (!this->pass)
661            return gpg_error (GPG_ERR_INV_PASSPHRASE);
662        if (_type < 1 || _type > 3)
663            return gpg_error (GPG_ERR_INV_VALUE);
664    
665        type = GPG_EDITKEY_ADDCARDKEY;
666        this->key_index = _type;
667        return gpg_editkey (this->ctx, this->key, this);
668    }
669    
670    
671  /* Add a new subkey to the given key.  /* Add a new subkey to the given key.
672     The new key will have @pubkey_algo as the algorithm     The new key will have @pubkey_algo as the algorithm
673     and a size of @pubkey_size bits. If valid > 0, the     and a size of @pubkey_size bits. If valid > 0, the
# Line 823  GpgKeyEdit::cleanKey (void) Line 886  GpgKeyEdit::cleanKey (void)
886     index @uid_index to the prefs given in @new_prefs.     index @uid_index to the prefs given in @new_prefs.
887     Return value: 0 on success. */     Return value: 0 on success. */
888  gpgme_error_t  gpgme_error_t
889  GpgKeyEdit::setUseridPreferences (int _uid_index, const char *new_prefs)  GpgKeyEdit::setUseridPreferences (int _uid_index, const char *_new_prefs)
890  {  {
891      if (!this->key)      if (!this->key)
892          return gpg_error (GPG_ERR_INV_OBJ);          return gpg_error (GPG_ERR_INV_OBJ);
893      if (key_has_passwd && !this->pass)      if (key_has_passwd && !this->pass)
894          return gpg_error (GPG_ERR_INV_PASSPHRASE);          return gpg_error (GPG_ERR_INV_PASSPHRASE);
895      return 0;      type = GPG_EDITKEY_SETPREF;
896        this->uid_index = _uid_index;
897        this->new_prefs = _new_prefs;
898        return gpg_editkey (this->ctx, this->key, this);
899  }  }
900    
901    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26