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

Diff of /trunk/Src/wptGPGUtil.cpp

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

revision 174 by twoaday, Fri Jan 20 09:19:15 2006 UTC revision 175 by twoaday, Tue Feb 7 08:58:04 2006 UTC
# Line 29  Line 29 
29  #include "gpgme.h"  #include "gpgme.h"
30  #include "wptTypes.h"  #include "wptTypes.h"
31  #include "wptErrors.h"  #include "wptErrors.h"
32    #include "wptW32API.h"
33    
34    
35  #define NROFHEXDIGITS 2    #define NROFHEXDIGITS 2  
36  /* Convert two hexadecimal digits from STR to the value they  /* Convert two hexadecimal digits from STR to the value they
# Line 221  create_tmpfile (const char *name) Line 223  create_tmpfile (const char *name)
223      sec_attr.lpSecurityDescriptor = NULL;      sec_attr.lpSecurityDescriptor = NULL;
224      sec_attr.nLength = sizeof sec_attr;      sec_attr.nLength = sizeof sec_attr;
225    
226      GetTempPath (sizeof (tmp)-1 - strlen (name)-1, tmp);      get_temp_name (tmp, DIM (tmp)-1, name);
     strcat (tmp, name);  
227      out = CreateFile (tmp, GENERIC_READ|GENERIC_WRITE,      out = CreateFile (tmp, GENERIC_READ|GENERIC_WRITE,
228                        FILE_SHARE_WRITE, &sec_attr,                        FILE_SHARE_WRITE, &sec_attr,
229                        OPEN_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL);                        OPEN_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL);
# Line 604  gpg_get_photoid_data (const char *keyid, Line 605  gpg_get_photoid_data (const char *keyid,
605  }  }
606    
607    
608    /* Extract one or more keys from the key file @keyfile.
609       The keys to extract are give in @keys and the size of it is @nkeys.
610       @new_keyfile is a file with the extract keys.
611       Return value: 0 on success. */
612    gpgme_error_t
613    gpg_extract_keys (const char *keyfile, const char **keys, DWORD nkeys,
614                      char **new_keyfile)
615    {
616        gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
617        const char *fmt;
618        char *p, *cmd;
619        char tmpnam[MAX_PATH], tmpdir[MAX_PATH];
620        int i, n;
621    
622        /* copy key file to temp dir. */
623        GetTempPath (MAX_PATH-1, tmpdir);
624        get_temp_name (tmpnam, MAX_PATH-1, NULL);
625        CopyFile (keyfile, tmpnam, FALSE);
626    
627        /* create temp file for output. */
628        *new_keyfile = new char[MAX_PATH];
629        if (!*new_keyfile)
630            BUG (NULL);
631        get_temp_name (*new_keyfile, MAX_PATH-1, "sel_keys");
632    
633        p = read_gpg_program ();
634        if (!p)
635            return gpg_error (GPG_ERR_INV_ARG);
636    
637        /* Use the temp key file as a keyring and export the selected
638           keys from it. */
639        fmt = "%s --yes --output %s --no-options --homedir %s --keyring %s --export ";
640        n = strlen (fmt) + strlen (p)+1 + strlen (tmpdir)+1 + strlen (tmpnam) + 1;
641        n += strlen (*new_keyfile)+1;
642        for (i=0; i < (int)nkeys; i++)
643            n += strlen (keys[i])+1+2;
644        cmd = (char*)calloc (1, n+1);
645        sprintf (cmd, fmt, p, *new_keyfile, tmpdir, tmpnam);
646        for (i=0; i < (int)nkeys; i++) {
647            strcat (cmd, keys[i]);
648            strcat (cmd, " " );
649        }
650    
651        if (create_process (cmd, NULL, NULL, NULL))
652            err = gpgme_error (GPG_ERR_INTERNAL);
653    
654        DeleteFile (tmpnam);
655        safe_free (cmd);
656        safe_free (p);
657        return err;
658    }
659    
660    
661  /* Return the validity of the user attribute, informerly known  /* Return the validity of the user attribute, informerly known
662     as photo-ID. If no uat was found, return 0 for unknown. */     as photo-ID. If no uat was found, return 0 for unknown. */
663  gpgme_error_t  gpgme_error_t
# Line 629  get_uat_validity (const char *keyid, gpg Line 683  get_uat_validity (const char *keyid, gpg
683      if (create_process (cmd, NULL, out, NULL))      if (create_process (cmd, NULL, out, NULL))
684          err = gpg_error (GPG_ERR_INTERNAL);          err = gpg_error (GPG_ERR_INTERNAL);
685    
686      free (p);      safe_free (p);
687      free (cmd);      safe_free (cmd);
688            
689      p = map_tmpfile (out, NULL);      p = map_tmpfile (out, NULL);
690      if ((uat = strstr (p, "uat:"))) {      if ((uat = strstr (p, "uat:"))) {

Legend:
Removed from v.174  
changed lines
  Added in v.175

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26