Changeset 5439:d8bbdcd01ec4 for crypt-gpgme.c
- Timestamp:
- 2008-07-01 17:57:37 (5 months ago)
- Branch:
- HEAD
- Files:
-
- 1 modified
-
crypt-gpgme.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
crypt-gpgme.c
r5438 r5439 1839 1839 } 1840 1840 1841 static int pgp_gpgme_extract_keys (gpgme_data_t keydata, FILE** fp )1841 static int pgp_gpgme_extract_keys (gpgme_data_t keydata, FILE** fp, int dryrun) 1842 1842 { 1843 1843 /* there's no side-effect free way to view key data in GPGME, … … 1857 1857 int rc = -1; 1858 1858 1859 snprintf (tmpdir, sizeof(tmpdir), "%s/mutt-gpgme-XXXXXX", Tempdir);1860 if (!mkdtemp (tmpdir))1861 {1862 dprint (1, (debugfile, "Error creating temporary GPGME home\n"));1863 return rc;1864 }1865 1866 1859 if ((err = gpgme_new (&tmpctx)) != GPG_ERR_NO_ERROR) 1867 1860 { 1868 1861 dprint (1, (debugfile, "Error creating GPGME context\n")); 1869 goto err_tmpdir;1862 return rc; 1870 1863 } 1871 1872 engineinfo = gpgme_ctx_get_engine_info (tmpctx); 1873 while (engineinfo && engineinfo->protocol != GPGME_PROTOCOL_OpenPGP) 1874 engineinfo = engineinfo->next; 1875 if (!engineinfo) 1864 1865 if (dryrun) 1876 1866 { 1877 dprint (1, (debugfile, "Error finding GPGME PGP engine\n")); 1878 goto err_ctx; 1879 } 1880 1881 err = gpgme_ctx_set_engine_info (tmpctx, GPGME_PROTOCOL_OpenPGP, 1882 engineinfo->file_name, tmpdir); 1883 if (err != GPG_ERR_NO_ERROR) 1884 { 1885 dprint (1, (debugfile, "Error setting GPGME context home\n")); 1886 goto err_ctx; 1867 snprintf (tmpdir, sizeof(tmpdir), "%s/mutt-gpgme-XXXXXX", Tempdir); 1868 if (!mkdtemp (tmpdir)) 1869 { 1870 dprint (1, (debugfile, "Error creating temporary GPGME home\n")); 1871 goto err_ctx; 1872 } 1873 1874 engineinfo = gpgme_ctx_get_engine_info (tmpctx); 1875 while (engineinfo && engineinfo->protocol != GPGME_PROTOCOL_OpenPGP) 1876 engineinfo = engineinfo->next; 1877 if (!engineinfo) 1878 { 1879 dprint (1, (debugfile, "Error finding GPGME PGP engine\n")); 1880 goto err_tmpdir; 1881 } 1882 1883 err = gpgme_ctx_set_engine_info (tmpctx, GPGME_PROTOCOL_OpenPGP, 1884 engineinfo->file_name, tmpdir); 1885 if (err != GPG_ERR_NO_ERROR) 1886 { 1887 dprint (1, (debugfile, "Error setting GPGME context home\n")); 1888 goto err_tmpdir; 1889 } 1887 1890 } 1888 1891 … … 1890 1893 { 1891 1894 dprint (1, (debugfile, "Error importing key\n")); 1892 goto err_ ctx;1895 goto err_tmpdir; 1893 1896 } 1894 1897 … … 1898 1901 { 1899 1902 mutt_perror (tmpfile); 1900 goto err_ ctx;1903 goto err_tmpdir; 1901 1904 } 1902 1905 unlink (tmpfile); … … 1945 1948 *fp = NULL; 1946 1949 } 1950 err_tmpdir: 1951 if (dryrun) 1952 mutt_rmtree (tmpdir); 1947 1953 err_ctx: 1948 1954 gpgme_release (tmpctx); 1949 err_tmpdir:1950 mutt_rmtree (tmpdir);1951 1955 1952 1956 return rc; … … 2033 2037 } 2034 2038 return rv; 2039 } 2040 2041 /* TODO: looks like this won't work and we'll have to fully parse the 2042 * message file. GPGME makes life hard yet again. */ 2043 void pgp_gpgme_invoke_import (const char *fname) 2044 { 2045 gpgme_data_t keydata; 2046 gpgme_error_t err; 2047 FILE* in; 2048 FILE* out; 2049 long outlen; 2050 2051 if (!(in = safe_fopen (fname, "r"))) 2052 return; 2053 if ((err = gpgme_data_new_from_stream (&keydata, in)) != GPG_ERR_NO_ERROR) 2054 { 2055 dprint (1, (debugfile, "error converting key file into data object\n")); 2056 return; 2057 } 2058 fclose (in); 2059 2060 if (!pgp_gpgme_extract_keys (keydata, &out, 0)) 2061 { 2062 /* display import results */ 2063 outlen = ftell (out); 2064 fseek (out, 0, SEEK_SET); 2065 mutt_copy_bytes (out, stdout, outlen); 2066 fclose (out); 2067 } 2068 else 2069 printf (_("Error extracting key data!\n")); 2035 2070 } 2036 2071 … … 2180 2215 if (pgp_keyblock) 2181 2216 { 2182 pgp_gpgme_extract_keys (armored_data, &pgpout );2217 pgp_gpgme_extract_keys (armored_data, &pgpout, 1); 2183 2218 } 2184 2219 else if (!clearsign || (s->flags & M_VERIFY))
