From 75938f1ab9f38cbb4502af598cd4dca7805dee6d Mon Sep 17 00:00:00 2001 From: Repo Admin Date: Mon, 4 Mar 2002 11:16:11 +0000 Subject: [PATCH] This commit was manufactured by cvs2svn to create tag 'V0-3-4'. --- tags/V0-3-4/.cvsignore | 13 + tags/V0-3-4/AUTHORS | 23 + tags/V0-3-4/ChangeLog | 154 ++ tags/V0-3-4/INSTALL | 196 ++ tags/V0-3-4/Makefile.am | 54 + tags/V0-3-4/NEWS | 199 ++ tags/V0-3-4/README | 42 + tags/V0-3-4/README-alpha | 1 + tags/V0-3-4/THANKS | 21 + tags/V0-3-4/TODO | 68 + tags/V0-3-4/acconfig.h | 65 + tags/V0-3-4/acinclude.m4 | 57 + tags/V0-3-4/assuan/.cvsignore | 2 + tags/V0-3-4/assuan/ChangeLog | 175 ++ tags/V0-3-4/assuan/Makefile.am | 49 + tags/V0-3-4/assuan/README.1st | 1 + tags/V0-3-4/assuan/assuan-buffer.c | 416 +++ tags/V0-3-4/assuan/assuan-client.c | 186 ++ tags/V0-3-4/assuan/assuan-connect.c | 54 + tags/V0-3-4/assuan/assuan-defs.h | 143 + tags/V0-3-4/assuan/assuan-handler.c | 682 +++++ tags/V0-3-4/assuan/assuan-inquire.c | 223 ++ tags/V0-3-4/assuan/assuan-listen.c | 132 + tags/V0-3-4/assuan/assuan-pipe-connect.c | 269 ++ tags/V0-3-4/assuan/assuan-pipe-server.c | 123 + tags/V0-3-4/assuan/assuan-socket-connect.c | 150 + tags/V0-3-4/assuan/assuan-socket-server.c | 121 + tags/V0-3-4/assuan/assuan-util.c | 196 ++ tags/V0-3-4/assuan/assuan.h | 216 ++ tags/V0-3-4/assuan/mkerrors | 71 + tags/V0-3-4/autogen.sh | 149 + tags/V0-3-4/bonobo/.cvsignore | 1 + tags/V0-3-4/bonobo/Makefile.am | 30 + tags/V0-3-4/bonobo/gpgme.c | 20 + tags/V0-3-4/bonobo/main.c | 20 + tags/V0-3-4/bonobo/main.h | 42 + tags/V0-3-4/complus/.cvsignore | 2 + tags/V0-3-4/complus/ChangeLog | 15 + tags/V0-3-4/complus/Makefile.am | 49 + tags/V0-3-4/complus/README | 72 + tags/V0-3-4/complus/debug.c | 40 + tags/V0-3-4/complus/example.c | 598 ++++ tags/V0-3-4/complus/gpgcom.c | 545 ++++ tags/V0-3-4/complus/gpgcom.idl | 62 + tags/V0-3-4/complus/gpgcom.rc | 22 + tags/V0-3-4/complus/gpgcom.tlb | Bin 0 -> 18596 bytes tags/V0-3-4/complus/guidgen.c | 130 + tags/V0-3-4/complus/igpgme.c | 859 ++++++ tags/V0-3-4/complus/igpgme.h | 163 ++ tags/V0-3-4/complus/main.h | 49 + tags/V0-3-4/complus/regtlb.c | 70 + tags/V0-3-4/complus/tgpgcom.c | 157 ++ tags/V0-3-4/complus/utf8.c | 236 ++ tags/V0-3-4/complus/vbtest.html | 47 + tags/V0-3-4/complus/vbtest.vbs | 39 + tags/V0-3-4/configure.ac | 242 ++ tags/V0-3-4/doc/.cvsignore | 1 + tags/V0-3-4/doc/ChangeLog | 107 + tags/V0-3-4/doc/Makefile.am | 25 + tags/V0-3-4/doc/fdl.texi | 402 +++ tags/V0-3-4/doc/gdoc | 681 +++++ tags/V0-3-4/doc/gpgme.texi | 2435 +++++++++++++++++ tags/V0-3-4/doc/gpl.texi | 397 +++ tags/V0-3-4/gpgme.txt | 90 + tags/V0-3-4/gpgme/.cvsignore | 6 + tags/V0-3-4/gpgme/ChangeLog | 1265 +++++++++ tags/V0-3-4/gpgme/Makefile.am | 70 + tags/V0-3-4/gpgme/context.h | 151 + tags/V0-3-4/gpgme/data.c | 991 +++++++ tags/V0-3-4/gpgme/debug.c | 240 ++ tags/V0-3-4/gpgme/decrypt-verify.c | 80 + tags/V0-3-4/gpgme/decrypt.c | 165 ++ tags/V0-3-4/gpgme/delete.c | 157 ++ tags/V0-3-4/gpgme/encrypt-sign.c | 150 + tags/V0-3-4/gpgme/encrypt.c | 230 ++ tags/V0-3-4/gpgme/engine-gpgsm.c | 1148 ++++++++ tags/V0-3-4/gpgme/engine-gpgsm.h | 67 + tags/V0-3-4/gpgme/engine.c | 643 +++++ tags/V0-3-4/gpgme/engine.h | 82 + tags/V0-3-4/gpgme/export.c | 107 + tags/V0-3-4/gpgme/fopencookie.c | 37 + tags/V0-3-4/gpgme/genkey.c | 224 ++ tags/V0-3-4/gpgme/gpgme-config.in | 93 + tags/V0-3-4/gpgme/gpgme.c | 425 +++ tags/V0-3-4/gpgme/gpgme.h | 554 ++++ tags/V0-3-4/gpgme/gpgme.m4 | 170 ++ tags/V0-3-4/gpgme/import.c | 223 ++ tags/V0-3-4/gpgme/io.h | 71 + tags/V0-3-4/gpgme/key.c | 974 +++++++ tags/V0-3-4/gpgme/key.h | 82 + tags/V0-3-4/gpgme/keylist.c | 647 +++++ tags/V0-3-4/gpgme/mkerrors | 84 + tags/V0-3-4/gpgme/mkstatus | 61 + tags/V0-3-4/gpgme/ops.h | 137 + tags/V0-3-4/gpgme/passphrase.c | 175 ++ tags/V0-3-4/gpgme/posix-io.c | 356 +++ tags/V0-3-4/gpgme/posix-sema.c | 71 + tags/V0-3-4/gpgme/posix-util.c | 53 + tags/V0-3-4/gpgme/progress.c | 80 + tags/V0-3-4/gpgme/recipient.c | 240 ++ tags/V0-3-4/gpgme/rungpg.c | 1597 +++++++++++ tags/V0-3-4/gpgme/rungpg.h | 150 + tags/V0-3-4/gpgme/sema.h | 63 + tags/V0-3-4/gpgme/sign.c | 262 ++ tags/V0-3-4/gpgme/signers.c | 120 + tags/V0-3-4/gpgme/syshdr.h | 40 + tags/V0-3-4/gpgme/trustlist.c | 333 +++ tags/V0-3-4/gpgme/types.h | 92 + tags/V0-3-4/gpgme/util.c | 66 + tags/V0-3-4/gpgme/util.h | 153 ++ tags/V0-3-4/gpgme/vasprintf.c | 155 ++ tags/V0-3-4/gpgme/verify.c | 467 ++++ tags/V0-3-4/gpgme/version.c | 269 ++ tags/V0-3-4/gpgme/w32-io.c | 1133 ++++++++ tags/V0-3-4/gpgme/w32-sema.c | 124 + tags/V0-3-4/gpgme/w32-util.c | 140 + tags/V0-3-4/gpgme/wait.c | 449 +++ tags/V0-3-4/gpgme/wait.h | 40 + tags/V0-3-4/gpgmeplug/.cvsignore | 2 + tags/V0-3-4/gpgmeplug/ChangeLog | 75 + tags/V0-3-4/gpgmeplug/Makefile.am | 39 + tags/V0-3-4/gpgmeplug/cryptplug.h | 1634 +++++++++++ tags/V0-3-4/gpgmeplug/gpgme-openpgp.c | 37 + tags/V0-3-4/gpgmeplug/gpgme-smime.c | 37 + tags/V0-3-4/gpgmeplug/gpgmeplug.c | 1296 +++++++++ tags/V0-3-4/gpgmeplug/gpgmeplug.dox | 121 + tags/V0-3-4/jnlib/.cvsignore | 1 + tags/V0-3-4/jnlib/ChangeLog | 84 + tags/V0-3-4/jnlib/Makefile.am | 36 + tags/V0-3-4/jnlib/README | 7 + tags/V0-3-4/jnlib/argparse.c | 995 +++++++ tags/V0-3-4/jnlib/argparse.h | 67 + tags/V0-3-4/jnlib/dotlock.c | 346 +++ tags/V0-3-4/jnlib/dotlock.h | 32 + tags/V0-3-4/jnlib/libjnlib-config.h | 75 + tags/V0-3-4/jnlib/logging.c | 305 +++ tags/V0-3-4/jnlib/logging.h | 74 + tags/V0-3-4/jnlib/mischelp.h | 43 + tags/V0-3-4/jnlib/stringhelp.c | 396 +++ tags/V0-3-4/jnlib/stringhelp.h | 74 + tags/V0-3-4/jnlib/strlist.c | 133 + tags/V0-3-4/jnlib/strlist.h | 43 + tags/V0-3-4/jnlib/types.h | 101 + tags/V0-3-4/jnlib/xmalloc.c | 88 + tags/V0-3-4/jnlib/xmalloc.h | 31 + tags/V0-3-4/tests/.cvsignore | 28 + tags/V0-3-4/tests/ChangeLog | 234 ++ tags/V0-3-4/tests/Makefile.am | 46 + tags/V0-3-4/tests/gpg/.cvsignore | 7 + tags/V0-3-4/tests/gpg/Makefile.am | 54 + tags/V0-3-4/tests/gpg/cipher-1.asc | 15 + tags/V0-3-4/tests/gpg/cipher-2.asc | 16 + tags/V0-3-4/tests/gpg/geheim.txt | 2 + tags/V0-3-4/tests/gpg/mkdemodirs | 44 + tags/V0-3-4/tests/gpg/pubdemo.asc | 566 ++++ tags/V0-3-4/tests/gpg/pubkey-1.asc | 26 + tags/V0-3-4/tests/gpg/secdemo.asc | 737 +++++ tags/V0-3-4/tests/gpg/seckey-1.asc | 30 + tags/V0-3-4/tests/gpg/t-decrypt-verify.c | 146 + tags/V0-3-4/tests/gpg/t-decrypt.c | 139 + tags/V0-3-4/tests/gpg/t-encrypt-sign.c | 139 + tags/V0-3-4/tests/gpg/t-encrypt.c | 118 + tags/V0-3-4/tests/gpg/t-export.c | 92 + tags/V0-3-4/tests/gpg/t-genkey.c | 84 + tags/V0-3-4/tests/gpg/t-import.c | 108 + tags/V0-3-4/tests/gpg/t-keylist.c | 158 ++ tags/V0-3-4/tests/gpg/t-sign.c | 154 ++ tags/V0-3-4/tests/gpg/t-signers.c | 167 ++ tags/V0-3-4/tests/gpg/t-trustlist.c | 90 + tags/V0-3-4/tests/gpg/t-verify.c | 226 ++ tags/V0-3-4/tests/gpgsm/.cvsignore | 12 + .../32100C27173EF6E9C4E9A25D3D69F86D37A4F939 | 18 + tags/V0-3-4/tests/gpgsm/Makefile.am | 54 + tags/V0-3-4/tests/gpgsm/cert_dfn_pca01.der | Bin 0 -> 1224 bytes tags/V0-3-4/tests/gpgsm/cert_dfn_pca15.der | Bin 0 -> 1560 bytes .../V0-3-4/tests/gpgsm/cert_g10code_test1.der | Bin 0 -> 793 bytes tags/V0-3-4/tests/gpgsm/t-decrypt.c | 103 + tags/V0-3-4/tests/gpgsm/t-encrypt.c | 116 + tags/V0-3-4/tests/gpgsm/t-genkey.c | 85 + tags/V0-3-4/tests/gpgsm/t-import.c | 95 + tags/V0-3-4/tests/gpgsm/t-keylist.c | 166 ++ tags/V0-3-4/tests/gpgsm/t-sign.c | 135 + tags/V0-3-4/tests/gpgsm/t-verify.c | 161 ++ tags/V0-3-4/tests/t-data-1.txt | 1 + tags/V0-3-4/tests/t-data-2.txt | 3 + tags/V0-3-4/tests/t-data.c | 324 +++ tags/V0-3-4/tests/t-version.c | 45 + 187 files changed, 38777 insertions(+) create mode 100644 tags/V0-3-4/.cvsignore create mode 100644 tags/V0-3-4/AUTHORS create mode 100644 tags/V0-3-4/ChangeLog create mode 100644 tags/V0-3-4/INSTALL create mode 100644 tags/V0-3-4/Makefile.am create mode 100644 tags/V0-3-4/NEWS create mode 100644 tags/V0-3-4/README create mode 100644 tags/V0-3-4/README-alpha create mode 100644 tags/V0-3-4/THANKS create mode 100644 tags/V0-3-4/TODO create mode 100644 tags/V0-3-4/acconfig.h create mode 100644 tags/V0-3-4/acinclude.m4 create mode 100644 tags/V0-3-4/assuan/.cvsignore create mode 100644 tags/V0-3-4/assuan/ChangeLog create mode 100644 tags/V0-3-4/assuan/Makefile.am create mode 100644 tags/V0-3-4/assuan/README.1st create mode 100644 tags/V0-3-4/assuan/assuan-buffer.c create mode 100644 tags/V0-3-4/assuan/assuan-client.c create mode 100644 tags/V0-3-4/assuan/assuan-connect.c create mode 100644 tags/V0-3-4/assuan/assuan-defs.h create mode 100644 tags/V0-3-4/assuan/assuan-handler.c create mode 100644 tags/V0-3-4/assuan/assuan-inquire.c create mode 100644 tags/V0-3-4/assuan/assuan-listen.c create mode 100644 tags/V0-3-4/assuan/assuan-pipe-connect.c create mode 100644 tags/V0-3-4/assuan/assuan-pipe-server.c create mode 100644 tags/V0-3-4/assuan/assuan-socket-connect.c create mode 100644 tags/V0-3-4/assuan/assuan-socket-server.c create mode 100644 tags/V0-3-4/assuan/assuan-util.c create mode 100644 tags/V0-3-4/assuan/assuan.h create mode 100755 tags/V0-3-4/assuan/mkerrors create mode 100755 tags/V0-3-4/autogen.sh create mode 100644 tags/V0-3-4/bonobo/.cvsignore create mode 100644 tags/V0-3-4/bonobo/Makefile.am create mode 100644 tags/V0-3-4/bonobo/gpgme.c create mode 100644 tags/V0-3-4/bonobo/main.c create mode 100644 tags/V0-3-4/bonobo/main.h create mode 100644 tags/V0-3-4/complus/.cvsignore create mode 100644 tags/V0-3-4/complus/ChangeLog create mode 100644 tags/V0-3-4/complus/Makefile.am create mode 100644 tags/V0-3-4/complus/README create mode 100644 tags/V0-3-4/complus/debug.c create mode 100644 tags/V0-3-4/complus/example.c create mode 100644 tags/V0-3-4/complus/gpgcom.c create mode 100644 tags/V0-3-4/complus/gpgcom.idl create mode 100644 tags/V0-3-4/complus/gpgcom.rc create mode 100644 tags/V0-3-4/complus/gpgcom.tlb create mode 100644 tags/V0-3-4/complus/guidgen.c create mode 100644 tags/V0-3-4/complus/igpgme.c create mode 100644 tags/V0-3-4/complus/igpgme.h create mode 100644 tags/V0-3-4/complus/main.h create mode 100644 tags/V0-3-4/complus/regtlb.c create mode 100644 tags/V0-3-4/complus/tgpgcom.c create mode 100644 tags/V0-3-4/complus/utf8.c create mode 100644 tags/V0-3-4/complus/vbtest.html create mode 100644 tags/V0-3-4/complus/vbtest.vbs create mode 100644 tags/V0-3-4/configure.ac create mode 100644 tags/V0-3-4/doc/.cvsignore create mode 100644 tags/V0-3-4/doc/ChangeLog create mode 100644 tags/V0-3-4/doc/Makefile.am create mode 100644 tags/V0-3-4/doc/fdl.texi create mode 100755 tags/V0-3-4/doc/gdoc create mode 100644 tags/V0-3-4/doc/gpgme.texi create mode 100644 tags/V0-3-4/doc/gpl.texi create mode 100644 tags/V0-3-4/gpgme.txt create mode 100644 tags/V0-3-4/gpgme/.cvsignore create mode 100644 tags/V0-3-4/gpgme/ChangeLog create mode 100644 tags/V0-3-4/gpgme/Makefile.am create mode 100644 tags/V0-3-4/gpgme/context.h create mode 100644 tags/V0-3-4/gpgme/data.c create mode 100644 tags/V0-3-4/gpgme/debug.c create mode 100644 tags/V0-3-4/gpgme/decrypt-verify.c create mode 100644 tags/V0-3-4/gpgme/decrypt.c create mode 100644 tags/V0-3-4/gpgme/delete.c create mode 100644 tags/V0-3-4/gpgme/encrypt-sign.c create mode 100644 tags/V0-3-4/gpgme/encrypt.c create mode 100644 tags/V0-3-4/gpgme/engine-gpgsm.c create mode 100644 tags/V0-3-4/gpgme/engine-gpgsm.h create mode 100644 tags/V0-3-4/gpgme/engine.c create mode 100644 tags/V0-3-4/gpgme/engine.h create mode 100644 tags/V0-3-4/gpgme/export.c create mode 100644 tags/V0-3-4/gpgme/fopencookie.c create mode 100644 tags/V0-3-4/gpgme/genkey.c create mode 100644 tags/V0-3-4/gpgme/gpgme-config.in create mode 100644 tags/V0-3-4/gpgme/gpgme.c create mode 100644 tags/V0-3-4/gpgme/gpgme.h create mode 100644 tags/V0-3-4/gpgme/gpgme.m4 create mode 100644 tags/V0-3-4/gpgme/import.c create mode 100644 tags/V0-3-4/gpgme/io.h create mode 100644 tags/V0-3-4/gpgme/key.c create mode 100644 tags/V0-3-4/gpgme/key.h create mode 100644 tags/V0-3-4/gpgme/keylist.c create mode 100755 tags/V0-3-4/gpgme/mkerrors create mode 100755 tags/V0-3-4/gpgme/mkstatus create mode 100644 tags/V0-3-4/gpgme/ops.h create mode 100644 tags/V0-3-4/gpgme/passphrase.c create mode 100644 tags/V0-3-4/gpgme/posix-io.c create mode 100644 tags/V0-3-4/gpgme/posix-sema.c create mode 100644 tags/V0-3-4/gpgme/posix-util.c create mode 100644 tags/V0-3-4/gpgme/progress.c create mode 100644 tags/V0-3-4/gpgme/recipient.c create mode 100644 tags/V0-3-4/gpgme/rungpg.c create mode 100644 tags/V0-3-4/gpgme/rungpg.h create mode 100644 tags/V0-3-4/gpgme/sema.h create mode 100644 tags/V0-3-4/gpgme/sign.c create mode 100644 tags/V0-3-4/gpgme/signers.c create mode 100644 tags/V0-3-4/gpgme/syshdr.h create mode 100644 tags/V0-3-4/gpgme/trustlist.c create mode 100644 tags/V0-3-4/gpgme/types.h create mode 100644 tags/V0-3-4/gpgme/util.c create mode 100644 tags/V0-3-4/gpgme/util.h create mode 100644 tags/V0-3-4/gpgme/vasprintf.c create mode 100644 tags/V0-3-4/gpgme/verify.c create mode 100644 tags/V0-3-4/gpgme/version.c create mode 100644 tags/V0-3-4/gpgme/w32-io.c create mode 100644 tags/V0-3-4/gpgme/w32-sema.c create mode 100644 tags/V0-3-4/gpgme/w32-util.c create mode 100644 tags/V0-3-4/gpgme/wait.c create mode 100644 tags/V0-3-4/gpgme/wait.h create mode 100644 tags/V0-3-4/gpgmeplug/.cvsignore create mode 100644 tags/V0-3-4/gpgmeplug/ChangeLog create mode 100644 tags/V0-3-4/gpgmeplug/Makefile.am create mode 100644 tags/V0-3-4/gpgmeplug/cryptplug.h create mode 100644 tags/V0-3-4/gpgmeplug/gpgme-openpgp.c create mode 100644 tags/V0-3-4/gpgmeplug/gpgme-smime.c create mode 100644 tags/V0-3-4/gpgmeplug/gpgmeplug.c create mode 100644 tags/V0-3-4/gpgmeplug/gpgmeplug.dox create mode 100644 tags/V0-3-4/jnlib/.cvsignore create mode 100644 tags/V0-3-4/jnlib/ChangeLog create mode 100644 tags/V0-3-4/jnlib/Makefile.am create mode 100644 tags/V0-3-4/jnlib/README create mode 100644 tags/V0-3-4/jnlib/argparse.c create mode 100644 tags/V0-3-4/jnlib/argparse.h create mode 100644 tags/V0-3-4/jnlib/dotlock.c create mode 100644 tags/V0-3-4/jnlib/dotlock.h create mode 100644 tags/V0-3-4/jnlib/libjnlib-config.h create mode 100644 tags/V0-3-4/jnlib/logging.c create mode 100644 tags/V0-3-4/jnlib/logging.h create mode 100644 tags/V0-3-4/jnlib/mischelp.h create mode 100644 tags/V0-3-4/jnlib/stringhelp.c create mode 100644 tags/V0-3-4/jnlib/stringhelp.h create mode 100644 tags/V0-3-4/jnlib/strlist.c create mode 100644 tags/V0-3-4/jnlib/strlist.h create mode 100644 tags/V0-3-4/jnlib/types.h create mode 100644 tags/V0-3-4/jnlib/xmalloc.c create mode 100644 tags/V0-3-4/jnlib/xmalloc.h create mode 100644 tags/V0-3-4/tests/.cvsignore create mode 100644 tags/V0-3-4/tests/ChangeLog create mode 100644 tags/V0-3-4/tests/Makefile.am create mode 100644 tags/V0-3-4/tests/gpg/.cvsignore create mode 100644 tags/V0-3-4/tests/gpg/Makefile.am create mode 100644 tags/V0-3-4/tests/gpg/cipher-1.asc create mode 100644 tags/V0-3-4/tests/gpg/cipher-2.asc create mode 100644 tags/V0-3-4/tests/gpg/geheim.txt create mode 100755 tags/V0-3-4/tests/gpg/mkdemodirs create mode 100644 tags/V0-3-4/tests/gpg/pubdemo.asc create mode 100644 tags/V0-3-4/tests/gpg/pubkey-1.asc create mode 100644 tags/V0-3-4/tests/gpg/secdemo.asc create mode 100644 tags/V0-3-4/tests/gpg/seckey-1.asc create mode 100644 tags/V0-3-4/tests/gpg/t-decrypt-verify.c create mode 100644 tags/V0-3-4/tests/gpg/t-decrypt.c create mode 100644 tags/V0-3-4/tests/gpg/t-encrypt-sign.c create mode 100644 tags/V0-3-4/tests/gpg/t-encrypt.c create mode 100644 tags/V0-3-4/tests/gpg/t-export.c create mode 100644 tags/V0-3-4/tests/gpg/t-genkey.c create mode 100644 tags/V0-3-4/tests/gpg/t-import.c create mode 100644 tags/V0-3-4/tests/gpg/t-keylist.c create mode 100644 tags/V0-3-4/tests/gpg/t-sign.c create mode 100644 tags/V0-3-4/tests/gpg/t-signers.c create mode 100644 tags/V0-3-4/tests/gpg/t-trustlist.c create mode 100644 tags/V0-3-4/tests/gpg/t-verify.c create mode 100644 tags/V0-3-4/tests/gpgsm/.cvsignore create mode 100644 tags/V0-3-4/tests/gpgsm/32100C27173EF6E9C4E9A25D3D69F86D37A4F939 create mode 100644 tags/V0-3-4/tests/gpgsm/Makefile.am create mode 100644 tags/V0-3-4/tests/gpgsm/cert_dfn_pca01.der create mode 100644 tags/V0-3-4/tests/gpgsm/cert_dfn_pca15.der create mode 100644 tags/V0-3-4/tests/gpgsm/cert_g10code_test1.der create mode 100644 tags/V0-3-4/tests/gpgsm/t-decrypt.c create mode 100644 tags/V0-3-4/tests/gpgsm/t-encrypt.c create mode 100644 tags/V0-3-4/tests/gpgsm/t-genkey.c create mode 100644 tags/V0-3-4/tests/gpgsm/t-import.c create mode 100644 tags/V0-3-4/tests/gpgsm/t-keylist.c create mode 100644 tags/V0-3-4/tests/gpgsm/t-sign.c create mode 100644 tags/V0-3-4/tests/gpgsm/t-verify.c create mode 100644 tags/V0-3-4/tests/t-data-1.txt create mode 100644 tags/V0-3-4/tests/t-data-2.txt create mode 100644 tags/V0-3-4/tests/t-data.c create mode 100644 tags/V0-3-4/tests/t-version.c diff --git a/tags/V0-3-4/.cvsignore b/tags/V0-3-4/.cvsignore new file mode 100644 index 0000000..46d1979 --- /dev/null +++ b/tags/V0-3-4/.cvsignore @@ -0,0 +1,13 @@ +Makefile +Makefile.in +aclocal.m4 +config.cache +config.h +config.h.in +config.log +config.status +configure +stamp-h +stamp-h.in +stamp-h1 +libtool diff --git a/tags/V0-3-4/AUTHORS b/tags/V0-3-4/AUTHORS new file mode 100644 index 0000000..5cc9c29 --- /dev/null +++ b/tags/V0-3-4/AUTHORS @@ -0,0 +1,23 @@ +Program: gpgme +Maintainer: wk@g10gnupg.org + + +FSF + - Code taken from GnuPG 1.0: gpgme/w32-util.c, GnuPG 1.1: jnlib/. + +g10 Code GmbH + - All stuff since mid march 2001. + +Werner Koch + - Design and most stuff. + + + Copyright 2001 g10 Code GmbH + + This file is free software; as a special exception the author gives + unlimited permission to copy and/or distribute it, with or without + modifications, as long as this notice is preserved. + + This file is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, to the extent permitted by law; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/tags/V0-3-4/ChangeLog b/tags/V0-3-4/ChangeLog new file mode 100644 index 0000000..605e1a6 --- /dev/null +++ b/tags/V0-3-4/ChangeLog @@ -0,0 +1,154 @@ +2002-03-04 Werner Koch + + Released 0.3.4. + + * configure.ac: Bumbed LT version numbers to (7,1,0), requires + gpgsm 0.3.1. + +2002-03-03 Marcus Brinkmann + + * configure.ac (AC_INIT): Change version number to snapshot CVS + version. + +2002-02-13 Werner Koch + + * configure.ac (vasprintf,fopencookie): Add checks. + +2002-02-12 Marcus Brinkmann + + * configure.ac (AC_INIT): Bump version to 0.3.3. + * jnlib/Makefile.am: Rever to older version that includes xmalloc + but not dotlock and some other files. Reported by Stéphane + Corthésy. + +2002-02-10 Marcus Brinkmann + + * Released 0.3.2. + + * configure.ac (AC_INIT): Bump version to 0.3.2. + * jnlib/libjnlibconfig.h: Revert to older version that doesn't + expect libgcrypt. Reported by Jose Carlos Garcia Sogo + . + +2002-02-09 Marcus Brinkmann + + * Released 0.3.1. + + * configure.ac (LIBGPGME_LT_CURRENT): Bump it up to 6! + (NEED_GPGSM_VERSION): Bump it up to 0.3.0! + (AC_INIT): Bump version to 0.3.1 + +2002-01-22 Marcus Brinkmann + + * configure.ac (HAVE_JNLIB_LOGGING): Define always for assuan. + +2001-12-19 Werner Koch + + * configure.ac (VERSION,PACKAGE): Defined and subst. Used for + AM_INIT_AUTOMAKE and moved all version number more to the top. + +2001-12-18 Marcus Brinkmann + + * autogen.sh (libtool_vers): Bump to 1.4. + + * configure.ac (LIBGPGME_LT_CURRENT): Increment. + (LIBGPGME_LT_AGE): Reset. + Improve comment. + Fix wrong comment character. + +2001-12-18 Werner Koch + + * acinclude.m4 (GNUPG_FIX_HDR_VERSION): Fixed for new automake. + +2001-12-14 Marcus Brinkmann + + * configure.ac (GPG): Substitute this variable. + (GPGSM): Likewise. + +2001-11-22 Marcus Brinkmann + + * configure.ac (AC_CONFIG_FILES): Add tests/gpg/Makefile and + tests/gpgsm/Makefile. + +2001-11-21 Marcus Brinkmann + + * Makefile.am (gpgmeplug): New variable, set to gpgmeplug if + [BUILD_GPGMEPLUG]. + * configure.ac (AC_CONFIG_FILES): Add gpgmeplug/Makefile. + Support --enable-gpgmeplug. + +2001-11-21 Marcus Brinkmann + + * autogen.sh: Tighten version dependencies. + +2001-11-20 Marcus Brinkmann + + * Makefile.am (SUBDIRS): Support building the assuan library + (currently if GPGSM_PATH is set).. + * configure.ac: Support building the assuan library. + * assuan: New directory, populated with the Assuan library + (copied from the newpg repository). + +2001-11-20 Marcus Brinkmann + + * configure.ac (NEED_GPGSM_VERSION): New variable. Treat it + similarly to NEED_GPG_VERSION. + * acconfig.h: Likewise. + +2001-11-18 Marcus Brinkmann + + * configure.in: Renamed to ... + * configure.ac: ... this. Update to autoconf 2.52. Lots of small + changes in the transition. Support --with-gpg=PATH and + --with-gpgsm=PATH options. Check if test suites can be run. + * acconfig.h: Add GPGSM_PATH. + * Makefile.am: New variable `tests', set to `tests' if + RUN_GPG_TESTS. + (SUBDIRS): Replace string `tests' with variable `tests'. + +2001-10-22 Marcus Brinkmann + + * autogen.sh: Invoke automake with `-a' (add missing files). + Do not invoke configure. + +2001-09-17 Werner Koch + + Released 0.2.3. + + * configure.in (NEED_GPG_VERSION): Set to 1.0.6. Incremented LT + current and age. + + * Makefile.am (SUBDIRS): Add doc + +2001-06-12 Werner Koch + + Released 0.2.2. + +2001-04-05 Werner Koch + + * configure.in (NEED_GPG_VERSION): Set to 1.0.4g + +2001-04-02 Werner Koch + + Released 0.2.1. + + Changed the copyright notices all over the place. + +2001-02-28 Werner Koch + + Released 0.2.0. + +2001-01-18 Werner Koch + + * autogen.sh: Added option --build-w32. + + + Copyright 2001, 2002 g10 Code GmbH + + This file is free software; as a special exception the author gives + unlimited permission to copy and/or distribute it, with or without + modifications, as long as this notice is preserved. + + This file is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, to the extent permitted by law; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/tags/V0-3-4/INSTALL b/tags/V0-3-4/INSTALL new file mode 100644 index 0000000..ebae9ac --- /dev/null +++ b/tags/V0-3-4/INSTALL @@ -0,0 +1,196 @@ +Installation Instructions for GPGME +=================================== + + Copyright 2001 g10 Code GmbH + + This file is free software; as a special exception the author gives + unlimited permission to copy and/or distribute it, with or without + modifications, as long as this notice is preserved. + + This file is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, to the extent permitted by law; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + +Basic Installation +================== + + These are generic installation instructions. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, a file +`config.cache' that saves the results of its tests to speed up +reconfiguring, and a file `config.log' containing compiler output +(useful mainly for debugging `configure'). + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If at some point `config.cache' +contains results you don't want to keep, you may remove or edit it. + + The file `configure.in' is used to create `configure' by a program +called `autoconf'. You only need `configure.in' if you want to change +it or regenerate `configure' using a newer version of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. If you're + using `csh' on an old version of System V, you might need to type + `sh ./configure' instead to prevent `csh' from trying to execute + `configure' itself. + + Running `configure' takes awhile. While running, it prints some + messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + +Compilers and Options +===================== + + Some systems require unusual options for compilation or linking that +the `configure' script does not know about. You can give `configure' +initial values for variables by setting them in the environment. Using +a Bourne-compatible shell, you can do that on the command line like +this: + CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure + +Or on systems that have the `env' program, you can do it like this: + env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure + +Compiling For Multiple Architectures +==================================== + + You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you must use a version of `make' that +supports the `VPATH' variable, such as GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + If you have to use a `make' that does not supports the `VPATH' +variable, you have to compile the package for one architecture at a time +in the source code directory. After you have installed the package for +one architecture, use `make distclean' before reconfiguring for another +architecture. + +Installation Names +================== + + By default, `make install' will install the package's files in +`/usr/local/bin', `/usr/local/man', etc. You can specify an +installation prefix other than `/usr/local' by giving `configure' the +option `--prefix=PATH'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +give `configure' the option `--exec-prefix=PATH', the package will use +PATH as the prefix for installing programs and libraries. +Documentation and other data files will still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=PATH' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + + Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Specifying the System Type +========================== + + There may be some features `configure' can not figure out +automatically, but needs to determine by the type of host the package +will run on. Usually `configure' can figure that out, but if it prints +a message saying it can not guess the host type, give it the +`--host=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name with three fields: + CPU-COMPANY-SYSTEM + +See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the host type. + + If you are building compiler tools for cross-compiling, you can also +use the `--target=TYPE' option to select the type of system they will +produce code for and the `--build=TYPE' option to select the type of +system on which you are compiling the package. + +Sharing Defaults +================ + + If you want to set default values for `configure' scripts to share, +you can create a site shell script called `config.site' that gives +default values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Operation Controls +================== + + `configure' recognizes the following options to control how it +operates. + +`--cache-file=FILE' + Use and save the results of the tests in FILE instead of + `./config.cache'. Set FILE to `/dev/null' to disable caching, for + debugging `configure'. + +`--help' + Print a summary of the options to `configure', and exit. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`--version' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`configure' also accepts some other, not widely useful, options. diff --git a/tags/V0-3-4/Makefile.am b/tags/V0-3-4/Makefile.am new file mode 100644 index 0000000..5ed1b62 --- /dev/null +++ b/tags/V0-3-4/Makefile.am @@ -0,0 +1,54 @@ +# Copyright (C) 2000 Werner Koch (dd9jn) +# Copyright (C) 2001 g10 Code GmbH +# +# This file is part of GPGME. +# +# GPGME is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# GPGME is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +## Process this file with automake to produce Makefile.in + +EXTRA_DIST = README-alpha autogen.sh + +if BUILD_ASSUAN +assuan = assuan +else +assuan = +endif + +if BUILD_BONOBO +bonobo = bonobo +else +bonobo = +endif + +if BUILD_COMPLUS +complus = complus +else +complus = +endif + +if RUN_GPG_TESTS +tests = tests +else +tests = +endif + +if BUILD_GPGMEPLUG +gpgmeplug = gpgmeplug +else +gpgmeplug = +endif + +SUBDIRS = ${assuan} jnlib gpgme ${tests} doc ${bonobo} ${complus} ${gpgmeplug} diff --git a/tags/V0-3-4/NEWS b/tags/V0-3-4/NEWS new file mode 100644 index 0000000..3e70ac4 --- /dev/null +++ b/tags/V0-3-4/NEWS @@ -0,0 +1,199 @@ +Noteworthy changes in version 0.3.4 (2002-03-04) +------------------------------------------------ + + * gpgme_op_encrypt does now fail with GPGME_Invalid_Recipients if + some recipients have been invalid, whereas earlier versions + succeeded in this case. The plaintext is still encrypted for all valid + recipients, so the application might take this error as a hint that + the ciphertext is not usable for all requested recipients. + Information about invalid recipients is available with gpgme_get_op_info. + + * gpgme_op_verify now allows to pass an uninitialized data object as + its plaintext argument to check for normal and cleartext + signatures. The plaintext is then returned in the data object. + + * New interfaces gpgme_set_include_certs and gpgme_get_include_certs + to set and get the number of certifications to include in S/MIME + signed messages. + + * New interfaces gpgme_op_encrypt_sign and gpgme_op_encrypt_sign_start + to encrypt and sign a message in a combined operation. + + * New interface gpgme_op_keylist_ext_start to search for multiple patterns. + + * gpgme_key_get_ulong_attr supports the GPGME_ATTR_EXPIRE attribute. + + * Interface changes relative to the 0.3.3 release: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +gpgme_op_encrypt CHANGED: Can fail with GPGME_Invalid_Recipients +gpgme_op_verify EXTENDED: Accepts uninitialized text argument +gpgme_key_get_ulong_attr EXTENDED: Supports GPGME_ATTR_EXPIRE +gpgme_set_include_certs NEW +gpgme_get_include_certs NEW +gpgme_op_encrypt_sign NEW +gpgme_op_encrypt_sign_start NEW +gpgme_op_keylist_ext_start NEW +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Noteworthy changes in version 0.3.3 (2002-02-12) +------------------------------------------------ + + * Fix the Makefile in jnlib. + + * Fix the test suite (hopefully). It should clean up all its state + with `make check' now. + + +Noteworthy changes in version 0.3.2 (2002-02-10) +------------------------------------------------ + + * Remove erroneous dependency on libgcrypt in jnlib. + + +Noteworthy changes in version 0.3.1 (2002-02-09) +------------------------------------------------ + + * There is a Texinfo manual documenting the API. + + * The gpgme_set_keylist_mode function returns an error, and changed + its meaning. It is no longer usable to select between normal and + fast mode (newer versions of GnuPG will always be fast), but + selects between local keyring, remote keyserver, or both. + For this, two new macros are defined, GPGME_KEYLIST_MODE_LOCAL + and GPGME_KEYLIST_MODE_EXTERN. To make it possible to modify the + current setting, a fucntion gpgme_get_keylist_mode was added to + retrieve the current mode. + + * gpgme_wait accepts a new argument STATUS to return the error status + of the operation on the context. Its definition is closer to + waitpid() now than before. + + * The LENGTH argument to gpgme_data_new_from_filepart changed its + type from off_t to the unsigned size_t. + + * The R_HD argument to the GpgmePassphraseCb type changed its type + from void* to void**. + + * New interface gpgme_op_trustlist_end() to match + gpgme_op_keylist_end(). + + * The CryptPlug modules have been renamed to gpgme-openpgp and + gpgme-smime, and they are installed in pkglibdir by `make install'. + + * An idle function can be registered with gpgme_register_idle(). + + * The GpgSM backend supports key generation with gpgme_op_genkey(). + + * Interface changes relative to the 0.3.0 release: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +gpgme_data_new_from_filepart CHANGED: Type of LENGTH is size_t. +GpgmePassphraseCb CHANGED: Type of R_HD is void **. +gpgme_wait CHANGED: New argument STATUS. +gpgme_set_keylist_mode CHANGED: Type of return value is GpgmeError. + The function has a new meaning! +gpgme_get_keylist_mode NEW +GPGME_KEYLIST_MODE_LOCAL NEW +GPGME_KEYLIST_MODE_EXTERN NEW +gpgme_op_trustlist_next NEW +GpgmeIdleFunc NEW +gpgme_register_idle NEW +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Noteworthy changes in version 0.3.0 (2001-12-19) +------------------------------------------------ + + * New interface gpgme_set_protocol() to set the protocol and thus the + crypto engine to be used by the context. Currently, the OpenPGP + and the CMS protocols are supported. They are specified by the new + preprocessor symbols GPGME_PROTOCOL_OpenPGP and GPGME_PROTOCOL_CMS. + A new context uses the OpenPGP engine by default. + + * gpgme_get_engine_info() returns information for all crypto engines + compiled into the library. The XML format has changed. To + reliably get the version of a crypto engine, the tag + after the appropriate tag has to be looked for. + + * New interface gpgme_engine_check_version(), obsoleting + gpgme_check_engine(). Check the version of all engines you are + supporting in your software. + + * GpgmeKey lists the user ids in the order as they are returned by + GnuPG, first the primary key with index 0, then the sub-user ids. + + * New operation gpgme_op_decrypt_verify() to decrypt and verify + signatures simultaneously. + + * The new interface gpgme_op_keylist_end() terminates a pending + keylist operation. A keylist operation is also terminated when + gpgme_op_keylist_next() returns GPGME_EOF. + + * GPGME can be compiled without GnuPG being installed (`--with-gpg=PATH'), + cross-compiled, or even compiled without support for GnuPG + (`--without-gpg'). + + * GPGME can be compiled with support for GpgSM (GnuPG for S/MIME, + `--with-gpgsm=PATH'). It is enabled by default if the `gpgsm' is found + in the path, but it can also be compiled without support for GpgSM + (`--without-gpgsm'). + + * CryptPlug modules for GPGME are included and can be enabled at + configure time (`--enable-gpgmeplug'). There is one module which + uses the GnuPG engine (`gpgmeplug') and one module which uses the + GpgSM engine (`gpgsmplug'). + + * Interface changes relative to the latest 0.2.x release: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +gpgme_key_get_as_xml CHANGED: Sub-user ids reversed in order. +gpgme_key_get_string_attr CHANGED: User ids reversed in order. +gpgme_key_get_ulong_attr CHANGED: User ids reversed in order. +gpgme_get_engine_info CHANGED: New format, extended content. +gpgme_engine_check_version NEW +gpgme_decrypt_verify_start NEW +gpgme_decrypt_verify NEW +gpgme_op_keylist_next NEW +gpgme_set_protocol NEW +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +Noteworthy changes in version 0.2.3 (2001-09-17) +------------------------------------------------ + + * New function gpgme_get_op_info which can be used to get the micalg + parameter needed for MOSS. + + * New functions gpgme_get_armor and gpgme_get_textmode. + + * The usual bug fixes and some minor functionality improvements. + + * Added a simple encryption component for MS-Windows; however the + build procedure might have some problems. + + +Noteworthy changes in version 0.2.2 (2001-06-12) +------------------------------------------------ + + * Implemented a key cache. + + * Fixed a race condition under W32 and some other bug fixes. + + +Noteworthy changes in version 0.2.1 (2001-04-02) +------------------------------------------------ + + * Changed debug output and GPGME_DEBUG variable (gpgme/debug.c) + + * Handle GnuPG's new key capabilities output and support revocation + et al. attributes + + * Made the W32 support more robust. + + + Copyright 2001, 2002 g10 Code GmbH + + This file is free software; as a special exception the author gives + unlimited permission to copy and/or distribute it, with or without + modifications, as long as this notice is preserved. + + This file is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, to the extent permitted by law; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/tags/V0-3-4/README b/tags/V0-3-4/README new file mode 100644 index 0000000..2236c24 --- /dev/null +++ b/tags/V0-3-4/README @@ -0,0 +1,42 @@ + GPGME - GnuPG Made Easy + --------------------------- + + !!!! THIS IS WORK IN PROGRESS !!! + +If you want to hack on it, start with one of the `tests/t-foo' +programs. + +For support of the OpenPGP protocol (default), you need the latest CVS +version of GnuPG 1.0, see `http://www.gnupg.org/cvs-access.html'. + +You need at least GnuPG 1.0.6, but don't use a 1.1.x version. + +If configure can't find the `gpg' binary in your path, you can specify +the location with the --with-gpg=/path/to/gpg argument to configure. + +For support of the CMS (Cryptographic Message Syntax) protocol, you +need the latest CVS version of GpgSM, module name `newpg', at +`:pserver:anoncvs@cvs.gnupg.org:/cvs/aegypten'. + +You need at least GpgSM 0.3.0. + +If configure can't find the `gpgsm' binary in your path, you can +specify the location with the --with-gpgsm=/path/to/gpgsm argument to +configure. + +To enable the CryptPlug GPGME PlugIn for both protocols, use the +`--enable-gpgmeplug' option to the configure script. `gpgmeplug' is +experimental and you should not assume that it will stay with gpgme. +The plug-ins are installed by `make install' in `pkglibdir', normally +`PREFIX/lib/gpgme'. + +Before building the CVS version following the generic install +instructions in `INSTALL', you need to set up the build scripts with +`./autogen.sh'. To build the W32 version, use `./autogen.sh +--build-w32'. You also need to enable maintainer mode at configure +time with `--enable-maintainer-mode', or the documentation will not +built (because the version.texi won't be generated unless maintainer +mode is enabled). + +Please subscribe to the gnupg-devel@gnupg.org mailing list if you want +to do serious work. diff --git a/tags/V0-3-4/README-alpha b/tags/V0-3-4/README-alpha new file mode 100644 index 0000000..0f748e3 --- /dev/null +++ b/tags/V0-3-4/README-alpha @@ -0,0 +1 @@ + THIS IS WORK IN PROGRESS !!!! \ No newline at end of file diff --git a/tags/V0-3-4/THANKS b/tags/V0-3-4/THANKS new file mode 100644 index 0000000..48729fd --- /dev/null +++ b/tags/V0-3-4/THANKS @@ -0,0 +1,21 @@ + +Alfons Hoogervorst alfons@proteus.demon.nl +Enno Cramer uebergeek@web.de +Jan-Oliver Wagner jan@intevation.de +Johannes Poehlmann jhp@caldera.de +Jose C. García Sogo jose@jaimedelamo.eu.org +Mark Mutz mutz@kde.org +Stéphane Corthésy stephane@sente.ch +Timo Schulz twoaday@freakmail.de +Tommy Reynolds reynolds@redhat.com + + + Copyright 2001 g10 Code GmbH + + This file is free software; as a special exception the author gives + unlimited permission to copy and/or distribute it, with or without + modifications, as long as this notice is preserved. + + This file is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, to the extent permitted by law; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/tags/V0-3-4/TODO b/tags/V0-3-4/TODO new file mode 100644 index 0000000..0e1752c --- /dev/null +++ b/tags/V0-3-4/TODO @@ -0,0 +1,68 @@ +Hey Emacs, this is -*- outline -*- mode! + +* ABI's to break: +** string representation of non-secret keys and ATTR_IS_SECRET is NULL, + which can not be differentiated from the case that it is not + representable. + +* Allow to use GTK's main loop instead of the select stuff in + wait.c + +* add locking to the key cache? + +* Documentation +** Add note about GPGME clearing out pointer return values. +** validity/trust +** Document gpgme.m4 + +* Engines +** Move code common to all engines up from gpg to engine. +** engine operations can return General Error on unknown protocol + (it's an internal error, as select_protocol checks already). +** When server mode is implemented properly, more care has to be taken to + release all resources on error (for example to free assuan_cmd). + +* Operations +** Export status handler need much more work. +** Import should return a useful error when one happened. +** Genkey should return something more useful than General_Error. +** Factor out common code in _op_*_start functions. +** Add ATTR to return the number of subkeys or uids. +** "When returning a GpgmeKey GPGME_ATTR_COMMENT attribute, characters + like ":" are not un-escaped, they are returned as \x3a" Bug + reported by Stephane Corthesy. + + +* Error Values +** Map ASSUAN/GpgSM ERR error values in a better way than is done now. +** Verify (and document) if Read_Error, Write_Error, Pipe_Error set errno. + +* Tests +** Write a fake gpg-agent so that we can supply known passphrases to + gpgsm and setup the configuration files to use the agent. Without + this we are testing a currently running gpg-agent which is not a + clever idea. +** t-data +*** Test gpgme_data_release_and_get_mem. +*** Test gpgme_data_rewind for invalid types. +*** Test gpgme_data_read's readable feature. + +* Build suite +** Make sure everything is cleaned correctly (esp. test area). + +* Architecture support +** Implement posix-sema.c + +Bugs reported by Stephane Corthesy: +> BTW, here's another bug: it it not possible to retrieve fingerprints +> for subkeys + +> In GpgmeRecipients, would it be possible to provide a function which +> would return the validity assigned to a name contained in the +> GpgmeRecipients instance? + +> passphrase callback. If I use the same GpgmeContext as the one which +> is currently asking for a passphrase, my app crashes: the r_hd in +> the +> callback has become invalid; if I use a brand new one, the callback +> is called recursively, when I ask to enumerate keys. diff --git a/tags/V0-3-4/acconfig.h b/tags/V0-3-4/acconfig.h new file mode 100644 index 0000000..39d3844 --- /dev/null +++ b/tags/V0-3-4/acconfig.h @@ -0,0 +1,65 @@ +/* acconfig.h - used by autoheader to make config.h.in + * Copyright (C) 2000 Werner Koch (dd9jn) + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#ifndef GPGME_CONFIG_H +#define GPGME_CONFIG_H + +/* need this, because some autoconf tests rely on this (e.g. stpcpy) + * and it should be used for new programs */ +#define _GNU_SOURCE 1 +/* To allow the use of gpgme in multithreaded programs we have to use + * special features from the library. + * IMPORTANT: gpgme is not yet fully reentrant and you should use it + * only from one thread. */ +#define _REENTRANT 1 + +@TOP@ + +/* defined if we run on some of the PCDOS like systems (DOS, Windoze. OS/2) + * with special properties like no file modes */ +#undef HAVE_DOSISH_SYSTEM +/* defined if the filesystem uses driver letters */ +#undef HAVE_DRIVE_LETTERS +/* Some systems have a mkdir that takes a single argument. */ +#undef MKDIR_TAKES_ONE_ARG + +/* Path to the GnuPG binary. */ +#undef GPG_PATH +/* Min. needed GnuPG version. */ +#undef NEED_GPG_VERSION + +/* Path to the GpgSM binary. */ +#undef GPGSM_PATH +/* Min. needed GpgSM version. */ +#undef NEED_GPGSM_VERSION + +/* Stuff needed by jnlib. */ +#undef HAVE_BYTE_TYPEDEF +#undef HAVE_USHORT_TYPEDEF +#undef HAVE_ULONG_TYPEDEF +#undef HAVE_U16_TYPEDEF +#undef HAVE_U32_TYPEDEF + + + +@BOTTOM@ + +/* not yet needed #include "gpgme-defs.h"*/ + +#endif /*GPGME_CONFIG_H*/ diff --git a/tags/V0-3-4/acinclude.m4 b/tags/V0-3-4/acinclude.m4 new file mode 100644 index 0000000..01fe6ba --- /dev/null +++ b/tags/V0-3-4/acinclude.m4 @@ -0,0 +1,57 @@ +dnl Macros to configure gpgme + + +dnl GNUPG_FIX_HDR_VERSION(FILE, NAME) +dnl Make the version number in gcrypt/gcrypt.h the same as the one here. +dnl (this is easier than to have a .in file just for one substitution) +dnl We must use a temp file in the current directory because make distcheck +dnl install all sourcefiles RO. +dnl (wk 2001-12-18) +AC_DEFUN(GNUPG_FIX_HDR_VERSION, + [ sed "s/^#define $2 \".*/#define $2 \"$VERSION\"/" $srcdir/$1 > fixhdr.tmp + if cmp -s $srcdir/$1 fixhdr.tmp 2>/dev/null; then + rm -f fixhdr.tmp + else + rm -f $srcdir/$1 + if mv fixhdr.tmp $srcdir/$1 ; then + : + else + AC_MSG_ERROR([[ +*** +*** Failed to fix the version string macro $2 in $1. +*** The old file has been saved as fixhdr.tmp +***]]) + fi + AC_MSG_WARN([fixed the $2 macro in $1]) + fi + ]) + + + + +dnl GNUPG_CHECK_TYPEDEF(TYPE, HAVE_NAME) +dnl Check whether a typedef exists and create a #define $2 if it exists +dnl +AC_DEFUN(GNUPG_CHECK_TYPEDEF, + [ AC_MSG_CHECKING(for $1 typedef) + AC_CACHE_VAL(gnupg_cv_typedef_$1, + [AC_TRY_COMPILE([#include + #include ], [ + #undef $1 + int a = sizeof($1); + ], gnupg_cv_typedef_$1=yes, gnupg_cv_typedef_$1=no )]) + AC_MSG_RESULT($gnupg_cv_typedef_$1) + if test "$gnupg_cv_typedef_$1" = yes; then + AC_DEFINE($2) + fi + ]) + + + + + + + + + + diff --git a/tags/V0-3-4/assuan/.cvsignore b/tags/V0-3-4/assuan/.cvsignore new file mode 100644 index 0000000..564fd58 --- /dev/null +++ b/tags/V0-3-4/assuan/.cvsignore @@ -0,0 +1,2 @@ +Makefile.in Makefile .deps +assuan-errors.c diff --git a/tags/V0-3-4/assuan/ChangeLog b/tags/V0-3-4/assuan/ChangeLog new file mode 100644 index 0000000..290fef5 --- /dev/null +++ b/tags/V0-3-4/assuan/ChangeLog @@ -0,0 +1,175 @@ +2002-02-01 Marcus Brinkmann + + * Makefile.am (MOSTLYCLEANFILES): New variable. + +2002-01-23 Werner Koch + + * assuan-socket-connect.c (LOGERRORX): and removed typo. + +2002-01-22 Marcus Brinkmann + + * assuan-socket-connect.c (LOGERRORX): Reverse arguments to fputs. + +2002-01-21 Werner Koch + + * assuan-connect.c: Move all except assuan_get_pid to... + * assuan-pipe-connect.c: this. + (assuan_pipe_disconnect): Removed. + (do_finish, do_deinit): New + (assuan_pipe_connect): and set them into the context. + * assuan-socket-connect.c: New. + + * assuan-util.c (_assuan_log_sanitized_string): New. + + * assuan-pipe-server.c (assuan_init_pipe_server): Factored most + code out to ... + (_assuan_new_context): new func. + (_assuan_release_context): New + * assuan-connect.c (assuan_pipe_connect): Use the new functions. + +2002-01-20 Werner Koch + + * assuan.h: Added Invalid Option error code. + + * assuan-handler.c (std_handler_option): New. + (std_cmd_tbl): Add OPTION as standard command. + (assuan_register_option_handler): New. + (dispatch_command): Use case insensitive matching as a fallback. + (my_strcasecmp): New. + +2002-01-19 Werner Koch + + * assuan-buffer.c (_assuan_read_line): Add output logging. + (assuan_write_line): Ditto. + (_assuan_cookie_write_data): Ditto. + (_assuan_cookie_write_flush): Ditto. + * assuan-util.c (_assuan_log_print_buffer): New. + (assuan_set_log_stream): New. + (assuan_begin_confidential): New. + (assuan_end_confidential): New. + + * assuan-defs.h: Add a few handler variables. + * assuan-pipe-server.c (assuan_deinit_pipe_server): Removed. + (deinit_pipe_server): New. + (assuan_deinit_server): New. Changed all callers to use this. + * assuan-listen.c (assuan_accept): Use the accept handler. + * assuan-handler.c (process_request): Use the close Handler. + * assuan-socket-server.c: New. + +2002-01-14 Werner Koch + + * assuan-client.c (_assuan_read_from_server): Skip spaces after + the keyword. + +2002-01-03 Werner Koch + + * assuan-handler.c (assuan_set_okay_line): New. + (process_request): And use it here. + +2002-01-02 Werner Koch + + * assuan-inquire.c (init_membuf,put_membuf,get_membuf): Apply a + hidden 0 behind the buffer so that the buffer can be used as a + string in certain contexts. + +2001-12-14 Marcus Brinkmann + + * assuan-connect.c (assuan_pipe_connect): New argument + FD_CHILD_LIST. Don't close those fds. + * assuan.h: Likewise for prototype. + +2001-12-14 Werner Koch + + * assuan-listen.c (assuan_close_input_fd): New. + (assuan_close_output_fd): New. + * assuan-handler.c (std_handler_reset): Always close them after a + reset command. + (std_handler_bye): Likewise. + +2001-12-14 Marcus Brinkmann + + * assuan-buffer.c (_assuan_read_line): New variable ATTICLEN, use + it to save the length of the attic line. + Rediddle the code a bit to make it more clear what happens. + +2001-12-14 Marcus Brinkmann + + * assuan-defs.h (LINELENGTH): Define as ASSUAN_LINELENGTH. + assuan.h: Define ASSUAN_LINELENGTH. + +2001-12-13 Marcus Brinkmann + + * assuan-buffer.c (assuan_read_line): Fix order of execution to + get correct return values. + +2001-12-13 Werner Koch + + * assuan-handler.c (assuan_get_active_fds): Fixed silly bug, + pretty obvious that nobody ever tested this function. + +2001-12-12 Werner Koch + + * assuan-connect.c (assuan_pipe_connect): Implemented the inital + handshake. + * assuan-client.c (read_from_server): Renamed to + (_assuan_read_from_server): this and made external. + + * assuan-listen.c (assuan_set_hello_line): New. + (assuan_accept): Use a custom hello line is available. + + * assuan-buffer.c (assuan_read_line): New. + (assuan_pending_line): New. + (_assuan_write_line): Renamed to .. + (assuan_write_line): this, made public and changed all callers. + +2001-12-04 Werner Koch + + * assuan-connect.c (assuan_pipe_connect): Add more error reporting. + * assuan-client.c: New. + + * assuan-inquire.c: New. + * assuan-handler.c (process_request): Check for nested invocations. + +2001-11-27 Werner Koch + + * assuan-handler.c (assuan_register_input_notify): New. + (assuan_register_output_notify): New. + +2001-11-26 Werner Koch + + * assuan.h: Added more status codes. + +2001-11-25 Werner Koch + + * assuan-handler.c (assuan_register_bye_notify) + (assuan_register_reset_notify) + (assuan_register_cancel_notify): New and call them from the + standard handlers. + (assuan_process): Moved bulk of function to .. + (process_request): .. new. + (assuan_process_next): One shot version of above. + (assuan_get_active_fds): New. + +2001-11-24 Werner Koch + + * assuan-connect.c (assuan_get_pid): New. + + * assuan-buffer.c (_assuan_read_line): Deal with reads of more + than a line. + * assuan-defs.h: Add space in the context for this. + + + *********************************************************** + * Please note that Assuan is maintained as part of GnuPG. * + * You may find it source-copied in other packages. * + *********************************************************** + + Copyright 2001, 2002 Free Software Foundation, Inc. + + This file is free software; as a special exception the author gives + unlimited permission to copy and/or distribute it, with or without + modifications, as long as this notice is preserved. + + This file is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, to the extent permitted by law; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/tags/V0-3-4/assuan/Makefile.am b/tags/V0-3-4/assuan/Makefile.am new file mode 100644 index 0000000..10be173 --- /dev/null +++ b/tags/V0-3-4/assuan/Makefile.am @@ -0,0 +1,49 @@ +# Assuan Makefile for test purposes +# Copyright (C) 2001 Free Software Foundation, Inc. +# +# This file is part of GnuPG. +# +# GnuPG is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# GnuPG is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +## Process this file with automake to produce Makefile.in + +EXTRA_DIST = mkerrors +INCLUDES = -I.. -I$(top_srcdir)/include +BUILT_SOURCES = assuan-errors.c +MOSTLYCLEANFILES = assuan-errors.c + +noinst_LIBRARIES = libassuan.a + + +#libassuan_a_LDFLAGS = +libassuan_a_SOURCES = \ + assuan.h \ + assuan-defs.h \ + assuan-util.c \ + assuan-errors.c \ + assuan-buffer.c \ + assuan-handler.c \ + assuan-inquire.c \ + assuan-listen.c \ + assuan-connect.c \ + assuan-client.c \ + assuan-pipe-server.c \ + assuan-socket-server.c \ + assuan-pipe-connect.c \ + assuan-socket-connect.c + + +assuan-errors.c : assuan.h + $(srcdir)/mkerrors < $(srcdir)/assuan.h > assuan-errors.c diff --git a/tags/V0-3-4/assuan/README.1st b/tags/V0-3-4/assuan/README.1st new file mode 100644 index 0000000..bb52959 --- /dev/null +++ b/tags/V0-3-4/assuan/README.1st @@ -0,0 +1 @@ +Please don't modify it here but in the copy which comes with GnuPG. \ No newline at end of file diff --git a/tags/V0-3-4/assuan/assuan-buffer.c b/tags/V0-3-4/assuan/assuan-buffer.c new file mode 100644 index 0000000..bd08817 --- /dev/null +++ b/tags/V0-3-4/assuan/assuan-buffer.c @@ -0,0 +1,416 @@ +/* assuan-buffer.c - read and send data + * Copyright (C) 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "assuan-defs.h" + + +static int +writen ( int fd, const char *buffer, size_t length ) +{ + while (length) + { + int nwritten = write (fd, buffer, length); + + if (nwritten < 0) + { + if (errno == EINTR) + continue; + return -1; /* write error */ + } + length -= nwritten; + buffer += nwritten; + } + return 0; /* okay */ +} + +/* read an entire line */ +static int +readline (int fd, char *buf, size_t buflen, int *r_nread, int *eof) +{ + size_t nleft = buflen; + char *p; + + *eof = 0; + *r_nread = 0; + while (nleft > 0) + { + int n = read (fd, buf, nleft); + if (n < 0) + { + if (errno == EINTR) + continue; + return -1; /* read error */ + } + else if (!n) + { + *eof = 1; + break; /* allow incomplete lines */ + } + p = buf; + nleft -= n; + buf += n; + *r_nread += n; + + for (; n && *p != '\n'; n--, p++) + ; + if (n) + break; /* at least one full line available - that's enough for now */ + } + + return 0; +} + + +int +_assuan_read_line (ASSUAN_CONTEXT ctx) +{ + char *line = ctx->inbound.line; + int n, nread, atticlen; + int rc; + + if (ctx->inbound.eof) + return -1; + + atticlen = ctx->inbound.attic.linelen; + if (atticlen) + { + memcpy (line, ctx->inbound.attic.line, atticlen); + ctx->inbound.attic.linelen = 0; + for (n=0; n < atticlen && line[n] != '\n'; n++) + ; + if (n < atticlen) + { + rc = 0; /* found another line in the attic */ + nread = atticlen; + atticlen = 0; + } + else + { /* read the rest */ + assert (atticlen < LINELENGTH); + rc = readline (ctx->inbound.fd, line + atticlen, + LINELENGTH - atticlen, &nread, &ctx->inbound.eof); + } + } + else + rc = readline (ctx->inbound.fd, line, LINELENGTH, + &nread, &ctx->inbound.eof); + if (rc) + { + if (ctx->log_fp) + fprintf (ctx->log_fp, "%p <- [Error: %s]\n", + ctx, strerror (errno)); + return ASSUAN_Read_Error; + } + if (!nread) + { + assert (ctx->inbound.eof); + if (ctx->log_fp) + fprintf (ctx->log_fp, "%p <- [EOF]\n", ctx); + return -1; + } + + ctx->inbound.attic.pending = 0; + nread += atticlen; + for (n=0; n < nread; n++) + { + if (line[n] == '\n') + { + if (n+1 < nread) + { + char *s, *d; + int i; + + n++; + /* we have to copy the rest because the handlers are + allowed to modify the passed buffer */ + for (d=ctx->inbound.attic.line, s=line+n, i=nread-n; i; i--) + { + if (*s=='\n') + ctx->inbound.attic.pending = 1; + *d++ = *s++; + } + ctx->inbound.attic.linelen = nread-n; + n--; + } + if (n && line[n-1] == '\r') + n--; + line[n] = 0; + ctx->inbound.linelen = n; + if (ctx->log_fp) + { + fprintf (ctx->log_fp, "%p <- ", ctx); + if (ctx->confidential) + fputs ("[Confidential data not shown]", ctx->log_fp); + else + _assuan_log_print_buffer (ctx->log_fp, + ctx->inbound.line, + ctx->inbound.linelen); + putc ('\n', ctx->log_fp); + } + return 0; + } + } + + if (ctx->log_fp) + fprintf (ctx->log_fp, "%p <- [Invalid line]\n", ctx); + *line = 0; + ctx->inbound.linelen = 0; + return ctx->inbound.eof? ASSUAN_Line_Not_Terminated : ASSUAN_Line_Too_Long; +} + + +/* Read the next line from the client or server and return a pointer + to a buffer with holding that line. linelen returns the length of + the line. This buffer is valid until another read operation is + done on this buffer. The caller is allowed to modify this buffer. + He should only use the buffer if the function returns without an + error. + + Returns: 0 on success or an assuan error code + See also: assuan_pending_line(). +*/ +AssuanError +assuan_read_line (ASSUAN_CONTEXT ctx, char **line, size_t *linelen) +{ + AssuanError err; + + if (!ctx) + return ASSUAN_Invalid_Value; + + err = _assuan_read_line (ctx); + *line = ctx->inbound.line; + *linelen = ctx->inbound.linelen; + return err; +} + + +/* Return true when a full line is pending for a read, without the need + for actual IO */ +int +assuan_pending_line (ASSUAN_CONTEXT ctx) +{ + return ctx && ctx->inbound.attic.pending; +} + + +AssuanError +assuan_write_line (ASSUAN_CONTEXT ctx, const char *line ) +{ + int rc; + + if (!ctx) + return ASSUAN_Invalid_Value; + + /* fixme: we should do some kind of line buffering */ + if (ctx->log_fp) + { + fprintf (ctx->log_fp, "%p -> ", ctx); + if (ctx->confidential) + fputs ("[Confidential data not shown]", ctx->log_fp); + else + _assuan_log_print_buffer (ctx->log_fp, + line, strlen (line)); + putc ('\n', ctx->log_fp); + } + + rc = writen (ctx->outbound.fd, line, strlen(line)); + if (rc) + rc = ASSUAN_Write_Error; + if (!rc) + { + rc = writen (ctx->outbound.fd, "\n", 1); + if (rc) + rc = ASSUAN_Write_Error; + } + + return rc; +} + + + +/* Write out the data in buffer as datalines with line wrapping and + percent escaping. This fucntion is used for GNU's custom streams */ +int +_assuan_cookie_write_data (void *cookie, const char *buffer, size_t size) +{ + ASSUAN_CONTEXT ctx = cookie; + char *line; + size_t linelen; + + if (ctx->outbound.data.error) + return 0; + + line = ctx->outbound.data.line; + linelen = ctx->outbound.data.linelen; + line += linelen; + while (size) + { + /* insert data line header */ + if (!linelen) + { + *line++ = 'D'; + *line++ = ' '; + linelen += 2; + } + + /* copy data, keep some space for the CRLF and to escape one character */ + while (size && linelen < LINELENGTH-2-2) + { + if (*buffer == '%' || *buffer == '\r' || *buffer == '\n') + { + sprintf (line, "%%%02X", *(unsigned char*)buffer); + line += 3; + linelen += 3; + buffer++; + } + else + { + *line++ = *buffer++; + linelen++; + } + size--; + } + + if (linelen >= LINELENGTH-2-2) + { + if (ctx->log_fp) + { + fprintf (ctx->log_fp, "%p -> ", ctx); + if (ctx->confidential) + fputs ("[Confidential data not shown]", ctx->log_fp); + else + _assuan_log_print_buffer (ctx->log_fp, + ctx->outbound.data.line, + linelen); + putc ('\n', ctx->log_fp); + } + *line++ = '\n'; + linelen++; + if (writen (ctx->outbound.fd, ctx->outbound.data.line, linelen)) + { + ctx->outbound.data.error = ASSUAN_Write_Error; + return 0; + } + line = ctx->outbound.data.line; + linelen = 0; + } + } + + ctx->outbound.data.linelen = linelen; + return 0; +} + + +/* Write out any buffered data + This fucntion is used for GNU's custom streams */ +int +_assuan_cookie_write_flush (void *cookie) +{ + ASSUAN_CONTEXT ctx = cookie; + char *line; + size_t linelen; + + if (ctx->outbound.data.error) + return 0; + + line = ctx->outbound.data.line; + linelen = ctx->outbound.data.linelen; + line += linelen; + if (linelen) + { + if (ctx->log_fp) + { + fprintf (ctx->log_fp, "%p -> ", ctx); + if (ctx->confidential) + fputs ("[Confidential data not shown]", ctx->log_fp); + else + _assuan_log_print_buffer (ctx->log_fp, + ctx->outbound.data.line, + linelen); + putc ('\n', ctx->log_fp); + } + *line++ = '\n'; + linelen++; + if (writen (ctx->outbound.fd, ctx->outbound.data.line, linelen)) + { + ctx->outbound.data.error = ASSUAN_Write_Error; + return 0; + } + ctx->outbound.data.linelen = 0; + } + return 0; +} + + +/** + * assuan_send_data: + * @ctx: An assuan context + * @buffer: Data to send or NULL to flush + * @length: length of the data to send/ + * + * This function may be used by the server or the client to send data + * lines. The data will be escaped as required by the Assuan protocol + * and may get buffered until a line is full. To force sending the + * data out @buffer may be passed as NULL (in which case @length must + * also be 0); however when used by a client this flush operation does + * also send the terminating "END" command to terminate the reponse on + * a INQUIRE response. However, when assuan_transact() is used, this + * function takes care of sending END itself. + * + * Return value: 0 on success or an error code + **/ + +AssuanError +assuan_send_data (ASSUAN_CONTEXT ctx, const void *buffer, size_t length) +{ + if (!ctx) + return ASSUAN_Invalid_Value; + if (!buffer && length) + return ASSUAN_Invalid_Value; + + if (!buffer) + { /* flush what we have */ + _assuan_cookie_write_flush (ctx); + if (ctx->outbound.data.error) + return ctx->outbound.data.error; + if (!ctx->is_server) + return assuan_write_line (ctx, "END"); + } + else + { + _assuan_cookie_write_data (ctx, buffer, length); + if (ctx->outbound.data.error) + return ctx->outbound.data.error; + } + + return 0; +} + + + + diff --git a/tags/V0-3-4/assuan/assuan-client.c b/tags/V0-3-4/assuan/assuan-client.c new file mode 100644 index 0000000..d56357d --- /dev/null +++ b/tags/V0-3-4/assuan/assuan-client.c @@ -0,0 +1,186 @@ +/* assuan-client.c - client functions + * Copyright (C) 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include + +#include "assuan-defs.h" + +#define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \ + *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10)) +#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1)) + + +AssuanError +_assuan_read_from_server (ASSUAN_CONTEXT ctx, int *okay, int *off) +{ + char *line; + int linelen; + AssuanError rc; + + *okay = 0; + *off = 0; + do + { + rc = _assuan_read_line (ctx); + if (rc) + return rc; + line = ctx->inbound.line; + linelen = ctx->inbound.linelen; + } + while (*line == '#' || !linelen); + + if (linelen >= 1 + && line[0] == 'D' && line[1] == ' ') + { + *okay = 2; /* data line */ + *off = 2; + } + else if (linelen >= 2 + && line[0] == 'O' && line[1] == 'K' + && (line[2] == '\0' || line[2] == ' ')) + { + *okay = 1; + *off = 2; + while (line[*off] == ' ') + ++*off; + } + else if (linelen >= 3 + && line[0] == 'E' && line[1] == 'R' && line[2] == 'R' + && (line[3] == '\0' || line[3] == ' ')) + { + *okay = 0; + *off = 3; + while (line[*off] == ' ') + ++*off; + } + else if (linelen >= 7 + && line[0] == 'I' && line[1] == 'N' && line[2] == 'Q' + && line[3] == 'U' && line[4] == 'I' && line[5] == 'R' + && line[6] == 'E' + && (line[7] == '\0' || line[7] == ' ')) + { + *okay = 3; + *off = 7; + while (line[*off] == ' ') + ++*off; + } + else + rc = ASSUAN_Invalid_Response; + return rc; +} + + + +/** + * assuan_transact: + * @ctx: The Assuan context + * @command: Coimmand line to be send to server + * @data_cb: Callback function for data lines + * @data_cb_arg: first argument passed to @data_cb + * @inquire_cb: Callback function for a inquire response + * @inquire_cb_arg: first argument passed to @inquire_cb + * + * FIXME: Write documentation + * + * Return value: 0 on success or error code. The error code may be + * the one one returned by the server in error lines or from the + * callback functions. + **/ +AssuanError +assuan_transact (ASSUAN_CONTEXT ctx, + const char *command, + AssuanError (*data_cb)(void *, const void *, size_t), + void *data_cb_arg, + AssuanError (*inquire_cb)(void*, const char *), + void *inquire_cb_arg) +{ + int rc, okay, off; + unsigned char *line; + int linelen; + + rc = assuan_write_line (ctx, command); + if (rc) + return rc; + + again: + rc = _assuan_read_from_server (ctx, &okay, &off); + if (rc) + return rc; /* error reading from server */ + + line = ctx->inbound.line + off; + linelen = ctx->inbound.linelen - off; + + if (!okay) + { + rc = atoi (line); + if (rc < 100) + rc = ASSUAN_Server_Fault; + } + else if (okay == 2) + { + if (!data_cb) + rc = ASSUAN_No_Data_Callback; + else + { + unsigned char *s, *d; + + for (s=d=line; linelen; linelen--) + { + if (*s == '%' && linelen > 2) + { /* handle escaping */ + s++; + *d++ = xtoi_2 (s); + s += 2; + linelen -= 2; + } + else + *d++ = *s++; + } + *d = 0; /* add a hidden string terminator */ + rc = data_cb (data_cb_arg, line, d - line); + if (!rc) + goto again; + } + } + else if (okay == 3) + { + if (!inquire_cb) + { + assuan_write_line (ctx, "END"); /* get out of inquire mode */ + _assuan_read_from_server (ctx, &okay, &off); /* dummy read */ + rc = ASSUAN_No_Inquire_Callback; + } + else + { + rc = inquire_cb (inquire_cb_arg, line); + if (!rc) + rc = assuan_send_data (ctx, NULL, 0); /* flush and send END */ + if (!rc) + goto again; + } + } + + return rc; +} diff --git a/tags/V0-3-4/assuan/assuan-connect.c b/tags/V0-3-4/assuan/assuan-connect.c new file mode 100644 index 0000000..49d4aac --- /dev/null +++ b/tags/V0-3-4/assuan/assuan-connect.c @@ -0,0 +1,54 @@ +/* assuan-connect.c - Establish a connection (client) + * Copyright (C) 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "assuan-defs.h" + +/* Disconnect and release the context CTX. */ +void +assuan_disconnect (ASSUAN_CONTEXT ctx) +{ + if (ctx) + { + assuan_write_line (ctx, "BYE"); + ctx->finish_handler (ctx); + ctx->deinit_handler (ctx); + ctx->deinit_handler = NULL; + _assuan_release_context (ctx); + } +} + +pid_t +assuan_get_pid (ASSUAN_CONTEXT ctx) +{ + return ctx ? ctx->pid : -1; +} diff --git a/tags/V0-3-4/assuan/assuan-defs.h b/tags/V0-3-4/assuan/assuan-defs.h new file mode 100644 index 0000000..7d55aab --- /dev/null +++ b/tags/V0-3-4/assuan/assuan-defs.h @@ -0,0 +1,143 @@ +/* assuan-defs.c - Internal definitions to Assuan + * Copyright (C) 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef ASSUAN_DEFS_H +#define ASSUAN_DEFS_H + +#include +#include "assuan.h" + +#define LINELENGTH ASSUAN_LINELENGTH + +struct cmdtbl_s { + const char *name; + int cmd_id; + int (*handler)(ASSUAN_CONTEXT, char *line); +}; + +struct assuan_context_s { + AssuanError err_no; + const char *err_str; + int os_errno; /* last system error number used with certain error codes*/ + + int confidential; + int is_server; /* set if this is context belongs to a server */ + int in_inquire; + char *hello_line; + char *okay_line; /* see assan_set_okay_line() */ + + void *user_pointer; /* for assuan_[gs]et_pointer () */ + + FILE *log_fp; + + struct { + int fd; + int eof; + char line[LINELENGTH]; + int linelen; /* w/o CR, LF - might not be the same as + strlen(line) due to embedded nuls. However a nul + is always written at this pos */ + struct { + char line[LINELENGTH]; + int linelen ; + int pending; /* i.e. at least one line is available in the attic */ + } attic; + } inbound; + + struct { + int fd; + struct { + FILE *fp; + char line[LINELENGTH]; + int linelen; + int error; + } data; + } outbound; + + int pipe_mode; /* We are in pipe mode, i.e. we can handle just one + connection and must terminate then */ + pid_t pid; /* In pipe mode, the pid of the child server process. + In socket mode, the pid of the server */ + int listen_fd; /* The fd we are listening on (used by socket servers) */ + + void (*deinit_handler)(ASSUAN_CONTEXT); + int (*accept_handler)(ASSUAN_CONTEXT); + int (*finish_handler)(ASSUAN_CONTEXT); + + struct cmdtbl_s *cmdtbl; + size_t cmdtbl_used; /* used entries */ + size_t cmdtbl_size; /* allocated size of table */ + + void (*bye_notify_fnc)(ASSUAN_CONTEXT); + void (*reset_notify_fnc)(ASSUAN_CONTEXT); + void (*cancel_notify_fnc)(ASSUAN_CONTEXT); + int (*option_handler_fnc)(ASSUAN_CONTEXT,const char*, const char*); + void (*input_notify_fnc)(ASSUAN_CONTEXT, const char *); + void (*output_notify_fnc)(ASSUAN_CONTEXT, const char *); + + + int input_fd; /* set by INPUT command */ + int output_fd; /* set by OUTPUT command */ + +}; + + +/*-- assuan-pipe-server.c --*/ +int _assuan_new_context (ASSUAN_CONTEXT *r_ctx); +void _assuan_release_context (ASSUAN_CONTEXT ctx); + + +/*-- assuan-handler.c --*/ +int _assuan_register_std_commands (ASSUAN_CONTEXT ctx); + +/*-- assuan-buffer.c --*/ +int _assuan_read_line (ASSUAN_CONTEXT ctx); +int _assuan_cookie_write_data (void *cookie, const char *buffer, size_t size); +int _assuan_cookie_write_flush (void *cookie); + +/*-- assuan-client.c --*/ +AssuanError _assuan_read_from_server (ASSUAN_CONTEXT ctx, int *okay, int *off); + + +/*-- assuan-util.c --*/ +void *_assuan_malloc (size_t n); +void *_assuan_calloc (size_t n, size_t m); +void *_assuan_realloc (void *p, size_t n); +void _assuan_free (void *p); + +#define xtrymalloc(a) _assuan_malloc ((a)) +#define xtrycalloc(a,b) _assuan_calloc ((a),(b)) +#define xtryrealloc(a,b) _assuan_realloc((a),(b)) +#define xfree(a) _assuan_free ((a)) + +#define set_error(c,e,t) assuan_set_error ((c), ASSUAN_ ## e, (t)) + +void _assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length); +void _assuan_log_sanitized_string (const char *string); + + +#endif /*ASSUAN_DEFS_H*/ + + + + + + + diff --git a/tags/V0-3-4/assuan/assuan-handler.c b/tags/V0-3-4/assuan/assuan-handler.c new file mode 100644 index 0000000..1c8aded --- /dev/null +++ b/tags/V0-3-4/assuan/assuan-handler.c @@ -0,0 +1,682 @@ +/* assuan-handler.c - dispatch commands + * Copyright (C) 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include "assuan-defs.h" + +#define spacep(p) (*(p) == ' ' || *(p) == '\t') +#define digitp(a) ((a) >= '0' && (a) <= '9') + + +static int +dummy_handler (ASSUAN_CONTEXT ctx, char *line) +{ + return set_error (ctx, Server_Fault, "no handler registered"); +} + + +static int +std_handler_nop (ASSUAN_CONTEXT ctx, char *line) +{ + return 0; /* okay */ +} + +static int +std_handler_cancel (ASSUAN_CONTEXT ctx, char *line) +{ + if (ctx->cancel_notify_fnc) + ctx->cancel_notify_fnc (ctx); + return set_error (ctx, Not_Implemented, NULL); +} + +static int +std_handler_option (ASSUAN_CONTEXT ctx, char *line) +{ + char *key, *value, *p; + + for (key=line; spacep (key); key++) + ; + if (!*key) + return set_error (ctx, Syntax_Error, "argument required"); + if (*key == '=') + return set_error (ctx, Syntax_Error, "no option name given"); + for (value=key; *value && !spacep (value) && *value != '='; value++) + ; + if (*value) + { + if (spacep (value)) + *value++ = 0; /* terminate key */ + for (; spacep (value); value++) + ; + if (*value == '=') + { + *value++ = 0; /* terminate key */ + for (; spacep (value); value++) + ; + if (!*value) + return set_error (ctx, Syntax_Error, "option argument expected"); + } + if (*value) + { + for (p = value + strlen(value) - 1; p > value && spacep (p); p--) + ; + if (p > value) + *++p = 0; /* strip trailing spaces */ + } + } + + if (*key == '-' && key[1] == '-' && key[2]) + key += 2; /* the double dashes are optional */ + if (*key == '-') + return set_error (ctx, Syntax_Error, + "option should not begin with one dash"); + + if (ctx->option_handler_fnc) + return ctx->option_handler_fnc (ctx, key, value); + return 0; +} + +static int +std_handler_bye (ASSUAN_CONTEXT ctx, char *line) +{ + if (ctx->bye_notify_fnc) + ctx->bye_notify_fnc (ctx); + assuan_close_input_fd (ctx); + assuan_close_output_fd (ctx); + return -1; /* pretty simple :-) */ +} + +static int +std_handler_auth (ASSUAN_CONTEXT ctx, char *line) +{ + return set_error (ctx, Not_Implemented, NULL); +} + +static int +std_handler_reset (ASSUAN_CONTEXT ctx, char *line) +{ + if (ctx->reset_notify_fnc) + ctx->reset_notify_fnc (ctx); + assuan_close_input_fd (ctx); + assuan_close_output_fd (ctx); + return 0; +} + +static int +std_handler_end (ASSUAN_CONTEXT ctx, char *line) +{ + return set_error (ctx, Not_Implemented, NULL); +} + +static int +parse_cmd_input_output (ASSUAN_CONTEXT ctx, char *line, int *rfd) +{ + char *endp; + + if (strncmp (line, "FD=", 3)) + return set_error (ctx, Syntax_Error, "FD= expected"); + line += 3; + if (!digitp (*line)) + return set_error (ctx, Syntax_Error, "number required"); + *rfd = strtoul (line, &endp, 10); + /* remove that argument so that a notify handler won't see it */ + memset (line, ' ', endp? (endp-line):strlen(line)); + + if (*rfd == ctx->inbound.fd) + return set_error (ctx, Parameter_Conflict, "fd same as inbound fd"); + if (*rfd == ctx->outbound.fd) + return set_error (ctx, Parameter_Conflict, "fd same as outbound fd"); + return 0; +} + +/* Format is INPUT FD= */ +static int +std_handler_input (ASSUAN_CONTEXT ctx, char *line) +{ + int rc, fd; + + rc = parse_cmd_input_output (ctx, line, &fd); + if (rc) + return rc; + ctx->input_fd = fd; + if (ctx->input_notify_fnc) + ctx->input_notify_fnc (ctx, line); + return 0; +} + +/* Format is OUTPUT FD= */ +static int +std_handler_output (ASSUAN_CONTEXT ctx, char *line) +{ + int rc, fd; + + rc = parse_cmd_input_output (ctx, line, &fd); + if (rc) + return rc; + ctx->output_fd = fd; + if (ctx->output_notify_fnc) + ctx->output_notify_fnc (ctx, line); + return 0; +} + + + + + +/* This is a table with the standard commands and handler for them. + The table is used to initialize a new context and assuciate strings + and handlers with cmd_ids */ +static struct { + const char *name; + int cmd_id; + int (*handler)(ASSUAN_CONTEXT, char *line); + int always; /* always initialize this command */ +} std_cmd_table[] = { + { "NOP", ASSUAN_CMD_NOP, std_handler_nop, 1 }, + { "CANCEL", ASSUAN_CMD_CANCEL, std_handler_cancel, 1 }, + { "OPTION", ASSUAN_CMD_OPTION, std_handler_option, 1 }, + { "BYE", ASSUAN_CMD_BYE, std_handler_bye, 1 }, + { "AUTH", ASSUAN_CMD_AUTH, std_handler_auth, 1 }, + { "RESET", ASSUAN_CMD_RESET, std_handler_reset, 1 }, + { "END", ASSUAN_CMD_END, std_handler_end, 1 }, + + { "INPUT", ASSUAN_CMD_INPUT, std_handler_input }, + { "OUTPUT", ASSUAN_CMD_OUTPUT, std_handler_output }, + { "OPTION", ASSUAN_CMD_OPTION, std_handler_option, 1 }, + { NULL } +}; + + +/** + * assuan_register_command: + * @ctx: the server context + * @cmd_id: An ID value for the command + * @cmd_name: A string with the command name + * @handler: The handler function to be called + * + * Register a handler to be used for a given command. + * + * The @cmd_name must be %NULL or an empty string for all @cmd_ids + * below %ASSUAN_CMD_USER because predefined values are used. + * + * Return value: + **/ +int +assuan_register_command (ASSUAN_CONTEXT ctx, + int cmd_id, const char *cmd_name, + int (*handler)(ASSUAN_CONTEXT, char *)) +{ + int i; + + if (cmd_name && !*cmd_name) + cmd_name = NULL; + + if (cmd_id < ASSUAN_CMD_USER) + { + if (cmd_name) + return ASSUAN_Invalid_Value; /* must be NULL for these values*/ + + for (i=0; std_cmd_table[i].name; i++) + { + if (std_cmd_table[i].cmd_id == cmd_id) + { + cmd_name = std_cmd_table[i].name; + if (!handler) + handler = std_cmd_table[i].handler; + break; + } + } + if (!std_cmd_table[i].name) + return ASSUAN_Invalid_Value; /* not a pre-registered one */ + } + + if (!handler) + handler = dummy_handler; + + if (!cmd_name) + return ASSUAN_Invalid_Value; + +/* fprintf (stderr, "DBG-assuan: registering %d as `%s'\n", cmd_id, cmd_name); */ + + if (!ctx->cmdtbl) + { + ctx->cmdtbl_size = 50; + ctx->cmdtbl = xtrycalloc ( ctx->cmdtbl_size, sizeof *ctx->cmdtbl); + if (!ctx->cmdtbl) + return ASSUAN_Out_Of_Core; + ctx->cmdtbl_used = 0; + } + else if (ctx->cmdtbl_used >= ctx->cmdtbl_size) + { + struct cmdtbl_s *x; + + x = xtryrealloc ( ctx->cmdtbl, (ctx->cmdtbl_size+10) * sizeof *x); + if (!x) + return ASSUAN_Out_Of_Core; + ctx->cmdtbl = x; + ctx->cmdtbl_size += 50; + } + + ctx->cmdtbl[ctx->cmdtbl_used].name = cmd_name; + ctx->cmdtbl[ctx->cmdtbl_used].cmd_id = cmd_id; + ctx->cmdtbl[ctx->cmdtbl_used].handler = handler; + ctx->cmdtbl_used++; + return 0; +} + +int +assuan_register_bye_notify (ASSUAN_CONTEXT ctx, void (*fnc)(ASSUAN_CONTEXT)) +{ + if (!ctx) + return ASSUAN_Invalid_Value; + ctx->bye_notify_fnc = fnc; + return 0; +} + +int +assuan_register_reset_notify (ASSUAN_CONTEXT ctx, void (*fnc)(ASSUAN_CONTEXT)) +{ + if (!ctx) + return ASSUAN_Invalid_Value; + ctx->reset_notify_fnc = fnc; + return 0; +} + +int +assuan_register_cancel_notify (ASSUAN_CONTEXT ctx, void (*fnc)(ASSUAN_CONTEXT)) +{ + if (!ctx) + return ASSUAN_Invalid_Value; + ctx->cancel_notify_fnc = fnc; + return 0; +} + +int +assuan_register_option_handler (ASSUAN_CONTEXT ctx, + int (*fnc)(ASSUAN_CONTEXT, + const char*, const char*)) +{ + if (!ctx) + return ASSUAN_Invalid_Value; + ctx->option_handler_fnc = fnc; + return 0; +} + +int +assuan_register_input_notify (ASSUAN_CONTEXT ctx, + void (*fnc)(ASSUAN_CONTEXT, const char *)) +{ + if (!ctx) + return ASSUAN_Invalid_Value; + ctx->input_notify_fnc = fnc; + return 0; +} + +int +assuan_register_output_notify (ASSUAN_CONTEXT ctx, + void (*fnc)(ASSUAN_CONTEXT, const char *)) +{ + if (!ctx) + return ASSUAN_Invalid_Value; + ctx->output_notify_fnc = fnc; + return 0; +} + + +/* Helper to register the standards commands */ +int +_assuan_register_std_commands (ASSUAN_CONTEXT ctx) +{ + int i, rc; + + for (i=0; std_cmd_table[i].name; i++) + { + if (std_cmd_table[i].always) + { + rc = assuan_register_command (ctx, std_cmd_table[i].cmd_id, + NULL, NULL); + if (rc) + return rc; + } + } + return 0; +} + + + +/* Process the special data lines. The "D " has already been removed + from the line. As all handlers this function may modify the line. */ +static int +handle_data_line (ASSUAN_CONTEXT ctx, char *line, int linelen) +{ + return set_error (ctx, Not_Implemented, NULL); +} + +/* like ascii_strcasecmp but assume that B is already uppercase */ +static int +my_strcasecmp (const char *a, const char *b) +{ + if (a == b) + return 0; + + for (; *a && *b; a++, b++) + { + if (((*a >= 'a' && *a <= 'z')? (*a&~0x20):*a) != *b) + break; + } + return *a == *b? 0 : (((*a >= 'a' && *a <= 'z')? (*a&~0x20):*a) - *b); +} + +/* Parse the line, break out the command, find it in the command + table, remove leading and white spaces from the arguments, all the + handler with the argument line and return the error */ +static int +dispatch_command (ASSUAN_CONTEXT ctx, char *line, int linelen) +{ + char *p; + const char *s; + int shift, i; + + if (*line == 'D' && line[1] == ' ') /* divert to special handler */ + return handle_data_line (ctx, line+2, linelen-2); + + for (p=line; *p && *p != ' ' && *p != '\t'; p++) + ; + if (p==line) + return set_error (ctx, Invalid_Command, "leading white-space"); + if (*p) + { /* Skip over leading WS after the keyword */ + *p++ = 0; + while ( *p == ' ' || *p == '\t') + p++; + } + shift = p - line; + + for (i=0; (s=ctx->cmdtbl[i].name); i++) + { + if (!strcmp (line, s)) + break; + } + if (!s) + { /* and try case insensitive */ + for (i=0; (s=ctx->cmdtbl[i].name); i++) + { + if (!my_strcasecmp (line, s)) + break; + } + } + if (!s) + return set_error (ctx, Unknown_Command, NULL); + line += shift; + linelen -= shift; + +/* fprintf (stderr, "DBG-assuan: processing %s `%s'\n", s, line); */ + return ctx->cmdtbl[i].handler (ctx, line); +} + + + + +static int +process_request (ASSUAN_CONTEXT ctx) +{ + int rc; + + if (ctx->in_inquire) + return ASSUAN_Nested_Commands; + + rc = _assuan_read_line (ctx); + if (rc) + return rc; + if (*ctx->inbound.line == '#' || !ctx->inbound.linelen) + return 0; /* comment line - ignore */ + + ctx->outbound.data.error = 0; + ctx->outbound.data.linelen = 0; + /* dispatch command and return reply */ + rc = dispatch_command (ctx, ctx->inbound.line, ctx->inbound.linelen); + /* check from data write errors */ + if (ctx->outbound.data.fp) + { /* Flush the data lines */ + fclose (ctx->outbound.data.fp); + ctx->outbound.data.fp = NULL; + if (!rc && ctx->outbound.data.error) + rc = ctx->outbound.data.error; + } + /* Error handling */ + if (!rc) + { + rc = assuan_write_line (ctx, ctx->okay_line? ctx->okay_line : "OK"); + } + else if (rc == -1) + { /* No error checking because the peer may have already disconnect */ + assuan_write_line (ctx, "OK closing connection"); + ctx->finish_handler (ctx); + } + else + { + char errline[256]; + + if (rc < 100) + sprintf (errline, "ERR %d server fault (%.50s)", + ASSUAN_Server_Fault, assuan_strerror (rc)); + else + { + const char *text = ctx->err_no == rc? ctx->err_str:NULL; + + sprintf (errline, "ERR %d %.50s%s%.100s", + rc, assuan_strerror (rc), text? " - ":"", text?text:""); + } + rc = assuan_write_line (ctx, errline); + } + + ctx->confidential = 0; + if (ctx->okay_line) + { + xfree (ctx->okay_line); + ctx->okay_line = NULL; + } + return rc; +} + +/** + * assuan_process: + * @ctx: assuan context + * + * This fucntion is used to handle the assuan protocol after a + * connection has been established using assuan_accept(). This is the + * main protocol handler. + * + * Return value: 0 on success or an error code if the assuan operation + * failed. Note, that no error is returned for operational errors. + **/ +int +assuan_process (ASSUAN_CONTEXT ctx) +{ + int rc; + + do { + rc = process_request (ctx); + } while (!rc); + + if (rc == -1) + rc = 0; + + return rc; +} + + +/** + * assuan_process_next: + * @ctx: Assuan context + * + * Same as assuan_process() but the user has to provide the outer + * loop. He should loop as long as the return code is zero and stop + * otherwise; -1 is regular end. + * + * See also: assuan_get_active_fds() + * Return value: -1 for end of server, 0 on success or an error code + **/ +int +assuan_process_next (ASSUAN_CONTEXT ctx) +{ + return process_request (ctx); +} + + +/** + * assuan_get_active_fds: + * @ctx: Assuan context + * @what: 0 for read fds, 1 for write fds + * @fdarray: Caller supplied array to store the FDs + * @fdarraysize: size of that array + * + * Return all active filedescriptors for the given context. This + * function can be used to select on the fds and call + * assuan_process_next() if there is an active one. The first fd in + * the array is the one used for the command connection. + * + * Note, that write FDs are not yet supported. + * + * Return value: number of FDs active and put into @fdarray or -1 on + * error which is most likely a too small fdarray. + **/ +int +assuan_get_active_fds (ASSUAN_CONTEXT ctx, int what, + int *fdarray, int fdarraysize) +{ + int n = 0; + + if (!ctx || fdarraysize < 2 || what < 0 || what > 1) + return -1; + + if (!what) + { + if (ctx->inbound.fd != -1) + fdarray[n++] = ctx->inbound.fd; + } + else + { + if (ctx->outbound.fd != -1) + fdarray[n++] = ctx->outbound.fd; + if (ctx->outbound.data.fp) + fdarray[n++] = fileno (ctx->outbound.data.fp); + } + + return n; +} + +/* Return a FP to be used for data output. The FILE pointer is valid + until the end of a handler. So a close is not needed. Assuan does + all the buffering needed to insert the status line as well as the + required line wappping and quoting for data lines. + + We use GNU's custom streams here. There should be an alternative + implementaion for systems w/o a glibc, a simple implementation + could use a child process */ +FILE * +assuan_get_data_fp (ASSUAN_CONTEXT ctx) +{ + cookie_io_functions_t cookie_fnc; + + if (ctx->outbound.data.fp) + return ctx->outbound.data.fp; + + cookie_fnc.read = NULL; + cookie_fnc.write = _assuan_cookie_write_data; + cookie_fnc.seek = NULL; + cookie_fnc.close = _assuan_cookie_write_flush; + + ctx->outbound.data.fp = fopencookie (ctx, "wb", cookie_fnc); + ctx->outbound.data.error = 0; + return ctx->outbound.data.fp; +} + + +/* Set the text used for the next OK reponse. This string is + automatically reset to NULL after the next command. */ +AssuanError +assuan_set_okay_line (ASSUAN_CONTEXT ctx, const char *line) +{ + if (!ctx) + return ASSUAN_Invalid_Value; + if (!line) + { + xfree (ctx->okay_line); + ctx->okay_line = NULL; + } + else + { + /* FIXME: we need to use gcry_is_secure() to test whether + we should allocate the entire line in secure memory */ + char *buf = xtrymalloc (3+strlen(line)+1); + if (!buf) + return ASSUAN_Out_Of_Core; + strcpy (buf, "OK "); + strcpy (buf+3, line); + xfree (ctx->okay_line); + ctx->okay_line = buf; + } + return 0; +} + + + +void +assuan_write_status (ASSUAN_CONTEXT ctx, const char *keyword, const char *text) +{ + char buffer[256]; + char *helpbuf; + size_t n; + + if ( !ctx || !keyword) + return; + if (!text) + text = ""; + + n = 2 + strlen (keyword) + 1 + strlen (text) + 1; + if (n < sizeof (buffer)) + { + strcpy (buffer, "S "); + strcat (buffer, keyword); + if (*text) + { + strcat (buffer, " "); + strcat (buffer, text); + } + assuan_write_line (ctx, buffer); + } + else if ( (helpbuf = xtrymalloc (n)) ) + { + strcpy (helpbuf, "S "); + strcat (helpbuf, keyword); + if (*text) + { + strcat (helpbuf, " "); + strcat (helpbuf, text); + } + assuan_write_line (ctx, helpbuf); + xfree (helpbuf); + } +} diff --git a/tags/V0-3-4/assuan/assuan-inquire.c b/tags/V0-3-4/assuan/assuan-inquire.c new file mode 100644 index 0000000..933091e --- /dev/null +++ b/tags/V0-3-4/assuan/assuan-inquire.c @@ -0,0 +1,223 @@ +/* assuan-inquire.c - handle inquire stuff + * Copyright (C) 2001, 2002 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include "assuan-defs.h" + +#define digitp(a) ((a) >= '0' && (a) <= '9') +#define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \ + *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10)) +#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1)) + + +struct membuf { + size_t len; + size_t size; + char *buf; + int out_of_core; + int too_large; + size_t maxlen; +}; + + + +/* A simple implemnation of a dynamic buffer. Use init_membuf() to + create a buffer, put_membuf to append bytes and get_membuf to + release and return the buffer. Allocation errors are detected but + only returned at the final get_membuf(), this helps not to clutter + the code with out of core checks. */ + +static void +init_membuf (struct membuf *mb, int initiallen, size_t maxlen) +{ + mb->len = 0; + mb->size = initiallen; + mb->out_of_core = 0; + mb->too_large = 0; + mb->maxlen = maxlen; + /* we need to allocate one byte more for get_membuf */ + mb->buf = xtrymalloc (initiallen+1); + if (!mb->buf) + mb->out_of_core = 1; +} + +static void +put_membuf (struct membuf *mb, const void *buf, size_t len) +{ + if (mb->out_of_core || mb->too_large) + return; + + if (mb->maxlen && mb->len + len > mb->maxlen) + { + mb->too_large = 1; + return; + } + + if (mb->len + len >= mb->size) + { + char *p; + + mb->size += len + 1024; + /* we need to allocate one byte more for get_membuf */ + p = xtryrealloc (mb->buf, mb->size+1); + if (!p) + { + mb->out_of_core = 1; + return; + } + mb->buf = p; + } + memcpy (mb->buf + mb->len, buf, len); + mb->len += len; +} + +static void * +get_membuf (struct membuf *mb, size_t *len) +{ + char *p; + + if (mb->out_of_core || mb->too_large) + { + xfree (mb->buf); + mb->buf = NULL; + return NULL; + } + + mb->buf[mb->len] = 0; /* there is enough space for the hidden eos */ + p = mb->buf; + *len = mb->len; + mb->buf = NULL; + mb->out_of_core = 1; /* don't allow a reuse */ + return p; +} + +static void +free_membuf (struct membuf *mb) +{ + xfree (mb->buf); + mb->buf = NULL; +} + + +/** + * assuan_inquire: + * @ctx: An assuan context + * @keyword: The keyword used for the inquire + * @r_buffer: Returns an allocated buffer + * @r_length: Returns the length of this buffer + * @maxlen: If no 0, the size limit of the inquired data. + * + * A Server may use this to Send an inquire + * + * Return value: 0 on success or an ASSUAN error code + **/ +AssuanError +assuan_inquire (ASSUAN_CONTEXT ctx, const char *keyword, + char **r_buffer, size_t *r_length, size_t maxlen) +{ + AssuanError rc; + struct membuf mb; + char cmdbuf[100]; + unsigned char *line, *p; + int linelen; + + if (!ctx || !keyword || (10 + strlen (keyword) >= sizeof (cmdbuf)) + || !r_buffer || !r_length ) + return ASSUAN_Invalid_Value; + if (!ctx->is_server) + return ASSUAN_Not_A_Server; + if (ctx->in_inquire) + return ASSUAN_Nested_Commands; + + ctx->in_inquire = 1; + init_membuf (&mb, maxlen? maxlen:1024, maxlen); + + strcpy (stpcpy (cmdbuf, "INQUIRE "), keyword); + rc = assuan_write_line (ctx, cmdbuf); + if (rc) + goto leave; + + for (;;) + { + do + { + rc = _assuan_read_line (ctx); + if (rc) + goto leave; + line = ctx->inbound.line; + linelen = ctx->inbound.linelen; + } + while (*line == '#' || !linelen); + if (line[0] == 'E' && line[1] == 'N' && line[2] == 'D' + && (!line[3] || line[3] == ' ')) + break; /* END command received*/ + if (line[0] != 'D' || line[1] != ' ') + { + rc = ASSUAN_Unexpected_Command; + goto leave; + } + if (linelen < 3) + continue; + line += 2; + linelen -= 2; + + p = line; + while (linelen) + { + for (;linelen && *p != '%'; linelen--, p++) + ; + put_membuf (&mb, line, p-line); + if (linelen > 2) + { /* handle escaping */ + unsigned char tmp[1]; + p++; + *tmp = xtoi_2 (p); + p += 2; + linelen -= 3; + put_membuf (&mb, tmp, 1); + } + line = p; + } + if (mb.too_large) + { + rc = ASSUAN_Too_Much_Data; + goto leave; + } + } + + *r_buffer = get_membuf (&mb, r_length); + if (!*r_buffer) + rc = ASSUAN_Out_Of_Core; + + leave: + free_membuf (&mb); + ctx->in_inquire = 0; + return rc; +} + + + + + + diff --git a/tags/V0-3-4/assuan/assuan-listen.c b/tags/V0-3-4/assuan/assuan-listen.c new file mode 100644 index 0000000..db63ad2 --- /dev/null +++ b/tags/V0-3-4/assuan/assuan-listen.c @@ -0,0 +1,132 @@ +/* assuan-listen.c - Wait for a connection (server) + * Copyright (C) 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "assuan-defs.h" + +AssuanError +assuan_set_hello_line (ASSUAN_CONTEXT ctx, const char *line) +{ + if (!ctx) + return ASSUAN_Invalid_Value; + if (!line) + { + xfree (ctx->hello_line); + ctx->hello_line = NULL; + } + else + { + char *buf = xtrymalloc (3+strlen(line)+1); + if (!buf) + return ASSUAN_Out_Of_Core; + strcpy (buf, "OK "); + strcpy (buf+3, line); + xfree (ctx->hello_line); + ctx->hello_line = buf; + } + return 0; +} + + +/** + * assuan_accept: + * @ctx: context + * + * Cancel any existing connectiion and wait for a connection from a + * client. The initial handshake is performed which may include an + * initial authentication or encryption negotiation. + * + * Return value: 0 on success or an error if the connection could for + * some reason not be established. + **/ +AssuanError +assuan_accept (ASSUAN_CONTEXT ctx) +{ + int rc; + + if (!ctx) + return ASSUAN_Invalid_Value; + + if (ctx->pipe_mode > 1) + return -1; /* second invocation for pipemode -> terminate */ + ctx->finish_handler (ctx); + + rc = ctx->accept_handler (ctx); + if (rc) + return rc; + + /* send the hello */ + rc = assuan_write_line (ctx, ctx->hello_line? ctx->hello_line + : "OK Your orders please"); + if (rc) + return rc; + + if (ctx->pipe_mode) + ctx->pipe_mode = 2; + + return 0; +} + + + +int +assuan_get_input_fd (ASSUAN_CONTEXT ctx) +{ + return ctx? ctx->input_fd : -1; +} + + +int +assuan_get_output_fd (ASSUAN_CONTEXT ctx) +{ + return ctx? ctx->output_fd : -1; +} + + +/* Close the fd descriptor set by the command INPUT FD=n. We handle + this fd inside assuan so that we can do some initial checks */ +AssuanError +assuan_close_input_fd (ASSUAN_CONTEXT ctx) +{ + if (!ctx || ctx->input_fd == -1) + return ASSUAN_Invalid_Value; + close (ctx->input_fd); + ctx->input_fd = -1; + return 0; +} + +/* Close the fd descriptor set by the command OUTPUT FD=n. We handle + this fd inside assuan so that we can do some initial checks */ +AssuanError +assuan_close_output_fd (ASSUAN_CONTEXT ctx) +{ + if (!ctx || ctx->output_fd == -1) + return ASSUAN_Invalid_Value; + + close (ctx->output_fd); + ctx->output_fd = -1; + return 0; +} + diff --git a/tags/V0-3-4/assuan/assuan-pipe-connect.c b/tags/V0-3-4/assuan/assuan-pipe-connect.c new file mode 100644 index 0000000..ccfc1f0 --- /dev/null +++ b/tags/V0-3-4/assuan/assuan-pipe-connect.c @@ -0,0 +1,269 @@ +/* assuan-pipe-connect.c - Establish a pipe connection (client) + * Copyright (C) 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "assuan-defs.h" + +#ifdef _POSIX_OPEN_MAX +#define MAX_OPEN_FDS _POSIX_OPEN_MAX +#else +#define MAX_OPEN_FDS 20 +#endif + +#ifdef HAVE_JNLIB_LOGGING +#include "../jnlib/logging.h" +#define LOGERROR1(a,b) log_error ((a), (b)) +#else +#define LOGERROR1(a,b) fprintf (stderr, (a), (b)) +#endif + + + +static int +writen ( int fd, const char *buffer, size_t length ) +{ + while (length) + { + int nwritten = write (fd, buffer, length); + + if (nwritten < 0) + { + if (errno == EINTR) + continue; + return -1; /* write error */ + } + length -= nwritten; + buffer += nwritten; + } + return 0; /* okay */ +} + + +static int +do_finish (ASSUAN_CONTEXT ctx) +{ + if (ctx->inbound.fd != -1) + { + close (ctx->inbound.fd); + ctx->inbound.fd = -1; + } + if (ctx->outbound.fd != -1) + { + close (ctx->outbound.fd); + ctx->outbound.fd = -1; + } + if (ctx->pid != -1) + { + waitpid (ctx->pid, NULL, 0); /* FIXME Check return value. */ + ctx->pid = -1; + } + return 0; +} + +static void +do_deinit (ASSUAN_CONTEXT ctx) +{ + do_finish (ctx); +} + + + +/* Connect to a server over a pipe, creating the assuan context and + returning it in CTX. The server filename is NAME, the argument + vector in ARGV. FD_CHILD_LIST is a -1 terminated list of file + descriptors not to close in the child. */ +AssuanError +assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[], + int *fd_child_list) +{ + static int fixed_signals = 0; + AssuanError err; + int rp[2]; + int wp[2]; + + if (!ctx || !name || !argv || !argv[0]) + return ASSUAN_Invalid_Value; + + if (!fixed_signals) + { + struct sigaction act; + + sigaction (SIGPIPE, NULL, &act); + if (act.sa_handler == SIG_DFL) + { + act.sa_handler = SIG_IGN; + sigemptyset (&act.sa_mask); + act.sa_flags = 0; + sigaction (SIGPIPE, &act, NULL); + } + fixed_signals = 1; + /* FIXME: This is not MT safe */ + } + + if (pipe (rp) < 0) + return ASSUAN_General_Error; + + if (pipe (wp) < 0) + { + close (rp[0]); + close (rp[1]); + return ASSUAN_General_Error; + } + + err = _assuan_new_context (ctx); + if (err) + { + close (rp[0]); + close (rp[1]); + close (wp[0]); + close (wp[1]); + return err; + } + (*ctx)->pipe_mode = 1; + (*ctx)->inbound.fd = rp[0]; /* Our inbound is read end of read pipe. */ + (*ctx)->outbound.fd = wp[1]; /* Our outbound is write end of write pipe. */ + (*ctx)->deinit_handler = do_deinit; + (*ctx)->finish_handler = do_finish; + + (*ctx)->pid = fork (); + if ((*ctx)->pid < 0) + { + close (rp[0]); + close (rp[1]); + close (wp[0]); + close (wp[1]); + _assuan_release_context (*ctx); + return ASSUAN_General_Error; + } + + if ((*ctx)->pid == 0) + { + int i, n; + char errbuf[512]; +#ifdef HAVE_JNLIB_LOGGING + int log_fd = log_get_fd (); +#endif + /* close all files which will not be duped but keep stderr + and log_stream for now */ + n = sysconf (_SC_OPEN_MAX); + if (n < 0) + n = MAX_OPEN_FDS; + for (i=0; i < n; i++) + { + int *fdp = fd_child_list; + + if (fdp) + { + while (*fdp != -1 && *fdp != i) + fdp++; + } + + if (!(fdp && *fdp != -1) + && i != fileno (stderr) +#ifdef HAVE_JNLIB_LOGGING + && i != log_fd +#endif + && i != rp[1] && i != wp[0]) + close(i); + } + errno = 0; + + /* Dup handles and to stdin/stdout and exec */ + if (rp[1] != STDOUT_FILENO) + { + if (dup2 (rp[1], STDOUT_FILENO) == -1) + { + LOGERROR1 ("dup2 failed in child: %s\n", strerror (errno)); + _exit (4); + } + close (rp[1]); + } + if (wp[0] != STDIN_FILENO) + { + if (dup2 (wp[0], STDIN_FILENO) == -1) + { + LOGERROR1 ("dup2 failed in child: %s\n", strerror (errno)); + _exit (4); + } + close (wp[0]); + } + + execv (name, argv); + /* oops - use the pipe to tell the parent about it */ + snprintf (errbuf, sizeof(errbuf)-1, "ERR %d can't exec `%s': %.50s\n", + ASSUAN_Problem_Starting_Server, name, strerror (errno)); + errbuf[sizeof(errbuf)-1] = 0; + writen (1, errbuf, strlen (errbuf)); + _exit (4); + } + + close (rp[1]); + close (wp[0]); + + /* initial handshake */ + { + int okay, off; + + err = _assuan_read_from_server (*ctx, &okay, &off); + if (err) + { + LOGERROR1 ("can't connect server: %s\n", assuan_strerror (err)); + } + else if (okay != 1) + { + LOGERROR1 ("can't connect server: `%s'\n", (*ctx)->inbound.line); + err = ASSUAN_Connect_Failed; + } + } + + if (err) + { + assuan_disconnect (*ctx); + *ctx = NULL; + } + + return err; +} + + + + + + + + + + + + + + diff --git a/tags/V0-3-4/assuan/assuan-pipe-server.c b/tags/V0-3-4/assuan/assuan-pipe-server.c new file mode 100644 index 0000000..d15f54f --- /dev/null +++ b/tags/V0-3-4/assuan/assuan-pipe-server.c @@ -0,0 +1,123 @@ +/* assuan-pipe-server.c - Assuan server working over a pipe + * Copyright (C) 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include + +#include "assuan-defs.h" + +static void +deinit_pipe_server (ASSUAN_CONTEXT ctx) +{ + /* nothing to do for this simple server */ +} + +static int +accept_connection (ASSUAN_CONTEXT ctx) +{ + /* This is a NOP for a pipe server */ + return 0; +} + +static int +finish_connection (ASSUAN_CONTEXT ctx) +{ + /* This is a NOP for a pipe server */ + return 0; +} + + +/* Create a new context. Note that the handlers are set up for a pipe + server/client - this wau we don't need extra dummy functions */ +int +_assuan_new_context (ASSUAN_CONTEXT *r_ctx) +{ + ASSUAN_CONTEXT ctx; + int rc; + + *r_ctx = NULL; + ctx = xtrycalloc (1, sizeof *ctx); + if (!ctx) + return ASSUAN_Out_Of_Core; + ctx->input_fd = -1; + ctx->output_fd = -1; + + ctx->inbound.fd = -1; + ctx->outbound.fd = -1; + + ctx->listen_fd = -1; + /* use the pipe server handler as a default */ + ctx->deinit_handler = deinit_pipe_server; + ctx->accept_handler = accept_connection; + ctx->finish_handler = finish_connection; + + rc = _assuan_register_std_commands (ctx); + if (rc) + xfree (ctx); + else + *r_ctx = ctx; + return rc; +} + + + +int +assuan_init_pipe_server (ASSUAN_CONTEXT *r_ctx, int filedes[2]) +{ + int rc; + + rc = _assuan_new_context (r_ctx); + if (!rc) + { + ASSUAN_CONTEXT ctx = *r_ctx; + + ctx->is_server = 1; + ctx->inbound.fd = filedes[0]; + ctx->outbound.fd = filedes[1]; + ctx->pipe_mode = 1; + } + return rc; +} + + +void +_assuan_release_context (ASSUAN_CONTEXT ctx) +{ + if (ctx) + { + xfree (ctx->hello_line); + xfree (ctx->okay_line); + xfree (ctx); + } +} + +void +assuan_deinit_server (ASSUAN_CONTEXT ctx) +{ + if (ctx) + { + /* We use this function pointer to avoid linking other server + when not needed but still allow for a generic deinit function */ + ctx->deinit_handler (ctx); + ctx->deinit_handler = NULL; + _assuan_release_context (ctx); + } +} diff --git a/tags/V0-3-4/assuan/assuan-socket-connect.c b/tags/V0-3-4/assuan/assuan-socket-connect.c new file mode 100644 index 0000000..748a91f --- /dev/null +++ b/tags/V0-3-4/assuan/assuan-socket-connect.c @@ -0,0 +1,150 @@ +/* assuan-socket-connect.c - Assuan socket based client + * Copyright (C) 2002 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "assuan-defs.h" + +#ifdef HAVE_JNLIB_LOGGING +#include "../jnlib/logging.h" +#define LOGERROR(a) log_error ((a)) +#define LOGERROR1(a,b) log_error ((a), (b)) +#define LOGERROR2(a,b,c) log_error ((a), (b), (c)) +#define LOGERRORX(a) log_printf ((a)) +#else +#define LOGERROR(a) fprintf (stderr, (a)) +#define LOGERROR1(a,b) fprintf (stderr, (a), (b)) +#define LOGERROR2(a,b,c) fprintf (stderr, (a), (b), (c)) +#define LOGERRORX(a) fputs ((a), stderr) +#endif + + + +static int +do_finish (ASSUAN_CONTEXT ctx) +{ + if (ctx->inbound.fd != -1) + { + close (ctx->inbound.fd); + } + ctx->inbound.fd = -1; + ctx->outbound.fd = -1; + return 0; +} + +static void +do_deinit (ASSUAN_CONTEXT ctx) +{ + do_finish (ctx); +} + + + +/* Make a connection to the Unix domain socket NAME and return a new + Assuan context in CTX. SERVER_PID is currently not used but may + becode handy in future. */ +AssuanError +assuan_socket_connect (ASSUAN_CONTEXT *r_ctx, + const char *name, pid_t server_pid) +{ + AssuanError err; + ASSUAN_CONTEXT ctx; + int fd; + struct sockaddr_un srvr_addr; + size_t len; + + if (!r_ctx || !name) + return ASSUAN_Invalid_Value; + *r_ctx = NULL; + + /* we require that the name starts with a slash, so that we can + alter reuse this function for other socket types */ + if (*name != '/') + return ASSUAN_Invalid_Value; + if (strlen (name)+1 >= sizeof srvr_addr.sun_path) + return ASSUAN_Invalid_Value; + + err = _assuan_new_context (&ctx); + if (err) + return err; + ctx->pid = server_pid; /* save it in case we need it later */ + ctx->deinit_handler = do_deinit; + ctx->finish_handler = do_finish; + + fd = socket (AF_UNIX, SOCK_STREAM, 0); + if (fd == -1) + { + LOGERROR1 ("can't create socket: %s\n", strerror (errno)); + _assuan_release_context (ctx); + return ASSUAN_General_Error; + } + + memset (&srvr_addr, 0, sizeof srvr_addr ); + srvr_addr.sun_family = AF_UNIX; + strcpy (srvr_addr.sun_path, name); + len = (offsetof (struct sockaddr_un, sun_path) + + strlen (srvr_addr.sun_path) + 1); + + if (connect (fd, (struct sockaddr*)&srvr_addr, len) == -1) + { + LOGERROR2 ("can't connect to `%s': %s\n", name, strerror (errno)); + _assuan_release_context (ctx); + close (fd ); + return ASSUAN_Connect_Failed; + } + + ctx->inbound.fd = fd; + ctx->outbound.fd = fd; + + /* initial handshake */ + { + int okay, off; + + err = _assuan_read_from_server (ctx, &okay, &off); + if (err) + { + LOGERROR1 ("can't connect server: %s\n", assuan_strerror (err)); + } + else if (okay != 1) + { + LOGERROR ("can't connect server: `"); + _assuan_log_sanitized_string (ctx->inbound.line); + LOGERRORX ("'\n"); + err = ASSUAN_Connect_Failed; + } + } + + if (err) + { + assuan_disconnect (ctx); + } + else + *r_ctx = ctx; + return 0; +} + + diff --git a/tags/V0-3-4/assuan/assuan-socket-server.c b/tags/V0-3-4/assuan/assuan-socket-server.c new file mode 100644 index 0000000..6ad6455 --- /dev/null +++ b/tags/V0-3-4/assuan/assuan-socket-server.c @@ -0,0 +1,121 @@ +/* assuan-socket-server.c - Assuan socket based server + * Copyright (C) 2002 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "assuan-defs.h" + +static int +accept_connection (ASSUAN_CONTEXT ctx) +{ + int fd; + struct sockaddr_un clnt_addr; + size_t len = sizeof clnt_addr; + + fd = accept (ctx->listen_fd, (struct sockaddr*)&clnt_addr, &len ); + if (fd == -1) + { + ctx->os_errno = errno; + return ASSUAN_Accept_Failed; + } + + ctx->inbound.fd = fd; + ctx->inbound.eof = 0; + ctx->inbound.linelen = 0; + ctx->inbound.attic.linelen = 0; + ctx->inbound.attic.pending = 0; + + ctx->outbound.fd = fd; + ctx->outbound.data.linelen = 0; + ctx->outbound.data.error = 0; + + ctx->confidential = 0; + + return 0; +} + +static int +finish_connection (ASSUAN_CONTEXT ctx) +{ + if (ctx->inbound.fd != -1) + { + close (ctx->inbound.fd); + } + ctx->inbound.fd = -1; + ctx->outbound.fd = -1; + return 0; +} + + +static void +deinit_socket_server (ASSUAN_CONTEXT ctx) +{ + finish_connection (ctx); +} + + + +/* Initialize a server for the socket LISTEN_FD which has already be + put into listen mode */ +int +assuan_init_socket_server (ASSUAN_CONTEXT *r_ctx, int listen_fd) +{ + ASSUAN_CONTEXT ctx; + int rc; + + *r_ctx = NULL; + ctx = xtrycalloc (1, sizeof *ctx); + if (!ctx) + return ASSUAN_Out_Of_Core; + ctx->is_server = 1; + ctx->input_fd = -1; + ctx->output_fd = -1; + + ctx->inbound.fd = -1; + ctx->outbound.fd = -1; + + ctx->listen_fd = listen_fd; + ctx->deinit_handler = deinit_socket_server; + ctx->accept_handler = accept_connection; + ctx->finish_handler = finish_connection; + + rc = _assuan_register_std_commands (ctx); + if (rc) + xfree (ctx); + else + *r_ctx = ctx; + return rc; +} + + + + + + + + + + diff --git a/tags/V0-3-4/assuan/assuan-util.c b/tags/V0-3-4/assuan/assuan-util.c new file mode 100644 index 0000000..4153ef8 --- /dev/null +++ b/tags/V0-3-4/assuan/assuan-util.c @@ -0,0 +1,196 @@ +/* assuan-util.c - Utility functions for Assuan + * Copyright (C) 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include "assuan-defs.h" + +#ifdef HAVE_JNLIB_LOGGING +#include "../jnlib/logging.h" +#endif + + +static void *(*alloc_func)(size_t n) = malloc; +static void *(*realloc_func)(void *p, size_t n) = realloc; +static void (*free_func)(void*) = free; + + + +void +assuan_set_malloc_hooks ( void *(*new_alloc_func)(size_t n), + void *(*new_realloc_func)(void *p, size_t n), + void (*new_free_func)(void*) ) +{ + alloc_func = new_alloc_func; + realloc_func = new_realloc_func; + free_func = new_free_func; +} + +void * +_assuan_malloc (size_t n) +{ + return alloc_func (n); +} + +void * +_assuan_realloc (void *a, size_t n) +{ + return realloc_func (a, n); +} + +void * +_assuan_calloc (size_t n, size_t m) +{ + void *p = _assuan_malloc (n*m); + if (p) + memset (p, 0, n* m); + return p; +} + +void +_assuan_free (void *p) +{ + if (p) + free_func (p); +} + + + +/* Store the error in the context so that the error sending function + can take out a descriptive text. Inside the assuan code, use the + macro set_error instead of this function. */ +int +assuan_set_error (ASSUAN_CONTEXT ctx, int err, const char *text) +{ + ctx->err_no = err; + ctx->err_str = text; + return err; +} + +void +assuan_set_pointer (ASSUAN_CONTEXT ctx, void *pointer) +{ + if (ctx) + ctx->user_pointer = pointer; +} + +void * +assuan_get_pointer (ASSUAN_CONTEXT ctx) +{ + return ctx? ctx->user_pointer : NULL; +} + + +void +assuan_set_log_stream (ASSUAN_CONTEXT ctx, FILE *fp) +{ + if (ctx) + { + if (ctx->log_fp) + fflush (ctx->log_fp); + ctx->log_fp = fp; + } +} + + +void +assuan_begin_confidential (ASSUAN_CONTEXT ctx) +{ + if (ctx) + { + ctx->confidential = 1; + } +} + +void +assuan_end_confidential (ASSUAN_CONTEXT ctx) +{ + if (ctx) + { + ctx->confidential = 0; + } +} + +void +_assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length) +{ + const unsigned char *s; + int n; + + for (n=length,s=buffer; n; n--, s++) + { + if (*s < ' ' || (*s >= 0x7f && *s <= 0xa0)) + break; + } + s = buffer; + if (!n && *s != '[') + fwrite (buffer, length, 1, fp); + else + { + putc ('[', fp); + for (n=0; n < length; n++, s++) + fprintf (fp, " %02x", *s); + putc (' ', fp); + putc (']', fp); + } +} + + +/* print a user supplied string after filtering out potential bad + characters*/ +void +_assuan_log_sanitized_string (const char *string) +{ + const unsigned char *s = string; +#ifdef HAVE_JNLIB_LOGGING + FILE *fp = log_get_stream (); +#else + FILE *fp = stderr; +#endif + + for (; *s; s++) + { + if (*s < 0x20 || (*s >= 0x7f && *s <= 0xa0)) + { + putc ('\\', fp); + if (*s == '\n') + putc ('n', fp); + else if (*s == '\r') + putc ('r', fp); + else if (*s == '\f') + putc ('f', fp); + else if (*s == '\v') + putc ('v', fp); + else if (*s == '\b') + putc ('b', fp); + else if (!*s) + putc ('0', fp); + else + fprintf (fp, "x%02x", *s ); + } + else + putc (*s, fp); + } +} + + diff --git a/tags/V0-3-4/assuan/assuan.h b/tags/V0-3-4/assuan/assuan.h new file mode 100644 index 0000000..5971d81 --- /dev/null +++ b/tags/V0-3-4/assuan/assuan.h @@ -0,0 +1,216 @@ +/* assuan.c - Definitions for the Assuna protocol + * Copyright (C) 2001, 2002 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef ASSUAN_H +#define ASSUAN_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#if 0 + } +#endif +#endif + +typedef enum { + ASSUAN_No_Error = 0, + ASSUAN_General_Error = 1, + ASSUAN_Out_Of_Core = 2, + ASSUAN_Invalid_Value = 3, + ASSUAN_Timeout = 4, + ASSUAN_Read_Error = 5, + ASSUAN_Write_Error = 6, + ASSUAN_Problem_Starting_Server = 7, + ASSUAN_Not_A_Server = 8, + ASSUAN_Not_A_Client = 9, + ASSUAN_Nested_Commands = 10, + ASSUAN_Invalid_Response = 11, + ASSUAN_No_Data_Callback = 12, + ASSUAN_No_Inquire_Callback = 13, + ASSUAN_Connect_Failed = 14, + ASSUAN_Accept_Failed = 15, + + /* error codes above 99 are meant as status codes */ + ASSUAN_Not_Implemented = 100, + ASSUAN_Server_Fault = 101, + ASSUAN_Invalid_Command = 102, + ASSUAN_Unknown_Command = 103, + ASSUAN_Syntax_Error = 104, + ASSUAN_Parameter_Error = 105, + ASSUAN_Parameter_Conflict = 106, + ASSUAN_Line_Too_Long = 107, + ASSUAN_Line_Not_Terminated = 108, + ASSUAN_No_Input = 109, + ASSUAN_No_Output = 110, + ASSUAN_Canceled = 111, + ASSUAN_Unsupported_Algorithm = 112, + ASSUAN_Server_Resource_Problem = 113, + ASSUAN_Server_IO_Error = 114, + ASSUAN_Server_Bug = 115, + ASSUAN_No_Data_Available = 116, + ASSUAN_Invalid_Data = 117, + ASSUAN_Unexpected_Command = 118, + ASSUAN_Too_Much_Data = 119, + ASSUAN_Inquire_Unknown = 120, + ASSUAN_Inquire_Error = 121, + ASSUAN_Invalid_Option = 122, + + ASSUAN_Bad_Certificate = 201, + ASSUAN_Bad_Certificate_Path = 202, + ASSUAN_Missing_Certificate = 203, + ASSUAN_Bad_Signature = 204, + ASSUAN_No_Agent = 205, + ASSUAN_Agent_Error = 206, + ASSUAN_No_Public_Key = 207, + ASSUAN_No_Secret_Key = 208, + ASSUAN_Invalid_Name = 209, + + ASSUAN_Cert_Revoked = 301, + ASSUAN_No_CRL_For_Cert = 302, + ASSUAN_CRL_Too_Old = 303, + ASSUAN_Not_Trusted = 304, + +} AssuanError; + +/* This is a list of pre-registered ASSUAN commands */ +typedef enum { + ASSUAN_CMD_NOP = 0, + ASSUAN_CMD_CANCEL, /* cancel the current request */ + ASSUAN_CMD_BYE, + ASSUAN_CMD_AUTH, + ASSUAN_CMD_RESET, + ASSUAN_CMD_OPTION, + ASSUAN_CMD_DATA, + ASSUAN_CMD_END, + ASSUAN_CMD_INPUT, + ASSUAN_CMD_OUTPUT, + + ASSUAN_CMD_USER = 256 /* Other commands should be used with this offset*/ +} AssuanCommand; + +#define ASSUAN_LINELENGTH 1002 /* 1000 + [CR,]LF */ + +struct assuan_context_s; +typedef struct assuan_context_s *ASSUAN_CONTEXT; + +/*-- assuan-handler.c --*/ +int assuan_register_command (ASSUAN_CONTEXT ctx, + int cmd_id, const char *cmd_string, + int (*handler)(ASSUAN_CONTEXT, char *)); +int assuan_register_bye_notify (ASSUAN_CONTEXT ctx, + void (*fnc)(ASSUAN_CONTEXT)); +int assuan_register_reset_notify (ASSUAN_CONTEXT ctx, + void (*fnc)(ASSUAN_CONTEXT)); +int assuan_register_cancel_notify (ASSUAN_CONTEXT ctx, + void (*fnc)(ASSUAN_CONTEXT)); +int assuan_register_input_notify (ASSUAN_CONTEXT ctx, + void (*fnc)(ASSUAN_CONTEXT, const char *)); +int assuan_register_output_notify (ASSUAN_CONTEXT ctx, + void (*fnc)(ASSUAN_CONTEXT, const char *)); + +int assuan_register_option_handler (ASSUAN_CONTEXT ctx, + int (*fnc)(ASSUAN_CONTEXT, + const char*, const char*)); + +int assuan_process (ASSUAN_CONTEXT ctx); +int assuan_process_next (ASSUAN_CONTEXT ctx); +int assuan_get_active_fds (ASSUAN_CONTEXT ctx, int what, + int *fdarray, int fdarraysize); + + +FILE *assuan_get_data_fp (ASSUAN_CONTEXT ctx); +AssuanError assuan_set_okay_line (ASSUAN_CONTEXT ctx, const char *line); +void assuan_write_status (ASSUAN_CONTEXT ctx, + const char *keyword, const char *text); + + +/*-- assuan-listen.c --*/ +AssuanError assuan_set_hello_line (ASSUAN_CONTEXT ctx, const char *line); +AssuanError assuan_accept (ASSUAN_CONTEXT ctx); +int assuan_get_input_fd (ASSUAN_CONTEXT ctx); +int assuan_get_output_fd (ASSUAN_CONTEXT ctx); +AssuanError assuan_close_input_fd (ASSUAN_CONTEXT ctx); +AssuanError assuan_close_output_fd (ASSUAN_CONTEXT ctx); + + +/*-- assuan-pipe-server.c --*/ +int assuan_init_pipe_server (ASSUAN_CONTEXT *r_ctx, int filedes[2]); +void assuan_deinit_server (ASSUAN_CONTEXT ctx); + +/*-- assuan-socket-server.c --*/ +int assuan_init_socket_server (ASSUAN_CONTEXT *r_ctx, int listen_fd); + + +/*-- assuan-pipe-connect.c --*/ +AssuanError assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, + char *const argv[], int *fd_child_list); +/*-- assuan-socket-connect.c --*/ +AssuanError assuan_socket_connect (ASSUAN_CONTEXT *ctx, const char *name, + pid_t server_pid); + +/*-- assuan-connect.c --*/ +void assuan_disconnect (ASSUAN_CONTEXT ctx); +pid_t assuan_get_pid (ASSUAN_CONTEXT ctx); + +/*-- assuan-client.c --*/ +AssuanError +assuan_transact (ASSUAN_CONTEXT ctx, + const char *command, + AssuanError (*data_cb)(void *, const void *, size_t), + void *data_cb_arg, + AssuanError (*inquire_cb)(void*, const char *), + void *inquire_cb_arg); + + +/*-- assuan-inquire.c --*/ +AssuanError assuan_inquire (ASSUAN_CONTEXT ctx, const char *keyword, + char **r_buffer, size_t *r_length, size_t maxlen); + +/*-- assuan-buffer.c --*/ +AssuanError assuan_read_line (ASSUAN_CONTEXT ctx, + char **line, size_t *linelen); +int assuan_pending_line (ASSUAN_CONTEXT ctx); +AssuanError assuan_write_line (ASSUAN_CONTEXT ctx, const char *line ); +AssuanError assuan_send_data (ASSUAN_CONTEXT ctx, + const void *buffer, size_t length); + + +/*-- assuan-util.c --*/ +void assuan_set_malloc_hooks ( void *(*new_alloc_func)(size_t n), + void *(*new_realloc_func)(void *p, size_t n), + void (*new_free_func)(void*) ); +void assuan_set_log_stream (ASSUAN_CONTEXT ctx, FILE *fp); +int assuan_set_error (ASSUAN_CONTEXT ctx, int err, const char *text); +void assuan_set_pointer (ASSUAN_CONTEXT ctx, void *pointer); +void *assuan_get_pointer (ASSUAN_CONTEXT ctx); + +void assuan_begin_confidential (ASSUAN_CONTEXT ctx); +void assuan_end_confidential (ASSUAN_CONTEXT ctx); + +/*-- assuan-errors.c (built) --*/ +const char *assuan_strerror (AssuanError err); + + +#ifdef __cplusplus +} +#endif +#endif /*ASSUAN_H*/ diff --git a/tags/V0-3-4/assuan/mkerrors b/tags/V0-3-4/assuan/mkerrors new file mode 100755 index 0000000..13eabde --- /dev/null +++ b/tags/V0-3-4/assuan/mkerrors @@ -0,0 +1,71 @@ +#!/bin/sh +# mkerrors - Extract error strings from assuan.h +# and create C source for assuan_strerror +# Copyright (C) 2001 Free Software Foundation, Inc. +# +# This file is part of GnuPG. +# +# GnuPG is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# GnuPG is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +cat < +#include "assuan.h" + +/** + * assuan_strerror: + * @err: Error code + * + * This function returns a textual representaion of the given + * errorcode. If this is an unknown value, a string with the value + * is returned (Beware: it is hold in a static buffer). + * + * Return value: String with the error description. + **/ +const char * +assuan_strerror (AssuanError err) +{ + const char *s; + static char buf[25]; + + switch (err) + { +EOF + +awk ' +/ASSUAN_No_Error/ { okay=1 } +!okay {next} +/}/ { exit 0 } +/ASSUAN_[A-Za-z_]*/ { print_code($1) } + + +function print_code( s ) +{ +printf " case %s: s=\"", s ; +gsub(/_/, " ", s ); +printf "%s\"; break;\n", tolower(substr(s,8)); +} +' + +cat <&2 + exit 1 + fi + host=`./config.guess` + + if ! mingw32 --version >/dev/null; then + echo "We need at least version 0.3 of MingW32/CPD" >&2 + exit 1 + fi + + if [ -f config.h ]; then + if grep HAVE_DOSISH_SYSTEM config.h | grep undef >/dev/null; then + echo "Pease run a 'make distclean' first" >&2 + exit 1 + fi + fi + + crossinstalldir=`mingw32 --install-dir` + crossbindir=`mingw32 --get-bindir 2>/dev/null` \ + || crossbindir="$crossinstalldir/bin" + crossdatadir=`mingw32 --get-datadir 2>/dev/null` \ + || crossdatadir="$crossinstalldir/share" + crosslibdir=`mingw32 --get-libdir 2>/dev/null` \ + || crosslibdir="$crossinstalldir/i386--mingw32/lib" + crossincdir=`mingw32 --get-includedir 2>/dev/null` \ + || crossincdir="$crossinstalldir/i386--mingw32/include" + CC=`mingw32 --get-path gcc` + CPP=`mingw32 --get-path cpp` + AR=`mingw32 --get-path ar` + RANLIB=`mingw32 --get-path ranlib` + export CC CPP AR RANLIB + + disable_foo_tests="" + if [ -n "$lib_config_files" ]; then + for i in $lib_config_files; do + j=`echo $i | tr '[a-z-]' '[A-Z_]'` + eval "$j=${crossbindir}/$i" + export $j + disable_foo_tests="$disable_foo_tests --disable-`echo $i| \ + sed 's,-config$,,'`-test" + if [ ! -f "${crossbindir}/$i" ]; then + echo "$i not installed for MingW32" >&2 + DIE=yes + fi + done + fi + [ $DIE = yes ] && exit 1 + + ./configure --host=${host} --target=${target} ${disable_foo_tests} \ + --bindir=${crossbindir} --libdir=${crosslibdir} \ + --datadir=${crossdatadir} --includedir=${crossincdir} \ + --enable-maintainer-mode $* + exit $? +fi + + + +if (autoconf --version) < /dev/null > /dev/null 2>&1 ; then + if (autoconf --version | awk 'NR==1 { if( $3 >= '$autoconf_vers') \ + exit 1; exit 0; }'); + then + echo "**Error**: "\`autoconf\'" is too old." + echo ' (version ' $autoconf_vers ' or newer is required)' + DIE="yes" + fi +else + echo + echo "**Error**: You must have "\`autoconf\'" installed to compile $PGM." + echo ' (version ' $autoconf_vers ' or newer is required)' + DIE="yes" +fi + +if (automake --version) < /dev/null > /dev/null 2>&1 ; then + if (automake --version | awk 'NR==1 { if( $4 >= '$automake_vers') \ + exit 1; exit 0; }'); + then + echo "**Error**: "\`automake\'" is too old." + echo ' (version ' $automake_vers ' or newer is required)' + DIE="yes" + fi + if (aclocal --version) < /dev/null > /dev/null 2>&1; then + if (aclocal --version | awk 'NR==1 { if( $4 >= '$aclocal_vers' ) \ + exit 1; exit 0; }' ); + then + echo "**Error**: "\`aclocal\'" is too old." + echo ' (version ' $aclocal_vers ' or newer is required)' + DIE="yes" + fi + else + echo + echo "**Error**: Missing "\`aclocal\'". The version of "\`automake\' + echo " installed doesn't appear recent enough." + DIE="yes" + fi +else + echo + echo "**Error**: You must have "\`automake\'" installed to compile $PGM." + echo ' (version ' $automake_vers ' or newer is required)' + DIE="yes" +fi + + +if (libtool --version) < /dev/null > /dev/null 2>&1 ; then + if (libtool --version | awk 'NR==1 { if( $4 >= '$libtool_vers') \ + exit 1; exit 0; }'); + then + echo "**Error**: "\`libtool\'" is too old." + echo ' (version ' $libtool_vers ' or newer is required)' + DIE="yes" + fi +else + echo + echo "**Error**: You must have "\`libtool\'" installed to compile $PGM." + echo ' (version ' $libtool_vers ' or newer is required)' + DIE="yes" +fi + +if test "$DIE" = "yes"; then + exit 1 +fi + +echo "Running libtoolize... Ignore non-fatal messages." +echo "no" | libtoolize + + +echo "Running aclocal..." +aclocal +echo "Running autoheader..." +autoheader +echo "Running automake --gnu -a ..." +automake --gnu -a +echo "Running autoconf..." +autoconf diff --git a/tags/V0-3-4/bonobo/.cvsignore b/tags/V0-3-4/bonobo/.cvsignore new file mode 100644 index 0000000..3f85e61 --- /dev/null +++ b/tags/V0-3-4/bonobo/.cvsignore @@ -0,0 +1 @@ +Makefile.in Makefile .deps diff --git a/tags/V0-3-4/bonobo/Makefile.am b/tags/V0-3-4/bonobo/Makefile.am new file mode 100644 index 0000000..27bc13d --- /dev/null +++ b/tags/V0-3-4/bonobo/Makefile.am @@ -0,0 +1,30 @@ +# Copyright (C) 2000 Werner Koch (dd9jn) +# Copyright (C) 2001 g10 Code GmbH +# +# This file is part of GPGME. +# +# GPGME is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# GPGME is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +## Process this file with automake to produce Makefile.in + +bin_PROGRAMS = gpgme + +INCLUDES = -I$(top_srcdir)/jnlib +LDADD = -L ../jnlib -ljnlib + +gpgme_SOURCES = main.c main.h + + + diff --git a/tags/V0-3-4/bonobo/gpgme.c b/tags/V0-3-4/bonobo/gpgme.c new file mode 100644 index 0000000..765de50 --- /dev/null +++ b/tags/V0-3-4/bonobo/gpgme.c @@ -0,0 +1,20 @@ +/* gpgme - Bonbobo component to access GnuPG + * Copyright (C) 2000 Werner Koch (dd9jn) + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + diff --git a/tags/V0-3-4/bonobo/main.c b/tags/V0-3-4/bonobo/main.c new file mode 100644 index 0000000..e42d20a --- /dev/null +++ b/tags/V0-3-4/bonobo/main.c @@ -0,0 +1,20 @@ +/* main.c - Bonbobo component to access GnuPG + * Copyright (C) 2000 Werner Koch (dd9jn) + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + diff --git a/tags/V0-3-4/bonobo/main.h b/tags/V0-3-4/bonobo/main.h new file mode 100644 index 0000000..41b56df --- /dev/null +++ b/tags/V0-3-4/bonobo/main.h @@ -0,0 +1,42 @@ +/* main.h - GPGME Bonobo component + * Copyright (C) 2000 Werner Koch (dd9jn) + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef MAIN_H +#define MAIN_H + + +struct { + int verbose; + int quiet; + unsigned int debug; + char *homedir; +} opt; + + + + +#endif /* MAIN_H */ + + + + + + + diff --git a/tags/V0-3-4/complus/.cvsignore b/tags/V0-3-4/complus/.cvsignore new file mode 100644 index 0000000..5580591 --- /dev/null +++ b/tags/V0-3-4/complus/.cvsignore @@ -0,0 +1,2 @@ +.libs +Makefile.in Makefile .deps diff --git a/tags/V0-3-4/complus/ChangeLog b/tags/V0-3-4/complus/ChangeLog new file mode 100644 index 0000000..fe34a66 --- /dev/null +++ b/tags/V0-3-4/complus/ChangeLog @@ -0,0 +1,15 @@ +2001-07-30 Werner Koch + + Encryption basically works. + + + Copyright 2001 g10 Code GmbH + + This file is free software; as a special exception the author gives + unlimited permission to copy and/or distribute it, with or without + modifications, as long as this notice is preserved. + + This file is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, to the extent permitted by law; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + \ No newline at end of file diff --git a/tags/V0-3-4/complus/Makefile.am b/tags/V0-3-4/complus/Makefile.am new file mode 100644 index 0000000..1965b9f --- /dev/null +++ b/tags/V0-3-4/complus/Makefile.am @@ -0,0 +1,49 @@ +# Copyright (C) 2000 Werner Koch (dd9jn) +# Copyright (C) 2001 g10 Code GmbH +# +# This file is part of GPGME. +# +# GPGME is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# GPGME is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +## Process this file with automake to produce Makefile.in + +# Because there is no free IDL compiler for OLE, we have to distribute +# a binary typelibrary. To generate a new one, copy the idl file to a +# system with an install MIDL and run the command +# midl /nocpp gpgcom.idl +# Sorry, there is no other way yet. +EXTRA_DIST = gpgcom.idl gpgcom.tlb gpgcom.rc vbtest.html vbtest.vbs README + +# No need to install this because we are cross-compiling anyway. +noinst_PROGRAMS = gpgcom tgpgcom + +INCLUDES = -I$(top_srcdir)/jnlib +LDADD = ../gpgme/libgpgme.la -L ../jnlib -ljnlib -lole32 -loleaut32 +gpgcom_LDADD = gpgcom_res.o $(LDADD) + +gpgcom_SOURCES = gpgcom.c main.h \ + debug.c utf8.c \ + igpgme.h igpgme.c + +tgpgcom_SOURCES = tgpgcom.c\ + debug.c \ + igpgme.h + +#regtlb_SOURCES = regtlb.c +#guidgen_SOURCES = guidgen.c + +gpgcom_res.o: gpgcom.rc + mingw32 windres $< gpgcom_res.o + diff --git a/tags/V0-3-4/complus/README b/tags/V0-3-4/complus/README new file mode 100644 index 0000000..7dc3bb1 --- /dev/null +++ b/tags/V0-3-4/complus/README @@ -0,0 +1,72 @@ + How to install and use the Gpgcom Windows Component + =================================================== + 2001-07-31 + + +Installation should be pretty easy: +----------------------------------- + + * Get and install the latest GnuPG binary for windows + (ftp://ftp.gnupg.org/gcrypt/binary/gnupg-w32-1.0.6.zip) + + * Check that you have an untampered version of this package by + comparing an MD5SUM against the one on the webpage or by checking + the signature of the package using "gpg --verify". See the + webpacge for details. + + * Because you are reading this file, you probably have already + unpacked it distribution using a unzip utility :-). You should + find these files: + + README - This file + gpgcom.exe - The Gpgcom server + vbtest.html - A Test webpage + vbtest.vbs - A VB script to be used with the cscript utility + + * If you are updating Gpgcom, run the old Gpgcom like this: + + c:\gnupg\gpgcom -UnregServer + + (Replace c:\gnupg with the actually used path) + + * Copy the file gpgcom.exe to a some location. C:\gnupg seems to be + a good choice. + + * Register the component using this command: + + c:\gnupg\gpgcom -RegServer + + * Ready + +Testing the installation: +------------------------- + + * Make sure that you have a working GnuPG (gpg.exe) and that at least + one key is installed. + + * Edit the vbtest.vbs script and replace "alice" in the line + + gpg.AddRecipient "alice" + + with a keyID or user name you have in your key ring. + + * Run the test script: + + cscript vbtest.vbs + + and you should see a valid MIME message with the encrypted text. + + +Using Gpgcom +------------ + +Gpgcom currently support only encryption but will be extended to the +full range of operations GnuPG provides. The 2 examples should goive +yopu a hint on how to use it. We suggest that you always set armor to +true, so that the returned text is a string. If you don't use armor, +the "ciphertext" property will return an array with the binary +message. + + + + diff --git a/tags/V0-3-4/complus/debug.c b/tags/V0-3-4/complus/debug.c new file mode 100644 index 0000000..d7cb0a0 --- /dev/null +++ b/tags/V0-3-4/complus/debug.c @@ -0,0 +1,40 @@ +/* debug.c - COM+ debug helpers + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + + +const char * +debugstr_guid (const GUID *id) +{ + static char str[100]; + + if (!id) + return "(null)"; + sprintf( str, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", + id->Data1, id->Data2, id->Data3, + id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3], + id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] ); + return str; +} + diff --git a/tags/V0-3-4/complus/example.c b/tags/V0-3-4/complus/example.c new file mode 100644 index 0000000..a7d838d --- /dev/null +++ b/tags/V0-3-4/complus/example.c @@ -0,0 +1,598 @@ +/* + * Copyright 1999 Marcus Meissner + */ +#include +#include +#include + +#include "winbase.h" +#include "winnls.h" +#include "mmsystem.h" +#include "winerror.h" +#include "debugtools.h" + +#include "initguid.h" +#include "vfw.h" + +DEFAULT_DEBUG_CHANNEL(avifile); + +static HRESULT WINAPI IAVIFile_fnQueryInterface(IAVIFile* iface,REFIID refiid,LPVOID *obj); +static ULONG WINAPI IAVIFile_fnAddRef(IAVIFile* iface); +static ULONG WINAPI IAVIFile_fnRelease(IAVIFile* iface); +static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile*iface,AVIFILEINFOW*afi,LONG size); +static HRESULT WINAPI IAVIFile_fnGetStream(IAVIFile*iface,PAVISTREAM*avis,DWORD fccType,LONG lParam); +static HRESULT WINAPI IAVIFile_fnCreateStream(IAVIFile*iface,PAVISTREAM*avis,AVISTREAMINFOW*asi); +static HRESULT WINAPI IAVIFile_fnWriteData(IAVIFile*iface,DWORD ckid,LPVOID lpData,LONG size); +static HRESULT WINAPI IAVIFile_fnReadData(IAVIFile*iface,DWORD ckid,LPVOID lpData,LONG *size); +static HRESULT WINAPI IAVIFile_fnEndRecord(IAVIFile*iface); +static HRESULT WINAPI IAVIFile_fnDeleteStream(IAVIFile*iface,DWORD fccType,LONG lParam); + +struct ICOM_VTABLE(IAVIFile) iavift = { + ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE + IAVIFile_fnQueryInterface, + IAVIFile_fnAddRef, + IAVIFile_fnRelease, + IAVIFile_fnInfo, + IAVIFile_fnGetStream, + IAVIFile_fnCreateStream, + IAVIFile_fnWriteData, + IAVIFile_fnReadData, + IAVIFile_fnEndRecord, + IAVIFile_fnDeleteStream +}; + +static HRESULT WINAPI IAVIStream_fnQueryInterface(IAVIStream*iface,REFIID refiid,LPVOID *obj); +static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream*iface); +static ULONG WINAPI IAVIStream_fnRelease(IAVIStream* iface); +static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream*iface,LPARAM lParam1,LPARAM lParam2); +static HRESULT WINAPI IAVIStream_fnInfo(IAVIStream*iface,AVISTREAMINFOW *psi,LONG size); +static LONG WINAPI IAVIStream_fnFindSample(IAVIStream*iface,LONG pos,LONG flags); +static HRESULT WINAPI IAVIStream_fnReadFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG *formatsize); +static HRESULT WINAPI IAVIStream_fnSetFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG formatsize); +static HRESULT WINAPI IAVIStream_fnRead(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread); +static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,DWORD flags,LONG *sampwritten,LONG *byteswritten); +static HRESULT WINAPI IAVIStream_fnDelete(IAVIStream*iface,LONG start,LONG samples); +static HRESULT WINAPI IAVIStream_fnReadData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG *lpread); +static HRESULT WINAPI IAVIStream_fnWriteData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG size); +static HRESULT WINAPI IAVIStream_fnSetInfo(IAVIStream*iface,AVISTREAMINFOW*info,LONG infolen); + +struct ICOM_VTABLE(IAVIStream) iavist = { + ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE + IAVIStream_fnQueryInterface, + IAVIStream_fnAddRef, + IAVIStream_fnRelease, + IAVIStream_fnCreate, + IAVIStream_fnInfo, + IAVIStream_fnFindSample, + IAVIStream_fnReadFormat, + IAVIStream_fnSetFormat, + IAVIStream_fnRead, + IAVIStream_fnWrite, + IAVIStream_fnDelete, + IAVIStream_fnReadData, + IAVIStream_fnWriteData, + IAVIStream_fnSetInfo +}; + +typedef struct IAVIStreamImpl { + /* IUnknown stuff */ + ICOM_VFIELD(IAVIStream); + DWORD ref; + /* IAVIStream stuff */ + LPVOID lpInputFormat; + DWORD inputformatsize; + BOOL iscompressing; + DWORD curframe; + + /* Compressor stuff */ + HIC hic; + LPVOID lpCompressFormat; + ICINFO icinfo; + DWORD compbufsize; + LPVOID compbuffer; + + DWORD decompbufsize; + LPVOID decompbuffer; + LPVOID decompformat; + AVICOMPRESSOPTIONS aco; + + LPVOID lpPrev; /* pointer to decompressed frame later */ + LPVOID lpPrevFormat; /* pointer to decompressed info later */ +} IAVIStreamImpl; + +/*********************************************************************** + * AVIFileInit + */ +void WINAPI +AVIFileInit(void) { + FIXME("(),stub!\n"); +} + +typedef struct IAVIFileImpl { + /* IUnknown stuff */ + ICOM_VFIELD(IAVIFile); + DWORD ref; + /* IAVIFile stuff... */ +} IAVIFileImpl; + +static HRESULT WINAPI IAVIFile_fnQueryInterface(IAVIFile* iface,REFIID refiid,LPVOID *obj) { + ICOM_THIS(IAVIFileImpl,iface); + + TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj); + if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) || + !memcmp(&IID_IAVIFile,refiid,sizeof(IID_IAVIFile)) + ) { + *obj = iface; + return S_OK; + } + return OLE_E_ENUM_NOMORE; +} + +static ULONG WINAPI IAVIFile_fnAddRef(IAVIFile* iface) { + ICOM_THIS(IAVIFileImpl,iface); + + FIXME("(%p)->AddRef()\n",iface); + return ++(This->ref); +} + +static ULONG WINAPI IAVIFile_fnRelease(IAVIFile* iface) { + ICOM_THIS(IAVIFileImpl,iface); + + FIXME("(%p)->Release()\n",iface); + if (!--(This->ref)) { + HeapFree(GetProcessHeap(),0,iface); + return 0; + } + return This->ref; +} + +static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile*iface,AVIFILEINFOW*afi,LONG size) { + FIXME("(%p)->Info(%p,%ld)\n",iface,afi,size); + + /* FIXME: fill out struct? */ + return E_FAIL; +} + +static HRESULT WINAPI IAVIFile_fnGetStream(IAVIFile*iface,PAVISTREAM*avis,DWORD fccType,LONG lParam) { + FIXME("(%p)->GetStream(%p,0x%08lx,%ld)\n",iface,avis,fccType,lParam); + /* FIXME: create interface etc. */ + return E_FAIL; +} + +static HRESULT WINAPI IAVIFile_fnCreateStream(IAVIFile*iface,PAVISTREAM*avis,AVISTREAMINFOW*asi) { + ICOM_THIS(IAVIStreamImpl,iface); + char fcc[5]; + IAVIStreamImpl *istream; + + FIXME("(%p,%p,%p)\n",This,avis,asi); + istream = (IAVIStreamImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IAVIStreamImpl)); + istream->ref = 1; + ICOM_VTBL(istream) = &iavist; + fcc[4]='\0'; + memcpy(fcc,(char*)&(asi->fccType),4); + FIXME("\tfccType '%s'\n",fcc); + memcpy(fcc,(char*)&(asi->fccHandler),4); + FIXME("\tfccHandler '%s'\n",fcc); + FIXME("\tdwFlags 0x%08lx\n",asi->dwFlags); + FIXME("\tdwCaps 0x%08lx\n",asi->dwCaps); + FIXME("\tname '%s'\n",debugstr_w(asi->szName)); + + istream->curframe = 0; + *avis = (PAVISTREAM)istream; + return S_OK; +} + +static HRESULT WINAPI IAVIFile_fnWriteData(IAVIFile*iface,DWORD ckid,LPVOID lpData,LONG size) { + FIXME("(%p)->WriteData(0x%08lx,%p,%ld)\n",iface,ckid,lpData,size); + /* FIXME: write data to file */ + return E_FAIL; +} + +static HRESULT WINAPI IAVIFile_fnReadData(IAVIFile*iface,DWORD ckid,LPVOID lpData,LONG *size) { + FIXME("(%p)->ReadData(0x%08lx,%p,%p)\n",iface,ckid,lpData,size); + /* FIXME: read at most size bytes from file */ + return E_FAIL; +} + +static HRESULT WINAPI IAVIFile_fnEndRecord(IAVIFile*iface) { + FIXME("(%p)->EndRecord()\n",iface); + /* FIXME: end record? */ + return E_FAIL; +} + +static HRESULT WINAPI IAVIFile_fnDeleteStream(IAVIFile*iface,DWORD fccType,LONG lParam) { + FIXME("(%p)->DeleteStream(0x%08lx,%ld)\n",iface,fccType,lParam); + /* FIXME: delete stream? */ + return E_FAIL; +} + +/*********************************************************************** + * AVIFileOpenA + */ +HRESULT WINAPI AVIFileOpenA( + PAVIFILE * ppfile,LPCSTR szFile,UINT uMode,LPCLSID lpHandler +) { + IAVIFileImpl *iavi; + + FIXME("(%p,%s,0x%08lx,%s),stub!\n",ppfile,szFile,(DWORD)uMode,debugstr_guid(lpHandler)); + iavi = (IAVIFileImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IAVIFileImpl)); + iavi->ref = 1; + ICOM_VTBL(iavi) = &iavift; + *ppfile = (LPVOID)iavi; + return S_OK; +} + +static HRESULT WINAPI IAVIStream_fnQueryInterface(IAVIStream*iface,REFIID refiid,LPVOID *obj) { + ICOM_THIS(IAVIStreamImpl,iface); + + TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj); + if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) || + !memcmp(&IID_IAVIStream,refiid,sizeof(IID_IAVIStream)) + ) { + *obj = This; + return S_OK; + } + /* can return IGetFrame interface too */ + return OLE_E_ENUM_NOMORE; +} + +static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream*iface) { + ICOM_THIS(IAVIStreamImpl,iface); + + FIXME("(%p)->AddRef()\n",iface); + return ++(This->ref); +} + +static ULONG WINAPI IAVIStream_fnRelease(IAVIStream* iface) { + ICOM_THIS(IAVIStreamImpl,iface); + + FIXME("(%p)->Release()\n",iface); + if (!--(This->ref)) { + HeapFree(GetProcessHeap(),0,This); + return 0; + } + return This->ref; +} + +static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream*iface,LPARAM lParam1,LPARAM lParam2) { + FIXME("(%p)->Create(0x%08lx,0x%08lx)\n",iface,lParam1,lParam2); + return E_FAIL; +} + +static HRESULT WINAPI IAVIStream_fnInfo(IAVIStream*iface,AVISTREAMINFOW *psi,LONG size) { + FIXME("(%p)->Info(%p,%ld)\n",iface,psi,size); + return E_FAIL; +} + +static LONG WINAPI IAVIStream_fnFindSample(IAVIStream*iface,LONG pos,LONG flags) { + FIXME("(%p)->FindSample(%ld,0x%08lx)\n",iface,pos,flags); + return E_FAIL; +} + +static HRESULT WINAPI IAVIStream_fnReadFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG *formatsize) { + FIXME("(%p)->ReadFormat(%ld,%p,%p)\n",iface,pos,format,formatsize); + return E_FAIL; +} + +/*********************************************************************** + * IAVIStream::SetFormat + */ +static HRESULT WINAPI IAVIStream_fnSetFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG formatsize) { + IAVIStreamImpl *as = (IAVIStreamImpl*)iface; + + FIXME("(%p)->SetFormat(%ld,%p,%ld)\n",iface,pos,format,formatsize); + if (as->lpInputFormat) HeapFree(GetProcessHeap(),0,as->lpInputFormat); + as->inputformatsize = formatsize; + as->lpInputFormat = HeapAlloc(GetProcessHeap(),0,formatsize); + memcpy(as->lpInputFormat,format,formatsize); + if (as->iscompressing) { + int xsize; + /* Set up the Compressor part */ + xsize = ICCompressGetFormatSize(as->hic,as->lpInputFormat); + as->lpCompressFormat = HeapAlloc(GetProcessHeap(),0,xsize); + ICCompressGetFormat(as->hic,as->lpInputFormat,as->lpCompressFormat); + ICCompressBegin(as->hic,as->lpInputFormat,as->lpCompressFormat); + as->compbufsize = ICCompressGetSize(as->hic,as->lpInputFormat,as->lpCompressFormat); + as->compbuffer = HeapAlloc(GetProcessHeap(),0,as->compbufsize); + + /* Set up the Decompressor part (for prev frames?) */ + xsize=ICDecompressGetFormatSize(as->hic,as->lpCompressFormat); + as->decompformat = HeapAlloc(GetProcessHeap(),0,xsize); + ICDecompressGetFormat(as->hic,as->lpCompressFormat,as->decompformat); + as->decompbufsize=((LPBITMAPINFOHEADER)as->decompbuffer)->biSizeImage; + as->decompbuffer = HeapReAlloc(GetProcessHeap(),0,as->decompbuffer,as->decompbufsize); + memset(as->decompbuffer,0xff,as->decompbufsize); + assert(HeapValidate(GetProcessHeap(),0,NULL)); + + ICDecompressGetFormat(as->hic,as->lpCompressFormat,as->decompformat); + ICDecompressBegin(as->hic,as->lpCompressFormat,as->decompformat); + as->lpPrev = as->lpPrevFormat = NULL; + } + return S_OK; +} + +static HRESULT WINAPI IAVIStream_fnRead(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread) { + FIXME("(%p)->Read(%ld,%ld,%p,%ld,%p,%p)\n",iface,start,samples,buffer,buffersize,bytesread,samplesread); + return E_FAIL; +} + +static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,DWORD flags,LONG *sampwritten,LONG *byteswritten) { + IAVIStreamImpl *as = (IAVIStreamImpl*)iface; + DWORD ckid,xflags; + + FIXME("(%p)->Write(%ld,%ld,%p,%ld,0x%08lx,%p,%p)\n",iface,start,samples,buffer,buffersize,flags,sampwritten,byteswritten); + + ICCompress( + as->hic,flags, + as->lpCompressFormat, + as->compbuffer, + as->lpInputFormat,buffer, + &ckid,&xflags, + as->curframe,0xffffff/*framesize*/,as->aco.dwQuality, + as->lpPrevFormat,as->lpPrev + ); + ICDecompress( + as->hic, + flags, /* FIXME: check */ + as->lpCompressFormat, + as->compbuffer, + as->decompformat, + as->decompbuffer + ); + /* We now have a prev format for the next compress ... */ + as->lpPrevFormat = as->decompformat; + as->lpPrev = as->decompbuffer; + return S_OK; +} + +static HRESULT WINAPI IAVIStream_fnDelete(IAVIStream*iface,LONG start,LONG samples) { + FIXME("(%p)->Delete(%ld,%ld)\n",iface,start,samples); + return E_FAIL; +} +static HRESULT WINAPI IAVIStream_fnReadData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG *lpread) { + FIXME("(%p)->ReadData(0x%08lx,%p,%p)\n",iface,fcc,lp,lpread); + return E_FAIL; +} + +static HRESULT WINAPI IAVIStream_fnWriteData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG size) { + FIXME("(%p)->WriteData(0x%08lx,%p,%ld)\n",iface,fcc,lp,size); + return E_FAIL; +} + +static HRESULT WINAPI IAVIStream_fnSetInfo(IAVIStream*iface,AVISTREAMINFOW*info,LONG infolen) { + FIXME("(%p)->SetInfo(%p,%ld)\n",iface,info,infolen); + return E_FAIL; +} + +/*********************************************************************** + * AVIFileCreateStreamA + */ +HRESULT WINAPI AVIFileCreateStreamA(PAVIFILE iface,PAVISTREAM *ppavi,AVISTREAMINFOA * psi) { + AVISTREAMINFOW psiw; + + /* Only the szName at the end is different */ + memcpy(&psiw,psi,sizeof(*psi)-sizeof(psi->szName)); + MultiByteToWideChar( CP_ACP, 0, psi->szName, -1, + psiw.szName, sizeof(psiw.szName) / sizeof(WCHAR) ); + return IAVIFile_CreateStream(iface,ppavi,&psiw); +} + +/*********************************************************************** + * AVIFileCreateStreamW + */ +HRESULT WINAPI AVIFileCreateStreamW(IAVIFile*iface,PAVISTREAM*avis,AVISTREAMINFOW*asi) { + return IAVIFile_CreateStream(iface,avis,asi); +} + + +/*********************************************************************** + * AVIFileGetStream + */ +HRESULT WINAPI AVIFileGetStream(IAVIFile*iface,PAVISTREAM*avis,DWORD fccType,LONG lParam) { + return IAVIFile_GetStream(iface,avis,fccType,lParam); +} + +/*********************************************************************** + * AVIFileInfoA + */ +HRESULT WINAPI AVIFileInfoA(PAVIFILE iface,LPAVIFILEINFOA afi,LONG size) { + AVIFILEINFOW afiw; + HRESULT hres; + + if (size < sizeof(AVIFILEINFOA)) + return AVIERR_BADSIZE; + hres = IAVIFile_Info(iface,&afiw,sizeof(afiw)); + memcpy(afi,&afiw,sizeof(*afi)-sizeof(afi->szFileType)); + WideCharToMultiByte( CP_ACP, 0, afiw.szFileType, -1, + afi->szFileType, sizeof(afi->szFileType), NULL, NULL ); + afi->szFileType[sizeof(afi->szFileType)-1] = 0; + return hres; +} + +/*********************************************************************** + * AVIStreamInfoW + */ +HRESULT WINAPI AVIStreamInfoW(PAVISTREAM iface,AVISTREAMINFOW *asi,LONG + size) { + return IAVIFile_Info(iface,asi,size); +} + +/*********************************************************************** + * AVIStreamInfoA + */ +HRESULT WINAPI AVIStreamInfoA(PAVISTREAM iface,AVISTREAMINFOA *asi,LONG + size) { + AVISTREAMINFOW asiw; + HRESULT hres; + + if (sizeszName, sizeof(asi->szName), NULL, NULL ); + asi->szName[sizeof(asi->szName)-1] = 0; + return hres; +} + +/*********************************************************************** + * AVIFileInfoW + */ +HRESULT WINAPI AVIFileInfoW(PAVIFILE iface,LPAVIFILEINFOW afi,LONG size) { + return IAVIFile_Info(iface,afi,size); +} + +/*********************************************************************** + * AVIMakeCompressedStream + */ +HRESULT WINAPI AVIMakeCompressedStream(PAVISTREAM *ppsCompressed,PAVISTREAM ppsSource,AVICOMPRESSOPTIONS *aco,CLSID *pclsidHandler) { + char fcc[5]; + IAVIStreamImpl *as; + FIXME("(%p,%p,%p,%p)\n",ppsCompressed,ppsSource,aco,pclsidHandler); + fcc[4]='\0'; + memcpy(fcc,&(aco->fccType),4); + FIXME("\tfccType: '%s'\n",fcc); + memcpy(fcc,&(aco->fccHandler),4); + FIXME("\tfccHandler: '%s'\n",fcc); + FIXME("\tdwFlags: 0x%08lx\n",aco->dwFlags); + + /* we just create a duplicate for now */ + IAVIStream_AddRef(ppsSource); + *ppsCompressed = ppsSource; + as = (IAVIStreamImpl*)ppsSource; + + /* this is where the fun begins. Open a compressor and prepare it. */ + as->hic = ICOpen(aco->fccType,aco->fccHandler,ICMODE_COMPRESS); + + /* May happen. for instance if the codec is not able to compress */ + if (!as->hic) + return AVIERR_UNSUPPORTED; + + ICGetInfo(as->hic,&(as->icinfo),sizeof(ICINFO)); + FIXME("Opened compressor: '%s' '%s'\n",debugstr_w(as->icinfo.szName),debugstr_w(as->icinfo.szDescription)); + as->iscompressing = TRUE; + memcpy(&(as->aco),aco,sizeof(*aco)); + if (as->icinfo.dwFlags & VIDCF_COMPRESSFRAMES) { + ICCOMPRESSFRAMES icf; + + /* now what to fill in there ... Hmm */ + memset(&icf,0,sizeof(icf)); + icf.lDataRate = aco->dwBytesPerSecond; + icf.lQuality = aco->dwQuality; + icf.lKeyRate = aco->dwKeyFrameEvery; + + icf.GetData = (void *)0xdead4242; + icf.PutData = (void *)0xdead4243; + ICSendMessage(as->hic,ICM_COMPRESS_FRAMES_INFO,(LPARAM)&icf,sizeof(icf)); + } + return S_OK; +} + +/*********************************************************************** + * AVIStreamSetFormat + */ +HRESULT WINAPI AVIStreamSetFormat(PAVISTREAM iface,LONG pos,LPVOID format,LONG formatsize) { + return IAVIStream_SetFormat(iface,pos,format,formatsize); +} + +/*********************************************************************** + * AVIStreamReadFormat + */ +HRESULT WINAPI AVIStreamReadFormat(PAVISTREAM iface,LONG pos,LPVOID format,LONG *formatsize) { + return IAVIStream_ReadFormat(iface,pos,format,formatsize); +} + +/*********************************************************************** + * AVIStreamWrite( + */ +HRESULT WINAPI AVIStreamWrite(PAVISTREAM iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,DWORD flags,LONG *sampwritten,LONG *byteswritten) { + return IAVIStream_Write(iface,start,samples,buffer,buffersize,flags,sampwritten,byteswritten); +} + +/*********************************************************************** + * AVIStreamRead + */ +HRESULT WINAPI AVIStreamRead(PAVISTREAM iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread) { + return IAVIStream_Read(iface,start,samples,buffer,buffersize,bytesread,samplesread); +} + +/*********************************************************************** + * AVIStreamWriteData + */ +HRESULT WINAPI AVIStreamWriteData(PAVISTREAM iface,DWORD fcc,LPVOID lp,LONG size) { + return IAVIStream_WriteData(iface,fcc,lp,size); +} + +/*********************************************************************** + * AVIStreamReadData + */ +HRESULT WINAPI AVIStreamReadData(PAVISTREAM iface,DWORD fcc,LPVOID lp,LONG *lpread) { + return IAVIStream_ReadData(iface,fcc,lp,lpread); +} + +/*********************************************************************** + * AVIStreamStart + */ +LONG WINAPI AVIStreamStart(PAVISTREAM iface) { + AVISTREAMINFOW si; + + IAVIStream_Info(iface,&si,sizeof(si)); + return si.dwStart; +} + +/*********************************************************************** + * AVIStreamLength + */ +LONG WINAPI AVIStreamLength(PAVISTREAM iface) { + AVISTREAMINFOW si; + HRESULT ret; + + ret = IAVIStream_Info(iface,&si,sizeof(si)); + if (ret) /* error */ + return 1; + return si.dwLength; +} + +/*********************************************************************** + * AVIStreamRelease + */ +ULONG WINAPI AVIStreamRelease(PAVISTREAM iface) { + return IAVIStream_Release(iface); +} + +/*********************************************************************** + * AVIStreamGetFrameOpen + */ +PGETFRAME WINAPI AVIStreamGetFrameOpen(PAVISTREAM iface,LPBITMAPINFOHEADER bmi) { + FIXME("(%p)->(%p),stub!\n",iface,bmi); + return NULL; +} + +/*********************************************************************** + * AVIStreamGetFrame + */ +LPVOID WINAPI AVIStreamGetFrame(PGETFRAME pg,LONG pos) { + return IGetFrame_GetFrame(pg,pos); +} + +/*********************************************************************** + * AVIStreamGetFrameClose + */ +HRESULT WINAPI AVIStreamGetFrameClose(PGETFRAME pg) { + if (pg) IGetFrame_Release(pg); + return 0; +} + +/*********************************************************************** + * AVIFileRelease + */ +ULONG WINAPI AVIFileRelease(PAVIFILE iface) { + return IAVIFile_Release(iface); +} + +/*********************************************************************** + * AVIFileExit + */ +void WINAPI AVIFileExit(void) { + FIXME("(), stub.\n"); +} diff --git a/tags/V0-3-4/complus/gpgcom.c b/tags/V0-3-4/complus/gpgcom.c new file mode 100644 index 0000000..7c967be --- /dev/null +++ b/tags/V0-3-4/complus/gpgcom.c @@ -0,0 +1,545 @@ +/* gpgcom.c - COM+ component to access GnuPG + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "argparse.h" + +#include "main.h" +#include "igpgme.h" + +static void register_server (void); +static void unregister_server (void); +static void enter_complus (void); + + +enum cmd_and_opt_values { aNull = 0, + oQuiet = 'q', + oVerbose = 'v', + + oNoVerbose = 500, + oOptions, + oDebug, + oDebugAll, + oNoGreeting, + oNoOptions, + oHomedir, + oGPGBinary, + oRegServer, + oUnregServer, + oEmbedding, +aTest }; + + +static ARGPARSE_OPTS opts[] = { + + { 301, NULL, 0, N_("@Options:\n ") }, + + { oVerbose, "verbose", 0, N_("verbose") }, + { oQuiet, "quiet", 0, N_("be somewhat more quiet") }, + { oOptions, "options" , 2, N_("read options from file")}, + { oDebug, "debug" ,4|16, N_("set debugging flags")}, + { oDebugAll, "debug-all" ,0, N_("enable full debugging")}, + { oGPGBinary, "gpg-program", 2 , "" }, + { oRegServer, "RegServer" , 0, "" }, + { oUnregServer, "UnregServer" , 0, "" }, + { oEmbedding, "Embedding" , 0, "" }, +{0} }; + + + + +static const char * +my_strusage( int level ) +{ + const char *p; + switch( level ) { + case 11: p = "gpgcom"; + break; + case 13: p = VERSION; break; + /*case 17: p = PRINTABLE_OS_NAME; break;*/ + case 19: p = + _("Please report bugs to .\n"); + break; + case 1: + case 40: p = + _("Usage: gpgcom [options] (-h for help)"); + break; + case 41: p = + _("Syntax: gpgcom [options]\n" + "GnuPG COM+ component\n"); + break; + + default: p = NULL; + } + return p; +} + + +int +main (int argc, char **argv ) +{ + ARGPARSE_ARGS pargs; + int orig_argc; + char **orig_argv; + FILE *configfp = NULL; + char *configname = NULL; + unsigned configlineno; + int parse_debug = 0; + int default_config =1; + int greeting = 0; + int nogreeting = 0; + int action = 0; + + set_strusage( my_strusage ); + /*log_set_name ("gpa"); not yet implemented in logging.c */ + + opt.homedir = getenv("GNUPGHOME"); + if( !opt.homedir || !*opt.homedir ) { + #ifdef HAVE_DRIVE_LETTERS + opt.homedir = "c:/gnupg"; + #else + opt.homedir = "~/.gnupg"; + #endif + } + + /* check whether we have a config file on the commandline */ + orig_argc = argc; + orig_argv = argv; + pargs.argc = &argc; + pargs.argv = &argv; + pargs.flags= 1|(1<<6); /* do not remove the args, ignore version */ + while( arg_parse( &pargs, opts) ) { + if( pargs.r_opt == oDebug || pargs.r_opt == oDebugAll ) + parse_debug++; + else if( pargs.r_opt == oOptions ) { + /* yes there is one, so we do not try the default one, but + * read the option file when it is encountered at the commandline + */ + default_config = 0; + } + else if( pargs.r_opt == oNoOptions ) + default_config = 0; /* --no-options */ + else if( pargs.r_opt == oHomedir ) + opt.homedir = pargs.r.ret_str; + } + + if( default_config ) + configname = make_filename(opt.homedir, "gpgme.conf", NULL ); + + + argc = orig_argc; + argv = orig_argv; + pargs.argc = &argc; + pargs.argv = &argv; + pargs.flags= 1 | (1<<5); /* do not remove the args, allow one dash */ + next_pass: + if( configname ) { + configlineno = 0; + configfp = fopen( configname, "r" ); + if( !configfp ) { + if( default_config ) { + if( parse_debug ) + log_info(_("NOTE: no default option file `%s'\n"), + configname ); + } + else { + log_error(_("option file `%s': %s\n"), + configname, strerror(errno) ); + exit(2); + } + free(configname); configname = NULL; + } + if( parse_debug && configname ) + log_info(_("reading options from `%s'\n"), configname ); + default_config = 0; + } + + while( optfile_parse( configfp, configname, &configlineno, + &pargs, opts) ) { + switch( pargs.r_opt ) { + case oQuiet: opt.quiet = 1; break; + case oVerbose: opt.verbose++; break; + + case oDebug: opt.debug |= pargs.r.ret_ulong; break; + case oDebugAll: opt.debug = ~0; break; + + case oOptions: + /* config files may not be nested (silently ignore them) */ + if( !configfp ) { + free(configname); + configname = xstrdup(pargs.r.ret_str); + goto next_pass; + } + break; + case oNoGreeting: nogreeting = 1; break; + case oNoVerbose: opt.verbose = 0; break; + case oNoOptions: break; /* no-options */ + case oHomedir: opt.homedir = pargs.r.ret_str; break; + case oGPGBinary: break; + + case oRegServer: action = 1; break; + case oUnregServer: action = 2; break; + case oEmbedding: action = 3; break; + + default : pargs.err = configfp? 1:2; break; + } + } + if( configfp ) { + fclose( configfp ); + configfp = NULL; + free(configname); configname = NULL; + goto next_pass; + } + free( configname ); configname = NULL; + if( log_get_errorcount(0) ) + exit(2); + if( nogreeting ) + greeting = 0; + + if( greeting ) { + fprintf(stderr, "%s %s; %s\n", + strusage(11), strusage(13), strusage(14) ); + fprintf(stderr, "%s\n", strusage(15) ); + } + #ifdef IS_DEVELOPMENT_VERSION + log_info("NOTE: this is a development version!\n"); + #endif + + if ( action == 1 ) + register_server (); + else if (action == 2 ) + unregister_server (); + else if (action == 3 ) + enter_complus (); + else { + fprintf (stderr, "This is a COM+ component with no user interface.\n" + "gpgme --help will give you a list of options\n" ); + exit (1); + } + + return 0; +} + + +static void +register_progid ( const char *name ) +{ + HKEY hk = 0; + char buf[500]; + + /* Create a ProgID entry to point to the ClassID */ + sprintf (buf, "%.400s", name); + if (RegCreateKeyA (HKEY_CLASSES_ROOT, buf, &hk)) { + fprintf (stderr,"RegCreateKey(`%s') failed\n", buf); + exit (1); + } + sprintf (buf, "g10 Code's GnuPG made easy COMponent" ); + if (RegSetValueExA (hk, 0, 0, REG_SZ, buf, 0)) { + fprintf (stderr,"RegSetValueEx(`%s') failed\n", buf); + exit (1); + } + if (RegCloseKey (hk)) { + fprintf (stderr,"RegCloseKey() failed\n"); + exit (1); + } + sprintf (buf, "%.400s\\CLSID", name); + if (RegCreateKeyA (HKEY_CLASSES_ROOT, buf, &hk)) { + fprintf (stderr,"RegCreateKey(`%s') failed\n", buf); + exit (1); + } + sprintf (buf, "%.100s", debugstr_guid (&CLSID_Gpgme) ); + if (RegSetValueExA (hk, 0, 0, REG_SZ, buf, strlen (buf))) { + fprintf (stderr,"RegSetValueEx(`%s') failed\n", buf); + exit (1); + } + if (RegCloseKey (hk)) { + fprintf (stderr,"RegCloseKey() failed\n"); + exit (1); + } + hk = 0; +} + + +static void +register_typelib (void) +{ + ITypeLib *pTypeLib; + HRESULT hr; + char name[500]; + wchar_t *wname; + size_t n; + + if ( !GetModuleFileNameA (0, name, sizeof (name)-10) ) { + fprintf (stderr,"GetModuleFileName() failed: %d\n", + (int)GetLastError()); + exit (1); + } + n = mbstowcs (NULL, name, strlen(name)+1); + wname = xmalloc ((n+1)*sizeof *wname); + mbstowcs (wname, name, strlen (name)+1); + + hr = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED); + if (hr) + fprintf (stderr, "CoInitializeEx() failed: hr=%lu\n", hr); + + hr = LoadTypeLibEx (wname, REGKIND_REGISTER, &pTypeLib); + if (hr) + fprintf (stderr, "LoadTypeLibEx() failed: hr=%lx\n", hr); + + ITypeLib_Release (pTypeLib); + CoUninitialize (); + free (wname); +} + +static void +unregister_typelib (void) +{ + UnRegisterTypeLib (&TLBID_Gpgcom, 1, 0, LANG_NEUTRAL, SYS_WIN32); +} + +static void +register_server () +{ + HKEY hk = 0; + char buf[500]; + + + register_typelib (); + + /* Create a key for the CLSID */ + sprintf (buf, "CLSID\\%.100s", debugstr_guid (&CLSID_Gpgme) ); + if (RegCreateKeyA (HKEY_CLASSES_ROOT, buf, &hk)) { + fprintf (stderr,"RegCreateKey(`%s') failed\n", buf); + exit (1); + } + /* Store our class name as default value */ + strcpy (buf, "Gpgme"); + if (RegSetValueExA (hk, 0, 0, REG_SZ, buf, strlen (buf))) { + fprintf (stderr,"RegSetValueEx(`%s') failed\n", buf); + exit (1); + } + + /* Set the application ID */ + sprintf (buf, "%.100s", debugstr_guid (&APPID_Gpgcom) ); + if (RegSetValueExA (hk, "AppID", 0, REG_SZ, buf, strlen (buf))) { + fprintf (stderr,"RegSetValueEx(`%s') failed\n", buf); + exit (1); + } + if (RegCloseKey (hk)) { + fprintf (stderr,"RegCloseKey() failed\n"); + exit (1); + } + hk = 0; + + /* Create the LocalServer32 subkey under the CLSID key */ + sprintf (buf, "CLSID\\%.100s\\LocalServer32", + debugstr_guid (&CLSID_Gpgme) ); + if (RegCreateKeyA (HKEY_CLASSES_ROOT, buf, &hk)) { + fprintf (stderr,"RegCreateKey(`%s') failed\n", buf); + exit (1); + } + /* retrieve the module name and add it under the key */ + if ( !GetModuleFileNameA (0, buf, sizeof (buf)-10) ) { + fprintf (stderr,"GetModuleFileName() failed\n"); + exit (1); + } + if (RegSetValueExA (hk, 0, 0, REG_SZ, buf, strlen (buf))) { + fprintf (stderr,"RegSetValueEx(`%s') failed\n", buf); + exit (1); + } + if (RegCloseKey (hk)) { + fprintf (stderr,"RegCloseKey() failed\n"); + exit (1); + } + hk = 0; + + /* Create the ProgID subkey under the CLSID key */ + sprintf (buf, "CLSID\\%.100s\\ProgID", + debugstr_guid (&CLSID_Gpgme) ); + if (RegCreateKeyA (HKEY_CLASSES_ROOT, buf, &hk)) { + fprintf (stderr,"RegCreateKey(`%s') failed\n", buf); + exit (1); + } + if (RegSetValueExA (hk, 0, 0, REG_SZ, "Gpgcom.Gpgme.1", 0)) { + fprintf (stderr,"RegSetValueEx(`%s') failed\n", buf); + exit (1); + } + if (RegCloseKey (hk)) { + fprintf (stderr,"RegCloseKey() failed\n"); + exit (1); + } + hk = 0; + /* Create the VersionIndependentProgID subkey under the CLSID key */ + sprintf (buf, "CLSID\\%.100s\\VersionIndependentProgID", + debugstr_guid (&CLSID_Gpgme) ); + if (RegCreateKeyA (HKEY_CLASSES_ROOT, buf, &hk)) { + fprintf (stderr,"RegCreateKey(`%s') failed\n", buf); + exit (1); + } + if (RegSetValueExA (hk, 0, 0, REG_SZ, "Gpgcom.Gpgme", 0)) { + fprintf (stderr,"RegSetValueEx(`%s') failed\n", buf); + exit (1); + } + if (RegCloseKey (hk)) { + fprintf (stderr,"RegCloseKey() failed\n"); + exit (1); + } + hk = 0; + + + /* Create a key to store AppID info */ + sprintf (buf, "AppID\\%.100s", debugstr_guid (&APPID_Gpgcom) ); + if (RegCreateKeyA (HKEY_CLASSES_ROOT, buf, &hk)) { + fprintf (stderr,"RegCreateKey(`%s') failed\n", buf); + exit (1); + } + /* Store the name as default value */ + strcpy (buf, "Gpgcom"); + if (RegSetValueExA (hk, 0, 0, REG_SZ, buf, strlen (buf))) { + fprintf (stderr,"RegSetValueEx(`%s') failed\n", buf); + exit (1); + } + if (RegCloseKey (hk)) { + fprintf (stderr,"RegCloseKey() failed\n"); + exit (1); + } + hk = 0; + + register_progid ("Gpgcom.Gpgme"); + register_progid ("Gpgcom.Gpgme.1"); + + /* Create a convenience cross reference to the AppID */ + sprintf (buf, "AppID\\gpgcom.exe"); + if (RegCreateKeyA (HKEY_CLASSES_ROOT, buf, &hk)) { + fprintf (stderr,"RegCreateKey(`%s') failed\n", buf); + exit (1); + } + sprintf (buf, "%.100s", debugstr_guid (&APPID_Gpgcom) ); + if (RegSetValueExA (hk, "AppID", 0, REG_SZ, buf, strlen (buf))) { + fprintf (stderr,"RegSetValueEx(`%s') failed\n", buf); + exit (1); + } + if (RegCloseKey (hk)) { + fprintf (stderr,"RegCloseKey() failed\n"); + exit (1); + } + hk = 0; + + fprintf (stderr,"*** Component registered\n"); +} + +static void +unregister_server () +{ + char buf[500]; + + unregister_typelib (); + sprintf (buf, "CLSID\\%.100s\\LocalServer32", + debugstr_guid (&CLSID_Gpgme) ); + if (RegDeleteKey (HKEY_CLASSES_ROOT, buf)) + fprintf (stderr,"RegDeleteKey(`%s') failed\n", buf); + + sprintf (buf, "CLSID\\%.100s\\ProgID", debugstr_guid (&CLSID_Gpgme) ); + if (RegDeleteKey (HKEY_CLASSES_ROOT, buf)) + fprintf (stderr,"RegDeleteKey(`%s') failed\n", buf); + + sprintf (buf, "CLSID\\%.100s", debugstr_guid (&CLSID_Gpgme) ); + if (RegDeleteKey (HKEY_CLASSES_ROOT, buf)) + fprintf (stderr,"RegDeleteKey(`%s') failed\n", buf); + + sprintf (buf, "Gpgcom.Gpgme.1\\CLSID"); + if (RegDeleteKey (HKEY_CLASSES_ROOT, buf)) + fprintf (stderr,"RegDeleteKey(`%s') failed\n", buf); + sprintf (buf, "Gpgcom.Gpgme.1"); + if (RegDeleteKey (HKEY_CLASSES_ROOT, buf)) + fprintf (stderr,"RegDeleteKey(`%s') failed\n", buf); + + sprintf (buf, "Gpgcom.Gpgme\\CLSID"); + if (RegDeleteKey (HKEY_CLASSES_ROOT, buf)) + fprintf (stderr,"RegDeleteKey(`%s') failed\n", buf); + sprintf (buf, "Gpgcom.Gpgme"); + if (RegDeleteKey (HKEY_CLASSES_ROOT, buf)) + fprintf (stderr,"RegDeleteKey(`%s') failed\n", buf); + + + sprintf (buf, "AppID\\%.100s", debugstr_guid (&APPID_Gpgcom) ); + if (RegDeleteKey (HKEY_CLASSES_ROOT, buf)) + fprintf (stderr,"RegDeleteKey(`%s') failed\n", buf); + + sprintf (buf, "AppID\\gpgcom.exe" ); + if (RegDeleteKey (HKEY_CLASSES_ROOT, buf)) + fprintf (stderr,"RegDeleteKey(`%s') failed\n", buf); + + fprintf (stderr,"*** component unregistered\n"); +} + + +static void +enter_complus () +{ + HANDLE running; + DWORD reg; + IClassFactory *factory; + CLSID clsid; + HRESULT hr; + + fprintf (stderr,"*** enter enter_complus()\n"); + CoInitializeEx (NULL, COINIT_MULTITHREADED); + running = CreateEvent (NULL, FALSE, FALSE, NULL ); + fprintf (stderr,"*** CoInitialize() done; event=%lx\n", (unsigned long)running ); + + igpgme_register_exit_event (running); + factory = igpgme_factory_new ( &clsid ); + fprintf (stderr,"*** igpgme_factory_new() done; got=%p\n", factory ); + hr = CoRegisterClassObject (&clsid, (IUnknown*)factory, + CLSCTX_LOCAL_SERVER, + REGCLS_SUSPENDED|REGCLS_MULTIPLEUSE, ® ); + if (hr) { + fprintf (stderr, "CoRegisterClassObject() failed: hr=%lx\n", hr); + exit (1); + } + hr = CoResumeClassObjects (); + if (hr) + fprintf (stderr, "CoRegisterClassObject() failed: hr=%lx\n", hr); + fprintf (stderr,"*** class object registered; waiting\n" ); + + WaitForSingleObject ( running, INFINITE ); + fprintf (stderr,"*** shutting down\n" ); + igpgme_register_exit_event (NULL); + CloseHandle (running); + CoRevokeClassObject ( reg ); + fprintf (stderr,"*** class object revoked\n" ); + igpgme_factory_release (factory); + fprintf (stderr,"*** factory released\n" ); + CoUninitialize (); + fprintf (stderr,"*** leave enter_complus()\n" ); +} + diff --git a/tags/V0-3-4/complus/gpgcom.idl b/tags/V0-3-4/complus/gpgcom.idl new file mode 100644 index 0000000..654eec0 --- /dev/null +++ b/tags/V0-3-4/complus/gpgcom.idl @@ -0,0 +1,62 @@ +/* ignupg.idl - Interface definition for the COM+ class GnuPG + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + + +import "unknwn.idl"; +import "oaidl.idl"; + + +[ object, uuid(3811fd50-7f72-11d5-8c9e-0080ad190cd5), dual] +interface IGpgme : IDispatch +{ + HRESULT GetVersion([out] BSTR *retval); + HRESULT GetEngineInfo([out] BSTR *retval); + HRESULT Cancel(void); + [propput] HRESULT Armor([in] BOOL flag); + [propget] HRESULT Armor([out, retval] BOOL *retval); + [propput] HRESULT Textmode([in] BOOL flag); + [propget] HRESULT Textmode([out, retval] BOOL *retval); + [propput] HRESULT Plaintext([in] VARIANT val); + [propget] HRESULT Plaintext([out, retval] VARIANT *retval); + [propput] HRESULT Ciphertext([in] VARIANT val); + [propget] HRESULT Ciphertext([out,retval] VARIANT *retval); + HRESULT ClearRecipients(void); + HRESULT AddRecipient([in] BSTR name, + [in, optional, defaultvalue(-1)] signed short trust); + HRESULT ResetSignKeys(void); + HRESULT AddSignKey([in] BSTR name); + HRESULT Encrypt(void); + HRESULT Sign([in,optional,defaultvalue(0)] signed short signmode); + HRESULT SignEncrypt([in,optional,defaultvalue(0)] signed short signmode); + +}; + + +[ uuid(3811fd48-7f72-11d5-8c9e-0080ad190cd5), + helpstring("g10Code.gpgcom, type library"), + version(1.0) ] +library GpgcomLib +{ + [ uuid(3811fd40-7f72-11d5-8c9e-0080ad190cd5) ] + coclass Gpgcom + { + [default] interface IGpgme; + } +}; diff --git a/tags/V0-3-4/complus/gpgcom.rc b/tags/V0-3-4/complus/gpgcom.rc new file mode 100644 index 0000000..d9ac566 --- /dev/null +++ b/tags/V0-3-4/complus/gpgcom.rc @@ -0,0 +1,22 @@ +/* gpgcom.rc - Resource file for gpgcom + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +1 TYPELIB "gpgcom.tlb" + diff --git a/tags/V0-3-4/complus/gpgcom.tlb b/tags/V0-3-4/complus/gpgcom.tlb new file mode 100644 index 0000000000000000000000000000000000000000..ae3d1627d3bfd8d9902ebb95ef3afdc55c328f55 GIT binary patch literal 18596 zcmcIs4{)4Ebzl9zJDucDw&KV}kUOF_VxlCU6A`Y&G@q=KtRwn!NN1lylKSMkvvkQx zI!-4`hJcS&lX@Bhnl=QN7~*L{ac7*4OO?S4h6o77K$y7GggR4G6bQu>GdN6O0tCCi z-|n|}-^piFb;`~>efzzA``+8PZ{O~>yQhJX-bkgW5KQiB`4C-rD2x!-DOBO_Z;(rP z)axZX`S6+tu#T>mK>ie<1Bg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^Gds;BJ?=#u8jW;?|Ym@UsWV zFl2uqi_|9PmuAr#7|Isb&=%Gh7Dkr^ zH?iOz7FL@U`oMyVSiDQawaQ7r3xEp%z1HGg0p4dx0NCF=+hdz?9RM~a0w4|f@H-9}t@oJq^jws6K0 zRnE13F_zfXB)@0z!u?D|r)*7r<#;&9yORgU%Yvi5%c#Eq&~vO;uJ5^*%HPOdymSN& zLKP{4_fMH8Z=UHeUotlW!TmnCMalZE4|u&^iyxSyzTu2R zj5owPeL~Szh(pZCgq0wk^u=X`z~2rzpE0hSD&X3re=@F|cHj);8CT9YaFofoQYk9) z3a#fge1SV~*dqj;s|437arioS(7i?CJmQ36hQE6LE1jE6RbJM1Fq2hoj^Ns!XZbw4 z=b0|of;3cqf4OH<)zWwBLtqoKr`PrOU=Gcmr2Dm!j>!mCmIQ!)`6{ zDF!&+f#H3IQ2>)u5BB^2r=66prSm!B0(32%&z1hA^Etvb=t}2vj0NCI=W}#3aPE@6 zW!sza4dt{YntPc&AlHH%tK1ml-I-+of1knMIPmukyjQ`qqcDJX7xDo9Mu5p_NA@Ls zuH4unj3N&EPF9RBVk z2;dzSrq%7?`w9zW>X3h_!vPFFm5TEW_f8b9*cVQmEuusR{vL*lczhVj`yH(B)M3ef zclMv6Dcuu8_n=-Syx)~)IpeYNk*X3Ld>?exB{=HEG3V?rL*h!m!>AX>oRh9a;<(@9 z$s>!@CjaLKG9~TQzT_NBJS*n!d3Zm9=a$tF+6v(BiTGP5o}V%~?GeU%0^l4w?Pz=( zaK-gn`8{M4{ibQ~+Y;=XU`HMGocn0bHI#``P2Vi{BQSffqF;s|#Bi=iyos@=>02a! z?9>BKoAcX@E>p_ixi`ms#%f8w0z&=%v zeL*GGqHmYqPdSBpDz!=fXIyv205$GP +#include +#include +#include +#include +#include +#include +#include + +#include "obj_base.h" + +#include "argparse.h" + + +enum cmd_and_opt_values { aNull = 0, + oVerbose = 'v', + +aTest }; + + +static ARGPARSE_OPTS opts[] = { + + { 301, NULL, 0, "@Options:\n " }, + + { oVerbose, "verbose", 0, "verbose" }, +{0} }; + +static struct { + int verbose; +} opt; + + +static void create_guid (void); + +static const char * +my_strusage( int level ) +{ + const char *p; + switch( level ) { + case 11: p = "guidgen"; + break; + case 13: p = VERSION; break; + /*case 17: p = PRINTABLE_OS_NAME; break;*/ + case 19: p = + "Please report bugs to .\n"; + break; + case 1: + case 40: p = + "Usage: guidgen [options] (-h for help)"; + break; + case 41: p = + "Syntax: guidgen [options]\n" + "Generate GUIDs\n"; + break; + + default: p = NULL; + } + return p; +} + + +int +main (int argc, char **argv ) +{ + ARGPARSE_ARGS pargs; + + set_strusage( my_strusage ); + /*log_set_name ("gpa"); not yet implemented in logging.c */ + + pargs.argc = &argc; + pargs.argv = &argv; + pargs.flags= 0; + while( arg_parse( &pargs, opts) ) { + switch( pargs.r_opt ) { + case oVerbose: opt.verbose++; break; + + default : pargs.err = 2; break; + } + } + + if (!argc) + create_guid(); + else { + int n; + + for (n = atoi (argv[0]); n > 0; n-- ) + create_guid (); + } + + return 0; +} + + +static void +create_guid () +{ + GUID guid, *id; + id = &guid; + if ( CoCreateGuid (id) ) { + fprintf (stderr,"failed to create GUID\n"); + exit (1); + } + printf( "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n", + id->Data1, id->Data2, id->Data3, + id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3], + id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] ); +} + + diff --git a/tags/V0-3-4/complus/igpgme.c b/tags/V0-3-4/complus/igpgme.c new file mode 100644 index 0000000..9aa64a2 --- /dev/null +++ b/tags/V0-3-4/complus/igpgme.c @@ -0,0 +1,859 @@ +/* igpgme.c - COM+ class IGpgme + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../gpgme/gpgme.h" + +/* FIXME: Put them into an extra header */ +void *_gpgme_malloc (size_t n ); +void *_gpgme_calloc (size_t n, size_t m ); +void *_gpgme_realloc (void *p, size_t n); +char *_gpgme_strdup (const char *p); +void _gpgme_free ( void *a ); + + + +#define INITGUID +#include "igpgme.h" + +/* + * Declare the interface implementation structures + */ +typedef struct IGpgmeImpl IGpgmeImpl; +typedef struct IClassFactoryImpl IClassFactoryImpl; + +static HANDLE my_exit_event; + +struct IGpgmeImpl { + /* IUnknown required stuff */ + ICOM_VFIELD (IGpgme); + DWORD ref; + /* Delegation to IDispatch */ + struct { + IUnknown *disp; + ITypeInfo *tinfo; + } std_disp; + /* Our stuff */ + GpgmeCtx mainctx; + GpgmeData plaintext; + int plaintext_given_as_bstr; + GpgmeData ciphertext; + int ciphertext_is_armored; + GpgmeRecipients rset; +}; + + +struct IClassFactoryImpl { + /* IUnknown fields */ + ICOM_VFIELD(IClassFactory); + DWORD ref; +}; + +/********************************************************** + ************** helper functions ************************ + *********************************************************/ +static HRESULT +map_gpgme_error (GpgmeError err) +{ + HRESULT hr; + + if (!err) + return 0; + if ( err < 0 || err > 0x1000 ) { + fprintf (stderr,"*** GpgmeError `%s' mapped to GPGME_General_Error\n", + gpgme_strerror (err) ); + err = GPGME_General_Error; + } + hr = MAKE_HRESULT (SEVERITY_ERROR, FACILITY_ITF, 0x1000 + err); + fprintf (stderr,"*** GpgmeError `%s' mapped to %lx\n", + gpgme_strerror (err), (unsigned long)hr ); + return hr; +} + + +/********************************************************** + ************** IGpgme Implementation ******************* + *********************************************************/ + +static HRESULT WINAPI +m_IGpgme_QueryInterface (IGpgme *iface, REFIID refiid, LPVOID *obj) +{ + ICOM_THIS (IGpgmeImpl,iface); + + /*fprintf (stderr,"*** m_IGpgme_QueryInterface(%p,%s)", + This, debugstr_guid(refiid));*/ + if ( IsEqualGUID (&IID_IUnknown, refiid) + || IsEqualGUID (&IID_IGpgme, refiid) ) { + *obj = This; + IGpgme_AddRef (iface); + fprintf (stderr," -> got %p\n", *obj); + return 0; + } + else if ( IsEqualGUID (&IID_IDispatch, refiid) ) { + HRESULT hr = IDispatch_QueryInterface (This->std_disp.disp, + refiid, obj); + /*fprintf (stderr," -> delegated, hr=%lx, got %p\n", + hr, hr? NULL: *obj);*/ + return hr; + } + /*fprintf (stderr," -> none\n");*/ + *obj = NULL; + return E_NOINTERFACE; +} + + +static ULONG WINAPI +m_IGpgme_AddRef (IGpgme *iface) +{ + ICOM_THIS (IGpgmeImpl,iface); + + return ++This->ref; +} + + +static ULONG WINAPI +m_IGpgme_Release (IGpgme *iface) +{ + ICOM_THIS (IGpgmeImpl,iface); + + if (--This->ref) + return This->ref; + + gpgme_release (This->mainctx); This->mainctx = NULL; + gpgme_data_release (This->plaintext); This->plaintext = NULL; + gpgme_data_release (This->ciphertext); This->ciphertext = NULL; + gpgme_recipients_release (This->rset); This->rset = NULL; + if (This->std_disp.disp) + IDispatch_Release (This->std_disp.disp); + if (This->std_disp.tinfo) + ITypeInfo_Release (This->std_disp.tinfo); + HeapFree(GetProcessHeap(),0,iface); + { + ULONG count = CoReleaseServerProcess (); + if (!count && my_exit_event) + SetEvent (my_exit_event); + } + return 0; +} + + +static HRESULT WINAPI +m_stub_IDispatch_GetTypeInfoCount (IGpgme *iface, unsigned int *pctinfo) +{ + return E_NOTIMPL; +} + +static HRESULT WINAPI +m_stub_IDispatch_GetTypeInfo (IGpgme *iface, UINT iTInfo, + LCID lcid, ITypeInfo **ppTInfo) +{ + return E_NOTIMPL; +} + +static HRESULT WINAPI +m_stub_IDispatch_GetIDsOfNames (IGpgme *iface, REFIID riid, + LPOLESTR *rgszNames, UINT cNames, + LCID lcid, DISPID *rgDispId) +{ + return E_NOTIMPL; +} + +static HRESULT WINAPI +m_stub_IDispatch_Invoke (IGpgme *iface, DISPID dispIdMember, + REFIID riid, LCID lcid, WORD wFlags, + DISPPARAMS *pDispParams, VARIANT *pVarResult, + EXCEPINFO *pExepInfo, UINT *puArgErr) +{ + return E_NOTIMPL; +} + + + +static HRESULT WINAPI +m_IGpgme_GetVersion (IGpgme *iface, BSTR *retvat) +{ + return E_NOTIMPL; +} + +static HRESULT WINAPI +m_IGpgme_GetEngineInfo (IGpgme *iface, BSTR *retval) +{ + return E_NOTIMPL; +} + + +static HRESULT WINAPI +m_IGpgme_Cancel (IGpgme *iface) +{ + return E_NOTIMPL; +} + + +static HRESULT WINAPI +m_IGpgme_SetArmor (IGpgme *iface, BOOL yes) +{ + ICOM_THIS (IGpgmeImpl,iface); + + gpgme_set_armor (This->mainctx, yes); + return 0; +} + +static HRESULT WINAPI +m_IGpgme_GetArmor (IGpgme *iface, BOOL *retval) +{ + ICOM_THIS (IGpgmeImpl,iface); + + *retval = gpgme_get_armor (This->mainctx); + return 0; +} + + +static HRESULT WINAPI +m_IGpgme_SetTextmode (IGpgme *iface, BOOL yes) +{ + ICOM_THIS (IGpgmeImpl,iface); + + gpgme_set_textmode (This->mainctx, yes); + return 0; +} + +static HRESULT WINAPI +m_IGpgme_GetTextmode (IGpgme *iface, BOOL *retval) +{ + ICOM_THIS (IGpgmeImpl,iface); + + *retval = gpgme_get_textmode (This->mainctx); + return 0; +} + + +/* + * Put the data from VAL into a a Gpgme data object, which is passed by + * reference. Valid types of the Variant are: BSTR, SAFEARRAY of BYTE and + * SAFEARRAY of VARIANTS of signed or unsigned integers. + */ +static HRESULT WINAPI +set_data_from_variant (GpgmeData *data, VARIANT val, int *given_as_bstr) +{ + GpgmeError err = 0; + HRESULT hr; + unsigned char *buf; + SAFEARRAY *array; + size_t len; + int i; + + if ( val.vt == VT_BSTR) { + len = bstrtoutf8 (val.u.bstrVal, NULL, 0); + buf = _gpgme_malloc (len); + if (!buf) + return E_OUTOFMEMORY; + + if (bstrtoutf8 (val.u.bstrVal, buf, len) < 0) { + fprintf (stderr,"problem with bstrtoutf8\n"); + _gpgme_free (buf); + return E_FAIL; + } + + #if 0 + fprintf (stderr,"Got a BSTR (utf8):"); + for (i=0; i < len; i++) + fprintf (stderr, " %0X", buf[i] ); + putc ('\n', stderr); + #endif + gpgme_data_release (*data); *data = NULL; + err = gpgme_data_new_from_mem (data, buf, len, 0 /*no need to copy*/ ); + if (!err && given_as_bstr) + *given_as_bstr = 1; + } + else if ( val.vt == (VT_ARRAY|VT_UI1)) { + array = val.u.parray; + + /*fprintf (stderr,"Got an ARRAY of bytes:");*/ + hr = SafeArrayAccessData (array, (void**)&buf); + if (hr) { + fprintf (stderr,"*** SafeArrayAccessData failed: hr=%lx\n", hr); + return hr; + } + len = array->rgsabound[0].cElements; + /*for (i=0; i < len; i++) + fprintf (stderr, " %0X", buf[i] ); + putc ('\n', stderr);*/ + + gpgme_data_release (*data); *data = NULL; + err = gpgme_data_new_from_mem (data, buf, len, 1 ); + SafeArrayUnaccessData (array); + if (given_as_bstr) + *given_as_bstr = 0; + } + else if ( val.vt == (VT_ARRAY|VT_VARIANT)) { + VARIANT *vp; + array = val.u.parray; + + /*fprintf (stderr,"Got an ARRAY of VARIANTS:");*/ + hr = SafeArrayAccessData (array, (void**)&vp); + if (hr) { + fprintf (stderr,"*** SafeArrayAccessData failed: hr=%lx\n", hr); + return hr; + } + len = array->rgsabound[0].cElements; + /* allocate the array using the gpgme allocator so that we can + * later use a new without the copy set*/ + buf = _gpgme_malloc (len); + if (!buf) { + SafeArrayUnaccessData (array); + return E_OUTOFMEMORY; + } + /* coerce all array elements into rawtext */ + for (i=0; i < len; i++) { + switch (vp[i].vt) { + case VT_I1: buf[i] = (BYTE)vp[i].u.cVal; break; + case VT_I2: buf[i] = ((UINT)vp[i].u.iVal) & 0xff; break; + case VT_I4: buf[i] = ((ULONG)vp[i].u.lVal) & 0xff; break; + case VT_INT: buf[i] = ((UINT)vp[i].u.intVal) & 0xff; break; + case VT_UI1: buf[i] = vp[i].u.bVal; break; + case VT_UI2: buf[i] = vp[i].u.uiVal & 0xff; break; + case VT_UI4: buf[i] = vp[i].u.ulVal & 0xff; break; + case VT_UINT: buf[i] = vp[i].u.uintVal & 0xff; break; + default: + fprintf (stderr, "Invalid value in array as pos %d\n", i); + _gpgme_free (buf); + SafeArrayUnaccessData (array); + return E_INVALIDARG; + } + } + + /*for (i=0; i < len; i++) + fprintf (stderr, " %0X", buf[i] ); + putc ('\n', stderr);*/ + + gpgme_data_release (*data); *data = NULL; + err = gpgme_data_new_from_mem (data, buf, len, 0); + SafeArrayUnaccessData (array); + if (given_as_bstr) + *given_as_bstr = 0; + } + else { + fprintf (stderr, "Got a variant type = %d (0x%x)\n", + (int)val.vt, (int)val.vt ); + return E_INVALIDARG; /* not a safearray of bytes */ + } + return map_gpgme_error (err); +} + + +static HRESULT WINAPI +set_data_to_variant (GpgmeData data, VARIANT *retval, int use_bstr) +{ + GpgmeError err; + HRESULT hr; + SAFEARRAY *array; + char *p; + size_t nread, len; + int i; + + /* Get some info on the data */ + err = gpgme_data_rewind (data); + if (err ) { + fprintf (stderr, "*** gpgme_data_rewind failed: %d\n", err); + return map_gpgme_error (err); + } + err = gpgme_data_read (data, NULL, 0, &nread); + if (err && err != GPGME_EOF ) { + fprintf (stderr, "*** gpgme_data_read [length] failed: %d\n", err); + return map_gpgme_error (err); + } + len = nread; /*(eof returns a length of 0)*/ + /*fprintf (stderr,"*** %d bytes are availabe\n", (int)len);*/ + + /* convert it to the target data type */ + if (use_bstr) { + BSTR bs; + unsigned char *helpbuf; + + /* It is easier to allocate some helper storage */ + helpbuf = _gpgme_malloc (len); + if (!helpbuf) + return E_OUTOFMEMORY; + err = gpgme_data_read (data, helpbuf, len, &nread); + if (err ) { + _gpgme_free (helpbuf); + fprintf (stderr, "*** gpgme_data_read [data] failed: %d\n", err); + return map_gpgme_error (err); + } + + bs = SysAllocStringLen (NULL, len+1); + if (!bs) { + _gpgme_free (helpbuf); + return E_OUTOFMEMORY; + } + + for (i=0, p=helpbuf; i < len; i++, p++) + bs[i] = *p; + bs[i] = 0; + _gpgme_free (helpbuf); + + /* Ready */ + VariantInit (retval); + retval->vt = VT_BSTR; + retval->u.bstrVal = bs; + } +#if 0 + else if (use_byte_array) { + array = SafeArrayCreateVector (VT_UI1, 0, len); + if (!array) + return E_OUTOFMEMORY; + + p = NULL; + hr = SafeArrayAccessData (array, (void**)&p); + if (hr) { + fprintf (stderr,"*** SafeArrayAccessData failed: hr=%lx\n", hr); + SafeArrayDestroyData (array); + SafeArrayDestroy (array); + return hr; + } + if (len) { + err = gpgme_data_read (data, p, len, &nread); + if (err ) { + SafeArrayUnaccessData (array); + SafeArrayDestroyData (array); + SafeArrayDestroy (array); + fprintf (stderr, "*** gpgme_data_read [data] failed: %d\n", + err); + return map_gpgme_error (err); + } + } + SafeArrayUnaccessData (array); + + /* pass the data to the caller */ + VariantInit (retval); + retval->vt = (VT_ARRAY|VT_UI1); + retval->u.parray = array; + } +#endif + else { /* Create an array of variants of bytes */ + VARIANT *v; + unsigned char *helpbuf; + + /* It is easier to allocate some helper storage */ + helpbuf = _gpgme_malloc (len); + if (!helpbuf) + return E_OUTOFMEMORY; + err = gpgme_data_read (data, helpbuf, len, &nread); + if (err ) { + _gpgme_free (helpbuf); + fprintf (stderr, "*** gpgme_data_read [data] failed: %d\n", err); + return map_gpgme_error (err); + } + + /* The create the array */ + array = SafeArrayCreateVector (VT_VARIANT, 0, len); + if (!array) { + _gpgme_free (helpbuf); + return E_OUTOFMEMORY; + } + + v = NULL; + hr = SafeArrayAccessData (array, (void**)&v); + if (hr) { + fprintf (stderr,"*** SafeArrayAccessData failed: hr=%lx\n", hr); + _gpgme_free (helpbuf); + SafeArrayDestroyData (array); + SafeArrayDestroy (array); + return hr; + } + + for (p=helpbuf; len; len--, v++) { + VariantInit (v); + v->vt = VT_UI1; + v->u.bVal = *p; + } + SafeArrayUnaccessData (array); + _gpgme_free (helpbuf); + + /* pass the data to the caller */ + VariantInit (retval); + retval->vt = (VT_ARRAY|VT_VARIANT); + retval->u.parray = array; + } + return 0; +} + + +static HRESULT WINAPI +m_IGpgme_SetPlaintext (IGpgme *iface, VARIANT val) +{ + ICOM_THIS (IGpgmeImpl,iface); + + return set_data_from_variant (&This->plaintext, val, + &This->plaintext_given_as_bstr); +} + + +static HRESULT WINAPI +m_IGpgme_GetPlaintext (IGpgme *iface, VARIANT *retval) +{ + ICOM_THIS (IGpgmeImpl,iface); + + /*fprintf (stderr,"*** " __PRETTY_FUNCTION__ "(%p)\n", This );*/ + return set_data_to_variant (This->plaintext, retval, + This->plaintext_given_as_bstr); +} + +static HRESULT WINAPI +m_IGpgme_SetCiphertext (IGpgme *iface, VARIANT val) +{ + ICOM_THIS (IGpgmeImpl,iface); + + return set_data_from_variant (&This->ciphertext, val, NULL); +} + +static HRESULT WINAPI +m_IGpgme_GetCiphertext (IGpgme *iface, VARIANT *retval) +{ + ICOM_THIS (IGpgmeImpl,iface); + + return set_data_to_variant (This->ciphertext, retval, + This->ciphertext_is_armored); +} + +static HRESULT WINAPI +m_IGpgme_ClearRecipients (IGpgme *iface) +{ + ICOM_THIS (IGpgmeImpl,iface); + + gpgme_recipients_release (This->rset); This->rset = NULL; + return 0; +} + + +static HRESULT WINAPI +m_IGpgme_AddRecipient (IGpgme *iface, BSTR name, signed short int trust) +{ + GpgmeError err; + int n; + char *p; + ICOM_THIS (IGpgmeImpl,iface); + + /*fprintf (stderr,"*** " __PRETTY_FUNCTION__ "(%p, %d)\n", + This, (int)trust);*/ + if (!This->rset) { + err = gpgme_recipients_new (&This->rset); + if (err) + return map_gpgme_error (err); + } + + n = bstrtoutf8 (name, NULL, 0); + p = HeapAlloc (GetProcessHeap(), 0, n ); + if (!p) { + fprintf (stderr,"HeapAlloc failed: ec=%d\n", (int)GetLastError () ); + return E_OUTOFMEMORY; + } + if (bstrtoutf8 (name, p, n) < 0) { + fprintf (stderr,"problem with bstrtoutf8\n"); + HeapFree (GetProcessHeap(), 0, p); + return E_FAIL; + } + err = gpgme_recipients_add_name (This->rset, p); + HeapFree (GetProcessHeap(), 0, p); + return map_gpgme_error (err); +} + +static HRESULT WINAPI +m_IGpgme_ResetSignKeys (IGpgme *iface) +{ + return E_NOTIMPL; +} + +static HRESULT WINAPI +m_IGpgme_AddSignKey (IGpgme *iface, BSTR name) +{ + return E_NOTIMPL; +} + +static HRESULT WINAPI +m_IGpgme_Encrypt (IGpgme *iface) +{ + GpgmeError err; + ICOM_THIS (IGpgmeImpl,iface); + + gpgme_data_release (This->ciphertext); + err = gpgme_data_new (&This->ciphertext); + if (err) + return map_gpgme_error (err); + + + This->ciphertext_is_armored = gpgme_get_armor (This->mainctx); + err = gpgme_op_encrypt (This->mainctx, This->rset, + This->plaintext, This->ciphertext); +#if 0 + if (!err ) { + char buf[100]; + size_t nread; + + err = gpgme_data_rewind ( This->ciphertext ); + if (err ) + fprintf (stderr, "*** gpgme_data_rewind failed: %d\n", err); + while ( !(err = gpgme_data_read ( This->ciphertext, + buf, 100, &nread )) ) { + fwrite ( buf, nread, 1, stderr ); + } + if (err != GPGME_EOF) + fprintf (stderr, "*** gpgme_data_read failed: %d\n", err); + err = 0; + } +#endif + + return map_gpgme_error (err); +} + +static HRESULT WINAPI +m_IGpgme_Sign (IGpgme *iface, short int signmode) +{ + ICOM_THIS (IGpgmeImpl,iface); + + fprintf (stderr,"*** " __PRETTY_FUNCTION__ "(%p)\n", This ); + + return E_NOTIMPL; +} + +static HRESULT WINAPI +m_IGpgme_SignEncrypt (IGpgme *iface, short int signmode) +{ + ICOM_THIS (IGpgmeImpl,iface); + + fprintf (stderr,"*** " __PRETTY_FUNCTION__ "(%p)\n", This ); + + return E_NOTIMPL; +} + +#if 0 +static HRESULT WINAPI +m_IGpgme_GetSigStatus(GpgmeCtx c, int idx, + GpgmeSigStat *r_stat, time_t *r_created ); +{ + return 0; +} + + +static HRESULT WINAPI +m_IGpgme_GetSigKey (GpgmeCtx c, int idx, GpgmeKey *r_key); +{ + return 0; +} + +static HRESULT WINAPI +m_IGpgme_GetNotation(IGpgme *c, BSTR *retval) +{ + return 0; +} +#endif + + +static ICOM_VTABLE(IGpgme) igpgme_vtbl = +{ + /* IUnknown methods */ + ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE + m_IGpgme_QueryInterface, + m_IGpgme_AddRef, + m_IGpgme_Release, + /* IDispatch methods */ + m_stub_IDispatch_GetTypeInfoCount, + m_stub_IDispatch_GetTypeInfo, + m_stub_IDispatch_GetIDsOfNames, + m_stub_IDispatch_Invoke, + /* Our methods */ + m_IGpgme_GetVersion, + m_IGpgme_GetEngineInfo, + m_IGpgme_Cancel, + m_IGpgme_SetArmor, + m_IGpgme_GetArmor, + m_IGpgme_SetTextmode, + m_IGpgme_GetTextmode, + m_IGpgme_SetPlaintext, + m_IGpgme_GetPlaintext, + m_IGpgme_SetCiphertext, + m_IGpgme_GetCiphertext, + m_IGpgme_ClearRecipients, + m_IGpgme_AddRecipient, + m_IGpgme_ResetSignKeys, + m_IGpgme_AddSignKey, + m_IGpgme_Encrypt, + m_IGpgme_Sign, + m_IGpgme_SignEncrypt +}; + + + +/*************************************************************** + ****************** Gpgme Factory **************************** + ***************************************************************/ + +static HRESULT WINAPI +m_GpgmeFactory_QueryInterface (IClassFactory *iface, + REFIID refiid, LPVOID *obj) +{ + ICOM_THIS (IClassFactoryImpl,iface); + + /*fprintf (stderr,"*** m_GpgmeFactory_QueryInterface(%p,%s)", + This, debugstr_guid(refiid));*/ + if ( IsEqualGUID (&IID_IUnknown, refiid) + || IsEqualGUID (&IID_IClassFactory, refiid) ) { + *obj = This; + /*fprintf (stderr," -> got %p\n", obj);*/ + return 0; + } + *obj = NULL; + /*fprintf (stderr," -> none\n");*/ + return E_NOINTERFACE; +} + +static ULONG WINAPI +m_GpgmeFactory_AddRef (IClassFactory *iface) +{ + ICOM_THIS(IClassFactoryImpl,iface); + return ++(This->ref); +} + +static ULONG WINAPI +m_GpgmeFactory_Release (IClassFactory *iface) +{ + ICOM_THIS(IClassFactoryImpl,iface); + return --(This->ref); +} + +static HRESULT WINAPI +m_GpgmeFactory_CreateInstance (IClassFactory *iface, IUnknown *outer, + REFIID refiid, LPVOID *r_obj ) +{ + /*ICOM_THIS(IClassFactoryImpl,iface);*/ + + fprintf (stderr,"*** m_GpgmeFactory_CreateInstance(%s)", + debugstr_guid(refiid) ); + if ( IsEqualGUID (&IID_IUnknown, refiid) + || IsEqualGUID (&IID_IGpgme, refiid) ) { + IGpgmeImpl *obj; + GpgmeCtx ctx; + GpgmeError err; + + + err = gpgme_new (&ctx); + if (err) { + fprintf (stderr," -> gpgme_new failed: %s\n", gpgme_strerror (err)); + return E_OUTOFMEMORY; + } + + obj = HeapAlloc (GetProcessHeap(), 0, sizeof *obj ); + if ( !obj) { + fprintf (stderr," -> out of core\n"); + gpgme_release (ctx); + return E_OUTOFMEMORY; + } + memset (obj, 0, sizeof *obj); + + ICOM_VTBL(obj) = &igpgme_vtbl; + obj->ref = 1; + obj->mainctx = ctx; + { /* Fixme: need to release some stuff on error */ + HRESULT hr; + ITypeLib *pTypeLib; + + hr = LoadRegTypeLib (&TLBID_Gpgcom, 1, 0, LANG_NEUTRAL, &pTypeLib); + if (hr) { + fprintf (stderr," -> LoadRegTypeLib failed: %lx\n", hr); + return hr; + } + hr = ITypeLib_GetTypeInfoOfGuid (pTypeLib, &IID_IGpgme, + &obj->std_disp.tinfo); + ITypeLib_Release (pTypeLib); + if (hr) { + fprintf (stderr," -> GetTypeInfoOfGuid failed: %lx\n", hr); + return hr; + } + hr = CreateStdDispatch ((IUnknown*)obj, obj, obj->std_disp.tinfo, + &obj->std_disp.disp); + if (hr) { + fprintf (stderr," -> CreateStdDispatch failed: %lx\n", hr); + return hr; + } + } + + CoAddRefServerProcess (); + *r_obj = obj; + fprintf (stderr," -> created %p\n", obj ); + return 0; + } + fprintf (stderr," -> no interface\n" ); + *r_obj = NULL; + return E_NOINTERFACE; +} + +static HRESULT WINAPI +m_GpgmeFactory_LockServer (IClassFactory *iface, BOOL dolock ) +{ + if (dolock) { + CoAddRefServerProcess (); + } + else { + ULONG count = CoReleaseServerProcess (); + if (!count && my_exit_event) + SetEvent (my_exit_event); + } + return 0; +} + +static ICOM_VTABLE(IClassFactory) igpgme_factory_vtbl = { + ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE + m_GpgmeFactory_QueryInterface, + m_GpgmeFactory_AddRef, + m_GpgmeFactory_Release, + m_GpgmeFactory_CreateInstance, + m_GpgmeFactory_LockServer +}; +static IClassFactoryImpl igpgme_CF = {&igpgme_factory_vtbl, 1 }; + +void +igpgme_register_exit_event (HANDLE ev) +{ + my_exit_event = ev; +} + + +IClassFactory * +igpgme_factory_new ( CLSID *r_clsid ) +{ + *r_clsid = CLSID_Gpgme; + IClassFactory_AddRef((IClassFactory*)&igpgme_CF); + return (IClassFactory*)&igpgme_CF; +} + +void +igpgme_factory_release ( IClassFactory *factory ) +{ + /* it's static - nothing to do */ +} diff --git a/tags/V0-3-4/complus/igpgme.h b/tags/V0-3-4/complus/igpgme.h new file mode 100644 index 0000000..fa96762 --- /dev/null +++ b/tags/V0-3-4/complus/igpgme.h @@ -0,0 +1,163 @@ +/* igpgme.h - COM+ class IGpgme + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef IGPGME_H +#define IGPGME_H 1 + +#include + +DEFINE_GUID(CLSID_Gpgme, 0x3811fd40, 0x7f72, 0x11d5, + 0x8c, 0x9e, 0x00, 0x80, 0xad, 0x19, 0x0c, 0xd5); +#if 0 +DEFINE_GUID(CLSID_GpgmeData, 0x3811fd41, 0x7f72, 0x11d5, + 0x8c, 0x9e, 0x00, 0x80, 0xad, 0x19, 0x0c, 0xd5); +DEFINE_GUID(CLSID_GpgmeKey, 0x3811fd42, 0x7f72, 0x11d5, + 0x8c, 0x9e, 0x00, 0x80, 0xad, 0x19, 0x0c, 0xd5); +DEFINE_GUID(CLSID_GpgmeRSet, 0x3811fd43, 0x7f72, 0x11d5, + 0x8c, 0x9e, 0x00, 0x80, 0xad, 0x19, 0x0c, 0xd5); +#endif + +DEFINE_GUID(TLBID_Gpgcom, 0x3811fd48, 0x7f72, 0x11d5, + 0x8c, 0x9e, 0x00, 0x80, 0xad, 0x19, 0x0c, 0xd5); +DEFINE_GUID(APPID_Gpgcom, 0x3811fd4f, 0x7f72, 0x11d5, + 0x8c, 0x9e, 0x00, 0x80, 0xad, 0x19, 0x0c, 0xd5); + + +DEFINE_GUID(IID_IGpgme, 0x3811fd50, 0x7f72, 0x11d5, + 0x8c, 0x9e, 0x00, 0x80, 0xad, 0x19, 0x0c, 0xd5); + +typedef struct IGpgme IGpgme; + +void igpgme_register_exit_event (HANDLE ev); +IClassFactory *igpgme_factory_new( CLSID *r_clsid ); +void igpgme_factory_release ( IClassFactory *factory ); + + +/******************************************** + ***** The IGpgme interface ***************** + ********************************************/ + +#define ICOM_INTERFACE IGpgme + +#define IGpgme_METHODS \ + ICOM_METHOD1(HRESULT,GetVersion, BSTR*,) \ + ICOM_METHOD1(HRESULT,GetEngineInfo, BSTR*,) \ + ICOM_METHOD(HRESULT,Cancel) \ + ICOM_METHOD1(HRESULT,SetArmor,BOOL,) \ + ICOM_METHOD1(HRESULT,GetArmor,BOOL*,) \ + ICOM_METHOD1(HRESULT,SetTextmode,BOOL,) \ + ICOM_METHOD1(HRESULT,GetTextmode,BOOL*,) \ + ICOM_METHOD1(HRESULT,SetPlaintext,VARIANT,) \ + ICOM_METHOD1(HRESULT,GetPlaintext,VARIANT*,) \ + ICOM_METHOD1(HRESULT,SetCiphertext,VARIANT,) \ + ICOM_METHOD1(HRESULT,GetCiphertext,VARIANT*,) \ + ICOM_METHOD(HRESULT,ClearRecipients) \ + ICOM_METHOD2(HRESULT,AddRecipient,BSTR,,signed short int,) \ + ICOM_METHOD(HRESULT,ResetSignKeys) \ + ICOM_METHOD1(HRESULT,AddSignKey,BSTR,) \ + ICOM_METHOD(HRESULT,Encrypt) \ + ICOM_METHOD1(HRESULT,Sign,signed short int,) \ + ICOM_METHOD1(HRESULT,SignEncrypt,signed short int,) + +#if 0 + ICOM_METHOD1(HRESULT,SetKeylistMode,) + ICOM_METHOD1(HRESULT,SetPassphraseCB,) + ICOM_METHOD1(HRESULT,SetProgressCB,) + ICOM_METHOD1(HRESULT,SignersClear,) + ICOM_METHOD1(HRESULT,SignersAdd,) + ICOM_METHOD1(HRESULT,SignersEnum,) + ICOM_METHOD1(HRESULT,GetSigStatus,) + ICOM_METHOD1(HRESULT,GetNotation,) +#endif + +#define IGpgme_IMETHODS \ + IDispatch_IMETHODS \ + IGpgme_METHODS + +ICOM_DEFINE(IGpgme,IDispatch) +#undef ICOM_INTERFACE + + +/*** IUnknown methods ***/ +#define IGpgme_QueryInterface(p,a,b) ICOM_CALL2(QueryInterface,p,a,b) +#define IGpgme_AddRef(p) ICOM_CALL (AddRef,p) +#define IGpgme_Release(p) ICOM_CALL (Release,p) +/*** IGpgme methods ***/ +#define IGpgme_GetVersion(p,r) ICOM_CALL1(GetVersion,p,r) +#define IGpgme_GetEngineInfo(p,r) ICOM_CALL1(GetEngineInfo,p,r) +#define IGpgme_Cancel(p,a) ICOM_CALL1(Cancel,p,a) +#define IGpgme_SetArmor(p,a) ICOM_CALL1(SetArmor,p,a) +#define IGpgme_GetArmor(p,a) ICOM_CALL1(GetArmor,p,a) +#define IGpgme_SetTextmode(p,a) ICOM_CALL1(SetTextmode,p,a) +#define IGpgme_GetTextmode(p,a) ICOM_CALL1(GetTextmode,p,a) +#define IGpgme_SetPlaintext(p,a) ICOM_CALL1(SetPlaintext,p,a) +#define IGpgme_GetPlaintext(p,a) ICOM_CALL1(GetPlaintext,p,a) +#define IGpgme_SetCiphertext(p,a) ICOM_CALL1(SetCiphertext,p,a) +#define IGpgme_GetCiphertext(p,a) ICOM_CALL1(GetCiphertext,p,a) +#define IGpgme_ClearRecipients(p) ICOM_CALL (ClearRecipients,p) +#define IGpgme_AddRecipient(p,a,b) ICOM_CALL2(AddRecipient,p,a,b) +#define IGpgme_ResetSignKeys(p) ICOM_CALL (ResetSignKeys,p) +#define IGpgme_AddSignKey(p,a) ICOM_CALL (AddSignKey,p,a) +#define IGpgme_Encrypt(p) ICOM_CALL (Encrypt,p) +#define IGpgme_Sign(p,a) ICOM_CALL (Sign,p,a) +#define IGpgme_SignEncrypt(p,a) ICOM_CALL (SignEncrypt,p,a) +#if 0 +#define IGpgme_SetKeylistMode(p,a) ICOM_CALL1(SetKeylistMode,p,a) +#define IGpgme_SetPassphraseCB(p,a) ICOM_CALL1(SetPassphraseCB,p,a) +#define IGpgme_SetProgressCB(p,a) ICOM_CALL1(SetProgressCB,p,a) +#define IGpgme_SignersClear(p,a) ICOM_CALL1(SignersClear,p,a) +#define IGpgme_SignersAdd(p,a) ICOM_CALL1(SignersAdd,p,a) +#define IGpgme_SignersEnum(p,a) ICOM_CALL1(SignersEnum,p,a) +#define IGpgme_GetSigStatus(p,a) ICOM_CALL1(GetSigStatus,p,a) +#define IGpgme_GetSigKey(p,a) ICOM_CALL1(GetSigKey,p,a) +#define IGpgme_GetNotation(p,a) ICOM_CALL1(GetNotation,p,a) +#endif + + +#if 0 +/******************************************** + ***** The IGpgmeKey interface ************** + ********************************************/ + +#define ICOM_INTERFACE IGpgmeKey + +#define IGpgmeKey_METHODS \ + ICOM_METHOD1(HRESULT,GetVersion, BSTR,) \ + ICOM_METHOD1(HRESULT,GetEngineInfo, BSTR,) + + +#define IGpgmeKey_IMETHODS \ + IUnknown_IMETHODS \ + IGpgmeKey_METHODS + +ICOM_DEFINE(IGpgmeKey,IUnknown) +#undef ICOM_INTERFACE + +/*** IUnknown methods ***/ +#define IGpgmeKey_QueryInterface(p,a,b) ICOM_CALL2(QueryInterface,p,a,b) +#define IGpgmeKey_AddRef(p) ICOM_CALL (AddRef,p) +#define IGpgmeKey_Release(p) ICOM_CALL (Release,p) +/*** IGpgmeKey methods ***/ +#define IGpgmeKey_GetVersion(p,r) ICOM_CALL1(GetVersion,p,r) +#define IGpgmeKey_GetEngineInfo(p,r) ICOM_CALL1(GetEngineInfo,p,r) +#endif + +#endif /*IGPGME_H*/ + diff --git a/tags/V0-3-4/complus/main.h b/tags/V0-3-4/complus/main.h new file mode 100644 index 0000000..7e48ad4 --- /dev/null +++ b/tags/V0-3-4/complus/main.h @@ -0,0 +1,49 @@ +/* main.h - GPGME COM+ component + * Copyright (C) 2000 Werner Koch (dd9jn) + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef COMPLUS_MAIN_H +#define COMPLUS_MAIN_H + +#include "xmalloc.h" +#include "stringhelp.h" +#include "logging.h" + + +#define _(a) (a) +#define N_(a) (a) + + +struct { + int verbose; + int quiet; + unsigned int debug; + char *homedir; +} opt; + + + +#endif /* COMPLUS_MAIN_H */ + + + + + + + diff --git a/tags/V0-3-4/complus/regtlb.c b/tags/V0-3-4/complus/regtlb.c new file mode 100644 index 0000000..4ea1342 --- /dev/null +++ b/tags/V0-3-4/complus/regtlb.c @@ -0,0 +1,70 @@ +/* regtlb.c - Register a type library + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "xmalloc.h" +#include "oleauto.h" + +int +main (int argc, char **argv) +{ + ITypeLib *pTypeLib; + wchar_t *fname; + HRESULT hr; + size_t n; + + if ( argc != 2 ) { + fprintf (stderr,"usage: regtlb foo.tlb\n"); + return 1; + } + + n = mbstowcs (NULL, argv[1], strlen(argv[1])+1); + fprintf (stderr, "need %d bytes\n", (int)n); + fname = xmalloc ((n+1)*sizeof *fname); + mbstowcs (fname, argv[1], strlen (argv[1])+1); + + hr = CoInitializeEx (NULL, COINIT_MULTITHREADED); + if (hr) + fprintf (stderr, "CoInitializeEx() failed: hr=%lu\n", hr); + + hr = LoadTypeLibEx (fname, REGKIND_REGISTER, &pTypeLib); + if (hr) + fprintf (stderr, "LoadTypeLibEx() failed: hr=%lx\n", hr); + + ITypeLib_Release (pTypeLib); + + CoUninitialize (); + return 0; +} + + + + + + diff --git a/tags/V0-3-4/complus/tgpgcom.c b/tags/V0-3-4/complus/tgpgcom.c new file mode 100644 index 0000000..27516b1 --- /dev/null +++ b/tags/V0-3-4/complus/tgpgcom.c @@ -0,0 +1,157 @@ +/* tgpgcom.c - Test the IGpgme classes + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#define INITGUID +#include "igpgme.h" + + +int +main (int argc, char **argv) +{ + IUnknown *pUnknown = NULL; + IGpgme *pGpgme; + HRESULT hr; + BSTR bs; + + hr = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED); + if (hr) + fprintf (stderr, "CoInitializeEx() failed: hr=%lu\n", hr); + + fprintf (stderr, "system initialized\n"); + hr = CoCreateInstance (&CLSID_Gpgme, NULL, CLSCTX_LOCAL_SERVER, + &IID_IUnknown, (void**)&pUnknown ); + if (hr) + fprintf (stderr, "CoCreateInstance() failed: hr=%lx\n", hr); + if (!pUnknown) + exit (1); + + fprintf (stderr,"got object %p - querying %s\n", + pUnknown, debugstr_guid(&IID_IGpgme)); + hr = IGpgme_QueryInterface (pUnknown, &IID_IGpgme, (void**)&pGpgme); + if (hr) { + fprintf (stderr, "QueryInterface() failed: hr=%lx\n", hr); + goto leave; + } + fprintf (stderr, "got interface %p\n", pGpgme); + + hr = IGpgme_SetArmor (pGpgme, 1); + fprintf (stderr, "SetArmor returned %lx\n", hr); + + hr = IGpgme_SetTextmode (pGpgme, 0); + fprintf (stderr, "SetTextmode returned %lx\n", hr); + + hr = IGpgme_ClearRecipients (pGpgme); + fprintf (stderr, "ClearRecipients returned %lx\n", hr); + + bs = SysAllocString (L"alice"); + if (!bs) + fprintf (stderr, "SysAllocString failed: ec=%d\n", (int)GetLastError()); + else { + int i; + + for (i=-4; i < 12; i++ ) + fprintf (stderr," %02X", ((unsigned char*)bs)[i] ); + putc ('\n', stderr); + } + hr = IGpgme_AddRecipient (pGpgme, bs, -1); + fprintf (stderr, "AddRecipients returned %lx\n", hr); + + { + SAFEARRAY *sa; + VARIANT v; + char *p; + + sa = SafeArrayCreateVector (VT_UI1, 0, 20); + if (!sa) { + fprintf (stderr, "SafeArrayCreateVector failed\n"); + goto leave; + } + + hr = SafeArrayAccessData (sa, (void**)&p); + if (hr) { + fprintf (stderr,"SafeArrayAccessData failed: hr=%lx\n", hr); + goto leave; + } + + memcpy (p, "=> Omnis enim res <=", 20 ); + SafeArrayUnaccessData (sa); + + VariantInit (&v); + v.vt = (VT_ARRAY|VT_UI1); + v.u.parray = sa; + + hr = IGpgme_SetPlaintext (pGpgme, v ); + fprintf (stderr, "SetPlaintext returned %lx\n", hr); + SafeArrayDestroyData (sa); + SafeArrayDestroy (sa); + + VariantClear (&v); + } + + hr = IGpgme_Encrypt (pGpgme); + fprintf (stderr, "Encrypt returned %lx\n", hr); + + { + VARIANT v; + + hr = IGpgme_GetCiphertext (pGpgme, &v); + fprintf (stderr, "GetCiphertext returned %lx\n", hr); + if (!hr) { + if (v.vt != (VT_ARRAY|VT_UI1)) + fprintf (stderr, "Invalid array typed returned\n"); + else { + unsigned char *p; + + hr = SafeArrayAccessData (v.u.parray, (void**)&p); + if (hr) + fprintf (stderr,"*** SafeArrayAccessData failed: %lx\n", hr); + else { + size_t arraysize = v.u.parray->rgsabound[0].cElements; + fprintf (stderr,"*** got %d bytes\n", (int)arraysize); + for (;arraysize; arraysize--, p++ ) + putc (*p, stderr); + SafeArrayUnaccessData (v.u.parray); + } + } + } + } + IGpgme_Release (pGpgme); + + leave: + CoUninitialize (); + fprintf (stderr, "system uninitialized\n"); + return 0; +} + + + + + + diff --git a/tags/V0-3-4/complus/utf8.c b/tags/V0-3-4/complus/utf8.c new file mode 100644 index 0000000..0237a62 --- /dev/null +++ b/tags/V0-3-4/complus/utf8.c @@ -0,0 +1,236 @@ +/* + * UTF-8 support routines + * + * Copyright 2000 Alexandre Julliard + * + * Taken from WINE, so the usual WINE copyright applies: +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include + +#include + +/* number of following bytes in sequence based on first byte value (for bytes above 0x7f) */ +static const char utf8_length[128] = +{ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x80-0x8f */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x90-0x9f */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xa0-0xaf */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xb0-0xbf */ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0xc0-0xcf */ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0xd0-0xdf */ + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, /* 0xe0-0xef */ + 3,3,3,3,3,3,3,3,4,4,4,4,5,5,0,0 /* 0xf0-0xff */ +}; + +/* first byte mask depending on UTF-8 sequence length */ +static const unsigned char utf8_mask[6] = { 0x7f, 0x1f, 0x0f, 0x07, 0x03, 0x01 }; + +/* minimum Unicode value depending on UTF-8 sequence length */ +static const unsigned int utf8_minval[6] = { 0x0, 0x80, 0x800, 0x10000, 0x200000, 0x4000000 }; + + +/* query necessary dst length for src string */ +inline static int get_length_wcs_utf8( const WCHAR *src, unsigned int srclen ) +{ + int len; + + for (len = 0; srclen; srclen--, src++, len++) + { + if (*src >= 0x80) + { + len++; + if (*src >= 0x800) len++; + } + } + return len; +} + +/* wide char to UTF-8 string conversion */ +/* return -1 on dst buffer overflow */ +int utf8_wcstombs( const WCHAR *src, int srclen, char *dst, int dstlen ) +{ + char *orig_dst = dst; + + if (!dstlen) return get_length_wcs_utf8( src, srclen ); + + for (; srclen; srclen--, src++) + { + WCHAR ch = *src; + + if (ch < 0x80) /* 0x00-0x7f: 1 byte */ + { + if (!dstlen--) return -1; /* overflow */ + *dst++ = ch; + continue; + } + + if (ch < 0x800) /* 0x80-0x7ff: 2 bytes */ + { + if ((dstlen -= 2) < 0) return -1; /* overflow */ + dst[1] = 0x80 | (ch & 0x3f); + ch >>= 6; + dst[0] = 0xc0 | ch; + dst += 2; + continue; + } + + /* 0x800-0xffff: 3 bytes */ + + if ((dstlen -= 3) < 0) return -1; /* overflow */ + dst[2] = 0x80 | (ch & 0x3f); + ch >>= 6; + dst[1] = 0x80 | (ch & 0x3f); + ch >>= 6; + dst[0] = 0xe0 | ch; + dst += 3; + } + return dst - orig_dst; +} + +/* query necessary dst length for src string */ +inline static int get_length_mbs_utf8( const unsigned char *src, int srclen ) +{ + int ret; + const unsigned char *srcend = src + srclen; + + for (ret = 0; src < srcend; ret++) + { + unsigned char ch = *src++; + if (ch < 0xc0) continue; + + switch(utf8_length[ch-0x80]) + { + case 5: + if (src >= srcend) return ret; /* ignore partial char */ + if ((ch = *src ^ 0x80) >= 0x40) continue; + src++; + case 4: + if (src >= srcend) return ret; /* ignore partial char */ + if ((ch = *src ^ 0x80) >= 0x40) continue; + src++; + case 3: + if (src >= srcend) return ret; /* ignore partial char */ + if ((ch = *src ^ 0x80) >= 0x40) continue; + src++; + case 2: + if (src >= srcend) return ret; /* ignore partial char */ + if ((ch = *src ^ 0x80) >= 0x40) continue; + src++; + case 1: + if (src >= srcend) return ret; /* ignore partial char */ + if ((ch = *src ^ 0x80) >= 0x40) continue; + src++; + } + } + return ret; +} + +/* UTF-8 to wide char string conversion */ +/* return -1 on dst buffer overflow, -2 on invalid input char */ +int utf8_mbstowcs( int flags, const char *src, int srclen, WCHAR *dst, int dstlen ) +{ + int len, count; + unsigned int res; + const char *srcend = src + srclen; + + if (!dstlen) return get_length_mbs_utf8( src, srclen ); + + for (count = dstlen; count && (src < srcend); count--, dst++) + { + unsigned char ch = *src++; + if (ch < 0x80) /* special fast case for 7-bit ASCII */ + { + *dst = ch; + continue; + } + len = utf8_length[ch-0x80]; + res = ch & utf8_mask[len]; + + switch(len) + { + case 5: + if (src >= srcend) goto done; /* ignore partial char */ + if ((ch = *src ^ 0x80) >= 0x40) goto bad; + res = (res << 6) | ch; + src++; + case 4: + if (src >= srcend) goto done; /* ignore partial char */ + if ((ch = *src ^ 0x80) >= 0x40) goto bad; + res = (res << 6) | ch; + src++; + case 3: + if (src >= srcend) goto done; /* ignore partial char */ + if ((ch = *src ^ 0x80) >= 0x40) goto bad; + res = (res << 6) | ch; + src++; + case 2: + if (src >= srcend) goto done; /* ignore partial char */ + if ((ch = *src ^ 0x80) >= 0x40) goto bad; + res = (res << 6) | ch; + src++; + case 1: + if (src >= srcend) goto done; /* ignore partial char */ + if ((ch = *src ^ 0x80) >= 0x40) goto bad; + res = (res << 6) | ch; + src++; + if (res < utf8_minval[len]) goto bad; + if (res >= 0x10000) goto bad; /* FIXME: maybe we should do surrogates here */ + *dst = res; + continue; + } + bad: + if (flags & MB_ERR_INVALID_CHARS) return -2; /* bad char */ + *dst = (WCHAR)'?'; + } + if (src < srcend) return -1; /* overflow */ +done: + return dstlen - count; +} + + +int +bstrtoutf8 ( BSTR src, char *dst, size_t dstlen ) +{ + size_t srclen, needed; + int n; + + srclen = src? SysStringLen (src): 0; + + needed = srclen? (utf8_wcstombs (src, srclen, NULL, 0) + 1) : 1; + if (!dst || !dstlen) + return needed; + if (dstlen < needed) + return -1; + if (srclen) { + n = utf8_wcstombs (src, srclen, dst, dstlen); + if (n < 0) + return -1; + } + else + n = 0; + dst[n] = 0; + return n; +} + + + diff --git a/tags/V0-3-4/complus/vbtest.html b/tags/V0-3-4/complus/vbtest.html new file mode 100644 index 0000000..03df463 --- /dev/null +++ b/tags/V0-3-4/complus/vbtest.html @@ -0,0 +1,47 @@ + +g10 code - GPGCOM test + + + + + + + +

Silly Gpgcom test page

+ +
+ +

+Encrypt for + +

+ +

+ +

+ + + + + + diff --git a/tags/V0-3-4/complus/vbtest.vbs b/tags/V0-3-4/complus/vbtest.vbs new file mode 100644 index 0000000..8246b45 --- /dev/null +++ b/tags/V0-3-4/complus/vbtest.vbs @@ -0,0 +1,39 @@ +' Demo script to generate a RFC2015 compliant message using Gpgcom +Dim gpg, body, crlf + +crlf = chr(10) & chr(13) + +' Create out Gpgcom object +set gpg = CreateObject("Gpgcom.Gpgme") +' We must use the ASCII armor and switch to textmode +gpg.armor = true +gpg.textmode = true + +' Set the secret message +gpg.plaintext = "This is the secret message." 'or: InputBox('Enter message:") + +' Set the Recipient. You may also use a keyID or an fingerprint +gpg.AddRecipient "alice" + +' And encrypt the stuff +gpg.encrypt + +' Build the MIME message +body = "Content-Type: multipart/encrypted; boundary=" +body = body & Chr(34) & "=-=-=-=" & Chr(34) & crlf & " protocol=" & Chr(34) +body = body & "application/pgp-encrypted" & Chr(34) & crlf & crlf +body = body & "--=-=-=-=" & crlf +body = body & "Content-Type: application/pgp-encrypted" & crlf & crlf +body = body & "Version: 1" & crlf & crlf +body = body & "--=-=-=-=" & crlf +body = body & "Content-Type: application/octet-stream" & crlf & crlf +body = body & gpg.ciphertext +body = body & "--=-=-=-=--" & crlf + +' And display it +Print body + +' output function for the windows scripting host +sub Print(x) + WScript.Echo x +end sub diff --git a/tags/V0-3-4/configure.ac b/tags/V0-3-4/configure.ac new file mode 100644 index 0000000..0f35255 --- /dev/null +++ b/tags/V0-3-4/configure.ac @@ -0,0 +1,242 @@ +# configure.in for GPGME +# Copyright (C) 2000 Werner Koch (dd9jn) +# Copyright (C) 2001 g10 Code GmbH +# +# This file is part of GPGME. +# +# GPGME is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# GPGME is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +# (Process this file with autoconf to produce a configure script.) + +# Version numbers (Remember to change them just before a release.) +# (Code changed: REVISION++) +# (Interfaces added/removed/changed: CURRENT++, REVISION=0) +# (Interfaces added: AGE++) +# (Interfaces removed: AGE=0) +# +AC_INIT(gpgme, 0.3.4, [gnupg-devel@gnupg.org]) +LIBGPGME_LT_CURRENT=7 +LIBGPGME_LT_AGE=1 +LIBGPGME_LT_REVISION=0 +NEED_GPG_VERSION=1.0.6 +NEED_GPGSM_VERSION=0.3.1 +############################################## +AC_PREREQ(2.52) +AC_REVISION($Revision$) + +PACKAGE=$PACKAGE_NAME +VERSION=$PACKAGE_VERSION + +AC_CONFIG_SRCDIR(gpgme/gpgme.h) +AM_CONFIG_HEADER(config.h) +AM_INIT_AUTOMAKE($PACKAGE, $VERSION) +AM_MAINTAINER_MODE + +AC_PROG_CC + + +AC_SUBST(LIBGPGME_LT_CURRENT) +AC_SUBST(LIBGPGME_LT_AGE) +AC_SUBST(LIBGPGME_LT_REVISION) +AC_DEFINE_UNQUOTED(NEED_GPG_VERSION, "$NEED_GPG_VERSION") +AC_DEFINE_UNQUOTED(NEED_GPGSM_VERSION, "$NEED_GPGSM_VERSION") + +AC_SUBST(PACKAGE) +AC_SUBST(VERSION) +AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package]) +AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package]) + +dnl Don't default to build static libs. +dnl AC_DISABLE_STATIC +AC_PROG_LIBTOOL + +GPG_DEFAULT=no +GPGSM_DEFAULT=no +component_system=None +case "${target}" in + *-*-mingw32* | i?86-emx-os2 | i?86-*-os2*emx | i?86-*-msdosdjgpp* ) + # special stuff for Windoze NT + # OS/2 with the EMX environment + # DOS with the DJGPP environment + AC_DEFINE(HAVE_DRIVE_LETTERS) + AC_DEFINE(HAVE_DOSISH_SYSTEM) + GPG_DEFAULT='c:\\gnupg\\gpg.exe' + GPGSM_DEFAULT='c:\\gnupg\\gpgsm.exe' + #component_system='COM+' + ;; + *) +dnl # XXX: Probably use exec-prefix here? +dnl GPG_DEFAULT='/usr/bin/gpg' +dnl GPGSM_DEFAULT='/usr/bin/gpgsm' + ;; +esac + +dnl +dnl Checks for libraries. +dnl + +dnl FIXME: check whether Bonobo is installed + +dnl +dnl Checks for header files. +dnl + +dnl +dnl Checks for typedefs and structures. +dnl +GNUPG_CHECK_TYPEDEF(byte, HAVE_BYTE_TYPEDEF) +GNUPG_CHECK_TYPEDEF(ushort, HAVE_USHORT_TYPEDEF) +GNUPG_CHECK_TYPEDEF(ulong, HAVE_ULONG_TYPEDEF) +GNUPG_CHECK_TYPEDEF(u16, HAVE_U16_TYPEDEF) +GNUPG_CHECK_TYPEDEF(u32, HAVE_U32_TYPEDEF) + +dnl We should not use them in this software; +dnl However jnlib/types.h needs them - so we take the easy way. +AC_CHECK_SIZEOF(unsigned short) +AC_CHECK_SIZEOF(unsigned int) +AC_CHECK_SIZEOF(unsigned long) + +dnl +dnl Checks for compiler features. +dnl + +if test "$GCC" = yes; then + CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes" +fi + +dnl +dnl Checks for library functions. +dnl +dnl These are needed by libjnlib +AC_CHECK_FUNCS(memicmp stpcpy strlwr strtoul memmove stricmp) + +# asprintf() is at least used in assuan +AC_REPLACE_FUNCS(vasprintf) +# Note: fopencokie is only a dummy stub and not used. +# However some code in assuan/ links against it. +AC_REPLACE_FUNCS(fopencookie) + + +dnl We use jnlib, so tell other modules about it +AC_DEFINE(HAVE_JNLIB_LOGGING, 1, + [Defined if jnlib style logging fucntions are available.]) + +dnl +dnl Checks for system services +dnl + +NO_OVERRIDE=no +AC_ARG_WITH(gpg, + AC_HELP_STRING([--with-gpg=PATH], [use GnuPG binary at PATH]), + GPG=$withval, NO_OVERRIDE=yes) +if test "$NO_OVERRIDE" = "yes" || test "$GPG" = "yes"; then + GPG= + NO_OVERRIDE=yes + if test "$cross_compiling" != "yes"; then + AC_PATH_PROG(GPG, gpg) + fi + if test -z "$GPG"; then + GPG="$GPG_DEFAULT" + fi +fi +if test "$GPG" = no; then + if test "$NO_OVERRIDE" = "yes"; then + if test "$cross_compiling" != "yes"; then + AC_MSG_WARN([Could not find GnuPG, install GnuPG or use --with-gpg=PATH to enable it]) + else + AC_MSG_ERROR([Can not determine path to GnuPG when cross-compiling, use --with-gpg=PATH]) + fi + fi +else + AC_DEFINE_UNQUOTED(GPG_PATH, "$GPG") + AC_SUBST(GPG) +fi +AM_CONDITIONAL(RUN_GPG_TESTS, + [test "$cross_compiling" != "yes" && test -n "$GPG" && test -r "$GPG"]) +AC_SUBST(GPG_PATH) + +NO_OVERRIDE=no +AC_ARG_WITH(gpgsm, + AC_HELP_STRING([--with-gpgsm=PATH], [use GpgSM binary at PATH]), + GPGSM=$withval, NO_OVERRIDE=yes) +if test "$NO_OVERRIDE" = "yes" || test "$GPGSM" = "yes"; then + GPGSM= + NO_OVERRIDE=yes + if test "$cross_compiling" != "yes"; then + AC_PATH_PROG(GPGSM, gpgsm) + fi + if test -z "$GPGSM"; then + GPGSM="$GPGSM_DEFAULT" + fi +fi +if test "$GPGSM" = no; then + if test "$NO_OVERRIDE" = "yes"; then + if test "$cross_compiling" != "yes"; then + AC_MSG_WARN([Could not find GpgSM, install GpgSM or use --with-gpgsm=PATH to enable it]) + else + AC_MSG_ERROR([Can not determine path to GpgSM when cross-compiling, use --with-gpgsm=PATH]) + fi + fi +else + AC_DEFINE_UNQUOTED(GPGSM_PATH, "$GPGSM") + AC_SUBST(GPGSM) +fi +AM_CONDITIONAL(RUN_GPGSM_TESTS, + [test "$cross_compiling" != "yes" && test -n "$GPGSM" && test -r "$GPGSM"]) + +dnl FIXME: Only build if supported. +AM_CONDITIONAL(BUILD_ASSUAN, test "$GPGSM" != "no") + +AM_CONDITIONAL(BUILD_COMPLUS, test "$component_system" = "COM+") +AM_CONDITIONAL(BUILD_BONOBO, test "$component_system" = "Bonobo") + +GPGMEPLUG=no +AC_ARG_ENABLE(gpgmeplug, + AC_HELP_STRING([--enable-gpgmeplug], [build GPGME Crypt Plug-In]), + GPGMEPLUG=$enableval) +AM_CONDITIONAL(BUILD_GPGMEPLUG, test "$GPGMEPLUG" = "yes") + +dnl Make the version number in gpgme/gpgme.h the same as the one here. +dnl (this is easier than to have a *.in file just for one substitution) +GNUPG_FIX_HDR_VERSION(gpgme/gpgme.h, GPGME_VERSION) + +dnl Substitution used for gpgme-config +GPGME_LIBS="-L${libdir} -lgpgme" +GPGME_CFLAGS="" +AC_SUBST(GPGME_LIBS) +AC_SUBST(GPGME_CFLAGS) + +dnl +dnl Create config files +dnl + +AC_CONFIG_FILES(Makefile assuan/Makefile jnlib/Makefile gpgme/Makefile + tests/Makefile tests/gpg/Makefile tests/gpgsm/Makefile + doc/Makefile + bonobo/Makefile complus/Makefile gpgmeplug/Makefile) +AC_CONFIG_FILES(gpgme/gpgme-config, chmod +x gpgme/gpgme-config) +AC_OUTPUT + +echo " + GPGME v${VERSION} has been configured as follows: + + GnuPG version: min. $NEED_GPG_VERSION + GnuPG path: $GPG + + GpgSM version: min. $NEED_GPGSM_VERSION + GpgSM path: $GPGSM + + GPGME CryptPlug: $GPGMEPLUG +" diff --git a/tags/V0-3-4/doc/.cvsignore b/tags/V0-3-4/doc/.cvsignore new file mode 100644 index 0000000..aa61a42 --- /dev/null +++ b/tags/V0-3-4/doc/.cvsignore @@ -0,0 +1 @@ +Makefile.in Makefile diff --git a/tags/V0-3-4/doc/ChangeLog b/tags/V0-3-4/doc/ChangeLog new file mode 100644 index 0000000..a4c733e --- /dev/null +++ b/tags/V0-3-4/doc/ChangeLog @@ -0,0 +1,107 @@ +2002-03-03 Marcus Brinkmann + + * gpgme.texi (Information About Keys): Document GPGME_ATTR_EXPIRE. + +2002-03-03 Marcus Brinkmann + + * gpgme.texi (Verify): Document verification of normal and + cleartext signatures. + +2002-02-27 Marcus Brinkmann + + * gpgme.texi (Listing Keys): Document gpgme_op_keylist_ext_start. + +2002-02-27 Marcus Brinkmann + + * gpgme.texi (Encrypting a Plaintext): Document + GPGME_Invalid_Recipients. + (Error Values): Likewise. + +2002-02-26 Marcus Brinkmann + + * gpgme.texi (Encrypting a Plaintext): Document + gpgme_op_encrypt_sign and gpgme_op_encrypt_sign_start. + +2002-02-25 Marcus Brinkmann + + * gpgme.texi (Creating a Signature): Add a note about + certificates to include. + (Included Certificates): New section. + +2002-02-09 Marcus Brinkmann + + * gpgme.texi (Detailed Results): Remove literal tags. + (Generating Keys): Update documentation. + + * gpgme.texi (Generating Keys): Fix syntax error. + +2002-02-06 Marcus Brinkmann + + * gpgme.texi (Waiting For Completion): Adjust doc to changes in + the code. + +2002-02-06 Marcus Brinkmann + + * gpgme.texi (Key Listing Mode): Update documentation. + +2002-01-31 Marcus Brinkmann + + * gpgme.texi (Generating Keys): Document error at creation + failure. + +2002-01-30 Marcus Brinkmann + + * gpgme.texi (Deleting Keys): Document new error values. + +2002-01-30 Marcus Brinkmann + + * gpgme.texi (Importing Keys): Add reference to gpgme_get_op_info. + +2002-01-30 Marcus Brinkmann + + * gpgme.texi: Some spell checking. + +2002-01-30 Marcus Brinkmann + + * gpgme.texi: Add all the gpgme_op_*_start functions. + Fill the concept index with many, many entries. + +2002-01-29 Marcus Brinkmann + + * gpgme.texi (Run Control): New section. + (Verify): Docuent gpgme_get_notation. + (More Information): New section describing gpgme_get_op_info. + +2002-01-22 Marcus Brinkmann + + * gpgme.texi (Passphrase callback): Change GpgmePassphraseCb's + R_HD type from void* to void**. + +2002-01-22 Marcus Brinkmann + + * gpgme.texi (Creating data buffers): Change + gpgme_data_new_from_filepart's LENGTH type from off_t to size_t. + +2002-01-22 Marcus Brinkmann + + * gpgme.texi (Generating keys): New subsection. + (Exporting keys): Likewise. + (Importing keys): Likewise. + (Deleting keys): Likewise. + +2002-01-16 Marcus Brinkmann + + * gpgme.texi: g10Code -> g10 Code + + * gpgme.texi (Top): Complete detailmenu. + + * gpgme.texi: Convert embarassing cruft to the real thing. + +2002-01-16 Marcus Brinkmann + + * ChangeLog: New file. + * gpgme.texi: Likewise. + * gpl.texi: Likewise. + * fdl.texi: Likewise. + * Makefile.am (info_TEXINFOS): New variable. + (gpgme_TEXINFOS): Likewise. diff --git a/tags/V0-3-4/doc/Makefile.am b/tags/V0-3-4/doc/Makefile.am new file mode 100644 index 0000000..ce11810 --- /dev/null +++ b/tags/V0-3-4/doc/Makefile.am @@ -0,0 +1,25 @@ +# doc - Automake template +# Copyright (C) 2001 g10 Code GmbH +# +# This file is part of GPGME. +# +# GPGME is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# GPGME is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +## Process this file with automake to produce Makefile.in + +EXTRA_DIST = gdoc + +info_TEXINFOS = gpgme.texi +gpgme_TEXINFOS = gpl.texi fdl.texi diff --git a/tags/V0-3-4/doc/fdl.texi b/tags/V0-3-4/doc/fdl.texi new file mode 100644 index 0000000..50028ab --- /dev/null +++ b/tags/V0-3-4/doc/fdl.texi @@ -0,0 +1,402 @@ +@node Free Documentation License +@appendix GNU Free Documentation License + +@cindex FDL, GNU Free Documentation License +@center Version 1.1, March 2000 + +@display +Copyright @copyright{} 2000 Free Software Foundation, Inc. +59 Temple Place, Suite 330, Boston, MA 02111-1307, USA + +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. +@end display + +@enumerate 0 +@item +PREAMBLE + +The purpose of this License is to make a manual, textbook, or other +written document @dfn{free} in the sense of freedom: to assure everyone +the effective freedom to copy and redistribute it, with or without +modifying it, either commercially or noncommercially. Secondarily, +this License preserves for the author and publisher a way to get +credit for their work, while not being considered responsible for +modifications made by others. + +This License is a kind of ``copyleft'', which means that derivative +works of the document must themselves be free in the same sense. It +complements the GNU General Public License, which is a copyleft +license designed for free software. + +We have designed this License in order to use it for manuals for free +software, because free software needs free documentation: a free +program should come with manuals providing the same freedoms that the +software does. But this License is not limited to software manuals; +it can be used for any textual work, regardless of subject matter or +whether it is published as a printed book. We recommend this License +principally for works whose purpose is instruction or reference. + +@item +APPLICABILITY AND DEFINITIONS + +This License applies to any manual or other work that contains a +notice placed by the copyright holder saying it can be distributed +under the terms of this License. The ``Document'', below, refers to any +such manual or work. Any member of the public is a licensee, and is +addressed as ``you''. + +A ``Modified Version'' of the Document means any work containing the +Document or a portion of it, either copied verbatim, or with +modifications and/or translated into another language. + +A ``Secondary Section'' is a named appendix or a front-matter section of +the Document that deals exclusively with the relationship of the +publishers or authors of the Document to the Document's overall subject +(or to related matters) and contains nothing that could fall directly +within that overall subject. (For example, if the Document is in part a +textbook of mathematics, a Secondary Section may not explain any +mathematics.) The relationship could be a matter of historical +connection with the subject or with related matters, or of legal, +commercial, philosophical, ethical or political position regarding +them. + +The ``Invariant Sections'' are certain Secondary Sections whose titles +are designated, as being those of Invariant Sections, in the notice +that says that the Document is released under this License. + +The ``Cover Texts'' are certain short passages of text that are listed, +as Front-Cover Texts or Back-Cover Texts, in the notice that says that +the Document is released under this License. + +A ``Transparent'' copy of the Document means a machine-readable copy, +represented in a format whose specification is available to the +general public, whose contents can be viewed and edited directly and +straightforwardly with generic text editors or (for images composed of +pixels) generic paint programs or (for drawings) some widely available +drawing editor, and that is suitable for input to text formatters or +for automatic translation to a variety of formats suitable for input +to text formatters. A copy made in an otherwise Transparent file +format whose markup has been designed to thwart or discourage +subsequent modification by readers is not Transparent. A copy that is +not ``Transparent'' is called ``Opaque''. + +Examples of suitable formats for Transparent copies include plain +@sc{ascii} without markup, Texinfo input format, La@TeX{} input format, +@acronym{SGML} or @acronym{XML} using a publicly available +@acronym{DTD}, and standard-conforming simple @acronym{HTML} designed +for human modification. Opaque formats include PostScript, +@acronym{PDF}, proprietary formats that can be read and edited only by +proprietary word processors, @acronym{SGML} or @acronym{XML} for which +the @acronym{DTD} and/or processing tools are not generally available, +and the machine-generated @acronym{HTML} produced by some word +processors for output purposes only. + +The ``Title Page'' means, for a printed book, the title page itself, +plus such following pages as are needed to hold, legibly, the material +this License requires to appear in the title page. For works in +formats which do not have any title page as such, ``Title Page'' means +the text near the most prominent appearance of the work's title, +preceding the beginning of the body of the text. + +@item +VERBATIM COPYING + +You may copy and distribute the Document in any medium, either +commercially or noncommercially, provided that this License, the +copyright notices, and the license notice saying this License applies +to the Document are reproduced in all copies, and that you add no other +conditions whatsoever to those of this License. You may not use +technical measures to obstruct or control the reading or further +copying of the copies you make or distribute. However, you may accept +compensation in exchange for copies. If you distribute a large enough +number of copies you must also follow the conditions in section 3. + +You may also lend copies, under the same conditions stated above, and +you may publicly display copies. + +@item +COPYING IN QUANTITY + +If you publish printed copies of the Document numbering more than 100, +and the Document's license notice requires Cover Texts, you must enclose +the copies in covers that carry, clearly and legibly, all these Cover +Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on +the back cover. Both covers must also clearly and legibly identify +you as the publisher of these copies. The front cover must present +the full title with all words of the title equally prominent and +visible. You may add other material on the covers in addition. +Copying with changes limited to the covers, as long as they preserve +the title of the Document and satisfy these conditions, can be treated +as verbatim copying in other respects. + +If the required texts for either cover are too voluminous to fit +legibly, you should put the first ones listed (as many as fit +reasonably) on the actual cover, and continue the rest onto adjacent +pages. + +If you publish or distribute Opaque copies of the Document numbering +more than 100, you must either include a machine-readable Transparent +copy along with each Opaque copy, or state in or with each Opaque copy +a publicly-accessible computer-network location containing a complete +Transparent copy of the Document, free of added material, which the +general network-using public has access to download anonymously at no +charge using public-standard network protocols. If you use the latter +option, you must take reasonably prudent steps, when you begin +distribution of Opaque copies in quantity, to ensure that this +Transparent copy will remain thus accessible at the stated location +until at least one year after the last time you distribute an Opaque +copy (directly or through your agents or retailers) of that edition to +the public. + +It is requested, but not required, that you contact the authors of the +Document well before redistributing any large number of copies, to give +them a chance to provide you with an updated version of the Document. + +@item +MODIFICATIONS + +You may copy and distribute a Modified Version of the Document under +the conditions of sections 2 and 3 above, provided that you release +the Modified Version under precisely this License, with the Modified +Version filling the role of the Document, thus licensing distribution +and modification of the Modified Version to whoever possesses a copy +of it. In addition, you must do these things in the Modified Version: + +@enumerate A +@item +Use in the Title Page (and on the covers, if any) a title distinct +from that of the Document, and from those of previous versions +(which should, if there were any, be listed in the History section +of the Document). You may use the same title as a previous version +if the original publisher of that version gives permission. + +@item +List on the Title Page, as authors, one or more persons or entities +responsible for authorship of the modifications in the Modified +Version, together with at least five of the principal authors of the +Document (all of its principal authors, if it has less than five). + +@item +State on the Title page the name of the publisher of the +Modified Version, as the publisher. + +@item +Preserve all the copyright notices of the Document. + +@item +Add an appropriate copyright notice for your modifications +adjacent to the other copyright notices. + +@item +Include, immediately after the copyright notices, a license notice +giving the public permission to use the Modified Version under the +terms of this License, in the form shown in the Addendum below. + +@item +Preserve in that license notice the full lists of Invariant Sections +and required Cover Texts given in the Document's license notice. + +@item +Include an unaltered copy of this License. + +@item +Preserve the section entitled ``History'', and its title, and add to +it an item stating at least the title, year, new authors, and +publisher of the Modified Version as given on the Title Page. If +there is no section entitled ``History'' in the Document, create one +stating the title, year, authors, and publisher of the Document as +given on its Title Page, then add an item describing the Modified +Version as stated in the previous sentence. + +@item +Preserve the network location, if any, given in the Document for +public access to a Transparent copy of the Document, and likewise +the network locations given in the Document for previous versions +it was based on. These may be placed in the ``History'' section. +You may omit a network location for a work that was published at +least four years before the Document itself, or if the original +publisher of the version it refers to gives permission. + +@item +In any section entitled ``Acknowledgments'' or ``Dedications'', +preserve the section's title, and preserve in the section all the +substance and tone of each of the contributor acknowledgments +and/or dedications given therein. + +@item +Preserve all the Invariant Sections of the Document, +unaltered in their text and in their titles. Section numbers +or the equivalent are not considered part of the section titles. + +@item +Delete any section entitled ``Endorsements''. Such a section +may not be included in the Modified Version. + +@item +Do not retitle any existing section as ``Endorsements'' +or to conflict in title with any Invariant Section. +@end enumerate + +If the Modified Version includes new front-matter sections or +appendices that qualify as Secondary Sections and contain no material +copied from the Document, you may at your option designate some or all +of these sections as invariant. To do this, add their titles to the +list of Invariant Sections in the Modified Version's license notice. +These titles must be distinct from any other section titles. + +You may add a section entitled ``Endorsements'', provided it contains +nothing but endorsements of your Modified Version by various +parties---for example, statements of peer review or that the text has +been approved by an organization as the authoritative definition of a +standard. + +You may add a passage of up to five words as a Front-Cover Text, and a +passage of up to 25 words as a Back-Cover Text, to the end of the list +of Cover Texts in the Modified Version. Only one passage of +Front-Cover Text and one of Back-Cover Text may be added by (or +through arrangements made by) any one entity. If the Document already +includes a cover text for the same cover, previously added by you or +by arrangement made by the same entity you are acting on behalf of, +you may not add another; but you may replace the old one, on explicit +permission from the previous publisher that added the old one. + +The author(s) and publisher(s) of the Document do not by this License +give permission to use their names for publicity for or to assert or +imply endorsement of any Modified Version. + +@item +COMBINING DOCUMENTS + +You may combine the Document with other documents released under this +License, under the terms defined in section 4 above for modified +versions, provided that you include in the combination all of the +Invariant Sections of all of the original documents, unmodified, and +list them all as Invariant Sections of your combined work in its +license notice. + +The combined work need only contain one copy of this License, and +multiple identical Invariant Sections may be replaced with a single +copy. If there are multiple Invariant Sections with the same name but +different contents, make the title of each such section unique by +adding at the end of it, in parentheses, the name of the original +author or publisher of that section if known, or else a unique number. +Make the same adjustment to the section titles in the list of +Invariant Sections in the license notice of the combined work. + +In the combination, you must combine any sections entitled ``History'' +in the various original documents, forming one section entitled +``History''; likewise combine any sections entitled ``Acknowledgments'', +and any sections entitled ``Dedications''. You must delete all sections +entitled ``Endorsements.'' + +@item +COLLECTIONS OF DOCUMENTS + +You may make a collection consisting of the Document and other documents +released under this License, and replace the individual copies of this +License in the various documents with a single copy that is included in +the collection, provided that you follow the rules of this License for +verbatim copying of each of the documents in all other respects. + +You may extract a single document from such a collection, and distribute +it individually under this License, provided you insert a copy of this +License into the extracted document, and follow this License in all +other respects regarding verbatim copying of that document. + +@item +AGGREGATION WITH INDEPENDENT WORKS + +A compilation of the Document or its derivatives with other separate +and independent documents or works, in or on a volume of a storage or +distribution medium, does not as a whole count as a Modified Version +of the Document, provided no compilation copyright is claimed for the +compilation. Such a compilation is called an ``aggregate'', and this +License does not apply to the other self-contained works thus compiled +with the Document, on account of their being thus compiled, if they +are not themselves derivative works of the Document. + +If the Cover Text requirement of section 3 is applicable to these +copies of the Document, then if the Document is less than one quarter +of the entire aggregate, the Document's Cover Texts may be placed on +covers that surround only the Document within the aggregate. +Otherwise they must appear on covers around the whole aggregate. + +@item +TRANSLATION + +Translation is considered a kind of modification, so you may +distribute translations of the Document under the terms of section 4. +Replacing Invariant Sections with translations requires special +permission from their copyright holders, but you may include +translations of some or all Invariant Sections in addition to the +original versions of these Invariant Sections. You may include a +translation of this License provided that you also include the +original English version of this License. In case of a disagreement +between the translation and the original English version of this +License, the original English version will prevail. + +@item +TERMINATION + +You may not copy, modify, sublicense, or distribute the Document except +as expressly provided for under this License. Any other attempt to +copy, modify, sublicense or distribute the Document is void, and will +automatically terminate your rights under this License. However, +parties who have received copies, or rights, from you under this +License will not have their licenses terminated so long as such +parties remain in full compliance. + +@item +FUTURE REVISIONS OF THIS LICENSE + +The Free Software Foundation may publish new, revised versions +of the GNU Free Documentation License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. See +@uref{http://www.gnu.org/copyleft/}. + +Each version of the License is given a distinguishing version number. +If the Document specifies that a particular numbered version of this +License ``or any later version'' applies to it, you have the option of +following the terms and conditions either of that specified version or +of any later version that has been published (not as a draft) by the +Free Software Foundation. If the Document does not specify a version +number of this License, you may choose any version ever published (not +as a draft) by the Free Software Foundation. +@end enumerate + +@page +@appendixsubsec ADDENDUM: How to use this License for your documents + +To use this License in a document you have written, include a copy of +the License in the document and put the following copyright and +license notices just after the title page: + +@smallexample +@group + Copyright (C) @var{year} @var{your name}. + Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU Free Documentation License, Version 1.1 + or any later version published by the Free Software Foundation; + with the Invariant Sections being @var{list their titles}, with the + Front-Cover Texts being @var{list}, and with the Back-Cover Texts being @var{list}. + A copy of the license is included in the section entitled ``GNU + Free Documentation License''. +@end group +@end smallexample + +If you have no Invariant Sections, write ``with no Invariant Sections'' +instead of saying which ones are invariant. If you have no +Front-Cover Texts, write ``no Front-Cover Texts'' instead of +``Front-Cover Texts being @var{list}''; likewise for Back-Cover Texts. + +If your document contains nontrivial examples of program code, we +recommend releasing these examples in parallel under your choice of +free software license, such as the GNU General Public License, +to permit their use in free software. + +@c Local Variables: +@c ispell-local-pdict: "ispell-dict" +@c End: + diff --git a/tags/V0-3-4/doc/gdoc b/tags/V0-3-4/doc/gdoc new file mode 100755 index 0000000..a1c314d --- /dev/null +++ b/tags/V0-3-4/doc/gdoc @@ -0,0 +1,681 @@ +#!/usr/bin/perl + +## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## +## hacked to allow -tex option --nmav ## +## ## +## This software falls under the GNU Public License. Please read ## +## the COPYING file for more information ## + +# +# This will read a 'c' file and scan for embedded comments in the +# style of gnome comments (+minor extensions - see below). +# + +# Note: This only supports 'c'. + +# usage: +# gdoc [ -docbook | -html | -text | -man ] +# [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile +# +# Set output format using one of -docbook -html -text or -man. Default is man. +# +# -function funcname +# If set, then only generate documentation for the given function(s). All +# other functions are ignored. +# +# c files - list of 'c' files to process +# +# All output goes to stdout, with errors to stderr. + +# +# format of comments. +# In the following table, (...)? signifies optional structure. +# (...)* signifies 0 or more structure elements +# /** +# * function_name(:)? (- short description)? +# (* @parameterx: (description of parameter x)?)* +# (* a blank line)? +# * (Description:)? (Description of function)? +# * (section header: (section description)? )* +# (*)?*/ +# +# So .. the trivial example would be: +# +# /** +# * my_function +# **/ +# +# If the Description: header tag is ommitted, then there must be a blank line +# after the last parameter specification. +# e.g. +# /** +# * my_function - does my stuff +# * @my_arg: its mine damnit +# * +# * Does my stuff explained. +# */ +# +# or, could also use: +# /** +# * my_function - does my stuff +# * @my_arg: its mine damnit +# * Description: Does my stuff explained. +# */ +# etc. +# +# All descriptions can be multiline, apart from the short function description. +# +# All descriptive text is further processed, scanning for the following special +# patterns, which are highlighted appropriately. +# +# 'funcname()' - function +# '$ENVVAR' - environmental variable +# '&struct_name' - name of a structure +# '@parameter' - name of a parameter +# '%CONST' - name of a constant. + +# match expressions used to find embedded type information +$type_constant = "\\\%(\\w+)"; +#$type_func = "(\\w+\\(\\))"; +$type_func = "(\\(w||\\\\)+\\(\\))"; +$type_param = "\\\@(\\w+)"; +$type_struct = "\\\&(\\w+)"; +$type_env = "(\\\$\\w+)"; + + +# Output conversion substitutions. +# One for each output format + +# these work fairly well +%highlights_html = ( $type_constant, "\$1", + $type_func, "\$1", + $type_struct, "\$1", + $type_param, "\$1" ); +$blankline_html = "

"; + +%highlights_tex = ( $type_constant, "{\\\\it \$1}", + $type_func, "{\\\\bf \$1}", + $type_struct, "{\\\\it \$1}", + $type_param, "{\\\\bf \$1}" ); +$blankline_tex = "\\par"; + +# sgml, docbook format +%highlights_sgml = ( $type_constant, "\$1", + $type_func, "\$1", + $type_struct, "\$1", + $type_env, "\$1", + $type_param, "\$1" ); +$blankline_sgml = "\n"; + +# these are pretty rough +%highlights_man = ( $type_constant, "\\n.I \\\"\$1\\\"\\n", + $type_func, "\\n.B \\\"\$1\\\"\\n", + $type_struct, "\\n.I \\\"\$1\\\"\\n", + $type_param."([\.\, ]*)\n?", "\\n.I \\\"\$1\$2\\\"\\n" ); +$blankline_man = ""; + +# text-mode +%highlights_text = ( $type_constant, "\$1", + $type_func, "\$1", + $type_struct, "\$1", + $type_param, "\$1" ); +$blankline_text = ""; + + +sub usage { + print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man | -tex ]\n"; + print " [ -function funcname [ -function funcname ...] ]\n"; + print " c source file(s) > outputfile\n"; + exit 1; +} + +# read arguments +if ($#ARGV==-1) { + usage(); +} + +$verbose = 0; +$output_mode = "man"; +%highlights = %highlights_man; +$blankline = $blankline_man; +$modulename = "API Documentation"; +$function_only = 0; +while ($ARGV[0] =~ m/^-(.*)/) { + $cmd = shift @ARGV; + if ($cmd eq "-html") { + $output_mode = "html"; + %highlights = %highlights_html; + $blankline = $blankline_html; + } elsif ($cmd eq "-man") { + $output_mode = "man"; + %highlights = %highlights_man; + $blankline = $blankline_man; + } elsif ($cmd eq "-tex") { + $output_mode = "tex"; + %highlights = %highlights_tex; + $blankline = $blankline_tex; + } elsif ($cmd eq "-text") { + $output_mode = "text"; + %highlights = %highlights_text; + $blankline = $blankline_text; + } elsif ($cmd eq "-docbook") { + $output_mode = "sgml"; + %highlights = %highlights_sgml; + $blankline = $blankline_sgml; + } elsif ($cmd eq "-module") { # not needed for sgml, inherits from calling document + $modulename = shift @ARGV; + } elsif ($cmd eq "-function") { # to only output specific functions + $function_only = 1; + $function = shift @ARGV; + $function_table{$function} = 1; + } elsif ($cmd eq "-v") { + $verbose = 1; + } elsif (($cmd eq "-h") || ($cmd eq "--help")) { + usage(); + } +} + + +# generate a sequence of code that will splice in highlighting information +# using the s// operator. +$dohighlight = ""; +foreach $pattern (keys %highlights) { +# print "scanning pattern $pattern ($highlights{$pattern})\n"; + $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n"; +} + +## +# dumps section contents to arrays/hashes intended for that purpose. +# +sub dump_section { + my $name = shift @_; + my $contents = join "\n", @_; + + if ($name =~ m/$type_constant/) { + $name = $1; +# print STDERR "constant section '$1' = '$contents'\n"; + $constants{$name} = $contents; + } elsif ($name =~ m/$type_param/) { +# print STDERR "parameter def '$1' = '$contents'\n"; + $name = $1; + $parameters{$name} = $contents; + } else { +# print STDERR "other section '$name' = '$contents'\n"; + $sections{$name} = $contents; + push @sectionlist, $name; + } +} + +## +# output function +# +# parameters, a hash. +# function => "function name" +# parameterlist => @list of parameters +# parameters => %parameter descriptions +# sectionlist => @list of sections +# sections => %descriont descriptions +# + +sub output_highlight { + my $contents = join "\n", @_; + my $line; + + eval $dohighlight; + foreach $line (split "\n", $contents) { + if ($line eq ""){ + print $lineprefix, $blankline; + } else { + print $lineprefix, $line; + } + print "\n"; + } +} + + +# output in html +sub output_html { + my %args = %{$_[0]}; + my ($parameter, $section); + my $count; + print "\n\n 

Function

\n"; + + print "".$args{'functiontype'}."\n"; + print "".$args{'function'}."\n"; + print "("; + $count = 0; + foreach $parameter (@{$args{'parameterlist'}}) { + print "".$args{'parametertypes'}{$parameter}." ".$parameter."\n"; + if ($count != $#{$args{'parameterlist'}}) { + $count++; + print ", "; + } + } + print ")\n"; + + print "

Arguments

\n"; + print "
\n"; + foreach $parameter (@{$args{'parameterlist'}}) { + print "
".$args{'parametertypes'}{$parameter}." ".$parameter."\n"; + print "
"; + output_highlight($args{'parameters'}{$parameter}); + } + print "
\n"; + foreach $section (@{$args{'sectionlist'}}) { + print "

$section

\n"; + print "
    \n"; + output_highlight($args{'sections'}{$section}); + print "
\n"; + } + print "
\n"; +} + +# output in tex +sub output_tex { + my %args = %{$_[0]}; + my ($parameter, $section); + my $count; + my $func = $args{'function'}; + my $param; + my $param2; + my $sec; + my $check; + my $type; + + $func =~ s/_/\\_/g; + + print "\n\n\\subsection{". $func . "}\n\\label{" . $args{'function'} . "}\n"; + + $type = $args{'functiontype'}; + $type =~ s/_/\\_/g; + + print "{\\it ".$type."}\n"; + print "{\\bf ".$func."}\n"; + print "(\n"; + $count = 0; + foreach $parameter (@{$args{'parameterlist'}}) { + $param = $args{'parametertypes'}{$parameter}; + $param2 = $parameter; + $param =~ s/_/\\_/g; + $param2 =~ s/_/\\_/g; + + print "{\\it ".$param."} {\\bf ".$param2."}\n"; + if ($count != $#{$args{'parameterlist'}}) { + $count++; + print ", "; + } + } + print ")\n"; + + print "\n{\\large{Arguments}}\n"; + + print "\\begin{itemize}\n"; + $check=0; + foreach $parameter (@{$args{'parameterlist'}}) { + $param = $args{'parametertypes'}{$parameter}; + $param =~ s/_/\\_/g; + $param2 = $parameter; + $param2 =~ s/_/\\_/g; + + $check = 1; + print "\\item {\\it ".$param."} {\\bf ".$param2."}\n"; + print "\n"; + + output_highlight($param{$parameter}); + } + if ($check==0) { + print "\\item void\n"; + } + print "\\end{itemize}\n"; + + foreach $section (@{$args{'sectionlist'}}) { + print "\n\\par{\\large{$section}}\\par\n"; + print "\\begin{rmfamily}\n"; + + $sec = $args{'sections'}{$section}; + $sec =~ s/_/\\_/g; + $sec =~ s/&/\\&/g; + output_highlight($sec); + print "\\end{rmfamily}\n"; + } + print "\n"; +} + + +# output in sgml DocBook +sub output_sgml { + my %args = %{$_[0]}; + my ($parameter, $section); + my $count; + my $id; + + $id = $args{'module'}."-".$args{'function'}; + $id =~ s/[^A-Za-z0-9]/-/g; + + print "\n"; + print "\n"; + print "".$args{'function'}."\n"; + print "\n"; + print "\n"; + print " ".$args{'function'}."\n"; + print " \n"; + print " ".$args{'purpose'}."\n"; + print " \n"; + print "\n"; + + print "\n"; + print " Synopsis\n"; + print " \n"; + print " ".$args{'functiontype'}." "; + print "".$args{'function'}." "; + print "\n"; + +# print "\n"; +# print " Synopsis\n"; +# print " \n"; +# print " ".$args{'functiontype'}." "; +# print "".$args{'function'}." "; +# print "\n"; + + $count = 0; + if ($#{$args{'parameterlist'}} >= 0) { + foreach $parameter (@{$args{'parameterlist'}}) { + print " ".$args{'parametertypes'}{$parameter}; + print " $parameter\n"; + } + } else { + print " \n"; + } + print " \n"; + print "\n"; +# print "\n"; + + # print parameters + print "\n Arguments\n"; +# print "\nArguments\n"; + if ($#{$args{'parameterlist'}} >= 0) { + print " \n"; + foreach $parameter (@{$args{'parameterlist'}}) { + print " \n $parameter\n"; + print " \n \n"; + $lineprefix=" "; + output_highlight($args{'parameters'}{$parameter}); + print " \n \n \n"; + } + print " \n"; + } else { + print " \n None\n \n"; + } + print "\n"; + + # print out each section + $lineprefix=" "; + foreach $section (@{$args{'sectionlist'}}) { + print "\n $section\n \n"; +# print "\n$section\n"; + if ($section =~ m/EXAMPLE/i) { + print "\n"; + } + output_highlight($args{'sections'}{$section}); +# print ""; + if ($section =~ m/EXAMPLE/i) { + print "\n"; + } + print " \n\n"; + } + + print "\n\n"; +} + +## +# output in man +sub output_man { + my %args = %{$_[0]}; + my ($parameter, $section); + my $count; + + print ".TH \"$args{'module'}\" \"$args{'function'}\" \"25 May 1998\" \"API Manual\" GNOME\n"; + + print ".SH Function\n"; + + print ".I \"".$args{'functiontype'}."\"\n"; + print ".B \"".$args{'function'}."\"\n"; + print "(\n"; + $count = 0; + foreach $parameter (@{$args{'parameterlist'}}) { + print ".I \"".$args{'parametertypes'}{$parameter}."\"\n.B \"".$parameter."\"\n"; + if ($count != $#{$args{'parameterlist'}}) { + $count++; + print ",\n"; + } + } + print ")\n"; + + print ".SH Arguments\n"; + foreach $parameter (@{$args{'parameterlist'}}) { + print ".IP \"".$args{'parametertypes'}{$parameter}." ".$parameter."\" 12\n"; + output_highlight($args{'parameters'}{$parameter}); + } + foreach $section (@{$args{'sectionlist'}}) { + print ".SH \"$section\"\n"; + output_highlight($args{'sections'}{$section}); + } +} + +## +# output in text +sub output_text { + my %args = %{$_[0]}; + my ($parameter, $section); + + print "Function = ".$args{'function'}."\n"; + print " return type: ".$args{'functiontype'}."\n\n"; + foreach $parameter (@{$args{'parameterlist'}}) { + print " ".$args{'parametertypes'}{$parameter}." ".$parameter."\n"; + print " -> ".$args{'parameters'}{$parameter}."\n"; + } + foreach $section (@{$args{'sectionlist'}}) { + print " $section:\n"; + print " -> "; + output_highlight($args{'sections'}{$section}); + } +} + +## +# generic output function - calls the right one based +# on current output mode. +sub output_function { +# output_html(@_); + eval "output_".$output_mode."(\@_);"; +} + + +## +# takes a function prototype and spits out all the details +# stored in the global arrays/hsahes. +sub dump_function { + my $prototype = shift @_; + + if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ || + $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ || + $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ || + $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/) { + $return_type = $1; + $function_name = $2; + $args = $3; + +# print STDERR "ARGS = '$args'\n"; + + foreach $arg (split ',', $args) { + # strip leading/trailing spaces + $arg =~ s/^\s*//; + $arg =~ s/\s*$//; +# print STDERR "SCAN ARG: '$arg'\n"; + @args = split('\s', $arg); + +# print STDERR " -> @args\n"; + $param = pop @args; +# print STDERR " -> @args\n"; + if ($param =~ m/^(\*+)(.*)/) { + $param = $2; + push @args, $1; + } + $type = join " ", @args; + + if ($parameters{$param} eq "") { + $parameters{$param} = "-- undescribed --"; + print STDERR "Warning($lineno): Function parameter '$param' not described in '$function_name'\n"; + } + + push @parameterlist, $param; + $parametertypes{$param} = $type; + +# print STDERR "param = '$param', type = '$type'\n"; + } + } else { + print STDERR "Error($lineno): cannot understand prototype: '$prototype'\n"; + return; + } + + if ($function_only==0 || defined($function_table{$function_name})) { + output_function({'function' => $function_name, + 'module' => $modulename, + 'functiontype' => $return_type, + 'parameterlist' => \@parameterlist, + 'parameters' => \%parameters, + 'parametertypes' => \%parametertypes, + 'sectionlist' => \@sectionlist, + 'sections' => \%sections, + 'purpose' => $function_purpose + }); + } +} + +###################################################################### +# main +# states +# 0 - normal code +# 1 - looking for function name +# 2 - scanning field start. +# 3 - scanning prototype. +$state = 0; +$section = ""; + +$doc_special = "\@\%\$\&"; + +$doc_start = "^/\\*\\*\$"; +$doc_end = "\\*/"; +$doc_com = "\\s*\\*\\s*"; +$doc_func = $doc_com."(\\w+):?"; +$doc_sect = $doc_com."([".$doc_special."]?[\\w ]+):(.*)"; +$doc_content = $doc_com."(.*)"; + +%constants = (); +%parameters = (); +@parameterlist = (); +%sections = (); +@sectionlist = (); + +$contents = ""; +$section_default = "Description"; # default section +$section = $section_default; + +$lineno = 0; +foreach $file (@ARGV) { + if (!open(IN,"<$file")) { + print STDERR "Error: Cannot open file $file\n"; + next; + } + while () { + $lineno++; + + if ($state == 0) { + if (/$doc_start/o) { + $state = 1; # next line is always the function name + } + } elsif ($state == 1) { # this line is the function name (always) + if (/$doc_func/o) { + $function = $1; + $state = 2; + if (/-(.*)/) { + $function_purpose = $1; + } else { + $function_purpose = ""; + } + if ($verbose) { + print STDERR "Info($lineno): Scanning doc for $function\n"; + } + } else { + print STDERR "WARN($lineno): Cannot understand $_ on line $lineno", + " - I thought it was a doc line\n"; + $state = 0; + } + } elsif ($state == 2) { # look for head: lines, and include content + if (/$doc_sect/o) { + $newsection = $1; + $newcontents = $2; + + if ($contents ne "") { + dump_section($section, $contents); + $section = $section_default; + } + + $contents = $newcontents; + if ($contents ne "") { + $contents .= "\n"; + } + $section = $newsection; + } elsif (/$doc_end/) { + + if ($contents ne "") { + dump_section($section, $contents); + $section = $section_default; + $contents = ""; + } + +# print STDERR "end of doc comment, looking for prototype\n"; + $prototype = ""; + $state = 3; + } elsif (/$doc_content/) { + # miguel-style comment kludge, look for blank lines after + # @parameter line to signify start of description + if ($1 eq "" && $section =~ m/^@/) { + dump_section($section, $contents); + $section = $section_default; + $contents = ""; + } else { + $contents .= $1."\n"; + } + } else { + # i dont know - bad line? ignore. + print STDERR "WARNING($lineno): bad line: $_"; + } + } elsif ($state == 3) { # scanning for function { (end of prototype) + if (m#\s*/\*\s+MACDOC\s*#io) { + # do nothing + } + elsif (/([^\{]*)/) { + $prototype .= $1; + } + if (/\{/) { + $prototype =~ s@/\*.*?\*/@@gos; # strip comments. + $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. + $prototype =~ s@^ +@@gos; # strip leading spaces + dump_function($prototype); + + $function = ""; + %constants = (); + %parameters = (); + %parametertypes = (); + @parameterlist = (); + %sections = (); + @sectionlist = (); + $prototype = ""; + + $state = 0; + } + } + } +} + diff --git a/tags/V0-3-4/doc/gpgme.texi b/tags/V0-3-4/doc/gpgme.texi new file mode 100644 index 0000000..fb3cbe3 --- /dev/null +++ b/tags/V0-3-4/doc/gpgme.texi @@ -0,0 +1,2435 @@ +\input texinfo @c -*- Texinfo -*- +@setfilename gpgme.info +@settitle The `GnuPG Made Easy' Reference Manual + +@dircategory GNU Libraries +@direntry +* @acronym{GPGME}: (gpgme) Adding support for cryptography to your program. +@end direntry + +@include version.texi + +@c Unify some of the indices. +@syncodeindex tp fn +@syncodeindex pg fn + +@ifinfo +This file documents the @acronym{GPGME} library. + +This is Edition @value{EDITION}, last updated @value{UPDATED}, of +@cite{The `GnuPG Made Easy' Reference Manual}, for Version +@value{VERSION}. + +Copyright @copyright{} 2002 g10 Code GmbH. + +Permission is granted to copy, distribute and/or modify this document +under the terms of the GNU Free Documentation License, Version 1.1 or +any later version published by the Free Software Foundation; with the +Invariant Sections being ``Free Software Needs Free Documentation'' and +``GNU Lesser General Public License'', the Front-Cover texts being (a) +(see below), and with the Back-Cover Texts being (b) (see below). A +copy of the license is included in the section entitled ``GNU Free +Documentation License''. + +@end ifinfo + +@iftex +@shorttitlepage The `GnuPG Made Easy' Reference Manual +@end iftex +@titlepage +@center @titlefont{The `GnuPG Made Easy'} +@sp 1 +@center @titlefont{Reference Manual} +@sp 6 +@center Edition @value{EDITION} +@sp 1 +@center last updated @value{UPDATED} +@sp 1 +@center for version @value{VERSION} +@page +@vskip 0pt plus 1filll +Copyright @copyright{} 2002 g10 Code GmbH. + +Permission is granted to copy, distribute and/or modify this document +under the terms of the GNU Free Documentation License, Version 1.1 or +any later version published by the Free Software Foundation; with the +Invariant Sections being ``Free Software Needs Free Documentation'' and +``GNU Lesser General Public License'', the Front-Cover texts being (a) +(see below), and with the Back-Cover Texts being (b) (see below). A +copy of the license is included in the section entitled ``GNU Free +Documentation License''. +@end titlepage +@page + +@ifnottex +@node Top +@top Main Menu +This is Edition @value{EDITION}, last updated @value{UPDATED}, of +@cite{The `GnuPG Made Easy' Reference Manual}, for Version +@value{VERSION} of the @acronym{GPGME} library. +@end ifnottex + +@menu +* Introduction:: How to use this manual. +* Preparation:: What you should do before using the library. +* Protocols and Engines:: Supported crypto protocols. +* Error Handling:: Error numbers and their meanings. +* Exchanging Data:: Passing data to and from @acronym{GPGME}. +* Contexts:: Handling @acronym{GPGME} contexts. + +Appendices + +* Copying:: The GNU General Public License says how you + can copy and share `GnuPG Made Easy'. +* Free Documentation License:: This manual is under the GNU Free + Documentation License. + +Indices + +* Concept Index:: Index of concepts and programs. +* Function and Data Index:: Index of functions, variables and data types. + + +@detailmenu + --- The Detailed Node Listing --- + +Introduction + +* Getting Started:: Purpose of the manual, and how to use it. +* Features:: Reasons to install and use @acronym{GPGME}. +* Overview:: Basic architecture of the @acronym{GPGME} library. + +Preparation + +* Header:: What header file you need to include. +* Building the Source:: Compiler options to be used. +* Library Version Check:: Getting and verifying the library version. + +Protocols and Engines + +* Engine Version Check:: Verifying the engine version. +* Engine Information:: Obtaining more information about the engines. +* OpenPGP:: Support for the OpenPGP protocol. +* Cryptographic Message Syntax:: Support for the CMS. + +Error Handling + +* Error Values:: A list of all error values used. +* Error Strings:: How to get a descriptive string from a value. + +Exchanging Data + +* Creating Data Buffers:: Creating new data buffers. +* Destroying Data Buffers:: Releasing data buffers. +* Manipulating Data Buffers:: Operations on data buffers. + +Contexts + +* Creating Contexts:: Creating new @acronym{GPGME} contexts. +* Destroying Contexts:: Releasing @acronym{GPGME} contexts. +* Context Attributes:: Setting properties of a context. +* Key Management:: Managing keys with @acronym{GPGME}. +* Trust Item Management:: Managing trust items with @acronym{GPGME}. +* Crypto Operations:: Using a context for cryptography. +* Run Control:: Controlling how operations are run. + +Context Attributes + +* Protocol Selection:: Selecting the protocol used by a context. +* @acronym{ASCII} Armor:: Requesting @acronym{ASCII} armored output. +* Text Mode:: Choosing canonical text mode. +* Included Certificates:: Including a number of certificates. +* Key Listing Mode:: Selecting key listing mode. +* Passphrase Callback:: Getting the passphrase from the user. +* Progress Meter Callback:: Being informed about the progress. + +Key Management + +* Listing Keys:: Browsing the list of available keys. +* Information About Keys:: Requesting detailed information about keys. +* Manipulating Keys:: Operations on keys. +* Generating Keys:: Creating new key pairs. +* Exporting Keys:: Retrieving key data from the key ring. +* Importing Keys:: Adding keys to the key ring. +* Deleting Keys:: Removing keys from the key ring. + +Trust Item Management + +* Listing Trust Items:: Browsing the list of available trust items. +* Information About Trust Items:: Requesting detailed information about trust items. +* Manipulating Trust Items:: Operations on trust items. + +Crypto Operations + +* Decrypt:: Decrypting a ciphertext. +* Verify:: Verifying a signature. +* Decrypt and Verify:: Decrypting a signed ciphertext. +* Sign:: Creating a signature. +* Encrypt:: Encrypting a plaintext. +* Detailed Results:: How to obtain more info about the operation. + +Sign + +* Selecting Signers:: How to choose the keys to sign with. +* Creating a Signature:: How to create a signature. + +Encrypt + +* Selecting Recipients:: How to choose the recipients. +* Encrypting a Plaintext:: How to encrypt a plaintext. + +Run Control + +* Waiting For Completion:: Waiting until an operation is completed. +* Cancelling an Operation:: Interrupting a running operation. +* Hooking Up Into Idle Time:: Doing something when nothing has to be done. + +@end detailmenu +@end menu + +@node Introduction +@chapter Introduction + +`GnuPG Made Easy' (@acronym{GPGME}) is a C language library that +allows to add support for cryptography to a program. It is designed +to make access to crypto engines like GnuPG or GpgSM easier for +applications. @acronym{GPGME} provides a high-level crypto API for +encryption, decryption, signing, signature verification and key +management. + +@acronym{GPGME} uses GnuPG and GpgSM as its backends to support +OpenPGP and the Cryptographic Message Syntax (CMS). + +@menu +* Getting Started:: Purpose of the manual, and how to use it. +* Features:: Reasons to install and use @acronym{GPGME}. +* Overview:: Basic architecture of the @acronym{GPGME} library. +@end menu + + +@node Getting Started +@section Getting Started + +This library documents the @acronym{GPGME} library programming +interface. All functions and data types provided by the library are +explained. + +The reader is assumed to possess basic knowledge about cryptography in +general, and public key cryptography in particular. The underlying +cryptographic engines that are used by the library are not explained, +but where necessary, special features or requirements by an engine are +mentioned as far as they are relevant to @acronym{GPGME} or its users. + +This manual can be used in several ways. If read from the beginning +to the end, it gives a good introduction into the library and how it +can be used in an application. Forward references are included where +necessary. Later on, the manual can be used as a reference manual to +get just the information needed about any particular interface of the +library. Experienced programmers might want to start looking at the +examples at the end of the manual, and then only read up those parts +of the interface which are unclear. + + +@node Features +@section Features + +@acronym{GPGME} has a couple of advantages over other libraries doing +a similar job, and over implementing support for GnuPG or other crypto +engines into your application directly. + +@table @asis +@item it's free software +Anybody can use, modify, and redistribute it under the terms of the GNU +General Public License (@pxref{Copying}). + +@item it's flexible +@acronym{GPGME} provides transparent support for several cryptographic +protocols by different engines. Currently, @acronym{GPGME} supports +the OpenPGP protocol using GnuPG as the backend, and the Cryptographic +Message Syntax using GpgSM as the backend. + +@item it's easy +@acronym{GPGME} hides the differences between the protocols and +engines from the programmer behind an easy-to-use interface. This way +the programmer can focus on the other parts of the program, and still +integrate strong cryptography in his application. Once support for +@acronym{GPGME} has been added to a program, it is easy to add support +for other crypto protocols once @acronym{GPGME} backends provide them. +@end table + + +@node Overview +@section Overview + +@acronym{GPGME} provides a data abstraction that is used to pass data +to the crypto engine, and receive returned data from it. Data can be +read from memory or from files, but it can also be provided by a +callback function. + +The actual cryptographic operations are always set within a context. +A context provides configuration parameters that define the behaviour +of all operations performed within it. Only one operation per context +is allowed at any time, but when one operation is finished, you can +run the next operation in the same context. There can be more than +one context, and all can run different operations at the same time. + +Furthermore, @acronym{GPGME} has rich key management facilities +including listing keys, querying their attributes, generating, +importing, exporting and deleting keys, and acquiring information +about the trust path. + +@cindex thread-safeness +@cindex multi-threading +@strong{Caution:} The @acronym{GPGME} library is not thread-safe. It +will be to some extent in the future, but currently great care has to +be taken if @acronym{GPGME} is used in a multi-threaded environment. + + +@node Preparation +@chapter Preparation + +To use @acronym{GPGME}, you have to perform some changes to your +sources and the build system. The necessary changes are small and +explained in the following sections. At the end of this chapter, it +is described how the library is initialized, and how the requirements +of the library are verified. + +@menu +* Header:: What header file you need to include. +* Building the Source:: Compiler options to be used. +* Library Version Check:: Getting and verifying the library version. +@end menu + + +@node Header +@section Header +@cindex header file +@cindex include file + +All interfaces (data types and functions) of the library are defined +in the header file `gpgme.h'. You must include this in all programs +using the library, either directly or through some other header file, +like this: + +@example +#include +@end example + +The name space of @acronym{GPGME} is @code{gpgme_*} for function +names, @code{Gpgme*} for data types and @code{GPGME_*} for other +symbols. + + +@node Building the Source +@section Building the Source +@cindex compiler options +@cindex compiler flags + +If you want to compile a source file including the `gpgme.h' header +file, you must make sure that the compiler can find it in the +directory hierarchy. This is accomplished by adding the path to the +directory in which the header file is located to the compilers include +file search path (via the @option{-I} option). + +However, the path to the include file is determined at the time the +source is configured. To solve this problem, gpgme ships with a small +helper program @command{gpgme-config} that knows about the path to the +include file and other configuration options. The options that need +to be added to the compiler invocation at compile time are output by +the @option{--cflags} option to @command{gpgme-config}. The following +example shows how it can be used at the command line: + +@example +gcc -c foo.c `gpgme-config --cflags` +@end example + +Adding the output of @samp{gpgme-config --cflags} to the compilers +command line will ensure that the compiler can find the @acronym{GPGME} header +file. + +A similar problem occurs when linking the program with the library. +Again, the compiler has to find the library files. For this to work, +the path to the library files has to be added to the library search +path (via the @option{-L} option). For this, the option +@option{--libs} to @command{gpgme-config} can be used. For +convenience, this option also outputs all other options that are +required to link the program with @acronym{GPGME} (in particular, the +@samp{-lgpgme} option). The example shows how to link @file{foo.o} +with the @acronym{GPGME} library to a program @command{foo}. + +@example +gcc -o foo foo.o `gpgme-config --libs` +@end example + +Of course you can also combine both examples to a single command by +specifying both options to @command{gpgme-config}: + +@example +gcc -o foo foo.c `gpgme-config --cflags --libs` +@end example + + +@node Library Version Check +@section Library Version Check +@cindex version check, of the library + +@deftypefun {const char *} gpgme_check_version (@w{const char *@var{required_version}}) +The function @code{gpgme_check_version} has three purposes. It can be +used to retrieve the version number of the library. In addition it +can verify that the version number is higher than a certain required +version number. In either case, the function initializes some +sub-systems, and for this reason alone it must be invoked early in +your program, before you make use of the other functions in +@acronym{GPGME}. + +If @var{required_version} is @code{NULL}, the function returns a +pointer to a statically allocated string containing the version number +of the library. + +If @var{required_version} is not @code{NULL}, it should point to a +string containing a version number, and the function checks that the +version of the library is at least as high as the version number +provided. In this case, the function returns a pointer to a +statically allocated string containing the version number of the +library. If @var{REQUIRED_VERSION} is not a valid version number, or +if the version requirement is not met, the function returns +@code{NULL}. + +If you use a version of a library that is backwards compatible with +older releases, but contains additional interfaces which your program +uses, this function provides a run-time check if the necessary +features are provided by the installed version of the library. +@end deftypefun + + +@node Protocols and Engines +@chapter Protocols and Engines +@cindex protocol +@cindex engine +@cindex crypto engine +@cindex backend +@cindex crypto backend + +@acronym{GPGME} supports several cryptographic protocols, however, it +does not implement them. Rather it uses backends (also called +engines) which implement the protocol. @acronym{GPGME} uses +inter-process communication to pass data back and forth between the +application and the backend, but the details of the communication +protocol and invocation of the backends is completely hidden by the +interface. All complexity is handled by @acronym{GPGME}. Where an +exchange of information between the application and the backend is +necessary, @acronym{GPGME} provides the necessary callback function +hooks and further interfaces. + +@deftp {Data type} {enum GpgmeProtocol} +@tindex GpgmeProtocol +The @code{GpgmeProtocol} type specifies the set of possible protocol +values that are supported by @acronym{GPGME}. The following protocols +are supported: + +@table @code +@item GPGME_PROTOCOL_OpenPGP +This specifies the OpenPGP protocol. +@item GPGME_PROTOCOL_CMS +This specifies the Cryptographic Message Syntax. +@end table +@end deftp + +@menu +* Engine Version Check:: Verifying the engine version. +* Engine Information:: Obtaining more information about the engines. +* OpenPGP:: Support for the OpenPGP protocol. +* Cryptographic Message Syntax:: Support for the CMS. +@end menu + + +@node Engine Version Check +@section Engine Version Check +@cindex version check, of the engines + +@deftypefun GpgmeError gpgme_engine_check_version (@w{GpgmeProtocol @var{protocol}}) +The function @code{gpgme_engine_check_version} verifies that the +engine implementing the protocol @var{PROTOCOL} is installed in the +expected path and meets the version requirement of @acronym{GPGME}. + +This function returns @code{GPGME_No_Error} if the engine is available +and @code{GPGME_Invalid_Engine} if it is not. +@end deftypefun + +@deftypefun GpgmeError gpgme_check_engine (void) +The function @code{gpgme_check_engine} is equivalent to + +@example +gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP); +@end example + +This function is deprecated and provided for backwards compatibility +only. It is obsoleted by @code{gpgme_engine_check_version}. +@end deftypefun + + +@node Engine Information +@section Engine Information +@cindex engine, information about + +@deftypefun {const char *} gpgme_get_engine_info (void) +The function @code{gpgme_get_engine_info} returns an @acronym{XML} +string containing information about the available protocols and the +engine which implement them. The following information is returned +for each engine: + +@table @samp +@item +The name of the protocol. +@item +The version of the engine. +@item +The path to the engine binary. +@end table + +A string is always returned. If an error occurs, the string will +contain an @samp{} tag with a description of the failure. +@end deftypefun + +Here is the example output of what @code{gpgme_get_engine_info} might +return on your system: + +@example + + + OpenPGP + 1.0.6 + /usr/bin/gpg + + + CMS + 0.0.0 + /usr/bin/gpgsm + + +@end example + + +@node OpenPGP +@section OpenPGP +@cindex OpenPGP +@cindex GnuPG +@cindex protocol, GnuPG +@cindex engine, GnuPG + +OpenPGP is implemented by GnuPG, the @acronym{GNU} Privacy Guard. +This is the first protocol that was supported by @acronym{GPGME}. + +The OpenPGP protocol is specified by @code{GPGME_PROTOCOL_OpenPGP}. + + +@node Cryptographic Message Syntax +@section Cryptographic Message Syntax +@cindex CMS +@cindex cryptographic message syntax +@cindex GpgSM +@cindex protocol, CMS +@cindex engine, GpgSM +@cindex S/MIME +@cindex protocol, S/MIME + +@acronym{CMS} is implemented by GpgSM, the S/MIME implementation for +GnuPG. + +The @acronym{CMS} protocol is specified by @code{GPGME_PROTOCOL_CMS}. + + +@node Error Handling +@chapter Error Handling +@cindex error handling + +Many functions in @acronym{GPGME} can return an error if they fail. +For this reason, the application should always catch the error +condition and take appropriate measures, for example by releasing the +resources and passing the error up to the caller, or by displaying a +descriptive message to the user and cancelling the operation. + +Some error values do not indicate a system error or an error in the +operation, but the result of an operation that failed properly. For +example, if you try to decrypt a tempered message, the decryption will +fail. Another error value actually means that the end of a data +buffer or list has been reached. The following descriptions explain +what each error message means in general. Some error values have +specific meanings if returned by a specific function. Such cases are +described in the documentation of those functions. + +@menu +* Error Values:: A list of all error values used. +* Error Strings:: How to get a descriptive string from a value. +@end menu + + +@node Error Values +@section Error Values +@cindex error values, list of + +@deftp {Data type} {enum GpgmeError} +@tindex GpgmeError +The @code{GpgmeError} type specifies the set of all error values that +are used by @acronym{GPGME}. Possible values are: + +@table @code +@item GPGME_EOF +This value indicates the end of a list, buffer or file. + +@item GPGME_No_Error +This value indicates success. The value of this error is @code{0}. + +@item GPGME_General_Error +This value means that something went wrong, but either there is not +enough information about the problem to return a more useful error +value, or there is no separate error value for this type of problem. + +@item GPGME_Out_Of_Core +This value means that an out-of-memory condition occurred. + +@item GPGME_Invalid_Value +This value means that some user provided data was out of range. This +can also refer to objects. For example, if an empty @code{GpgmeData} +object was expected, but one containing data was provided, this error +value is returned. + +@item GPGME_Busy +This value is returned if you try to start a new operation in a +context that is already busy with some earlier operation which was not +cancelled or finished yet. + +@item GPGME_No_Request +This value is in some sense the opposite of @code{GPGME_Busy}. There +is no pending operation, but it is required for the function to +succeed. + +@item GPGME_Exec_Error +This value means that an error occurred when trying to spawn a child +process. + +@item GPGME_Too_Many_Procs +This value means that there are too many active backend processes. + +@item GPGME_Pipe_Error +This value means that the creation of a pipe failed. + +@item GPGME_No_Recipients +This value means that no valid recipients for a message have been set. + +@item GPGME_Invalid_Recipients +This value means that some, but not all, recipients for a message have +been invalid. + +@item GPGME_No_Data +This value means that a @code{GpgmeData} object which was expected to +have content was found empty. + +@item GPGME_Conflict +This value means that a conflict of some sort occurred. + +@item GPGME_Not_Implemented +This value indicates that the specific function (or operation) is not +implemented. This error should never happen. It can only occur if +you use certain values or configuration options which do not work, +but for which we think that they should work at some later time. + +@item GPGME_Read_Error +This value means that an I/O read operation failed. + +@item GPGME_Write_Error +This value means that an I/O write operation failed. + +@item GPGME_Invalid_Type +This value means that a user provided object was of a wrong or +incompatible type. Usually this refers to the type of a +@code{GpgmeData} object. + +@item GPGME_Invalid_Mode +This value means that a @code{GpgmeData} object has an incorrect mode +of operation (for example, doesn't support output although it is +attempted to use it as an output buffer). + +@item GPGME_File_Error +This value means that a file I/O operation failed. The value of +@code{errno} contains the system error value. + +@item GPGME_Decryption_Failed +This value indicates that a decryption operation was unsuccessful. + +@item GPGME_No_Passphrase +This value means that the user did not provide a passphrase when +requested. + +@item GPGME_Canceled +This value means that the operation was canceled. + +@item GPGME_Invalid_Key +This value means that a key was invalid. + +@item GPGME_Invalid_Engine +This value means that the engine that implements the desired protocol +is currently not available. This can either be because the sources +were configured to exclude support for this engine, or because the +engine is not installed properly. +@end table +@end deftp + + +@node Error Strings +@section Error Strings +@cindex error values, printing of +@cindex error strings + +@deftypefun {const char *} gpgme_strerror (@w{GpgmeError @var{err}}) +The function @code{gpgme_strerror} returns a pointer to a statically +allocated string containing a description of the error with the error +value @var{err}. This string can be used to output a diagnostic +message to the user. +@end deftypefun + + +@node Exchanging Data +@chapter Exchanging Data +@cindex data, exchanging + +A lot of data has to be exchanged between the user and the crypto +engine, like plaintext messages, ciphertext, signatures and +information about the keys. The technical details about exchanging +the data information are completely abstracted by @acronym{GPGME}. +The user provides and receives the data via @code{GpgmeData} objects, +regardless of the communication protocol between @acronym{GPGME} and +the crypto engine in use. + +@deftp {Data type} {GpgmeData} +The @code{GpgmeData} type is a handle for a container for generic +data, which is used by @acronym{GPGME} to exchange data with the user. +@end deftp + +@menu +* Creating Data Buffers:: Creating new data buffers. +* Destroying Data Buffers:: Releasing data buffers. +* Manipulating Data Buffers:: Operations on data buffers. +@end menu + + +@node Creating Data Buffers +@section Creating Data Buffers +@cindex data buffer, creation + +@deftypefun GpgmeError gpgme_data_new (@w{GpgmeData *@var{dh}}) +The function @code{gpgme_data_new} creates a new @code{GpgmeData} +object and returns a handle for it in @var{dh}. The data object is +initially empty. + +The function returns @code{GPGME_No_Error} if the data object was +successfully created, @code{GPGME_Invalid_Value} if @var{dh} is not a +valid pointer, and @code{GPGME_Out_Of_Core} if not enough memory is +available. +@end deftypefun + +@deftypefun GpgmeError gpgme_data_new_from_mem (@w{GpgmeData *@var{dh}}, @w{const char *@var{buffer}}, @w{size_t @var{size}}, @w{int @var{copy}}) +The function @code{gpgme_data_new_from_mem} creates a new +@code{GpgmeData} object and fills it with @var{size} bytes starting +from @var{buffer}. + +If @var{copy} is not zero, a private copy of the data is made. If +@var{copy} is zero, the data is taken from the specified buffer as +needed, and the user has to ensure that the buffer remains valid for +the whole life span of the data object. + +The function returns @code{GPGME_No_Error} if the data object was +successfully created, @code{GPGME_Invalid_Value} if @var{dh} or +@var{buffer} is not a valid pointer, and @code{GPGME_Out_Of_Core} if +not enough memory is available. +@end deftypefun + +@deftypefun GpgmeError gpgme_data_new_from_file (@w{GpgmeData *@var{dh}}, @w{const char *@var{filename}}, @w{int @var{copy}}) +The function @code{gpgme_data_new_from_file} creates a new +@code{GpgmeData} object and fills it with the content of the file +@var{filename}. + +If @var{copy} is not zero, the whole file is read in at initialization +time and the file is not used anymore after that. This is the only +mode supported currently. Later, a value of zero for @var{copy} might +cause all reads to be delayed until the data is needed, but this is +not yet implemented. + +The function returns @code{GPGME_No_Error} if the data object was +successfully created, @code{GPGME_Invalid_Value} if @var{dh} or +@var{filename} is not a valid pointer, @code{GPGME_File_Error} if an +I/O operation fails, @code{GPGME_Not_Implemented} if @var{code} is +zero, and @code{GPGME_Out_Of_Core} if not enough memory is available. +@end deftypefun + +@deftypefun GpgmeError gpgme_data_new_from_filepart (@w{GpgmeData *@var{dh}}, @w{const char *@var{filename}}, @w{FILE *@var{fp}}, @w{off_t @var{offset}}, @w{size_t @var{length}}) +The function @code{gpgme_data_new_from_filepart} creates a new +@code{GpgmeData} object and fills it with a part of the file specified +by @var{filename} or @var{fp}. + +Exactly one of @var{filename} and @var{fp} must be non-zero, the other +must be zero. The argument that is not zero specifies the file from +which @var{length} bytes are read into the data object, starting from +@var{offset}. + +The function returns @code{GPGME_No_Error} if the data object was +successfully created, @code{GPGME_Invalid_Value} if @var{dh} and +exactly one of @var{filename} and @var{fp} is not a valid pointer, +@code{GPGME_File_Error} if an I/O operation fails, and +@code{GPGME_Out_Of_Core} if not enough memory is available. +@end deftypefun + + +@deftypefun GpgmeError gpgme_data_new_with_read_cb (@w{GpgmeData *@var{dh}}, @w{int (*@var{readfunc})} (@w{void *@var{hook}}, @w{char *@var{buffer}}, @w{size_t @var{count}}, @w{size_t *@var{nread}}), @w{void *@var{hook_value}}) +The function @code{gpgme_data_new_with_read_cb} creates a new +@code{GpgmeData} object and uses the callback function @var{readfunc} +to retrieve the data on demand. As the callback function can supply +the data in any way it wants, this is the most flexible data type +@acronym{GPGME} provides. However, it can not be used to write data. + +The callback function receives @var{hook_value} as its first argument +whenever it is invoked. It should return up to @var{count} bytes in +@var{buffer}, and return the number of bytes actually read in +@var{nread}. It may return @code{0} in @var{nread} if no data is +currently available. To indicate @code{EOF} the function should +return with an error code of @code{-1} and set @var{nread} to +@code{0}. The callback function may support to reset its internal +read pointer if it is invoked with @var{buffer} and @var{nread} being +@code{NULL} and @var{count} being @code{0}. + +The function returns @code{GPGME_No_Error} if the data object was +successfully created, @code{GPGME_Invalid_Value} if @var{dh} or +@var{readfunc} is not a valid pointer, and @code{GPGME_Out_Of_Core} if +not enough memory is available. +@end deftypefun + + +@node Destroying Data Buffers +@section Destroying Data Buffers +@cindex data buffer, destruction + +@deftypefun void gpgme_data_release (@w{GpgmeData @var{dh}}) +The function @code{gpgme_data_release} destroys the data object with +the handle @var{dh}. It releases all associated resources that were +not provided by the user in the first place. +@end deftypefun + +@deftypefun {char *} gpgme_data_release_and_get_mem (@w{GpgmeData @var{dh}}, @w{size_t *@var{length}}) +The function @code{gpgme_data_release_and_get_mem} is like +@code{gpgme_data_release}, except that it returns the data buffer and +its length that was provided by the object. + +The user has to release the buffer with @code{free}. In case the user +provided the data buffer in non-copy mode, a copy will be made for +this purpose. + +In case an error returns, or there is no suitable data buffer that can +be returned to the user, the function will return @code{NULL}. +@end deftypefun + + +@node Manipulating Data Buffers +@section Manipulating Data Buffers +@cindex data buffere, manipulation + +@deftypefun GpgmeError gpgme_data_read (@w{GpgmeData @var{dh}}, @w{char *@var{buffer}}, @w{size_t @var{length}}, @w{size_t *@var{nread}}) +The function @code{gpgme_data_read} reads up to @var{length} bytes +from the data object with the handle @var{dh} into the space starting +at @var{buffer}. The actual amount read is returned in @var{nread}. + +If @var{buffer} is @code{NULL}, the function returns the amount of +bytes available in @var{nread} without changing the read pointer. +This is not supported by all types of data objects. If this function +is not supported, @code{GPGME_Invalid_Type} is returned. + +If the end of the data object is reached, the function returns +@code{GPGME_EOF} and sets @var{nread} to zero. + +In all other cases, the function returns @code{GPGME_No_Error} if the +operation was successfully performed and @code{GPGME_Invalid_Value} if +@var{dh} is not a valid pointer. +@end deftypefun + +@deftypefun GpgmeError gpgme_data_rewind (@w{GpgmeData @var{dh}}) +The function @code{gpgme_data_rewind} resets the read pointer of the +data object with the handle @var{dh}, so that a subsequent +@code{gpgme_data_read} operation starts at the beginning of the data. + +The function returns @code{GPGME_No_Error} if the operation was +successfully performed, @code{GPGME_Not_Implemented} if the operation +is not supported (for example, by a read callback function supplied by +the user) and @code{GPGME_Invalid_Value} if @var{dh} is not a valid +pointer. +@end deftypefun + +@deftypefun GpgmeError gpgme_data_write (@w{GpgmeData @var{dh}}, @w{const char *@var{buffer}}, @w{size_t @var{length}}) +The function @code{gpgme_data_write} writes @var{length} bytes +starting from @var{buffer} into the data object with the handle +@var{dh} at the current write position. + +The function returns @code{GPGME_No_Error} if the operation was +successfully performed, @code{GPGME_Invalid_Value} if @var{dh} or +@var{buffer} is not a valid pointer, @code{GPGME_Invalid_Type} or +@code{GPGME_Invalid_Mode} if the data object type does not support +writing, and @code{GPGME_Out_Of_Core} if not enough memory is +available. +@end deftypefun + +@deftp {Data type} {enum GpgmeDataType} +@tindex GpgmeDataType +The @code{GpgmeDataType} type specifies the type of a @code{GpgmeData} object. +The following data types are available: + +@table @code +@item GPGME_DATA_TYPE_NONE +This specifies that the type is not yet determined. + +@item GPGME_DATA_TYPE_MEM +This specifies that the data is stored in memory. + +@item GPGME_DATA_TYPE_FD +This type is not implemented. + +@item GPGME_DATA_TYPE_FILE +This type is not implemented. + +@item GPGME_DATA_TYPE_CB +This type specifies that the data is provided by a callback function +implemented by the user. +@end table +@end deftp + +@deftypefun GpgmeDataType gpgme_data_get_type (@w{GpgmeData @var{dh}}) +The function @code{gpgme_data_get_type} returns the type of the data +object with the handle @var{dh}. If @var{dh} is not a valid pointer, +@code{GPGME_DATA_TYPE_NONE} is returned. +@end deftypefun + + +@node Contexts +@chapter Contexts +@cindex context + +All cryptographic operations in @acronym{GPGME} are performed within a +context, which contains the internal state of the operation as well as +configuration parameters. By using several contexts you can run +several cryptographic operations in parallel, with different +configuration. + +@deftp {Data type} {GpgmeCtx} +The @code{GpgmeCtx} type is a handle for a @acronym{GPGME} context, +which is used to hold the configuration, status and result of +cryptographic operations. +@end deftp + +@menu +* Creating Contexts:: Creating new @acronym{GPGME} contexts. +* Destroying Contexts:: Releasing @acronym{GPGME} contexts. +* Context Attributes:: Setting properties of a context. +* Key Management:: Managing keys with @acronym{GPGME}. +* Trust Item Management:: Managing trust items with @acronym{GPGME}. +* Crypto Operations:: Using a context for cryptography. +* Run Control:: Controlling how operations are run. +@end menu + + +@node Creating Contexts +@section Creating Contexts +@cindex context, creation + +@deftypefun GpgmeError gpgme_new (@w{GpgmeCtx *@var{ctx}}) +The function @code{gpgme_data_new} creates a new @code{GpgmeCtx} +object and returns a handle for it in @var{ctx}. + +The function returns @code{GPGME_No_Error} if the context was +successfully created, @code{GPGME_Invalid_Value} if @var{ctx} is not a +valid pointer, and @code{GPGME_Out_Of_Core} if not enough memory is +available. +@end deftypefun + + +@node Destroying Contexts +@section Destroying Contexts +@cindex context, destruction + +@deftypefun void gpgme_release (@w{GpgmeCtx @var{ctx}}) +The function @code{gpgme_release} destroys the context with the handle +@var{ctx} and releases all associated resources. +@end deftypefun + + +@node Context Attributes +@section Context Attributes +@cindex context, attributes + +@menu +* Protocol Selection:: Selecting the protocol used by a context. +* @acronym{ASCII} Armor:: Requesting @acronym{ASCII} armored output. +* Text Mode:: Choosing canonical text mode. +* Included Certificates:: Including a number of certificates. +* Key Listing Mode:: Selecting key listing mode. +* Passphrase Callback:: Getting the passphrase from the user. +* Progress Meter Callback:: Being informed about the progress. +@end menu + + +@node Protocol Selection +@subsection Protocol Selection +@cindex context, selecting protocol +@cindex protocol, selecting + +@deftypefun GpgmeError gpgme_set_protocol (@w{GpgmeCtx @var{ctx}}, @w{GpgmeProtocol @var{proto}}) +The function @code{gpgme_set_protocol} sets the protocol used within +the context @var{ctx} to @var{proto}. All crypto operations will be +performed by the crypto engine configured for that protocol. +@xref{Protocols and Engines}. + +Setting the protocol with @code{gpgme_set_protocol} does not check if +the crypto engine for that protocol is available and installed +correctly. @xref{Engine Version Check}. + +The function returns @code{GPGME_No_Error} if the protocol could be +set successfully, and @code{GPGME_Invalid_Value} if @var{protocol} is +not a valid protocol. +@end deftypefun + + +@node @acronym{ASCII} Armor +@subsection @acronym{ASCII} Armor +@cindex context, armor mode +@cindex @acronym{ASCII} armor +@cindex armor mode + +@deftypefun void gpgme_set_armor (@w{GpgmeCtx @var{ctx}}, @w{int @var{yes}}) +The function @code{gpgme_set_armor} specifies if the output should be +@acronym{ASCII} armored. By default, output is not @acronym{ASCII} +armored. + +@acronym{ASCII} armored output is disabled if @var{yes} is zero, and +enabled otherwise. +@end deftypefun + +@deftypefun int gpgme_get_armor (@w{GpgmeCtx @var{ctx}}) +The function @code{gpgme_get_armor} returns 1 if the output is +@acronym{ASCII} armored, and @code{0} if it is not, or if @var{ctx} is +not a valid pointer. +@end deftypefun + + +@node Text Mode +@subsection Text Mode +@cindex context, text mode +@cindex text mode +@cindex canonical text mode + +@deftypefun void gpgme_set_textmode (@w{GpgmeCtx @var{ctx}}, @w{int @var{yes}}) +The function @code{gpgme_set_textmode} specifies if canonical text mode +should be used. By default, text mode is not used. + +Text mode is for example used for the RFC2015 signatures; note that +the updated RFC 3156 mandates that the mail user agent does some +preparations so that text mode is not needed anymore. + +This option is only relevant to the OpenPGP crypto engine, and ignored +by all other engines. + +Canonical text mode is disabled if @var{yes} is zero, and enabled +otherwise. +@end deftypefun + +@deftypefun int gpgme_get_textmode (@w{GpgmeCtx @var{ctx}}) +The function @code{gpgme_get_textmode} returns 1 if canonical text +mode is enabled, and @code{0} if it is not, or if @var{ctx} is not a +valid pointer. +@end deftypefun + + +@node Included Certificates +@subsection Included Certificates +@cindex certificates, included + +@deftypefun void gpgme_set_include_certs (@w{GpgmeCtx @var{ctx}}, @w{int @var{nr_of_certs}}) +The function @code{gpgme_set_include_certs} specifies how many +certificates should be included in an S/MIME signed message. By +default, only the sender's certificate is included. The possible +values of @var{nr_of_certs} are: + +@table @code +@item -2 +Include all certificates except the root certificate. +@item -1 +Include all certificates. +@item 0 +Include no certificates. +@item 1 +Include the sender's certificate only. +@item n +Include the first n certificates of the certificates path, starting +from the sender's certificate. The number @code{n} must be positive. +@end table + +Values of @var{nr_of_certs} smaller than -2 are undefined. + +This option is only relevant to the CMS crypto engine, and ignored +by all other engines. +@end deftypefun + +@deftypefun int gpgme_get_include_certs (@w{GpgmeCtx @var{ctx}}) +The function @code{gpgme_get_include_certs} returns the number of +certificates to include into an S/MIME signed message. +@end deftypefun + + +@node Key Listing Mode +@subsection Key Listing Mode +@cindex key listing mode +@cindex key listing, mode of + +@deftypefun void gpgme_set_keylist_mode (@w{GpgmeCtx @var{ctx}}, @w{int @var{mode}}) +The function @code{gpgme_set_keylist_mode} changes the default +behaviour of the key listing functions. The value in @var{mode} is a +bitwise-or combination of one or multiple of the following bit values: + +@table @code +@item GPGME_KEYLIST_MODE_LOCAL +The @code{GPGME_KEYLIST_MODE_LOCAL} symbol specifies that the local +keyring should be searched for keys in the keylisting operation. This +is the default. + +@item GPGME_KEYLIST_MODE_EXTERN +The @code{GPGME_KEYLIST_MODE_EXTERN} symbol specifies that an external +source should be should be searched for keys in the keylisting +operation. The type of external source is dependant on the crypto +engine used. For example, it can be a remote keyserver or LDAP +certificate server. +@end table + +At least one of @code{GPGME_KEYLIST_MODE_LOCAL} and +@code{GPGME_KEYLIST_MODE_EXTERN} must be specified. For future binary +compatibility, you should get the current mode with +@code{gpgme_get_keylist_mode} and modify it by setting or clearing the +appropriate bits, and then using that calulcated value in the +@code{gpgme_set_keylisting_mode} operation. This will leave all other +bits in the mode value intact (in particular those that are not used +in the current version of the library). + +The function returns @code{GPGME_No_Error} if the mode could be set +correctly, and @code{GPGME_Invalid_Value} if @var{ctx} is not a valid +pointer or @var{mode} is not a valid mode. +@end deftypefun + + +@deftypefun int gpgme_get_keylist_mode (@w{GpgmeCtx @var{ctx}}) +The function @code{gpgme_get_keylist_mode} returns the current key +listing mode of the context @var{ctx}. This value can then be +modified and used in a subsequent @code{gpgme_set_keylist_mode} +operation to only affect the desired bits (and leave all others +intact). + +The function returns 0 if @var{ctx} is not a valid pointer, and the +current mode otherwise. Note that 0 is not a valid mode value. +@end deftypefun + + +@node Passphrase Callback +@subsection Passphrase Callback +@cindex callback, passphrase +@cindex passphrase callback + +@deftp {Data type} {const char *(*GpgmePassphraseCb)(void *@var{hook}, const char *@var{desc}, void **@var{r_hd})} +@tindex GpgmePassphraseCb +The @code{GpgmePassphraseCb} type is the type of functions usable as +passphrase callback function. + +The string @var{desc} contains a test usable to be displayed to the +user of the application. The function should return a passphrase for +the context when invoked with @var{desc} not being @code{NULL}. + +The user may store information about the resources associated with the +returned passphrase in @var{*r_hd}. When the passphrase is no longer +needed by @acronym{GPGME}, the passphrase callback function will be +called with @var{desc} being @var{NULL}, and @var{r_hd} being the same +as at the first invocation. +@end deftp + +@deftypefun void gpgme_set_passphrase_cb (@w{GpgmeCtx @var{ctx}}, @w{GpgmePassphraseCb @var{passfunc}}, @w{void *@var{hook_value}}) +The function @code{gpgme_set_passphrase_cb} sets the function that is +used when a passphrase needs to be provided by the user to +@var{passfunc}. The function @var{passfunc} needs to implemented by +the user, and whenever it is called, it is called with its first +argument being @var{hook_value}. By default, no passphrase callback +function is set. + +Not all crypto engines require this callback to retrieve the +passphrase. It is better if the engine retrieves the passphrase from +a trusted agent (a daemon process), rather than having each user to +implement their own passphrase query. + +The user can disable the use of a passphrase callback function by +calling @code{gpgme_set_passphrase_cb} with @var{passfunc} being +@code{NULL}. +@end deftypefun + + +@node Progress Meter Callback +@subsection Progress Meter Callback +@cindex callback, progress meter +@cindex progress meter callback + +@deftp {Data type} {const char *(*GpgmeProgressCb)(void *@var{hook}, const char *@var{what}, int @var{type}, int @var{current}, int @var{total})} +@tindex GpgmeProgressCb +The @code{GpgmeProgressCb} type is the type of functions usable as +progress callback function. + +The arguments are specific to the crypto engine. More information +about the progress information returned from the GnuPG engine can be +found in the GnuPG source code in the file @file{doc/DETAILS} in the +section PROGRESS. +@end deftp + +@deftypefun void gpgme_set_progress_cb (@w{GpgmeCtx @var{ctx}}, @w{GpgmeProgressCb @var{progfunc}}, @w{void *@var{hook_value}}) +The function @code{gpgme_set_progress_cb} sets the function that is +used when progress information about a cryptographic operation is +available. The function @var{progfunc} needs to implemented by the +user, and whenever it is called, it is called with its first argument +being @var{hook_value}. By default, no progress callback function +is set. + +Setting a callback function allows an interactive program to display +progress information about a long operation to the user. + +The user can disable the use of a progress callback function by +calling @code{gpgme_set_progress_cb} with @var{progfunc} being +@code{NULL}. +@end deftypefun + + +@node Key Management +@section Key Management +@cindex key management + +Some of the cryptographic operations require that recipients or +signers are specified. This is always done by specifying the +respective keys that should be used for the operation. The following +section describes how such keys can be selected and manipulated. + +@deftp {Data type} GpgmeKey +The @code{GpgmeKey} type is a handle for a public or secret key, and +is used to select the key for operations involving it. + +A key can contain several user IDs and sub keys. +@end deftp + +@menu +* Listing Keys:: Browsing the list of available keys. +* Information About Keys:: Requesting detailed information about keys. +* Manipulating Keys:: Operations on keys. +* Generating Keys:: Creating new key pairs. +* Exporting Keys:: Retrieving key data from the key ring. +* Importing Keys:: Adding keys to the key ring. +* Deleting Keys:: Removing keys from the key ring. +@end menu + + +@node Listing Keys +@subsection Listing Keys +@cindex listing keys +@cindex key listing +@cindex key listing, start +@cindex key ring, list +@cindex key ring, search + +@deftypefun GpgmeError gpgme_op_keylist_start (@w{GpgmeCtx @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{secret_only}}) +The function @code{gpgme_op_keylist_start} initiates a key listing +operation inside the context @var{ctx}. It sets everything up so that +subsequent invocations of @code{gpgme_op_keylist_next} return the keys +in the list. + +If @var{pattern} is @code{NULL}, all available keys are returned. +Otherwise, @var{pattern} contains an engine specific expression that +is used to limit the list to all keys matching the pattern. + +If @var{secret_only} is not @code{0}, the list is restricted to secret +keys only. + +The context will be busy until either all keys are received (and +@code{gpgme_op_keylist_next} returns @code{GPGME_EOF}), or +@code{gpgme_op_keylist_end} is called to finish the operation. + +The function returns @code{GPGME_Invalid_Value} if @var{ctx} is not a +valid pointer, and passes through any errors that are reported by the +crypto engine support routines. +@end deftypefun + +@deftypefun GpgmeError gpgme_op_keylist_ext_start (@w{GpgmeCtx @var{ctx}}, @w{const char *@var{pattern}[]}, @w{int @var{secret_only}}, @w{int @var{reserved}}) +The function @code{gpgme_op_keylist_ext_start} initiates an extended +key listing operation inside the context @var{ctx}. It sets +everything up so that subsequent invocations of +@code{gpgme_op_keylist_next} return the keys in the list. + +If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys +are returned. Otherwise, @var{pattern} is a @code{NULL} terminated +array of strings that are used to limit the list to all keys matching +at least one of the patterns verbatim. + +If @var{secret_only} is not @code{0}, the list is restricted to secret +keys only. + +The value of @var{reserved} must be @code{0}. + +The context will be busy until either all keys are received (and +@code{gpgme_op_keylist_next} returns @code{GPGME_EOF}), or +@code{gpgme_op_keylist_end} is called to finish the operation. + +The function returns @code{GPGME_Invalid_Value} if @var{ctx} is not a +valid pointer, and passes through any errors that are reported by the +crypto engine support routines. +@end deftypefun + +@deftypefun GpgmeError gpgme_op_keylist_next (@w{GpgmeCtx @var{ctx}}, @w{GpgmeKey *@var{r_key}}) +The function @code{gpgme_op_keylist_next} returns the next key in the +list created by a previous @code{gpgme_op_keylist_start} operation in +the context @var{ctx}. The key will have one reference for the user. +@xref{Manipulating Keys}. + +This is the only way to get at @code{GpgmeKey} objects in +@acronym{GPGME}. + +If the last key in the list has already been returned, +@code{gpgme_op_keylist_next} returns @code{GPGME_EOF}. + +The function returns @code{GPGME_Invalid_Value} if @var{ctx} or +@var{r_key} is not a valid pointer, @code{GPGME_No_Request} if there +is no pending operation, @code{GPGME_Out_Of_Core} if there is not +enough memory for the operation. +@end deftypefun + +@deftypefun GpgmeError gpgme_op_keylist_end (@w{GpgmeCtx @var{ctx}}) +The function @code{gpgme_op_keylist_next} ends a pending key list +operation in the context @var{ctx}. + +The function returns @code{GPGME_Invalid_Value} if @var{ctx} is not a +valid pointer, @code{GPGME_No_Request} if there is no pending +operation, @code{GPGME_Out_Of_Core} if at some time during the +operation there was not enough memory available. +@end deftypefun + + +@node Information About Keys +@subsection Information About Keys +@cindex key, information about +@cindex key, attributes +@cindex attributes, of a key + +@deftypefun {char *} gpgme_key_get_as_xml (@w{GpgmeKey @var{key}}) +The function @code{gpgme_key_get_as_xml} returns a string in +@acronym{XML} format describing the key @var{key}. The user has to +release the string with @code{free}. + +The function returns @code{NULL} if @var{key} is not a valid pointer, +or there is not enough memory available. +@end deftypefun + +@deftp {Data type} GpgmeAttr +The @code{GpgmeAttr} type is used to specify a key or trust item +attribute. The following attributes are defined: + +@table @code +@item GPGME_ATTR_KEYID +This is the key ID of a sub key. It is representable as a string. + +For trust items, the trust item refers to the key with this ID. + +@item GPGME_ATTR_FPR +This is the fingerprint of a sub key. It is representable as a +string. + +@item GPGME_ATTR_ALGO +This is the crypto algorithm for which the sub key can be used. It +is representable as a string and as a number. The numbers correspond +to the @code{enum gcry_pk_algos} values in the gcrypt library. + +@item GPGME_ATTR_LEN +This is the key length of a sub key. It is representable as a +number. + +@item GPGME_ATTR_CREATED +This is the timestamp at creation time of a sub key. It is +representable as a number. + +@item GPGME_ATTR_EXPIRE +This is the expiration time of a sub key. It is representable as a +number. + +@item GPGME_ATTR_OTRUST +XXX FIXME (also for trust items) + +@item GPGME_ATTR_USERID +This is a user ID. There can be more than one user IDs in a +@var{GpgmeKey} object. The first one (with index 0) is the primary +user ID. The user ID is representable as a number. + +For trust items, this is the user ID associated with this trust item. + +@item GPGME_ATTR_NAME +This is the name belonging to a user ID. It is representable as a string. + +@item GPGME_ATTR_EMAIL +This is the email address belonging to a user ID. It is representable +as a string. + +@item GPGME_ATTR_COMMENT +This is the comment belonging to a user ID. It is representable as a +string. + +@item GPGME_ATTR_VALIDITY +This is the validity belonging to a user ID. It is representable as a +string and as a number. See below for a list of available validities. + +For trust items, this is the validity that is associated with this +trust item. + +@item GPGME_ATTR_UID_REVOKED +This specifies if a user ID is revoked. It is representable as a +number, and is @code{1} if the user ID is revoked, and @code{0} +otherwise. + +@item GPGME_ATTR_UID_INVALID +This specifies if a user ID is invalid. It is representable as a +number, and is @code{1} if the user ID is invalid, and @code{0} +otherwise. + +@item GPGME_ATTR_LEVEL +This is the trust level of a trust item. + +@item GPGME_ATTR_TYPE +This is the type of a trust item. + +@item GPGME_ATTR_IS_SECRET +This specifies if the key is a secret key. It is representable as a +string or a number. If the key is a secret key, the representation is +``1'' or @code{1}, otherwise it is @code{NULL} or @code{0}. + +@item GPGME_ATTR_KEY_REVOKED +This specifies if a sub key is revoked. It is representable as a +number, and is @code{1} if the key is revoked, and @code{0} otherwise. + +@item GPGME_ATTR_KEY_INVALID +This specifies if a sub key is invalid. It is representable as a +number, and is @code{1} if the key is invalid, and @code{0} otherwise. + +@item GPGME_ATTR_KEY_EXPIRED +This specifies if a sub key is expired. It is representable as a +number, and is @code{1} if the key is expired, and @code{0} otherwise. + +@item GPGME_ATTR_KEY_DISABLED +This specifies if a sub key is disabled. It is representable as a +number, and is @code{1} if the key is disabled, and @code{0} otherwise. + +@item GPGME_ATTR_KEY_CAPS +This is a description of the capabilities of a sub key. It is +representable as a string. The string contains the letter ``e'' if +the key can be used for encryption, ``s'' if the key can be used for +signatures, and ``c'' if the key can be used for certifications. + +@item GPGME_ATTR_CAN_ENCRYPT +This specifies if a sub key can be used for encryption. It is +representable as a number, and is @code{1} if the sub key can be used +for encryption, and @code{0} otherwise. + +@item GPGME_ATTR_CAN_SIGN +This specifies if a sub key can be used for signatures. It is +representable as a number, and is @code{1} if the sub key can be used +for signatures, and @code{0} otherwise. + +@item GPGME_ATTR_CAN_CERTIFY +This specifies if a sub key can be used for certifications. It is +representable as a number, and is @code{1} if the sub key can be used +for certifications, and @code{0} otherwise. +@end table +@end deftp + +@deftp {Data type} GpgmeValidity +The @code{GpgmeValidity} type is used to specify the validity of a user ID +in a key. The following validities are defined: + +@table @code +@item GPGME_VALIDITY_UNKNOWN +The user ID is of unknown validity. The string representation of this +validity is ``?''. + +@item GPGME_VALIDITY_UNDEFINED +The validity of the user ID is undefined. The string representation of this +validity is ``q''. + +@item GPGME_VALIDITY_NEVER +The user ID is never valid. The string representation of this +validity is ``n''. + +@item GPGME_VALIDITY_MARGINAL +The user ID is marginally valid. The string representation of this +validity is ``m''. + +@item GPGME_VALIDITY_FULL +The user ID is fully valid. The string representation of this +validity is ``f''. + +@item GPGME_VALIDITY_ULTIMATE +The user ID is ultimately valid. The string representation of this +validity is ``u''. +@end table +@end deftp + +@deftypefun {const char *} gpgme_key_get_string_attr (@w{GpgmeKey @var{key}}, @w{GpgmeAttr @var{what}}, @w{const void *@var{reserved}}, @w{int @var{idx}}) +The function @code{gpgme_key_get_string_attr} returns the value of the +string-representable attribute @var{what} of key @var{key}. If the +attribute occurs more than once in the key, the index is specified by +@var{idx}. This applies to attributes of sub keys and user IDs. The +argument @var{reserved} is reserved for later use and should be +@code{NULL}. + +The string returned is only valid as long as the key is valid. + +The function returns @code{0} if an attribute can't be returned as a +string, @var{key} is not a valid pointer, @var{idx} out of range, +or @var{reserved} not @code{NULL}. +@end deftypefun + +@deftypefun {unsigned long} gpgme_key_get_ulong_attr (@w{GpgmeKey @var{key}}, @w{GpgmeAttr @var{what}}, @w{const void *@var{reserved}}, @w{int @var{idx}}) +The function @code{gpgme_key_get_ulong_attr} returns the value of the +number-representable attribute @var{what} of key @var{key}. If the +attribute occurs more than once in the key, the index is specified by +@var{idx}. This applies to attributes of sub keys and user IDs. The +argument @var{reserved} is reserved for later use and should be +@code{NULL}. + +The function returns @code{0} if the attribute can't be returned as a +number, @var{key} is not a valid pointer, @var{idx} out of range, +or @var{reserved} not @code{NULL}. +@end deftypefun + + +@node Manipulating Keys +@subsection Manipulating Keys +@cindex key, manipulation + +@deftypefun void gpgme_key_ref (@w{GpgmeKey @var{key}}) +The function @code{gpgme_key_ref} acquires an additional reference for +the key @var{key}. +@end deftypefun + +@deftypefun void gpgme_key_unref (@w{GpgmeKey @var{key}}) +@deftypefunx void gpgme_key_release (@w{GpgmeKey @var{key}}) +The function @code{gpgme_key_ref} releases a reference for the key +@var{key}. If this was the last reference, the key will be destroyed +and all resources associated to it will be released. + +The function @code{gpgme_key_release} is an alias for +@code{gpgme_key_unref}. +@end deftypefun + + +@node Generating Keys +@subsection Generating Keys +@cindex key, creation +@cindex key ring, add + +@deftypefun GpgmeError gpgme_op_genkey (@w{GpgmeCtx @var{ctx}}, @w{const char *@var{parms}}, @w{GpgmeData @var{pubkey}}, @w{GpgmeData @var{seckey}}) +The function @code{gpgme_op_genkey} generates a new key pair in the +context @var{ctx} and puts it into the standard key ring if both +@var{pubkey} and @var{seckey} are @code{NULL}. In this case the +function returns immediately after starting the operation, and does +not wait for it to complete. If @var{pubkey} is not @code{NULL} it +should be the handle for an empty (newly created) data object, and +upon successful completion the data object will contain the public +key. If @var{seckey} is not @code{NULL} it should be the handle for +an empty (newly created) data object, and upon successful completion +the data object will contain the secret key. + +Note that not all crypto engines support this interface equally. +GnuPG does not support @var{pubkey} and @var{subkey}, they should be +both @code{NULL}, and the key pair will be added to the standard key +ring. GpgSM does only support @var{pubkey}, the secret key will be +stored by @command{gpg-agent}. GpgSM expects @var{pubkey} being not +@code{NULL}. + +The argument @var{parms} specifies parameters for the key in an XML +string. The details about the format of @var{parms} are specific to +the crypto engine used by @var{ctx}. Here is an example for GnuPG as +the crypto engine: + +@example + +Key-Type: DSA +Key-Length: 1024 +Subkey-Type: ELG-E +Subkey-Length: 1024 +Name-Real: Joe Tester +Name-Comment: with stupid passphrase +Name-Email: joe@@foo.bar +Expire-Date: 0 +Passphrase: abc + +@end example + +Here is an example for GpgSM as the crypto engine: +@example + +Key-Type: RSA +Key-Length: 1024 +Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester +Name-Email: joe@@foo.bar + +@end example + +Strings should be given in UTF-8 encoding. The only format supported +for now is ``internal''. The content of the @code{GnupgKeyParms} +container is passed verbatim to GnuPG. Control statements are not +allowed. + +The function returns @code{GPGME_No_Error} if the operation could be +started successfully, @code{GPGME_Invalid_Value} if @var{parms} is not +a valid XML string, @code{GPGME_Not_Supported} if @var{pubkey} or +@var{seckey} is not valid, and @code{GPGME_General_Error} if no key +was created by the backend. +@end deftypefun + +@deftypefun GpgmeError gpgme_op_genkey_start (@w{GpgmeCtx @var{ctx}}, @w{const char *@var{parms}}, @w{GpgmeData @var{pubkey}}, @w{GpgmeData @var{seckey}}) +The function @code{gpgme_op_genkey_start} initiates a +@code{gpgme_op_genkey} operation. It can be completed by calling +@code{gpgme_wait} on the context. @xref{Waiting For Completion}. + +The function returns @code{GPGME_No_Error} if the operation could be +started successfully, @code{GPGME_Invalid_Value} if @var{parms} is not +a valid XML string, and @code{GPGME_Not_Supported} if @var{pubkey} or +@var{seckey} is not @code{NULL}. +@end deftypefun + + +@node Exporting Keys +@subsection Exporting Keys +@cindex key, export +@cindex key ring, export from + +@deftypefun GpgmeError gpgme_op_export (@w{GpgmeCtx @var{ctx}}, @w{GpgmeRecipients @var{recipients}}, @w{GpgmeData @var{keydata}}) +The function @code{gpgme_op_export} extracts the public keys of the +user IDs in @var{recipients} and returns them in the data buffer +@var{keydata}. The type of the public keys returned is determined by +the @acronym{ASCII} armor attribute set for the context @var{ctx}. + +The function returns @code{GPGME_No_Error} if the operation completed +successfully, @code{GPGME_Invalid_Value} if @var{recipients} is +@code{NULL} or @var{keydata} is not a valid empty data buffer, and +passes through any errors that are reported by the crypto engine +support routines. +@end deftypefun + +@deftypefun GpgmeError gpgme_op_export_start (@w{GpgmeCtx @var{ctx}}, @w{GpgmeRecipients @var{recipients}}, @w{GpgmeData @var{keydata}}) +The function @code{gpgme_op_export_start} initiates a +@code{gpgme_op_export} operation. It can be completed by calling +@code{gpgme_wait} on the context. @xref{Waiting For Completion}. + +The function returns @code{GPGME_No_Error} if the operation could be +started successfully, and @code{GPGME_Invalid_Value} if +@var{recipients} is @code{NULL} or @var{keydata} is not a valid empty +data buffer. +@end deftypefun + + +@node Importing Keys +@subsection Importing Keys +@cindex key, import +@cindex key ring, import to + +@deftypefun GpgmeError gpgme_op_import (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{keydata}}) +The function @code{gpgme_op_import} adds the keys in the data buffer +@var{keydata} to the key ring of the crypto engine used by @var{ctx}. +The format of @var{keydata} can be @var{ASCII} armored, for example, +but the details are specific to the crypto engine. + +More information about the import is available with +@code{gpgme_get_op_info}. @xref{Detailed Results}. + +The function returns @code{GPGME_No_Error} if the import was completed +successfully, @code{GPGME_Invalid_Value} if @var{keydata} if @var{ctx} +or @var{keydata} is not a valid pointer, and @code{GPGME_No_Data} if +@var{keydata} is an empty data buffer. +@end deftypefun + +@deftypefun GpgmeError gpgme_op_import_start (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{keydata}}) +The function @code{gpgme_op_import_start} initiates a +@code{gpgme_op_import} operation. It can be completed by calling +@code{gpgme_wait} on the context. @xref{Waiting For Completion}. + +The function returns @code{GPGME_No_Error} if the import could be +started successfully, @code{GPGME_Invalid_Value} if @var{keydata} if +@var{ctx} or @var{keydata} is not a valid pointer, and +@code{GPGME_No_Data} if @var{keydata} is an empty data buffer. +@end deftypefun + + +@node Deleting Keys +@subsection Deleting Keys +@cindex key, delete +@cindex key ring, delete from + +@deftypefun GpgmeError gpgme_op_delete (@w{GpgmeCtx @var{ctx}}, @w{const GpgmeKey @var{key}}, @w{int @var{allow_secret}}) +The function @code{gpgme_op_delete} deletes the key @var{key} from the +key ring of the crypto engine used by @var{ctx}. If +@var{allow_secret} is @code{0}, only public keys are deleted, +otherwise secret keys are deleted as well. + +The function returns @code{GPGME_No_Error} if the key was deleted +successfully, @code{GPGME_Invalid_Value} if @var{ctx} or @var{key} is +not a valid pointer, @code{GPGME_Invalid_Key} if @var{key} could not +be found in the keyring, and @code{GPGME_Conflict} if the secret key +for @var{key} is available, but @var{allow_secret} is zero. +@end deftypefun + +@deftypefun GpgmeError gpgme_op_delete_start (@w{GpgmeCtx @var{ctx}}, @w{const GpgmeKey @var{key}}, @w{int @var{allow_secret}}) +The function @code{gpgme_op_delete_start} initiates a +@code{gpgme_op_delete} operation. It can be completed by calling +@code{gpgme_wait} on the context. @xref{Waiting For Completion}. + +The function returns @code{GPGME_No_Error} if the operation was +started successfully, and @code{GPGME_Invalid_Value} if @var{ctx} or +@var{key} is not a valid pointer. +@end deftypefun + + +@node Trust Item Management +@section Trust Item Management +@cindex trust item + +@strong{Caution:} The trust items interface is experimental. + +@deftp {Data type} GpgmeTrustItem +The @code{GpgmeTrustItem} type is a handle for a trust item. +@end deftp + +@menu +* Listing Trust Items:: Browsing the list of available trust items. +* Information About Trust Items:: Requesting detailed information about trust items. +* Manipulating Trust Items:: Operations on trust items. +@end menu + + +@node Listing Trust Items +@subsection Listing Trust Items +@cindex trust item list + +@deftypefun GpgmeError gpgme_op_trustlist_start (@w{GpgmeCtx @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{max_level}}) +The function @code{gpgme_op_trustlist_start} initiates a trust item +listing operation inside the context @var{ctx}. It sets everything up +so that subsequent invocations of @code{gpgme_op_trustlist_next} return +the trust items in the list. + +The string @var{pattern} contains an engine specific expression that +is used to limit the list to all trust items matching the pattern. It +can not be the empty string. + +The argument @var{max_level} is currently ignored. + +The context will be busy until either all trust items are received +(and @code{gpgme_op_trustlist_next} returns @code{GPGME_EOF}), or +@code{gpgme_op_trustlist_end} is called to finish the operation. + +The function returns @code{GPGME_Invalid_Value} if @var{ctx} is not a +valid pointer, and passes through any errors that are reported by the +crypto engine support routines. +@end deftypefun + +@deftypefun GpgmeError gpgme_op_trustlist_next (@w{GpgmeCtx @var{ctx}}, @w{GpgmeTrustItem *@var{r_item}}) +The function @code{gpgme_op_trustlist_next} returns the next trust +item in the list created by a previous @code{gpgme_op_trustlist_start} +operation in the context @var{ctx}. The trust item can be destroyed +with @code{gpgme_trust_item_release}. @xref{Manipulating Trust Items}. + +This is the only way to get at @code{GpgmeTrustItem} objects in +@acronym{GPGME}. + +If the last trust item in the list has already been returned, +@code{gpgme_op_trustlist_next} returns @code{GPGME_EOF}. + +The function returns @code{GPGME_Invalid_Value} if @var{ctx} or +@var{r_item} is not a valid pointer, @code{GPGME_No_Request} if there +is no pending operation, @code{GPGME_Out_Of_Core} if there is not +enough memory for the operation. +@end deftypefun + +@deftypefun GpgmeError gpgme_op_trustlist_end (@w{GpgmeCtx @var{ctx}}) +The function @code{gpgme_op_trustlist_next} ends a pending key list +operation in the context @var{ctx}. + +The function returns @code{GPGME_Invalid_Value} if @var{ctx} is not a +valid pointer, @code{GPGME_No_Request} if there is no pending +operation, @code{GPGME_Out_Of_Core} if at some time during the +operation there was not enough memory available. +@end deftypefun + + +@node Information About Trust Items +@subsection Information About Trust Items +@cindex trust item, information about +@cindex trust item, attributes +@cindex attributes, of a trust item + +Trust items have attributes which can be queried using the interfaces +below. The attribute identifiers are shared with those for key +attributes. @xref{Information About Keys}. + +@deftypefun {const char *} gpgme_trust_item_get_string_attr (@w{GpgmeTrustItem @var{item}}, @w{GpgmeAttr @var{what}}, @w{const void *@var{reserved}}, @w{int @var{idx}}) +The function @code{gpgme_trust_item_get_string_attr} returns the value +of the string-representable attribute @var{what} of trust item +@var{item}. If the attribute occurs more than once in the trust +items, the index is specified by @var{idx}. However, currently no +such attributes exists, so @var{idx} should be @code{0}. The argument +@var{reserved} is reserved for later use and should be @code{NULL}. + +The string returned is only valid as long as the key is valid. + +The function returns @code{0} if an attribute can't be returned as a +string, @var{key} is not a valid pointer, @var{idx} out of range, +or @var{reserved} not @code{NULL}. +@end deftypefun + +@deftypefun int gpgme_trust_item_get_int_attr (@w{GpgmeTrustItem @var{item}}, @w{GpgmeAttr @var{what}}, @w{const void *@var{reserved}}, @w{int @var{idx}}) +The function @code{gpgme_trust_item_get_int_attr} returns the value of +the number-representable attribute @var{what} of trust item +@var{item}. If the attribute occurs more than once in the trust item, +the index is specified by @var{idx}. However, currently no such +attribute exists, so @var{idx} should be @code{0}. The argument +@var{reserved} is reserved for later use and should be @code{NULL}. + +The function returns @code{0} if the attribute can't be returned as a +number, @var{key} is not a valid pointer, @var{idx} out of range, +or @var{reserved} not @code{NULL}. +@end deftypefun + + +@node Manipulating Trust Items +@subsection Manipulating Trust Items +@cindex trust item, manipulation + +@deftypefun void gpgme_trust_item_release (@w{GpgmeTrustItem @var{item}}) +The function @code{gpgme_trust_item_release} destroys a +@code{GpgmeTrustItem} object and releases all associated resources. +@end deftypefun + +@node Crypto Operations +@section Crypto Operations +@cindex cryptographic operation + +@menu +* Decrypt:: Decrypting a ciphertext. +* Verify:: Verifying a signature. +* Decrypt and Verify:: Decrypting a signed ciphertext. +* Sign:: Creating a signature. +* Encrypt:: Encrypting a plaintext. +* Detailed Results:: How to obtain more info about the operation. +@end menu + + +@node Decrypt +@subsection Decrypt +@cindex decryption +@cindex cryptographic operation, decryption + +@deftypefun GpgmeError gpgme_op_decrypt (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{cipher}}, @w{GpgmeData @var{plain}}) +The function @code{gpgme_op_decrypt} decrypts the ciphertext in the +data object @var{cipher} and stores it into the data object +@var{plain}. + +The function returns @code{GPGME_No_Error} if the ciphertext could be +decrypted successfully, @code{GPGME_Invalid_Value} if @var{ctx}, +@var{cipher} or @var{plain} is not a valid pointer, +@code{GPGME_No_Data} if @var{cipher} does not contain any data to +decrypt, @code{GPGME_Decryption_Failed} if @var{cipher} is not a valid +cipher text, @code{GPGME_No_Passphrase} if the passphrase for the +secret key could not be retrieved, and passes through any errors that +are reported by the crypto engine support routines. +@end deftypefun + +@deftypefun GpgmeError gpgme_op_decrypt_start (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{cipher}}, @w{GpgmeData @var{plain}}) +The function @code{gpgme_op_decrypt_start} initiates a +@code{gpgme_op_decrypt} operation. It can be completed by calling +@code{gpgme_wait} on the context. @xref{Waiting For Completion}. + +The function returns @code{GPGME_No_Error} if the operation could be +started successfully, and @code{GPGME_Invalid_Value} if @var{cipher} +or @var{plain} is not a valid pointer. +@end deftypefun + + +@node Verify +@subsection Verify +@cindex verification +@cindex signature, verification +@cindex cryptographic operation, verification +@cindex cryptographic operation, signature check +@cindex signature, status + +@deftp {Data type} {enum GpgmeSigStat} +@tindex GpgmeSigStat +The @code{GpgmeSigStat} type holds the result of a signature check, or +the combined result of all signatures. The following results are +possible: + +@table @code +@item GPGME_SIG_STAT_NONE +This status should not occur in normal operation. + +@item GPGME_SIG_STAT_GOOD +This status indicates that the signature is valid. For the combined +result this status means that all signatures are valid. + +@item GPGME_SIG_STAT_BAD +This status indicates that the signature is invalid. For the combined +result this status means that all signatures are invalid. + +@item GPGME_SIG_STAT_NOKEY +This status indicates that the signature could not be verified due to +a missing key. For the combined result this status means that all +signatures could not be checked due to missing keys. + +@item GPGME_SIG_STAT_NOSIG +This status indicates that the signature data provided was not a real +signature. + +@item GPGME_SIG_STAT_ERROR +This status indicates that there was some other error which prevented +the signature verification. + +@item GPGME_SIG_STAT_DIFF +For the combined result this status means that at least two signatures +have a different status. You can get each key's status with +@code{gpgme_get_sig_status}. +@end table +@end deftp + +@deftypefun GpgmeError gpgme_op_verify (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{sig}}, @w{GpgmeData @var{plain}}, @w{GpgmeSigStat *@var{r_stat}}) +The function @code{gpgme_op_verify} verifies that the signature in the +data object @var{sig} is a valid signature. If @var{plain} is +initialized with plaintext data, it is assumed that @var{sig} is a +detached signature, and its validity for the plaintext given in +@var{plain} is verified. If @var{plain} is an uninitialized data +object, it is assumed that @var{sig} is a normal (or cleartext) +signature, and the plaintext is available in @var{plain} after +successful verification. + +The combined status of all signatures is returned in @var{r_stat}. +The results of the individual signature verifications can be retrieved +with @code{gpgme_get_sig_status} and @code{gpgme_get_sig_key}. + +The function returns @code{GPGME_No_Error} if the operation could be +completed successfully, @code{GPGME_Invalid_Value} if @var{ctx}, +@var{sig}, @var{plain} or @var{r_stat} is not a valid pointer, +@code{GPGME_No_Data} if @var{sig} does not contain any data to verify, +and passes through any errors that are reported by the crypto engine +support routines. +@end deftypefun + +@deftypefun GpgmeError gpgme_op_verify_start (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{sig}}, @w{GpgmeData @var{plain}}) +The function @code{gpgme_op_verify_start} initiates a +@code{gpgme_op_verify} operation. It can be completed by calling +@code{gpgme_wait} on the context. @xref{Waiting For Completion}. + +The function returns @code{GPGME_No_Error} if the operation could be +started successfully, @code{GPGME_Invalid_Value} if @var{ctx}, +@var{sig}, @var{plain} or @var{r_stat} is not a valid pointer, and +@code{GPGME_No_Data} if @var{sig} or @var{plain} does not contain any +data to verify. +@end deftypefun + +@deftypefun {const char *} gpgme_get_sig_status (@w{GpgmeCtx @var{ctx}}, @w{int @var{idx}}, @w{GpgmeSigStat *@var{r_stat}}, @w{time_t *@var{r_created}}) +The function @code{gpgme_get_sig_status} receives information about a +signature after the @code{gpgme_op_verify} or +@code{gpgme_op_verify_decrypt} operation. A single detached signature +can contain signatures by more than one key. The @var{idx} specifies +which signature's information should be retrieved, starting from +@var{0}. + +The status of the signature will be returned in @var{r_stat} if it is +not @code{NULL}. The creation time stamp of the signature will be +returned in @var{r_created} if it is not @var{NULL}. + +The function returns a statically allocated string that contains the +fingerprint of the key which signed the plaintext, or @code{NULL} if +@var{ctx} is not a valid pointer, the operation is still pending, or +no verification could be performed. +@end deftypefun + +@deftypefun {const char *} gpgme_get_sig_key (@w{GpgmeCtx @var{ctx}}, @w{int @var{idx}}, @w{GpgmeSigKey *@var{r_stat}}) +The function @code{gpgme_get_sig_status} receives a @code{GpgmeKey} +object for the key which was used to verify the signature after the +@code{gpgme_op_verify} or @code{gpgme_op_verify_decrypt} operation. A +single detached signature can contain signatures by more than one key. +The @var{idx} specifies which signature's information should be +retrieved, starting from @var{0}. The key will have on reference for +the user. + +The function is a convenient way to retrieve the keys belonging to the +fingerprints returned by @code{gpgme_get_sig_status}. + +The function returns @code{GPGME_No_Error} if the key could be +returned, @code{GPGME_Invalid_Value} if @var{r_key} is not a valid +pointer, @code{GPGME_Invalid_Key} if the fingerprint is not valid, +@code{GPGME_EOF} if @var{idx} is too large, or some other error value +if a problem occurred requesting the key. +@end deftypefun + +@deftypefun {char *} gpgme_get_notation (@w{GpgmeCtx @var{ctx}}) +The function @code{gpgme_get_notation} can be used to retrieve +notation data from the last signature check in the context @var{ctx}. + +If there is notation data available from the last signature check, +this function may be used to return this notation data as a string. +The string is an XML representation of that data embedded in a + container. The user has to release the string with +@code{free}. + +The function returns a string if the notation data is available or +@code{NULL} if there is no such data available. +@end deftypefun + + +@node Decrypt and Verify +@subsection Decrypt and Verify +@cindex decryption and verification +@cindex verification and decryption +@cindex signature check +@cindex cryptographic operation, decryption and verification + +@deftypefun GpgmeError gpgme_op_decrypt_verify (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{cipher}}, @w{GpgmeData @var{plain}}, @w{GpgmeSigStat *@var{r_stat}}) +The function @code{gpgme_op_decrypt_verify} decrypts the ciphertext in +the data object @var{cipher} and stores it into the data object +@var{plain}. If @var{cipher} contains signatures, they will be +verified and their combined status will be returned in @var{r_stat}. + +After the operation completed, @code{gpgme_op_get_sig_status} and +@code{gpgme_op_get_sig_key} can be used to retrieve more information +about the signatures. + +The function returns @code{GPGME_No_Error} if the ciphertext could be +decrypted successfully, @code{GPGME_Invalid_Value} if @var{ctx}, +@var{cipher}, @var{plain} or @var{r_stat} is not a valid pointer, +@code{GPGME_No_Data} if @var{cipher} does not contain any data to +decrypt, @code{GPGME_Decryption_Failed} if @var{cipher} is not a valid +cipher text, @code{GPGME_No_Passphrase} if the passphrase for the +secret key could not be retrieved, and passes through any errors that +are reported by the crypto engine support routines. +@end deftypefun + +@deftypefun GpgmeError gpgme_op_decrypt_verify (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{cipher}}, @w{GpgmeData @var{plain}}) +The function @code{gpgme_op_decrypt_verify_start} initiates a +@code{gpgme_op_decrypt_verify} operation. It can be completed by +calling @code{gpgme_wait} on the context. @xref{Waiting For +Completion}. + +The function returns @code{GPGME_No_Error} if the operation could be +started successfully, @code{GPGME_Invalid_Value} if @var{ctx}, +@var{cipher}, @var{plain} or @var{r_stat} is not a valid pointer, and +@code{GPGME_No_Data} if @var{cipher} does not contain any data to +decrypt. +@end deftypefun + + +@node Sign +@subsection Sign +@cindex signature, creation +@cindex sign +@cindex cryptographic operation, signing + +A signature can contain signatures by one or more keys. The set of +keys used to create a signatures is contained in a context, and is +applied to all following signing operations in this context (until the +set is changed). + +@menu +* Selecting Signers:: How to choose the keys to sign with. +* Creating a Signature:: How to create a signature. +@end menu + + +@node Selecting Signers +@subsubsection Selecting Signers +@cindex signature, selecting signers +@cindex signers, selecting + +@deftypefun void gpgme_signers_clear (@w{GpgmeCtx @var{ctx}}) +The function @code{gpgme_signers_clear} releases a reference for each +key on the signers list and removes the list of signers from the +context @var{ctx}. + +Every context starts with an empty list. +@end deftypefun + +@deftypefun GpgmeError gpgme_signers_add (@w{GpgmeCtx @var{ctx}}, @w{const GpgmeKey @var{key}}) +The function @code{gpgme_signers_add} adds the key @var{key} to the +list of signers in the context @var{ctx}. + +One reference for the key is consumed. +@end deftypefun + +@deftypefun GpgmeKey gpgme_signers_enum (@w{const GpgmeCtx @var{ctx}}, @w{int @var{seq}}) +The function @code{gpgme_signers_enum} returns the @var{seq}th key in +the list of signers in the context @var{ctx}. An additional reference +is acquired for the user. + +If @var{seq} is out of range, @code{NULL} is returned. +@end deftypefun + + +@node Creating a Signature +@subsubsection Creating a Signature + +@deftp {Data type} {enum GpgmeSigMode} +@tindex GpgmeSigMode +The @code{GpgmeSigMode} type is used to specify the desired type of a +signature. The following modes are available: + +@table @code +@item GPGME_SIG_MODE_NORMAL +A normal signature is made, the output includes the plaintext and the +signature. + +@item GPGME_SIG_MODE_DETACH +A detached signature is made. + +@item GPGME_SIG_MODE_CLEAR +A clear text signature is made. The @acronym{ASCII} armor and text +mode settings of the context are ignored. +@end table +@end deftp + +@deftypefun GpgmeError gpgme_op_sign (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{plain}}, @w{GpgmeData @var{sig}}, @w{GpgmeSigMode @var{mode}}) +The function @code{gpgme_op_sign} creates a signature for the text in +the data object @var{plain} and returns it in the data object +@var{sig}. The type of the signature created is determined by the +@acronym{ASCII} armor and text mode attributes set for the context +@var{ctx} and the requested signature mode @var{mode}. + +More information about the signatures is available with +@code{gpgme_get_op_info}. @xref{Detailed Results}. + +If an S/MIME signed message is created using the CMS crypto engine, +the number of certificates to include in the message can be specified +with @code{gpgme_set_include_certs}. @xref{Included Certificates}. + +The function returns @code{GPGME_No_Error} if the signature could be +created successfully, @code{GPGME_Invalid_Value} if @var{ctx}, +@var{plain} or @var{sig} is not a valid pointer, @code{GPGME_No_Data} +if the signature could not be created, @code{GPGME_No_Passphrase} if +the passphrase for the secret key could not be retrieved, and passes +through any errors that are reported by the crypto engine support +routines. +@end deftypefun + +@deftypefun GpgmeError gpgme_op_sign (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{plain}}, @w{GpgmeData @var{sig}}, @w{GpgmeSigMode @var{mode}}) +The function @code{gpgme_op_sign_start} initiates a +@code{gpgme_op_sign} operation. It can be completed by calling +@code{gpgme_wait} on the context. @xref{Waiting For Completion}. + +The function returns @code{GPGME_No_Error} if the operation could be +started successfully, and @code{GPGME_Invalid_Value} if @var{ctx}, +@var{plain} or @var{sig} is not a valid pointer. +@end deftypefun + + +@node Encrypt +@subsection Encrypt +@cindex encryption +@cindex cryptographic operation, encryption + +One plaintext can be encrypted for several recipients at the same +time. The list of recipients is created independently of any context, +and then passed to the encryption operation. + +@menu +* Selecting Recipients:: How to choose the recipients. +* Encrypting a Plaintext:: How to encrypt a plaintext. +@end menu + + +@node Selecting Recipients +@subsubsection Selecting Recipients +@cindex encryption, selecting recipients +@cindex recipients + +@deftp {Data type} GpgmeRecipients +The @code{GpgmeRecipients} type is a handle for a set of recipients +that can be used in an encryption process. +@end deftp + +@deftypefun GpgmeError gpgme_recipients_new (@w{GpgmeRecipients *@var{r_rset}}) +The function @code{gpgme_recipients_new} creates a new, empty set of +recipients and returns a handle for it in @var{r_rset}. + +The function returns @code{GPGME_No_Error} if the recipient set could +be created successfully, and @code{GPGME_Out_Of_Core} if not enough +memory was available. +@end deftypefun + +@deftypefun void gpgme_recipients_release (@w{GpgmeRecipients @var{rset}}) +The function @code{gpgme_recipients_release} destroys the set of +recipients @var{rset} and releases all associated resources. +@end deftypefun + +@deftypefun GpgmeError gpgme_recipients_add_name (@w{GpgmeRecipients @var{rset}}, @w{const char *@var{name}}) +The function @code{gpgme_recipients_add_name} adds the recipient +@var{name} to the set of recipients @var{rset}. This is equivalent to +@code{gpgme_recipients_add_name_with_validity} with a validity of +@code{GPGME_VALIDITY_UNKNOWN}. + +The function returns @code{GPGME_No_Error} if the recipient was added +successfully, @code{GPGME_Invalid_Value} if @var{rset} or @var{name} +is not a valid pointer, and @code{GPGME_Out_Of_Core} if not enough +memory is available. +@end deftypefun + +@deftypefun GpgmeError gpgme_recipients_add_name_with_validity (@w{GpgmeRecipients @var{rset}}, @w{const char *@var{name}}, @w{GpgmeValidity @var{val}}) +The function @code{gpgme_recipients_add_name_with_validity} adds the +recipient @var{name} with the validity @var{val} to the set of +recipients @var{rset}. If the validity is not known, the function +@code{gpgme_recipients_add_name} can be used. +@xref{Information About Keys}, for the possible values for @var{val}. + +The function returns @code{GPGME_No_Error} if the recipient was added +successfully, @code{GPGME_Invalid_Value} if @var{rset} or @var{name} +is not a valid pointer, and @code{GPGME_Out_Of_Core} if not enough +memory is available. +@end deftypefun + +@deftypefun {unsigned int} gpgme_recipients_count (@w{const @var{GpgmeRecipients rset}}) +The function @code{gpgme_recipients_count} returns the number of +recipients in the set @var{rset}. +@end deftypefun + +@deftypefun GpgmeError gpgme_recipients_enum_open (@w{const GpgmeRecipients @var{rset}}, @w{void **@var{iter}}) +The function @code{gpgme_recipients_enum_open} creates a new iterator +@var{iter} that can be used to walk through the set of recipients in +@var{rset}, using @code{gpgme_recipients_enum_read}. + +If the iterator is not needed anymore, it can be closed with +@code{gpgme_recipients_enum_close}. + +The function returns @code{GPGME_No_Error} if the enumerator was +successfully created and @code{GPGME_Invalid_Value} if @var{rset} or +@var{iter} is not a valid pointer. +@end deftypefun + +@deftypefun {const char *} gpgme_recipients_enum_read (@w{const GpgmeRecipients @var{rset}}, @w{void **@var{iter}}) +The function @code{gpgme_recipients_enum_read} returns a string +containing the name of the next recipient in the set @var{rset} for +the iterator @var{iter}. The string is valid as long as @var{rset} is +valid or the function is called the next time with the same recipient +set and iterator, whatever is earlier. +@end deftypefun + +@deftypefun GpgmeError gpgme_recipients_enum_close (@w{const GpgmeRecipients @var{rset}}, @w{void **@var{iter}}) +The function @code{gpgme_recipients_enum_close} releases the iterator +@var{iter} for the recipient set @var{rset}. +@end deftypefun + + +@node Encrypting a Plaintext +@subsubsection Encrypting a Plaintext + +@deftypefun GpgmeError gpgme_op_encrypt (@w{GpgmeCtx @var{ctx}}, @w{GpgmeRecipients @var{rset}}, @w{GpgmeData @var{plain}}, @w{GpgmeData @var{cipher}}) +The function @code{gpgme_op_encrypt} encrypts the plaintext in the data +object @var{plain} for the recipients @var{rset} and stores the +ciphertext in the data object @var{cipher}. The type of the +ciphertext created is determined by the @acronym{ASCII} armor and text +mode attributes set for the context @var{ctx}. + +If @code{GPGME_Invalid_Recipients} is returned, some recipients in +@var{rset} are invalid, but not all. In this case the plaintext is +encrypted for all valid recipients and returned in @var{cipher}. More +information about the invalid recipients is available with +@code{gpgme_get_op_info}. @xref{Detailed Results}. + +The function returns @code{GPGME_No_Error} if the ciphertext could be +created successfully, @code{GPGME_Invalid_Value} if @var{ctx}, +@var{rset}, @var{plain} or @var{cipher} is not a valid pointer, +@code{GPGME_No_Recipients} if @var{rset} does not contain any valid +recipients, @code{GPGME_Invalid_Recipients} if @var{rset} contains +some invalid recipients, @code{GPGME_No_Passphrase} if the passphrase +for the secret key could not be retrieved, and passes through any +errors that are reported by the crypto engine support routines. +@end deftypefun + +@deftypefun GpgmeError gpgme_op_encrypt_start (@w{GpgmeCtx @var{ctx}}, @w{GpgmeRecipients @var{rset}}, @w{GpgmeData @var{plain}}, @w{GpgmeData @var{cipher}}) +The function @code{gpgme_op_encrypt_start} initiates a +@code{gpgme_op_encrypt} operation. It can be completed by calling +@code{gpgme_wait} on the context. @xref{Waiting For Completion}. + +The function returns @code{GPGME_No_Error} if the operation could be +started successfully, @code{GPGME_Invalid_Value} if @var{ctx}, +@var{rset}, @var{plain} or @var{cipher} is not a valid pointer, and +@code{GPGME_No_Recipients} if @var{rset} does not contain any valid +recipients. +@end deftypefun + + +@deftypefun GpgmeError gpgme_op_encrypt_sign (@w{GpgmeCtx @var{ctx}}, @w{GpgmeRecipients @var{rset}}, @w{GpgmeData @var{plain}}, @w{GpgmeData @var{cipher}}) +The function @code{gpgme_op_encrypt_sign} does a combined encrypt and +sign operation. It is used like @code{gpgme_op_encrypt}, but the +ciphertext also contains signatures for the signers listed in +@var{ctx}. + +The combined encrypt and sign operation is currently only available +for the OpenPGP crypto engine. +@end deftypefun + +@deftypefun GpgmeError gpgme_op_encrypt_sign_start (@w{GpgmeCtx @var{ctx}}, @w{GpgmeRecipients @var{rset}}, @w{GpgmeData @var{plain}}, @w{GpgmeData @var{cipher}}) +The function @code{gpgme_op_encrypt_sign_start} initiates a +@code{gpgme_op_encrypt_sign} operation. It can be completed by +calling @code{gpgme_wait} on the context. @xref{Waiting For +Completion}. + +The function returns @code{GPGME_No_Error} if the operation could be +started successfully, @code{GPGME_Invalid_Value} if @var{ctx}, +@var{rset}, @var{plain} or @var{cipher} is not a valid pointer, and +@code{GPGME_No_Recipients} if @var{rset} does not contain any valid +recipients. +@end deftypefun + + +@node Detailed Results +@subsection Detailed Results +@cindex cryptographic operation, detailed results + +@deftypefun {char *} gpgme_get_op_info (@w{GpgmeCtx @var{ctx}}, @w{int @var{reserved}}) +The function @code{gpgme_get_op_info} retrieves more information about +the last crypto operation. + +The function returns a string in the XML format. The user has to +release the string with @code{free}. + +Here is a sample of the information that might be returned: +@example + + + + 17 + 2 + pgp-sha1 + 01 + 9222222 + 121212121212121212 + + +@end example + +Currently, the only operations that return additional information are +encrypt and sign. @xref{Encrypt}, @xref{Sign}. + +The function returns a string or @code{NULL} if no such data is +available. +@end deftypefun + + +@node Run Control +@section Run Control +@cindex run control +@cindex cryptographic operation, running + +Some basic support for running operations asynchronously is available +in @acronym{GPGME}. You can use it to set up a context completely up +to initiating the desired operation, but delay performing it to a +later point. + +@menu +* Waiting For Completion:: Waiting until an operation is completed. +* Cancelling an Operation:: Interrupting a running operation. +* Hooking Up Into Idle Time:: Doing something when nothing has to be done. +@end menu + + +@node Waiting For Completion +@subsection Waiting For Completion +@cindex cryptographic operation, wait for +@cindex wait for completion + +@deftypefun GpgmeCtx gpgme_wait (@w{GpgmeCtx @var{ctx}}, @w{GpgmeError *@var{status}}, @w{int @var{hang}}) +The function @code{gpgme_wait} does continue the pending operation +within the context @var{ctx}. In particular, it ensures the data +exchange between @acronym{GPGME} and the crypto backend and watches +over the run time status of the backend process. + +If @var{hang} is true, the function does not return until the +operation is completed or cancelled. Otherwise the function will not +block for a long time. + +The error status of the finished operation is returned in +@var{status}. + +The @var{ctx} argument can be @code{NULL}. In that case, +@code{gpgme_wait} waits for any context to complete its operation. + +The function returns the @var{ctx} of the context which has finished +the operation. +@end deftypefun + + +@node Cancelling an Operation +@subsection Cancelling an Operation +@cindex cancellation +@cindex cryptographic operation, cancel + +@deftypefun void gpgme_cancel (@w{GpgmeCtx @var{ctx}}) +The function @code{gpgme_cancel} tries to cancel the pending +operation. The function @code{gpgme_wait} might notice the +cancellation flag and return. It is currently not guaranteed to work +under all circumstances. It's current primary purpose is to prevent +asking for a passphrase again in the passphrase callback. +@end deftypefun + + +@node Hooking Up Into Idle Time +@subsection Hooking Up Into Idle Time +@cindex idle time +@cindex idle function + +@deftp {Data type} {void (*GpgmeIdleFunc) (void)} +@tindex GpgmeIdleFunc +The @code{GpgmeIdleFunc} type is the type of functions usable as +an idle function that can be registered with @code{gpgme_register_idle}. +@end deftp + +@deftypefun GpgmeIdleFunc gpgme_register_idle (@w{GpgmeIdleFunc @var{idle}}) +The function @code{gpgme_register_idle} can be used to register +@var{idle} as the idle function. + +@var{idle} will be called whenever @acronym{GPGME} thinks that it is +idle and time can better be spent elsewhere. Setting @var{idle} to +@code{NULL} disables use of the idle function (this is the default). + +The function returns the old idle function, or @code{NULL} if none was +registered yet. +@end deftypefun + + +@include gpl.texi + + +@include fdl.texi + + +@node Concept Index +@unnumbered Concept Index + +@printindex cp + + +@node Function and Data Index +@unnumbered Function and Data Index + +@printindex fn + + +@summarycontents +@contents +@bye + +@c LocalWords: GPGME gpgme diff --git a/tags/V0-3-4/doc/gpl.texi b/tags/V0-3-4/doc/gpl.texi new file mode 100644 index 0000000..ca0508f --- /dev/null +++ b/tags/V0-3-4/doc/gpl.texi @@ -0,0 +1,397 @@ +@node Copying +@appendix GNU GENERAL PUBLIC LICENSE + +@cindex GPL, GNU General Public License +@center Version 2, June 1991 + +@display +Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc. +59 Temple Place -- Suite 330, Boston, MA 02111-1307, USA + +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. +@end display + +@appendixsubsec Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software---to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + +@iftex +@appendixsubsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION +@end iftex +@ifinfo +@center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION +@end ifinfo + +@enumerate +@item +This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The ``Program'', below, +refers to any such program or work, and a ``work based on the Program'' +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term ``modification''.) Each licensee is addressed as ``you''. + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + +@item +You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + +@item +You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + +@enumerate a +@item +You must cause the modified files to carry prominent notices +stating that you changed the files and the date of any change. + +@item +You must cause any work that you distribute or publish, that in +whole or in part contains or is derived from the Program or any +part thereof, to be licensed as a whole at no charge to all third +parties under the terms of this License. + +@item +If the modified program normally reads commands interactively +when run, you must cause it, when started running for such +interactive use in the most ordinary way, to print or display an +announcement including an appropriate copyright notice and a +notice that there is no warranty (or else, saying that you provide +a warranty) and that users may redistribute the program under +these conditions, and telling the user how to view a copy of this +License. (Exception: if the Program itself is interactive but +does not normally print such an announcement, your work based on +the Program is not required to print an announcement.) +@end enumerate + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +@item +You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + +@enumerate a +@item +Accompany it with the complete corresponding machine-readable +source code, which must be distributed under the terms of Sections +1 and 2 above on a medium customarily used for software interchange; or, + +@item +Accompany it with a written offer, valid for at least three +years, to give any third party, for a charge no more than your +cost of physically performing source distribution, a complete +machine-readable copy of the corresponding source code, to be +distributed under the terms of Sections 1 and 2 above on a medium +customarily used for software interchange; or, + +@item +Accompany it with the information you received as to the offer +to distribute corresponding source code. (This alternative is +allowed only for noncommercial distribution and only if you +received the program in object code or executable form with such +an offer, in accord with Subsection b above.) +@end enumerate + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + +@item +You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + +@item +You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +@item +Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + +@item +If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +@item +If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + +@item +The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and ``any +later version'', you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + +@item +If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + +@iftex +@heading NO WARRANTY +@end iftex +@ifinfo +@center NO WARRANTY +@end ifinfo + +@item +BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + +@item +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. +@end enumerate + +@iftex +@heading END OF TERMS AND CONDITIONS +@end iftex +@ifinfo +@center END OF TERMS AND CONDITIONS +@end ifinfo + +@page +@unnumberedsec How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the ``copyright'' line and a pointer to where the full notice is found. + +@smallexample +@var{one line to give the program's name and an idea of what it does.} +Copyright (C) 19@var{yy} @var{name of author} + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. +@end smallexample + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + +@smallexample +Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author} +Gnomovision comes with ABSOLUTELY NO WARRANTY; for details +type `show w'. This is free software, and you are welcome +to redistribute it under certain conditions; type `show c' +for details. +@end smallexample + +The hypothetical commands @samp{show w} and @samp{show c} should show +the appropriate parts of the General Public License. Of course, the +commands you use may be called something other than @samp{show w} and +@samp{show c}; they could even be mouse-clicks or menu items---whatever +suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a ``copyright disclaimer'' for the program, if +necessary. Here is a sample; alter the names: + +@smallexample +@group +Yoyodyne, Inc., hereby disclaims all copyright +interest in the program `Gnomovision' +(which makes passes at compilers) written +by James Hacker. + +@var{signature of Ty Coon}, 1 April 1989 +Ty Coon, President of Vice +@end group +@end smallexample + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/tags/V0-3-4/gpgme.txt b/tags/V0-3-4/gpgme.txt new file mode 100644 index 0000000..9e04adc --- /dev/null +++ b/tags/V0-3-4/gpgme.txt @@ -0,0 +1,90 @@ +%%comments: +Copyright (C) 2001 Free Software Foundation, Inc. + +Permission is granted to copy, distribute and/or modify this document +under the terms of the GNU Free Documentation License, Version 1.1 or +any later version published by the Free Software Foundation; with no +Invariant Sections, with no Front-Cover Texts, and with no Back-Cover +Texts. A copy of the license is included in the file COPYING. + +%%name: GPGME + +%%short-description: GnuPG Made Easy + +%%full-description: GPGME is a library designed to make access to +GnuPG easier for applications. It provides a High-Level Crypto API +for encryption, decryption, signing, signature verification and key +management. Currently it uses GnuPG and GpgSM as its backends to +support OpenPGP and the Cryptographic Message Syntax. + +%%category: security, libraries + +%%license: GPL +%%license verified by: +%%license verified on: + +%%maintainer: g10 Code GmbH + +%%updated: 2001-12-19 + +%%keywords: encryption, public key, digital signature, GnuPG + +%%interface: + +%%programs: + +%%GNU: no + +%%web-page: http://www.gnupg.org/gpgme.html + +%%support: paid extension/consulting from http://www.g10code.com + +%%doc: English programmer reference in Texinfo, Postscript, HTML included + +%%developers: Werner Koch . + +%%contributors: + +%%sponsors: + +%%source: ftp://ftp.gnupg.org/gcrypt/alpha/gpgme/ + +%%debian: + +%%redhat: + +%%repository: See http://www.gnupg.org/cvs-access.html + +%%related: + +%%source-language: C + +%%supported-languages: C, C++ + +%%use-requirements: GnuPG 1.0.6, GpgSM 0.0.0 + +%%build-prerequisites: + +%%weak-prerequisites: + +%%source-prerequisites: + +%%version: 0.3.0 released on 2001-12-19 + +%%announce-list: announce@gnupg.org announce-request@gnupg.org + +%%announce-news: + +%%help-list: + +%%help-news: + +%%dev-list: gnupg-devel@gnupg.org gnupg-devel-request@gnupg.org + +%%dev-news: + +%%bug-list: + +%%bug-database: + +%%entry written by: Werner Koch diff --git a/tags/V0-3-4/gpgme/.cvsignore b/tags/V0-3-4/gpgme/.cvsignore new file mode 100644 index 0000000..9d8fd2d --- /dev/null +++ b/tags/V0-3-4/gpgme/.cvsignore @@ -0,0 +1,6 @@ +Makefile.in Makefile .deps .libs +*.lo *.la +errors.c +gpgme-config +status-table.h + diff --git a/tags/V0-3-4/gpgme/ChangeLog b/tags/V0-3-4/gpgme/ChangeLog new file mode 100644 index 0000000..f2104c7 --- /dev/null +++ b/tags/V0-3-4/gpgme/ChangeLog @@ -0,0 +1,1265 @@ +2002-03-03 Marcus Brinkmann + + * passphrase.c (_gpgme_passphrase_status_handler): Also set the + error No_Passphrase if only a bad passphrase was provided. + +2002-03-03 Marcus Brinkmann + + * rungpg.c (_gpgme_gpg_op_verify): If TEXT is of mode + GPGME_DATA_MODE_IN, construct a command line that stores the + plaintext in TEXT. + * verify.c (gpgme_op_verify_start): Accept TEXT being + uninitialized, and in this case interpret SIG as a normal or + cleartext signature and TEXT as a return data object. + * engine-gpgsm.c (_gpgme_gpgsm_op_verify): Likewise. + +2002-03-03 Marcus Brinkmann + + * engine-gpgsm.c (_gpgme_gpgsm_op_keylist_ext) [!ENABLE_GPGSM]: + Add stub function. + +2002-02-28 Werner Koch + + * key.h (subkey_s): New member expires_at. + * keylist.c (keylist_colon_handler): Set it here + * key.c (gpgme_key_get_as_xml,gpgme_key_get_ulong_attr): Return it. + +2002-02-27 Marcus Brinkmann + + * rungpg.h (_gpgme_gpg_op_keylist_ext): New prototype. + * rungpg.c (_gpgme_gpg_op_keylist_ext): New function. + * engine-gpgsm.h (_gpgme_gpgsm_op_keylist_ext): New prototype. + * engine-gpgsm.c (_gpgme_gpgsm_op_keylist_ext): New function. + * engine.h (_gpgme_engine_op_keylist_ext): New prototype. + * engine.c (_gpgme_engine_op_keylist_ext): New function. + * keylist.c (gpgme_op_keylist_ext_start): New function. + +2002-02-27 Marcus Brinkmann + + * gpgme.h: Add new error code GPGME_Invalid_Recipient. + * encrypt.c (struct encrypt_result_s): New member invalid_recipients, + rename no_recipients to no_valid_recipients. + (_gpgme_encrypt_status_handler): Include error for invalid + recipients. + * engine-gpgsm.c (gpgsm_set_recipients): Change type of first + argument to GpgsmObject. Use that to report back the status about + the recipients. + +2002-02-26 Marcus Brinkmann + + * verify.c (_gpgme_verify_status_handler): Fix the last change. + +2002-02-25 Marcus Brinkmann + + * engine.c (_gpgme_engine_op_encrypt_sign): New function. + * engine.h (_gpgme_engine_op_encrypt_sign): New prototype. + * rungpg.c (_gpgme_append_gpg_args_from_signers): New function. + (_gpgme_gpg_op_sign): Use that new function. + (_gpgme_gpg_op_encrypt_sign): New function. + * rungpg.h (_gpgme_gpg_op_encrypt_sign): New prototype. + * gpgme.h (gpgme_op_encrypt_sign_start): New prototype. + (gpgme_op_encrypt_sign): Likewise. + * Makefile.am (libgpgme_la_SOURCES): Add encrypt-sign.c. + * ops.h (_gpgme_encrypt_status_handler): Add prototype. + (_gpgme_sign_status_handler): Add prototype. + * sign.c (sign_status_handler): Rename to ... + (_gpgme_sign_status_handler): ... this and make non-static. + * encrypt.c (encrypt_status_handler): Rename to ... + (_gpgme_encrypt_status_handler): ... this and make non-static. + * encrypt.c (gpgme_op_encrypt_start): Use new status handler name. + * sign.c (gpgme_op_sign_start): Likewise. + +2002-02-25 Marcus Brinkmann + + * verify.c (_gpgme_verify_status_handler): Parse the args line to + see if the problem is due to a missing key, and report that back + to the user. + +2002-02-25 Marcus Brinkmann + + * context.h (struct gpgme_context_s): New member include_certs. + * gpgme.h (gpgme_set_include_certs): Add prototype. + (gpgme_get_include_certs): Likewise. + * gpgme.c (gpgme_set_include_certs): New function. + (gpgme_get_include_certs): Likewise. + (gpgme_new): Set include_certs to 1 (the default). + * engine.c (_gpgme_engine_op_sign): Accept new argument include_certs, + and pass it to _gpgme_gpgsm_op_sign. + * engine.h (_gpgme_engine_op_sign): Likewise for prototype. + * engine-gpgsm.c (_gpgme_gpgsm_op_sign): Accept new argument + include_certs and handle it. + * engine-gpgsm.h (_gpgme_gpgsm_start): Add new argument include_certs. + * sign.c (gpgme_op_sign_start): Add new argument to + _gpgme_engine_op_sign call. + +2002-02-14 Werner Koch + + * keylist.c (gpgme_op_keylist_start): Do not use a verbose listing. + +2002-02-13 Werner Koch + + * vasprintf.c, fopencookie.c: Add replacement functions. + * util.h: Add prototypes for them. + +2002-02-09 Marcus Brinkmann + + * engine-gpgsm.c (gpgsm_assuan_simple_command): Return 0 if we + reach the end of the function. + +2002-02-09 Marcus Brinkmann + + * genkey.c (gpgme_op_genkey_start): Fix logic in validity check. + (gpgme_op_genkey_start): Skip newlines after opening tag. + + * engine-gpgsm.c (_gpgme_gpgsm_start): Remove cruft. + +2002-02-08 Marcus Brinkmann + + * genkey.c (gpgme_op_genkey_start): Allow PUBKEY and SECKEY to be + set, and pass them down to the crypto engine. + * engine-gpgsm.h (_gpgme_gpgsm_start): New arguments PUBKEY and SECKEY. + * engine.h: Likewise. + * rungpg.h (_gpgme_gpg_spawn): Likewise. + * engine.c (_gpgme_engine_op_genkey): Likewise. Use those + arguments. + * rungpg.c (_gpgme_gpg_op_genkey): Likewise. Complain if those + arguments are set. + * engine-gpgsm.c (_gpgme_gpgsm_op_genkey): Likewise. Implement + function. + + * engine-gpgsm.c (_gpgme_gpgsm_op_keylist): Beautify comment. + +2002-02-06 Marcus Brinkmann + + * rungpg.c (_gpgme_gpg_op_keylist): Remove handling of keylist + mode (for now). + +2002-02-06 Marcus Brinkmann + + * wait.c (gpgme_wait): Add new argument STATUS, in which the + status of the returned context is returned. + (_gpgme_wait_on_condition): Rework the function a bit, to make it + aware of cancelled processes, and to allow to use gpgme_wait with + CTX being NULL (as documented in the source). + (struct proc_s): New member REPORTED. + * gpgme.h: Fix prototype. + * verify.c (gpgme_op_verify): Fix use of gpgme_wait. + * sign.c (gpgme_op_sign): Likewise. + * import.c (gpgme_op_import): Likewise. + * genkey.c (gpgme_op_genkey): Likewise. + * export.c (gpgme_op_export): Likewise. + * encrypt.c (gpgme_op_encrypt): Likewise. + * delete.c (gpgme_op_delete): Likewise. + * decrypt-verify.c (gpgme_op_decrypt_verify): Likewise. + +2002-02-06 Marcus Brinkmann + + * gpgme.c (gpgme_set_keylist_mode): Possibly return an error + value. + (gpgme_get_keylist_mode): New function. + (gpgme_new): Set the default for keylist_mode member of CTX. + + * gpgme.h (gpgme_set_keylist_mode): Fix prototype. + (gpgme_get_keylist_mode): New prototype. + (GPGME_KEYLIST_MODE_LOCAL): New macro. + (GPGME_KEYLIST_MODE_EXTERN): Likewise.. + +2002-02-02 Marcus Brinkmann + + This patch has gotten a bit large... mmh. The main thing that + happens here is that error values are now not determined in the + operation function after gpgme_wait completed, but in the status + handler when EOF is received. It should always be the case that + either an error is flagged or EOF is received, so that after a + gpgme_wait you should never have the situation that no error is + flagged and EOF is not received. One problem is that the engine + status handlers don't have access to the context, a horrible + kludge works around this for now. All errors that happen during a + pending operation should be catched and reported in ctx->error, + including out-of-core and cancellation. This rounds up neatly a + couple of loose ends, and makes it possible to pass up any errors + in the communication with the backend as well. As a bonus, there + will be a function to access gpgme->wait, so that the operations + can truly be implemented with their _start function. + + * engine-gpgsm.c (gpgsm_status_handler): Horrible kludge to report + error back to the context. + * rungpg.c (gpg_status_handler): Same horrible kludge applied here. + + * engine-gpgsm.c (gpgsm_assuan_simple_command): Add error checking. + + * wait.c (_gpgme_wait_on_condition): If canceled, set CTX->error + to a value indication that. + + * verify.c (add_notation): Set error, not out_of_core. + (finish_sig): Likewise. + (gpgme_op_verify_start): Don't clear out_of_core. + (_gpgme_verify_status_handler): At EOF, clean up the notation data. + (gpgme_op_verify): And don't do it here. + + * trustlist.c (trustlist_status_handler): Check error, not out_of_core. + (gpgme_op_trustlist_start): Don't clear out_of_core. + (gpgme_op_trustlist_next): Check error, not out_of_core. + (gpgme_op_trustlist_end): Likewise. + + * ops.h (test_and_allocate_result): New macro. + (_gpgme_passphrase_result): Remove prototype. + * delete.c (gpgme_op_delete): Return error from context. + (delete_status_handler): Use macro test_and_allocate_result. + Perform error checking at EOF. + (gpgme_op_delete_start): Release result. + * passphrase.c (_gpgme_passphrase_status_handler): Use macro + test_and_allocate_result, and perform error checking here. + (_gpgme_passphrase_result): Function removed. + * sign.c (gpgme_op_sign_start): Do not set out_of_core to zero. + (gpgme_op_sign): Just return the error value from the context. + (sign_status_handler): Only progress if no error is set yet. If + we process an EOF, set the resulting error value (if any). + * decrypt.c (_gpgme_decrypt_result): Function removed. + (create_result_struct): Function removed. + (_gpgme_decrypt_status_handler): Use macro test_and_allocate_result, + caclulate error on EOF, do not progress with errors. + (_gpgme_decrypt_start): Do not set out_of_core to zero. + (gpgme_op_decrypt): Just return the error value from the context. + * encrypt.c (encrypt_status_handler): Perform the error checking + here. + (gpgme_op_encrypt_start): Do not clear out_of_core. + * export.c (export_status_handler): Return if error is set in context. + (gpgme_op_export_start): Release result. + (gpgme_op_export): Return error from context. + * decrypt-verify.c (gpgme_op_decrypt_verify): Return the error in + the context. + * genkey.c (genkey_status_handler): Use macro + test_and_allocate_result. Perform error checking at EOF. + (gpgme_op_genkey): Just return the error from context. + * import.c (gpgme_op_import): Return the error from context. + (import_status_handler): Use macro test_and_allocate_result. + * keylist.c (gpgme_op_keylist_start): Do not clear out_of_core. + (gpgme_op_keylist_next): Return error of context. + (keylist_colon_handler): Set error instead out_of_code. + (finish_key): Likewise. + + * context.h: Remove member out_of_core, add member error. + * gpgme.c (_gpgme_release_result): Clear error flag. + + * engine.h (_gpgme_engine_get_error): New prototype. + * engine.c (_gpgme_engine_get_error): New function. + * engine-gpgsm.c (_gpgme_gpgsm_get_error): New function. + + * engine-gpgsm.c (map_assuan_error): New function. + (gpgsm_assuan_simple_command): Change return type to GpgmeError, + use the new function to map error values. + (gpgsm_set_fd): Change return type tp GpgmeError. + (_gpgme_gpgsm_op_decrypt): Change type of ERR to GpgmeError. + (gpgsm_set_recipients): Likewise. Change type of return value + equivalently. Adjust error values. + (_gpgme_gpgsm_op_import): Likewise. + (_gpgme_gpgsm_op_sign): Likewise. + (struct gpgsm_object_s): New member error. + (gpgsm_status_handler): Set error if error occurs. Determine + error number from ERR line received. If assuan_read_line fails, + terminate the connection. + +2002-02-01 Marcus Brinkmann + + * Makefile.am (MOSTLYCLEANFILES): New variable. + +2002-02-01 Marcus Brinkmann + + * engine-gpgsm.c (gpgsm_status_handler): At error, terminate the + connection to the server. + +2002-01-31 Marcus Brinkmann + + * rungpg.h: Add STATUS_KEY_CREATED. + + * progress.c: New file. + * Makefile.am (libgpgme_la_SOURCES): Add progress.c. + + * genkey.c (genkey_status_handler): Use + _gpgme_progress_status_handler. Add check for status. + (struct genkey_result_s): New structure. + (_gpgme_release_genkey_result): New function. + (gpgme_op_genkey): Check for error. + * gpgme.c (_gpgme_release_result): Call + _gpgme_release_genkey_result. + * ops.h (_gpgme_release_genkey_result): Add prototype. + * types.h (GenKeyResult): New type. + * context.h (gpgme_context_s): Add GenKeyResult to member result. + +2002-01-30 Marcus Brinkmann + + * gpgme.c (_gpgme_release_result): Call + _gpgme_release_delete_result. + * ops.h (_gpgme_release_delete_result): Add prototype. + * types.h (DeleteResult): New type. + * context.h (gpgme_context_s): Add DeleteResult to member result. + + * delete.c (enum delete_problem): New type. + (struct delete_result_s): New structure. + (_gpgme_release_delete_result): New function. + (delete_status_handler): Implement more status codes. + (gpgme_op_delete): Return error on failure. + + * import.c (MAX_IMPORTED_FIELDS): Bump up to 14. + +2002-01-30 Marcus Brinkmann + + * import.c (struct import_result_s): New structure. + (_gpgme_release_import_result): New function. + (append_xml_impinfo): Likewise. + (import_status_handler): Implement. + * gpgme.c (_gpgme_release_result): Add call to + _gpgme_release_import_result. + * ops.h (_gpgme_release_import_result): Add prototype. + * types.h (ImportResult): New type. + * context.h (gpgme_context_s): Add ImportResult to member result. + + * encrypt.c (gpgme_op_encrypt): Code clean up. + +2002-01-30 Marcus Brinkmann + + * gpgme.h: Add lots of comment and fix the formatting. Add + gpgme_trustlist_end prototype. + +2002-01-29 Marcus Brinkmann + + * gpgme.h: Add new type GpgmeIdleFunc. Change type of + gpgme_register_idle to return and accept this type. + * wait.c (gpgme_register_idle): Fix type. + Save and return old value of idle_function. + +2002-01-29 Werner Koch + + * engine-gpgsm.c (_gpgme_gpgsm_op_keylist): Implement secret only mode. + + * keylist.c (keylist_colon_handler): Add support for the new "crs" + record type. + +2002-01-22 Marcus Brinkmann + + * engine-gpgsm.c (_gpgme_gpgsm_release): Call assuan_disconnect, + not assuan_pipe_disconnect. + + * Makefile.am (libgpgme_la_LIBADD): Change to link assuan and + jnlib (needed by assuan) statically into libgpgme. Linking a + static library into a shared library this way is not portable. + +2002-01-22 Marcus Brinkmann + + * gpgme.h (GpgmePassphraseCb): Change type of R_HD from void* to + void**. + +2002-01-22 Marcus Brinkmann + + * data.c (gpgme_data_new_from_filepart): Change type of LENGTH + from off_t to size_t. + * gpgme.h: Likewise. + +2002-01-22 Marcus Brinkmann + + * wait.c (_gpgme_wait_on_condition): If the process finished, + reset the pending flag. Also if the operation was cancelled. + + (struct proc_s): Rename READY to DONE. + (wait_item_s): Likewise. + (set_process_ready): Rename to ... + (set_process_done): ... this. + (_gpgme_remove_proc_from_wait_queue): Call set_process_done + instead set_process_ready. + (_gpgme_wait_on_condition): Likewise. + (do_select): Rename READY to DONE. + + * verify.c (gpgme_op_verify): Do not set pending to zero here. + * sign.c (gpgme_op_sign): Likewise. + * import.c (gpgme_op_import): Likewise. + * genkey.c (gpgme_op_genkey): Likewise. + * export.c (gpgme_op_export): Likewise. + * encrypt.c (gpgme_op_encrypt): Likewise. + * delete.c (gpgme_op_delete): Likewise. + * decrypt-verify.c (gpgme_op_decrypt_verify): Likewise. + * decrypt.c (gpgme_op_decrypt): Likewise. + +2002-01-22 Marcus Brinkmann + + * export.c: Cleanup. + +2002-01-15 Marcus Brinkmann + + * trustlist.c: Various source clean ups. + (my_isdigit): Removed. + (gpgme_op_trustlist_end): New function. + +2002-01-13 Marcus Brinkmann + + * gpgme.c: Various source clean ups, like renaming C to CTX where + appropriate. + (gpgme_new): Clear R_CTX before starting the work. + (my_isdigit): Removed. + (my_isxdigit): Likewise. + + * data.c: Various source clean ups. + (gpgme_data_new_from_mem): Check BUFFER after clearing R_DH. + (gpgme_data_new_with_read_cb): Similar for READ_CB. + (gpgme_data_new_from_file): Loop over fread while EINTR. + (gpgme_data_new_from_filepart): Rediddled a bit. Allow LENGTH to + be zero. Loop over fread while EINTR. + + (my_isdigit): Removed. + (my_isxdigit): Likewise. + +2001-12-21 Marcus Brinkmann + + * engine-gpgsm.c (_gpgme_gpgsm_new): Replace General_Error with + Pipe_Error where appropriate. + +2001-12-19 Marcus Brinkmann + + * engine.c: Include `string.h'. Reported by Stéphane Corthésy. + + * version.c (get_engine_info): Remove prototype. + +2001-12-19 Marcus Brinkmann + + * engine-gpgsm.c (_gpgme_gpgsm_new): New variable CHILD_FDS. + Fill it with the servers fds, and pass it to assuan_pipe_connect. + +2001-12-18 Marcus Brinkmann + + * keylist.c (gpgme_op_keylist_end): New function. + * gpgme.h (gpgme_op_keylist_end): New prototype. + + * engine.h (gpgme_engine_check_version): Move prototype to ... + * gpgme.h (gpgme_engine_check_version): ... here. + + * genkey.c (gpgme_op_genkey_start): Remove unused variable. + +2001-12-18 Marcus Brinkmann + + * version.c (gpgme_get_engine_info): Reimplemented. + (gpgme_check_engine): Reimplemented. + (_gpgme_compare_versions): Return NULL if MY_VERSION is NULL. + + * engine.c: Include `io.h'. + (gpgme_engine_get_info): New function. + * engine.h (gpgme_engine_check_version, _gpgme_engine_get_info): + Add prototype. + +2001-12-18 Marcus Brinkmann + + * rungpg.c (struct reap_s, reap_list, reap_list_lock): Moved to ... + * engine.c (struct reap_s, reap_list, reap_list_lock): ... here. + Include `time.h', `sys/types.h', `assert.h', and `sema.h'. + + * rungpg.c (_gpgme_engine_add_child_to_reap_list): New function. + (do_reaping, _gpgme_gpg_housecleaning): Moved to ... + * engine.c (do_reaping, _gpgme_engine_housecleaning): ... here. + * rungpg.c (_gpgme_gpg_release): Replace code that is now in its + own function by call to _gpgme_engine_add_child_to_reap_list(). + + * wait.c: Include `engine.h'. + (run_idle): Call _gpgme_engine_housecleaning(), not + _gpgme_gpg_housecleaning(). + +2001-12-18 Marcus Brinkmann + + * key.c (_gpgme_key_append_name): Append, not prepend, the uid. + Initialize the next field of the uid structure. + (gpgme_key_get_as_xml): Do not list last uid first. + +2001-12-17 Marcus Brinkmann + + * engine-gpgsm.c (_gpgme_gpgsm_set_colon_line_handler): New + function [!ENABLE_GPGSM]. + +2001-12-14 Marcus Brinkmann + + * engine-gpgsm.c (_gpgme_gpgsm_op_verify): Put TEXT into + message_data, not SIG. + (_gpgme_gpgsm_op_sign): Use `--detached', not `--detach'. + + * sign.c (sign_status_handler): Call + _gpgme_passphrase_status_handler early. + +2001-12-14 Marcus Brinkmann + + * engine-gpgsm.c: Revert last change. + +2001-12-14 Marcus Brinkmann + + * engine-gpgsm.c (gpgsm_status_handler): Freeze the output file + handler when ending this operation, otherwise the wait function + will sit on it. + +2001-12-14 Marcus Brinkmann + + * engine-gpgsm.c (struct gpgsm_object_s): New member colon.attic. + (_gpgme_gpgsm_new): Initialize some more members. + (_gpgme_gpgsm_release): Free the colon line handler's attic line. + (gpgsm_status_handler): Rework the inline-data processing. + +2001-12-13 Marcus Brinkmann + + * rungpg.c (_gpgme_gpg_spawn): Do not add the fds to the child + list that are not dup'ed, for those the close-on-exec flag is set + now. + * version.c (_gpgme_get_program_version): Remove first entry in + CFD, as the close-on-exec flag is now set for this fd. + +2001-12-13 Marcus Brinkmann + + * engine-gpgsm.c (_gpgme_gpgsm_op_encrypt): Do not add `armor' + option to `ENCRYPT'. + * engine-gpgsm.c (gpgsm_set_recipients): Free LINE when returning + successfully. + +2001-12-13 Marcus Brinkmann + + * engine-gpgsm.c (close_notify_handler): New function. + (_gpgme_gpgsm_new): Manage the file descriptors a + bit differently. Do not set close-on-exec flags. + (_gpgme_gpgsm_op_decrypt): Do not set message_fd + to -1, this is done by the close handler. + (_gpgme_gpgsm_op_encrypt): Likewise. + (_gpgme_gpgsm_op_import): Likewise (also for output_fd). + (_gpgme_gpgsm_op_keylist): Likewise (also for input_fd and output_fd). + (_gpgme_gpgsm_op_sign): Likewise. + (_gpgme_gpgsm_op_verify): Likewise, but for output_fd. + + * posix-io.c (_gpgme_io_pipe): Set the close-on-exec flag for the + non-inherited file descriptor index of the pipe. + +2001-12-13 Werner Koch + + * engine-gpgsm.c (_gpgme_gpgsm_set_colon_line_handler): New. + (gpgsm_status_handler): Pass datalines to a colon handler + * engine.c (_gpgme_engine_set_colon_line_handler): Set the colon + handler for gpgsm. + + * engine-gpgsm.c (_gpgme_gpgsm_op_keylist): Allow NULL for + pattern. + (gpgsm_assuan_simple_command): Removed underscore from + assuan_write_line. + (_gpgme_gpgsm_start): Ditto. + (gpgsm_assuan_simple_command): Replaced interal Assuan read + function by the new assuan_read_line. Removed the use of the + internal header. + (gpgsm_status_handler): Ditto. Use the new assuan_pending_line. + (_gpgme_gpgsm_start): Use the documented way to get an fd from + assuan. + + * keylist.c (keylist_colon_handler): Handle "crt" records + * key.h (gpgme_key_s): Add an x509 flag. + * key.c (parse_x509_user_id): New. + (_gpgme_key_append_name): Handle x.509 names. + +2001-12-05 Marcus Brinkmann + + * engine-gpgsm.c (gpgsm_status_handler): Make it work with current + version of assuan. + +2001-12-05 Marcus Brinkmann + + * engine-gpgsm.c (gpgsm_set_fd): Accept one more argument OPT. + (_gpgme_gpgsm_op_encrypt): Pass armor argument to gpgsm_set_fd for + output descriptor. + (_gpgme_gpgsm_op_sign): Likewise. + +2001-12-05 Marcus Brinkmann + + * keylist.c (gpgme_op_keylist_next): Set pending to 0 if EOF + occurs. + +2001-11-26 Marcus Brinkmann + + * engine-gpgsm.c (_gpgme_gpgsm_op_sign): Fix stupid typo. + +2001-11-24 Marcus Brinkmann + + * engine-gpgsm.c (gpgsm_status_handler): Don't break if bsearch fails. + Deal with assuan read line returning more than one line (for now). + +2001-11-23 Marcus Brinkmann + + * engine-gpgsm.c (_gpgme_gpgsm_op_sign): Implement it according to + the current protocol definition. + +2001-11-23 Marcus Brinkmann + + * engine-gpgsm.c (_gpgme_gpgsm_new): Set CLOEXEC flag for parent + ends of the pipe. + +2001-11-22 Marcus Brinkmann + + * engine-gpgsm.c: Include stdlib.h and string.h. Also include, + for now, rungpg.h and status-table.h. + (gpgsm_status_handler): Implement more of the status handler. + +2001-11-22 Marcus Brinkmann + + * engine.c (_gpgme_engine_op_decrypt): Implement CMS case. + (_gpgme_engine_op_delete): Likewise. + (_gpgme_engine_op_encrypt): Likewise. + (_gpgme_engine_op_export): Likewise. + (_gpgme_engine_op_genkey): Likewise. + (_gpgme_engine_op_keylist): Likewise. + (_gpgme_engine_op_sign): Likewise. + (_gpgme_engine_op_trustlist): Likewise. + + * engine-gpgsm.c (_gpgme_gpgsm_op_encrypt): New function. + (gpgsm_assuan_simple_command): Likewise. + (gpgsm_set_recipients): Likewise. + (gpgsm_set_fd): Reimplement using gpgsm_assuan_simple_command. + (_gpgme_gpgsm_op_delete): New function. + (_gpgme_gpgsm_op_export): Likewise. + (_gpgme_gpgsm_op_genkey): Likewise. + (_gpgme_gpgsm_op_sign): Likewise. + (_gpgme_gpgsm_op_keylist): Likewise. + (_gpgme_gpgsm_op_trustlist): Likewise. + (_gpgme_gpgsm_release): Release command. + (_gpgme_gpgsm_op_decrypt): Allocate command. + (_gpgme_gpgsm_op_import): Likewise. + (gpgsm_status_handler): Also treat `ERR' strings as EOF. + +2001-11-22 Marcus Brinkmann + + * gpgme.h (gpgme_set_protocol): New prototype. + +2001-11-22 Marcus Brinkmann + + * engine-gpgsm.c (_gpgme_gpgsm_op_decrypt): New function. + (_gpgme_gpgsm_op_import): Likewise. + +2001-11-22 Marcus Brinkmann + + * engine-gpgsm.c: Shuffle around header inclusion a bit, to still + keep them seperate. + (_gpgme_set_status_handler) [!ENABLE_GPGSM]: New function. + +2001-11-22 Werner Koch + + * engine-gpgsm.c: Include more headers so that NULL and mk_error + is defined even with an undefined GPGSM_PATH. + +2001-11-22 Marcus Brinkmann + + * rungpg.c (gpg_inbound_handler, write_mem_data, write_cb_data, + gpg_outbound_handler): Moved to ... + * data.c (_gpgme_data_inbound_handler, write_mem_data, + write_cb_data, _gpgme_data_outbound_handler): ... here. Make the + _gpgme_* ones non-static. + * data.c: Include io.h. + + * ops.h (_gpgme_data_inbound_handler): New prototype. + (_gpgme_data_outbound_handler): Likewise. + (_gpgme_gpg_spawn): Use these new functions. + + * engine-gpgsm.h (_gpgme_gpgsm_op_decrypt, _gpgme_gpgsm_op_delete, + _gpgme_gpgsm_op_encrypt, _gpgme_gpgsm_op_export, + _gpgme_gpgsm_op_genkey, _gpgme_gpgsm_op_import, + _gpgme_gpgsm_op_keylist, _gpgme_gpgsm_op_sign, + _gpgme_gpgsm_op_trustlist, _gpgme_gpgsm_op_verify, + _gpgme_gpgsm_start, _gpgme_gpgsm_set_status_handler): New prototype. + Include for status handler function. + + * engine-gpgsm.c (struct gpgsm_object_s): New members input_fd, + input_data, output_fd, output_data, message_fd, message_data, command + and status. + (_gpgme_gpgsm_new): Open input, output and message pipes before + connecting to the client. Close server's ends afterwards. + (_gpgme_gpgsm_release): Close open file descriptors. Remove + server process from wait queue. + (_gpgme_gpgsm_op_verify, _gpgme_gpgsm_start, + _gpgme_gpgsm_set_status_handler, gpgms_status_handler): New function. + + * engine.c (_gpgme_engine_start): Implement for GPGME_PROTOCOL_CMS. + (_gpgme_engine_set_status_handler): Likewise. + (_gpgme_engine_op_verify): Likewise. + +2001-11-21 Marcus Brinkmann + + * context.h: Do not include rungpg.h, but engine.h. + (struct gpgme_context_s): Replace member gpg with engine. + * gpgme.c (gpgme_release): Release engine, not gpg. + + * recipient.c (_gpgme_append_gpg_args_from_recifgpients): Function + moved ... + * rungpg.c (_gpgme_append_gpg_args_from_recipients): ... here. + Make static, change order of arguments, and return an error value. + * ops.h (_gpgme_append_gpg_args_from_recipients): Removed prototype. + + * rungpg.h (_gpgme_gpg_op_verify): Add prototype. + (_gpgme_gpg_op_encrypt): Likewise. + (_gpgme_gpg_op_decrypt): Likewise. + (_gpgme_gpg_op_delete): Likewise. + (_gpgme_gpg_op_export): Likewise. + (_gpgme_gpg_op_genkey): Likewise. + (_gpgme_gpg_op_import): Likewise. + (_gpgme_gpg_op_keylist): Likewise. + (_gpgme_gpg_op_sign): Likewise. + (_gpgme_gpg_op_trustlist): Likewise. + * rungpg.c (_gpgme_gpg_op_verify): New function. + (_gpgme_gpg_op_encrypt): Likewise. + (_gpgme_gpg_op_decrypt): Likewise. + (_gpgme_gpg_op_delete): Likewise. + (_gpgme_gpg_op_export): Likewise. + (_gpgme_gpg_op_genkey): Likewise. + (_gpgme_gpg_op_import): Likewise. + (_gpgme_gpg_op_keylist): Likewise. + (_gpgme_gpg_op_sign): Likewise. + (_gpgme_gpg_op_trustlist): Likewise. + + * engine.h (_gpgme_engine_set_status_handler): Add prototype. + (_gpgme_engine_set_command_handler): Likewise. + (_gpgme_engine_set_colon_line_handler): Likewise. + (_gpgme_engine_op_decrypt): Likewise. + (_gpgme_engine_op_delete): Likewise. + (_gpgme_engine_op_encrypt): Likewise. + (_gpgme_engine_op_export): Likewise. + (_gpgme_engine_op_genkey): Likewise. + (_gpgme_engine_op_import): Likewise. + (_gpgme_engine_op_keylist): Likewise. + (_gpgme_engine_op_sign): Likewise. + (_gpgme_engine_op_trustlist): Likewise. + (_gpgme_engine_op_verify): Likewise. + (_gpgme_engine_start): Likewise. + * engine.c (_gpgme_engine_set_status_handler): New function. + (_gpgme_engine_set_command_handler): Likewise. + (_gpgme_engine_set_colon_line_handler): Likewise. + (_gpgme_engine_op_decrypt): Likewise. + (_gpgme_engine_op_delete): Likewise. + (_gpgme_engine_op_encrypt): Likewise. + (_gpgme_engine_op_export): Likewise. + (_gpgme_engine_op_genkey): Likewise. + (_gpgme_engine_op_import): Likewise. + (_gpgme_engine_op_keylist): Likewise. + (_gpgme_engine_op_sign): Likewise. + (_gpgme_engine_op_trustlist): Likewise. + (_gpgme_engine_op_verify): Likewise. + (_gpgme_engine_start): Likewise. + + * verify.c (gpgme_op_verify_start): Reimplement in terms of above + functions. + * encrypt.c (gpgme_op_encrypt_start): Likewise. + * decrypt.c (_gpgme_decrypt_start): Likewise. + * passphrase.c (_gpgme_passphrase_start): Likewise. + * keylist.c (gpgme_op_keylist_start): Likewise. + +2001-11-20 Marcus Brinkmann + + * types.h: Add types EngineObject and GpgsmObject. + + * Makefile.am (libgpgme_la_SOURCES): Add engine-gpgsm.h, + engine-gpgsm.c, engine.h and engine.c. + * engine.h: New file. + * engine.c: Likewise. + * engine-gpgsm.h: Likewise. + * engine-gpgsm.c: Likewise. + + * rungpg.c (_gpgme_gpg_get_version): New function. + (_gpgme_gpg_check_version): Likewise. + * rungpg.h: Add prototypes for _gpgme_gpg_get_version and + _gpgme_gpg_check_version. + + * version.c (compare_versions): Rename to ... + (_gpgme_compare_versions): ... this. Make non-static. + (gpgme_check_version): Use _gpgme_compare_versions rather than + compare_versions. + (gpgme_check_engine): Likewise. + * ops.h (_gpgme_get_program_version): Add prototype. + +2001-11-20 Marcus Brinkmann + + * Makefile.am (libgpgme_la_INCLUDES): Remove obsolete directive. + (AM_CPPFLAGS): New directive [BUILD_ASSUAN]. + (libgpgme_la_LIBADD): Likewise. + +2001-11-20 Marcus Brinkmann + + * version.c: Remove global variables lineno and + tmp_engine_version. + (version_handler): Removed. + (_gpgme_get_program_version): New function. + (get_engine_info): Don't use context and version_handler, + but _gpgme_get_program_version. + * ops.h (_gpgme_get_program_version): Add prototype for + _gpgme_get_program_version (we expect to use it elsewhere soon). + +2001-11-18 Marcus Brinkmann + + * version.c (get_engine_info): If GnuPG is not available, return + an error message. + * posix-util.c (_gpgme_get_gpg_path): Allow GPG_PATH to be + undefined. + (_gpgme_get_gpgsm_path): New function. + * w32-util.c (find_program_in_registry): New static function. + (_gpgme_get_gpg_path): Allow GPG_PATH to be undefined. Rework + to use find_program_in_registry. + (_gpgme_get_gpgsm_path): New function. + (util.h): Prototype _gpgme_get_gpgsm_path). + * rungpg.c (_gpgme_gpg_spawn): Verify that _gpgme_get_gpg_path() + returns non-null. + +2001-11-16 Marcus Brinkmann + + * decrypt-verify.c: New file. + * Makefile.am (libgpgme_la_SOURCES): Add decrypt-verify.c. + * types.h: Add decrypt-verify types. + * ops.h: Likewise. + * context.h: Add result type for decrypt-verify. + * gpgme.h: Add decrypt-verify prototypes. + + * decrypt.c (decrypt_status_handler): Renamed to ... + (_gpgme_decrypt_status_handler): ... this. Make non-static. + (_gpgme_decrypt_start): New function, derived from + gpgme_op_decrypt_start. + (gpgme_op_decrypt_start): Reimplement in terms of + _gpgme_decrypt_start. + (_gpgme_decrypt_result): New function to retrieve error value. + (gpgme_op_decrypt): Use _gpgme_decrypt_result. + * ops.h: Add prototypes for new functions. + + * verify.c (verify_status_handler): Renamed to ... + (_gpgme_verify_status_handler): ... this. Make non-static. + (gpgme_op_verify_start): Use new function name. + (intersect_stati): Renamed to ... + (_gpgme_intersect_stati): ... this. Make non-static. + (gpgme_op_verify): Use new name. + * ops.h: Add prototypes for new functions. + +2001-11-16 Marcus Brinkmann + + * passphrase.c: New file. + * Makefile.am (libgpgme_la_SOURCES): Add passphrase.c. + * ops.h (_gpgme_passphrase_result): Add prototypes from + passphrase.c. + * types.h: Likewise. + * context.h: Add member passphrase to result. + * gpgme.c (_gpgme_release_result): Release passphrase member. + + * decrypt.c: Some formatting and variable name changes (like + CTX instead C). + (struct decrypt_result_s): Remove members now found in + passphrase result. + (_gpgme_release_decrypt_result): Don't release removed members. + (decrypt_status_handler): Call _gpgme_passphrase_status_handler, + and don't handle the cases catched there. + (command_handler): Removed. + (gpgme_op_decrypt_start): Don't set command handler, but invoke + _gpgme_passphrase_start which does it. + (gpgme_op_decrypt): Invoke _gpgme_passphrase_result and drop the + cases covered by it. + + * sign.c Some formatting and variable name changes (like + CTX instead C). + (struct sign_result_s): Remove members now found in + passphrase result. + (_gpgme_release_sign_result): Don't release removed members. + (sign_status_handler): Call _gpgme_passphrase_status_handler, + and don't handle the cases catched there. + (command_handler): Removed. + (gpgme_op_sign_start): Don't set command handler, but invoke + _gpgme_passphrase_start which does it. + (gpgme_op_sign): Invoke _gpgme_passphrase_result and drop the + cases covered by it. + +2001-11-15 Marcus Brinkmann + + * decrypt.c (command_handler): Fix last change. + +2001-11-15 Marcus Brinkmann + + * verify.c (_gpgme_release_verify_result): Rename RES to RESULT. + Rename R2 to NEXT_RESULT. + (intersect_stati): Rename RES to RESULT. + (gpgme_get_sig_status): Likewise. Do not check return_type, but + the member verify of result. + (gpgme_get_sig_key): Likewise. + + * sign.c (_gpgme_release_sign_result): Rename RES to RESULT. If + RESULT is zero, return. + (sign_status_handler, command_handler): Do not check return_type, + but the member sign of result. + (gpgme_op_sign): Likewise. Drop assertion. + + * encrypt.c (_gpgme_release_encrypt_result): Rename RES to RESULT. + If RESULT is zero, return. + (encrypt_status_handler): Do not check return_type, but the member + encrypt of result. + (gpgme_op_encrypt): Likewise. Drop assertion. + + * decrypt.c (_gpgme_release_decrypt_result): Rename RES to RESULT. + (create_result_struct): Do not set result_type. + (command_handler, decrypt_status_handler): Do not check + return_type, but the member decrypt of result. + (gpgme_op_decrypt): Likewise. Drop assertion. + + * context.h (enum ResultType): Removed. + (struct gpgme_context_s): Remove member result_type. + (struct result): Replaces union result. + * gpgme.c: Include string.h. + (_gpgme_release_result): Release all members of c->result, which + is now a struct. Zero out all members of the struct afterwards. + +2001-11-11 Marcus Brinkmann + + * rungpg.c (_gpgme_gpg_release): Release GPG->cmd.cb_data. + Release all members of the list GPG->arglist. + Reported by Michael Schmidt . + +2001-11-02 Marcus Brinkmann + + * rungpg.c (pipemode_copy): Change type of NBYTES to size_t. + + * key.c: Include string.h. + * data.c: Likewise. + * recipient.c: Likewise. + +2001-10-29 Marcus Brinkmann + + * context.h: New member signers_len. + * signers.c (gpgme_signers_clear): Require that signers are + non-NULL with assertion. Use signers_len to determine how much + keys to release. Add documentation. + (gpgme_signers_add): Use signers_len to determine if the buffer is + large enough. Use xtryrealloc rather than xtrymalloc and copying. + Add documentation. + (gpgme_signers_enum): Use signers_len to determine if key is + available. Add documentation. + +2001-10-22 Marcus Brinkmann + + * data.c (_gpgme_data_append): Check if LENGTH is smaller than + ALLOC_CHUNK, not DH->length. + +2001-10-17 Marcus Brinkmann + + * gpgme.c (gpgme_set_protocol): Fix last change. + +2001-10-15 Werner Koch + + * gpgme.h (GpgmeProtocol): New. + * gpgme.c (gpgme_set_protocol): New. + +2001-09-26 Werner Koch + + * gpgme.c (gpgme_set_passphrase_cb): Ignore a NULL context. + (gpgme_set_progress_cb): Ditto. Suggested by Mark Mutz. + +2001-09-17 Werner Koch + + * keylist.c (finish_key): Shortcut for no tmp_key. Changed all + callers to use this function without a check for tmp_key. + + * keylist.c (gpgme_op_keylist_next): Reset the key_cond after + emptying the queue. Bug reported by Stéphane Corthésy. + +2001-09-12 Werner Koch + + * data.c (gpgme_data_rewind): Allow rewind for callbacks. + +2001-09-07 Werner Koch + + * rungpg.h: Add NO_RECP. + * encrypt.c (encrypt_status_handler): Take on No_RECP. + (gpgme_op_encrypt): Better error return. + + * verify.c (verify_status_handler): Take on NODATA. + +2001-09-03 Werner Koch + + * rungpg.h: Added STATUS_INV_RECP. + * gpgme.c (_gpgme_release_result): Add support for new + EncryptResult object. + * encrypt.c (append_xml_encinfo): New. + (encrypt_status_handler): Add some status parsing. + (_gpgme_release_encrypt_result): New. + +2001-08-29 Werner Koch + + * recipient.c (gpgme_recipients_release): Free the list. By Timo. + + * keylist.c (keylist_colon_handler): Do a finish key if we receive + an EOF here. This is probably the reason for a lot of bugs + related to keylisting. It is so obvious. Kudos to Enno Cramer + for pointing that out. + +2001-08-28 Werner Koch + + * gpgme.c, gpgme.h (gpgme_get_op_info): New. + (_gpgme_set_op_info): New. + (_gpgme_release_result): Reset the op_info here. + * sign.c (append_xml_siginfo): New. + (sign_status_handler): Store the sig create information. + +2001-07-31 Werner Koch + + * encrypt.c (gpgme_op_encrypt): Hack to detect no valid recipients. + +2001-07-30 Werner Koch + + * gpgme.c (gpgme_get_armor,gpgme_get_textmode): New. + + * rungpg.c (build_argv): Disable armor comments + * w32-io.c (build_commandline): Need to add quotes here + +2001-07-24 Werner Koch + + * data.c (gpgme_data_read): Add a a way to return the available bytes. + +2001-07-23 Werner Koch + + * util.c: Removed stpcpy() because we use the version from jnlib. + +2001-07-19 Werner Koch + + * mkstatus: Define the collating sequence for sort. + +2001-06-26 Werner Koch + + * rungpg.h: Add STATUS_UNEXPECTED as suggested by Timo. + +2001-06-15 Werner Koch + + * keylist.c (set_userid_flags): Fixed the assigned values. Kudos + to Timo for pointing this out. + +2001-06-01 Werner Koch + + * debug.c (_gpgme_debug_begin): Fixed a /tmp race. Noted by + Johannes Poehlmann. + +2001-05-28 Werner Koch + + * version.c (gpgme_check_engine): Stop version number parsing at + the opening angle and not the closing one. By Tommy Reynolds. + +2001-05-01 José Carlos García Sogo + + * encrypt.c (gpgme_op_encrypt_start): Deleted the assert ( !c->gpg ) + line, because it gave an error if another operation had been made + before using the same context. + + * decrypt.c (gpgme_op_decrypt_start): The same as above. Also added + one line to release the gpg object in the context (if any). + +2001-04-26 Werner Koch + + * key.c, key.h (_gpgme_key_cache_init): New. + (_gpgme_key_cache_add): New. + (_gpgme_key_cache_get): New. + * version.c (do_subsystem_inits): Init the cache. + * keylist.c (finish_key): Put key into the cache + * verify.c (gpgme_get_sig_key): First look into the cache. + +2001-04-19 Werner Koch + + * keylist.c (parse_timestamp): Adjusted for the changed + --fixed-list-mode of gpg 1.0.4h. + +2001-04-05 Werner Koch + + * verify.c (gpgme_op_verify_start): Enabled pipemode for detached sigs. + +2001-04-04 Werner Koch + + * w32-io.c (_gpgme_io_select): Don't select on the writer if there + are still bytes pending. Timo found this not easy to track down + race condition. + +2001-04-02 Werner Koch + + * gpgme.h: Add GPGME_ATTR_KEY_{EXPIRED,DISABLED}. + * key.c (gpgme_key_get_ulong_attr): And return those attribs. + + * verify.c (gpgme_get_sig_key): Set keyliosting mode depending on + the mode set in the current context. Suggested by Timo. + + * key.c (gpgme_key_get_ulong_attr): Return can_certify and not + can_encrypt. By Timo. + +2001-03-30 Werner Koch + + * debug.c (debug_init): Allow to specify a debug file. + (_gpgme_debug_level): New. + + * posix-io.c (_gpgme_io_read, _gpgme_io_write): Print output. + (_gpgme_io_select): Debug only with level > 2. + +2001-03-15 Werner Koch + + * rungpg.c: Included time.h. + + * key.h: New keyflags for capabilities. + * keylist.c (set_mainkey_capability, set_subkey_capability): New. + (keylist_colon_handler): Parse them. + * gpgme.h: New attribute values for capabilties. + * key.c (gpgme_key_get_string_attr): Return them. + (capabilities_to_string): New. + (gpgme_key_get_ulong_attr): Return the global caps. + +2001-03-14 Werner Koch + + * w32-io.c (destroy_reader,destroy_writer): Fixed syntax error. + Thanks to Jan Oliver Wagner. + +2001-03-13 Werner Koch + + * context.h: Add invalid and revoke flags to user_id structure. + * keylist.c (gpgme_op_keylist_start): Use --fixed-list-mode. + (keylist_colon_handler): Adjust for that. + (set_userid_flags): New. + (set_mainkey_trust_info): Handle new key invalid flag + (set_subkey_trust_info): Ditto. + * gpgme.h: Add new attributes for key and user ID flags. + * key.c (_gpgme_key_append_name): Init these flags + (gpgme_key_get_as_xml): Print them. + (one_uid_as_xml): New helper for above. + (gpgme_key_get_string_attr, gpgme_key_get_ulong_attr): + Return the new attributes. Enhanced, so that subkey information + can be returned now. + +2001-02-28 Werner Koch + + * w32-io.c (destroy_reader): Set stop_me flag. + (writer,create_writer,destroy_writer,find_writer,kill_writer): New. + (_gpgme_io_write): Use a writer thread to avaoid blocking. + (_gpgme_io_close): Cleanup a writer thread + (_gpgme_io_select): Repalce tthe faked wait on writing by a real + waiting which is now possible due to the use of a writer thread. + +2001-02-20 Werner Koch + + * w32-io.c (destroy_reader,kill_reader): New. + (create_reader, reader): Add a new event to stop the thread. + (_gpgme_io_close): Kill the reader thread. + + * posix-io.c (_gpgme_io_select): Handle frozen fds here. + * 32-io.c (_gpgme_io_select): Ditto. Removed a bunch of unused code. + + * wait.c: Reworked the whole thing. + * rungpg.c (_gpgme_gpg_new): Init pid to -1. + (_gpgme_gpg_release): Remove the process from the wait queue. + +2001-02-19 Werner Koch + + * w32-io.c (_gpgme_io_set_close_notify): New. + (_gpgme_io_close): Do the notification. + + * posix-io.c (_gpgme_io_select): Use a 1 sec timeout and not 200 + microseconds. + + * wait.c (remove_process): Don't close the fd here. + (do_select): Set the fd to -1 and remove the is_closed flag everywhere. + (_gpgme_wait_on_condition): Remove the assert on the queue and + break out if we could not find the queue. The whole thing should + be reworked. + + * posix-io.c (_gpgme_io_set_close_notify): New. + (_gpgme_io_close): Do the notification. + + * rungpg.c (close_notify_handler): New. + (_gpgme_gpg_new): Register a callback for the fd. + (_gpgme_gpg_set_colon_line_handler): Ditto. + (build_argv): Ditto + +2001-02-13 Werner Koch + + * rungpg.c (struct reap_s): Replaced pid_t by int. + + * types.h: Add ulong typedef. + + * rungpg.c (do_reaping,_gpgme_gpg_housecleaning): New. + (_gpgme_gpg_release): Reap children. + * io.h, posix-io.c (_gpgme_io_kill): New. + * w32-io.c (_gpgme_io_kill): New (dummy). + + * keylist.c (gpgme_op_keylist_start): Cancel a pending request. + + * posix-io.c (_gpgme_io_read): Add some debug output. + (_gpgme_io_write): Ditto. + (_gpgme_io_select): Increased the timeout. + +2001-02-12 Werner Koch + + Enhanced the signature verification, so that it can how handle + more than one signature and is able to return more information on + the signatures. + * verify.c (gpgme_get_sig_key): New. + (gpgme_get_sig_status): New. + + * gpgme.h: Add stdio.h. + (GpgmeSigStat): New status DIFF. + +2001-02-01 Werner Koch + + * w32-io.c (set_synchronize): Add EVENT_MODIFY_STATE. Add Debug + code to all Set/ResetEvent(). + + * rungpg.c (read_status): Check for end of stream only if we have + an r. By Timo. + +2001-01-31 Werner Koch + + * wait.c (_gpgme_wait_on_condition): Removed all exit code processing. + (propagate_term_results,clear_active_fds): Removed. + (count_active_fds): Renamed to .. + (count_active_and_thawed_fds): .. this and count only thawed fds. + + * rungpg.c (gpg_colon_line_handler): Return colon.eof and not + status.eof ;-) + +2001-01-30 Werner Koch + + * w32-io.c (_gpgme_io_spawn): Use the supplied path arg. + + * version.c (get_engine_info): Return better error information. + + * posix-util.c, w32-util.c: New. + (_gpgme_get_gpg_path): New, suggested by Jan-Oliver. + * rungpg.c (_gpgme_gpg_spawn): Use new function to get GPG's path. + + * signers.c (gpgme_signers_add): Ooops, one should test code and + not just write it; the newarr was not assigned. Thanks to José + for pointing this out. Hmmm, still not tested, why shoudl a coder + test his fix :-) + + * w32-io.c: Does now use reader threads, so that we can use + WaitForMultipleObjects. + * sema.h, posix-sema.c, w32-sema.c: Support for Critcial sections. + Does currently only work for W32. + + * debug.c, util.h : New. Changed all fprintfs to use this new + set of debugging functions. + +2001-01-23 Werner Koch + + * data.c (_gpgme_data_release_and_return_string): Fixed string + termination. + +2001-01-22 Werner Koch + + * delete.c: New. + + * signers.c: New. + * key.c (gpgme_key_ref, gpgme_key_unref): New. + * sign.c (gpgme_op_sign_start): Allow the use of other keys. + + * version.c (gpgme_get_engine_info,gpgme_check_engine): New. + * rungpg.c (_gpgme_gpg_set_simple_line_handler): New. + +2001-01-05 Werner Koch + + * data.c (gpgme_data_rewind): Allow to rewind data_type_none. + + + Copyright 2001, 2002 g10 Code GmbH + + This file is free software; as a special exception the author gives + unlimited permission to copy and/or distribute it, with or without + modifications, as long as this notice is preserved. + + This file is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, to the extent permitted by law; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + diff --git a/tags/V0-3-4/gpgme/Makefile.am b/tags/V0-3-4/gpgme/Makefile.am new file mode 100644 index 0000000..aa6ef83 --- /dev/null +++ b/tags/V0-3-4/gpgme/Makefile.am @@ -0,0 +1,70 @@ +# Copyright (C) 2000 Werner Koch (dd9jn) +# Copyright (C) 2001, 2002 g10 Code GmbH +# +# This file is part of GPGME. +# +# GPGME is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# GPGME is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +## Process this file with automake to produce Makefile.in + +EXTRA_DIST = gpgme-config.in gpgme.m4 mkerrors mkstatus +BUILT_SOURCES = errors.c status-table.h +MOSTLYCLEANFILES = errors.c status-table.h +bin_SCRIPTS = gpgme-config +m4datadir = $(datadir)/aclocal +m4data_DATA = gpgme.m4 +include_HEADERS = gpgme.h +lib_LTLIBRARIES = libgpgme.la + +libgpgme_la_LDFLAGS = -version-info \ + @LIBGPGME_LT_CURRENT@:@LIBGPGME_LT_REVISION@:@LIBGPGME_LT_AGE@ +if BUILD_ASSUAN +AM_CPPFLAGS = -I$(top_srcdir)/assuan +libgpgme_la_LIBADD = ../assuan/libassuan.a ../jnlib/libjnlib.a +endif + +libgpgme_la_SOURCES = \ + gpgme.h types.h \ + util.h util.c posix-util.c w32-util.c \ + context.h ops.h \ + data.c recipient.c signers.c \ + wait.c wait.h \ + encrypt.c \ + encrypt-sign.c \ + decrypt.c \ + decrypt-verify.c \ + verify.c \ + sign.c \ + passphrase.c \ + progress.c \ + key.c key.h \ + keylist.c \ + trustlist.c \ + import.c \ + export.c \ + genkey.c \ + delete.c \ + rungpg.c rungpg.h status-table.h \ + engine-gpgsm.c engine-gpgsm.h \ + engine.c engine.h \ + sema.h posix-sema.c w32-sema.c \ + syshdr.h io.h posix-io.c w32-io.c \ + gpgme.c debug.c version.c errors.c + +errors.c : gpgme.h + $(srcdir)/mkerrors < $(srcdir)/gpgme.h > errors.c + +status-table.h : rungpg.h + $(srcdir)/mkstatus < $(srcdir)/rungpg.h > status-table.h diff --git a/tags/V0-3-4/gpgme/context.h b/tags/V0-3-4/gpgme/context.h new file mode 100644 index 0000000..8ecdaf1 --- /dev/null +++ b/tags/V0-3-4/gpgme/context.h @@ -0,0 +1,151 @@ +/* context.h + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef CONTEXT_H +#define CONTEXT_H + +#include "gpgme.h" +#include "types.h" +#include "engine.h" + +struct key_queue_item_s { + struct key_queue_item_s *next; + GpgmeKey key; +}; +struct trust_queue_item_s { + struct trust_queue_item_s *next; + GpgmeTrustItem item; +}; + + +/* Currently we need it at several places, so we put the definition + * into this header file */ +struct gpgme_context_s +{ + int initialized; + /* A gpg request is still pending. */ + int pending; + + int use_cms; + + /* At some points we need to remember an error which we can't report + immediately. */ + GpgmeError error; + /* Cancel operation requested. */ + int cancel; + + /* The running engine process. */ + EngineObject engine; + + /* Level of verbosity to use. */ + int verbosity; + int use_armor; + int use_textmode; + int keylist_mode; + int include_certs; + + /* The number of keys in signers. */ + int signers_len; + /* Size of the following array. */ + int signers_size; + GpgmeKey *signers; + + struct + { + VerifyResult verify; + DecryptResult decrypt; + SignResult sign; + EncryptResult encrypt; + PassphraseResult passphrase; + ImportResult import; + DeleteResult delete; + GenKeyResult genkey; + } result; + + /* Last signature notation. */ + GpgmeData notation; + /* Last operation info. */ + GpgmeData op_info; + + /* Used by keylist.c. */ + GpgmeKey tmp_key; + /* Something new is available. */ + volatile int key_cond; + struct key_queue_item_s *key_queue; + struct trust_queue_item_s *trust_queue; + + GpgmePassphraseCb passphrase_cb; + void *passphrase_cb_value; + + GpgmeProgressCb progress_cb; + void *progress_cb_value; + + GpgmeData help_data_1; +}; + + +struct gpgme_data_s { + size_t len; + const char *data; + GpgmeDataType type; + GpgmeDataMode mode; + + int (*read_cb)( void *, char *, size_t, size_t *); + void *read_cb_value; + int read_cb_eof; + + size_t readpos; + size_t writepos; + size_t private_len; + char *private_buffer; +}; + +struct user_id_s { + struct user_id_s *next; + unsigned int revoked:1; + unsigned int invalid:1; + GpgmeValidity validity; + const char *name_part; /* all 3 point into strings behind name */ + const char *email_part; /* or to read-only strings */ + const char *comment_part; + char name[1]; +}; + +struct gpgme_recipients_s { + struct user_id_s *list; + int checked; /* wether the recipients are all valid */ +}; + + +#define fail_on_pending_request(c) \ + do { \ + if (!(c)) return GPGME_Invalid_Value; \ + if ((c)->pending) return GPGME_Busy; \ + } while (0) + +#define wait_on_request_or_fail(c) \ + do { \ + if (!(c)) return GPGME_Invalid_Value;\ + if (!(c)->pending) return GPGME_No_Request; \ + gpgme_wait ((c), 1); \ + } while (0) + +#endif /* CONTEXT_H */ diff --git a/tags/V0-3-4/gpgme/data.c b/tags/V0-3-4/gpgme/data.c new file mode 100644 index 0000000..911be5c --- /dev/null +++ b/tags/V0-3-4/gpgme/data.c @@ -0,0 +1,991 @@ +/* data.c + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "syshdr.h" + +#include "util.h" +#include "context.h" +#include "ops.h" +#include "io.h" + +/* When expanding an internal buffer, always extend it by ALLOC_CHUNK + bytes at a time. */ +#define ALLOC_CHUNK 1024 + + +/** + * gpgme_data_new: + * @r_dh: returns the new data object + * + * Create a new data object without any content. + * + * Return value: An error value or 0 on success + **/ +GpgmeError +gpgme_data_new (GpgmeData *r_dh) +{ + GpgmeData dh; + + if (!r_dh) + return mk_error (Invalid_Value); + *r_dh = NULL; + + dh = xtrycalloc (1, sizeof *dh); + if (!dh) + return mk_error (Out_Of_Core); + + dh->mode = GPGME_DATA_MODE_INOUT; + + *r_dh = dh; + return 0; +} + + +/** + * gpgme_data_new_from_mem: + * @r_dh: Returns a new data object. + * @buffer: Initialize with this. + * @size: Size of the buffer + * @copy: Flag wether a copy of the buffer should be used. + * + * Create a new data object and initialize with data from the memory. + * A @copy with value %TRUE creates a copy of the memory, a value of + * %FALSE uses the original memory of @buffer and the caller has to + * make sure that this buffer is valid until gpgme_data_release() is + * called. + * + * Return value: An error value or 0 for success. + **/ +GpgmeError +gpgme_data_new_from_mem (GpgmeData *r_dh, const char *buffer, size_t size, + int copy) +{ + GpgmeData dh; + GpgmeError err; + + if (!r_dh) + return mk_error (Invalid_Value); + *r_dh = NULL; + if (!buffer) + return mk_error (Invalid_Value); + + err = gpgme_data_new (&dh); + if (err) + return err; + + dh->type = GPGME_DATA_TYPE_MEM; + dh->len = size; + if (!copy) + dh->data = buffer; + else + { + dh->private_buffer = xtrymalloc (size); + if (!dh->private_buffer) + { + gpgme_data_release (dh); + return mk_error (Out_Of_Core); + } + dh->private_len = size; + memcpy (dh->private_buffer, buffer, size); + dh->data = dh->private_buffer; + dh->writepos = size; + } + + *r_dh = dh; + return 0; +} + + +/** + * gpgme_data_new_with_read_cb: + * @r_dh: returns the new data object + * @read_cb: callback function + * @read_cb_value: value passed to the callback function + * + * Create a new data object which is a wrapper around the callback function. + * The callback function is defined as: + * + * typedef int (*read_cb) (void *cb_value, + * char *buffer, + * size_t count, + * size_t *nread); + * + * + * The callback should return a maximium of @count bytes in @buffer + * and the number actually read in @nread. It may return 0 in @nread + * if there are no bytes currently available. To indicate EOF the + * function should return with an error code of %-1 and set @nread to + * 0. The callback may support passing %NULL for @buffer and @nread + * and %0 for count as an indication to reset its internal read + * pointer. + * + * Return value: An error value or 0 for success. + **/ +GpgmeError +gpgme_data_new_with_read_cb (GpgmeData *r_dh, + int (*read_cb) (void *,char *, size_t ,size_t *), + void *read_cb_value) +{ + GpgmeData dh; + GpgmeError err; + + if (!r_dh) + return mk_error (Invalid_Value); + *r_dh = NULL; + + if (!read_cb) + return mk_error (Invalid_Value); + + err = gpgme_data_new (&dh); + if (err) + return err; + + dh->type = GPGME_DATA_TYPE_CB; + dh->mode = GPGME_DATA_MODE_OUT; + dh->read_cb = read_cb; + dh->read_cb_value = read_cb_value; + + *r_dh = dh; + return 0; +} + + +/** + * gpgme_data_new_from_file: + * @r_dh: returns the new data object + * @fname: filename + * @copy: Flag, whether the file should be copied. + * + * Create a new data object and initialize it with the content of + * the file @file. If @copy is %True the file is immediately read in + * and closed. @copy of %False is not yet supportted. + * + * Return value: An error code or 0 on success. If the error code is + * %GPGME_File_Error, the OS error code is held in %errno. + **/ +GpgmeError +gpgme_data_new_from_file (GpgmeData *r_dh, const char *fname, int copy) +{ + GpgmeData dh; + GpgmeError err; + struct stat st; + FILE *fp; + + if (!r_dh) + return mk_error (Invalid_Value); + *r_dh = NULL; + if (!fname) + return mk_error (Invalid_Value); + + /* We only support copy for now. In future we might want to honor + the copy flag and just store a file pointer. */ + if (!copy) + return mk_error (Not_Implemented); + + err = gpgme_data_new (&dh); + if (err) + return err; + + fp = fopen (fname, "rb"); + if (!fp) + { + int save_errno = errno; + gpgme_data_release (dh); + errno = save_errno; + return mk_error (File_Error); + } + + if (fstat(fileno(fp), &st)) + { + int save_errno = errno; + fclose (fp); + gpgme_data_release (dh); + errno = save_errno; + return mk_error (File_Error); + } + + /* We should check the length of the file and don't allow for too + large files. */ + dh->private_buffer = xtrymalloc (st.st_size); + if (!dh->private_buffer) + { + fclose (fp); + gpgme_data_release (dh); + return mk_error (Out_Of_Core); + } + dh->private_len = st.st_size; + + while (fread (dh->private_buffer, dh->private_len, 1, fp) < 1 + && ferror (fp) && errno == EINTR); + + if (ferror (fp)) + { + int save_errno = errno; + fclose (fp); + gpgme_data_release (dh); + errno = save_errno; + return mk_error (File_Error); + } + + fclose (fp); + + dh->type = GPGME_DATA_TYPE_MEM; + dh->len = dh->private_len; + dh->data = dh->private_buffer; + dh->writepos = dh->len; + + *r_dh = dh; + return 0; +} + + +/** + * gpgme_data_new_from_filepart: + * @r_dh: returns the new data object + * @fname: filename + * @fp: filepointer + * @offset: Start reading at this offset + * @length: Read this many bytes + * + * Create a new data object and initialize it with @length bytes + * starting at @offset of @file or @fp. Either a filename or an open + * filepointer may be given. + * + * + * Return value: An error code or 0 on success. If the error code is + * %GPGME_File_Error, the OS error code is held in %errno. + **/ +GpgmeError +gpgme_data_new_from_filepart (GpgmeData *r_dh, const char *fname, FILE *fp, + off_t offset, size_t length) +{ + GpgmeData dh; + GpgmeError err; + int save_errno = 0; + + if (!r_dh) + return mk_error (Invalid_Value); + *r_dh = NULL; + + if ((fname && fp) || (!fname && !fp)) + return mk_error (Invalid_Value); + + err = gpgme_data_new (&dh); + if (err) + return err; + + if (!length) + goto out; + + if (fname) + { + fp = fopen (fname, "rb"); + if (!fp) + { + err = mk_error (File_Error); + goto out; + } + } + + if (fseek (fp, (long) offset, SEEK_SET)) + { + err = mk_error (File_Error); + goto out; + } + + dh->private_buffer = xtrymalloc (length); + if (!dh->private_buffer) + { + err = mk_error (Out_Of_Core); + goto out; + } + dh->private_len = length; + + while (fread (dh->private_buffer, dh->private_len, 1, fp) < 1 + && ferror (fp) && errno == EINTR); + + if (ferror (fp)) + { + err = mk_error (File_Error); + goto out; + } + + dh->type = GPGME_DATA_TYPE_MEM; + dh->len = dh->private_len; + dh->data = dh->private_buffer; + dh->writepos = dh->len; + + out: + if (err) + save_errno = errno; + + if (fname && fp) + fclose (fp); + + if (err) + { + gpgme_data_release (dh); + errno = save_errno; + } + else + *r_dh = dh; + return err; +} + + +/** + * gpgme_data_release: + * @dh: Data object + * + * Release the data object @dh. @dh may be NULL in which case nothing + * happens. + **/ +void +gpgme_data_release (GpgmeData dh) +{ + if (dh) + { + xfree (dh->private_buffer); + xfree (dh); + } +} + + +/* + * Release the data object @dh. @dh may be NULL in which case nothing + * happens. + * + * Return value: An allocated memory object with the content of the + * data object. The function makes sure that the returned string can + * safely be accessed using the string fucntions. + **/ +char * +_gpgme_data_release_and_return_string (GpgmeData dh) +{ + char *val = NULL; + + if (dh) + { + if (_gpgme_data_append (dh, "", 1)) /* append EOS */ + xfree (dh->private_buffer ); + else + { + val = dh->private_buffer; + if (!val && dh->data) + { + val = xtrymalloc (dh->len); + if (val) + memcpy (val, dh->data, dh->len); + } + } + xfree (dh); + } + return val; +} + + +/** + * gpgme_data_release_and_get_mem: + * @dh: the data object + * @r_len: returns the length of the memory + * + * Release the data object @dh and return its content and the length + * of that content. The caller has to free this data. @dh maybe NULL + * in which case NULL is returned. If there is not enough memory for + * allocating the return value, NULL is returned and the object is + * released. + * + * Return value: a pointer to an allocated buffer of length @r_len. + **/ +char * +gpgme_data_release_and_get_mem (GpgmeData dh, size_t *r_len) +{ + char *val = NULL; + + if (r_len) + *r_len = 0; + if (dh) + { + size_t len = dh->len; + val = dh->private_buffer; + if (!val && dh->data) + { + val = xtrymalloc (len); + if (val) + memcpy (val, dh->data, len); + } + xfree (dh); + if (val && r_len) + *r_len = len; + } + return val; +} + + +/** + * gpgme_data_get_type: + * @dh: the data object + * + * Get the type of the data object. + * Data types are prefixed with %GPGME_DATA_TYPE_ + * + * Return value: the data type + **/ +GpgmeDataType +gpgme_data_get_type (GpgmeData dh) +{ + if (!dh || (!dh->data && !dh->read_cb)) + return GPGME_DATA_TYPE_NONE; + + return dh->type; +} + + +void +_gpgme_data_set_mode (GpgmeData dh, GpgmeDataMode mode) +{ + assert (dh); + dh->mode = mode; +} + + +GpgmeDataMode +_gpgme_data_get_mode (GpgmeData dh) +{ + assert (dh); + return dh->mode; +} + + +/** + * gpgme_data_rewind: + * @dh: the data object + * + * Prepare the data object in a way, that a gpgme_data_read() does start + * at the beginning of the data. This has to be done for all types + * of data objects. + * + * Return value: An error code or 0 on success + **/ +GpgmeError +gpgme_data_rewind (GpgmeData dh) +{ + if (!dh) + return mk_error (Invalid_Value); + + switch (dh->type) + { + case GPGME_DATA_TYPE_NONE: + case GPGME_DATA_TYPE_MEM: + dh->readpos = 0; + return 0; + + case GPGME_DATA_TYPE_CB: + dh->len = dh->readpos = 0; + dh->read_cb_eof = 0; + if (dh->read_cb (dh->read_cb_value, NULL, 0, NULL)) + return mk_error (Not_Implemented); + return 0; + + default: + return mk_error (General_Error); + } +} + +/** + * gpgme_data_read: + * @dh: the data object + * @buffer: A buffer + * @length: The length of that bufer + * @nread: Returns the number of bytes actually read. + * + * Copy data from the current read position (which may be set by + * gpgme_data_rewind()) to the supplied @buffer, max. @length bytes + * are copied and the actual number of bytes are returned in @nread. + * If there are no more bytes available %GPGME_EOF is returned and @nread + * is set to 0. + * + * With a @buffer of NULL, the function does only return the number of + * bytes available and does not move the read pointer. This does only + * work for certain data types, all other will respond with an + * %GPGME_Invalid_Type. + * + * Return value: An error code or 0 on success, EOF is indcated by the + * error code GPGME_EOF. + **/ +GpgmeError +gpgme_data_read (GpgmeData dh, char *buffer, size_t length, size_t *nread) +{ + size_t nbytes; + + if (!dh) + return mk_error (Invalid_Value); + + switch (dh->type) + { + case GPGME_DATA_TYPE_MEM: + nbytes = dh->len - dh->readpos; + if (!nbytes) + { + *nread = 0; + return mk_error(EOF); + } + + if (!buffer) + *nread = nbytes; + else + { + if (nbytes > length) + nbytes = length; + memcpy (buffer, dh->data + dh->readpos, nbytes); + *nread = nbytes; + dh->readpos += nbytes; + } + return 0; + + case GPGME_DATA_TYPE_CB: + if (!buffer) + { + *nread = 0; + return mk_error (Invalid_Type); + } + nbytes = dh->len - dh->readpos; + if (nbytes) + { + /* We have unread data - return this. */ + if (nbytes > length) + nbytes = length; + memcpy (buffer, dh->data + dh->readpos, nbytes); + *nread = nbytes; + dh->readpos += nbytes; + } + else + { + /* Get the data from the callback. */ + if (!dh->read_cb || dh->read_cb_eof) + { + *nread = 0; + return mk_error (EOF); + } + if (dh->read_cb (dh->read_cb_value, buffer, length, nread)) + { + *nread = 0; + dh->read_cb_eof = 1; + return mk_error (EOF); + } + } + return 0; + + default: + return mk_error (General_Error); + } +} + + +GpgmeError +_gpgme_data_unread (GpgmeData dh, const char *buffer, size_t length) +{ + if (!dh) + return mk_error (Invalid_Value); + + if (dh->type == GPGME_DATA_TYPE_MEM) + { + /* Check that we don't unread more than we have yet read. */ + if (dh->readpos < length) + return mk_error (Invalid_Value); + /* No need to use the buffer for this data type. */ + dh->readpos -= length; + } + else + return mk_error (General_Error); + + return 0; +} + + +/* + * This function does make sense when we know that it contains no nil chars. + */ +char * +_gpgme_data_get_as_string (GpgmeData dh) +{ + char *val = NULL; + + if (dh) + { + val = xtrymalloc (dh->len+1); + if (val) + { + memcpy (val, dh->data, dh->len); + val[dh->len] = 0; + } + } + return val; +} + + +/** + * gpgme_data_write: + * @dh: the context + * @buffer: data to be written to the data object + * @length: length of this data + * + * Write the content of @buffer to the data object @dh at the current write + * position. + * + * Return value: 0 on success or an error code + **/ +GpgmeError +gpgme_data_write (GpgmeData dh, const char *buffer, size_t length) +{ + if (!dh || !buffer) + return mk_error (Invalid_Value); + + return _gpgme_data_append (dh, buffer, length ); +} + + +GpgmeError +_gpgme_data_append (GpgmeData dh, const char *buffer, size_t length) +{ + assert (dh); + + if (dh->type == GPGME_DATA_TYPE_NONE) + { + /* Convert it to a mem data type. */ + assert (!dh->private_buffer); + dh->type = GPGME_DATA_TYPE_MEM; + dh->private_len = length < ALLOC_CHUNK? ALLOC_CHUNK : length; + dh->private_buffer = xtrymalloc (dh->private_len); + if (!dh->private_buffer) + { + dh->private_len = 0; + return mk_error (Out_Of_Core); + } + dh->writepos = 0; + dh->data = dh->private_buffer; + } + else if (dh->type != GPGME_DATA_TYPE_MEM) + return mk_error (Invalid_Type); + + if (dh->mode != GPGME_DATA_MODE_INOUT + && dh->mode != GPGME_DATA_MODE_IN) + return mk_error (Invalid_Mode); + + if (!dh->private_buffer) + { + /* We have to copy it now. */ + assert (dh->data); + dh->private_len = dh->len+length; + if (dh->private_len < ALLOC_CHUNK) + dh->private_len = ALLOC_CHUNK; + dh->private_buffer = xtrymalloc (dh->private_len); + if (!dh->private_buffer) + { + dh->private_len = 0; + return mk_error (Out_Of_Core); + } + memcpy (dh->private_buffer, dh->data, dh->len); + dh->writepos = dh->len; + dh->data = dh->private_buffer; + } + + /* Allocate more memory if needed. */ + if (dh->writepos + length > dh->private_len) + { + char *p; + size_t newlen = dh->private_len + + (length < ALLOC_CHUNK? ALLOC_CHUNK : length); + p = xtryrealloc (dh->private_buffer, newlen); + if (!p) + return mk_error (Out_Of_Core); + dh->private_buffer = p; + dh->private_len = newlen; + dh->data = dh->private_buffer; + assert (!(dh->writepos + length > dh->private_len)); + } + + memcpy (dh->private_buffer + dh->writepos, buffer, length); + dh->writepos += length; + dh->len += length; + + return 0; +} + + +GpgmeError +_gpgme_data_append_string (GpgmeData dh, const char *s) +{ + return _gpgme_data_append (dh, s, s ? strlen(s) : 0); +} + + +GpgmeError +_gpgme_data_append_for_xml (GpgmeData dh, + const char *buffer, size_t len) +{ + const char *text, *s; + size_t n; + int rc = 0; + + if (!dh || !buffer) + return mk_error (Invalid_Value); + + do + { + for (text=NULL, s = buffer, n = len; n && !text; s++, n--) + { + if (*s == '<') + text = "<"; + else if (*s == '>') + text = ">"; /* Not sure whether this is really needed. */ + else if (*s == '&') + text = "&"; + else if (!*s) + text = "�"; + } + if (text) + { + s--; + n++; + } + if (s != buffer) + rc = _gpgme_data_append (dh, buffer, s-buffer); + if (!rc && text) + { + rc = _gpgme_data_append_string (dh, text); + s++; + n--; + } + buffer = s; + len = n; + } + while (!rc && len); + return rc; +} + + +/* + * Append a string to DATA and convert it so that the result will be + * valid XML. + */ +GpgmeError +_gpgme_data_append_string_for_xml (GpgmeData dh, const char *string) +{ + return _gpgme_data_append_for_xml (dh, string, strlen (string)); +} + + +static int +hextobyte(const byte *s) +{ + int c; + + if (*s >= '0' && *s <= '9') + c = 16 * (*s - '0'); + else if (*s >= 'A' && *s <= 'F') + c = 16 * (10 + *s - 'A'); + else if (*s >= 'a' && *s <= 'f') + c = 16 * (10 + *s - 'a'); + else + return -1; + s++; + if (*s >= '0' && *s <= '9') + c += *s - '0'; + else if (*s >= 'A' && *s <= 'F') + c += 10 + *s - 'A'; + else if (*s >= 'a' && *s <= 'f') + c += 10 + *s - 'a'; + else + return -1; + return c; +} + +/* + * Append a string with percent style (%XX) escape characters as XML. + */ +GpgmeError +_gpgme_data_append_percentstring_for_xml (GpgmeData dh, const char *string) +{ + const byte *s; + byte *buf, *d; + int val; + GpgmeError err; + + d = buf = xtrymalloc (strlen (string)); + for (s = string; *s; s++) + { + if (*s == '%' && (val = hextobyte (s+1)) != -1) + { + *d++ = val; + s += 2; + } + else + *d++ = *s; + } + + err = _gpgme_data_append_for_xml (dh, buf, d - buf); + xfree (buf); + return err; +} + +/* Functions to support the wait interface. */ + +int +_gpgme_data_inbound_handler (void *opaque, int pid, int fd) +{ + GpgmeData dh = opaque; + GpgmeError err; + int nread; + char buf[200]; + + assert (_gpgme_data_get_mode (dh) == GPGME_DATA_MODE_IN); + + nread = _gpgme_io_read (fd, buf, 200); + if (nread < 0) + { + DEBUG3 ("read_mem_data: read failed on fd %d (n=%d): %s", + fd, nread, strerror (errno) ); + return 1; + } + else if (!nread) + return 1; /* eof */ + + /* We could improve this with a GpgmeData function which takes + * the read function or provides a memory area for writing to it. + */ + + err = _gpgme_data_append (dh, buf, nread); + if (err) + { + DEBUG1 ("_gpgme_append_data failed: %s\n", + gpgme_strerror(err)); + /* Fixme: we should close the pipe or read it to /dev/null in + * this case. Returnin EOF is not sufficient */ + return 1; + } + + return 0; +} + +static int +write_mem_data (GpgmeData dh, int fd) +{ + size_t nbytes; + int nwritten; + + nbytes = dh->len - dh->readpos; + if (!nbytes) + { + _gpgme_io_close (fd); + return 1; + } + + /* FIXME: Arggg, the pipe blocks on large write request, although + * select told us that it is okay to write - need to figure out + * why this happens? Stevens says nothing about this problem (or + * is it my Linux kernel 2.4.0test1) + * To avoid that we have set the pipe to nonblocking. + */ + + nwritten = _gpgme_io_write (fd, dh->data+dh->readpos, nbytes); + if (nwritten == -1 && errno == EAGAIN) + return 0; + if (nwritten < 1) + { + DEBUG3 ("write_mem_data(%d): write failed (n=%d): %s", + fd, nwritten, strerror (errno)); + _gpgme_io_close (fd); + return 1; + } + + dh->readpos += nwritten; + return 0; +} + +static int +write_cb_data (GpgmeData dh, int fd) +{ + size_t nbytes; + int err, nwritten; + char buffer[512]; + + err = gpgme_data_read (dh, buffer, DIM(buffer), &nbytes); + if (err == GPGME_EOF) + { + _gpgme_io_close (fd); + return 1; + } + + nwritten = _gpgme_io_write (fd, buffer, nbytes); + if (nwritten == -1 && errno == EAGAIN ) + return 0; + if (nwritten < 1) + { + DEBUG3 ("write_cb_data(%d): write failed (n=%d): %s", + fd, nwritten, strerror (errno)); + _gpgme_io_close (fd); + return 1; + } + + if (nwritten < nbytes) + { + /* ugly, ugly: It does currently only for for MEM type data */ + if (_gpgme_data_unread (dh, buffer + nwritten, nbytes - nwritten)) + DEBUG1 ("wite_cb_data: unread of %d bytes failed\n", + nbytes - nwritten); + _gpgme_io_close (fd); + return 1; + } + + return 0; +} + +int +_gpgme_data_outbound_handler (void *opaque, int pid, int fd) +{ + GpgmeData dh = opaque; + + assert (_gpgme_data_get_mode (dh) == GPGME_DATA_MODE_OUT); + switch (gpgme_data_get_type (dh)) + { + case GPGME_DATA_TYPE_MEM: + if (write_mem_data (dh, fd)) + return 1; /* ready */ + break; + case GPGME_DATA_TYPE_CB: + if (write_cb_data (dh, fd)) + return 1; /* ready */ + break; + default: + assert (0); + } + + return 0; +} diff --git a/tags/V0-3-4/gpgme/debug.c b/tags/V0-3-4/gpgme/debug.c new file mode 100644 index 0000000..8770768 --- /dev/null +++ b/tags/V0-3-4/gpgme/debug.c @@ -0,0 +1,240 @@ +/* debug.c + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#ifndef HAVE_DOSISH_SYSTEM + #include + #include + #include +#endif +#include + +#include "util.h" +#include "sema.h" + +DEFINE_STATIC_LOCK (debug_lock); + +struct debug_control_s { + FILE *fp; + char fname[100]; +}; + +static int debug_level = 0; +static FILE *errfp = NULL; + +/**************** + * remove leading and trailing white spaces + */ +static char * +trim_spaces( char *str ) +{ + char *string, *p, *mark; + + string = str; + /* find first non space character */ + for( p=string; *p && isspace( *(byte*)p ) ; p++ ) + ; + /* move characters */ + for( (mark = NULL); (*string = *p); string++, p++ ) + if( isspace( *(byte*)p ) ) { + if( !mark ) + mark = string ; + } + else + mark = NULL ; + if( mark ) + *mark = '\0' ; /* remove trailing spaces */ + + return str ; +} + + +static void +debug_init (void) +{ + static volatile int initialized = 0; + + if (initialized) + return; + LOCK (debug_lock); + if (!initialized) { + const char *e = getenv ("GPGME_DEBUG"); + const char *s1, *s2;; + + initialized = 1; + debug_level = 0; + errfp = stderr; + if (e) { + debug_level = atoi (e); + s1 = strchr (e, ':'); + if (s1 +#ifndef HAVE_DOSISH_SYSTEM + && getuid () == geteuid () +#endif + ) { + char *p; + FILE *fp; + + s1++; + if ( !(s2 = strchr (s1, ':')) ) + s2 = s1 + strlen(s1); + p = xtrymalloc (s2-s1+1); + if (p) { + memcpy (p, s1, s2-s1); + p[s2-s1] = 0; + trim_spaces (p); + fp = fopen (p,"a"); + if (fp) { + setvbuf (fp, NULL, _IOLBF, 0); + errfp = fp; + } + xfree (p); + } + } + } + + if (debug_level > 0) + fprintf (errfp,"gpgme_debug: level=%d\n", debug_level); + } + UNLOCK (debug_lock); +} + +int +_gpgme_debug_level () +{ + return debug_level; +} + +void +_gpgme_debug (int level, const char *format, ...) +{ + va_list arg_ptr ; + + debug_init (); + if ( debug_level < level ) + return; + + va_start ( arg_ptr, format ) ; + LOCK (debug_lock); + vfprintf (errfp, format, arg_ptr) ; + va_end ( arg_ptr ) ; + if( format && *format && format[strlen(format)-1] != '\n' ) + putc ('\n', errfp); + UNLOCK (debug_lock); + fflush (errfp); +} + + + +void +_gpgme_debug_begin ( void **helper, int level, const char *text) +{ + struct debug_control_s *ctl; + + debug_init (); + + *helper = NULL; + if ( debug_level < level ) + return; + ctl = xtrycalloc (1, sizeof *ctl ); + if (!ctl) { + _gpgme_debug (255, __FILE__ ":" STR2(__LINE__)": out of core"); + return; + } + + /* Oh what a pitty that we don't have a asprintf or snprintf under + * Windoze. We definitely should write our own clib for W32! */ + sprintf ( ctl->fname, "/tmp/gpgme_debug.%d.%p", getpid (), ctl ); + #if defined (__GLIBC__) || defined (HAVE_DOSISH_SYSTEM) + ctl->fp = fopen (ctl->fname, "w+x"); + #else + { + int fd = open (ctl->fname, O_WRONLY|O_TRUNC|O_CREAT|O_EXCL, + S_IRUSR|S_IWUSR ); + if (fd == -1) + ctl->fp = NULL; + else + ctl->fp = fdopen (fd, "w+"); + } + #endif + if (!ctl->fp) { + _gpgme_debug (255,__FILE__ ":" STR2(__LINE__)": failed to create `%s'", + ctl->fname ); + xfree (ctl); + return; + } + *helper = ctl; + _gpgme_debug_add (helper, "%s", text ); +} + +int +_gpgme_debug_enabled (void **helper) +{ + return helper && *helper; +} + + +void +_gpgme_debug_add (void **helper, const char *format, ...) +{ + struct debug_control_s *ctl = *helper; + va_list arg_ptr ; + + if ( !*helper ) + return; + + va_start ( arg_ptr, format ) ; + vfprintf (ctl->fp, format, arg_ptr) ; + va_end ( arg_ptr ) ; +} + +void +_gpgme_debug_end (void **helper, const char *text) +{ + struct debug_control_s *ctl = *helper; + int c, last_c=EOF; + + if ( !*helper ) + return; + + _gpgme_debug_add (helper, "%s", text ); + fflush (ctl->fp); /* we need this for the buggy Windoze libc */ + rewind (ctl->fp); + LOCK (debug_lock); + while ( (c=getc (ctl->fp)) != EOF ) { + putc (c, errfp); + last_c = c; + } + if (last_c != '\n') + putc ('\n', errfp); + UNLOCK (debug_lock); + + fclose (ctl->fp); + remove (ctl->fname); + xfree (ctl); + *helper = NULL; +} + diff --git a/tags/V0-3-4/gpgme/decrypt-verify.c b/tags/V0-3-4/gpgme/decrypt-verify.c new file mode 100644 index 0000000..b309408 --- /dev/null +++ b/tags/V0-3-4/gpgme/decrypt-verify.c @@ -0,0 +1,80 @@ +/* decrypt-verify.c - decrypt and verify functions + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "util.h" +#include "context.h" +#include "ops.h" + + +static void +decrypt_verify_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args) +{ + _gpgme_decrypt_status_handler (ctx, code, args); + _gpgme_verify_status_handler (ctx, code, args); +} + + +GpgmeError +gpgme_op_decrypt_verify_start (GpgmeCtx ctx, GpgmeData ciph, GpgmeData plain) +{ + return _gpgme_decrypt_start (ctx, ciph, plain, + decrypt_verify_status_handler); +} + + +/** + * gpgme_op_decrypt_verify: + * @ctx: The context + * @in: ciphertext input + * @out: plaintext output + * + * This function decrypts @in to @out and performs a signature check. + * Other parameters are take from the context @c. + * The function does wait for the result. + * + * Return value: 0 on success or an errorcode. + **/ +GpgmeError +gpgme_op_decrypt_verify (GpgmeCtx ctx, + GpgmeData in, GpgmeData out, + GpgmeSigStat *r_stat) +{ + GpgmeError err; + + gpgme_data_release (ctx->notation); + ctx->notation = NULL; + + *r_stat = GPGME_SIG_STAT_NONE; + err = gpgme_op_decrypt_verify_start (ctx, in, out); + if (!err) + { + gpgme_wait (ctx, &err, 1); + if (!err) + *r_stat = _gpgme_intersect_stati (ctx->result.verify); + } + return err; +} diff --git a/tags/V0-3-4/gpgme/decrypt.c b/tags/V0-3-4/gpgme/decrypt.c new file mode 100644 index 0000000..7eacece --- /dev/null +++ b/tags/V0-3-4/gpgme/decrypt.c @@ -0,0 +1,165 @@ +/* decrypt.c - decrypt functions + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "util.h" +#include "context.h" +#include "ops.h" + + +struct decrypt_result_s +{ + int okay; + int failed; +}; + + +void +_gpgme_release_decrypt_result (DecryptResult result) +{ + if (!result) + return; + xfree (result); +} + + +void +_gpgme_decrypt_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args) +{ + _gpgme_passphrase_status_handler (ctx, code, args); + + if (ctx->error) + return; + test_and_allocate_result (ctx, decrypt); + + switch (code) + { + case STATUS_EOF: + if (ctx->result.decrypt->failed) + ctx->error = mk_error (Decryption_Failed); + else if (!ctx->result.decrypt->okay) + ctx->error = mk_error (No_Data); + break; + + case STATUS_DECRYPTION_OKAY: + ctx->result.decrypt->okay = 1; + break; + + case STATUS_DECRYPTION_FAILED: + ctx->result.decrypt->failed = 1; + break; + + default: + /* Ignore all other codes. */ + break; + } +} + + +GpgmeError +_gpgme_decrypt_start (GpgmeCtx ctx, GpgmeData ciph, GpgmeData plain, + void *status_handler) +{ + GpgmeError err = 0; + + fail_on_pending_request (ctx); + ctx->pending = 1; + + _gpgme_release_result (ctx); + + /* Create a process object. */ + _gpgme_engine_release (ctx->engine); + err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS + : GPGME_PROTOCOL_OpenPGP, &ctx->engine); + if (err) + goto leave; + + /* Check the supplied data. */ + if (!ciph || gpgme_data_get_type (ciph) == GPGME_DATA_TYPE_NONE) + { + err = mk_error (No_Data); + goto leave; + } + _gpgme_data_set_mode (ciph, GPGME_DATA_MODE_OUT); + + if (gpgme_data_get_type (plain) != GPGME_DATA_TYPE_NONE) + { + err = mk_error (Invalid_Value); + goto leave; + } + _gpgme_data_set_mode (plain, GPGME_DATA_MODE_IN); + + err = _gpgme_passphrase_start (ctx); + if (err) + goto leave; + + _gpgme_engine_set_status_handler (ctx->engine, status_handler, ctx); + _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); + + err = _gpgme_engine_op_decrypt (ctx->engine, ciph, plain); + + if (!err) /* And kick off the process. */ + err = _gpgme_engine_start (ctx->engine, ctx); + + leave: + if (err) + { + ctx->pending = 0; + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + return err; +} + + +GpgmeError +gpgme_op_decrypt_start (GpgmeCtx ctx, GpgmeData ciph, GpgmeData plain) +{ + return _gpgme_decrypt_start (ctx, ciph, plain, + _gpgme_decrypt_status_handler); +} + + +/** + * gpgme_op_decrypt: + * @ctx: The context + * @in: ciphertext input + * @out: plaintext output + * + * This function decrypts @in to @out. + * Other parameters are take from the context @ctx. + * The function does wait for the result. + * + * Return value: 0 on success or an errorcode. + **/ +GpgmeError +gpgme_op_decrypt (GpgmeCtx ctx, GpgmeData in, GpgmeData out) +{ + GpgmeError err = gpgme_op_decrypt_start (ctx, in, out); + if (!err) + gpgme_wait (ctx, &err, 1); + return err; +} diff --git a/tags/V0-3-4/gpgme/delete.c b/tags/V0-3-4/gpgme/delete.c new file mode 100644 index 0000000..9b2735a --- /dev/null +++ b/tags/V0-3-4/gpgme/delete.c @@ -0,0 +1,157 @@ +/* delete.c - delete a key + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include + +#include "util.h" +#include "context.h" +#include "ops.h" +#include "key.h" + + +enum delete_problem + { + DELETE_No_Problem = 0, + DELETE_No_Such_Key = 1, + DELETE_Must_Delete_Secret_Key = 2 + }; + + +struct delete_result_s +{ + enum delete_problem problem; +}; + + +void +_gpgme_release_delete_result (DeleteResult result) +{ + if (!result) + return; + xfree (result); +} + + +static void +delete_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args) +{ + if (ctx->error) + return; + test_and_allocate_result (ctx, delete); + + switch (code) + { + case STATUS_EOF: + switch (ctx->result.delete->problem) + { + case DELETE_No_Problem: + break; + case DELETE_No_Such_Key: + ctx->error = mk_error(Invalid_Key); + break; + case DELETE_Must_Delete_Secret_Key: + ctx->error = mk_error(Conflict); + break; + default: + ctx->error = mk_error(General_Error); + break; + } + break; + + case STATUS_DELETE_PROBLEM: + ctx->result.delete->problem = atoi (args); + break; + + default: + /* Ignore all other codes. */ + break; + } +} + + +GpgmeError +gpgme_op_delete_start (GpgmeCtx ctx, const GpgmeKey key, int allow_secret) +{ + GpgmeError err = 0; + + fail_on_pending_request (ctx); + ctx->pending = 1; + + if (!key) + { + err = mk_error (Invalid_Value); + goto leave; + } + + if (ctx->engine) + { + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + + _gpgme_release_result (ctx); + + err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS + : GPGME_PROTOCOL_OpenPGP, &ctx->engine); + if (err) + goto leave; + + _gpgme_engine_set_status_handler (ctx->engine, delete_status_handler, ctx); + _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); + + err = _gpgme_engine_op_delete (ctx->engine, key, allow_secret); + if (!err) + err = _gpgme_engine_start (ctx->engine, ctx); + + leave: + if (err) + { + ctx->pending = 0; + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + return err; +} + + +/** + * gpgme_op_delete: + * @c: Context + * @key: A Key Object + * @allow_secret: Allow secret key delete + * + * Delete the give @key from the key database. To delete a secret + * along with the public key, @allow_secret must be true. + * + * Return value: 0 on success or an error code. + **/ +GpgmeError +gpgme_op_delete (GpgmeCtx ctx, const GpgmeKey key, int allow_secret) +{ + GpgmeError err = gpgme_op_delete_start (ctx, key, allow_secret); + if (!err) + gpgme_wait (ctx, &err, 1); + return err; +} diff --git a/tags/V0-3-4/gpgme/encrypt-sign.c b/tags/V0-3-4/gpgme/encrypt-sign.c new file mode 100644 index 0000000..1c8e596 --- /dev/null +++ b/tags/V0-3-4/gpgme/encrypt-sign.c @@ -0,0 +1,150 @@ +/* encrypt-sign.c - encrypt and verify functions + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "util.h" +#include "context.h" +#include "ops.h" + + +static void +encrypt_sign_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args) +{ + char *encrypt_info = 0; + int encrypt_info_len; + + _gpgme_encrypt_status_handler (ctx, code, args); + + if (code == STATUS_EOF) + { + encrypt_info = gpgme_data_release_and_get_mem (ctx->op_info, + &encrypt_info_len); + ctx->op_info = NULL; + } + _gpgme_sign_status_handler (ctx, code, args); + if (code == STATUS_EOF && encrypt_info) + _gpgme_data_append (ctx->op_info, encrypt_info, encrypt_info_len); +} + + +GpgmeError +gpgme_op_encrypt_sign_start (GpgmeCtx ctx, GpgmeRecipients recp, + GpgmeData plain, GpgmeData cipher) +{ + int err = 0; + + fail_on_pending_request (ctx); + ctx->pending = 1; + + _gpgme_release_result (ctx); + + /* Do some checks. */ + if (!gpgme_recipients_count (recp)) + { + /* FIXME: In this case we should do symmetric encryption. */ + err = mk_error (No_Recipients); + goto leave; + } + + /* Create an engine object. */ + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS + : GPGME_PROTOCOL_OpenPGP, &ctx->engine); + if (err) + goto leave; + + err = _gpgme_passphrase_start (ctx); + if (err) + goto leave; + + _gpgme_engine_set_status_handler (ctx->engine, + encrypt_sign_status_handler, ctx); + _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); + + /* Check the supplied data */ + if (gpgme_data_get_type (plain) == GPGME_DATA_TYPE_NONE) + { + err = mk_error (No_Data); + goto leave; + } + _gpgme_data_set_mode (plain, GPGME_DATA_MODE_OUT); + if (!cipher || gpgme_data_get_type (cipher) != GPGME_DATA_TYPE_NONE) + { + err = mk_error (Invalid_Value); + goto leave; + } + _gpgme_data_set_mode (cipher, GPGME_DATA_MODE_IN); + + err = _gpgme_engine_op_encrypt_sign (ctx->engine, recp, plain, cipher, + ctx->use_armor, ctx /* FIXME */); + + if (!err) /* And kick off the process. */ + err = _gpgme_engine_start (ctx->engine, ctx); + + leave: + if (err) + { + ctx->pending = 0; + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + return err; +} + + +/** + * gpgme_op_encrypt_sign: + * @ctx: The context + * @recp: The set of recipients + * @plain: plaintext input + * @cipher: signed ciphertext + * + * This function encrypts @plain for all recipients in recp, signs it, + * and returns the ciphertext in @out. The function does wait for the + * result. + * + * Return value: 0 on success or an errorcode. + **/ +GpgmeError +gpgme_op_encrypt_sign (GpgmeCtx ctx, GpgmeRecipients recp, + GpgmeData plain, GpgmeData cipher) +{ + GpgmeError err = gpgme_op_encrypt_sign_start (ctx, recp, plain, cipher); + + if (!err) + { + gpgme_wait (ctx, &err, 1); + /* Old gpg versions don't return status info for invalid + recipients, so we simply check whether we got any output at + all, and if not we assume that we don't have valid + recipients. */ + if (!ctx->error && gpgme_data_get_type (cipher) == GPGME_DATA_TYPE_NONE) + ctx->error = mk_error (No_Recipients); + err = ctx->error; + } + return err; +} diff --git a/tags/V0-3-4/gpgme/encrypt.c b/tags/V0-3-4/gpgme/encrypt.c new file mode 100644 index 0000000..ffaf2d9 --- /dev/null +++ b/tags/V0-3-4/gpgme/encrypt.c @@ -0,0 +1,230 @@ +/* encrypt.c - encrypt functions + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "util.h" +#include "context.h" +#include "ops.h" + +#define SKIP_TOKEN_OR_RETURN(a) do { \ + while (*(a) && *(a) != ' ') (a)++; \ + while (*(a) == ' ') (a)++; \ + if (!*(a)) \ + return; /* oops */ \ +} while (0) + +struct encrypt_result_s +{ + int no_valid_recipients; + int invalid_recipients; + GpgmeData xmlinfo; +}; + +void +_gpgme_release_encrypt_result (EncryptResult result) +{ + if (!result) + return; + gpgme_data_release (result->xmlinfo); + xfree (result); +} + +/* + * Parse the args and save the information + * in an XML structure. + * With args of NULL the xml structure is closed. + */ +static void +append_xml_encinfo (GpgmeData *rdh, char *args) +{ + GpgmeData dh; + char helpbuf[100]; + + if (!*rdh) + { + if (gpgme_data_new (rdh)) + return; /* FIXME: We are ignoring out-of-core. */ + dh = *rdh; + _gpgme_data_append_string (dh, "\n"); + } + else + { + dh = *rdh; + _gpgme_data_append_string (dh, " \n"); + } + + if (!args) + { + /* Just close the XML containter. */ + _gpgme_data_append_string (dh, "\n"); + return; + } + + _gpgme_data_append_string (dh, " \n" + " \n" + " \n"); + + sprintf (helpbuf, " %d\n", atoi (args)); + _gpgme_data_append_string (dh, helpbuf); + SKIP_TOKEN_OR_RETURN (args); + + _gpgme_data_append_string (dh, " "); + _gpgme_data_append_percentstring_for_xml (dh, args); + _gpgme_data_append_string (dh, "\n" + " \n"); +} + + +void +_gpgme_encrypt_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args) +{ + if (ctx->error) + return; + test_and_allocate_result (ctx, encrypt); + + switch (code) + { + case STATUS_EOF: + if (ctx->result.encrypt->xmlinfo) + { + append_xml_encinfo (&ctx->result.encrypt->xmlinfo, NULL); + _gpgme_set_op_info (ctx, ctx->result.encrypt->xmlinfo); + ctx->result.encrypt->xmlinfo = NULL; + } + if (ctx->result.encrypt->no_valid_recipients) + ctx->error = mk_error (No_Recipients); + else if (ctx->result.encrypt->invalid_recipients) + ctx->error = mk_error (Invalid_Recipients); + break; + + case STATUS_INV_RECP: + ctx->result.encrypt->invalid_recipients++; + append_xml_encinfo (&ctx->result.encrypt->xmlinfo, args); + break; + + case STATUS_NO_RECP: + ctx->result.encrypt->no_valid_recipients = 1; + break; + + default: + break; + } +} + + +GpgmeError +gpgme_op_encrypt_start (GpgmeCtx ctx, GpgmeRecipients recp, GpgmeData plain, + GpgmeData ciph) +{ + int err = 0; + + fail_on_pending_request (ctx); + ctx->pending = 1; + + _gpgme_release_result (ctx); + + /* Do some checks. */ + if (!gpgme_recipients_count (recp)) + { + /* Fixme: In this case we should do symmentric encryption. */ + err = mk_error (No_Recipients); + goto leave; + } + + /* Create an engine object. */ + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS + : GPGME_PROTOCOL_OpenPGP, &ctx->engine); + if (err) + goto leave; + + _gpgme_engine_set_status_handler (ctx->engine, _gpgme_encrypt_status_handler, + ctx); + _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); + + /* Check the supplied data */ + if (gpgme_data_get_type (plain) == GPGME_DATA_TYPE_NONE) + { + err = mk_error (No_Data); + goto leave; + } + _gpgme_data_set_mode (plain, GPGME_DATA_MODE_OUT); + if (!ciph || gpgme_data_get_type (ciph) != GPGME_DATA_TYPE_NONE) + { + err = mk_error (Invalid_Value); + goto leave; + } + _gpgme_data_set_mode (ciph, GPGME_DATA_MODE_IN); + + err = _gpgme_engine_op_encrypt (ctx->engine, recp, plain, ciph, ctx->use_armor); + + + if (!err) /* And kick off the process. */ + err = _gpgme_engine_start (ctx->engine, ctx); + + leave: + if (err) + { + ctx->pending = 0; + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + return err; +} + + +/** + * gpgme_op_encrypt: + * @c: The context + * @recp: A set of recipients + * @in: plaintext input + * @out: ciphertext output + * + * This function encrypts @in to @out for all recipients from + * @recp. Other parameters are take from the context @c. + * The function does wait for the result. + * + * Return value: 0 on success or an errorcode. + **/ +GpgmeError +gpgme_op_encrypt (GpgmeCtx ctx, GpgmeRecipients recp, + GpgmeData plain, GpgmeData cipher) +{ + int err = gpgme_op_encrypt_start (ctx, recp, plain, cipher); + if (!err) + { + gpgme_wait (ctx, &err, 1); + /* Old gpg versions don't return status info for invalid + recipients, so we simply check whether we got any output at + all, and if not we assume that we don't have valid + recipients. */ + if (!ctx->error && gpgme_data_get_type (cipher) == GPGME_DATA_TYPE_NONE) + ctx->error = mk_error (No_Recipients); + err = ctx->error; + } + return err; +} diff --git a/tags/V0-3-4/gpgme/engine-gpgsm.c b/tags/V0-3-4/gpgme/engine-gpgsm.c new file mode 100644 index 0000000..c2d28b5 --- /dev/null +++ b/tags/V0-3-4/gpgme/engine-gpgsm.c @@ -0,0 +1,1148 @@ +/* engine-gpgsm.c - GpgSM engine + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#if HAVE_CONFIG_H +#include +#endif + +/* FIXME: Correct check? */ +#ifdef GPGSM_PATH +#define ENABLE_GPGSM 1 +#endif + +#ifdef ENABLE_GPGSM + +#include +#include +#include +#include +#include /* FIXME */ + +#include "rungpg.h" +#include "status-table.h" + +#include "gpgme.h" +#include "util.h" +#include "types.h" +#include "ops.h" +#include "wait.h" +#include "io.h" +#include "key.h" + +#include "engine-gpgsm.h" + +#include "assuan.h" + +#define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \ + *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10)) +#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1)) + + +struct gpgsm_object_s +{ + ASSUAN_CONTEXT assuan_ctx; + + /* Input, output etc are from the servers perspective. */ + int input_fd; + int input_fd_server; + GpgmeData input_data; + int output_fd; + int output_fd_server; + GpgmeData output_data; + int message_fd; + int message_fd_server; + GpgmeData message_data; + + char *command; + + struct + { + GpgStatusHandler fnc; + void *fnc_value; + } status; + + struct + { + GpgColonLineHandler fnc; + void *fnc_value; + struct + { + unsigned char *line; + int linesize; + int linelen; + } attic; + } colon; +}; + + +const char * +_gpgme_gpgsm_get_version (void) +{ + static const char *gpgsm_version; + + /* FIXME: Locking. */ + if (!gpgsm_version) + gpgsm_version = _gpgme_get_program_version (_gpgme_get_gpgsm_path ()); + + return gpgsm_version; +} + + +GpgmeError +_gpgme_gpgsm_check_version (void) +{ + return _gpgme_compare_versions (_gpgme_gpgsm_get_version (), + NEED_GPGSM_VERSION) + ? 0 : mk_error (Invalid_Engine); +} + + +static void +close_notify_handler (int fd, void *opaque) +{ + GpgsmObject gpgsm = opaque; + + assert (fd != -1); + if (gpgsm->input_fd == fd) + gpgsm->input_fd = -1; + else if (gpgsm->output_fd == fd) + gpgsm->output_fd = -1; + else if (gpgsm->message_fd == fd) + gpgsm->message_fd = -1; +} + + +GpgmeError +_gpgme_gpgsm_new (GpgsmObject *r_gpgsm) +{ + GpgmeError err = 0; + GpgsmObject gpgsm; + char *argv[] = { "gpgsm", "--server", NULL }; + int fds[2]; + int child_fds[4]; + + *r_gpgsm = NULL; + gpgsm = xtrycalloc (1, sizeof *gpgsm); + if (!gpgsm) + { + err = mk_error (Out_Of_Core); + return err; + } + + gpgsm->input_fd = -1; + gpgsm->input_fd_server = -1; + gpgsm->output_fd = -1; + gpgsm->output_fd_server = -1; + gpgsm->message_fd = -1; + gpgsm->message_fd_server = -1; + + gpgsm->status.fnc = 0; + gpgsm->colon.fnc = 0; + gpgsm->colon.attic.line = 0; + gpgsm->colon.attic.linesize = 0; + gpgsm->colon.attic.linelen = 0; + + if (_gpgme_io_pipe (fds, 0) < 0) + { + err = mk_error (Pipe_Error); + goto leave; + } + gpgsm->input_fd = fds[1]; + gpgsm->input_fd_server = fds[0]; + + if (_gpgme_io_pipe (fds, 1) < 0) + { + err = mk_error (Pipe_Error); + goto leave; + } + gpgsm->output_fd = fds[0]; + gpgsm->output_fd_server = fds[1]; + + if (_gpgme_io_pipe (fds, 0) < 0) + { + err = mk_error (Pipe_Error); + goto leave; + } + gpgsm->message_fd = fds[1]; + gpgsm->message_fd_server = fds[0]; + + child_fds[0] = gpgsm->input_fd_server; + child_fds[1] = gpgsm->output_fd_server; + child_fds[2] = gpgsm->message_fd_server; + child_fds[3] = -1; + err = assuan_pipe_connect (&gpgsm->assuan_ctx, + _gpgme_get_gpgsm_path (), argv, child_fds); + + if (!err && + (_gpgme_io_set_close_notify (gpgsm->input_fd, + close_notify_handler, gpgsm) + || _gpgme_io_set_close_notify (gpgsm->output_fd, + close_notify_handler, gpgsm) + || _gpgme_io_set_close_notify (gpgsm->message_fd, + close_notify_handler, gpgsm))) + { + err = mk_error (General_Error); + goto leave; + } + + leave: + /* Close the server ends of the pipes. Our ends are closed in + _gpgme_gpgsm_release. */ + if (gpgsm->input_fd_server != -1) + _gpgme_io_close (gpgsm->input_fd_server); + if (gpgsm->output_fd_server != -1) + _gpgme_io_close (gpgsm->output_fd_server); + if (gpgsm->message_fd_server != -1) + _gpgme_io_close (gpgsm->message_fd_server); + + if (err) + _gpgme_gpgsm_release (gpgsm); + else + *r_gpgsm = gpgsm; + + return err; +} + + +void +_gpgme_gpgsm_release (GpgsmObject gpgsm) +{ + pid_t pid; + + if (!gpgsm) + return; + + pid = assuan_get_pid (gpgsm->assuan_ctx); + if (pid != -1) + _gpgme_remove_proc_from_wait_queue (pid); + + if (gpgsm->input_fd != -1) + _gpgme_io_close (gpgsm->input_fd); + if (gpgsm->output_fd != -1) + _gpgme_io_close (gpgsm->output_fd); + if (gpgsm->message_fd != -1) + _gpgme_io_close (gpgsm->message_fd); + + assuan_disconnect (gpgsm->assuan_ctx); + + xfree (gpgsm->colon.attic.line); + xfree (gpgsm->command); + xfree (gpgsm); +} + + +static GpgmeError +map_assuan_error (AssuanError err) +{ + switch (err) + { + case ASSUAN_No_Error: + return mk_error (No_Error); + case ASSUAN_General_Error: + return mk_error (General_Error); + case ASSUAN_Out_Of_Core: + return mk_error (Out_Of_Core); + case ASSUAN_Invalid_Value: + return mk_error (Invalid_Value); + case ASSUAN_Read_Error: + return mk_error (Read_Error); + case ASSUAN_Write_Error: + return mk_error (Write_Error); + + case ASSUAN_Timeout: + case ASSUAN_Problem_Starting_Server: + case ASSUAN_Not_A_Server: + case ASSUAN_Not_A_Client: + case ASSUAN_Nested_Commands: + case ASSUAN_Invalid_Response: + case ASSUAN_No_Data_Callback: + case ASSUAN_No_Inquire_Callback: + case ASSUAN_Connect_Failed: + case ASSUAN_Accept_Failed: + return mk_error (General_Error); + + /* The following error codes are meant as status codes. */ + case ASSUAN_Not_Implemented: + return mk_error (Not_Implemented); + case ASSUAN_Canceled: + return mk_error (Canceled); + case ASSUAN_Unsupported_Algorithm: + return mk_error (Not_Implemented); /* XXX Argh. */ + + /* These are errors internal to GPGME. */ + case ASSUAN_No_Data_Available: + case ASSUAN_No_Input: + case ASSUAN_No_Output: + case ASSUAN_Invalid_Command: + case ASSUAN_Unknown_Command: + case ASSUAN_Syntax_Error: + case ASSUAN_Parameter_Error: + case ASSUAN_Parameter_Conflict: + case ASSUAN_Line_Too_Long: + case ASSUAN_Line_Not_Terminated: + case ASSUAN_Invalid_Data: + case ASSUAN_Unexpected_Command: + case ASSUAN_Too_Much_Data: + case ASSUAN_Inquire_Unknown: + case ASSUAN_Inquire_Error: + case ASSUAN_Invalid_Option: + return mk_error (General_Error); + + /* These are errors in the server. */ + case ASSUAN_Server_Fault: + case ASSUAN_Server_Resource_Problem: + case ASSUAN_Server_IO_Error: + case ASSUAN_Server_Bug: + case ASSUAN_No_Agent: + case ASSUAN_Agent_Error: + return mk_error (Invalid_Engine); /* XXX: Need something more useful. */ + + case ASSUAN_Bad_Certificate: + case ASSUAN_Bad_Certificate_Path: + case ASSUAN_Missing_Certificate: + case ASSUAN_No_Public_Key: + case ASSUAN_No_Secret_Key: + case ASSUAN_Invalid_Name: + return mk_error(Invalid_Key); + + case ASSUAN_Bad_Signature: + return mk_error(Invalid_Key); /* XXX: This is wrong. */ + + case ASSUAN_Cert_Revoked: + case ASSUAN_No_CRL_For_Cert: + case ASSUAN_CRL_Too_Old: + case ASSUAN_Not_Trusted: + return mk_error(Invalid_Key); /* XXX Some more details would be good. */ + + default: + return mk_error (General_Error); + } +} + + +static GpgmeError +gpgsm_assuan_simple_command (ASSUAN_CONTEXT ctx, char *cmd) +{ + AssuanError err; + char *line; + size_t linelen; + + err = assuan_write_line (ctx, cmd); + if (err) + return map_assuan_error (err); + + do + { + err = assuan_read_line (ctx, &line, &linelen); + if (err) + return map_assuan_error (err); + } + while (*line == '#' || !linelen); + + if (linelen >= 2 + && line[0] == 'O' && line[1] == 'K' + && (line[2] == '\0' || line[2] == ' ')) + return 0; + + if (linelen >= 4 + && line[0] == 'E' && line[1] == 'R' && line[2] == 'R' + && line[3] == ' ') + err = map_assuan_error (atoi (&line[4])); + + if (!err) + err = mk_error (General_Error); + return 0; +} + + +#define COMMANDLINELEN 40 +static GpgmeError +gpgsm_set_fd (ASSUAN_CONTEXT ctx, const char *which, int fd, const char *opt) +{ + char line[COMMANDLINELEN]; + + if (opt) + snprintf (line, COMMANDLINELEN, "%s FD=%i %s", which, fd, opt); + else + snprintf (line, COMMANDLINELEN, "%s FD=%i", which, fd); + + return gpgsm_assuan_simple_command (ctx, line); +} + + +GpgmeError +_gpgme_gpgsm_op_decrypt (GpgsmObject gpgsm, GpgmeData ciph, GpgmeData plain) +{ + GpgmeError err; + + if (!gpgsm) + return mk_error (Invalid_Value); + + gpgsm->command = xtrystrdup ("DECRYPT"); + if (!gpgsm->command) + return mk_error (Out_Of_Core); + + gpgsm->input_data = ciph; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, 0); + if (err) + return mk_error (General_Error); /* FIXME */ + gpgsm->output_data = plain; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, 0); + if (err) + return mk_error (General_Error); /* FIXME */ + _gpgme_io_close (gpgsm->message_fd); + + return 0; +} + + +GpgmeError +_gpgme_gpgsm_op_delete (GpgsmObject gpgsm, GpgmeKey key, int allow_secret) +{ + /* FIXME */ + return mk_error (Not_Implemented); +} + + +static GpgmeError +gpgsm_set_recipients (GpgsmObject gpgsm, GpgmeRecipients recp) +{ + GpgmeError err; + ASSUAN_CONTEXT ctx = gpgsm->assuan_ctx; + char *line; + int linelen; + struct user_id_s *r; + int valid_recipients = 0; + + linelen = 10 + 40 + 1; /* "RECIPIENT " + guess + '\0'. */ + line = xtrymalloc (10 + 40 + 1); + if (!line) + return mk_error (Out_Of_Core); + strcpy (line, "RECIPIENT "); + for (r = recp->list; r; r = r->next) + { + int newlen = 11 + strlen (r->name); + if (linelen < newlen) + { + char *newline = xtryrealloc (line, newlen); + if (! newline) + { + xfree (line); + return mk_error(Out_Of_Core); + } + line = newline; + linelen = newlen; + } + strcpy (&line[10], r->name); + + err = gpgsm_assuan_simple_command (ctx, line); + if (!err) + valid_recipients = 1; + else if (err == GPGME_Invalid_Key && gpgsm->status.fnc) + { + /* FIXME: Include other reasons. */ + line[8] = '0'; /* FIXME: Report detailed reason. */ + gpgsm->status.fnc (gpgsm->status.fnc_value, STATUS_INV_RECP, &line[8]); + line[8] = 'T'; + } + else if (err != GPGME_Invalid_Key) + { + xfree (line); + return err; + } + } + xfree (line); + if (!valid_recipients && gpgsm->status.fnc) + gpgsm->status.fnc (gpgsm->status.fnc_value, STATUS_NO_RECP, ""); + return 0; +} + + +GpgmeError +_gpgme_gpgsm_op_encrypt (GpgsmObject gpgsm, GpgmeRecipients recp, + GpgmeData plain, GpgmeData ciph, int use_armor) +{ + GpgmeError err; + + if (!gpgsm) + return mk_error (Invalid_Value); + + gpgsm->command = xtrystrdup ("ENCRYPT"); + if (!gpgsm->command) + return mk_error (Out_Of_Core); + + gpgsm->input_data = plain; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, 0); + if (err) + return err; + gpgsm->output_data = ciph; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, + use_armor ? "--armor" : 0); + if (err) + return err; + _gpgme_io_close (gpgsm->message_fd); + + err = gpgsm_set_recipients (gpgsm, recp); + if (err) + return err; + + return 0; +} + + +GpgmeError +_gpgme_gpgsm_op_export (GpgsmObject gpgsm, GpgmeRecipients recp, + GpgmeData keydata, int use_armor) +{ + /* FIXME */ + return mk_error (Not_Implemented); +} + + +GpgmeError +_gpgme_gpgsm_op_genkey (GpgsmObject gpgsm, GpgmeData help_data, int use_armor, + GpgmeData pubkey, GpgmeData seckey) +{ + GpgmeError err; + + if (!gpgsm || !pubkey || seckey) + return mk_error (Invalid_Value); + + gpgsm->command = xtrystrdup ("GENKEY"); + if (!gpgsm->command) + return mk_error (Out_Of_Core); + + gpgsm->input_data = help_data; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, 0); + if (err) + return err; + gpgsm->output_data = pubkey; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, + use_armor ? "--armor" : 0); + if (err) + return err; + _gpgme_io_close (gpgsm->message_fd); + + return 0; +} + + +GpgmeError +_gpgme_gpgsm_op_import (GpgsmObject gpgsm, GpgmeData keydata) +{ + GpgmeError err; + + if (!gpgsm) + return mk_error (Invalid_Value); + + gpgsm->command = xtrystrdup ("IMPORT"); + if (!gpgsm->command) + return mk_error (Out_Of_Core); + + gpgsm->input_data = keydata; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, 0); + if (err) + return err; + _gpgme_io_close (gpgsm->output_fd); + _gpgme_io_close (gpgsm->message_fd); + + return 0; +} + + +GpgmeError +_gpgme_gpgsm_op_keylist (GpgsmObject gpgsm, const char *pattern, + int secret_only, int keylist_mode) +{ + char *line; + + if (!pattern) + pattern = ""; + + /* Length is "LISTSECRETKEYS " + p + '\0'. */ + line = xtrymalloc (15 + strlen (pattern) + 1); + if (!line) + return mk_error (Out_Of_Core); + if (secret_only) + { + strcpy (line, "LISTSECRETKEYS "); + strcpy (&line[15], pattern); + } + else + { + strcpy (line, "LISTKEYS "); + strcpy (&line[9], pattern); + } + + _gpgme_io_close (gpgsm->input_fd); + _gpgme_io_close (gpgsm->output_fd); + _gpgme_io_close (gpgsm->message_fd); + + gpgsm->command = line; + return 0; +} + + +GpgmeError +_gpgme_gpgsm_op_keylist_ext (GpgsmObject gpgsm, const char *pattern[], + int secret_only, int reserved, int keylist_mode) +{ + char *line; + /* Length is "LISTSECRETKEYS " + p + '\0'. */ + int length = 15 + 1; + char *linep; + + if (reserved) + return mk_error (Invalid_Value); + + if (pattern && *pattern) + { + const char **pat = pattern; + + while (*pat) + { + const char *patlet = *pat; + + while (*patlet) + { + length++; + if (*patlet == '%' || *patlet == ' ' || *patlet == '+') + length += 2; + patlet++; + } + pat++; + /* This will allocate one byte more than necessary. */ + length++; + } + } + line = xtrymalloc (length); + if (!line) + return mk_error (Out_Of_Core); + if (secret_only) + { + strcpy (line, "LISTSECRETKEYS "); + linep = &line[15]; + } + else + { + strcpy (line, "LISTKEYS "); + linep = &line[9]; + } + + if (pattern && *pattern) + { + while (*pattern) + { + const char *patlet = *pattern; + + while (*patlet) + { + switch (*patlet) + { + case '%': + *(linep++) = '%'; + *(linep++) = '2'; + *(linep++) = '5'; + break; + case ' ': + *(linep++) = '%'; + *(linep++) = '2'; + *(linep++) = '0'; + break; + case '+': + *(linep++) = '%'; + *(linep++) = '2'; + *(linep++) = 'B'; + break; + default: + *(linep++) = *patlet; + break; + } + patlet++; + } + pattern++; + } + } + *linep = '\0'; + + _gpgme_io_close (gpgsm->input_fd); + _gpgme_io_close (gpgsm->output_fd); + _gpgme_io_close (gpgsm->message_fd); + + gpgsm->command = line; + return 0; +} + + +GpgmeError +_gpgme_gpgsm_op_sign (GpgsmObject gpgsm, GpgmeData in, GpgmeData out, + GpgmeSigMode mode, int use_armor, + int use_textmode, int include_certs, + GpgmeCtx ctx /* FIXME */) +{ + GpgmeError err; + char *assuan_cmd; + + if (!gpgsm) + return mk_error (Invalid_Value); + + gpgsm->command = xtrystrdup (mode == GPGME_SIG_MODE_DETACH + ? "SIGN --detached" : "SIGN"); + if (!gpgsm->command) + return mk_error (Out_Of_Core); + + if (asprintf (&assuan_cmd, "OPTION include-certs %i", include_certs) < 0) + return mk_error (Out_Of_Core); + err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, assuan_cmd); + free (assuan_cmd); + if (err) + return err; + + gpgsm->input_data = in; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, 0); + if (err) + return err; + gpgsm->output_data = out; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, + use_armor ? "--armor" : 0); + if (err) + return err; + _gpgme_io_close (gpgsm->message_fd); + + return 0; +} + + +GpgmeError +_gpgme_gpgsm_op_trustlist (GpgsmObject gpgsm, const char *pattern) +{ + /* FIXME */ + return mk_error (Not_Implemented); +} + + +GpgmeError +_gpgme_gpgsm_op_verify (GpgsmObject gpgsm, GpgmeData sig, GpgmeData text) +{ + GpgmeError err; + + if (!gpgsm) + return mk_error (Invalid_Value); + + gpgsm->command = xtrystrdup ("VERIFY"); + if (!gpgsm->command) + return mk_error (Out_Of_Core); + + gpgsm->input_data = sig; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, 0); + if (err) + return err; + if (_gpgme_data_get_mode (text) == GPGME_DATA_MODE_IN) + { + /* Normal or cleartext signature. */ + gpgsm->output_data = text; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, + 0); + } + else + { + /* Detached signature. */ + gpgsm->message_data = text; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "MESSAGE", + gpgsm->message_fd_server, 0); + } + if (err) + return err; + _gpgme_io_close (gpgsm->output_fd); + + return 0; +} + + +static int +status_cmp (const void *ap, const void *bp) +{ + const struct status_table_s *a = ap; + const struct status_table_s *b = bp; + + return strcmp (a->name, b->name); +} + + +static int +gpgsm_status_handler (void *opaque, int pid, int fd) +{ + AssuanError err; + GpgsmObject gpgsm = opaque; + char *line; + size_t linelen; + + do + { + err = assuan_read_line (gpgsm->assuan_ctx, &line, &linelen); + + if (err + || (linelen >= 2 + && line[0] == 'O' && line[1] == 'K' + && (line[2] == '\0' || line[2] == ' ')) + || (linelen >= 3 + && line[0] == 'E' && line[1] == 'R' && line[2] == 'R' + && (line[3] == '\0' || line[3] == ' '))) + { + /* XXX: If an error occured, find out what happened, then save the error value + before running the status handler (so it takes precedence). */ + if (!err && line[0] == 'E' && line[3] == ' ') + { + err = map_assuan_error (atoi (&line[4])); + if (!err) + err = mk_error (General_Error); + } + if (err) + { + /* XXX Kludge ahead. We really, really, really must not + make use of status.fnc_value. */ + GpgmeCtx ctx = (GpgmeCtx) gpgsm->status.fnc_value; + if (!ctx->error) + ctx->error = err; + } + + if (gpgsm->status.fnc) + gpgsm->status.fnc (gpgsm->status.fnc_value, STATUS_EOF, ""); + + /* XXX: Try our best to terminate the connection. */ + if (err) + assuan_write_line (gpgsm->assuan_ctx, "BYE"); + + return 1; + } + + if (linelen > 2 + && line[0] == 'D' && line[1] == ' ' + && gpgsm->colon.fnc) + { + /* We are using the colon handler even for plain inline data + - strange name for that function but for historic reasons + we keep it. */ + /* FIXME We can't use this for binary data because we + assume this is a string. For the current usage of colon + output it is correct. */ + unsigned char *src = line + 2; + unsigned char *end = line + linelen; + unsigned char *dst; + unsigned char **aline = &gpgsm->colon.attic.line; + int *alinelen = &gpgsm->colon.attic.linelen; + + if (gpgsm->colon.attic.linesize + < *alinelen + linelen + 1) + { + unsigned char *newline = xtryrealloc (*aline, + *alinelen + linelen + 1); + if (!newline) + return mk_error (Out_Of_Core); + *aline = newline; + gpgsm->colon.attic.linesize += linelen + 1; + } + + dst = *aline + *alinelen; + + while (src < end) + { + if (*src == '%' && src + 2 < end) + { + /* Handle escaped characters. */ + ++src; + *dst = xtoi_2 (src); + (*alinelen)++; + src += 2; + } + else + { + *dst = *src++; + (*alinelen)++; + } + + if (*dst == '\n') + { + /* Terminate the pending line, pass it to the colon + handler and reset it. */ + + if (*alinelen > 1 && *(dst - 1) == '\r') + dst--; + *dst = '\0'; + + /* FIXME How should we handle the return code? */ + gpgsm->colon.fnc (gpgsm->colon.fnc_value, *aline); + dst = *aline; + *alinelen = 0; + } + else + dst++; + } + } + else if (linelen > 2 + && line[0] == 'S' && line[1] == ' ') + { + struct status_table_s t, *r; + char *rest; + + rest = strchr (line + 2, ' '); + if (!rest) + rest = line + linelen; /* set to an empty string */ + else + *rest++ = 0; + + t.name = line + 2; + r = bsearch (&t, status_table, DIM(status_table) - 1, + sizeof t, status_cmp); + + if (r) + { + if (gpgsm->status.fnc) + gpgsm->status.fnc (gpgsm->status.fnc_value, r->code, rest); + } + else + fprintf (stderr, "[UNKNOWN STATUS]%s %s", t.name, rest); + } + } + while (assuan_pending_line (gpgsm->assuan_ctx)); + + return 0; +} + + +void +_gpgme_gpgsm_set_status_handler (GpgsmObject gpgsm, + GpgStatusHandler fnc, void *fnc_value) +{ + assert (gpgsm); + + gpgsm->status.fnc = fnc; + gpgsm->status.fnc_value = fnc_value; +} + + +void +_gpgme_gpgsm_set_colon_line_handler (GpgsmObject gpgsm, + GpgColonLineHandler fnc, void *fnc_value) +{ + assert (gpgsm); + + gpgsm->colon.fnc = fnc; + gpgsm->colon.fnc_value = fnc_value; +} + + +GpgmeError +_gpgme_gpgsm_start (GpgsmObject gpgsm, void *opaque) +{ + GpgmeError err = 0; + pid_t pid; + int fdlist[5]; + int nfds; + + if (!gpgsm) + return mk_error (Invalid_Value); + + pid = assuan_get_pid (gpgsm->assuan_ctx); + + /* We need to know the fd used by assuan for reads. We do this by + using the assumption that the first returned fd from + assuan_get_active_fds() is always this one. */ + nfds = assuan_get_active_fds (gpgsm->assuan_ctx, 0 /* read fds */, + fdlist, DIM (fdlist)); + if (nfds < 1) + return mk_error (General_Error); /* FIXME */ + err = _gpgme_register_pipe_handler (opaque, gpgsm_status_handler, gpgsm, pid, + fdlist[0], 1); + + + if (gpgsm->input_fd != -1) + { + err = _gpgme_register_pipe_handler (opaque, _gpgme_data_outbound_handler, + gpgsm->input_data, pid, + gpgsm->input_fd, 0); + if (!err) /* FIXME Kludge around poll() problem. */ + err = _gpgme_io_set_nonblocking (gpgsm->input_fd); + } + if (!err && gpgsm->output_fd != -1) + err = _gpgme_register_pipe_handler (opaque, _gpgme_data_inbound_handler, + gpgsm->output_data, pid, + gpgsm->output_fd, 1); + if (!err && gpgsm->message_fd != -1) + { + err = _gpgme_register_pipe_handler (opaque, _gpgme_data_outbound_handler, + gpgsm->message_data, pid, + gpgsm->message_fd, 0); + if (!err) /* FIXME Kludge around poll() problem. */ + err = _gpgme_io_set_nonblocking (gpgsm->message_fd); + } + + if (!err) + err = assuan_write_line (gpgsm->assuan_ctx, gpgsm->command); + + return err; +} + + +#else /* ENABLE_GPGSM */ + + +#include +#include "util.h" + +#include "engine-gpgsm.h" + + +const char * +_gpgme_gpgsm_get_version (void) +{ + return NULL; +} + + +GpgmeError +_gpgme_gpgsm_check_version (void) +{ + return mk_error (Invalid_Engine); +} + + +GpgmeError +_gpgme_gpgsm_new (GpgsmObject *r_gpgsm) +{ + return mk_error (Invalid_Engine); +} + + +void +_gpgme_gpgsm_release (GpgsmObject gpgsm) +{ + return; +} + + +void +_gpgme_gpgsm_set_status_handler (GpgsmObject gpgsm, + GpgStatusHandler fnc, void *fnc_value) +{ + return; +} + + +GpgmeError +_gpgme_gpgsm_op_decrypt (GpgsmObject gpgsm, GpgmeData ciph, GpgmeData plain) +{ + return mk_error (Invalid_Engine); +} + + +GpgmeError +_gpgme_gpgsm_op_delete (GpgsmObject gpgsm, GpgmeKey key, int allow_secret) +{ + return mk_error (Invalid_Engine); +} + + +GpgmeError +_gpgme_gpgsm_op_encrypt (GpgsmObject gpgsm, GpgmeRecipients recp, + GpgmeData plain, GpgmeData ciph, int use_armor) +{ + return mk_error (Invalid_Engine); +} + + +GpgmeError +_gpgme_gpgsm_op_export (GpgsmObject gpgsm, GpgmeRecipients recp, + GpgmeData keydata, int use_armor) +{ + return mk_error (Invalid_Engine); +} + + +GpgmeError +_gpgme_gpgsm_op_genkey (GpgsmObject gpgsm, GpgmeData help_data, int use_armor, + GpgmeData pubkey, GpgmeData seckey) +{ + return mk_error (Invalid_Engine); +} + + +GpgmeError +_gpgme_gpgsm_op_import (GpgsmObject gpgsm, GpgmeData keydata) +{ + return mk_error (Invalid_Engine); +} + + +GpgmeError +_gpgme_gpgsm_op_keylist (GpgsmObject gpgsm, const char *pattern, + int secret_only, int keylist_mode) +{ + return mk_error (Invalid_Engine); +} + + +GpgmeError +_gpgme_gpgsm_op_keylist_ext (GpgsmObject gpgsm, const char *pattern[], + int secret_only, int reserved, int keylist_mode) +{ + return mk_error (Invalid_Engine); +} + +GpgmeError +_gpgme_gpgsm_op_sign (GpgsmObject gpgsm, GpgmeData in, GpgmeData out, + GpgmeSigMode mode, int use_armor, + int use_textmode, int include_certs, + GpgmeCtx ctx /* FIXME */) +{ + return mk_error (Invalid_Engine); +} + + +GpgmeError +_gpgme_gpgsm_op_trustlist (GpgsmObject gpgsm, const char *pattern) +{ + return mk_error (Invalid_Engine); +} + + +GpgmeError +_gpgme_gpgsm_op_verify (GpgsmObject gpgsm, GpgmeData sig, GpgmeData text) +{ + return mk_error (Invalid_Engine); +} + + +void +_gpgme_gpgsm_set_colon_line_handler (GpgsmObject gpgsm, + GpgColonLineHandler fnc, void *fnc_value) +{ +} + + +GpgmeError +_gpgme_gpgsm_start (GpgsmObject gpgsm, void *opaque) +{ + return mk_error (Invalid_Engine); +} + + +#endif /* ! ENABLE_GPGSM */ diff --git a/tags/V0-3-4/gpgme/engine-gpgsm.h b/tags/V0-3-4/gpgme/engine-gpgsm.h new file mode 100644 index 0000000..ecd80b4 --- /dev/null +++ b/tags/V0-3-4/gpgme/engine-gpgsm.h @@ -0,0 +1,67 @@ +/* engine-gpgsm.h - GPGME GpgSM engine calling functions + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef ENGINE_GPGSM_H +#define ENGINE_GPGSM_H + +#include "types.h" +#include "rungpg.h" /* FIXME statusHandler */ + +const char *_gpgme_gpgsm_get_version (void); +GpgmeError _gpgme_gpgsm_check_version (void); + +GpgmeError _gpgme_gpgsm_new (GpgsmObject *r_gpg); +void _gpgme_gpgsm_release (GpgsmObject gpg); + +void _gpgme_gpgsm_set_status_handler (GpgsmObject gpgsm, + GpgStatusHandler fnc, void *fnc_value); +void _gpgme_gpgsm_set_colon_line_handler (GpgsmObject gpgsm, + GpgColonLineHandler fnc, void *fnc_value) ; +GpgmeError _gpgme_gpgsm_op_decrypt (GpgsmObject gpgsm, GpgmeData ciph, + GpgmeData plain); +GpgmeError _gpgme_gpgsm_op_delete (GpgsmObject gpgsm, GpgmeKey key, + int allow_secret); +GpgmeError _gpgme_gpgsm_op_encrypt (GpgsmObject gpgsm, GpgmeRecipients recp, + GpgmeData plain, GpgmeData ciph, + int use_armor); +GpgmeError _gpgme_gpgsm_op_export (GpgsmObject gpgsm, GpgmeRecipients recp, + GpgmeData keydata, int use_armor); +GpgmeError _gpgme_gpgsm_op_genkey (GpgsmObject gpgsm, GpgmeData help_data, + int use_armor, GpgmeData pubkey, + GpgmeData seckey); +GpgmeError _gpgme_gpgsm_op_import (GpgsmObject gpgsm, GpgmeData keydata); +GpgmeError _gpgme_gpgsm_op_keylist (GpgsmObject gpgsm, const char *pattern, + int secret_only, int keylist_mode); +GpgmeError _gpgme_gpgsm_op_keylist_ext (GpgsmObject gpgsm, + const char *pattern[], + int secret_only, int reserved, + int keylist_mode); +GpgmeError _gpgme_gpgsm_op_sign (GpgsmObject gpgsm, GpgmeData in, + GpgmeData out, + GpgmeSigMode mode, int use_armor, + int use_textmode, int include_certs, + GpgmeCtx ctx /* FIXME */); +GpgmeError _gpgme_gpgsm_op_trustlist (GpgsmObject gpgsm, const char *pattern); +GpgmeError _gpgme_gpgsm_op_verify (GpgsmObject gpgsm, GpgmeData sig, + GpgmeData text); +GpgmeError _gpgme_gpgsm_start (GpgsmObject gpgsm, void *opaque); + +#endif /* ENGINE_GPGSM_H */ diff --git a/tags/V0-3-4/gpgme/engine.c b/tags/V0-3-4/gpgme/engine.c new file mode 100644 index 0000000..c1dd630 --- /dev/null +++ b/tags/V0-3-4/gpgme/engine.c @@ -0,0 +1,643 @@ +/* engine.c + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include +#include + +#include "gpgme.h" +#include "util.h" +#include "sema.h" +#include "io.h" + +#include "engine.h" +#include "rungpg.h" +#include "engine-gpgsm.h" + +struct engine_object_s + { + GpgmeProtocol protocol; + + const char *path; + const char *version; + + union + { + GpgObject gpg; + GpgsmObject gpgsm; + } engine; +}; + +struct reap_s +{ + struct reap_s *next; + int pid; + time_t entered; + int term_send; +}; + +static struct reap_s *reap_list; +DEFINE_STATIC_LOCK (reap_list_lock); + +/* Get the path of the engine for PROTOCOL. */ +const char * +_gpgme_engine_get_path (GpgmeProtocol proto) +{ + switch (proto) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_get_gpg_path (); + case GPGME_PROTOCOL_CMS: + return _gpgme_get_gpgsm_path (); + default: + return NULL; + } +} + +/* Get the version number of the engine for PROTOCOL. */ +const char * +_gpgme_engine_get_version (GpgmeProtocol proto) +{ + switch (proto) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_get_version (); + case GPGME_PROTOCOL_CMS: + return _gpgme_gpgsm_get_version (); + default: + return NULL; + } +} + +GpgmeError +gpgme_engine_check_version (GpgmeProtocol proto) +{ + switch (proto) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_check_version (); + case GPGME_PROTOCOL_CMS: + return _gpgme_gpgsm_check_version (); + default: + return mk_error (Invalid_Value); + } +} + +const char * +_gpgme_engine_get_info (GpgmeProtocol proto) +{ + static const char fmt[] = " \n" + " %s\n" + " %s\n" + " %s\n" + " \n"; + static const char *const strproto[3] = { "OpenPGP", "CMS", NULL }; + static const char *engine_info[3]; /* FIXME: MAX_PROTO + 1*/ + const char *path; + const char *version; + char *info; + + if (proto > 2 /* FIXME MAX_PROTO */ || !strproto[proto]) + return NULL; + + /* FIXME: Make sure that only one instance does run. */ + if (engine_info[proto]) + return engine_info[proto]; + + path = _gpgme_engine_get_path (proto); + version = _gpgme_engine_get_version (proto); + + if (!path || !version) + return NULL; + + info = xtrymalloc (strlen(fmt) + strlen(strproto[proto]) + strlen(path) + + strlen (version) + 1); + if (!info) + info = " \n" + " Out of core\n" + " "; + else + sprintf (info, fmt, strproto[proto], version, path); + engine_info[proto] = info; + + return engine_info[proto]; +} + +GpgmeError +_gpgme_engine_new (GpgmeProtocol proto, EngineObject *r_engine) +{ + EngineObject engine; + GpgmeError err = 0; + + engine = xtrycalloc (1, sizeof *engine); + if (!engine) + { + err = mk_error (Out_Of_Core); + goto leave; + } + + engine->protocol = proto; + switch (proto) + { + case GPGME_PROTOCOL_OpenPGP: + err =_gpgme_gpg_new (&engine->engine.gpg); + break; + case GPGME_PROTOCOL_CMS: + err = _gpgme_gpgsm_new (&engine->engine.gpgsm); + if (err) + goto leave; + break; + default: + err = mk_error (Invalid_Value); + } + if (err) + goto leave; + + engine->path = _gpgme_engine_get_path (proto); + engine->version = _gpgme_engine_get_version (proto); + + if (!engine->path || !engine->version) + { + err = mk_error (Invalid_Engine); + goto leave; + } + + leave: + if (err) + _gpgme_engine_release (engine); + else + *r_engine = engine; + + return err; +} + +void +_gpgme_engine_release (EngineObject engine) +{ + if (!engine) + return; + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + _gpgme_gpg_release (engine->engine.gpg); + break; + case GPGME_PROTOCOL_CMS: + _gpgme_gpgsm_release (engine->engine.gpgsm); + break; + default: + break; + } + xfree (engine); +} + + +void +_gpgme_engine_set_verbosity (EngineObject engine, int verbosity) +{ + if (!engine) + return; + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + while (verbosity-- > 0) + _gpgme_gpg_add_arg (engine->engine.gpg, "--verbose"); + break; + case GPGME_PROTOCOL_CMS: + /* FIXME */ + break; + default: + break; + } +} + +void +_gpgme_engine_set_status_handler (EngineObject engine, + GpgStatusHandler fnc, void *fnc_value) +{ + if (!engine) + return; + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + _gpgme_gpg_set_status_handler (engine->engine.gpg, fnc, fnc_value); + break; + case GPGME_PROTOCOL_CMS: + _gpgme_gpgsm_set_status_handler (engine->engine.gpgsm, fnc, fnc_value); + break; + default: + break; + } +} + +GpgmeError +_gpgme_engine_set_command_handler (EngineObject engine, + GpgCommandHandler fnc, void *fnc_value) +{ + if (!engine) + return mk_error (Invalid_Value); + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_set_command_handler (engine->engine.gpg, fnc, fnc_value); + case GPGME_PROTOCOL_CMS: + /* FIXME */ + break; + default: + break; + } + return 0; +} + +GpgmeError _gpgme_engine_set_colon_line_handler (EngineObject engine, + GpgColonLineHandler fnc, + void *fnc_value) +{ + if (!engine) + return mk_error (Invalid_Value); + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_set_colon_line_handler (engine->engine.gpg, + fnc, fnc_value); + case GPGME_PROTOCOL_CMS: + _gpgme_gpgsm_set_colon_line_handler (engine->engine.gpgsm, + fnc, fnc_value); + break; + + default: + break; + } + return 0; +} + +GpgmeError +_gpgme_engine_op_decrypt (EngineObject engine, GpgmeData ciph, GpgmeData plain) +{ + if (!engine) + return mk_error (Invalid_Value); + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_op_decrypt (engine->engine.gpg, ciph, plain); + case GPGME_PROTOCOL_CMS: + return _gpgme_gpgsm_op_decrypt (engine->engine.gpgsm, ciph, plain); + default: + break; + } + return 0; +} + +GpgmeError +_gpgme_engine_op_delete (EngineObject engine, GpgmeKey key, int allow_secret) +{ + if (!engine) + return mk_error (Invalid_Value); + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_op_delete (engine->engine.gpg, key, allow_secret); + case GPGME_PROTOCOL_CMS: + return _gpgme_gpgsm_op_delete (engine->engine.gpgsm, key, allow_secret); + default: + break; + } + return 0; +} + + +GpgmeError +_gpgme_engine_op_encrypt (EngineObject engine, GpgmeRecipients recp, + GpgmeData plain, GpgmeData ciph, int use_armor) +{ + if (!engine) + return mk_error (Invalid_Value); + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_op_encrypt (engine->engine.gpg, recp, plain, ciph, + use_armor); + case GPGME_PROTOCOL_CMS: + return _gpgme_gpgsm_op_encrypt (engine->engine.gpgsm, recp, plain, ciph, + use_armor); + default: + break; + } + return 0; +} + + +GpgmeError +_gpgme_engine_op_encrypt_sign (EngineObject engine, GpgmeRecipients recp, + GpgmeData plain, GpgmeData ciph, int use_armor, + GpgmeCtx ctx /* FIXME */) +{ + if (!engine) + return mk_error (Invalid_Value); + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_op_encrypt_sign (engine->engine.gpg, recp, plain, ciph, + use_armor, ctx); + case GPGME_PROTOCOL_CMS: + return mk_error (Not_Implemented); + default: + break; + } + return 0; +} + + +GpgmeError +_gpgme_engine_op_export (EngineObject engine, GpgmeRecipients recp, + GpgmeData keydata, int use_armor) +{ + if (!engine) + return mk_error (Invalid_Value); + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_op_export (engine->engine.gpg, recp, keydata, + use_armor); + case GPGME_PROTOCOL_CMS: + return _gpgme_gpgsm_op_export (engine->engine.gpgsm, recp, keydata, + use_armor); + default: + break; + } + return 0; +} + +GpgmeError +_gpgme_engine_op_genkey (EngineObject engine, GpgmeData help_data, + int use_armor, GpgmeData pubkey, GpgmeData seckey) +{ + if (!engine) + return mk_error (Invalid_Value); + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_op_genkey (engine->engine.gpg, help_data, use_armor, + pubkey, seckey); + case GPGME_PROTOCOL_CMS: + return _gpgme_gpgsm_op_genkey (engine->engine.gpgsm, help_data, use_armor, + pubkey, seckey); + default: + break; + } + return 0; +} + +GpgmeError +_gpgme_engine_op_import (EngineObject engine, GpgmeData keydata) +{ + if (!engine) + return mk_error (Invalid_Value); + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_op_import (engine->engine.gpg, keydata); + case GPGME_PROTOCOL_CMS: + return _gpgme_gpgsm_op_import (engine->engine.gpgsm, keydata); + default: + break; + } + return 0; +} + + +GpgmeError +_gpgme_engine_op_keylist (EngineObject engine, const char *pattern, + int secret_only, int keylist_mode) +{ + if (!engine) + return mk_error (Invalid_Value); + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_op_keylist (engine->engine.gpg, pattern, secret_only, + keylist_mode); + case GPGME_PROTOCOL_CMS: + return _gpgme_gpgsm_op_keylist (engine->engine.gpgsm, pattern, secret_only, + keylist_mode); + default: + break; + } + return 0; +} + + +GpgmeError +_gpgme_engine_op_keylist_ext (EngineObject engine, const char *pattern[], + int secret_only, int reserved, int keylist_mode) +{ + if (!engine) + return mk_error (Invalid_Value); + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_op_keylist_ext (engine->engine.gpg, pattern, + secret_only, reserved, keylist_mode); + case GPGME_PROTOCOL_CMS: + return _gpgme_gpgsm_op_keylist_ext (engine->engine.gpgsm, pattern, + secret_only, reserved, keylist_mode); + default: + break; + } + return 0; +} + + +GpgmeError +_gpgme_engine_op_sign (EngineObject engine, GpgmeData in, GpgmeData out, + GpgmeSigMode mode, int use_armor, + int use_textmode, int include_certs, + GpgmeCtx ctx /* FIXME */) +{ + if (!engine) + return mk_error (Invalid_Value); + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_op_sign (engine->engine.gpg, in, out, mode, use_armor, + use_textmode, ctx); + case GPGME_PROTOCOL_CMS: + return _gpgme_gpgsm_op_sign (engine->engine.gpgsm, in, out, mode, + use_armor, use_textmode, include_certs, ctx); + break; + default: + break; + } + return 0; +} + +GpgmeError +_gpgme_engine_op_trustlist (EngineObject engine, const char *pattern) +{ + if (!engine) + return mk_error (Invalid_Value); + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_op_trustlist (engine->engine.gpg, pattern); + case GPGME_PROTOCOL_CMS: + return _gpgme_gpgsm_op_trustlist (engine->engine.gpgsm, pattern); + default: + break; + } + return 0; +} + +GpgmeError +_gpgme_engine_op_verify (EngineObject engine, GpgmeData sig, GpgmeData text) +{ + if (!engine) + return mk_error (Invalid_Value); + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_op_verify (engine->engine.gpg, sig, text); + case GPGME_PROTOCOL_CMS: + return _gpgme_gpgsm_op_verify (engine->engine.gpgsm, sig, text); + default: + break; + } + return 0; +} + +GpgmeError +_gpgme_engine_start (EngineObject engine, void *opaque) +{ + if (!engine) + return mk_error (Invalid_Value); + + switch (engine->protocol) + { + case GPGME_PROTOCOL_OpenPGP: + return _gpgme_gpg_spawn (engine->engine.gpg, opaque); + case GPGME_PROTOCOL_CMS: + return _gpgme_gpgsm_start (engine->engine.gpgsm, opaque); + default: + break; + } + return 0; +} + +void +_gpgme_engine_add_child_to_reap_list (void *buf, int buflen, pid_t pid) +{ + /* Reuse the memory, so that we don't need to allocate another + memory block and to handle errors. */ + struct reap_s *child = buf; + + assert (buflen >= sizeof *child); + memset (child, 0, sizeof *child); + child->pid = pid; + child->entered = time (NULL); + LOCK(reap_list_lock); + child->next = reap_list; + reap_list = child; + UNLOCK(reap_list_lock); +} + +static void +do_reaping (void) +{ + struct reap_s *r, *rlast; + static time_t last_check; + time_t cur_time = time (NULL); + + /* A race does not matter here. */ + if (!last_check) + last_check = time (NULL); + + if (last_check >= cur_time) + return; /* We check only every second. */ + + /* Fixme: it would be nice if to have a TRYLOCK here. */ + LOCK (reap_list_lock); + for (r = reap_list, rlast = NULL; r; rlast = r, r = r ? r->next : NULL) + { + int dummy1, dummy2; + + if (_gpgme_io_waitpid (r->pid, 0, &dummy1, &dummy2)) + { + /* The process has terminated - remove it from the queue. */ + void *p = r; + if (!rlast) + { + reap_list = r->next; + r = reap_list; + } + else + { + rlast->next = r->next; + r = rlast; + } + xfree (p); + } + else if (!r->term_send) + { + if (r->entered + 1 >= cur_time) + { + _gpgme_io_kill (r->pid, 0); + r->term_send = 1; + r->entered = cur_time; + } + } + else + { + /* Give it 5 second before we are going to send the killer. */ + if (r->entered + 5 >= cur_time) + { + _gpgme_io_kill (r->pid, 1); + r->entered = cur_time; /* Just in case we have to repeat it. */ + } + } + } + UNLOCK (reap_list_lock); +} + +void +_gpgme_engine_housecleaning (void) +{ + do_reaping (); +} diff --git a/tags/V0-3-4/gpgme/engine.h b/tags/V0-3-4/gpgme/engine.h new file mode 100644 index 0000000..f684021 --- /dev/null +++ b/tags/V0-3-4/gpgme/engine.h @@ -0,0 +1,82 @@ +/* engine.h - GPGME engine calling functions + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef ENGINE_H +#define ENGINE_H + +#include "types.h" +#include "rungpg.h" + +const char *_gpgme_engine_get_path (GpgmeProtocol proto); +const char *_gpgme_engine_get_version (GpgmeProtocol proto); +const char * _gpgme_engine_get_info (GpgmeProtocol proto); +GpgmeError _gpgme_engine_new (GpgmeProtocol proto, EngineObject *r_engine); +void _gpgme_engine_release (EngineObject engine); +void _gpgme_engine_set_status_handler (EngineObject engine, + GpgStatusHandler fnc, void *fnc_value); +GpgmeError _gpgme_engine_set_command_handler (EngineObject engine, + GpgCommandHandler fnc, + void *fnc_value); +GpgmeError _gpgme_engine_set_colon_line_handler (EngineObject gpg, + GpgColonLineHandler fnc, + void *fnc_value); +void _gpgme_engine_set_verbosity (EngineObject engine, int verbosity); +GpgmeError _gpgme_engine_op_decrypt (EngineObject engine, GpgmeData ciph, + GpgmeData plain); +GpgmeError _gpgme_engine_op_delete (EngineObject engine, GpgmeKey key, + int allow_secret); +GpgmeError _gpgme_engine_op_encrypt (EngineObject engine, GpgmeRecipients recp, + GpgmeData plain, GpgmeData ciph, + int use_armor); +GpgmeError _gpgme_engine_op_encrypt_sign (EngineObject engine, + GpgmeRecipients recp, + GpgmeData plain, GpgmeData ciph, + int use_armor, + GpgmeCtx ctx /* FIXME */); +GpgmeError _gpgme_engine_op_export (EngineObject engine, GpgmeRecipients recp, + GpgmeData keydata, int use_armor); +GpgmeError _gpgme_engine_op_genkey (EngineObject engine, GpgmeData help_data, + int use_armor, GpgmeData pubkey, + GpgmeData seckey); +GpgmeError _gpgme_engine_op_import (EngineObject engine, GpgmeData keydata); +GpgmeError _gpgme_engine_op_keylist (EngineObject engine, const char *pattern, + int secret_only, + int keylist_mode); +GpgmeError _gpgme_engine_op_keylist_ext (EngineObject engine, + const char *pattern[], + int secret_only, + int reserved, + int keylist_mode); +GpgmeError _gpgme_engine_op_sign (EngineObject engine, GpgmeData in, + GpgmeData out, GpgmeSigMode mode, + int use_armor, int use_textmode, + int include_certs, + GpgmeCtx ctx /* FIXME */); +GpgmeError _gpgme_engine_op_trustlist (EngineObject engine, + const char *pattern); +GpgmeError _gpgme_engine_op_verify (EngineObject engine, GpgmeData sig, + GpgmeData text); +GpgmeError _gpgme_engine_start (EngineObject engine, void *opaque); + +void _gpgme_engine_add_child_to_reap_list (void *buf, int buflen, pid_t pid); +void _gpgme_engine_housecleaning (void); + +#endif /* ENGINE_H */ diff --git a/tags/V0-3-4/gpgme/export.c b/tags/V0-3-4/gpgme/export.c new file mode 100644 index 0000000..bbee68d --- /dev/null +++ b/tags/V0-3-4/gpgme/export.c @@ -0,0 +1,107 @@ +/* export.c - encrypt functions + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "util.h" +#include "context.h" +#include "ops.h" + + +static void +export_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args) +{ + if (ctx->error) + return; + + DEBUG2 ("export_status: code=%d args=`%s'\n", code, args); + /* FIXME: Need to do more */ +} + + +GpgmeError +gpgme_op_export_start (GpgmeCtx ctx, GpgmeRecipients recp, GpgmeData keydata) +{ + GpgmeError err = 0; + + fail_on_pending_request (ctx); + ctx->pending = 1; + + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + + _gpgme_release_result (ctx); + + err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS + : GPGME_PROTOCOL_OpenPGP, &ctx->engine); + if (err) + goto leave; + + if (!keydata || gpgme_data_get_type (keydata) != GPGME_DATA_TYPE_NONE) + { + err = mk_error (Invalid_Value); + goto leave; + } + _gpgme_data_set_mode (keydata, GPGME_DATA_MODE_IN); + + _gpgme_engine_set_status_handler (ctx->engine, export_status_handler, ctx); + _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); + + err = _gpgme_engine_op_export (ctx->engine, recp, keydata, ctx->use_armor); + if (!err) + err = _gpgme_engine_start (ctx->engine, ctx); + + leave: + if (err) + { + ctx->pending = 0; + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + return err; +} + + +/** + * gpgme_op_export: + * @c: the context + * @recp: a list of recipients or NULL + * @keydata: Returns the keys + * + * This function can be used to extract public keys from the GnuPG key + * database either in armored (by using gpgme_set_armor()) or in plain + * binary form. The function expects a list of user IDs in @recp for + * whom the public keys are to be exported. + * + * Return value: 0 for success or an error code + **/ +GpgmeError +gpgme_op_export (GpgmeCtx ctx, GpgmeRecipients recipients, GpgmeData keydata) +{ + GpgmeError err = gpgme_op_export_start (ctx, recipients, keydata); + if (!err) + gpgme_wait (ctx, &err, 1); + return err; +} diff --git a/tags/V0-3-4/gpgme/fopencookie.c b/tags/V0-3-4/gpgme/fopencookie.c new file mode 100644 index 0000000..7862b9a --- /dev/null +++ b/tags/V0-3-4/gpgme/fopencookie.c @@ -0,0 +1,37 @@ +/* fopencookie.c - Dummy glibc replacement + * Copyright (C) 2002 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include + +#include "util.h" + +FILE * +fopencookie (void *cookie, const char *opentype, + cookie_io_functions_t funclist) +{ + errno = ENOSYS; + return NULL; +} + + diff --git a/tags/V0-3-4/gpgme/genkey.c b/tags/V0-3-4/gpgme/genkey.c new file mode 100644 index 0000000..e8017f2 --- /dev/null +++ b/tags/V0-3-4/gpgme/genkey.c @@ -0,0 +1,224 @@ +/* genkey.c - key generation + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "util.h" +#include "context.h" +#include "ops.h" + + +struct genkey_result_s +{ + int created_primary : 1; + int created_sub : 1; +}; + + +void +_gpgme_release_genkey_result (GenKeyResult result) +{ + if (!result) + return; + xfree (result); +} + +static void +genkey_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args) +{ + _gpgme_progress_status_handler (ctx, code, args); + + if (ctx->error) + return; + test_and_allocate_result (ctx, genkey); + + switch (code) + { + case STATUS_KEY_CREATED: + if (args && *args) + { + if (*args == 'B' || *args == 'P') + ctx->result.genkey->created_primary = 1; + if (*args == 'B' || *args == 'S') + ctx->result.genkey->created_sub = 1; + } + break; + + case STATUS_EOF: + /* FIXME: Should return some more useful error value. */ + if (!ctx->result.genkey->created_primary + && !ctx->result.genkey->created_sub) + ctx->error = mk_error (General_Error); + break; + + default: + break; + } +} + + +/** + * gpgme_op_genkey: + * @c: the context + * @parms: XML string with the key parameters + * @pubkey: Returns the public key + * @seckey: Returns the secret key + * + * Generate a new key and store the key in the default keyrings if + * both @pubkey and @seckey are NULL. If @pubkey and @seckey are + * given, the newly created key will be returned in these data + * objects. This function just starts the gheneration and does not + * wait for completion. + * + * Here is an example on how @parms should be formatted; for deatils + * see the file doc/DETAILS from the GnuPG distribution. + * + * + * + * Key-Type: DSA + * Key-Length: 1024 + * Subkey-Type: ELG-E + * Subkey-Length: 1024 + * Name-Real: Joe Tester + * Name-Comment: with stupid passphrase + * Name-Email: joe@foo.bar + * Expire-Date: 0 + * Passphrase: abc + * + * ]]> + * + * + * Strings should be given in UTF-8 encoding. The format we support + * for now is only "internal". The content of the + * <GnupgKeyParms> container is passed verbatim to GnuPG. + * Control statements are not allowed. + * + * Return value: 0 for success or an error code + **/ +GpgmeError +gpgme_op_genkey_start (GpgmeCtx ctx, const char *parms, + GpgmeData pubkey, GpgmeData seckey) +{ + int err = 0; + const char *s, *s2, *sx; + + fail_on_pending_request (ctx); + ctx->pending = 1; + + gpgme_data_release (ctx->help_data_1); + ctx->help_data_1 = NULL; + + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS + : GPGME_PROTOCOL_OpenPGP, &ctx->engine); + if (err) + goto leave; + + if (!pubkey && !seckey) + ; /* okay: Add key to the keyrings */ + else if (pubkey && gpgme_data_get_type (pubkey) != GPGME_DATA_TYPE_NONE) + { + err = mk_error (Invalid_Value); + goto leave; + } + else if (seckey && gpgme_data_get_type (seckey) != GPGME_DATA_TYPE_NONE) + { + err = mk_error (Invalid_Value); + goto leave; + } + + if (pubkey) + /* FIXME: Need some more things here. */ + _gpgme_data_set_mode (pubkey, GPGME_DATA_MODE_IN); + + if (seckey) + /* FIXME: Need some more things here. */ + _gpgme_data_set_mode (seckey, GPGME_DATA_MODE_IN); + + if ((parms = strstr (parms, "')) + && (sx = strstr (parms, "format=\"internal\"")) + && sx < s + && (s2 = strstr (s+1, ""))) + { + /* FIXME: Check that there are no control statements inside. */ + s++; /* Skip '>'. */ + while (*s == '\n') + s++; + err = gpgme_data_new_from_mem (&ctx->help_data_1, s, s2-s, 1); + } + else + err = mk_error (Invalid_Value); + + if (err) + goto leave; + + _gpgme_data_set_mode (ctx->help_data_1, GPGME_DATA_MODE_OUT); + + _gpgme_engine_set_status_handler (ctx->engine, genkey_status_handler, ctx); + _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); + + err = _gpgme_engine_op_genkey (ctx->engine, ctx->help_data_1, ctx->use_armor, + pubkey, seckey); + + if (!err) + err = _gpgme_engine_start (ctx->engine, ctx); + + leave: + if (err) + { + ctx->pending = 0; + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + return err; +} + + +/** + * gpgme_op_genkey: + * @c: the context + * @parms: XML string with the key parameters + * @pubkey: Returns the public key + * @seckey: Returns the secret key + * + * Generate a new key and store the key in the default keyrings if both + * @pubkey and @seckey are NULL. If @pubkey and @seckey are given, the newly + * created key will be returned in these data objects. + * See gpgme_op_genkey_start() for a description of @parms. + * + * Return value: 0 for success or an error code + **/ +GpgmeError +gpgme_op_genkey (GpgmeCtx ctx, const char *parms, + GpgmeData pubkey, GpgmeData seckey) +{ + GpgmeError err = gpgme_op_genkey_start (ctx, parms, pubkey, seckey); + if (!err) + gpgme_wait (ctx, &err, 1); + return err; +} diff --git a/tags/V0-3-4/gpgme/gpgme-config.in b/tags/V0-3-4/gpgme/gpgme-config.in new file mode 100644 index 0000000..67bce0f --- /dev/null +++ b/tags/V0-3-4/gpgme/gpgme-config.in @@ -0,0 +1,93 @@ +#!/bin/sh + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +exec_prefix_set=no + +gpgme_libs="@GPGME_LIBS@" +gpgme_cflags="@GPGME_CFLAGS@" + + +usage() +{ + cat <&2 +fi + +while test $# -gt 0; do + case "$1" in + -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; + *) optarg= ;; + esac + + case $1 in + --prefix=*) + prefix=$optarg + if test $exec_prefix_set = no ; then + exec_prefix=$optarg + fi + ;; + --prefix) + echo_prefix=yes + ;; + --exec-prefix=*) + exec_prefix=$optarg + exec_prefix_set=yes + ;; + --exec-prefix) + echo_exec_prefix=yes + ;; + --version) + echo "@VERSION@" + exit 0 + ;; + --cflags) + echo_cflags=yes + ;; + --libs) + echo_libs=yes + ;; + *) + usage 1 1>&2 + ;; + esac + shift +done + +if test "$echo_prefix" = "yes"; then + echo $prefix +fi + +if test "$echo_exec_prefix" = "yes"; then + echo $exec_prefix +fi + +if test "$echo_cflags" = "yes"; then + if test "@includedir@" != "/usr/include" ; then + includes="-I@includedir@" + for i in $gpgme_cflags ; do + if test "$i" = "-I@includedir@" ; then + includes="" + fi + done + fi + echo $includes $gpgme_cflags +fi + +if test "$echo_libs" = "yes"; then + echo ${gpgme_libs} +fi + + diff --git a/tags/V0-3-4/gpgme/gpgme.c b/tags/V0-3-4/gpgme/gpgme.c new file mode 100644 index 0000000..1de0dc7 --- /dev/null +++ b/tags/V0-3-4/gpgme/gpgme.c @@ -0,0 +1,425 @@ +/* gpgme.c - GnuPG Made Easy + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "util.h" +#include "context.h" +#include "ops.h" + + +/** + * gpgme_new: + * @r_ctx: Returns the new context + * + * Create a new context to be used with most of the other GPGME + * functions. Use gpgme_release_context() to release all resources + * + * Return value: An error code + **/ +GpgmeError +gpgme_new (GpgmeCtx *r_ctx) +{ + GpgmeCtx ctx; + + if (!r_ctx) + return mk_error (Invalid_Value); + *r_ctx = 0; + ctx = xtrycalloc (1, sizeof *ctx); + if (!ctx) + return mk_error (Out_Of_Core); + ctx->keylist_mode = GPGME_KEYLIST_MODE_LOCAL; + ctx->verbosity = 1; + ctx->include_certs = 1; + *r_ctx = ctx; + + return 0; +} + + +/** + * gpgme_release: + * @c: Context to be released. + * + * Release all resources associated with the given context. + **/ +void +gpgme_release (GpgmeCtx ctx) +{ + if (!ctx) + return; + _gpgme_engine_release (ctx->engine); + _gpgme_release_result (ctx); + gpgme_key_release (ctx->tmp_key); + gpgme_data_release (ctx->help_data_1); + gpgme_data_release (ctx->notation); + gpgme_signers_clear (ctx); + if (ctx->signers) + xfree (ctx->signers); + /* FIXME: Release the key_queue. */ + xfree (ctx); +} + +void +_gpgme_release_result (GpgmeCtx ctx) +{ + _gpgme_release_verify_result (ctx->result.verify); + _gpgme_release_decrypt_result (ctx->result.decrypt); + _gpgme_release_sign_result (ctx->result.sign); + _gpgme_release_encrypt_result (ctx->result.encrypt); + _gpgme_release_passphrase_result (ctx->result.passphrase); + _gpgme_release_import_result (ctx->result.import); + _gpgme_release_delete_result (ctx->result.delete); + _gpgme_release_genkey_result (ctx->result.genkey); + memset (&ctx->result, 0, sizeof (ctx->result)); + _gpgme_set_op_info (ctx, NULL); + ctx->error = 0; +} + + +/** + * gpgme_cancel: + * @c: the context + * + * Cancel the current operation. It is not guaranteed that it will work for + * all kinds of operations. It is especially useful in a passphrase callback + * to stop the system from asking another time for the passphrase. + **/ +void +gpgme_cancel (GpgmeCtx ctx) +{ + return_if_fail (ctx); + + ctx->cancel = 1; +} + +/** + * gpgme_get_notation: + * @c: the context + * + * If there is notation data available from the last signature check, + * this function may be used to return this notation data as a string. + * The string is an XML represantaton of that data embedded in a + * %<notation> container. + * + * Return value: An XML string or NULL if no notation data is available. + **/ +char * +gpgme_get_notation (GpgmeCtx ctx) +{ + if (!ctx->notation) + return NULL; + return _gpgme_data_get_as_string (ctx->notation); +} + + +/** + * gpgme_get_op_info: + * @c: the context + * @reserved: + * + * Return information about the last information. The caller has to + * free the string. NULL is returned if there is not previous + * operation available or the operation has not yet finished. + * + * Here is a sample information we return: + * + * + * + * + * 17 + * 2 + * pgp-sha1 + * 01 + * 9222222 + * 121212121212121212 + * + * + * ]]> + * + * Return value: NULL for no info available or an XML string + **/ +char * +gpgme_get_op_info (GpgmeCtx ctx, int reserved) +{ + if (!ctx || reserved) + return NULL; /* Invalid value. */ + + return _gpgme_data_get_as_string (ctx->op_info); +} + + +/* + * Store the data object with the operation info in the + * context. Caller should not use that object anymore. + */ +void +_gpgme_set_op_info (GpgmeCtx ctx, GpgmeData info) +{ + assert (ctx); + + gpgme_data_release (ctx->op_info); + ctx->op_info = NULL; + + if (info) + ctx->op_info = info; +} + + +GpgmeError +gpgme_set_protocol (GpgmeCtx ctx, GpgmeProtocol protocol) +{ + if (!ctx) + return mk_error (Invalid_Value); + + switch (protocol) + { + case GPGME_PROTOCOL_OpenPGP: + ctx->use_cms = 0; + break; + case GPGME_PROTOCOL_CMS: + ctx->use_cms = 1; + break; + case GPGME_PROTOCOL_AUTO: + return mk_error (Not_Implemented); + default: + return mk_error (Invalid_Value); + } + + return 0; +} + + +/** + * gpgme_set_armor: + * @ctx: the context + * @yes: boolean value to set or clear that flag + * + * Enable or disable the use of an ascii armor for all output. + **/ +void +gpgme_set_armor (GpgmeCtx ctx, int yes) +{ + if (!ctx) + return; + ctx->use_armor = yes; +} + + +/** + * gpgme_get_armor: + * @ctx: the context + * + * Return the state of the armor flag which can be changed using + * gpgme_set_armor(). + * + * Return value: Boolean whether armor mode is to be used. + **/ +int +gpgme_get_armor (GpgmeCtx ctx) +{ + return ctx && ctx->use_armor; +} + + +/** + * gpgme_set_textmode: + * @ctx: the context + * @yes: boolean flag whether textmode should be enabled + * + * Enable or disable the use of the special textmode. Textmode is for example + * used for the RFC2015 signatures; note that the updated RFC 3156 mandates + * that the MUA does some preparations so that textmode is not needed anymore. + **/ +void +gpgme_set_textmode (GpgmeCtx ctx, int yes) +{ + if (!ctx) + return; + ctx->use_textmode = yes; +} + +/** + * gpgme_get_textmode: + * @ctx: the context + * + * Return the state of the textmode flag which can be changed using + * gpgme_set_textmode(). + * + * Return value: Boolean whether textmode is to be used. + **/ +int +gpgme_get_textmode (GpgmeCtx ctx) +{ + return ctx && ctx->use_textmode; +} + + +/** + * gpgme_set_include_certs: + * @ctx: the context + * + * Set the number of certifications to include in an S/MIME message. + * The default is 1 (only the cert of the sender). -1 means all certs, + * and -2 means all certs except the root cert. + * + * Return value: Boolean whether textmode is to be used. + **/ +void +gpgme_set_include_certs (GpgmeCtx ctx, int nr_of_certs) +{ + if (nr_of_certs < -2) + ctx->include_certs = -2; + else + ctx->include_certs = nr_of_certs; +} + + +/** + * gpgme_get_include_certs: + * @ctx: the context + * + * Get the number of certifications to include in an S/MIME message. + * + * Return value: Boolean whether textmode is to be used. + **/ +int +gpgme_get_include_certs (GpgmeCtx ctx) +{ + return ctx->include_certs; +} + + +/** + * gpgme_set_keylist_mode: + * @ctx: the context + * @mode: listing mode + * + * This function changes the default behaviour of the keylisting + * functions. mode is a bitwise-OR of the GPGME_KEYLIST_* flags. + * The default mode is GPGME_KEYLIST_MODE_LOCAL. + * + * Return value: GPGME_Invalid_Value if ctx is not a context or mode + * not a valid mode. + **/ +GpgmeError +gpgme_set_keylist_mode (GpgmeCtx ctx, int mode) +{ + if (!ctx) + return mk_error (Invalid_Value); + + if (!((mode & GPGME_KEYLIST_MODE_LOCAL) + || (mode & GPGME_KEYLIST_MODE_EXTERN))) + return mk_error (Invalid_Value); + + ctx->keylist_mode = mode; + return 0; +} + + +/** + * gpgme_get_keylist_mode: + * @ctx: the context + * + * This function ch the default behaviour of the keylisting functions. + * Defines values for @mode are: %0 = normal, %1 = fast listing without + * information about key validity. + * + * Return value: 0 if ctx is not a valid context, or the current mode. + * Note that 0 is never a valid mode. + **/ +int +gpgme_get_keylist_mode (GpgmeCtx ctx) +{ + if (!ctx) + return 0; + return ctx->keylist_mode; +} + + +/** + * gpgme_set_passphrase_cb: + * @ctx: the context + * @cb: A callback function + * @cb_value: The value passed to the callback function + * + * This function sets a callback function to be used to pass a passphrase + * to gpg. The preferred way to handle this is by using the gpg-agent, but + * because that beast is not ready for real use, you can use this passphrase + * thing. + * + * The callback function is defined as: + * + * typedef const char *(*GpgmePassphraseCb)(void*cb_value, + * const char *desc, + * void **r_hd); + * + * and called whenever gpgme needs a passphrase. DESC will have a nice + * text, to be used to prompt for the passphrase and R_HD is just a parameter + * to be used by the callback it self. Because the callback returns a const + * string, the callback might want to know when it can release resources + * assocated with that returned string; gpgme helps here by calling this + * passphrase callback with an DESC of %NULL as soon as it does not need + * the returned string anymore. The callback function might then choose + * to release resources depending on R_HD. + * + **/ +void +gpgme_set_passphrase_cb (GpgmeCtx ctx, GpgmePassphraseCb cb, void *cb_value) +{ + if (ctx) + { + ctx->passphrase_cb = cb; + ctx->passphrase_cb_value = cb_value; + } +} + +/** + * gpgme_set_progress_cb: + * @ctx: the context + * @cb: A callback function + * @cb_value: The value passed to the callback function + * + * This function sets a callback function to be used as a progress indicator. + * + * The callback function is defined as: + * + * typedef void (*GpgmeProgressCb) (void *cb_value, + * const char *what, int type, + * int curretn, int total); + * + * For details on the progress events, see the entry for the PROGRESS + * status in the file doc/DETAILS of the GnuPG distribution. + **/ +void +gpgme_set_progress_cb (GpgmeCtx ctx, GpgmeProgressCb cb, void *cb_value) +{ + if (ctx) + { + ctx->progress_cb = cb; + ctx->progress_cb_value = cb_value; + } +} diff --git a/tags/V0-3-4/gpgme/gpgme.h b/tags/V0-3-4/gpgme/gpgme.h new file mode 100644 index 0000000..66419d2 --- /dev/null +++ b/tags/V0-3-4/gpgme/gpgme.h @@ -0,0 +1,554 @@ +/* gpgme.h - GnuPG Made Easy + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef GPGME_H +#define GPGME_H + +#include /* For FILE *. */ +#ifdef _MSC_VER + typedef long off_t; +#else +# include +#endif + +#ifdef __cplusplus +extern "C" { +#if 0 /* just to make Emacs auto-indent happy */ +} +#endif +#endif + + +/* The version of this header should match the one of the library. Do + not use this symbol in your application, use gpgme_check_version + instead. The purpose of this macro is to let autoconf (using the + AM_PATH_GPGME macro) check that this header matches the installed + library. Warning: Do not edit the next line. configure will do + that for you! */ +#define GPGME_VERSION "0.3.4" + + +/* The opaque data types used by GPGME. */ + +/* The context holds some global state and configration options as + well as the results of a crypto operation. */ +struct gpgme_context_s; +typedef struct gpgme_context_s *GpgmeCtx; + +/* The data object used by GPGME to exchange arbitrary data. */ +struct gpgme_data_s; +typedef struct gpgme_data_s *GpgmeData; + +/* A list of recipients to be used in an encryption operation. */ +struct gpgme_recipients_s; +typedef struct gpgme_recipients_s *GpgmeRecipients; + +/* A key from the keyring. */ +struct gpgme_key_s; +typedef struct gpgme_key_s *GpgmeKey; + +/* A trust item. */ +struct gpgme_trust_item_s; +typedef struct gpgme_trust_item_s *GpgmeTrustItem; + + +/* The error numbers used by GPGME. */ +typedef enum + { + GPGME_EOF = -1, + GPGME_No_Error = 0, + GPGME_General_Error = 1, + GPGME_Out_Of_Core = 2, + GPGME_Invalid_Value = 3, + GPGME_Busy = 4, + GPGME_No_Request = 5, + GPGME_Exec_Error = 6, + GPGME_Too_Many_Procs = 7, + GPGME_Pipe_Error = 8, + GPGME_No_Recipients = 9, + GPGME_No_Data = 10, + GPGME_Conflict = 11, + GPGME_Not_Implemented = 12, + GPGME_Read_Error = 13, + GPGME_Write_Error = 14, + GPGME_Invalid_Type = 15, + GPGME_Invalid_Mode = 16, + GPGME_File_Error = 17, /* errno is set in this case. */ + GPGME_Decryption_Failed = 18, + GPGME_No_Passphrase = 19, + GPGME_Canceled = 20, + GPGME_Invalid_Key = 21, + GPGME_Invalid_Engine = 22, + GPGME_Invalid_Recipients = 23 + } +GpgmeError; + +/* The possible types of GpgmeData objects. */ +typedef enum + { + GPGME_DATA_TYPE_NONE = 0, + GPGME_DATA_TYPE_MEM = 1, + GPGME_DATA_TYPE_FD = 2, + GPGME_DATA_TYPE_FILE = 3, + GPGME_DATA_TYPE_CB = 4 + } +GpgmeDataType; + +/* The possible signature stati. */ +typedef enum + { + GPGME_SIG_STAT_NONE = 0, + GPGME_SIG_STAT_GOOD = 1, + GPGME_SIG_STAT_BAD = 2, + GPGME_SIG_STAT_NOKEY = 3, + GPGME_SIG_STAT_NOSIG = 4, + GPGME_SIG_STAT_ERROR = 5, + GPGME_SIG_STAT_DIFF = 6 + } +GpgmeSigStat; + +/* The available signature modes. */ +typedef enum + { + GPGME_SIG_MODE_NORMAL = 0, + GPGME_SIG_MODE_DETACH = 1, + GPGME_SIG_MODE_CLEAR = 2 + } +GpgmeSigMode; + +/* The available key attributes. */ +typedef enum + { + GPGME_ATTR_KEYID = 1, + GPGME_ATTR_FPR = 2, + GPGME_ATTR_ALGO = 3, + GPGME_ATTR_LEN = 4, + GPGME_ATTR_CREATED = 5, + GPGME_ATTR_EXPIRE = 6, + GPGME_ATTR_OTRUST = 7, + GPGME_ATTR_USERID = 8, + GPGME_ATTR_NAME = 9, + GPGME_ATTR_EMAIL = 10, + GPGME_ATTR_COMMENT = 11, + GPGME_ATTR_VALIDITY = 12, + GPGME_ATTR_LEVEL = 13, + GPGME_ATTR_TYPE = 14, + GPGME_ATTR_IS_SECRET = 15, + GPGME_ATTR_KEY_REVOKED = 16, + GPGME_ATTR_KEY_INVALID = 17, + GPGME_ATTR_UID_REVOKED = 18, + GPGME_ATTR_UID_INVALID = 19, + GPGME_ATTR_KEY_CAPS = 20, + GPGME_ATTR_CAN_ENCRYPT = 21, + GPGME_ATTR_CAN_SIGN = 22, + GPGME_ATTR_CAN_CERTIFY = 23, + GPGME_ATTR_KEY_EXPIRED = 24, + GPGME_ATTR_KEY_DISABLED = 25 + } +GpgmeAttr; + +/* The available validities for a trust item or key. */ +typedef enum + { + GPGME_VALIDITY_UNKNOWN = 0, + GPGME_VALIDITY_UNDEFINED = 1, + GPGME_VALIDITY_NEVER = 2, + GPGME_VALIDITY_MARGINAL = 3, + GPGME_VALIDITY_FULL = 4, + GPGME_VALIDITY_ULTIMATE = 5 + } +GpgmeValidity; + +/* The available protocols. */ +typedef enum + { + GPGME_PROTOCOL_OpenPGP = 0, /* The default mode. */ + GPGME_PROTOCOL_CMS = 1, + GPGME_PROTOCOL_AUTO = 2 + } +GpgmeProtocol; + + +/* The available keylist mode flags. */ +#define GPGME_KEYLIST_MODE_LOCAL 1 +#define GPGME_KEYLIST_MODE_EXTERN 2 + + +/* Types for callback functions. */ + +/* Request a passphrase from the user. */ +typedef const char *(*GpgmePassphraseCb) (void *hook, const char *desc, + void **r_hd); + +/* Inform the user about progress made. */ +typedef void (*GpgmeProgressCb) (void *opaque, const char *what, + int type, int current, int total); + + +/* Context management functions. */ + +/* Create a new context and return it in CTX. */ +GpgmeError gpgme_new (GpgmeCtx *ctx); + +/* Release the context CTX. */ +void gpgme_release (GpgmeCtx ctx); + +/* Retrieve more info about performed signature check. */ +char *gpgme_get_notation (GpgmeCtx ctx); + +/* Set the protocol to be used by CTX to PROTO. */ +GpgmeError gpgme_set_protocol (GpgmeCtx ctx, GpgmeProtocol proto); + +/* If YES is non-zero, enable armor mode in CTX, disable it otherwise. */ +void gpgme_set_armor (GpgmeCtx ctx, int yes); + +/* Return non-zero if armor mode is set in CTX. */ +int gpgme_get_armor (GpgmeCtx ctx); + +/* If YES is non-zero, enable text mode in CTX, disable it otherwise. */ +void gpgme_set_textmode (GpgmeCtx ctx, int yes); + +/* Return non-zero if text mode is set in CTX. */ +int gpgme_get_textmode (GpgmeCtx ctx); + +/* Include up to NR_OF_CERTS certificates in an S/MIME message. */ +void gpgme_set_include_certs (GpgmeCtx ctx, int nr_of_certs); + +/* Return the number of certs to include in an S/MIME message. */ +int gpgme_get_include_certs (GpgmeCtx ctx); + +/* Set keylist mode in CTX to MODE. */ +GpgmeError gpgme_set_keylist_mode (GpgmeCtx ctx, int mode); + +/* Get keylist mode in CTX. */ +int gpgme_get_keylist_mode (GpgmeCtx ctx); + +/* Set the passphrase callback function in CTX to CB. HOOK_VALUE is + passed as first argument to the passphrase callback function. */ +void gpgme_set_passphrase_cb (GpgmeCtx ctx, + GpgmePassphraseCb cb, void *hook_value); + +/* Set the progress callback function in CTX to CB. HOOK_VALUE is + passed as first argument to the progress callback function. */ +void gpgme_set_progress_cb (GpgmeCtx c, GpgmeProgressCb cb, void *hook_value); + +/* Delete all signers from CTX. */ +void gpgme_signers_clear (GpgmeCtx ctx); + +/* Add KEY to list of signers in CTX. */ +GpgmeError gpgme_signers_add (GpgmeCtx ctx, const GpgmeKey key); + +/* Return the SEQth signer's key in CTX. */ +GpgmeKey gpgme_signers_enum (const GpgmeCtx ctx, int seq); + +/* Retrieve the signature status of signature IDX in CTX after a + successful verify operation in R_STAT (if non-null). The creation + time stamp of the signature is returned in R_CREATED (if non-null). + The function returns a string containing the fingerprint. */ +const char *gpgme_get_sig_status (GpgmeCtx ctx, int idx, + GpgmeSigStat *r_stat, time_t *r_created); + +/* Get the key used to create signature IDX in CTX and return it in + R_KEY. */ +GpgmeError gpgme_get_sig_key (GpgmeCtx ctx, int idx, GpgmeKey *r_key); + +/* Return a string with more info about the last crypto operating in CTX. + RESERVED should be zero. The user has to free the string. */ +char *gpgme_get_op_info (GpgmeCtx ctx, int reserved); + + +/* Run control. */ + +/* Cancel a pending operation in CTX. */ +void gpgme_cancel (GpgmeCtx ctx); + +/* Process the pending operation and, if HANG is non-zero, wait for + the pending operation to finish. */ +GpgmeCtx gpgme_wait (GpgmeCtx ctx, GpgmeError *status, int hang); + + +/* Functions to handle recipients. */ + +/* Create a new recipients set and return it in R_RSET. */ +GpgmeError gpgme_recipients_new (GpgmeRecipients *r_rset); + +/* Release the recipients set RSET. */ +void gpgme_recipients_release (GpgmeRecipients rset); + +/* Add NAME to the recipients set RSET. */ +GpgmeError gpgme_recipients_add_name (GpgmeRecipients rset, const char *name); + +/* Add NAME with validity AL to the recipients set RSET. */ +GpgmeError gpgme_recipients_add_name_with_validity (GpgmeRecipients rset, + const char *name, + GpgmeValidity val); + +/* Return the number of recipients in RSET. */ +unsigned int gpgme_recipients_count (const GpgmeRecipients rset); + +/* Create a new enumeration handle for the recipients set RSET and + return it in ITER. */ +GpgmeError gpgme_recipients_enum_open (const GpgmeRecipients rset, + void **iter); + +/* Return the next recipient from the recipient set RSET in the + enumerator ITER. */ +const char *gpgme_recipients_enum_read (const GpgmeRecipients rset, + void **iter); + +/* Destroy the enumerator ITER for the recipient set RSET. */ +GpgmeError gpgme_recipients_enum_close (const GpgmeRecipients rset, + void **iter); + + +/* Functions to handle data objects. */ + +/* Create a new data buffer and return it in R_DH. */ +GpgmeError gpgme_data_new (GpgmeData *r_dh); + +/* Create a new data buffer filled with SIZE bytes starting from + BUFFER. If COPY is zero, copying is delayed until necessary, and + the data is taken from the original location when needed. */ +GpgmeError gpgme_data_new_from_mem (GpgmeData *r_dh, + const char *buffer, size_t size, + int copy); + +/* Create a new data buffer which retrieves the data from the callback + function READ_CB. */ +GpgmeError gpgme_data_new_with_read_cb (GpgmeData *r_dh, + int (*read_cb) (void*,char *,size_t,size_t*), + void *read_cb_value); + +/* Create a new data buffer filled with the content of file FNAME. + COPY must be non-zero (delayed reads are not supported yet). */ +GpgmeError gpgme_data_new_from_file (GpgmeData *r_dh, + const char *fname, + int copy); + +/* Create a new data buffer filled with LENGTH bytes starting from + OFFSET within the file FNAME or stream FP (exactly one must be + non-zero). */ +GpgmeError gpgme_data_new_from_filepart (GpgmeData *r_dh, + const char *fname, FILE *fp, + off_t offset, size_t length); + +/* Destroy the data buffer DH. */ +void gpgme_data_release (GpgmeData dh); + +/* Destroy the data buffer DH and return a pointer to its content. + The memory has be to released with free by the user. It's size is + returned in R_LEN. */ +char *gpgme_data_release_and_get_mem (GpgmeData dh, size_t *r_len); + +/* Return the type of the data buffer DH. */ +GpgmeDataType gpgme_data_get_type (GpgmeData dh); + +/* Reset the read pointer in DH. */ +GpgmeError gpgme_data_rewind (GpgmeData dh); + +/* Read LENGTH bytes from the data object DH and store them in the + memory starting at BUFFER. The number of bytes actually read is + returned in NREAD. */ +GpgmeError gpgme_data_read (GpgmeData dh, char *buffer, + size_t length, size_t *nread); + +/* Write LENGTH bytes starting from BUFFER into the data object DH. */ +GpgmeError gpgme_data_write (GpgmeData dh, const char *buffer, size_t length); + + +/* Key and trust functions. */ + +/* Acquire a reference to KEY. */ +void gpgme_key_ref (GpgmeKey key); + +/* Release a reference to KEY. If this was the last one the key is + destroyed. */ +void gpgme_key_unref (GpgmeKey key); +void gpgme_key_release (GpgmeKey key); + +/* Get the data from key KEY in a XML string, which has to be released + with free by the user. */ +char *gpgme_key_get_as_xml (GpgmeKey key); + +/* Return the value of the attribute WHAT of KEY, which has to be + representable by a string. IDX specifies a running index if the + attribute appears more than once in the key. */ +const char *gpgme_key_get_string_attr (GpgmeKey key, GpgmeAttr what, + const void *reserved, int idx); + +/* Return the value of the attribute WHAT of KEY, which has to be + representable by an unsigned integer. IDX specifies a running + index if the attribute appears more than once in the key. */ +unsigned long gpgme_key_get_ulong_attr (GpgmeKey key, GpgmeAttr what, + const void *reserved, int idx); + +/* Release the trust item ITEM. */ +void gpgme_trust_item_release (GpgmeTrustItem item); + +/* Return the value of the attribute WHAT of ITEM, which has to be + representable by a string. IDX specifies a running index if the + attribute appears more than once in the key. */ +const char *gpgme_trust_item_get_string_attr (GpgmeTrustItem item, + GpgmeAttr what, + const void *reserved, int idx); + +/* Return the value of the attribute WHAT of KEY, which has to be + representable by an integer. IDX specifies a running index if the + attribute appears more than once in the key. */ +int gpgme_trust_item_get_int_attr (GpgmeTrustItem item, GpgmeAttr what, + const void *reserved, int idx); + + +/* Crypto operation function. */ + +/* Encrypt plaintext PLAIN within CTX for the recipients RECP and + store the resulting ciphertext in CIPHER. */ +GpgmeError gpgme_op_encrypt_start (GpgmeCtx ctx, + GpgmeRecipients recp, + GpgmeData plain, GpgmeData cipher); +GpgmeError gpgme_op_encrypt (GpgmeCtx ctx, + GpgmeRecipients recp, + GpgmeData plain, GpgmeData cipher); + +/* Encrypt plaintext PLAIN within CTX for the recipients RECP and + store the resulting ciphertext in CIPHER. Also sign the ciphertext + with the signers in CTX. */ +GpgmeError gpgme_op_encrypt_sign_start (GpgmeCtx ctx, + GpgmeRecipients recp, + GpgmeData plain, GpgmeData cipher); +GpgmeError gpgme_op_encrypt_sign (GpgmeCtx ctx, + GpgmeRecipients recp, + GpgmeData plain, GpgmeData cipher); + +/* Decrypt ciphertext CIPHER within CTX and store the resulting + plaintext in PLAIN. */ +GpgmeError gpgme_op_decrypt_start (GpgmeCtx ctx, + GpgmeData cipher, GpgmeData plain); +GpgmeError gpgme_op_decrypt (GpgmeCtx ctx, + GpgmeData cipher, GpgmeData plain); + +/* Decrypt ciphertext CIPHER and make a signature verification within + CTX and store the resulting plaintext in PLAIN. */ +GpgmeError gpgme_op_decrypt_verify_start (GpgmeCtx ctx, + GpgmeData cipher, GpgmeData plain); +GpgmeError gpgme_op_decrypt_verify (GpgmeCtx ctx, + GpgmeData cipher, GpgmeData plain, + GpgmeSigStat *r_status); + +/* Sign the plaintext PLAIN and store the signature in SIG. Only + detached signatures are supported for now. */ +GpgmeError gpgme_op_sign_start (GpgmeCtx ctx, + GpgmeData plain, GpgmeData sig, + GpgmeSigMode mode); +GpgmeError gpgme_op_sign (GpgmeCtx ctx, + GpgmeData plain, GpgmeData sig, + GpgmeSigMode mode); + +/* Verify within CTX that SIG is a valid signature for TEXT. */ +GpgmeError gpgme_op_verify_start (GpgmeCtx ctx, + GpgmeData sig, GpgmeData text); +GpgmeError gpgme_op_verify (GpgmeCtx ctx, + GpgmeData sig, GpgmeData text, + GpgmeSigStat *r_status); + +/* Import the key in KEYDATA into the keyring. */ +GpgmeError gpgme_op_import_start (GpgmeCtx ctx, GpgmeData keydata); +GpgmeError gpgme_op_import (GpgmeCtx ctx, GpgmeData keydata); + +/* Export the keys listed in RECP into KEYDATA. */ +GpgmeError gpgme_op_export_start (GpgmeCtx ctx, GpgmeRecipients recp, + GpgmeData keydata); +GpgmeError gpgme_op_export (GpgmeCtx ctx, GpgmeRecipients recp, + GpgmeData keydata); + +/* Generate a new keypair and add it to the keyring. PUBKEY and + SECKEY should be null for now. PARMS specifies what keys should be + generated. */ +GpgmeError gpgme_op_genkey_start (GpgmeCtx ctx, const char *parms, + GpgmeData pubkey, GpgmeData seckey); +GpgmeError gpgme_op_genkey (GpgmeCtx ctx, const char *parms, + GpgmeData pubkey, GpgmeData seckey); + +/* Delete KEY from the keyring. If ALLOW_SECRET is non-zero, secret + keys are also deleted. */ +GpgmeError gpgme_op_delete_start (GpgmeCtx ctx, const GpgmeKey key, + int allow_secret); +GpgmeError gpgme_op_delete (GpgmeCtx ctx, const GpgmeKey key, + int allow_secret); + + +/* Key management functions */ + +/* Start a keylist operation within CTX, searching for keys which + match PATTERN. If SECRET_ONLY is true, only secret keys are + returned. */ +GpgmeError gpgme_op_keylist_start (GpgmeCtx ctx, + const char *pattern, int secret_only); + +/* Return the next key from the keylist in R_KEY. */ +GpgmeError gpgme_op_keylist_next (GpgmeCtx ctx, GpgmeKey *r_key); + +/* Terminate a pending keylist operation within CTX. */ +GpgmeError gpgme_op_keylist_end (GpgmeCtx ctx); + + +/* Start a trustlist operation within CTX, searching for trust items + which match PATTERN. */ +GpgmeError gpgme_op_trustlist_start (GpgmeCtx ctx, + const char *pattern, int max_level); + +/* Return the next trust item from the trustlist in R_ITEM. */ +GpgmeError gpgme_op_trustlist_next (GpgmeCtx ctx, GpgmeTrustItem *r_item); + +/* Terminate a pending trustlist operation within CTX. */ +GpgmeError gpgme_op_trustlist_end (GpgmeCtx ctx); + + +/* Various functions. */ + +/* Check that the library fulfills the version requirement. */ +const char *gpgme_check_version (const char *req_version); + +/* Check that the backend engine is available. DEPRECATED. */ +GpgmeError gpgme_check_engine (void); + +/* Retrieve information about the backend engines. */ +const char *gpgme_get_engine_info (void); + +/* Return a string describing ERR. */ +const char *gpgme_strerror (GpgmeError err); + +/* Register an idle function. */ +typedef void (*GpgmeIdleFunc)(void); +GpgmeIdleFunc gpgme_register_idle (GpgmeIdleFunc idle); + + +/* Engine support functions. */ + +/* Verify that the engine implementing PROTO is installed and + available. */ +GpgmeError gpgme_engine_check_version (GpgmeProtocol proto); + + +#ifdef __cplusplus +} +#endif +#endif /* GPGME_H */ diff --git a/tags/V0-3-4/gpgme/gpgme.m4 b/tags/V0-3-4/gpgme/gpgme.m4 new file mode 100644 index 0000000..1fb0260 --- /dev/null +++ b/tags/V0-3-4/gpgme/gpgme.m4 @@ -0,0 +1,170 @@ +dnl Autoconf macros for libgpgme +dnl $Id$ + +# Configure paths for GPGME +# Shamelessly stolen from the one of XDELTA by Owen Taylor +# Werner Koch 2000-11-17 + +dnl AM_PATH_GPGME([MINIMUM-VERSION, +dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]]) +dnl Test for gpgme, and define GPGME_CFLAGS and GPGME_LIBS +dnl +AC_DEFUN(AM_PATH_GPGME, +[dnl +dnl Get the cflags and libraries from the gpgme-config script +dnl + AC_ARG_WITH(gpgme-prefix, + [ --with-gpgme-prefix=PFX Prefix where gpgme is installed (optional)], + gpgme_config_prefix="$withval", gpgme_config_prefix="") + AC_ARG_ENABLE(gpgmetest, + [ --disable-gpgmetest Do not try to compile and run a test gpgme program], + , enable_gpgmetest=yes) + + if test x$gpgme_config_prefix != x ; then + gpgme_config_args="$gpgme_config_args --prefix=$gpgme_config_prefix" + if test x${GPGME_CONFIG+set} != xset ; then + GPGME_CONFIG=$gpgme_config_prefix/bin/gpgme-config + fi + fi + + AC_PATH_PROG(GPGME_CONFIG, gpgme-config, no) + min_gpgme_version=ifelse([$1], ,1.0.0,$1) + AC_MSG_CHECKING(for GPGME - version >= $min_gpgme_version) + no_gpgme="" + if test "$GPGME_CONFIG" = "no" ; then + no_gpgme=yes + else + GPGME_CFLAGS=`$GPGME_CONFIG $gpgme_config_args --cflags` + GPGME_LIBS=`$GPGME_CONFIG $gpgme_config_args --libs` + gpgme_config_version=`$GPGME_CONFIG $gpgme_config_args --version` + if test "x$enable_gpgmetest" = "xyes" ; then + ac_save_CFLAGS="$CFLAGS" + ac_save_LIBS="$LIBS" + CFLAGS="$CFLAGS $GPGME_CFLAGS" + LIBS="$LIBS $GPGME_LIBS" +dnl +dnl Now check if the installed gpgme is sufficiently new. Also sanity +dnl checks the results of gpgme-config to some extent +dnl + rm -f conf.gpgmetest + AC_TRY_RUN([ +#include +#include +#include +#include + +int +main () +{ + system ("touch conf.gpgmetest"); + + if( strcmp( gpgme_check_version(NULL), "$gpgme_config_version" ) ) + { + printf("\n" +"*** 'gpgme-config --version' returned %s, but GPGME (%s) was found!\n", + "$gpgme_config_version", gpgme_check_version(NULL) ); + printf( +"*** If gpgme-config was correct, then it is best to remove the old\n" +"*** version of GPGME. You may also be able to fix the error\n" +"*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n" +"*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n" +"*** required on your system.\n" +"*** If gpgme-config was wrong, set the environment variable GPGME_CONFIG\n" +"*** to point to the correct copy of gpgme-config, \n" +"*** and remove the file config.cache before re-running configure\n" + ); + } + else if ( strcmp(gpgme_check_version(NULL), GPGME_VERSION ) ) + { + printf("\n*** GPGME header file (version %s) does not match\n", + GPGME_VERSION); + printf("*** library (version %s)\n", gpgme_check_version(NULL) ); + } + else + { + if ( gpgme_check_version( "$min_gpgme_version" ) ) + return 0; + printf("no\n" +"*** An old version of GPGME (%s) was found.\n", gpgme_check_version(NULL) ); + printf( +"*** You need a version of GPGME newer than %s.\n", "$min_gpgme_version" ); + printf( +"*** The latest version of GPGME is always available at\n" +"*** ftp://ftp.gnupg.org/pub/gcrypt/alpha/gpgme/\n" +"*** \n" +"*** If you have already installed a sufficiently new version, this error\n" +"*** probably means that the wrong copy of the gpgme-config shell script is\n" +"*** being found. The easiest way to fix this is to remove the old version\n" +"*** of GPGME, but you can also set the GPGME_CONFIG environment to point to\n" +"*** the correct copy of gpgme-config. (In this case, you will have to\n" +"*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n" +"*** so that the correct libraries are found at run-time).\n" + ); + } + return 1; +} +],, no_gpgme=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) + CFLAGS="$ac_save_CFLAGS" + LIBS="$ac_save_LIBS" + fi + fi + if test "x$no_gpgme" = x ; then + AC_MSG_RESULT(yes) + ifelse([$2], , :, [$2]) + else + if test -f conf.gpgmetest ; then + : + else + AC_MSG_RESULT(no) + fi + if test "$GPGME_CONFIG" = "no" ; then + echo "*** The gpgme-config script installed by GPGME could not be found" + echo "*** If GPGME was installed in PREFIX, make sure PREFIX/bin is in" + echo "*** your path, or set the GPGME_CONFIG environment variable to the" + echo "*** full path to gpgme-config." + else + if test -f conf.gpgmetest ; then + : + else + echo "*** Could not run gpgme test program, checking why..." + CFLAGS="$CFLAGS $GPGME_CFLAGS" + LIBS="$LIBS $GPGME_LIBS" + AC_TRY_LINK([ +#include +#include +#include +#include +], [ gpgme_check_version(NULL); return 0 ], + [ +echo "*** The test program compiled, but did not run. This usually means" +echo "*** that the run-time linker is not finding GPGME or finding the wrong" +echo "*** version of GPGME. If it is not finding GPGME, you'll need to set your" +echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" +echo "*** to the installed location Also, make sure you have run ldconfig if" +echo "*** that is required on your system" +echo "***" +echo "*** If you have an old version installed, it is best to remove it," +echo "*** although you may also be able to get things to work by" +echo "*** modifying LD_LIBRARY_PATH" +echo "***" + ], + [ +echo "*** The test program failed to compile or link. See the file config.log" +echo "*** for the exact error that occured. This usually means GPGME was" +echo "*** incorrectly installed or that you have moved GPGME since it was" +echo "*** installed. In the latter case, you may want to edit the" +echo "*** gpgme-config script: $GPGME_CONFIG" + ]) + CFLAGS="$ac_save_CFLAGS" + LIBS="$ac_save_LIBS" + fi + fi + GPGME_CFLAGS="" + GPGME_LIBS="" + ifelse([$3], , :, [$3]) + fi + AC_SUBST(GPGME_CFLAGS) + AC_SUBST(GPGME_LIBS) + rm -f conf.gpgmetest +]) + diff --git a/tags/V0-3-4/gpgme/import.c b/tags/V0-3-4/gpgme/import.c new file mode 100644 index 0000000..6d07051 --- /dev/null +++ b/tags/V0-3-4/gpgme/import.c @@ -0,0 +1,223 @@ +/* import.c - encrypt functions + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "util.h" +#include "context.h" +#include "ops.h" + + +struct import_result_s +{ + GpgmeData xmlinfo; +}; + + +void +_gpgme_release_import_result (ImportResult result) +{ + if (!result) + return; + gpgme_data_release (result->xmlinfo); + xfree (result); +} + + +/* Parse the args and append the information to the XML structure in + the data buffer. With args of NULL the xml structure is + closed. */ +static void +append_xml_impinfo (GpgmeData *rdh, GpgStatusCode code, char *args) +{ +#define MAX_IMPORTED_FIELDS 14 + static char *imported_fields[MAX_IMPORTED_FIELDS] + = { "keyid", "username", 0 }; + static char *import_res_fields[MAX_IMPORTED_FIELDS] + = { "count", "no_user_id", "imported", "imported_rsa", + "unchanged", "n_uids", "n_subk", "n_sigs", "s_sigsn_revoc", + "sec_read", "sec_imported", "sec_dups", "skipped_new", 0 }; + char *field[MAX_IMPORTED_FIELDS]; + char **field_name = 0; + GpgmeData dh; + int i; + + /* Verify that we can use the args. */ + if (code != STATUS_EOF) + { + if (!args) + return; + + if (code == STATUS_IMPORTED) + field_name = imported_fields; + else if (code == STATUS_IMPORT_RES) + field_name = import_res_fields; + else + return; + + for (i = 0; field_name[i]; i++) + { + field[i] = args; + if (field_name[i + 1]) + { + args = strchr (args, ' '); + if (!args) + return; /* Invalid line. */ + *args++ = '\0'; + } + } + } + + /* Initialize the data buffer if necessary. */ + if (!*rdh) + { + if (gpgme_data_new (rdh)) + return; /* FIXME: We are ignoring out-of-core. */ + dh = *rdh; + _gpgme_data_append_string (dh, "\n"); + } + else + dh = *rdh; + + if (code == STATUS_EOF) + { + /* Just close the XML containter. */ + _gpgme_data_append_string (dh, "\n"); + } + else + { + if (code == STATUS_IMPORTED) + _gpgme_data_append_string (dh, " \n"); + else if (code == STATUS_IMPORT_RES) + _gpgme_data_append_string (dh, " \n"); + + for (i = 0; field_name[i]; i++) + { + _gpgme_data_append_string (dh, " <"); + _gpgme_data_append_string (dh, field_name[i]); + _gpgme_data_append_string (dh, ">"); + _gpgme_data_append_string (dh, field[i]); + _gpgme_data_append_string (dh, "\n"); + } + + if (code == STATUS_IMPORTED) + _gpgme_data_append_string (dh, " \n"); + else if (code == STATUS_IMPORT_RES) + _gpgme_data_append_string (dh, " \n"); + } +} + + +static void +import_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args) +{ + if (ctx->error) + return; + test_and_allocate_result (ctx, import); + + switch (code) + { + case STATUS_EOF: + if (ctx->result.import->xmlinfo) + { + append_xml_impinfo (&ctx->result.import->xmlinfo, code, NULL); + _gpgme_set_op_info (ctx, ctx->result.import->xmlinfo); + ctx->result.import->xmlinfo = NULL; + } + /* XXX Calculate error value. */ + break; + + case STATUS_IMPORTED: + case STATUS_IMPORT_RES: + append_xml_impinfo (&ctx->result.import->xmlinfo, code, args); + break; + + default: + break; + } +} + + +GpgmeError +gpgme_op_import_start (GpgmeCtx ctx, GpgmeData keydata) +{ + int err = 0; + + fail_on_pending_request (ctx); + ctx->pending = 1; + + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS + : GPGME_PROTOCOL_OpenPGP, &ctx->engine); + if (err) + goto leave; + + /* Check the supplied data */ + if (gpgme_data_get_type (keydata) == GPGME_DATA_TYPE_NONE) + { + err = mk_error (No_Data); + goto leave; + } + _gpgme_data_set_mode (keydata, GPGME_DATA_MODE_OUT); + + _gpgme_engine_set_status_handler (ctx->engine, import_status_handler, ctx); + _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); + + _gpgme_engine_op_import (ctx->engine, keydata); + + if (!err) + err = _gpgme_engine_start (ctx->engine, ctx); + + leave: + if (err) + { + ctx->pending = 0; + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + return err; +} + + +/** + * gpgme_op_import: + * @c: Context + * @keydata: Data object + * + * Import all key material from @keydata into the key database. + * + * Return value: o on success or an error code. + **/ +GpgmeError +gpgme_op_import (GpgmeCtx ctx, GpgmeData keydata) +{ + GpgmeError err = gpgme_op_import_start (ctx, keydata); + if (!err) + gpgme_wait (ctx, &err, 1); + return err; +} diff --git a/tags/V0-3-4/gpgme/io.h b/tags/V0-3-4/gpgme/io.h new file mode 100644 index 0000000..0965a1d --- /dev/null +++ b/tags/V0-3-4/gpgme/io.h @@ -0,0 +1,71 @@ +/* io.h - I/O functions + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef IO_H +#define IO_H + +#include "types.h" + +struct spawn_fd_item_s { + int fd; + int dup_to; +}; + + +struct io_select_fd_s { + int fd; + int is_closed; + int for_read; + int for_write; + int signaled; + int frozen; + void *opaque; +}; + + +/* These function are either defined in posix-io.c or w32-io.c */ + +int _gpgme_io_read ( int fd, void *buffer, size_t count ); +int _gpgme_io_write ( int fd, const void *buffer, size_t count ); +int _gpgme_io_pipe ( int filedes[2], int inherit_idx ); +int _gpgme_io_close ( int fd ); +int _gpgme_io_set_close_notify (int fd, + void (*handler)(int, void*), void *value); +int _gpgme_io_set_nonblocking ( int fd ); +int _gpgme_io_spawn ( const char *path, char **argv, + struct spawn_fd_item_s *fd_child_list, + struct spawn_fd_item_s *fd_parent_list ); +int _gpgme_io_waitpid ( int pid, int hang, int *r_status, int *r_signal ); +int _gpgme_io_kill ( int pid, int hard ); +int _gpgme_io_select ( struct io_select_fd_s *fds, size_t nfds); + + + + + + + +#endif /* IO_H */ + + + + + diff --git a/tags/V0-3-4/gpgme/key.c b/tags/V0-3-4/gpgme/key.c new file mode 100644 index 0000000..25d6a5d --- /dev/null +++ b/tags/V0-3-4/gpgme/key.c @@ -0,0 +1,974 @@ +/* key.c - Key and keyList objects + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "util.h" +#include "ops.h" +#include "key.h" + +#define ALLOC_CHUNK 1024 +#define my_isdigit(a) ( (a) >='0' && (a) <= '9' ) + +#if SIZEOF_UNSIGNED_INT < 4 +#error unsigned int too short to be used as a hash value +#endif + +struct key_cache_item_s { + struct key_cache_item_s *next; + GpgmeKey key; +}; + +static int key_cache_initialized; +static struct key_cache_item_s **key_cache; +static size_t key_cache_size; +static size_t key_cache_max_chain_length; +static struct key_cache_item_s *key_cache_unused_items; + +static int +hextobyte ( const byte *s ) +{ + int c; + + if ( *s >= '0' && *s <= '9' ) + c = 16 * (*s - '0'); + else if ( *s >= 'A' && *s <= 'F' ) + c = 16 * (10 + *s - 'A'); + else if ( *s >= 'a' && *s <= 'f' ) + c = 16 * (10 + *s - 'a'); + else + return -1; + s++; + if ( *s >= '0' && *s <= '9' ) + c += *s - '0'; + else if ( *s >= 'A' && *s <= 'F' ) + c += 10 + *s - 'A'; + else if ( *s >= 'a' && *s <= 'f' ) + c += 10 + *s - 'a'; + else + return -1; + return c; +} + +static int +hash_key (const char *fpr, unsigned int *rhash) +{ + unsigned int hash; + int c; + + if ( !fpr ) return -1; + if ( (c = hextobyte(fpr)) == -1 ) return -1; + hash = c; + if ( (c = hextobyte(fpr+2)) == -1 ) return -1; + hash |= c << 8; + if ( (c = hextobyte(fpr+4)) == -1 ) return -1; + hash |= c << 16; + if ( (c = hextobyte(fpr+6)) == -1 ) return -1; + hash |= c << 24; + + *rhash = hash; + return 0; +} + +void +_gpgme_key_cache_init (void) +{ + if (key_cache_initialized) + return; + key_cache_size = 503; + key_cache = xtrycalloc (key_cache_size, sizeof *key_cache); + if (!key_cache) { + key_cache_size = 0; + key_cache_initialized = 1; + return; + } + /* + * The upper bound for our cache size is + * key_cache_max_chain_length * key_cache_size + */ + key_cache_max_chain_length = 10; + key_cache_initialized = 1; +} + + +void +_gpgme_key_cache_add (GpgmeKey key) +{ + struct subkey_s *k; + + if (!key) + return; + + /* FIXME: add locking */ + if (!key_cache_initialized) + _gpgme_key_cache_init (); + if (!key_cache_size) + return; /* cache was not enabled */ + + /* put the key under each fingerprint into the cache. We use the + * first 4 digits to calculate the hash */ + for (k=&key->keys; k; k = k->next ) { + size_t n; + unsigned int hash; + struct key_cache_item_s *item; + + if ( hash_key (k->fingerprint, &hash) ) + continue; + + hash %= key_cache_size; + for (item=key_cache[hash],n=0; item; item = item->next, n++) { + struct subkey_s *k2; + if (item->key == key) + break; /* already in cache */ + /* now do a deeper check */ + for (k2=&item->key->keys; k2; k2 = k2->next ) { + if( k2->fingerprint + && !strcmp (k->fingerprint, k2->fingerprint) ) { + /* okay, replace it with the new copy */ + gpgme_key_unref (item->key); + item->key = key; + gpgme_key_ref (item->key); + return; + } + } + } + if (item) + continue; + + if (n > key_cache_max_chain_length ) { /* remove the last entries */ + struct key_cache_item_s *last = NULL; + + for (item=key_cache[hash]; + item && n < key_cache_max_chain_length; + last = item, item = item->next, n++ ) { + ; + } + if (last) { + struct key_cache_item_s *next; + + assert (last->next == item); + last->next = NULL; + for ( ;item; item=next) { + next = item->next; + gpgme_key_unref (item->key); + item->key = NULL; + item->next = key_cache_unused_items; + key_cache_unused_items = item; + } + } + } + + item = key_cache_unused_items; + if (item) { + key_cache_unused_items = item->next; + item->next = NULL; + } + else { + item = xtrymalloc (sizeof *item); + if (!item) + return; /* out of core */ + } + + item->key = key; + gpgme_key_ref (key); + item->next = key_cache[hash]; + key_cache[hash] = item; + } +} + + +GpgmeKey +_gpgme_key_cache_get (const char *fpr) +{ + struct key_cache_item_s *item; + unsigned int hash; + + if (!key_cache_size) + return NULL; /* cache not (yet) enabled */ + + if (hash_key (fpr, &hash)) + return NULL; + + hash %= key_cache_size; + for (item=key_cache[hash]; item; item = item->next) { + struct subkey_s *k; + + for (k=&item->key->keys; k; k = k->next ) { + if( k->fingerprint && !strcmp (k->fingerprint, fpr) ) { + gpgme_key_ref (item->key); + return item->key; + } + } + } + return NULL; +} + + +static const char * +pkalgo_to_string ( int algo ) +{ + switch (algo) { + case 1: + case 2: + case 3: return "RSA"; + case 16: + case 20: return "ElG"; + case 17: return "DSA"; + default: return "Unknown"; + } +} + + +static GpgmeError +key_new ( GpgmeKey *r_key, int secret ) +{ + GpgmeKey key; + + *r_key = NULL; + key = xtrycalloc ( 1, sizeof *key ); + if (!key) + return mk_error (Out_Of_Core); + key->ref_count = 1; + *r_key = key; + if (secret) + key->secret = 1; + return 0; +} + +GpgmeError +_gpgme_key_new ( GpgmeKey *r_key ) +{ + return key_new ( r_key, 0 ); +} + +GpgmeError +_gpgme_key_new_secret ( GpgmeKey *r_key ) +{ + return key_new ( r_key, 1 ); +} + + +/** + * gpgme_key_ref: + * @key: Key object + * + * To safe memory the Key objects implement reference counting. + * Use this function to bump the reference counter. + **/ +void +gpgme_key_ref ( GpgmeKey key ) +{ + return_if_fail (key); + key->ref_count++; +} + + +static struct subkey_s * +add_subkey (GpgmeKey key, int secret) +{ + struct subkey_s *k, *kk; + + k = xtrycalloc (1, sizeof *k); + if (!k) + return NULL; + + if( !(kk=key->keys.next) ) + key->keys.next = k; + else { + while ( kk->next ) + kk = kk->next; + kk->next = k; + } + if (secret) + k->secret = 1; + return k; +} + +struct subkey_s * +_gpgme_key_add_subkey (GpgmeKey key) +{ + return add_subkey (key, 0); +} + +struct subkey_s * +_gpgme_key_add_secret_subkey (GpgmeKey key) +{ + return add_subkey (key, 1); +} + + + +/** + * gpgme_key_release: + * @key: Key Object or NULL + * + * Release the key object. Note, that this function may not do an + * actual release if there are other shallow copies of the objects. + * You have to call this function for every newly created key object + * as well as for every gpgme_key_ref() done on the key object. + **/ +void +gpgme_key_release ( GpgmeKey key ) +{ + struct user_id_s *u, *u2; + struct subkey_s *k, *k2; + + if (!key) + return; + + assert (key->ref_count); + if ( --key->ref_count ) + return; + + xfree (key->keys.fingerprint); + for (k = key->keys.next; k; k = k2 ) { + k2 = k->next; + xfree (k->fingerprint); + xfree (k); + } + for (u = key->uids; u; u = u2 ) { + u2 = u->next; + xfree (u); + } + xfree (key); +} + +/** + * gpgme_key_unref: + * @key: Key Object + * + * This is an alias for gpgme_key_release(). + **/ +void +gpgme_key_unref (GpgmeKey key) +{ + gpgme_key_release (key); +} + + +static char * +set_user_id_part ( char *tail, const char *buf, size_t len ) +{ + while ( len && (buf[len-1] == ' ' || buf[len-1] == '\t') ) + len--; + for ( ; len; len--) + *tail++ = *buf++; + *tail++ = 0; + return tail; +} + + +static void +parse_user_id ( struct user_id_s *uid, char *tail ) +{ + const char *s, *start=NULL; + int in_name = 0; + int in_email = 0; + int in_comment = 0; + + for (s=uid->name; *s; s++ ) { + if ( in_email ) { + if ( *s == '<' ) + in_email++; /* not legal but anyway */ + else if (*s== '>') { + if ( !--in_email ) { + if (!uid->email_part) { + uid->email_part = tail; + tail = set_user_id_part ( tail, start, s-start ); + } + } + } + } + else if ( in_comment ) { + if ( *s == '(' ) + in_comment++; + else if (*s== ')') { + if ( !--in_comment ) { + if (!uid->comment_part) { + uid->comment_part = tail; + tail = set_user_id_part ( tail, start, s-start ); + } + } + } + } + else if ( *s == '<' ) { + if ( in_name ) { + if ( !uid->name_part ) { + uid->name_part = tail; + tail = set_user_id_part (tail, start, s-start ); + } + in_name = 0; + } + in_email = 1; + start = s+1; + } + else if ( *s == '(' ) { + if ( in_name ) { + if ( !uid->name_part ) { + uid->name_part = tail; + tail = set_user_id_part (tail, start, s-start ); + } + in_name = 0; + } + in_comment = 1; + start = s+1; + } + else if ( !in_name && *s != ' ' && *s != '\t' ) { + in_name = 1; + start = s; + } + } + + if ( in_name ) { + if ( !uid->name_part ) { + uid->name_part = tail; + tail = set_user_id_part (tail, start, s-start ); + } + } + + /* let unused parts point to an EOS */ + tail--; + if (!uid->name_part) + uid->name_part = tail; + if (!uid->email_part) + uid->email_part = tail; + if (!uid->comment_part) + uid->comment_part = tail; + +} + +static void +parse_x509_user_id ( struct user_id_s *uid, char *tail ) +{ + const char *s; + + s=uid->name; + if (*s == '<' && s[strlen(s)-1] == '>') + uid->email_part = s; + + /* let unused parts point to an EOS */ + tail--; + if (!uid->name_part) + uid->name_part = tail; + if (!uid->email_part) + uid->email_part = tail; + if (!uid->comment_part) + uid->comment_part = tail; +} + +/* + * Take a name from the --with-colon listing, remove certain escape sequences + * sequences and put it into the list of UIDs + */ +GpgmeError +_gpgme_key_append_name (GpgmeKey key, const char *s) +{ + struct user_id_s *uid; + char *d; + + assert (key); + /* We can malloc a buffer of the same length, because the converted + string will never be larger. Actually we allocate it twice the + size, so that we are able to store the parsed stuff there too. */ + uid = xtrymalloc ( sizeof *uid + 2*strlen (s)+3); + if (!uid) + return mk_error (Out_Of_Core); + uid->revoked = 0; + uid->invalid = 0; + uid->validity = 0; + uid->name_part = NULL; + uid->email_part = NULL; + uid->comment_part = NULL; + uid->next = NULL; + d = uid->name; + + while (*s) + { + if (*s != '\\') + *d++ = *s++; + else if (s[1] == '\\') + { + s++; + *d++ = *s++; + } + else if (s[1] == 'n') + { + s += 2; + *d++ = '\n'; + } + else if (s[1] == 'r') + { + s += 2; + *d++ = '\r'; + } + else if (s[1] == 'v') + { + s += 2; + *d++ = '\v'; + } + else if (s[1] == 'b') + { + s += 2; + *d++ = '\b'; + } + else if (s[1] == '0') + { + /* Hmmm: no way to express this */ + s += 2; + *d++ = '\\'; + *d++ = '\0'; + } + else if (s[1] == 'x' && my_isdigit (s[2]) && my_isdigit (s[3])) + { + unsigned int val = (s[2]-'0')*16 + (s[3]-'0'); + if (!val) + { + *d++ = '\\'; + *d++ = '\0'; + } + else + *(byte*)d++ = val; + s += 3; + } + else + { + /* should not happen */ + s++; + *d++ = '\\'; + *d++ = *s++; + } + } + *d++ = 0; + if (key->x509) + parse_x509_user_id (uid, d); + else + parse_user_id (uid, d); + + if (key->uids) + { + struct user_id_s *u = key->uids; + while (u->next) + u = u->next; + u->next = uid; + } + else + key->uids = uid; + + return 0; +} + + +static void +add_otag ( GpgmeData d, const char *tag ) +{ + _gpgme_data_append_string ( d, " <" ); + _gpgme_data_append_string ( d, tag ); + _gpgme_data_append_string ( d, ">" ); +} + +static void +add_ctag ( GpgmeData d, const char *tag ) +{ + _gpgme_data_append_string ( d, "\n" ); +} + +static void +add_tag_and_string ( GpgmeData d, const char *tag, const char *string ) +{ + add_otag (d, tag); + _gpgme_data_append_string_for_xml ( d, string ); + add_ctag (d, tag); +} + +static void +add_tag_and_uint ( GpgmeData d, const char *tag, unsigned int val ) +{ + char buf[30]; + sprintf (buf, "%u", val ); + add_tag_and_string ( d, tag, buf ); +} + +static void +add_tag_and_time ( GpgmeData d, const char *tag, time_t val ) +{ + char buf[30]; + + if (!val || val == (time_t)-1 ) + return; + sprintf (buf, "%lu", (unsigned long)val ); + add_tag_and_string ( d, tag, buf ); +} + +static void +one_uid_as_xml (GpgmeData d, struct user_id_s *u) +{ + _gpgme_data_append_string (d, " \n"); + if ( u->invalid ) + _gpgme_data_append_string ( d, " \n"); + if ( u->revoked ) + _gpgme_data_append_string ( d, " \n"); + add_tag_and_string ( d, "raw", u->name ); + if ( *u->name_part ) + add_tag_and_string ( d, "name", u->name_part ); + if ( *u->email_part ) + add_tag_and_string ( d, "email", u->email_part ); + if ( *u->comment_part ) + add_tag_and_string ( d, "comment", u->comment_part ); + _gpgme_data_append_string (d, " \n"); +} + + +/** + * gpgme_key_get_as_xml: + * @key: Key object + * + * Return the key object as an XML string. The classer has to free + * that string. + * + * Return value: An XML string or NULL in case of a memory problem or + * a NULL passed as @key + **/ +char * +gpgme_key_get_as_xml ( GpgmeKey key ) +{ + GpgmeData d; + struct user_id_s *u; + struct subkey_s *k; + + if ( !key ) + return NULL; + + if ( gpgme_data_new ( &d ) ) + return NULL; + + _gpgme_data_append_string ( d, "\n" + " \n" ); + if ( key->keys.secret ) + _gpgme_data_append_string ( d, " \n"); + if ( key->keys.flags.invalid ) + _gpgme_data_append_string ( d, " \n"); + if ( key->keys.flags.revoked ) + _gpgme_data_append_string ( d, " \n"); + if ( key->keys.flags.expired ) + _gpgme_data_append_string ( d, " \n"); + if ( key->keys.flags.disabled ) + _gpgme_data_append_string ( d, " \n"); + add_tag_and_string (d, "keyid", key->keys.keyid ); + if (key->keys.fingerprint) + add_tag_and_string (d, "fpr", key->keys.fingerprint ); + add_tag_and_uint (d, "algo", key->keys.key_algo ); + add_tag_and_uint (d, "len", key->keys.key_len ); + add_tag_and_time (d, "created", key->keys.timestamp ); + add_tag_and_time (d, "expire", key->keys.expires_at ); + _gpgme_data_append_string (d, " \n"); + + /* Now the user IDs. */ + for (u = key->uids; u; u = u->next) + one_uid_as_xml (d,u); + + /* and now the subkeys */ + for (k=key->keys.next; k; k = k->next ) { + _gpgme_data_append_string (d, " \n"); + if ( k->secret ) + _gpgme_data_append_string ( d, " \n"); + if ( k->flags.invalid ) + _gpgme_data_append_string ( d, " \n"); + if ( k->flags.revoked ) + _gpgme_data_append_string ( d, " \n"); + if ( k->flags.expired ) + _gpgme_data_append_string ( d, " \n"); + if ( k->flags.disabled ) + _gpgme_data_append_string ( d, " \n"); + add_tag_and_string (d, "keyid", k->keyid ); + if (k->fingerprint) + add_tag_and_string (d, "fpr", k->fingerprint ); + add_tag_and_uint (d, "algo", k->key_algo ); + add_tag_and_uint (d, "len", k->key_len ); + add_tag_and_time (d, "created", k->timestamp ); + add_tag_and_time (d, "expire", k->expires_at ); + _gpgme_data_append_string (d, " \n"); + } + _gpgme_data_append_string ( d, "\n" ); + + return _gpgme_data_release_and_return_string (d); +} + + +static const char * +capabilities_to_string (struct subkey_s *k) +{ + static char *strings[8] = { + "", + "c", + "s", + "sc", + "e", + "ec", + "es", + "esc" + }; + return strings[ (!!k->flags.can_encrypt << 2) + | (!!k->flags.can_sign << 1) + | (!!k->flags.can_certify ) ]; +} + + + +/** + * gpgme_key_get_string_attr: + * @key: Key Object + * @what: Attribute specifier + * @reserved: Must be 0 + * @idx: Index counter + * + * Return a attribute as specified by @what and @idx. Note that not + * all attributes can be returned as a string, in which case NULL is + * returned. @idx is used to iterate through attributes which do have + * more than one instance (e.g. user IDs or sub keys). + * + * Return value: NULL or an const string which is only valid as long + * as the key object itself is valid. + **/ +const char * +gpgme_key_get_string_attr ( GpgmeKey key, GpgmeAttr what, + const void *reserved, int idx ) +{ + const char *val = NULL; + struct subkey_s *k; + struct user_id_s *u; + + if (!key) + return NULL; + if (reserved) + return NULL; + if (idx < 0) + return NULL; + + switch (what) { + case GPGME_ATTR_KEYID: + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = k->keyid; + break; + case GPGME_ATTR_FPR: + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = k->fingerprint; + break; + case GPGME_ATTR_ALGO: + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = pkalgo_to_string (k->key_algo); + break; + case GPGME_ATTR_LEN: + case GPGME_ATTR_CREATED: + case GPGME_ATTR_EXPIRE: + break; /* use another get function */ + case GPGME_ATTR_OTRUST: + val = "[fixme]"; + break; + case GPGME_ATTR_USERID: + for (u=key->uids; u && idx; u=u->next, idx-- ) + ; + val = u? u->name : NULL; + break; + case GPGME_ATTR_NAME: + for (u=key->uids; u && idx; u=u->next, idx-- ) + ; + val = u? u->name_part : NULL; + break; + case GPGME_ATTR_EMAIL: + for (u=key->uids; u && idx; u=u->next, idx-- ) + ; + val = u? u->email_part : NULL; + break; + case GPGME_ATTR_COMMENT: + for (u=key->uids; u && idx; u=u->next, idx-- ) + ; + val = u? u->comment_part : NULL; + break; + case GPGME_ATTR_VALIDITY: + for (u=key->uids; u && idx; u=u->next, idx-- ) + ; + if (u) { + switch (u->validity) { + case GPGME_VALIDITY_UNKNOWN: val = "?"; break; + case GPGME_VALIDITY_UNDEFINED: val = "q"; break; + case GPGME_VALIDITY_NEVER: val = "n"; break; + case GPGME_VALIDITY_MARGINAL: val = "m"; break; + case GPGME_VALIDITY_FULL: val = "f"; break; + case GPGME_VALIDITY_ULTIMATE: val = "u"; break; + } + } + break; + case GPGME_ATTR_LEVEL: /* not used here */ + case GPGME_ATTR_TYPE: + case GPGME_ATTR_KEY_REVOKED: + case GPGME_ATTR_KEY_INVALID: + case GPGME_ATTR_KEY_EXPIRED: + case GPGME_ATTR_KEY_DISABLED: + case GPGME_ATTR_UID_REVOKED: + case GPGME_ATTR_UID_INVALID: + case GPGME_ATTR_CAN_ENCRYPT: + case GPGME_ATTR_CAN_SIGN: + case GPGME_ATTR_CAN_CERTIFY: + break; + case GPGME_ATTR_IS_SECRET: + if (key->secret) + val = "1"; + break; + case GPGME_ATTR_KEY_CAPS: + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = capabilities_to_string (k); + break; + } + return val; +} + + +/** + * gpgme_key_get_ulong_attr: + * @key: + * @what: + * @reserved: + * @idx: + * + * Return a attribute as specified by @what and @idx. Note that not + * all attributes can be returned as an integer, in which case 0 is + * returned. @idx is used to iterate through attributes which do have + * more than one instance (e.g. user IDs or sub keys). + * + * See gpgme.h for a list of attributes. + * + * Return value: 0 or the requested value. + **/ +unsigned long +gpgme_key_get_ulong_attr ( GpgmeKey key, GpgmeAttr what, + const void *reserved, int idx ) +{ + unsigned long val = 0; + struct subkey_s *k; + struct user_id_s *u; + + if (!key) + return 0; + if (reserved) + return 0; + if (idx < 0) + return 0; + + switch (what) { + case GPGME_ATTR_ALGO: + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = (unsigned long)k->key_algo; + break; + case GPGME_ATTR_LEN: + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = (unsigned long)k->key_len; + break; + case GPGME_ATTR_CREATED: + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = k->timestamp < 0? 0L:(unsigned long)k->timestamp; + break; + case GPGME_ATTR_EXPIRE: + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = k->expires_at < 0? 0L:(unsigned long)k->expires_at; + break; + case GPGME_ATTR_VALIDITY: + for (u=key->uids; u && idx; u=u->next, idx-- ) + ; + if (u) + val = u->validity; + break; + case GPGME_ATTR_IS_SECRET: + val = !!key->secret; + break; + case GPGME_ATTR_KEY_REVOKED: + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = k->flags.revoked; + break; + case GPGME_ATTR_KEY_INVALID: + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = k->flags.invalid; + break; + case GPGME_ATTR_KEY_EXPIRED: + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = k->flags.expired; + break; + case GPGME_ATTR_KEY_DISABLED: + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = k->flags.disabled; + break; + case GPGME_ATTR_UID_REVOKED: + for (u=key->uids; u && idx; u=u->next, idx-- ) + ; + if (u) + val = u->revoked; + break; + case GPGME_ATTR_UID_INVALID: + for (u=key->uids; u && idx; u=u->next, idx-- ) + ; + if (u) + val = u->invalid; + break; + case GPGME_ATTR_CAN_ENCRYPT: + val = key->gloflags.can_certify; + break; + case GPGME_ATTR_CAN_SIGN: + val = key->gloflags.can_sign; + break; + case GPGME_ATTR_CAN_CERTIFY: + val = key->gloflags.can_encrypt; + break; + default: + break; + } + return val; +} + + diff --git a/tags/V0-3-4/gpgme/key.h b/tags/V0-3-4/gpgme/key.h new file mode 100644 index 0000000..9503d55 --- /dev/null +++ b/tags/V0-3-4/gpgme/key.h @@ -0,0 +1,82 @@ +/* key.h + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef KEY_H +#define KEY_H + +#include +#include "types.h" +#include "context.h" + +struct subkey_s { + struct subkey_s *next; + unsigned int secret:1; + struct { + unsigned int revoked:1 ; + unsigned int expired:1 ; + unsigned int disabled:1 ; + unsigned int invalid:1 ; + unsigned int can_encrypt:1; + unsigned int can_sign:1; + unsigned int can_certify:1; + } flags; + unsigned int key_algo; + unsigned int key_len; + char keyid[16+1]; + char *fingerprint; /* malloced hex digits */ + time_t timestamp; /* -1 for invalid, 0 for not available */ + time_t expires_at; /* 0 for does not expires */ +}; + +struct gpgme_key_s { + struct { + unsigned int revoked:1 ; + unsigned int expired:1 ; + unsigned int disabled:1 ; + unsigned int invalid:1 ; + unsigned int can_encrypt:1; + unsigned int can_sign:1; + unsigned int can_certify:1; + } gloflags; + unsigned int ref_count; + unsigned int secret:1; + unsigned int x509:1; + struct subkey_s keys; + struct user_id_s *uids; +}; + +void _gpgme_key_cache_init (void); +void _gpgme_key_cache_add (GpgmeKey key); +GpgmeKey _gpgme_key_cache_get (const char *fpr); + + +struct subkey_s *_gpgme_key_add_subkey (GpgmeKey key); +struct subkey_s *_gpgme_key_add_secret_subkey (GpgmeKey key); +GpgmeError _gpgme_key_append_name ( GpgmeKey key, const char *s ); + + + +#endif /* KEY_H */ + + + + + diff --git a/tags/V0-3-4/gpgme/keylist.c b/tags/V0-3-4/gpgme/keylist.c new file mode 100644 index 0000000..1bcda34 --- /dev/null +++ b/tags/V0-3-4/gpgme/keylist.c @@ -0,0 +1,647 @@ +/* keylist.c - key listing + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include + +#include "util.h" +#include "context.h" +#include "ops.h" +#include "key.h" + +#define my_isdigit(a) ( (a) >='0' && (a) <= '9' ) + +static void finish_key ( GpgmeCtx ctx ); + + +static void +keylist_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args) +{ + if (ctx->error) + return; + + switch (code) + { + case STATUS_EOF: + finish_key (ctx); + break; + + default: + /* Ignore all other codes. */ + break; + } +} + + +static time_t +parse_timestamp (char *p) +{ + if (!*p) + return 0; + + return (time_t)strtoul (p, NULL, 10); +} + + +static void +set_mainkey_trust_info (GpgmeKey key, const char *s) +{ + /* Look at letters and stop at the first digit. */ + for (; *s && !my_isdigit (*s); s++) + { + switch (*s) + { + case 'e': key->keys.flags.expired = 1; break; + case 'r': key->keys.flags.revoked = 1; break; + case 'd': key->keys.flags.disabled = 1; break; + case 'i': key->keys.flags.invalid = 1; break; + } + } +} + + +static void +set_userid_flags (GpgmeKey key, const char *s) +{ + /* Look at letters and stop at the first digit. */ + for (; *s && !my_isdigit (*s); s++) + { + switch (*s) + { + case 'r': key->uids->revoked = 1; break; + case 'i': key->uids->invalid = 1; break; + + case 'n': key->uids->validity = GPGME_VALIDITY_NEVER; break; + case 'm': key->uids->validity = GPGME_VALIDITY_MARGINAL; break; + case 'f': key->uids->validity = GPGME_VALIDITY_FULL; break; + case 'u': key->uids->validity = GPGME_VALIDITY_ULTIMATE; break; + } + } +} + + +static void +set_subkey_trust_info (struct subkey_s *k, const char *s) +{ + /* Look at letters and stop at the first digit. */ + for (; *s && !my_isdigit (*s); s++) + { + switch (*s) + { + case 'e': k->flags.expired = 1; break; + case 'r': k->flags.revoked = 1; break; + case 'd': k->flags.disabled = 1; break; + case 'i': k->flags.invalid = 1; break; + } + } +} + + +static void +set_mainkey_capability (GpgmeKey key, const char *s) +{ + for (; *s ; s++) + { + switch (*s) + { + case 'e': key->keys.flags.can_encrypt = 1; break; + case 's': key->keys.flags.can_sign = 1; break; + case 'c': key->keys.flags.can_certify = 1; break; + case 'E': key->gloflags.can_encrypt = 1; break; + case 'S': key->gloflags.can_sign = 1; break; + case 'C': key->gloflags.can_certify = 1; break; + } + } +} + + +static void +set_subkey_capability ( struct subkey_s *k, const char *s) +{ + for (; *s; s++) + { + switch (*s) + { + case 'e': k->flags.can_encrypt = 1; break; + case 's': k->flags.can_sign = 1; break; + case 'c': k->flags.can_certify = 1; break; + } + } +} + + +/* Note: We are allowed to modify LINE. */ +static void +keylist_colon_handler (GpgmeCtx ctx, char *line) +{ + char *p, *pend; + int field = 0; + enum + { + RT_NONE, RT_SIG, RT_UID, RT_SUB, RT_PUB, RT_FPR, RT_SSB, RT_SEC, + RT_CRT, RT_CRS + } + rectype = RT_NONE; + GpgmeKey key = ctx->tmp_key; + int i; + const char *trust_info = NULL; + struct subkey_s *sk = NULL; + + if (ctx->error) + return; + if (!line) + { + /* EOF */ + finish_key (ctx); + return; + } + + for (p = line; p; p = pend) + { + field++; + pend = strchr (p, ':'); + if (pend) + *pend++ = 0; + + if (field == 1) + { + if (!strcmp (p, "sig")) + rectype = RT_SIG; + else if (!strcmp (p, "uid") && key) + { + rectype = RT_UID; + key = ctx->tmp_key; + } + else if (!strcmp (p, "sub") && key) + { + /* Start a new subkey. */ + rectype = RT_SUB; + if (!(sk = _gpgme_key_add_subkey (key))) + { + ctx->error = mk_error (Out_Of_Core); + return; + } + } + else if (!strcmp (p, "ssb") && key) + { + /* Start a new secret subkey. */ + rectype = RT_SSB; + if (!(sk = _gpgme_key_add_secret_subkey (key))) + { + ctx->error = mk_error (Out_Of_Core); + return; + } + } + else if (!strcmp (p, "pub")) + { + /* Start a new keyblock. */ + if (_gpgme_key_new (&key)) + { + ctx->error = mk_error (Out_Of_Core); /* the only kind of error we can get*/ + return; + } + rectype = RT_PUB; + finish_key (ctx); + assert (!ctx->tmp_key); + ctx->tmp_key = key; + } + else if (!strcmp (p, "sec")) + { + /* Start a new keyblock, */ + if (_gpgme_key_new_secret (&key)) + { + ctx->error = mk_error (Out_Of_Core); /* The only kind of error we can get*/ + return; + } + rectype = RT_SEC; + finish_key (ctx); + assert (!ctx->tmp_key); + ctx->tmp_key = key; + } + else if (!strcmp (p, "crt")) + { + /* Start a new certificate. */ + if (_gpgme_key_new (&key)) + { + ctx->error = mk_error (Out_Of_Core); /* The only kind of error we can get*/ + return; + } + key->x509 = 1; + rectype = RT_CRT; + finish_key (ctx); + assert (!ctx->tmp_key); + ctx->tmp_key = key; + } + else if (!strcmp (p, "crs")) + { + /* Start a new certificate. */ + if (_gpgme_key_new_secret (&key)) + { + ctx->error = mk_error (Out_Of_Core); /* The only kind of error we can get*/ + return; + } + key->x509 = 1; + rectype = RT_CRS; + finish_key (ctx); + assert (!ctx->tmp_key); + ctx->tmp_key = key; + } + else if (!strcmp (p, "fpr") && key) + rectype = RT_FPR; + else + rectype = RT_NONE; + + } + else if (rectype == RT_PUB || rectype == RT_SEC + || rectype == RT_CRT || rectype == RT_CRS) + { + switch (field) + { + case 2: /* trust info */ + trust_info = p; + set_mainkey_trust_info (key, trust_info); + break; + case 3: /* key length */ + i = atoi (p); + if (i > 1) /* ignore invalid values */ + key->keys.key_len = i; + break; + case 4: /* pubkey algo */ + i = atoi (p); + if (i > 1 && i < 128) + key->keys.key_algo = i; + break; + case 5: /* long keyid */ + if (strlen (p) == DIM(key->keys.keyid) - 1) + strcpy (key->keys.keyid, p); + break; + case 6: /* timestamp (seconds) */ + key->keys.timestamp = parse_timestamp (p); + break; + case 7: /* expiration time (seconds) */ + key->keys.expires_at = parse_timestamp (p); + break; + case 8: /* X.509 serial number */ + /* fixme: store it */ + break; + case 9: /* ownertrust */ + break; + case 10: /* not used for gpg due to --fixed-list-mode option + but gpgsm stores the issuer name */ + /* fixme: store issuer name */ + break; + case 11: /* signature class */ + break; + case 12: /* capabilities */ + set_mainkey_capability (key, p); + break; + case 13: + pend = NULL; /* we can stop here */ + break; + } + } + else if ((rectype == RT_SUB || rectype== RT_SSB) && sk) + { + switch (field) + { + case 2: /* trust info */ + set_subkey_trust_info (sk, p); + break; + case 3: /* key length */ + i = atoi (p); + if (i > 1) /* ignore invalid values */ + sk->key_len = i; + break; + case 4: /* pubkey algo */ + i = atoi (p); + if (i > 1 && i < 128) + sk->key_algo = i; + break; + case 5: /* long keyid */ + if (strlen (p) == DIM(sk->keyid) - 1) + strcpy (sk->keyid, p); + break; + case 6: /* timestamp (seconds) */ + sk->timestamp = parse_timestamp (p); + break; + case 7: /* expiration time (seconds) */ + break; + case 8: /* reserved (LID) */ + break; + case 9: /* ownertrust */ + break; + case 10:/* user ID n/a for a subkey */ + break; + case 11: /* signature class */ + break; + case 12: /* capability */ + set_subkey_capability (sk, p); + break; + case 13: + pend = NULL; /* we can stop here */ + break; + } + } + else if (rectype == RT_UID) + { + switch (field) + { + case 2: /* trust info */ + trust_info = p; /*save for later */ + break; + case 10: /* user ID */ + if (_gpgme_key_append_name (key, p)) + ctx->error = mk_error (Out_Of_Core); /* The only kind of error we can get*/ + else + { + if (trust_info) + set_userid_flags (key, trust_info); + } + pend = NULL; /* we can stop here */ + break; + } + } + else if (rectype == RT_FPR) + { + switch (field) + { + case 10: /* fingerprint (take only the first one)*/ + if (!key->keys.fingerprint && *p) + { + key->keys.fingerprint = xtrystrdup (p); + if (!key->keys.fingerprint) + ctx->error = mk_error (Out_Of_Core); + } + pend = NULL; /* that is all we want */ + break; + } + } + } +} + + +/* + * We have read an entire key into ctx->tmp_key and should now finish + * it. It is assumed that this releases ctx->tmp_key. + */ +static void +finish_key (GpgmeCtx ctx) +{ + GpgmeKey key = ctx->tmp_key; + struct key_queue_item_s *q, *q2; + + if (key) + { + ctx->tmp_key = NULL; + + _gpgme_key_cache_add (key); + + q = xtrymalloc (sizeof *q); + if (!q) + { + gpgme_key_release (key); + ctx->error = mk_error (Out_Of_Core); + return; + } + q->key = key; + q->next = NULL; + /* FIXME: Lock queue. Use a tail pointer? */ + if (!(q2 = ctx->key_queue)) + ctx->key_queue = q; + else + { + for (; q2->next; q2 = q2->next) + ; + q2->next = q; + } + ctx->key_cond = 1; + /* FIXME: Unlock queue. */ + } +} + + +/** + * gpgme_op_keylist_start: + * @c: context + * @pattern: a GnuPG user ID or NULL for all + * @secret_only: List only keys where the secret part is available + * + * Note that this function also cancels a pending key listing + * operaton. To actually retrieve the key, use + * gpgme_op_keylist_next(). + * + * Return value: 0 on success or an errorcode. + **/ +GpgmeError +gpgme_op_keylist_start (GpgmeCtx ctx, const char *pattern, int secret_only) +{ + GpgmeError err = 0; + + if (!ctx) + return mk_error (Invalid_Value); + ctx->pending = 1; + + _gpgme_release_result (ctx); + + if (ctx->engine) + { + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + gpgme_key_release (ctx->tmp_key); + ctx->tmp_key = NULL; + /* Fixme: Release key_queue. */ + + err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS + : GPGME_PROTOCOL_OpenPGP, &ctx->engine); + if (err) + goto leave; + + _gpgme_engine_set_status_handler (ctx->engine, keylist_status_handler, ctx); + err = _gpgme_engine_set_colon_line_handler (ctx->engine, + keylist_colon_handler, ctx); + if (err) + goto leave; + + /* We don't want to use the verbose mode as this will also print + the key signatures which is in most cases not needed and furthermore we + just ignore those lines - This should speed up things */ + _gpgme_engine_set_verbosity (ctx->engine, 0); + + err = _gpgme_engine_op_keylist (ctx->engine, pattern, secret_only, ctx->keylist_mode); + + if (!err) /* And kick off the process. */ + err = _gpgme_engine_start (ctx->engine, ctx); + + leave: + if (err) + { + ctx->pending = 0; + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + return err; +} + + +/** + * gpgme_op_keylist_ext_start: + * @c: context + * @pattern: a NULL terminated array of search patterns + * @secret_only: List only keys where the secret part is available + * @reserved: Should be 0. + * + * Note that this function also cancels a pending key listing + * operaton. To actually retrieve the key, use + * gpgme_op_keylist_next(). + * + * Return value: 0 on success or an errorcode. + **/ +GpgmeError +gpgme_op_keylist_ext_start (GpgmeCtx ctx, const char *pattern[], + int secret_only, int reserved) +{ + GpgmeError err = 0; + + if (!ctx) + return mk_error (Invalid_Value); + ctx->pending = 1; + + _gpgme_release_result (ctx); + + if (ctx->engine) + { + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + gpgme_key_release (ctx->tmp_key); + ctx->tmp_key = NULL; + /* Fixme: Release key_queue. */ + + err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS + : GPGME_PROTOCOL_OpenPGP, &ctx->engine); + if (err) + goto leave; + + _gpgme_engine_set_status_handler (ctx->engine, keylist_status_handler, ctx); + err = _gpgme_engine_set_colon_line_handler (ctx->engine, + keylist_colon_handler, ctx); + if (err) + goto leave; + + /* We don't want to use the verbose mode as this will also print + the key signatures which is in most cases not needed and furthermore we + just ignore those lines - This should speed up things */ + _gpgme_engine_set_verbosity (ctx->engine, 0); + + err = _gpgme_engine_op_keylist_ext (ctx->engine, pattern, secret_only, + reserved, ctx->keylist_mode); + + if (!err) /* And kick off the process. */ + err = _gpgme_engine_start (ctx->engine, ctx); + + leave: + if (err) + { + ctx->pending = 0; + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + return err; +} + + +/** + * gpgme_op_keylist_next: + * @c: Context + * @r_key: Returned key object + * + * Return the next key from the key listing started with + * gpgme_op_keylist_start(). The caller must free the key using + * gpgme_key_release(). If the last key has already been returned the + * last time the function was called, %GPGME_EOF is returned and the + * operation is finished. + * + * Return value: 0 on success, %GPGME_EOF or another error code. + **/ +GpgmeError +gpgme_op_keylist_next (GpgmeCtx ctx, GpgmeKey *r_key) +{ + struct key_queue_item_s *queue_item; + + if (!r_key) + return mk_error (Invalid_Value); + *r_key = NULL; + if (!ctx) + return mk_error (Invalid_Value); + if (!ctx->pending) + return mk_error (No_Request); + if (ctx->error) + return ctx->error; + + if (!ctx->key_queue) + { + _gpgme_wait_on_condition (ctx, 1, &ctx->key_cond); + if (ctx->error) + return ctx->error; + if (!ctx->key_cond) + { + ctx->pending = 0; + return mk_error (EOF); + } + ctx->key_cond = 0; + assert (ctx->key_queue); + } + queue_item = ctx->key_queue; + ctx->key_queue = queue_item->next; + if (!ctx->key_queue) + ctx->key_cond = 0; + + *r_key = queue_item->key; + xfree (queue_item); + return 0; +} + + +/** + * gpgme_op_keylist_end: + * @c: Context + * + * Ends the keylist operation and allows to use the context for some + * other operation next. + **/ +GpgmeError +gpgme_op_keylist_end (GpgmeCtx ctx) +{ + if (!ctx) + return mk_error (Invalid_Value); + if (!ctx->pending) + return mk_error (No_Request); + if (ctx->error) + return ctx->error; + + ctx->pending = 0; + return 0; +} diff --git a/tags/V0-3-4/gpgme/mkerrors b/tags/V0-3-4/gpgme/mkerrors new file mode 100755 index 0000000..c5e1281 --- /dev/null +++ b/tags/V0-3-4/gpgme/mkerrors @@ -0,0 +1,84 @@ +#!/bin/sh +# mkerrors - Extract error strings from gpgme.h +# and create C source for gpgme_strerror +# Copyright (C) 2000 Werner Koch (dd9jn) +# Copyright (C) 2001 g10 Code GmbH +# +# This file is part of GPGME. +# +# GPGME is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# GPGME is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +cat < +#include "gpgme.h" + +/** + * gpgme_strerror: + * @err: Error code + * + * This function returns a textual representaion of the given + * errocode. If this is an unknown value, a string with the value + * is returned (which is hold in a static buffer). + * + * Return value: String with the error description. + **/ +const char * +gpgme_strerror (GpgmeError err) +{ + const char *s; + static char buf[25]; + + switch (err) { +EOF + +awk ' +/GPGME_No_Error/ { okay=1 } +!okay {next} +/}/ { exit 0 } +/GPGME_[A-Za-z_]*/ { print_code($1) } + + +function print_code( s ) +{ +printf " case %s: s=\"", s ; +gsub(/_/, " ", s ); +printf "%s\"; break;\n", substr(s,7); +} +' + +cat <result.field) \ + { \ + ctx->result.field = xtrycalloc (1, sizeof *ctx->result.field); \ + if (!ctx->result.field) \ + { \ + ctx->error = mk_error (Out_Of_Core); \ + return; \ + } \ + } \ + } \ + while (0) + +/*-- gpgme.c --*/ +void _gpgme_release_result ( GpgmeCtx c ); +void _gpgme_set_op_info (GpgmeCtx c, GpgmeData info); + +/*-- wait.c --*/ +GpgmeCtx _gpgme_wait_on_condition ( GpgmeCtx c, + int hang, volatile int *cond ); +void _gpgme_freeze_fd ( int fd ); +void _gpgme_thaw_fd ( int fd ); + + +/*-- recipient.c --*/ +int _gpgme_recipients_all_valid ( const GpgmeRecipients rset ); + + +/*-- data.c --*/ +char * _gpgme_data_release_and_return_string ( GpgmeData dh ); +GpgmeDataMode _gpgme_data_get_mode ( GpgmeData dh ); +void _gpgme_data_set_mode ( GpgmeData dh, GpgmeDataMode mode ); +char * _gpgme_data_get_as_string ( GpgmeData dh ); +GpgmeError _gpgme_data_append ( GpgmeData dh, + const char *buffer, size_t length ); +GpgmeError _gpgme_data_append_string ( GpgmeData dh, const char *s ); +GpgmeError _gpgme_data_append_string_for_xml ( GpgmeData dh, + const char *s); +GpgmeError _gpgme_data_append_for_xml ( GpgmeData dh, + const char *buffer, + size_t len ); +GpgmeError _gpgme_data_append_percentstring_for_xml ( GpgmeData dh, + const char *string ); + +GpgmeError _gpgme_data_unread (GpgmeData dh, + const char *buffer, size_t length ); + +int _gpgme_data_inbound_handler (void *opaque, int pid, int fd); +int _gpgme_data_outbound_handler (void *opaque, int pid, int fd); + + +/*-- key.c --*/ +GpgmeError _gpgme_key_new ( GpgmeKey *r_key ); +GpgmeError _gpgme_key_new_secret ( GpgmeKey *r_key ); + + +/*-- verify.c --*/ +void _gpgme_release_verify_result (VerifyResult result); +GpgmeSigStat _gpgme_intersect_stati (VerifyResult result); +void _gpgme_verify_status_handler (GpgmeCtx ctx, GpgStatusCode code, + char *args); + +/*-- decrypt.c --*/ +void _gpgme_release_decrypt_result (DecryptResult result); +void _gpgme_decrypt_status_handler (GpgmeCtx ctx, GpgStatusCode code, + char *args); +GpgmeError _gpgme_decrypt_start (GpgmeCtx ctx, GpgmeData ciph, GpgmeData plain, + void *status_handler); +GpgmeError _gpgme_decrypt_result (GpgmeCtx ctx); + +/*-- sign.c --*/ +void _gpgme_release_sign_result ( SignResult res ); +void _gpgme_sign_status_handler (GpgmeCtx ctx, GpgStatusCode code, + char *args); + +/*-- encrypt.c --*/ +void _gpgme_release_encrypt_result ( EncryptResult res ); +void _gpgme_encrypt_status_handler (GpgmeCtx ctx, GpgStatusCode code, + char *args); + +/*-- passphrase.c --*/ +void _gpgme_release_passphrase_result (PassphraseResult result); +void _gpgme_passphrase_status_handler (GpgmeCtx ctx, GpgStatusCode code, + char *args); +GpgmeError _gpgme_passphrase_start (GpgmeCtx ctx); + +/*-- progress.c --*/ +void _gpgme_progress_status_handler (GpgmeCtx ctx, GpgStatusCode code, + char *args); + +/*-- import.c --*/ +void _gpgme_release_import_result (ImportResult res); + +/*-- delete.c --*/ +void _gpgme_release_delete_result (DeleteResult res); + +/*-- genkey.c --*/ +void _gpgme_release_genkey_result (GenKeyResult res); + +/*-- version.c --*/ +const char *_gpgme_compare_versions (const char *my_version, + const char *req_version); +char *_gpgme_get_program_version (const char *const path); + + +#endif /* OPS_H */ diff --git a/tags/V0-3-4/gpgme/passphrase.c b/tags/V0-3-4/gpgme/passphrase.c new file mode 100644 index 0000000..6ba23ba --- /dev/null +++ b/tags/V0-3-4/gpgme/passphrase.c @@ -0,0 +1,175 @@ +/* passphrase.c - passphrase functions + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "util.h" +#include "context.h" +#include "ops.h" + + +struct passphrase_result_s +{ + int no_passphrase; + void *last_pw_handle; + char *userid_hint; + char *passphrase_info; + int bad_passphrase; +}; + + +void +_gpgme_release_passphrase_result (PassphraseResult result) +{ + if (!result) + return; + xfree (result->passphrase_info); + xfree (result->userid_hint); + xfree (result); +} + + +void +_gpgme_passphrase_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args) +{ + if (ctx->error) + return; + test_and_allocate_result (ctx, passphrase); + + switch (code) + { + case STATUS_USERID_HINT: + xfree (ctx->result.passphrase->userid_hint); + if (!(ctx->result.passphrase->userid_hint = xtrystrdup (args))) + ctx->error = mk_error (Out_Of_Core); + break; + + case STATUS_BAD_PASSPHRASE: + ctx->result.passphrase->bad_passphrase++; + break; + + case STATUS_GOOD_PASSPHRASE: + ctx->result.passphrase->bad_passphrase = 0; + break; + + case STATUS_NEED_PASSPHRASE: + case STATUS_NEED_PASSPHRASE_SYM: + xfree (ctx->result.passphrase->passphrase_info); + ctx->result.passphrase->passphrase_info = xtrystrdup (args); + if (!ctx->result.passphrase->passphrase_info) + ctx->error = mk_error (Out_Of_Core); + break; + + case STATUS_MISSING_PASSPHRASE: + DEBUG0 ("missing passphrase - stop\n");; + ctx->result.passphrase->no_passphrase = 1; + break; + + case STATUS_EOF: + if (ctx->result.passphrase->no_passphrase + || ctx->result.passphrase->bad_passphrase) + ctx->error = mk_error (No_Passphrase); + break; + + default: + /* Ignore all other codes. */ + break; + } +} + + +static const char * +command_handler (void *opaque, GpgStatusCode code, const char *key) +{ + GpgmeCtx ctx = opaque; + + if (!ctx->result.passphrase) + { + ctx->result.passphrase = xtrycalloc (1, sizeof *ctx->result.passphrase); + if (!ctx->result.passphrase) + { + ctx->error = mk_error (Out_Of_Core); + return NULL; + } + } + + if (!code) + { + /* We have been called for cleanup. */ + if (ctx->passphrase_cb) + { + /* Fixme: Take the key in account. */ + ctx->passphrase_cb (ctx->passphrase_cb_value, NULL, + &ctx->result.passphrase->last_pw_handle); + } + return NULL; + } + + if (!key || !ctx->passphrase_cb) + return NULL; + + if (code == STATUS_GET_HIDDEN && !strcmp (key, "passphrase.enter")) + { + const char *userid_hint = ctx->result.passphrase->userid_hint; + const char *passphrase_info = ctx->result.passphrase->passphrase_info; + int bad_passphrase = ctx->result.passphrase->bad_passphrase; + char *buf; + const char *s; + + ctx->result.passphrase->bad_passphrase = 0; + if (!userid_hint) + userid_hint = "[User ID hint missing]"; + if (!passphrase_info) + passphrase_info = "[passphrase info missing]"; + buf = xtrymalloc (20 + strlen (userid_hint) + + strlen (passphrase_info) + 3); + if (!buf) + { + ctx->error = mk_error (Out_Of_Core); + return NULL; + } + sprintf (buf, "%s\n%s\n%s", + bad_passphrase ? "TRY_AGAIN":"ENTER", + userid_hint, passphrase_info); + + s = ctx->passphrase_cb (ctx->passphrase_cb_value, + buf, &ctx->result.passphrase->last_pw_handle); + xfree (buf); + return s; + } + + return NULL; +} + + +GpgmeError +_gpgme_passphrase_start (GpgmeCtx ctx) +{ + GpgmeError err = 0; + + if (ctx->passphrase_cb) + err = _gpgme_engine_set_command_handler (ctx->engine, command_handler, ctx); + return err; +} diff --git a/tags/V0-3-4/gpgme/posix-io.c b/tags/V0-3-4/gpgme/posix-io.c new file mode 100644 index 0000000..eaa8950 --- /dev/null +++ b/tags/V0-3-4/gpgme/posix-io.c @@ -0,0 +1,356 @@ +/* posix-io.c - Posix I/O functions + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#ifndef HAVE_DOSISH_SYSTEM + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "syshdr.h" + +#include "util.h" +#include "io.h" + +static struct { + void (*handler)(int,void*); + void *value; +} notify_table[256]; + + +int +_gpgme_io_read ( int fd, void *buffer, size_t count ) +{ + int nread; + + DEBUG2 ("fd %d: about to read %d bytes\n", fd, (int)count ); + do { + nread = read (fd, buffer, count); + } while (nread == -1 && errno == EINTR ); + DEBUG2 ("fd %d: got %d bytes\n", fd, nread ); + if ( nread > 0 ) { + _gpgme_debug (2, "fd %d: got `%.*s'\n", fd, nread, buffer ); + } + return nread; +} + + +int +_gpgme_io_write ( int fd, const void *buffer, size_t count ) +{ + int nwritten; + + DEBUG2 ("fd %d: about to write %d bytes\n", fd, (int)count ); + _gpgme_debug (2, "fd %d: write `%.*s'\n", fd, (int)count, buffer ); + do { + nwritten = write (fd, buffer, count); + } while (nwritten == -1 && errno == EINTR ); + DEBUG2 ("fd %d: wrote %d bytes\n", fd, (int)nwritten ); + return nwritten; +} + +int +_gpgme_io_pipe (int filedes[2], int inherit_idx) +{ + int err; + + err = pipe (filedes); + if (err < 0) + return err; + /* FIXME: Should get the old flags first. */ + err = fcntl (filedes[1 - inherit_idx], F_SETFD, FD_CLOEXEC); + if (err < 0) + { + close (filedes[0]); + close (filedes[1]); + } + return err; +} + +int +_gpgme_io_close ( int fd ) +{ + if ( fd == -1 ) + return -1; + /* first call the notify handler */ + DEBUG1 ("closing fd %d", fd ); + if ( fd >= 0 && fd < DIM (notify_table) ) { + if (notify_table[fd].handler) { + notify_table[fd].handler (fd, notify_table[fd].value); + notify_table[fd].handler = NULL; + notify_table[fd].value = NULL; + } + } + /* then do the close */ + return close (fd); +} + +int +_gpgme_io_set_close_notify (int fd, void (*handler)(int, void*), void *value) +{ + assert (fd != -1); + + if ( fd < 0 || fd >= DIM (notify_table) ) + return -1; + DEBUG1 ("set notification for fd %d", fd ); + notify_table[fd].handler = handler; + notify_table[fd].value = value; + return 0; +} + + +int +_gpgme_io_set_nonblocking ( int fd ) +{ + int flags; + + flags = fcntl (fd, F_GETFL, 0); + if (flags == -1) + return -1; + flags |= O_NONBLOCK; + return fcntl (fd, F_SETFL, flags); +} + + +int +_gpgme_io_spawn ( const char *path, char **argv, + struct spawn_fd_item_s *fd_child_list, + struct spawn_fd_item_s *fd_parent_list ) +{ + static volatile int fixed_signals; + pid_t pid; + int i; + + if ( !fixed_signals ) { + struct sigaction act; + + sigaction( SIGPIPE, NULL, &act ); + if( act.sa_handler == SIG_DFL ) { + act.sa_handler = SIG_IGN; + sigemptyset( &act.sa_mask ); + act.sa_flags = 0; + sigaction( SIGPIPE, &act, NULL); + } + fixed_signals = 1; + /* fixme: This is not really MT safe */ + } + + + pid = fork (); + if (pid == -1) + return -1; + + if ( !pid ) { /* child */ + int duped_stdin = 0; + int duped_stderr = 0; + + /* first close all fds which will not be duped */ + for (i=0; fd_child_list[i].fd != -1; i++ ) { + if (fd_child_list[i].dup_to == -1 ) + close (fd_child_list[i].fd); + } + /* and now dup and close the rest */ + for (i=0; fd_child_list[i].fd != -1; i++ ) { + if (fd_child_list[i].dup_to != -1 ) { + if ( dup2 (fd_child_list[i].fd, + fd_child_list[i].dup_to ) == -1 ) { + DEBUG1 ("dup2 failed in child: %s\n", strerror (errno)); + _exit (8); + } + if ( fd_child_list[i].dup_to == 0 ) + duped_stdin=1; + if ( fd_child_list[i].dup_to == 2 ) + duped_stderr=1; + close (fd_child_list[i].fd); + } + } + + if( !duped_stdin || !duped_stderr ) { + int fd = open ( "/dev/null", O_RDWR ); + if ( fd == -1 ) { + DEBUG1 ("can't open `/dev/null': %s\n", strerror (errno) ); + _exit (8); + } + /* Make sure that the process has a connected stdin */ + if ( !duped_stdin ) { + if ( dup2 ( fd, 0 ) == -1 ) { + DEBUG1("dup2(/dev/null, 0) failed: %s\n", + strerror (errno) ); + _exit (8); + } + } + if ( !duped_stderr ) { + if ( dup2 ( fd, 2 ) == -1 ) { + DEBUG1 ("dup2(dev/null, 2) failed: %s\n", strerror (errno)); + _exit (8); + } + } + close (fd); + } + + execv ( path, argv ); + /* Hmm: in that case we could write a special status code to the + * status-pipe */ + DEBUG1 ("exec of `%s' failed\n", path ); + _exit (8); + } /* end child */ + + /* .dup_to is not used in the parent list */ + for (i=0; fd_parent_list[i].fd != -1; i++ ) { + close (fd_parent_list[i].fd); + } + + return (int)pid; +} + + +int +_gpgme_io_waitpid ( int pid, int hang, int *r_status, int *r_signal ) +{ + int status; + + *r_status = 0; + *r_signal = 0; + if ( waitpid ( pid, &status, hang? 0 : WNOHANG ) == pid ) { + if ( WIFSIGNALED (status) ) { + *r_status = 4; /* Need some value here */ + *r_signal = WTERMSIG (status); + } + else if ( WIFEXITED (status) ) { + *r_status = WEXITSTATUS (status); + } + else { + *r_status = 4; /* oops */ + } + return 1; + } + return 0; +} + +int +_gpgme_io_kill ( int pid, int hard ) +{ + return kill ( pid, hard? SIGKILL : SIGTERM ); +} + + +/* + * Select on the list of fds. + * Returns: -1 = error + * 0 = timeout or nothing to select + * >0 = number of signaled fds + */ +int +_gpgme_io_select ( struct io_select_fd_s *fds, size_t nfds ) +{ + static fd_set readfds; + static fd_set writefds; + int any, i, max_fd, n, count; + struct timeval timeout = { 1, 0 }; /* Use a 1s timeout */ + void *dbg_help = NULL; + + FD_ZERO ( &readfds ); + FD_ZERO ( &writefds ); + max_fd = 0; + + if ( _gpgme_debug_level () > 2 ) + DEBUG_BEGIN (dbg_help, "gpgme:select on [ "); + any = 0; + for ( i=0; i < nfds; i++ ) { + if ( fds[i].fd == -1 ) + continue; + if ( fds[i].frozen ) { + DEBUG_ADD1 (dbg_help, "f%d ", fds[i].fd ); + } + else if ( fds[i].for_read ) { + assert ( !FD_ISSET ( fds[i].fd, &readfds ) ); + FD_SET ( fds[i].fd, &readfds ); + if ( fds[i].fd > max_fd ) + max_fd = fds[i].fd; + DEBUG_ADD1 (dbg_help, "r%d ", fds[i].fd ); + any = 1; + } + else if ( fds[i].for_write ) { + assert ( !FD_ISSET ( fds[i].fd, &writefds ) ); + FD_SET ( fds[i].fd, &writefds ); + if ( fds[i].fd > max_fd ) + max_fd = fds[i].fd; + DEBUG_ADD1 (dbg_help, "w%d ", fds[i].fd ); + any = 1; + } + fds[i].signaled = 0; + } + DEBUG_END (dbg_help, "]" ); + if ( !any ) + return 0; + + do { + count = select ( max_fd+1, &readfds, &writefds, NULL, &timeout ); + } while ( count < 0 && errno == EINTR); + if ( count < 0 ) { + DEBUG1 ("_gpgme_io_select failed: %s\n", strerror (errno) ); + return -1; /* error */ + } + + if ( _gpgme_debug_level () > 2 ) + DEBUG_BEGIN (dbg_help, "select OK [ " ); + if (DEBUG_ENABLED(dbg_help)) { + for (i=0; i <= max_fd; i++ ) { + if (FD_ISSET (i, &readfds) ) + DEBUG_ADD1 (dbg_help, "r%d ", i ); + if (FD_ISSET (i, &writefds) ) + DEBUG_ADD1 (dbg_help, "w%d ", i ); + } + DEBUG_END (dbg_help, "]" ); + } + + /* n is used to optimize it a little bit */ + for ( n=count, i=0; i < nfds && n ; i++ ) { + if ( fds[i].fd == -1 ) + ; + else if ( fds[i].for_read ) { + if ( FD_ISSET ( fds[i].fd, &readfds ) ) { + fds[i].signaled = 1; + n--; + } + } + else if ( fds[i].for_write ) { + if ( FD_ISSET ( fds[i].fd, &writefds ) ) { + fds[i].signaled = 1; + n--; + } + } + } + return count; +} + + +#endif /*!HAVE_DOSISH_SYSTEM*/ + + + diff --git a/tags/V0-3-4/gpgme/posix-sema.c b/tags/V0-3-4/gpgme/posix-sema.c new file mode 100644 index 0000000..3d89520 --- /dev/null +++ b/tags/V0-3-4/gpgme/posix-sema.c @@ -0,0 +1,71 @@ +/* posix-sema.c + * Copyright (C) 2001 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + + +#include +#ifndef HAVE_DOSISH_SYSTEM + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "syshdr.h" + +#include "util.h" +#include "sema.h" + + + +void +_gpgme_sema_subsystem_init () +{ + /* FIXME: Posix semaphore support has not yet been implemented */ +} + + +void +_gpgme_sema_cs_enter ( struct critsect_s *s ) +{ +} + +void +_gpgme_sema_cs_leave (struct critsect_s *s) +{ +} + +void +_gpgme_sema_cs_destroy ( struct critsect_s *s ) +{ +} + + + +#endif /*!HAVE_DOSISH_SYSTEM*/ + + + + + diff --git a/tags/V0-3-4/gpgme/posix-util.c b/tags/V0-3-4/gpgme/posix-util.c new file mode 100644 index 0000000..ef59076 --- /dev/null +++ b/tags/V0-3-4/gpgme/posix-util.c @@ -0,0 +1,53 @@ +/* posix-util.c - Utility functions for Posix + * Copyright (C) 2001 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + + +#include +#ifndef HAVE_DOSISH_SYSTEM + +#include +#include +#include +#include + +#include "util.h" + +const char * +_gpgme_get_gpg_path (void) +{ +#ifdef GPG_PATH + return GPG_PATH; +#else + return NULL; +#endif +} + +const char * +_gpgme_get_gpgsm_path (void) +{ +#ifdef GPGSM_PATH + return GPGSM_PATH; +#else + return NULL; +#endif +} + +#endif /*!HAVE_DOSISH_SYSTEM*/ diff --git a/tags/V0-3-4/gpgme/progress.c b/tags/V0-3-4/gpgme/progress.c new file mode 100644 index 0000000..cb19dad --- /dev/null +++ b/tags/V0-3-4/gpgme/progress.c @@ -0,0 +1,80 @@ +/* progress.c - status handler for progress status + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include + +#include "util.h" +#include "context.h" + + +void +_gpgme_progress_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args) +{ + char *p; + char *args_cpy; + int type = 0; + int current = 0; + int total = 0; + + if (code != STATUS_PROGRESS || !*args || !ctx->progress_cb) + return; + + args_cpy = xtrystrdup (args); + if (!args_cpy) + { + ctx->error = mk_error (Out_Of_Core); + return; + } + + p = strchr (args_cpy, ' '); + if (p) + { + *p++ = 0; + if (*p) + { + type = *(byte *)p; + p = strchr (p+1, ' '); + if (p) + { + *p++ = 0; + if (*p) + { + current = atoi (p); + p = strchr (p+1, ' '); + if (p) + { + *p++ = 0; + total = atoi (p); + } + } + } + } + } + + if (type != 'X') + ctx->progress_cb (ctx->progress_cb_value, args_cpy, type, current, total); + + xfree (args_cpy); +} diff --git a/tags/V0-3-4/gpgme/recipient.c b/tags/V0-3-4/gpgme/recipient.c new file mode 100644 index 0000000..f1899ce --- /dev/null +++ b/tags/V0-3-4/gpgme/recipient.c @@ -0,0 +1,240 @@ +/* recipient.c - mainatin recipient sets + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "util.h" +#include "context.h" +#include "rungpg.h" + +/** + * gpgme_recipients_new: + * @r_rset: Returns the new object. + * + * Create a new uninitialized Reciepient set Object. + * + * Return value: 0 on success or an error code. + **/ +GpgmeError +gpgme_recipients_new (GpgmeRecipients *r_rset) +{ + GpgmeRecipients rset; + + rset = xtrycalloc ( 1, sizeof *rset ); + if (!rset) + return mk_error (Out_Of_Core); + *r_rset = rset; + return 0; +} + +/** + * gpgme_recipients_release: + * @rset: Recipient Set object + * + * Free the given object. + **/ +void +gpgme_recipients_release ( GpgmeRecipients rset ) +{ + if (rset) { + struct user_id_s *u, *u2; + + for (u = rset->list; u; u = u2) { + u2 = u->next; + xfree(u); + } + } + xfree ( rset ); +} + + +/** + * gpgme_recipients_add_name: + * @rset: Recipient Set object + * @name: user name or keyID + * + * Add a name to the recipient Set. + * + * Return value: 0 on success or an error code + **/ +GpgmeError +gpgme_recipients_add_name (GpgmeRecipients rset, const char *name ) +{ + return gpgme_recipients_add_name_with_validity ( + rset, name, GPGME_VALIDITY_UNKNOWN + ); +} + +/** + * gpgme_recipients_add_name_with_validity: + * @rset: Recipient Set object + * @name: user name or keyID + * @val: Validity value + * + * Same as gpgme_recipients_add_name() but with explictly given key + * validity. Use one of the constants + * %GPGME_VALIDITY_UNKNOWN, %GPGME_VALIDITY_UNDEFINED, + * %GPGME_VALIDITY_NEVER, %GPGME_VALIDITY_MARGINAL, + * %GPGME_VALIDITY_FULL, %GPGME_VALIDITY_ULTIMATE5 + * for the validity. %GPGME_VALIDITY_UNKNOWN is implicitly used by + * gpgme_recipients_add_name(). + * + * Return value: o on success or an error value. + **/ +GpgmeError +gpgme_recipients_add_name_with_validity (GpgmeRecipients rset, + const char *name, + GpgmeValidity val ) +{ + struct user_id_s *r; + + if (!name || !rset ) + return mk_error (Invalid_Value); + r = xtrymalloc ( sizeof *r + strlen (name) ); + if (!r) + return mk_error (Out_Of_Core); + r->validity = val; + r->name_part = ""; + r->email_part = ""; + r->comment_part = ""; + strcpy (r->name, name ); + r->next = rset->list; + rset->list = r; + return 0; +} + + + +/** + * gpgme_recipients_count: + * @rset: Recipient Set object + * + * Return value: The number of recipients in the set. + **/ +unsigned int +gpgme_recipients_count ( const GpgmeRecipients rset ) +{ + struct user_id_s *r; + unsigned int count = 0; + + if ( rset ) { + for (r=rset->list ; r; r = r->next ) + count++; + } + return count; +} + + + +/** + * gpgme_recipients_enum_open: + * @rset: Recipient Set object + * @ctx: Enumerator + * + * Start an enumeration on the Recipient Set object. The caller must pass + * the address of a void pointer which is used as the enumerator object. + * + * Return value: 0 on success or an error code. + * + * See also: gpgme_recipients_enum_read(), gpgme_recipients_enum_close(). + **/ +GpgmeError +gpgme_recipients_enum_open ( const GpgmeRecipients rset, void **ctx ) +{ + if (!rset || !ctx) + return mk_error (Invalid_Value); + + *ctx = rset->list; + return 0; +} + +/** + * gpgme_recipients_enum_read: + * @rset: Recipient Set object + * @ctx: Enumerator + * + * Return the name of the next user name from the given recipient + * set. This name is valid as along as the @rset is valid and until + * the next call to this function. + * + * Return value: name or NULL for no more names. + * + * See also: gpgme_recipients_enum_read(), gpgme_recipients_enum_close(). + **/ +const char * +gpgme_recipients_enum_read ( const GpgmeRecipients rset, void **ctx ) +{ + struct user_id_s *r; + + if (!rset || !ctx) + return NULL; /* oops */ + + r = *ctx; + if ( r ) { + const char *s = r->name; + r = r->next; + *ctx = r; + return s; + } + + return NULL; +} + +/** + * gpgme_recipients_enum_close: + * @rset: Recipient Set object + * @ctx: Enumerator + * + * Release the enumerator @rset for this object. + * + * Return value: 0 on success or %GPGME_Invalid_Value; + * + * See also: gpgme_recipients_enum_read(), gpgme_recipients_enum_close(). + **/ +GpgmeError +gpgme_recipients_enum_close ( const GpgmeRecipients rset, void **ctx ) +{ + if (!rset || !ctx) + return mk_error (Invalid_Value); + *ctx = NULL; + return 0; +} + +int +_gpgme_recipients_all_valid ( const GpgmeRecipients rset ) +{ + struct user_id_s *r; + + assert (rset); + for (r=rset->list ; r; r = r->next ) { + if (r->validity != GPGME_VALIDITY_FULL + && r->validity != GPGME_VALIDITY_ULTIMATE ) + return 0; /*no*/ + } + return 1; /*yes*/ +} + + + diff --git a/tags/V0-3-4/gpgme/rungpg.c b/tags/V0-3-4/gpgme/rungpg.c new file mode 100644 index 0000000..be639b9 --- /dev/null +++ b/tags/V0-3-4/gpgme/rungpg.c @@ -0,0 +1,1597 @@ +/* rungpg.c + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "unistd.h" + +#include "gpgme.h" +#include "util.h" +#include "ops.h" +#include "wait.h" +#include "rungpg.h" +#include "context.h" /*temp hack until we have GpmeData methods to do I/O */ +#include "io.h" +#include "sema.h" + +#include "status-table.h" + + +/* This type is used to build a list of gpg arguments and + * data sources/sinks */ +struct arg_and_data_s { + struct arg_and_data_s *next; + GpgmeData data; /* If this is not NULL .. */ + int dup_to; + int print_fd; /* print the fd number and not the special form of it */ + char arg[1]; /* .. this is used */ +}; + +struct fd_data_map_s { + GpgmeData data; + int inbound; /* true if this is used for reading from gpg */ + int dup_to; + int fd; /* the fd to use */ + int peer_fd; /* the outher side of the pipe */ +}; + + +struct gpg_object_s { + struct arg_and_data_s *arglist; + struct arg_and_data_s **argtail; + int arg_error; + + struct { + int fd[2]; + size_t bufsize; + char *buffer; + size_t readpos; + int eof; + GpgStatusHandler fnc; + void *fnc_value; + } status; + + /* This is a kludge - see the comment at gpg_colon_line_handler */ + struct { + int fd[2]; + size_t bufsize; + char *buffer; + size_t readpos; + int eof; + GpgColonLineHandler fnc; /* this indicate use of this structrue */ + void *fnc_value; + int simple; + } colon; + + char **argv; + struct fd_data_map_s *fd_data_map; + + int pid; /* we can't use pid_t because we don't use it in Windoze */ + + int running; + + /* stuff needed for pipemode */ + struct { + int used; + int active; + GpgmeData sig; + GpgmeData text; + int stream_started; + } pm; + + /* stuff needed for interactive (command) mode */ + struct { + int used; + int fd; + GpgmeData cb_data; /* hack to get init the above fd later */ + GpgStatusCode code; /* last code */ + char *keyword; /* what has been requested (malloced) */ + GpgCommandHandler fnc; + void *fnc_value; + } cmd; +}; + +static void free_argv ( char **argv ); +static void free_fd_data_map ( struct fd_data_map_s *fd_data_map ); + +static int gpg_status_handler ( void *opaque, int pid, int fd ); +static GpgmeError read_status ( GpgObject gpg ); + +static int gpg_colon_line_handler ( void *opaque, int pid, int fd ); +static GpgmeError read_colon_line ( GpgObject gpg ); + +static int pipemode_cb ( void *opaque, + char *buffer, size_t length, size_t *nread ); +static int command_cb ( void *opaque, + char *buffer, size_t length, size_t *nread ); + + +static void +close_notify_handler ( int fd, void *opaque ) +{ + GpgObject gpg = opaque; + + assert (fd != -1); + if (gpg->status.fd[0] == fd ) + gpg->status.fd[0] = -1; + else if (gpg->status.fd[1] == fd ) + gpg->status.fd[1] = -1; + else if (gpg->colon.fd[0] == fd ) + gpg->colon.fd[0] = -1; + else if (gpg->colon.fd[1] == fd ) + gpg->colon.fd[1] = -1; + else if (gpg->fd_data_map) { + int i; + + for (i=0; gpg->fd_data_map[i].data; i++ ) { + if ( gpg->fd_data_map[i].fd == fd ) { + gpg->fd_data_map[i].fd = -1; + break; + } + if ( gpg->fd_data_map[i].peer_fd == fd ) { + gpg->fd_data_map[i].peer_fd = -1; + break; + } + } + } +} + +const char * +_gpgme_gpg_get_version (void) +{ + static const char *gpg_version; + + /* FIXME: Locking. */ + if (!gpg_version) + gpg_version = _gpgme_get_program_version (_gpgme_get_gpg_path ()); + + return gpg_version; +} + +GpgmeError +_gpgme_gpg_check_version (void) +{ + return _gpgme_compare_versions (_gpgme_gpg_get_version (), + NEED_GPG_VERSION) + ? 0 : mk_error (Invalid_Engine); +} + +GpgmeError +_gpgme_gpg_new ( GpgObject *r_gpg ) +{ + GpgObject gpg; + int rc = 0; + + gpg = xtrycalloc ( 1, sizeof *gpg ); + if ( !gpg ) { + rc = mk_error (Out_Of_Core); + goto leave; + } + gpg->argtail = &gpg->arglist; + + gpg->status.fd[0] = -1; + gpg->status.fd[1] = -1; + gpg->colon.fd[0] = -1; + gpg->colon.fd[1] = -1; + gpg->cmd.fd = -1; + + gpg->pid = -1; + + /* allocate the read buffer for the status pipe */ + gpg->status.bufsize = 1024; + gpg->status.readpos = 0; + gpg->status.buffer = xtrymalloc (gpg->status.bufsize); + if (!gpg->status.buffer) { + rc = mk_error (Out_Of_Core); + goto leave; + } + /* In any case we need a status pipe - create it right here and + * don't handle it with our generic GpgmeData mechanism */ + if (_gpgme_io_pipe (gpg->status.fd, 1) == -1) { + rc = mk_error (Pipe_Error); + goto leave; + } + if ( _gpgme_io_set_close_notify (gpg->status.fd[0], + close_notify_handler, gpg) + || _gpgme_io_set_close_notify (gpg->status.fd[1], + close_notify_handler, gpg) ) { + rc = mk_error (General_Error); + goto leave; + } + gpg->status.eof = 0; + _gpgme_gpg_add_arg ( gpg, "--status-fd" ); + { + char buf[25]; + sprintf ( buf, "%d", gpg->status.fd[1]); + _gpgme_gpg_add_arg ( gpg, buf ); + } + _gpgme_gpg_add_arg ( gpg, "--no-tty" ); + + + leave: + if (rc) { + _gpgme_gpg_release (gpg); + *r_gpg = NULL; + } + else + *r_gpg = gpg; + return rc; +} + + +void +_gpgme_gpg_release (GpgObject gpg) +{ + if (!gpg) + return; + + while (gpg->arglist) + { + struct arg_and_data_s *next = gpg->arglist->next; + + xfree (gpg->arglist); + gpg->arglist = next; + } + + xfree (gpg->status.buffer); + xfree (gpg->colon.buffer); + if (gpg->argv) + free_argv (gpg->argv); + xfree (gpg->cmd.cb_data); + xfree (gpg->cmd.keyword); + + if (gpg->pid != -1) + _gpgme_remove_proc_from_wait_queue (gpg->pid); + if (gpg->status.fd[0] != -1) + _gpgme_io_close (gpg->status.fd[0]); + if (gpg->status.fd[1] != -1) + _gpgme_io_close (gpg->status.fd[1]); + if (gpg->colon.fd[0] != -1) + _gpgme_io_close (gpg->colon.fd[0]); + if (gpg->colon.fd[1] != -1) + _gpgme_io_close (gpg->colon.fd[1]); + free_fd_data_map (gpg->fd_data_map); + if (gpg->running) + _gpgme_engine_add_child_to_reap_list (gpg, sizeof *gpg, gpg->pid); + else + xfree (gpg); +} + +void +_gpgme_gpg_enable_pipemode ( GpgObject gpg ) +{ + gpg->pm.used = 1; + assert ( !gpg->pm.sig ); + assert ( !gpg->pm.text ); +} + +GpgmeError +_gpgme_gpg_add_arg ( GpgObject gpg, const char *arg ) +{ + struct arg_and_data_s *a; + + assert (gpg); + assert (arg); + + if (gpg->pm.active) + return 0; + + a = xtrymalloc ( sizeof *a + strlen (arg) ); + if ( !a ) { + gpg->arg_error = 1; + return mk_error(Out_Of_Core); + } + a->next = NULL; + a->data = NULL; + a->dup_to = -1; + strcpy ( a->arg, arg ); + *gpg->argtail = a; + gpg->argtail = &a->next; + return 0; +} + +GpgmeError +_gpgme_gpg_add_data ( GpgObject gpg, GpgmeData data, int dup_to ) +{ + struct arg_and_data_s *a; + + assert (gpg); + assert (data); + if (gpg->pm.active) + return 0; + + a = xtrymalloc ( sizeof *a - 1 ); + if ( !a ) { + gpg->arg_error = 1; + return mk_error(Out_Of_Core); + } + a->next = NULL; + a->data = data; + if ( dup_to == -2 ) { + a->print_fd = 1; + a->dup_to = -1; + } + else { + a->print_fd = 0; + a->dup_to = dup_to; + } + *gpg->argtail = a; + gpg->argtail = &a->next; + return 0; +} + +GpgmeError +_gpgme_gpg_add_pm_data ( GpgObject gpg, GpgmeData data, int what ) +{ + GpgmeError rc=0; + + assert ( gpg->pm.used ); + + if ( !what ) { + /* the signature */ + assert ( !gpg->pm.sig ); + gpg->pm.sig = data; + } + else if (what == 1) { + /* the signed data */ + assert ( !gpg->pm.text ); + gpg->pm.text = data; + } + else { + assert (0); + } + + if ( gpg->pm.sig && gpg->pm.text ) { + if ( !gpg->pm.active ) { + /* create the callback handler and connect it to stdin */ + GpgmeData tmp; + + rc = gpgme_data_new_with_read_cb ( &tmp, pipemode_cb, gpg ); + if (!rc ) + rc = _gpgme_gpg_add_data (gpg, tmp, 0); + } + if ( !rc ) { + /* here we can reset the handler stuff */ + gpg->pm.stream_started = 0; + } + } + + return rc; +} + +/* + * Note, that the status_handler is allowed to modifiy the args value + */ +void +_gpgme_gpg_set_status_handler ( GpgObject gpg, + GpgStatusHandler fnc, void *fnc_value ) +{ + assert (gpg); + if (gpg->pm.active) + return; + + gpg->status.fnc = fnc; + gpg->status.fnc_value = fnc_value; +} + +/* Kludge to process --with-colon output */ +GpgmeError +_gpgme_gpg_set_colon_line_handler ( GpgObject gpg, + GpgColonLineHandler fnc, void *fnc_value ) +{ + assert (gpg); + if (gpg->pm.active) + return 0; + + gpg->colon.bufsize = 1024; + gpg->colon.readpos = 0; + gpg->colon.buffer = xtrymalloc (gpg->colon.bufsize); + if (!gpg->colon.buffer) { + return mk_error (Out_Of_Core); + } + if (_gpgme_io_pipe (gpg->colon.fd, 1) == -1) { + xfree (gpg->colon.buffer); gpg->colon.buffer = NULL; + return mk_error (Pipe_Error); + } + if ( _gpgme_io_set_close_notify (gpg->colon.fd[0], + close_notify_handler, gpg) + || _gpgme_io_set_close_notify (gpg->colon.fd[1], + close_notify_handler, gpg) ) { + return mk_error (General_Error); + } + gpg->colon.eof = 0; + gpg->colon.fnc = fnc; + gpg->colon.fnc_value = fnc_value; + gpg->colon.simple = 0; + return 0; +} + + +GpgmeError +_gpgme_gpg_set_simple_line_handler ( GpgObject gpg, + GpgColonLineHandler fnc, + void *fnc_value ) +{ + GpgmeError err; + + err = _gpgme_gpg_set_colon_line_handler (gpg, fnc, fnc_value); + if (!err) + gpg->colon.simple = 1; + return err; +} + + +/* + * The Fnc will be called to get a value for one of the commands with + * a key KEY. If the Code pssed to FNC is 0, the function may release + * resources associated with the returned value from another call. To + * match such a second call to a first call, the returned value from + * the first call is passed as keyword. + */ + +GpgmeError +_gpgme_gpg_set_command_handler ( GpgObject gpg, + GpgCommandHandler fnc, void *fnc_value ) +{ + GpgmeData tmp; + GpgmeError err; + + assert (gpg); + if (gpg->pm.active) + return 0; + + err = gpgme_data_new_with_read_cb ( &tmp, command_cb, gpg ); + if (err) + return err; + + _gpgme_gpg_add_arg ( gpg, "--command-fd" ); + _gpgme_gpg_add_data (gpg, tmp, -2); + gpg->cmd.cb_data = tmp; + gpg->cmd.fnc = fnc; + gpg->cmd.fnc_value = fnc_value; + gpg->cmd.used = 1; + return 0; +} + + +static void +free_argv ( char **argv ) +{ + int i; + + for (i=0; argv[i]; i++ ) + xfree (argv[i]); + xfree (argv); +} + +static void +free_fd_data_map ( struct fd_data_map_s *fd_data_map ) +{ + int i; + + if ( !fd_data_map ) + return; + + for (i=0; fd_data_map[i].data; i++ ) { + if ( fd_data_map[i].fd != -1 ) + _gpgme_io_close (fd_data_map[i].fd); + if ( fd_data_map[i].peer_fd != -1 ) + _gpgme_io_close (fd_data_map[i].peer_fd); + /* don't release data because this is only a reference */ + } + xfree (fd_data_map); +} + + +static GpgmeError +build_argv ( GpgObject gpg ) +{ + struct arg_and_data_s *a; + struct fd_data_map_s *fd_data_map; + size_t datac=0, argc=0; + char **argv; + int need_special = 0; + int use_agent = !!getenv ("GPG_AGENT_INFO"); + + if ( gpg->argv ) { + free_argv ( gpg->argv ); + gpg->argv = NULL; + } + if (gpg->fd_data_map) { + free_fd_data_map (gpg->fd_data_map); + gpg->fd_data_map = NULL; + } + + argc++; /* for argv[0] */ + for ( a=gpg->arglist; a; a = a->next ) { + argc++; + if (a->data) { + /*fprintf (stderr, "build_argv: data\n" );*/ + datac++; + if ( a->dup_to == -1 && !a->print_fd ) + need_special = 1; + } + else { + /* fprintf (stderr, "build_argv: arg=`%s'\n", a->arg );*/ + } + } + if ( need_special ) + argc++; + if (use_agent) + argc++; + if (!gpg->cmd.used) + argc++; + argc += 2; /* --comment */ + + argv = xtrycalloc ( argc+1, sizeof *argv ); + if (!argv) + return mk_error (Out_Of_Core); + fd_data_map = xtrycalloc ( datac+1, sizeof *fd_data_map ); + if (!fd_data_map) { + free_argv (argv); + return mk_error (Out_Of_Core); + } + + argc = datac = 0; + argv[argc] = xtrystrdup ( "gpg" ); /* argv[0] */ + if (!argv[argc]) { + xfree (fd_data_map); + free_argv (argv); + return mk_error (Out_Of_Core); + } + argc++; + if ( need_special ) { + argv[argc] = xtrystrdup ( "--enable-special-filenames" ); + if (!argv[argc]) { + xfree (fd_data_map); + free_argv (argv); + return mk_error (Out_Of_Core); + } + argc++; + } + if ( use_agent ) { + argv[argc] = xtrystrdup ( "--use-agent" ); + if (!argv[argc]) { + xfree (fd_data_map); + free_argv (argv); + return mk_error (Out_Of_Core); + } + argc++; + } + if ( !gpg->cmd.used ) { + argv[argc] = xtrystrdup ( "--batch" ); + if (!argv[argc]) { + xfree (fd_data_map); + free_argv (argv); + return mk_error (Out_Of_Core); + } + argc++; + } + argv[argc] = xtrystrdup ( "--comment" ); + if (!argv[argc]) { + xfree (fd_data_map); + free_argv (argv); + return mk_error (Out_Of_Core); + } + argc++; + argv[argc] = xtrystrdup ( "" ); + if (!argv[argc]) { + xfree (fd_data_map); + free_argv (argv); + return mk_error (Out_Of_Core); + } + argc++; + for ( a=gpg->arglist; a; a = a->next ) { + if ( a->data ) { + switch ( _gpgme_data_get_mode (a->data) ) { + case GPGME_DATA_MODE_NONE: + case GPGME_DATA_MODE_INOUT: + xfree (fd_data_map); + free_argv (argv); + return mk_error (Invalid_Mode); + case GPGME_DATA_MODE_IN: + /* create a pipe to read from gpg */ + fd_data_map[datac].inbound = 1; + break; + case GPGME_DATA_MODE_OUT: + /* create a pipe to pass it down to gpg */ + fd_data_map[datac].inbound = 0; + break; + } + + switch ( gpgme_data_get_type (a->data) ) { + case GPGME_DATA_TYPE_NONE: + if ( fd_data_map[datac].inbound ) + break; /* allowed */ + xfree (fd_data_map); + free_argv (argv); + return mk_error (Invalid_Type); + case GPGME_DATA_TYPE_MEM: + case GPGME_DATA_TYPE_CB: + break; + case GPGME_DATA_TYPE_FD: + case GPGME_DATA_TYPE_FILE: + xfree (fd_data_map); + free_argv (argv); + return mk_error (Not_Implemented); + } + + /* create a pipe */ + { + int fds[2]; + + if (_gpgme_io_pipe (fds, fd_data_map[datac].inbound?1:0 ) + == -1) { + xfree (fd_data_map); + free_argv (argv); + return mk_error (Pipe_Error); + } + if ( _gpgme_io_set_close_notify (fds[0], + close_notify_handler, gpg) + || _gpgme_io_set_close_notify (fds[1], + close_notify_handler, + gpg)) { + return mk_error (General_Error); + } + /* if the data_type is FD, we have to do a dup2 here */ + if (fd_data_map[datac].inbound) { + fd_data_map[datac].fd = fds[0]; + fd_data_map[datac].peer_fd = fds[1]; + } + else { + fd_data_map[datac].fd = fds[1]; + fd_data_map[datac].peer_fd = fds[0]; + } + } + + /* Hack to get hands on the fd later */ + if ( gpg->cmd.used && gpg->cmd.cb_data == a->data ) { + assert (gpg->cmd.fd == -1); + gpg->cmd.fd = fd_data_map[datac].fd; + } + + fd_data_map[datac].data = a->data; + fd_data_map[datac].dup_to = a->dup_to; + if ( a->dup_to == -1 ) { + argv[argc] = xtrymalloc ( 25 ); + if (!argv[argc]) { + xfree (fd_data_map); + free_argv (argv); + return mk_error (Out_Of_Core); + } + sprintf ( argv[argc], + a->print_fd? "%d" : "-&%d", + fd_data_map[datac].peer_fd ); + argc++; + } + datac++; + } + else { + argv[argc] = xtrystrdup ( a->arg ); + if (!argv[argc]) { + xfree (fd_data_map); + free_argv (argv); + return mk_error (Out_Of_Core); + } + argc++; + } + } + + gpg->argv = argv; + gpg->fd_data_map = fd_data_map; + return 0; +} + +GpgmeError +_gpgme_gpg_spawn( GpgObject gpg, void *opaque ) +{ + int rc; + int i, n; + int pid; + struct spawn_fd_item_s *fd_child_list, *fd_parent_list; + + if (!gpg) + return mk_error (Invalid_Value); + + if (! _gpgme_get_gpg_path ()) + return mk_error (Invalid_Engine); + + /* Kludge, so that we don't need to check the return code of + * all the gpgme_gpg_add_arg(). we bail out here instead */ + if ( gpg->arg_error ) + return mk_error (Out_Of_Core); + + if (gpg->pm.active) + return 0; + + rc = build_argv ( gpg ); + if ( rc ) + return rc; + + n = 3; /* status_fd, colon_fd and end of list */ + for (i=0; gpg->fd_data_map[i].data; i++ ) + n++; + fd_child_list = xtrycalloc ( n+n, sizeof *fd_child_list ); + if (!fd_child_list) + return mk_error (Out_Of_Core); + fd_parent_list = fd_child_list + n; + + /* build the fd list for the child */ + n=0; + if ( gpg->colon.fnc ) { + fd_child_list[n].fd = gpg->colon.fd[1]; + fd_child_list[n].dup_to = 1; /* dup to stdout */ + n++; + } + for (i=0; gpg->fd_data_map[i].data; i++ ) { + if (gpg->fd_data_map[i].dup_to != -1) { + fd_child_list[n].fd = gpg->fd_data_map[i].peer_fd; + fd_child_list[n].dup_to = gpg->fd_data_map[i].dup_to; + n++; + } + } + fd_child_list[n].fd = -1; + fd_child_list[n].dup_to = -1; + + /* build the fd list for the parent */ + n=0; + if ( gpg->status.fd[1] != -1 ) { + fd_parent_list[n].fd = gpg->status.fd[1]; + fd_parent_list[n].dup_to = -1; + n++; + gpg->status.fd[1] = -1; + } + if ( gpg->colon.fd[1] != -1 ) { + fd_parent_list[n].fd = gpg->colon.fd[1]; + fd_parent_list[n].dup_to = -1; + n++; + gpg->colon.fd[1] = -1; + } + for (i=0; gpg->fd_data_map[i].data; i++ ) { + fd_parent_list[n].fd = gpg->fd_data_map[i].peer_fd; + fd_parent_list[n].dup_to = -1; + n++; + gpg->fd_data_map[i].peer_fd = -1; + } + fd_parent_list[n].fd = -1; + fd_parent_list[n].dup_to = -1; + + + pid = _gpgme_io_spawn (_gpgme_get_gpg_path (), + gpg->argv, fd_child_list, fd_parent_list); + xfree (fd_child_list); + if (pid == -1) { + return mk_error (Exec_Error); + } + + gpg->pid = pid; + if (gpg->pm.used) + gpg->pm.active = 1; + + /*_gpgme_register_term_handler ( closure, closure_value, pid );*/ + + if ( _gpgme_register_pipe_handler ( opaque, gpg_status_handler, + gpg, pid, gpg->status.fd[0], 1 ) ) { + /* FIXME: kill the child */ + return mk_error (General_Error); + + } + + if ( gpg->colon.fnc ) { + assert ( gpg->colon.fd[0] != -1 ); + if ( _gpgme_register_pipe_handler ( opaque, gpg_colon_line_handler, + gpg, pid, gpg->colon.fd[0], 1 ) ) { + /* FIXME: kill the child */ + return mk_error (General_Error); + + } + } + + for (i=0; gpg->fd_data_map[i].data; i++ ) { + /* Due to problems with select and write we set outbound pipes + * to non-blocking */ + if (!gpg->fd_data_map[i].inbound) { + _gpgme_io_set_nonblocking (gpg->fd_data_map[i].fd); + } + + if ( _gpgme_register_pipe_handler ( + opaque, + gpg->fd_data_map[i].inbound? + _gpgme_data_inbound_handler:_gpgme_data_outbound_handler, + gpg->fd_data_map[i].data, + pid, gpg->fd_data_map[i].fd, + gpg->fd_data_map[i].inbound ) + ) { + /* FIXME: kill the child */ + return mk_error (General_Error); + } + } + + if ( gpg->cmd.used ) + _gpgme_freeze_fd ( gpg->cmd.fd ); + + /* fixme: check what data we can release here */ + + gpg->running = 1; + return 0; +} + + +static int +gpg_status_handler (void *opaque, int pid, int fd) +{ + GpgObject gpg = opaque; + int err; + + assert (fd == gpg->status.fd[0]); + err = read_status (gpg); + if (err) + { + /* XXX Horrible kludge. We really must not make use of + fnc_value. */ + GpgmeCtx ctx = (GpgmeCtx) gpg->status.fnc_value; + ctx->error = err; + DEBUG1 ("gpg_handler: read_status problem %d\n - stop", err); + return 1; + } + return gpg->status.eof; +} + + +static int +status_cmp (const void *ap, const void *bp) +{ + const struct status_table_s *a = ap; + const struct status_table_s *b = bp; + + return strcmp (a->name, b->name); +} + + + +/* + * Handle the status output of GnuPG. This function does read entire + * lines and passes them as C strings to the callback function (we can + * use C Strings because the status output is always UTF-8 encoded). + * Of course we have to buffer the lines to cope with long lines + * e.g. with a large user ID. Note: We can optimize this to only cope + * with status line code we know about and skip all other stuff + * without buffering (i.e. without extending the buffer). */ +static GpgmeError +read_status ( GpgObject gpg ) +{ + char *p; + int nread; + size_t bufsize = gpg->status.bufsize; + char *buffer = gpg->status.buffer; + size_t readpos = gpg->status.readpos; + + assert (buffer); + if (bufsize - readpos < 256) { + /* need more room for the read */ + bufsize += 1024; + buffer = xtryrealloc (buffer, bufsize); + if ( !buffer ) + return mk_error (Out_Of_Core); + } + + + nread = _gpgme_io_read ( gpg->status.fd[0], + buffer+readpos, bufsize-readpos ); + if (nread == -1) + return mk_error(Read_Error); + + if (!nread) { + gpg->status.eof = 1; + if (gpg->status.fnc) + gpg->status.fnc ( gpg->status.fnc_value, STATUS_EOF, "" ); + return 0; + } + + while (nread > 0) { + for (p = buffer + readpos; nread; nread--, p++) { + if ( *p == '\n' ) { + /* (we require that the last line is terminated by a LF) */ + *p = 0; + if (!strncmp (buffer, "[GNUPG:] ", 9 ) + && buffer[9] >= 'A' && buffer[9] <= 'Z' ) { + struct status_table_s t, *r; + char *rest; + + rest = strchr (buffer+9, ' '); + if ( !rest ) + rest = p; /* set to an empty string */ + else + *rest++ = 0; + + t.name = buffer+9; + /* (the status table as one extra element) */ + r = bsearch ( &t, status_table, DIM(status_table)-1, + sizeof t, status_cmp ); + if ( r ) { + if ( gpg->cmd.used + && ( r->code == STATUS_GET_BOOL + || r->code == STATUS_GET_LINE + || r->code == STATUS_GET_HIDDEN )) { + gpg->cmd.code = r->code; + xfree (gpg->cmd.keyword); + gpg->cmd.keyword = xtrystrdup (rest); + if ( !gpg->cmd.keyword ) + return mk_error (Out_Of_Core); + /* this should be the last thing we have received + * and the next thing will be that the command + * handler does its action */ + if ( nread > 1 ) + DEBUG0 ("ERROR, unexpected data in read_status"); + _gpgme_thaw_fd (gpg->cmd.fd); + } + else if ( gpg->status.fnc ) { + gpg->status.fnc ( gpg->status.fnc_value, + r->code, rest); + } + + if ( r->code == STATUS_END_STREAM ) { + if ( gpg->cmd.used ) + _gpgme_freeze_fd ( gpg->cmd.fd ); + } + } + } + /* To reuse the buffer for the next line we have to + * shift the remaining data to the buffer start and + * restart the loop Hmmm: We can optimize this + * function by looking forward in the buffer to see + * whether a second complete line is available and in + * this case avoid the memmove for this line. */ + nread--; p++; + if (nread) + memmove (buffer, p, nread); + readpos = 0; + break; /* the for loop */ + } + else + readpos++; + } + } + + /* Update the gpg object. */ + gpg->status.bufsize = bufsize; + gpg->status.buffer = buffer; + gpg->status.readpos = readpos; + return 0; +} + + +/* + * This colonline handler thing is not the clean way to do it. + * It might be better to enhance the GpgmeData object to act as + * a wrapper for a callback. Same goes for the status thing. + * For now we use this thing here becuase it is easier to implement. + */ +static int +gpg_colon_line_handler ( void *opaque, int pid, int fd ) +{ + GpgObject gpg = opaque; + GpgmeError rc = 0; + + assert ( fd == gpg->colon.fd[0] ); + rc = read_colon_line ( gpg ); + if ( rc ) { + DEBUG1 ("gpg_colon_line_handler: " + "read problem %d\n - stop", rc); + return 1; + } + + return gpg->colon.eof; +} + +static GpgmeError +read_colon_line ( GpgObject gpg ) +{ + char *p; + int nread; + size_t bufsize = gpg->colon.bufsize; + char *buffer = gpg->colon.buffer; + size_t readpos = gpg->colon.readpos; + + assert (buffer); + if (bufsize - readpos < 256) { + /* need more room for the read */ + bufsize += 1024; + buffer = xtryrealloc (buffer, bufsize); + if ( !buffer ) + return mk_error (Out_Of_Core); + } + + + nread = _gpgme_io_read ( gpg->colon.fd[0], + buffer+readpos, bufsize-readpos ); + if (nread == -1) + return mk_error(Read_Error); + + if (!nread) { + gpg->colon.eof = 1; + assert (gpg->colon.fnc); + gpg->colon.fnc ( gpg->colon.fnc_value, NULL ); + return 0; + } + + while (nread > 0) { + for (p = buffer + readpos; nread; nread--, p++) { + if ( *p == '\n' ) { + /* (we require that the last line is terminated by a + * LF) and we skip empty lines. Note: we use UTF8 + * encoding and escaping of special characters + * We require at least one colon to cope with + * some other printed information. + */ + *p = 0; + if ( gpg->colon.simple + || (*buffer && strchr (buffer, ':')) ) { + assert (gpg->colon.fnc); + gpg->colon.fnc ( gpg->colon.fnc_value, buffer ); + } + + /* To reuse the buffer for the next line we have to + * shift the remaining data to the buffer start and + * restart the loop Hmmm: We can optimize this + * function by looking forward in the buffer to see + * whether a second complete line is available and in + * this case avoid the memmove for this line. */ + nread--; p++; + if (nread) + memmove (buffer, p, nread); + readpos = 0; + break; /* the for loop */ + } + else + readpos++; + } + } + + /* Update the gpg object. */ + gpg->colon.bufsize = bufsize; + gpg->colon.buffer = buffer; + gpg->colon.readpos = readpos; + return 0; +} + +static GpgmeError +pipemode_copy (char *buffer, size_t length, size_t *nread, GpgmeData data ) +{ + GpgmeError err; + size_t nbytes; + char tmp[1000], *s, *d; + + /* we can optimize this whole thing but for now we just + * return after each escape character */ + if (length > 990) + length = 990; + + err = gpgme_data_read ( data, tmp, length, &nbytes ); + if (err) + return err; + for (s=tmp, d=buffer; nbytes; s++, nbytes--) { + *d++ = *s; + if (*s == '@' ) { + *d++ = '@'; + break; + } + } + *nread = d - buffer; + return 0; +} + + +static int +pipemode_cb ( void *opaque, char *buffer, size_t length, size_t *nread ) +{ + GpgObject gpg = opaque; + GpgmeError err; + + if ( !buffer || !length || !nread ) + return 0; /* those values are reserved for extensions */ + *nread =0; + if ( !gpg->pm.stream_started ) { + assert (length > 4 ); + strcpy (buffer, "@<@B" ); + *nread = 4; + gpg->pm.stream_started = 1; + } + else if ( gpg->pm.sig ) { + err = pipemode_copy ( buffer, length, nread, gpg->pm.sig ); + if ( err == GPGME_EOF ) { + gpg->pm.sig = NULL; + assert (length > 4 ); + strcpy (buffer, "@t" ); + *nread = 2; + } + else if (err) { + DEBUG1 ("pipemode_cb: copy sig failed: %s\n", + gpgme_strerror (err) ); + return -1; + } + } + else if ( gpg->pm.text ) { + err = pipemode_copy ( buffer, length, nread, gpg->pm.text ); + if ( err == GPGME_EOF ) { + gpg->pm.text = NULL; + assert (length > 4 ); + strcpy (buffer, "@.@>" ); + *nread = 4; + } + else if (err) { + DEBUG1 ("pipemode_cb: copy data failed: %s\n", + gpgme_strerror (err) ); + return -1; + } + } + else { + return 0; /* eof */ + } + + return 0; +} + + +/* + * Here we handle --command-fd. This works closely together with + * the status handler. + */ + +static int +command_cb ( void *opaque, char *buffer, size_t length, size_t *nread ) +{ + GpgObject gpg = opaque; + const char *value; + int value_len; + + DEBUG0 ("command_cb: enter\n"); + assert (gpg->cmd.used); + if ( !buffer || !length || !nread ) + return 0; /* those values are reserved for extensions */ + *nread =0; + if ( !gpg->cmd.code ) { + DEBUG0 ("command_cb: no code\n"); + return -1; + } + + if ( !gpg->cmd.fnc ) { + DEBUG0 ("command_cb: no user cb\n"); + return -1; + } + + value = gpg->cmd.fnc ( gpg->cmd.fnc_value, + gpg->cmd.code, gpg->cmd.keyword ); + if ( !value ) { + DEBUG0 ("command_cb: no data from user cb\n"); + gpg->cmd.fnc ( gpg->cmd.fnc_value, 0, value); + return -1; + } + + value_len = strlen (value); + if ( value_len+1 > length ) { + DEBUG0 ("command_cb: too much data from user cb\n"); + gpg->cmd.fnc ( gpg->cmd.fnc_value, 0, value); + return -1; + } + + memcpy ( buffer, value, value_len ); + if ( !value_len || (value_len && value[value_len-1] != '\n') ) + buffer[value_len++] = '\n'; + *nread = value_len; + + gpg->cmd.fnc ( gpg->cmd.fnc_value, 0, value); + gpg->cmd.code = 0; + /* and sleep again until read_status will wake us up again */ + _gpgme_freeze_fd ( gpg->cmd.fd ); + return 0; +} + +GpgmeError +_gpgme_gpg_op_decrypt (GpgObject gpg, GpgmeData ciph, GpgmeData plain) +{ + GpgmeError err; + + err = _gpgme_gpg_add_arg (gpg, "--decrypt"); + + /* Tell the gpg object about the data. */ + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--output"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, "-"); + if (!err) + err = _gpgme_gpg_add_data (gpg, plain, 1); + if (!err) + err = _gpgme_gpg_add_data (gpg, ciph, 0); + + return err; +} + +GpgmeError +_gpgme_gpg_op_delete (GpgObject gpg, GpgmeKey key, int allow_secret) +{ + GpgmeError err; + + err = _gpgme_gpg_add_arg (gpg, allow_secret + ? "--delete-secret-and-public-key" + : "--delete-key"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--"); + if (!err) + { + const char *s = gpgme_key_get_string_attr (key, GPGME_ATTR_FPR, NULL, 0); + if (!s) + err = mk_error (Invalid_Key); + else + err = _gpgme_gpg_add_arg (gpg, s); + } + + return err; +} + + +static GpgmeError +_gpgme_append_gpg_args_from_recipients (GpgObject gpg, + const GpgmeRecipients rset) +{ + GpgmeError err = 0; + struct user_id_s *r; + + assert (rset); + for (r = rset->list; r; r = r->next) + { + err = _gpgme_gpg_add_arg (gpg, "-r"); + if (!err) + _gpgme_gpg_add_arg (gpg, r->name); + if (err) + break; + } + return err; +} + + +static GpgmeError +_gpgme_append_gpg_args_from_signers (GpgObject gpg, + GpgmeCtx ctx /* FIXME */) +{ + GpgmeError err = 0; + int i; + GpgmeKey key; + + for (i = 0; (key = gpgme_signers_enum (ctx, i)); i++) + { + const char *s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, + NULL, 0); + if (s) + { + if (!err) + err = _gpgme_gpg_add_arg (gpg, "-u"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, s); + } + gpgme_key_unref (key); + if (err) break; + } + return err; +} + + +GpgmeError +_gpgme_gpg_op_encrypt (GpgObject gpg, GpgmeRecipients recp, + GpgmeData plain, GpgmeData ciph, int use_armor) +{ + GpgmeError err; + + err = _gpgme_gpg_add_arg (gpg, "--encrypt"); + if (!err && use_armor) + err = _gpgme_gpg_add_arg (gpg, "--armor"); + + /* If we know that all recipients are valid (full or ultimate trust) + * we can suppress further checks */ + if (!err && _gpgme_recipients_all_valid (recp)) + err = _gpgme_gpg_add_arg (gpg, "--always-trust"); + + if (!err) + err = _gpgme_append_gpg_args_from_recipients (gpg, recp); + + /* Tell the gpg object about the data. */ + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--output"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, "-"); + if (!err) + err = _gpgme_gpg_add_data (gpg, ciph, 1); + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--"); + if (!err) + err = _gpgme_gpg_add_data (gpg, plain, 0); + + return err; +} + +GpgmeError +_gpgme_gpg_op_encrypt_sign (GpgObject gpg, GpgmeRecipients recp, + GpgmeData plain, GpgmeData ciph, int use_armor, + GpgmeCtx ctx /* FIXME */) +{ + GpgmeError err; + + err = _gpgme_gpg_add_arg (gpg, "--encrypt"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--sign"); + if (!err && use_armor) + err = _gpgme_gpg_add_arg (gpg, "--armor"); + + /* If we know that all recipients are valid (full or ultimate trust) + * we can suppress further checks */ + if (!err && _gpgme_recipients_all_valid (recp)) + err = _gpgme_gpg_add_arg (gpg, "--always-trust"); + + if (!err) + err = _gpgme_append_gpg_args_from_recipients (gpg, recp); + + if (!err) + err = _gpgme_append_gpg_args_from_signers (gpg, ctx); + + /* Tell the gpg object about the data. */ + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--output"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, "-"); + if (!err) + err = _gpgme_gpg_add_data (gpg, ciph, 1); + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--"); + if (!err) + err = _gpgme_gpg_add_data (gpg, plain, 0); + + return err; +} + +GpgmeError +_gpgme_gpg_op_export (GpgObject gpg, GpgmeRecipients recp, + GpgmeData keydata, int use_armor) +{ + GpgmeError err; + + err = _gpgme_gpg_add_arg (gpg, "--export"); + if (!err && use_armor) + err = _gpgme_gpg_add_arg (gpg, "--armor"); + if (!err) + err = _gpgme_gpg_add_data (gpg, keydata, 1); + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--"); + + if (!err) + { + void *ec; + const char *s; + + err = gpgme_recipients_enum_open (recp, &ec); + while (!err && (s = gpgme_recipients_enum_read (recp, &ec))) + err = _gpgme_gpg_add_arg (gpg, s); + if (!err) + err = gpgme_recipients_enum_close (recp, &ec); + } + + return err; +} + +GpgmeError +_gpgme_gpg_op_genkey (GpgObject gpg, GpgmeData help_data, int use_armor, + GpgmeData pubkey, GpgmeData seckey) +{ + GpgmeError err; + + if (!gpg) + return mk_error (Invalid_Value); + + /* We need a special mechanism to get the fd of a pipe here, so + * that we can use this for the %pubring and %secring parameters. + * We don't have this yet, so we implement only the adding to the + * standard keyrings */ + if (pubkey || seckey) + return err = mk_error (Not_Implemented); + + err = _gpgme_gpg_add_arg (gpg, "--gen-key"); + if (!err && use_armor) + err = _gpgme_gpg_add_arg (gpg, "--armor"); + if (!err) + err = _gpgme_gpg_add_data (gpg, help_data, 0); + + return err; +} + +GpgmeError +_gpgme_gpg_op_import (GpgObject gpg, GpgmeData keydata) +{ + GpgmeError err; + + err = _gpgme_gpg_add_arg (gpg, "--import"); + if (!err) + err = _gpgme_gpg_add_data (gpg, keydata, 0); + + return err; +} + + +GpgmeError +_gpgme_gpg_op_keylist (GpgObject gpg, const char *pattern, int secret_only, + int keylist_mode) +{ + GpgmeError err; + + err = _gpgme_gpg_add_arg (gpg, "--with-colons"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--fixed-list-mode"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--with-fingerprint"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, secret_only ? "--list-secret-keys" + : "--list-keys"); + + /* Tell the gpg object about the data */ + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--"); + if (!err && pattern && *pattern) + err = _gpgme_gpg_add_arg (gpg, pattern); + + return err; +} + + +GpgmeError +_gpgme_gpg_op_keylist_ext (GpgObject gpg, const char *pattern[], + int secret_only, int reserved, int keylist_mode) +{ + GpgmeError err; + + if (reserved) + return mk_error (Invalid_Value); + + err = _gpgme_gpg_add_arg (gpg, "--with-colons"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--fixed-list-mode"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--with-fingerprint"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, secret_only ? "--list-secret-keys" + : "--list-keys"); + + /* Tell the gpg object about the data */ + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--"); + if (!err && pattern && *pattern) + { + while (*pattern) + err = _gpgme_gpg_add_arg (gpg, *(pattern++)); + } + + return err; +} + + +GpgmeError +_gpgme_gpg_op_sign (GpgObject gpg, GpgmeData in, GpgmeData out, + GpgmeSigMode mode, int use_armor, + int use_textmode, GpgmeCtx ctx /* FIXME */) +{ + GpgmeError err; + + if (mode == GPGME_SIG_MODE_CLEAR) + err = _gpgme_gpg_add_arg (gpg, "--clearsign"); + else + { + err = _gpgme_gpg_add_arg (gpg, "--sign"); + if (!err && mode == GPGME_SIG_MODE_DETACH) + err = _gpgme_gpg_add_arg (gpg, "--detach"); + if (!err && use_armor) + err = _gpgme_gpg_add_arg (gpg, "--armor"); + if (!err && use_textmode) + _gpgme_gpg_add_arg (gpg, "--textmode"); + } + + if (!err) + err = _gpgme_append_gpg_args_from_signers (gpg, ctx); + + /* Tell the gpg object about the data. */ + if (!err) + err = _gpgme_gpg_add_data (gpg, in, 0); + if (!err) + err = _gpgme_gpg_add_data (gpg, out, 1); + + return err; +} + +GpgmeError +_gpgme_gpg_op_trustlist (GpgObject gpg, const char *pattern) +{ + GpgmeError err; + + err = _gpgme_gpg_add_arg (gpg, "--with-colons"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--list-trust-path"); + + /* Tell the gpg object about the data */ + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, pattern); + + return err; +} + +GpgmeError +_gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, GpgmeData text) +{ + GpgmeError err = 0; + + if (_gpgme_data_get_mode (text) == GPGME_DATA_MODE_IN) + { + /* Normal or cleartext signature. */ + + err = _gpgme_gpg_add_arg (gpg, "--output"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, "-"); + if (!err) + err = _gpgme_gpg_add_data (gpg, sig, 0); + if (!err) + err = _gpgme_gpg_add_data (gpg, text, 1); + } + else + { + if (gpg->pm.used) + { + err = _gpgme_gpg_add_arg (gpg, gpg->pm.used ? "--pipemode" : "--verify"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--"); + if (!err) + err = _gpgme_gpg_add_pm_data (gpg, sig, 0); + if (!err) + err = _gpgme_gpg_add_pm_data (gpg, text, 1); + } + else + { + err = _gpgme_gpg_add_arg (gpg, "--verify"); + if (!err) + err = _gpgme_gpg_add_arg (gpg, "--"); + if (!err) + err = _gpgme_gpg_add_data (gpg, sig, -1); + if (text) + { + if (!err) + err = _gpgme_gpg_add_arg (gpg, "-"); + if (!err) + err = _gpgme_gpg_add_data (gpg, text, 0); + } + } + } + return err; +} diff --git a/tags/V0-3-4/gpgme/rungpg.h b/tags/V0-3-4/gpgme/rungpg.h new file mode 100644 index 0000000..58afd8a --- /dev/null +++ b/tags/V0-3-4/gpgme/rungpg.h @@ -0,0 +1,150 @@ +/* rungpg.h - gpg calling functions + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef RUNGPG_H +#define RUNGPG_H + +#include "types.h" + + +typedef enum { + STATUS_EOF , + /* mkstatus starts here */ + STATUS_ENTER , + STATUS_LEAVE , + STATUS_ABORT , + STATUS_GOODSIG , + STATUS_BADSIG , + STATUS_ERRSIG , + STATUS_BADARMOR , + STATUS_RSA_OR_IDEA , + STATUS_SIGEXPIRED , + STATUS_KEYREVOKED , + STATUS_TRUST_UNDEFINED , + STATUS_TRUST_NEVER , + STATUS_TRUST_MARGINAL , + STATUS_TRUST_FULLY , + STATUS_TRUST_ULTIMATE , + STATUS_SHM_INFO , + STATUS_SHM_GET , + STATUS_SHM_GET_BOOL , + STATUS_SHM_GET_HIDDEN , + STATUS_NEED_PASSPHRASE , + STATUS_UNEXPECTED , + STATUS_VALIDSIG , + STATUS_SIG_ID , + STATUS_ENC_TO , + STATUS_NODATA , + STATUS_BAD_PASSPHRASE , + STATUS_NO_PUBKEY , + STATUS_NO_SECKEY , + STATUS_NEED_PASSPHRASE_SYM, + STATUS_DECRYPTION_FAILED , + STATUS_DECRYPTION_OKAY , + STATUS_MISSING_PASSPHRASE , + STATUS_GOOD_PASSPHRASE , + STATUS_GOODMDC , + STATUS_BADMDC , + STATUS_ERRMDC , + STATUS_IMPORTED , + STATUS_IMPORT_RES , + STATUS_FILE_START , + STATUS_FILE_DONE , + STATUS_FILE_ERROR , + STATUS_BEGIN_DECRYPTION , + STATUS_END_DECRYPTION , + STATUS_BEGIN_ENCRYPTION , + STATUS_END_ENCRYPTION , + STATUS_DELETE_PROBLEM , + STATUS_GET_BOOL , + STATUS_GET_LINE , + STATUS_GET_HIDDEN , + STATUS_GOT_IT , + STATUS_PROGRESS , + STATUS_SIG_CREATED , + STATUS_KEY_CREATED , + STATUS_SESSION_KEY , + STATUS_NOTATION_NAME , + STATUS_NOTATION_DATA , + STATUS_USERID_HINT , + STATUS_POLICY_URL , + STATUS_BEGIN_STREAM , + STATUS_END_STREAM , + STATUS_INV_RECP , + STATUS_NO_RECP +} GpgStatusCode; + +typedef void (*GpgStatusHandler)( GpgmeCtx, GpgStatusCode code, char *args ); +typedef void (*GpgColonLineHandler)( GpgmeCtx, char *line ); +typedef const char *(*GpgCommandHandler)(void*, GpgStatusCode code, + const char *keyword); + +const char *_gpgme_gpg_get_version (void); +GpgmeError _gpgme_gpg_check_version (void); + +GpgmeError _gpgme_gpg_new ( GpgObject *r_gpg ); +void _gpgme_gpg_release ( GpgObject gpg ); +void _gpgme_gpg_housecleaning (void); +void _gpgme_gpg_enable_pipemode ( GpgObject gpg ); +GpgmeError _gpgme_gpg_add_arg ( GpgObject gpg, const char *arg ); +GpgmeError _gpgme_gpg_add_data ( GpgObject gpg, GpgmeData data, int dup_to ); +GpgmeError _gpgme_gpg_add_pm_data ( GpgObject gpg, GpgmeData data, int what ); +void _gpgme_gpg_set_status_handler ( GpgObject gpg, + GpgStatusHandler fnc, + void *fnc_value ); +GpgmeError _gpgme_gpg_set_colon_line_handler ( GpgObject gpg, + GpgColonLineHandler fnc, + void *fnc_value ); +GpgmeError _gpgme_gpg_set_simple_line_handler ( GpgObject gpg, + GpgColonLineHandler fnc, + void *fnc_value ); +GpgmeError _gpgme_gpg_set_command_handler ( GpgObject gpg, + GpgCommandHandler fnc, + void *fnc_value ); + +GpgmeError _gpgme_gpg_op_decrypt (GpgObject gpg, GpgmeData ciph, + GpgmeData plain); +GpgmeError _gpgme_gpg_op_delete (GpgObject gpg, GpgmeKey key, int allow_secret); +GpgmeError _gpgme_gpg_op_encrypt (GpgObject gpg, GpgmeRecipients recp, + GpgmeData plain, GpgmeData ciph, + int use_armor); +GpgmeError _gpgme_gpg_op_encrypt_sign (GpgObject gpg, GpgmeRecipients recp, + GpgmeData plain, GpgmeData ciph, + int use_armor, GpgmeCtx ctx); +GpgmeError _gpgme_gpg_op_export (GpgObject gpg, GpgmeRecipients recp, + GpgmeData keydata, int use_armor); +GpgmeError _gpgme_gpg_op_genkey (GpgObject gpg, GpgmeData help_data, + int use_armor, GpgmeData pubkey, + GpgmeData seckey); +GpgmeError _gpgme_gpg_op_import (GpgObject gpg, GpgmeData keydata); +GpgmeError _gpgme_gpg_op_keylist (GpgObject gpg, const char *pattern, + int secret_only, int keylist_mode); +GpgmeError _gpgme_gpg_op_keylist_ext (GpgObject gpg, const char *pattern[], + int secret_only, int reserved, + int keylist_mode); +GpgmeError _gpgme_gpg_op_sign (GpgObject gpg, GpgmeData in, GpgmeData out, + GpgmeSigMode mode, int use_armor, + int use_textmode, GpgmeCtx ctx /* FIXME */); +GpgmeError _gpgme_gpg_op_trustlist (GpgObject gpg, const char *pattern); +GpgmeError _gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, GpgmeData text); +GpgmeError _gpgme_gpg_spawn (GpgObject gpg, void *opaque); + +#endif /* RUNGPG_H */ diff --git a/tags/V0-3-4/gpgme/sema.h b/tags/V0-3-4/gpgme/sema.h new file mode 100644 index 0000000..e476467 --- /dev/null +++ b/tags/V0-3-4/gpgme/sema.h @@ -0,0 +1,63 @@ +/* sema.h - definitions for semaphores + * Copyright (C) 2001 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef SEMA_H +#define SEMA_H + +struct critsect_s { + const char *name; + void *private; +}; + +#define DEFINE_GLOBAL_LOCK(name) \ + struct critsect_s name = { #name, NULL } +#define DEFINE_STATIC_LOCK(name) \ + static struct critsect_s name = { #name, NULL } + +#define DECLARE_LOCK(name) struct critsect_s name +#define INIT_LOCK(a) do { \ + (a).name = #a; \ + (a).private = NULL; \ + } while (0) +#define DESTROY_LOCK(name) _gpgme_sema_cs_destroy (&(name)) + + +#define LOCK(name) do { \ + _gpgme_sema_cs_enter ( &(name) );\ + } while (0) + +#define UNLOCK(name) do { \ + _gpgme_sema_cs_leave ( &(name) );\ + } while (0) + + +void _gpgme_sema_subsystem_init (void); +void _gpgme_sema_cs_enter ( struct critsect_s *s ); +void _gpgme_sema_cs_leave ( struct critsect_s *s ); +void _gpgme_sema_cs_destroy ( struct critsect_s *s ); + + +#endif /* SEMA_H */ + + + + + diff --git a/tags/V0-3-4/gpgme/sign.c b/tags/V0-3-4/gpgme/sign.c new file mode 100644 index 0000000..494eed8 --- /dev/null +++ b/tags/V0-3-4/gpgme/sign.c @@ -0,0 +1,262 @@ +/* sign.c - signing functions + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "util.h" +#include "context.h" +#include "ops.h" + +#define SKIP_TOKEN_OR_RETURN(a) do { \ + while (*(a) && *(a) != ' ') (a)++; \ + while (*(a) == ' ') (a)++; \ + if (!*(a)) \ + return; /* oops */ \ +} while (0) + +struct sign_result_s +{ + int okay; + GpgmeData xmlinfo; +}; + +void +_gpgme_release_sign_result (SignResult result) +{ + if (!result) + return; + gpgme_data_release (result->xmlinfo); + xfree (result); +} + +/* Parse the args and save the information + * + * in an XML structure. With args of NULL the xml structure is closed. + */ +static void +append_xml_siginfo (GpgmeData *rdh, char *args) +{ + GpgmeData dh; + char helpbuf[100]; + int i; + char *s; + unsigned long ul; + + if (!*rdh) + { + if (gpgme_data_new (rdh)) + { + return; /* fixme: We are ignoring out-of-core */ + } + dh = *rdh; + _gpgme_data_append_string (dh, "\n"); + } + else + { + dh = *rdh; + _gpgme_data_append_string (dh, " \n"); + } + + if (!args) + { + /* Just close the XML containter. */ + _gpgme_data_append_string (dh, "\n"); + return; + } + + _gpgme_data_append_string (dh, " \n"); + + _gpgme_data_append_string (dh, + *args == 'D' ? " \n" : + *args == 'C' ? " \n" : + *args == 'S' ? " \n" : ""); + SKIP_TOKEN_OR_RETURN (args); + + sprintf (helpbuf, " %d\n", atoi (args)); + _gpgme_data_append_string (dh, helpbuf); + SKIP_TOKEN_OR_RETURN (args); + + i = atoi (args); + sprintf (helpbuf, " %d\n", atoi (args)); + _gpgme_data_append_string (dh, helpbuf); + switch (i) + { + case 1: s = "pgp-md5"; break; + case 2: s = "pgp-sha1"; break; + case 3: s = "pgp-ripemd160"; break; + case 5: s = "pgp-md2"; break; + case 6: s = "pgp-tiger192"; break; + case 7: s = "pgp-haval-5-160"; break; + case 8: s = "pgp-sha256"; break; + case 9: s = "pgp-sha384"; break; + case 10: s = "pgp-sha512"; break; + default: s = "pgp-unknown"; break; + } + sprintf (helpbuf, " %s\n", s); + _gpgme_data_append_string (dh,helpbuf); + SKIP_TOKEN_OR_RETURN (args); + + sprintf (helpbuf, " %.2s\n", args); + _gpgme_data_append_string (dh, helpbuf); + SKIP_TOKEN_OR_RETURN (args); + + ul = strtoul (args, NULL, 10); + sprintf (helpbuf, " %lu\n", ul); + _gpgme_data_append_string (dh, helpbuf); + SKIP_TOKEN_OR_RETURN (args); + + /* Count the length of the finperprint. */ + for (i = 0; args[i] && args[i] != ' '; i++) + ; + _gpgme_data_append_string (dh, " "); + _gpgme_data_append (dh, args, i); + _gpgme_data_append_string (dh, "\n"); +} + +void +_gpgme_sign_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args) +{ + _gpgme_passphrase_status_handler (ctx, code, args); + + if (ctx->error) + return; + test_and_allocate_result (ctx, sign); + + switch (code) + { + case STATUS_EOF: + if (ctx->result.sign->okay) + { + append_xml_siginfo (&ctx->result.sign->xmlinfo, NULL); + _gpgme_set_op_info (ctx, ctx->result.sign->xmlinfo); + ctx->result.sign->xmlinfo = NULL; + } + if (!ctx->error && !ctx->result.sign->okay) + ctx->error = mk_error (No_Data); /* Hmmm: choose a better error? */ + break; + + case STATUS_SIG_CREATED: + /* FIXME: We have no error return for multiple signatures. */ + append_xml_siginfo (&ctx->result.sign->xmlinfo, args); + ctx->result.sign->okay = 1; + break; + + default: + break; + } +} + +GpgmeError +gpgme_op_sign_start (GpgmeCtx ctx, GpgmeData in, GpgmeData out, + GpgmeSigMode mode) +{ + GpgmeError err = 0; + + fail_on_pending_request (ctx); + ctx->pending = 1; + + _gpgme_release_result (ctx); + + if (mode != GPGME_SIG_MODE_NORMAL + && mode != GPGME_SIG_MODE_DETACH + && mode != GPGME_SIG_MODE_CLEAR) + return mk_error (Invalid_Value); + + /* Create a process object. */ + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS + : GPGME_PROTOCOL_OpenPGP, &ctx->engine); + if (err) + goto leave; + + /* Check the supplied data. */ + if (gpgme_data_get_type (in) == GPGME_DATA_TYPE_NONE) + { + err = mk_error (No_Data); + goto leave; + } + _gpgme_data_set_mode (in, GPGME_DATA_MODE_OUT); + if (!out || gpgme_data_get_type (out) != GPGME_DATA_TYPE_NONE) + { + err = mk_error (Invalid_Value); + goto leave; + } + _gpgme_data_set_mode (out, GPGME_DATA_MODE_IN); + + err = _gpgme_passphrase_start (ctx); + if (err) + goto leave; + + _gpgme_engine_set_status_handler (ctx->engine, _gpgme_sign_status_handler, + ctx); + _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); + + _gpgme_engine_op_sign (ctx->engine, in, out, mode, ctx->use_armor, + ctx->use_textmode, ctx->include_certs, + ctx /* FIXME */); + + /* And kick off the process. */ + err = _gpgme_engine_start (ctx->engine, ctx); + + leave: + if (err) + { + ctx->pending = 0; + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + return err; +} + +/** + * gpgme_op_sign: + * @ctx: The context + * @in: Data to be signed + * @out: Detached signature + * @mode: Signature creation mode + * + * Create a detached signature for @in and write it to @out. + * The data will be signed using either the default key or the ones + * defined through @ctx. + * The defined modes for signature create are: + * + * GPGME_SIG_MODE_NORMAL (or 0) + * GPGME_SIG_MODE_DETACH + * GPGME_SIG_MODE_CLEAR + * + * Note that the settings done by gpgme_set_armor() and gpgme_set_textmode() + * are ignore for @mode GPGME_SIG_MODE_CLEAR. + * + * Return value: 0 on success or an error code. + **/ +GpgmeError +gpgme_op_sign (GpgmeCtx ctx, GpgmeData in, GpgmeData out, GpgmeSigMode mode) +{ + GpgmeError err = gpgme_op_sign_start (ctx, in, out, mode); + if (!err) + gpgme_wait (ctx, &err, 1); + return err; +} diff --git a/tags/V0-3-4/gpgme/signers.c b/tags/V0-3-4/gpgme/signers.c new file mode 100644 index 0000000..2465434 --- /dev/null +++ b/tags/V0-3-4/gpgme/signers.c @@ -0,0 +1,120 @@ +/* signers.c - maintain signer sets + * Copyright (C) 2001 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include "util.h" +#include "context.h" +#include "rungpg.h" + +/* The signers are directly stored in the context. + * So this is quite different to a recipient set. + */ + + +/** + * gpgme_signers_clear: + * @c: context to clear from signers + * + * Remove the list of signers from the context and release the + * references to the signers keys. + * + * Return value: The version string or NULL + **/ +void +gpgme_signers_clear (GpgmeCtx ctx) +{ + int i; + + return_if_fail (ctx); + + if (!ctx->signers) + return; + for (i = 0; i < ctx->signers_len; i++) + { + assert (ctx->signers[i]); + gpgme_key_unref (ctx->signers[i]); + ctx->signers[i] = NULL; + } + ctx->signers_len = 0; +} + +/** + * gpgme_signers_add: + * @c: context to add signer to + * @key: key to add + * + * Add the key as a signer to the context. Acquires a reference to + * the key. + * + * Return value: NULL on success, or an error code. + **/ +GpgmeError +gpgme_signers_add (GpgmeCtx ctx, const GpgmeKey key) +{ + if (!ctx || !key) + return mk_error (Invalid_Value); + + if (ctx->signers_len == ctx->signers_size) + { + GpgmeKey *newarr; + int n = ctx->signers_size + 5; + int j; + + newarr = xtryrealloc (ctx->signers, n * sizeof (*newarr)); + if (!newarr) + return mk_error (Out_Of_Core); + for (j = ctx->signers_size; j < n; j++) + newarr[j] = NULL; + ctx->signers = newarr; + ctx->signers_size = n; + } + + gpgme_key_ref (key); + ctx->signers[ctx->signers_len++] = key; + return 0; +} + +/** + * gpgme_signers_enum: + * @c: context to retrieve signer from + * @seq: index of key to retrieve + * + * Acquire a reference to the signers key with the specified index + * number in the context and return it to the caller. + * + * Return value: A GpgmeKey or NULL on failure. + **/ +GpgmeKey +gpgme_signers_enum (const GpgmeCtx ctx, int seq) +{ + return_null_if_fail (ctx); + return_null_if_fail (seq >= 0); + + if (seq >= ctx->signers_len) + return NULL; + + gpgme_key_ref (ctx->signers[seq]); + return ctx->signers[seq]; +} diff --git a/tags/V0-3-4/gpgme/syshdr.h b/tags/V0-3-4/gpgme/syshdr.h new file mode 100644 index 0000000..af5e4ad --- /dev/null +++ b/tags/V0-3-4/gpgme/syshdr.h @@ -0,0 +1,40 @@ +/* syshdr.h - System specfic header files + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef SYSHDR_H +#define SYSHDR_H + +#include + +#ifdef HAVE_DOSISH_SYSTEM +#include +#else +#include +#include +#endif + + +#endif /* SYSHDR_H */ + + + + + diff --git a/tags/V0-3-4/gpgme/trustlist.c b/tags/V0-3-4/gpgme/trustlist.c new file mode 100644 index 0000000..fd704a1 --- /dev/null +++ b/tags/V0-3-4/gpgme/trustlist.c @@ -0,0 +1,333 @@ +/* trustlist.c - key listing + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include + +#include "util.h" +#include "context.h" +#include "ops.h" + +struct gpgme_trust_item_s +{ + int level; + char keyid[16+1]; + int type; + char ot[2]; + char val[2]; + char *name; +}; + + +static GpgmeTrustItem +trust_item_new (void) +{ + GpgmeTrustItem item; + + item = xtrycalloc (1, sizeof *item); + return item; +} + + +static void +trustlist_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args) +{ + if (ctx->error) + return; + + switch (code) + { + case STATUS_EOF: + break; + + default: + break; + } +} + + +/* + * This handler is used to parse the output of --list-trust-path: + * Format: + * level:keyid:type:recno:ot:val:mc:cc:name: + * With TYPE = U for a user ID + * K for a key + * The RECNO is either the one of the dir record or the one of the uid record. + * OT is the the usual trust letter and only availabel on K lines. + * VAL is the calcualted validity + * MC is the marginal trust counter and only available on U lines + * CC is the same for the complete count + * NAME ist the username and only printed on U lines + */ +static void +trustlist_colon_handler (GpgmeCtx ctx, char *line) +{ + char *p, *pend; + int field = 0; + GpgmeTrustItem item = NULL; + struct trust_queue_item_s *q, *q2; + + if (ctx->error) + return; + if (!line) + return; /* EOF */ + + for (p = line; p; p = pend) + { + field++; + pend = strchr (p, ':'); + if (pend) + *pend++ = 0; + + switch (field) + { + case 1: /* level */ + q = xtrymalloc (sizeof *q); + if (!q) + { + ctx->error = mk_error (Out_Of_Core); + return; + } + q->next = NULL; + q->item = item = trust_item_new (); + if (!q->item) + { + xfree (q); + ctx->error = mk_error (Out_Of_Core); + return; + } + /* fixme: lock queue, keep a tail pointer */ + q2 = ctx->trust_queue; + if (!q2) + ctx->trust_queue = q; + else + { + while (q2->next) + q2 = q2->next; + q2->next = q; + } + /* fixme: unlock queue */ + item->level = atoi (p); + break; + case 2: /* long keyid */ + if (strlen (p) == DIM(item->keyid) - 1) + strcpy (item->keyid, p); + break; + case 3: /* type */ + item->type = *p == 'K'? 1 : *p == 'U'? 2 : 0; + break; + case 5: /* owner trust */ + item->ot[0] = *p; + item->ot[1] = 0; + break; + case 6: /* validity */ + item->val[0] = *p; + item->val[1] = 0; + break; + case 9: /* user ID */ + item->name = xtrystrdup (p); + if (!item->name) + ctx->error = mk_error (Out_Of_Core); + break; + } + } + + if (field) + ctx->key_cond = 1; +} + + +GpgmeError +gpgme_op_trustlist_start (GpgmeCtx ctx, const char *pattern, int max_level) +{ + GpgmeError err = 0; + + fail_on_pending_request (ctx); + if (!pattern || !*pattern) + return mk_error (Invalid_Value); + + ctx->pending = 1; + + if (ctx->engine) + { + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + + _gpgme_release_result (ctx); + + err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS + : GPGME_PROTOCOL_OpenPGP, &ctx->engine); + if (err) + goto leave; + + _gpgme_engine_set_status_handler (ctx->engine, trustlist_status_handler, ctx); + err = _gpgme_engine_set_colon_line_handler (ctx->engine, + trustlist_colon_handler, ctx); + if (err) + goto leave; + + err =_gpgme_engine_op_trustlist (ctx->engine, pattern); + + if (!err) /* And kick off the process. */ + err = _gpgme_engine_start (ctx->engine, ctx); + + leave: + if (err) + { + ctx->pending = 0; + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + return err; +} + + +GpgmeError +gpgme_op_trustlist_next (GpgmeCtx ctx, GpgmeTrustItem *r_item) +{ + struct trust_queue_item_s *q; + + if (!r_item) + return mk_error (Invalid_Value); + *r_item = NULL; + if (!ctx) + return mk_error (Invalid_Value); + if (!ctx->pending) + return mk_error (No_Request); + if (ctx->error) + return ctx->error; + + if (!ctx->trust_queue) + { + _gpgme_wait_on_condition (ctx, 1, &ctx->key_cond); + if (ctx->error) + return ctx->error; + if (!ctx->key_cond) + return mk_error (EOF); + ctx->key_cond = 0; + assert (ctx->trust_queue); + } + q = ctx->trust_queue; + ctx->trust_queue = q->next; + + *r_item = q->item; + xfree (q); + return 0; +} + + +/** + * gpgme_op_trustlist_end: + * @c: Context + * + * Ends the trustlist operation and allows to use the context for some + * other operation next. + **/ +GpgmeError +gpgme_op_trustlist_end (GpgmeCtx ctx) +{ + if (!ctx) + return mk_error (Invalid_Value); + if (!ctx->pending) + return mk_error (No_Request); + if (ctx->error) + return ctx->error; + + ctx->pending = 0; + return 0; +} + + +void +gpgme_trust_item_release (GpgmeTrustItem item) +{ + if (!item) + return; + xfree (item->name); + xfree (item); +} + + +const char * +gpgme_trust_item_get_string_attr (GpgmeTrustItem item, GpgmeAttr what, + const void *reserved, int idx) +{ + const char *val = NULL; + + if (!item) + return NULL; + if (reserved) + return NULL; + if (idx) + return NULL; + + switch (what) + { + case GPGME_ATTR_KEYID: + val = item->keyid; + break; + case GPGME_ATTR_OTRUST: + val = item->ot; + break; + case GPGME_ATTR_VALIDITY: + val = item->val; + break; + case GPGME_ATTR_USERID: + val = item->name; + break; + default: + break; + } + return val; +} + + +int +gpgme_trust_item_get_int_attr (GpgmeTrustItem item, GpgmeAttr what, + const void *reserved, int idx) +{ + int val = 0; + + if (!item) + return 0; + if (reserved) + return 0; + if (idx) + return 0; + + switch (what) + { + case GPGME_ATTR_LEVEL: + val = item->level; + break; + case GPGME_ATTR_TYPE: + val = item->type; + break; + default: + break; + } + return val; +} diff --git a/tags/V0-3-4/gpgme/types.h b/tags/V0-3-4/gpgme/types.h new file mode 100644 index 0000000..9ebdfe9 --- /dev/null +++ b/tags/V0-3-4/gpgme/types.h @@ -0,0 +1,92 @@ +/* types.h - Some type definitions + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef TYPES_H +#define TYPES_H + +#include "gpgme.h" /* external objects and prototypes */ + +#ifndef HAVE_BYTE_TYPEDEF +typedef unsigned char byte; +#endif +#ifndef HAVE_ULONG_TYPEDEF +typedef unsigned long ulong; +#endif + + +typedef enum { + GPGME_DATA_MODE_NONE = 0, + GPGME_DATA_MODE_IN = 1, + GPGME_DATA_MODE_OUT = 2, + GPGME_DATA_MODE_INOUT = 3 +} GpgmeDataMode; + + +/* + * Declaration of internal objects + */ + +/*-- engine.c --*/ +struct engine_object_s; +typedef struct engine_object_s *EngineObject; + +/*-- engine-gpgsm.c --*/ +struct gpgsm_object_s; +typedef struct gpgsm_object_s *GpgsmObject; + +/*-- rungpg.c --*/ +struct gpg_object_s; +typedef struct gpg_object_s *GpgObject; + +/*-- verify.c --*/ +struct verify_result_s; +typedef struct verify_result_s *VerifyResult; + +/*-- decrypt.c --*/ +struct decrypt_result_s; +typedef struct decrypt_result_s *DecryptResult; + +/*-- sign.c --*/ +struct sign_result_s; +typedef struct sign_result_s *SignResult; + +/*-- encrypt.c --*/ +struct encrypt_result_s; +typedef struct encrypt_result_s *EncryptResult; + +/*-- passphrase.c --*/ +struct passphrase_result_s; +typedef struct passphrase_result_s *PassphraseResult; + +/*-- import.c --*/ +struct import_result_s; +typedef struct import_result_s *ImportResult; + +/*-- delete.c --*/ +struct delete_result_s; +typedef struct delete_result_s *DeleteResult; + +/*-- genkey.c --*/ +struct genkey_result_s; +typedef struct genkey_result_s *GenKeyResult; + + +#endif /* TYPES_H */ diff --git a/tags/V0-3-4/gpgme/util.c b/tags/V0-3-4/gpgme/util.c new file mode 100644 index 0000000..0c267fe --- /dev/null +++ b/tags/V0-3-4/gpgme/util.c @@ -0,0 +1,66 @@ +/* util.c + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "util.h" + +void * +_gpgme_malloc (size_t n ) +{ + return malloc (n); +} + +void * +_gpgme_calloc (size_t n, size_t m ) +{ + return calloc (n, m); +} + +void * +_gpgme_realloc (void *p, size_t n) +{ + return realloc (p, n ); +} + + +char * +_gpgme_strdup (const char *p) +{ + return strdup (p); +} + + +void +_gpgme_free ( void *a ) +{ + free (a); +} + + + + + + diff --git a/tags/V0-3-4/gpgme/util.h b/tags/V0-3-4/gpgme/util.h new file mode 100644 index 0000000..045c8bf --- /dev/null +++ b/tags/V0-3-4/gpgme/util.h @@ -0,0 +1,153 @@ +/* util.h + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef UTIL_H +#define UTIL_H + +#include "types.h" + +void *_gpgme_malloc (size_t n ); +void *_gpgme_calloc (size_t n, size_t m ); +void *_gpgme_realloc (void *p, size_t n); +char *_gpgme_strdup (const char *p); +void _gpgme_free ( void *a ); + +#define xtrymalloc(a) _gpgme_malloc((a)) +#define xtrycalloc(a,b) _gpgme_calloc((a),(b)) +#define xtryrealloc(a,b) _gpgme_realloc((a),(b)) +#define xtrystrdup(a) _gpgme_strdup((a)) +#define xfree(a) _gpgme_free((a)) + + +#define mk_error(a) ( GPGME_##a ) + +#define DIM(v) (sizeof(v)/sizeof((v)[0])) +#define DIMof(type,member) DIM(((type *)0)->member) +#ifndef STR + #define STR(v) #v +#endif +#define STR2(v) STR(v) + + +void _gpgme_debug (int level, const char *format, ...); +int _gpgme_debug_level (void); +void _gpgme_debug_begin ( void **helper, int level, const char *text); +int _gpgme_debug_enabled ( void **helper ); +void _gpgme_debug_add (void **helper, const char *format, ...); +void _gpgme_debug_end (void **helper, const char *text); + +#define DEBUG0(x) _gpgme_debug (1, __FILE__ ":" \ + STR2 (__LINE__) ": " x ) +#define DEBUG1(x,a) _gpgme_debug (1, __FILE__ ":" \ + STR2 (__LINE__)": " x, (a) ) +#define DEBUG2(x,a,b) _gpgme_debug (1, __FILE__ ":" \ + STR2 (__LINE__) ": " x, (a), (b) ) +#define DEBUG3(x,a,b,c) _gpgme_debug (1, __FILE__ ":" \ + STR2 (__LINE__) ": " x, (a), (b), (c) ) +#define DEBUG4(x,a,b,c,d) _gpgme_debug (1, __FILE__ ":" \ + STR2 (__LINE__) ": " x, (a), (b), (c), (d) ) +#define DEBUG5(x,a,b,c,d,e) _gpgme_debug (1, __FILE__ ":" \ + STR2 (__LINE__) ": " x, (a), (b), (c), (d), (e) ) +#define DEBUG6(x,a,b,c,d,e,f) _gpgme_debug (1, __FILE__ ":" \ + STR2 (__LINE__) ": " x, (a), (b), (c), (d), (e), (f) ) +#define DEBUG7(x,a,b,c,d,e,f,g) _gpgme_debug (1, __FILE__ ":" \ + STR2 (__LINE__) ": " x, (a), (b), (c), (d), (e), (f), (g) ) +#define DEBUG8(x,a,b,c,d,e,f,g,h) _gpgme_debug (1, __FILE__ ":" \ + STR2 (__LINE__) ": " x, (a), (b), (c), (d), (e), (f), (g), (h) ) +#define DEBUG9(x,a,b,c,d,e,f,g,h,i) _gpgme_debug (1, __FILE__ ":" \ + STR2 (__LINE__) ": " x, (a), (b), (c), (d), (e), (f), (g), (h), (i) ) +#define DEBUG10(x,a,b,c,d,e,f,g,h,i,j) _gpgme_debug (1, __FILE__ ":" \ + STR2 (__LINE__) ": " x, (a), (b), (c), (d), (e), (f), (g), (h), (i), (j) ) + +#define DEBUG_BEGIN(y,x) _gpgme_debug_begin (&(y), 1, __FILE__ ":" \ + STR2 (__LINE__) ": " x ) +#define DEBUG_ENABLED(y) _gpgme_debug_enabled(&(y)) +#define DEBUG_ADD0(y,x) _gpgme_debug_add (&(y), (x), \ + ) +#define DEBUG_ADD1(y,x,a) _gpgme_debug_add (&(y), (x), \ + (a) ) +#define DEBUG_ADD2(y,x,a,b) _gpgme_debug_add (&(y), (x), \ + (a), (b) ) +#define DEBUG_ADD3(y,x,a,b,c) _gpgme_debug_add (&(y), (x), \ + (a), (b), (c) ) +#define DEBUG_ADD4(y,x,a,b,c,d) _gpgme_debug_add (&(y), (x), \ + (a), (b), (c), (d) ) +#define DEBUG_ADD5(y,x,a,b,c,d,e) _gpgme_debug_add (&(y), (x), \ + (a), (b), (c), (d), (e) ) +#define DEBUG_END(y,x) _gpgme_debug_end (&(y), (x) ) + + + +#ifndef HAVE_STPCPY +char *stpcpy (char *a, const char *b); +#endif + +#define return_if_fail(expr) do { \ + if (!(expr)) { \ + fprintf (stderr, "%s:%d: assertion `%s' failed", \ + __FILE__, __LINE__, #expr ); \ + return; \ + } } while (0) +#define return_null_if_fail(expr) do { \ + if (!(expr)) { \ + fprintf (stderr, "%s:%d: assertion `%s' failed", \ + __FILE__, __LINE__, #expr ); \ + return NULL; \ + } } while (0) +#define return_val_if_fail(expr,val) do { \ + if (!(expr)) { \ + fprintf (stderr, "%s:%d: assertion `%s' failed", \ + __FILE__, __LINE__, #expr ); \ + return (val); \ + } } while (0) + + + +/*-- {posix,w32}-util.c --*/ +const char *_gpgme_get_gpg_path (void); +const char *_gpgme_get_gpgsm_path (void); + +/*-- replacement functions in .c --*/ +#ifdef HAVE_CONFIG_H +#if !HAVE_VASPRINTF +#include +int vasprintf (char **result, const char *format, va_list *args); +int asprintf (char **result, const char *format, ...); +#endif + +#if !HAVE_FOPENCOOKIE +typedef struct +{ + ssize_t (*read)(void*,char*,size_t); + ssize_t (*write)(void*,const char*,size_t); + int (*seek)(void*,off_t*,int); + int (*close)(coid*); +} _IO_cookie_io_functions_t; +typedef _IO_cookie_io_functions_t cookie_io_functions_t; +FILE *fopencookie (void *cookie, const char *opentype, + cookie_io_functions_t funclist); +#endif /*!HAVE_FOPENCOOKIE*/ +#endif /*HAVE_CONFIG_H*/ + + + + +#endif /* UTIL_H */ diff --git a/tags/V0-3-4/gpgme/vasprintf.c b/tags/V0-3-4/gpgme/vasprintf.c new file mode 100644 index 0000000..dbef4eb --- /dev/null +++ b/tags/V0-3-4/gpgme/vasprintf.c @@ -0,0 +1,155 @@ +/* Like vsprintf but provides a pointer to malloc'd storage, which must + be freed by the caller. + Copyright (C) 1994, 2002 Free Software Foundation, Inc. + +This file is part of the libiberty library. +Libiberty is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +Libiberty is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with libiberty; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include +#include + +#ifdef TEST +int global_total_width; +#endif + +int +vasprintf (char **result, const char *format, va_list *args) +{ + const char *p = format; + /* Add one to make sure that it is never zero, which might cause malloc + to return NULL. */ + int total_width = strlen (format) + 1; + va_list ap; + + /* FIXME: use va_copy() */ + memcpy (&ap, args, sizeof (va_list)); + + while (*p != '\0') + { + if (*p++ == '%') + { + while (strchr ("-+ #0", *p)) + ++p; + if (*p == '*') + { + ++p; + total_width += abs (va_arg (ap, int)); + } + else + total_width += strtoul (p, (char**)&p, 10); + if (*p == '.') + { + ++p; + if (*p == '*') + { + ++p; + total_width += abs (va_arg (ap, int)); + } + else + total_width += strtoul (p, (char**)&p, 10); + } + while (strchr ("hlL", *p)) + ++p; + /* Should be big enough for any format specifier except %s and floats. */ + total_width += 30; + switch (*p) + { + case 'd': + case 'i': + case 'o': + case 'u': + case 'x': + case 'X': + case 'c': + (void) va_arg (ap, int); + break; + case 'f': + case 'e': + case 'E': + case 'g': + case 'G': + (void) va_arg (ap, double); + /* Since an ieee double can have an exponent of 307, we'll + make the buffer wide enough to cover the gross case. */ + total_width += 307; + break; + case 's': + total_width += strlen (va_arg (ap, char *)); + break; + case 'p': + case 'n': + (void) va_arg (ap, char *); + break; + } + } + } +#ifdef TEST + global_total_width = total_width; +#endif + *result = malloc (total_width); + if (*result != NULL) + return vsprintf (*result, format, *args); + else + return 0; +} + + +int +asprintf (char **buf, const char *fmt, ...) +{ + int status; + va_list ap; + + va_start (ap, fmt); + status = vasprintf (buf, fmt, ap); + va_end (ap); + return status; +} + + +#ifdef TEST +void +checkit (const char* format, ...) +{ + va_list args; + char *result; + + va_start (args, format); + vasprintf (&result, format, args); + if (strlen (result) < global_total_width) + printf ("PASS: "); + else + printf ("FAIL: "); + printf ("%d %s\n", global_total_width, result); +} + +int +main (void) +{ + checkit ("%d", 0x12345678); + checkit ("%200d", 5); + checkit ("%.300d", 6); + checkit ("%100.150d", 7); + checkit ("%s", "jjjjjjjjjiiiiiiiiiiiiiiioooooooooooooooooppppppppppppaa\n\ +777777777777777777333333333333366666666666622222222222777777777777733333"); + checkit ("%f%s%d%s", 1.0, "foo", 77, "asdjffffffffffffffiiiiiiiiiiixxxxx"); +} +#endif /* TEST */ diff --git a/tags/V0-3-4/gpgme/verify.c b/tags/V0-3-4/gpgme/verify.c new file mode 100644 index 0000000..13b83c2 --- /dev/null +++ b/tags/V0-3-4/gpgme/verify.c @@ -0,0 +1,467 @@ +/* verify.c - signature verification + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "util.h" +#include "context.h" +#include "ops.h" +#include "key.h" + + +struct verify_result_s +{ + struct verify_result_s *next; + GpgmeSigStat status; + GpgmeData notation; /* We store an XML fragment here. */ + int collecting; /* Private to finish_sig(). */ + int notation_in_data; /* Private to add_notation(). */ + char fpr[41]; /* Fingerprint of a good signature or keyid of + a bad one. */ + ulong timestamp; /* Signature creation time. */ +}; + + +void +_gpgme_release_verify_result (VerifyResult result) +{ + while (result) + { + VerifyResult next_result = result->next; + gpgme_data_release (result->notation); + xfree (result); + result = next_result; + } +} + + +/* FIXME: Check that we are adding this to the correct signature. */ +static void +add_notation (GpgmeCtx ctx, GpgStatusCode code, const char *data) +{ + GpgmeData dh = ctx->result.verify->notation; + + if (!dh) + { + if (gpgme_data_new (&dh)) + { + ctx->error = mk_error (Out_Of_Core); + return; + } + ctx->result.verify->notation = dh; + _gpgme_data_append_string (dh, " \n"); + } + + if (code == STATUS_NOTATION_DATA) + { + if (!ctx->result.verify->notation_in_data) + _gpgme_data_append_string (dh, " "); + _gpgme_data_append_percentstring_for_xml (dh, data); + ctx->result.verify->notation_in_data = 1; + return; + } + + if (ctx->result.verify->notation_in_data) + { + _gpgme_data_append_string (dh, "\n"); + ctx->result.verify->notation_in_data = 0; + } + + if (code == STATUS_NOTATION_NAME) + { + _gpgme_data_append_string (dh, " "); + _gpgme_data_append_percentstring_for_xml (dh, data); + _gpgme_data_append_string (dh, "\n"); + } + else if (code == STATUS_POLICY_URL) + { + _gpgme_data_append_string (dh, " "); + _gpgme_data_append_percentstring_for_xml (dh, data); + _gpgme_data_append_string (dh, "\n"); + } + else + assert (0); +} + + +/* + * finish a pending signature info collection and prepare for a new + * signature info collection + */ +static void +finish_sig (GpgmeCtx ctx, int stop) +{ + if (stop) + return; /* nothing to do */ + + if (ctx->result.verify->collecting) + { + VerifyResult res2; + + ctx->result.verify->collecting = 0; + /* Create a new result structure. */ + res2 = xtrycalloc (1, sizeof *res2); + if (!res2) + { + ctx->error = mk_error (Out_Of_Core); + return; + } + + res2->next = ctx->result.verify; + ctx->result.verify = res2; + } + + ctx->result.verify->collecting = 1; +} + + +void +_gpgme_verify_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args) +{ + char *p; + int i; + + if (ctx->error) + return; + test_and_allocate_result (ctx, verify); + + if (code == STATUS_GOODSIG || code == STATUS_BADSIG || code == STATUS_ERRSIG) + { + finish_sig (ctx,0); + if (ctx->error) + return; + } + + switch (code) + { + case STATUS_NODATA: + ctx->result.verify->status = GPGME_SIG_STAT_NOSIG; + break; + + case STATUS_GOODSIG: + /* We only look at VALIDSIG */ + break; + + case STATUS_VALIDSIG: + ctx->result.verify->status = GPGME_SIG_STAT_GOOD; + p = ctx->result.verify->fpr; + for (i = 0; i < DIM(ctx->result.verify->fpr) + && args[i] && args[i] != ' ' ; i++) + *p++ = args[i]; + *p = 0; + /* Skip the formatted date. */ + while (args[i] && args[i] == ' ') + i++; + while (args[i] && args[i] != ' ') + i++; + /* And get the timestamp. */ + ctx->result.verify->timestamp = strtoul (args+i, NULL, 10); + break; + + case STATUS_BADSIG: + ctx->result.verify->status = GPGME_SIG_STAT_BAD; + /* Store the keyID in the fpr field. */ + p = ctx->result.verify->fpr; + for (i = 0; i < DIM(ctx->result.verify->fpr) + && args[i] && args[i] != ' ' ; i++) + *p++ = args[i]; + *p = 0; + break; + + case STATUS_ERRSIG: + /* The return code is the 6th argument, if it is 9, the problem + is a missing key. */ + for (p = args, i = 0; p && *p && i < 5; i++) + { + p = strchr (p, ' '); + if (p) + while (*p == ' ') + p++; + } + if (p && *(p++) == '9' && (*p == '\0' || *p == ' ')) + ctx->result.verify->status = GPGME_SIG_STAT_NOKEY; + else + ctx->result.verify->status = GPGME_SIG_STAT_ERROR; + /* Store the keyID in the fpr field. */ + p = ctx->result.verify->fpr; + for (i = 0; i < DIM(ctx->result.verify->fpr) + && args[i] && args[i] != ' ' ; i++) + *p++ = args[i]; + *p = 0; + break; + + case STATUS_NOTATION_NAME: + case STATUS_NOTATION_DATA: + case STATUS_POLICY_URL: + add_notation (ctx, code, args); + break; + + case STATUS_END_STREAM: + break; + + case STATUS_EOF: + finish_sig (ctx,1); + + /* FIXME: Put all notation data into one XML fragment. */ + if (ctx->result.verify->notation) + { + GpgmeData dh = ctx->result.verify->notation; + + if (ctx->result.verify->notation_in_data) + { + _gpgme_data_append_string (dh, "\n"); + ctx->result.verify->notation_in_data = 0; + } + _gpgme_data_append_string (dh, "\n"); + ctx->notation = dh; + ctx->result.verify->notation = NULL; + } + break; + + default: + /* Ignore all other codes. */ + break; + } +} + +GpgmeError +gpgme_op_verify_start (GpgmeCtx ctx, GpgmeData sig, GpgmeData text) +{ + int err = 0; + int pipemode = 0; /* !!text; use pipemode for detached sigs. */ + + fail_on_pending_request (ctx); + ctx->pending = 1; + + _gpgme_release_result (ctx); + + if (!pipemode) + { + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + + if (!ctx->engine) + err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS + : GPGME_PROTOCOL_OpenPGP, &ctx->engine); + if (err) + goto leave; + +#if 0 /* FIXME */ + if (pipemode) + _gpgme_gpg_enable_pipemode (c->engine->engine.gpg); +#endif + + _gpgme_engine_set_status_handler (ctx->engine, _gpgme_verify_status_handler, + ctx); + _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); + + /* Check the supplied data. */ + if (gpgme_data_get_type (sig) == GPGME_DATA_TYPE_NONE) + { + err = mk_error (No_Data); + goto leave; + } + if (!text) + { + err = mk_error (Invalid_Value); + goto leave; + } + _gpgme_data_set_mode (sig, GPGME_DATA_MODE_OUT); + if (gpgme_data_get_type (text) == GPGME_DATA_TYPE_NONE) + /* Normal or cleartext signature. */ + _gpgme_data_set_mode (text, GPGME_DATA_MODE_IN); + else + /* Detached signature. */ + _gpgme_data_set_mode (text, GPGME_DATA_MODE_OUT); + + err = _gpgme_engine_op_verify (ctx->engine, sig, text); + if (!err) /* And kick off the process. */ + err = _gpgme_engine_start (ctx->engine, ctx); + + leave: + if (err) + { + ctx->pending = 0; + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } + return err; +} + +/* + * Figure out a common status value for all signatures + */ +GpgmeSigStat +_gpgme_intersect_stati (VerifyResult result) +{ + GpgmeSigStat status = result->status; + + for (result = result->next; result; result = result->next) + { + if (status != result->status) + return GPGME_SIG_STAT_DIFF; + } + return status; +} + +/** + * gpgme_op_verify: + * @c: the context + * @sig: the signature data + * @text: the signed text + * @r_stat: returns the status of the signature + * + * Perform a signature check on the signature given in @sig. If @text + * is a new and uninitialized data object, it is assumed that @sig + * contains a normal or cleartext signature, and the plaintext is + * returned in @text upon successful verification. + * + * If @text is initialized, it is assumed that @sig is a detached + * signature for the material given in @text. + * + * The result of this operation is returned in @r_stat which can take these + * values: + * GPGME_SIG_STAT_NONE: No status - should not happen + * GPGME_SIG_STAT_GOOD: The signature is valid + * GPGME_SIG_STAT_BAD: The signature is not valid + * GPGME_SIG_STAT_NOKEY: The signature could not be checked due to a + * missing key + * GPGME_SIG_STAT_NOSIG: This is not a signature + * GPGME_SIG_STAT_ERROR: Due to some other error the check could not be done. + * GPGME_SIG_STAT_DIFF: There is more than 1 signature and they have not + * the same status. + * + * Return value: 0 on success or an errorcode if something not related to + * the signature itself did go wrong. + **/ +GpgmeError +gpgme_op_verify (GpgmeCtx ctx, GpgmeData sig, GpgmeData text, + GpgmeSigStat *r_stat) +{ + GpgmeError err; + + if (!r_stat) + return mk_error (Invalid_Value); + + gpgme_data_release (ctx->notation); + ctx->notation = NULL; + + *r_stat = GPGME_SIG_STAT_NONE; + err = gpgme_op_verify_start (ctx, sig, text); + if (!err) + { + gpgme_wait (ctx, &err, 1); + if (!err) + *r_stat = _gpgme_intersect_stati (ctx->result.verify); + } + return err; +} + + +/** + * gpgme_get_sig_status: + * @c: Context + * @idx: Index of the signature starting at 0 + * @r_stat: Returns the status + * @r_created: Returns the creation timestamp + * + * Return information about an already verified signatures. + * + * Return value: The fingerprint or NULL in case of an problem or + * when there are no more signatures. + **/ +const char * +gpgme_get_sig_status (GpgmeCtx c, int idx, + GpgmeSigStat *r_stat, time_t *r_created) +{ + VerifyResult result; + + if (!c || c->pending || !c->result.verify) + return NULL; /* No results yet or verification error. */ + + for (result = c->result.verify; + result && idx > 0; result = result->next, idx--) + ; + if (!result) + return NULL; /* No more signatures. */ + + if (r_stat) + *r_stat = result->status; + if (r_created) + *r_created = result->timestamp; + return result->fpr; +} + + +/** + * gpgme_get_sig_key: + * @c: context + * @idx: Index of the signature starting at 0 + * @r_key: Returns the key object + * + * Return a key object which was used to check the signature. + * + * Return value: An Errorcode or 0 for success. GPGME_EOF is returned to + * indicate that there are no more signatures. + **/ +GpgmeError +gpgme_get_sig_key (GpgmeCtx c, int idx, GpgmeKey *r_key) +{ + VerifyResult result; + GpgmeError err = 0; + + if (!c || !r_key) + return mk_error (Invalid_Value); + if (c->pending || !c->result.verify) + return mk_error (Busy); + + for (result = c->result.verify; + result && idx > 0; result = result->next, idx--) + ; + if (!result) + return mk_error (EOF); + + if (strlen(result->fpr) < 16) /* We have at least a key ID. */ + return mk_error (Invalid_Key); + + *r_key = _gpgme_key_cache_get (result->fpr); + if (!*r_key) + { + GpgmeCtx listctx; + + /* Fixme: This can be optimized by keeping an internal context + used for such key listings. */ + err = gpgme_new (&listctx); + if (err) + return err; + gpgme_set_keylist_mode (listctx, c->keylist_mode); + err = gpgme_op_keylist_start (listctx, result->fpr, 0); + if (!err) + err = gpgme_op_keylist_next (listctx, r_key); + gpgme_release (listctx); + } + return err; +} diff --git a/tags/V0-3-4/gpgme/version.c b/tags/V0-3-4/gpgme/version.c new file mode 100644 index 0000000..104f71d --- /dev/null +++ b/tags/V0-3-4/gpgme/version.c @@ -0,0 +1,269 @@ +/* version.c - version check + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "gpgme.h" +#include "context.h" +#include "rungpg.h" +#include "sema.h" +#include "util.h" +#include "key.h" /* for key_cache_init */ +#include "io.h" + + +static void +do_subsystem_inits (void) +{ + static int done = 0; + + if (done) + return; + _gpgme_sema_subsystem_init (); + _gpgme_key_cache_init (); +} + +static const char* +parse_version_number (const char *s, int *number) +{ + int val = 0; + + if (*s == '0' && isdigit(s[1])) + return NULL; /* Leading zeros are not allowed. */ + for (; isdigit(*s); s++) + { + val *= 10; + val += *s - '0'; + } + *number = val; + return val < 0 ? NULL : s; +} + +static const char * +parse_version_string (const char *s, int *major, int *minor, int *micro) +{ + s = parse_version_number (s, major); + if (!s || *s != '.') + return NULL; + s++; + s = parse_version_number (s, minor); + if (!s || *s != '.') + return NULL; + s++; + s = parse_version_number (s, micro); + if (!s) + return NULL; + return s; /* Patchlevel. */ +} + +const char * +_gpgme_compare_versions (const char *my_version, + const char *req_version) +{ + int my_major, my_minor, my_micro; + int rq_major, rq_minor, rq_micro; + const char *my_plvl, *rq_plvl; + + if (!req_version) + return my_version; + if (!my_version) + return NULL; + + my_plvl = parse_version_string (my_version, &my_major, &my_minor, &my_micro); + if (!my_plvl) + return NULL; /* Very strange: our own version is bogus. */ + rq_plvl = parse_version_string(req_version, + &rq_major, &rq_minor, &rq_micro); + if (!rq_plvl) + return NULL; /* Requested version string is invalid. */ + + if (my_major > rq_major + || (my_major == rq_major && my_minor > rq_minor) + || (my_major == rq_major && my_minor == rq_minor + && my_micro > rq_micro) + || (my_major == rq_major && my_minor == rq_minor + && my_micro == rq_micro + && strcmp( my_plvl, rq_plvl ) >= 0)) + { + return my_version; + } + return NULL; +} + +/** + * gpgme_check_version: + * @req_version: A string with a version + * + * Check that the the version of the library is at minimum the requested one + * and return the version string; return NULL if the condition is not + * met. If a NULL is passed to this function, no check is done and + * the version string is simply returned. It is a pretty good idea to + * run this function as soon as possible, because it also intializes + * some subsystems. In a multithreaded environment if should be called + * before the first thread is created. + * + * Return value: The version string or NULL + **/ +const char * +gpgme_check_version (const char *req_version) +{ + do_subsystem_inits (); + return _gpgme_compare_versions (VERSION, req_version); +} + +/** + * gpgme_get_engine_info: + * + * Return information about the underlying crypto engines. This is an + * XML string with various information. A string is always returned + * even if the crypto engines is not installed; in this case a XML + * string with some error information is returned. + * + * Return value: A XML string with information about the crypto + * engines. + **/ +const char * +gpgme_get_engine_info () +{ + static const char *engine_info; + const char *openpgp_info = _gpgme_engine_get_info (GPGME_PROTOCOL_OpenPGP); + const char *cms_info = _gpgme_engine_get_info (GPGME_PROTOCOL_CMS); + char *info; + + /* FIXME: Make sure that only one instance does run. */ + if (engine_info) + return engine_info; + + if (!openpgp_info && !cms_info) + info = "\n\n"; + else if (!openpgp_info || !cms_info) + { + const char *fmt = "\n" + "%s" + "\n"; + + info = xtrymalloc (strlen(fmt) + strlen(openpgp_info + ? openpgp_info : cms_info) + 1); + if (info) + sprintf (info, fmt, openpgp_info ? openpgp_info : cms_info); + } + else + { + const char *fmt = "\n" + "%s%s" + "\n"; + info = xtrymalloc (strlen(fmt) + strlen(openpgp_info) + + strlen (cms_info) + 1); + if (info) + sprintf (info, fmt, openpgp_info, cms_info); + } + if (!info) + info = "\n" + " Out of core\n" + "\n"; + engine_info = info; + return engine_info; +} + +/** + * gpgme_check_engine: + * + * Check whether the installed crypto engine for the OpenPGP protocol + * matches the requirement of GPGME. This function is deprecated, + * instead use gpgme_engine_get_info() with the specific protocol you + * need. + * + * Return value: 0 or an error code. + **/ +GpgmeError +gpgme_check_engine () +{ + return gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP); +} + + +#define LINELENGTH 80 + +char * +_gpgme_get_program_version (const char *const path) +{ + char line[LINELENGTH] = ""; + int linelen = 0; + char *mark = NULL; + int rp[2]; + pid_t pid; + int nread; + char *argv[] = {(char *) path, "--version", 0}; + struct spawn_fd_item_s pfd[] = { {0, -1}, {-1, -1} }; + struct spawn_fd_item_s cfd[] = { {-1, 1 /* STDOUT_FILENO */}, {-1, -1} }; + int status, signal; + + if (!path) + return NULL; + + if (_gpgme_io_pipe (rp, 1) < 0) + return NULL; + + pfd[0].fd = rp[1]; + cfd[0].fd = rp[1]; + + pid = _gpgme_io_spawn (path, argv, cfd, pfd); + if (pid < 0) + { + _gpgme_io_close (rp[0]); + _gpgme_io_close (rp[1]); + return NULL; + } + + do + { + nread = _gpgme_io_read (rp[0], &line[linelen], LINELENGTH - linelen - 1); + if (nread > 0) + { + line[linelen + nread] = '\0'; + mark = strchr (&line[linelen], '\n'); + if (mark) + { + *mark = '\0'; + break; + } + linelen += nread; + } + } + while (nread > 0 && linelen < LINELENGTH - 1); + + _gpgme_io_close (rp[0]); + _gpgme_io_waitpid (pid, 1, &status, &signal); + + if (mark) + { + mark = strrchr (line, ' '); + if (!mark) + return NULL; + return xtrystrdup (mark + 1); + } + + return NULL; +} diff --git a/tags/V0-3-4/gpgme/w32-io.c b/tags/V0-3-4/gpgme/w32-io.c new file mode 100644 index 0000000..de7e670 --- /dev/null +++ b/tags/V0-3-4/gpgme/w32-io.c @@ -0,0 +1,1133 @@ +/* w32-io.c - W32 API I/O functions + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#ifdef HAVE_DOSISH_SYSTEM + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "syshdr.h" + +#include "util.h" +#include "sema.h" +#include "io.h" + + +/* + * We assume that a HANDLE can be represented by an int which should be true + * for all i386 systems (HANDLE is defined as void *) and these are the only + * systems for which Windows is available. + * Further we assume that -1 denotes an invalid handle. + */ + +#define fd_to_handle(a) ((HANDLE)(a)) +#define handle_to_fd(a) ((int)(a)) +#define pid_to_handle(a) ((HANDLE)(a)) +#define handle_to_pid(a) ((int)(a)) + +#define READBUF_SIZE 4096 +#define WRITEBUF_SIZE 4096 +#define MAX_READERS 20 +#define MAX_WRITERS 20 + +static struct { + int inuse; + int fd; + void (*handler)(int,void*); + void *value; +} notify_table[256]; +DEFINE_STATIC_LOCK (notify_table_lock); + + +struct reader_context_s { + HANDLE file_hd; + HANDLE thread_hd; + DECLARE_LOCK (mutex); + + int stop_me; + int eof; + int eof_shortcut; + int error; + int error_code; + + HANDLE have_data_ev; /* manually reset */ + HANDLE have_space_ev; /* auto reset */ + HANDLE stopped; + size_t readpos, writepos; + char buffer[READBUF_SIZE]; +}; + + +static struct { + volatile int used; + int fd; + struct reader_context_s *context; +} reader_table[MAX_READERS]; +static int reader_table_size= MAX_READERS; +DEFINE_STATIC_LOCK (reader_table_lock); + + +struct writer_context_s { + HANDLE file_hd; + HANDLE thread_hd; + DECLARE_LOCK (mutex); + + int stop_me; + int error; + int error_code; + + HANDLE have_data; /* manually reset */ + HANDLE is_empty; + HANDLE stopped; + size_t nbytes; + char buffer[WRITEBUF_SIZE]; +}; + + +static struct { + volatile int used; + int fd; + struct writer_context_s *context; +} writer_table[MAX_WRITERS]; +static int writer_table_size= MAX_WRITERS; +DEFINE_STATIC_LOCK (writer_table_lock); + + + +static HANDLE +set_synchronize (HANDLE h) +{ + HANDLE tmp; + + /* For NT we have to set the sync flag. It seems that the only + * way to do it is by duplicating the handle. Tsss.. */ + if (!DuplicateHandle( GetCurrentProcess(), h, + GetCurrentProcess(), &tmp, + EVENT_MODIFY_STATE|SYNCHRONIZE, FALSE, 0 ) ) { + DEBUG1 ("** Set SYNCRONIZE failed: ec=%d\n", (int)GetLastError()); + } + else { + CloseHandle (h); + h = tmp; + } + return h; +} + + + +static DWORD CALLBACK +reader (void *arg) +{ + struct reader_context_s *c = arg; + int nbytes; + DWORD nread; + + DEBUG2 ("reader thread %p for file %p started", c->thread_hd, c->file_hd ); + for (;;) { + LOCK (c->mutex); + /* leave a 1 byte gap so that we can see whether it is empty or full*/ + if ((c->writepos + 1) % READBUF_SIZE == c->readpos) { + /* wait for space */ + if (!ResetEvent (c->have_space_ev) ) + DEBUG1 ("ResetEvent failed: ec=%d", (int)GetLastError ()); + UNLOCK (c->mutex); + DEBUG1 ("reader thread %p: waiting for space ...", c->thread_hd ); + WaitForSingleObject (c->have_space_ev, INFINITE); + DEBUG1 ("reader thread %p: got space", c->thread_hd ); + LOCK (c->mutex); + } + if ( c->stop_me ) { + UNLOCK (c->mutex); + break; + } + nbytes = (c->readpos + READBUF_SIZE - c->writepos-1) % READBUF_SIZE; + if ( nbytes > READBUF_SIZE - c->writepos ) + nbytes = READBUF_SIZE - c->writepos; + UNLOCK (c->mutex); + + DEBUG2 ("reader thread %p: reading %d bytes", c->thread_hd, nbytes ); + if ( !ReadFile ( c->file_hd, + c->buffer+c->writepos, nbytes, &nread, NULL) ) { + c->error_code = (int)GetLastError (); + if (c->error_code == ERROR_BROKEN_PIPE ) { + c->eof=1; + DEBUG1 ("reader thread %p: got eof (broken pipe)", + c->thread_hd ); + } + else { + c->error = 1; + DEBUG2 ("reader thread %p: read error: ec=%d", + c->thread_hd, c->error_code ); + } + break; + } + if ( !nread ) { + c->eof = 1; + DEBUG1 ("reader thread %p: got eof", c->thread_hd ); + break; + } + DEBUG2 ("reader thread %p: got %d bytes", c->thread_hd, (int)nread ); + + LOCK (c->mutex); + if (c->stop_me) { + UNLOCK (c->mutex); + break; + } + c->writepos = (c->writepos + nread) % READBUF_SIZE; + if ( !SetEvent (c->have_data_ev) ) + DEBUG1 ("SetEvent failed: ec=%d", (int)GetLastError ()); + UNLOCK (c->mutex); + } + /* indicate that we have an error or eof */ + if ( !SetEvent (c->have_data_ev) ) + DEBUG1 ("SetEvent failed: ec=%d", (int)GetLastError ()); + DEBUG1 ("reader thread %p ended", c->thread_hd ); + SetEvent (c->stopped); + + return 0; +} + + +static struct reader_context_s * +create_reader (HANDLE fd) +{ + struct reader_context_s *c; + SECURITY_ATTRIBUTES sec_attr; + DWORD tid; + + DEBUG1 ("creating new read thread for file handle %p", fd ); + memset (&sec_attr, 0, sizeof sec_attr ); + sec_attr.nLength = sizeof sec_attr; + sec_attr.bInheritHandle = FALSE; + + c = xtrycalloc (1, sizeof *c ); + if (!c) + return NULL; + + c->file_hd = fd; + c->have_data_ev = CreateEvent (&sec_attr, TRUE, FALSE, NULL); + c->have_space_ev = CreateEvent (&sec_attr, FALSE, TRUE, NULL); + c->stopped = CreateEvent (&sec_attr, TRUE, FALSE, NULL); + if (!c->have_data_ev || !c->have_space_ev || !c->stopped ) { + DEBUG1 ("** CreateEvent failed: ec=%d\n", (int)GetLastError ()); + if (c->have_data_ev) + CloseHandle (c->have_data_ev); + if (c->have_space_ev) + CloseHandle (c->have_space_ev); + if (c->stopped) + CloseHandle (c->stopped); + xfree (c); + return NULL; + } + + c->have_data_ev = set_synchronize (c->have_data_ev); + INIT_LOCK (c->mutex); + + c->thread_hd = CreateThread (&sec_attr, 0, reader, c, 0, &tid ); + if (!c->thread_hd) { + DEBUG1 ("** failed to create reader thread: ec=%d\n", + (int)GetLastError ()); + DESTROY_LOCK (c->mutex); + if (c->have_data_ev) + CloseHandle (c->have_data_ev); + if (c->have_space_ev) + CloseHandle (c->have_space_ev); + if (c->stopped) + CloseHandle (c->stopped); + xfree (c); + return NULL; + } + + return c; +} + +static void +destroy_reader (struct reader_context_s *c) +{ + LOCK (c->mutex); + c->stop_me = 1; + if (c->have_space_ev) + SetEvent (c->have_space_ev); + UNLOCK (c->mutex); + + DEBUG1 ("waiting for thread %p termination ...", c->thread_hd ); + WaitForSingleObject (c->stopped, INFINITE); + DEBUG1 ("thread %p has terminated", c->thread_hd ); + + if (c->stopped) + CloseHandle (c->stopped); + if (c->have_data_ev) + CloseHandle (c->have_data_ev); + if (c->have_space_ev) + CloseHandle (c->have_space_ev); + CloseHandle (c->thread_hd); + DESTROY_LOCK (c->mutex); + xfree (c); +} + + +/* + * Find a reader context or create a new one + * Note that the reader context will last until a io_close. + */ +static struct reader_context_s * +find_reader (int fd, int start_it) +{ + int i; + + for (i=0; i < reader_table_size ; i++ ) { + if ( reader_table[i].used && reader_table[i].fd == fd ) + return reader_table[i].context; + } + if (!start_it) + return NULL; + + LOCK (reader_table_lock); + for (i=0; i < reader_table_size; i++ ) { + if (!reader_table[i].used) { + reader_table[i].fd = fd; + reader_table[i].context = create_reader (fd_to_handle (fd)); + reader_table[i].used = 1; + UNLOCK (reader_table_lock); + return reader_table[i].context; + } + } + UNLOCK (reader_table_lock); + return NULL; +} + + +static void +kill_reader (int fd) +{ + int i; + + LOCK (reader_table_lock); + for (i=0; i < reader_table_size; i++ ) { + if (reader_table[i].used && reader_table[i].fd == fd ) { + destroy_reader (reader_table[i].context); + reader_table[i].context = NULL; + reader_table[i].used = 0; + break; + } + } + UNLOCK (reader_table_lock); +} + + + +int +_gpgme_io_read ( int fd, void *buffer, size_t count ) +{ + int nread; + struct reader_context_s *c = find_reader (fd,1); + + DEBUG2 ("fd %d: about to read %d bytes\n", fd, (int)count ); + if ( !c ) { + DEBUG0 ( "no reader thread\n"); + return -1; + } + if (c->eof_shortcut) { + DEBUG1 ("fd %d: EOF (again)", fd ); + return 0; + } + + LOCK (c->mutex); + if (c->readpos == c->writepos && !c->error) { /*no data avail*/ + UNLOCK (c->mutex); + DEBUG2 ("fd %d: waiting for data from thread %p", fd, c->thread_hd); + WaitForSingleObject (c->have_data_ev, INFINITE); + DEBUG2 ("fd %d: data from thread %p available", fd, c->thread_hd); + LOCK (c->mutex); + } + + if (c->readpos == c->writepos || c->error) { + UNLOCK (c->mutex); + c->eof_shortcut = 1; + if (c->eof) { + DEBUG1 ("fd %d: EOF", fd ); + return 0; + } + if (!c->error) { + DEBUG1 ("fd %d: EOF but eof flag not set", fd ); + return 0; + } + DEBUG1 ("fd %d: read error", fd ); + return -1; + } + + nread = c->readpos < c->writepos? c->writepos - c->readpos + : READBUF_SIZE - c->readpos; + if (nread > count) + nread = count; + memcpy (buffer, c->buffer+c->readpos, nread); + c->readpos = (c->readpos + nread) % READBUF_SIZE; + if (c->readpos == c->writepos && !c->eof) { + if ( !ResetEvent (c->have_data_ev) ) + DEBUG1 ("ResetEvent failed: ec=%d", (int)GetLastError ()); + } + if (!SetEvent (c->have_space_ev)) + DEBUG1 ("SetEvent failed: ec=%d", (int)GetLastError ()); + UNLOCK (c->mutex); + + DEBUG2 ("fd %d: got %d bytes\n", fd, nread ); + + return nread; +} + + + +/* + * The writer does use a simple buffering strategy so that we are + * informed about write errors as soon as possible (i.e. with the the + * next call to the write function + */ +static DWORD CALLBACK +writer (void *arg) +{ + struct writer_context_s *c = arg; + DWORD nwritten; + + DEBUG2 ("writer thread %p for file %p started", c->thread_hd, c->file_hd ); + for (;;) { + LOCK (c->mutex); + if ( !c->nbytes ) { + if (!ResetEvent (c->have_data) ) + DEBUG1 ("ResetEvent failed: ec=%d", (int)GetLastError ()); + UNLOCK (c->mutex); + DEBUG1 ("writer thread %p: idle ...", c->thread_hd ); + WaitForSingleObject (c->have_data, INFINITE); + DEBUG1 ("writer thread %p: got data to send", c->thread_hd ); + LOCK (c->mutex); + } + if ( c->stop_me ) { + UNLOCK (c->mutex); + break; + } + UNLOCK (c->mutex); + + DEBUG2 ("writer thread %p: writing %d bytes", + c->thread_hd, c->nbytes ); + if ( c->nbytes && !WriteFile ( c->file_hd, c->buffer, c->nbytes, + &nwritten, NULL)) { + c->error_code = (int)GetLastError (); + c->error = 1; + DEBUG2 ("writer thread %p: write error: ec=%d", + c->thread_hd, c->error_code ); + break; + } + DEBUG2 ("writer thread %p: wrote %d bytes", + c->thread_hd, (int)nwritten ); + + LOCK (c->mutex); + c->nbytes -= nwritten; + if (c->stop_me) { + UNLOCK (c->mutex); + break; + } + if ( !c->nbytes ) { + if ( !SetEvent (c->is_empty) ) + DEBUG1 ("SetEvent failed: ec=%d", (int)GetLastError ()); + } + UNLOCK (c->mutex); + } + /* indicate that we have an error */ + if ( !SetEvent (c->is_empty) ) + DEBUG1 ("SetEvent failed: ec=%d", (int)GetLastError ()); + DEBUG1 ("writer thread %p ended", c->thread_hd ); + SetEvent (c->stopped); + + return 0; +} + + +static struct writer_context_s * +create_writer (HANDLE fd) +{ + struct writer_context_s *c; + SECURITY_ATTRIBUTES sec_attr; + DWORD tid; + + DEBUG1 ("creating new write thread for file handle %p", fd ); + memset (&sec_attr, 0, sizeof sec_attr ); + sec_attr.nLength = sizeof sec_attr; + sec_attr.bInheritHandle = FALSE; + + c = xtrycalloc (1, sizeof *c ); + if (!c) + return NULL; + + c->file_hd = fd; + c->have_data = CreateEvent (&sec_attr, FALSE, FALSE, NULL); + c->is_empty = CreateEvent (&sec_attr, TRUE, TRUE, NULL); + c->stopped = CreateEvent (&sec_attr, TRUE, FALSE, NULL); + if (!c->have_data || !c->is_empty || !c->stopped ) { + DEBUG1 ("** CreateEvent failed: ec=%d\n", (int)GetLastError ()); + if (c->have_data) + CloseHandle (c->have_data); + if (c->is_empty) + CloseHandle (c->is_empty); + if (c->stopped) + CloseHandle (c->stopped); + xfree (c); + return NULL; + } + + c->is_empty = set_synchronize (c->is_empty); + INIT_LOCK (c->mutex); + + c->thread_hd = CreateThread (&sec_attr, 0, writer, c, 0, &tid ); + if (!c->thread_hd) { + DEBUG1 ("** failed to create writer thread: ec=%d\n", + (int)GetLastError ()); + DESTROY_LOCK (c->mutex); + if (c->have_data) + CloseHandle (c->have_data); + if (c->is_empty) + CloseHandle (c->is_empty); + if (c->stopped) + CloseHandle (c->stopped); + xfree (c); + return NULL; + } + + return c; +} + +static void +destroy_writer (struct writer_context_s *c) +{ + LOCK (c->mutex); + c->stop_me = 1; + if (c->have_data) + SetEvent (c->have_data); + UNLOCK (c->mutex); + + DEBUG1 ("waiting for thread %p termination ...", c->thread_hd ); + WaitForSingleObject (c->stopped, INFINITE); + DEBUG1 ("thread %p has terminated", c->thread_hd ); + + if (c->stopped) + CloseHandle (c->stopped); + if (c->have_data) + CloseHandle (c->have_data); + if (c->is_empty) + CloseHandle (c->is_empty); + CloseHandle (c->thread_hd); + DESTROY_LOCK (c->mutex); + xfree (c); +} + + +/* + * Find a writer context or create a new one + * Note that the writer context will last until a io_close. + */ +static struct writer_context_s * +find_writer (int fd, int start_it) +{ + int i; + + for (i=0; i < writer_table_size ; i++ ) { + if ( writer_table[i].used && writer_table[i].fd == fd ) + return writer_table[i].context; + } + if (!start_it) + return NULL; + + LOCK (writer_table_lock); + for (i=0; i < writer_table_size; i++ ) { + if (!writer_table[i].used) { + writer_table[i].fd = fd; + writer_table[i].context = create_writer (fd_to_handle (fd)); + writer_table[i].used = 1; + UNLOCK (writer_table_lock); + return writer_table[i].context; + } + } + UNLOCK (writer_table_lock); + return NULL; +} + + +static void +kill_writer (int fd) +{ + int i; + + LOCK (writer_table_lock); + for (i=0; i < writer_table_size; i++ ) { + if (writer_table[i].used && writer_table[i].fd == fd ) { + destroy_writer (writer_table[i].context); + writer_table[i].context = NULL; + writer_table[i].used = 0; + break; + } + } + UNLOCK (writer_table_lock); +} + + + + +int +_gpgme_io_write ( int fd, const void *buffer, size_t count ) +{ + struct writer_context_s *c = find_writer (fd,1); + + DEBUG2 ("fd %d: about to write %d bytes\n", fd, (int)count ); + if ( !c ) { + DEBUG0 ( "no writer thread\n"); + return -1; + } + + LOCK (c->mutex); + if ( c->nbytes ) { /* bytes are pending for send */ + UNLOCK (c->mutex); + DEBUG2 ("fd %d: waiting for empty buffer in thread %p", + fd, c->thread_hd); + WaitForSingleObject (c->is_empty, INFINITE); + DEBUG2 ("fd %d: thread %p buffer is empty", fd, c->thread_hd); + assert (!c->nbytes); + LOCK (c->mutex); + } + + if ( c->error) { + UNLOCK (c->mutex); + DEBUG1 ("fd %d: write error", fd ); + return -1; + } + + if (count > WRITEBUF_SIZE) + count = WRITEBUF_SIZE; + memcpy (c->buffer, buffer, count); + c->nbytes = count; + if (!SetEvent (c->have_data)) + DEBUG1 ("SetEvent failed: ec=%d", (int)GetLastError ()); + UNLOCK (c->mutex); + + DEBUG2 ("fd %d: copied %d bytes\n", + fd, (int)count ); + return (int)count; +} + + +int +_gpgme_io_pipe ( int filedes[2], int inherit_idx ) +{ + HANDLE r, w; + SECURITY_ATTRIBUTES sec_attr; + + memset (&sec_attr, 0, sizeof sec_attr ); + sec_attr.nLength = sizeof sec_attr; + sec_attr.bInheritHandle = FALSE; + + if (!CreatePipe ( &r, &w, &sec_attr, 0)) + return -1; + /* make one end inheritable */ + if ( inherit_idx == 0 ) { + HANDLE h; + if (!DuplicateHandle( GetCurrentProcess(), r, + GetCurrentProcess(), &h, 0, + TRUE, DUPLICATE_SAME_ACCESS ) ) { + DEBUG1 ("DuplicateHandle failed: ec=%d\n", (int)GetLastError()); + CloseHandle (r); + CloseHandle (w); + return -1; + } + CloseHandle (r); + r = h; + } + else if ( inherit_idx == 1 ) { + HANDLE h; + if (!DuplicateHandle( GetCurrentProcess(), w, + GetCurrentProcess(), &h, 0, + TRUE, DUPLICATE_SAME_ACCESS ) ) { + DEBUG1 ("DuplicateHandle failed: ec=%d\n", (int)GetLastError()); + CloseHandle (r); + CloseHandle (w); + return -1; + } + CloseHandle (w); + w = h; + } + + filedes[0] = handle_to_fd (r); + filedes[1] = handle_to_fd (w); + DEBUG5 ("CreatePipe %p %p %d %d inherit=%d\n", r, w, + filedes[0], filedes[1], inherit_idx ); + return 0; +} + +int +_gpgme_io_close ( int fd ) +{ + int i; + void (*handler)(int, void*) = NULL; + void *value = NULL; + + if ( fd == -1 ) + return -1; + + DEBUG1 ("** closing handle for fd %d\n", fd); + kill_reader (fd); + kill_writer (fd); + LOCK (notify_table_lock); + for ( i=0; i < DIM (notify_table); i++ ) { + if (notify_table[i].inuse && notify_table[i].fd == fd) { + handler = notify_table[i].handler; + value = notify_table[i].value; + notify_table[i].handler = NULL; + notify_table[i].value = NULL; + notify_table[i].inuse = 0; + break; + } + } + UNLOCK (notify_table_lock); + if (handler) + handler (fd, value); + + if ( !CloseHandle (fd_to_handle (fd)) ) { + DEBUG2 ("CloseHandle for fd %d failed: ec=%d\n", + fd, (int)GetLastError ()); + return -1; + } + + return 0; +} + +int +_gpgme_io_set_close_notify (int fd, void (*handler)(int, void*), void *value) +{ + int i; + + assert (fd != -1); + + LOCK (notify_table_lock); + for (i=0; i < DIM (notify_table); i++ ) { + if ( notify_table[i].inuse && notify_table[i].fd == fd ) + break; + } + if ( i == DIM (notify_table) ) { + for (i=0; i < DIM (notify_table); i++ ) { + if ( !notify_table[i].inuse ) + break; + } + } + if ( i == DIM (notify_table) ) { + UNLOCK (notify_table_lock); + return -1; + } + notify_table[i].fd = fd; + notify_table[i].handler = handler; + notify_table[i].value = value; + notify_table[i].inuse = 1; + UNLOCK (notify_table_lock); + DEBUG2 ("set notification for fd %d (idx=%d)", fd, i ); + return 0; +} + + +int +_gpgme_io_set_nonblocking ( int fd ) +{ + return 0; +} + + +static char * +build_commandline ( char **argv ) +{ + int i, n = 0; + char *buf, *p; + + /* FIXME: we have to quote some things because under Windows the + * program parses the commandline and does some unquoting */ + for (i=0; argv[i]; i++) + n += strlen (argv[i]) + 2 + 1; /* 2 extra bytes for possible quoting */ + buf = p = xtrymalloc (n); + if ( !buf ) + return NULL; + *buf = 0; + if ( argv[0] ) + p = stpcpy (p, argv[0]); + for (i = 1; argv[i]; i++) { + if (!*argv[i]) + p = stpcpy (p, " \"\""); + else + p = stpcpy (stpcpy (p, " "), argv[i]); + } + + return buf; +} + + +int +_gpgme_io_spawn ( const char *path, char **argv, + struct spawn_fd_item_s *fd_child_list, + struct spawn_fd_item_s *fd_parent_list ) +{ + SECURITY_ATTRIBUTES sec_attr; + PROCESS_INFORMATION pi = { + NULL, /* returns process handle */ + 0, /* returns primary thread handle */ + 0, /* returns pid */ + 0 /* returns tid */ + }; + STARTUPINFO si; + char *envblock = NULL; + int cr_flags = CREATE_DEFAULT_ERROR_MODE + | GetPriorityClass (GetCurrentProcess ()); + int i; + char *arg_string; + int duped_stdin = 0; + int duped_stderr = 0; + HANDLE hnul = INVALID_HANDLE_VALUE; + int debug_me = !!getenv ("GPGME_DEBUG"); + + memset (&sec_attr, 0, sizeof sec_attr ); + sec_attr.nLength = sizeof sec_attr; + sec_attr.bInheritHandle = FALSE; + + arg_string = build_commandline ( argv ); + if (!arg_string ) + return -1; + + memset (&si, 0, sizeof si); + si.cb = sizeof (si); + si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; + si.wShowWindow = debug_me? SW_SHOW : SW_MINIMIZE; + si.hStdInput = GetStdHandle (STD_INPUT_HANDLE); + si.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE); + si.hStdError = GetStdHandle (STD_ERROR_HANDLE); + + for (i=0; fd_child_list[i].fd != -1; i++ ) { + if (fd_child_list[i].dup_to == 0 ) { + si.hStdInput = fd_to_handle (fd_child_list[i].fd); + DEBUG1 ("using %d for stdin", fd_child_list[i].fd ); + duped_stdin=1; + } + else if (fd_child_list[i].dup_to == 1 ) { + si.hStdOutput = fd_to_handle (fd_child_list[i].fd); + DEBUG1 ("using %d for stdout", fd_child_list[i].fd ); + } + else if (fd_child_list[i].dup_to == 2 ) { + si.hStdError = fd_to_handle (fd_child_list[i].fd); + DEBUG1 ("using %d for stderr", fd_child_list[i].fd ); + duped_stderr = 1; + } + } + + if( !duped_stdin || !duped_stderr ) { + SECURITY_ATTRIBUTES sa; + + memset (&sa, 0, sizeof sa ); + sa.nLength = sizeof sa; + sa.bInheritHandle = TRUE; + hnul = CreateFile ( "nul", + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + &sa, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL ); + if ( hnul == INVALID_HANDLE_VALUE ) { + DEBUG1 ("can't open `nul': ec=%d\n", (int)GetLastError ()); + xfree (arg_string); + return -1; + } + /* Make sure that the process has a connected stdin */ + if ( !duped_stdin ) { + si.hStdInput = hnul; + DEBUG1 ("using %d for dummy stdin", (int)hnul ); + } + /* We normally don't want all the normal output */ + if ( !duped_stderr ) { + si.hStdError = hnul; + DEBUG1 ("using %d for dummy stderr", (int)hnul ); + } + } + + DEBUG2 ("CreateProcess, path=`%s' args=`%s'", path, arg_string); + cr_flags |= CREATE_SUSPENDED; + if ( !CreateProcessA (path, + arg_string, + &sec_attr, /* process security attributes */ + &sec_attr, /* thread security attributes */ + TRUE, /* inherit handles */ + cr_flags, /* creation flags */ + envblock, /* environment */ + NULL, /* use current drive/directory */ + &si, /* startup information */ + &pi /* returns process information */ + ) ) { + DEBUG1 ("CreateProcess failed: ec=%d\n", (int) GetLastError ()); + xfree (arg_string); + return -1; + } + + /* close the /dev/nul handle if used */ + if (hnul != INVALID_HANDLE_VALUE ) { + if ( !CloseHandle ( hnul ) ) + DEBUG1 ("CloseHandle(hnul) failed: ec=%d\n", (int)GetLastError()); + } + + /* Close the other ends of the pipes */ + for (i=0; fd_parent_list[i].fd != -1; i++ ) { + DEBUG1 ("Closing fd %d\n", fd_parent_list[i].fd ); + if ( !CloseHandle ( fd_to_handle (fd_parent_list[i].fd) ) ) + DEBUG1 ("CloseHandle failed: ec=%d", (int)GetLastError()); + } + + DEBUG4 ("CreateProcess ready\n" + "- hProcess=%p hThread=%p\n" + "- dwProcessID=%d dwThreadId=%d\n", + pi.hProcess, pi.hThread, + (int) pi.dwProcessId, (int) pi.dwThreadId); + + if ( ResumeThread ( pi.hThread ) < 0 ) { + DEBUG1 ("ResumeThread failed: ec=%d\n", (int)GetLastError ()); + } + + if ( !CloseHandle (pi.hThread) ) { + DEBUG1 ("CloseHandle of thread failed: ec=%d\n", + (int)GetLastError ()); + } + + return handle_to_pid (pi.hProcess); +} + + + + +int +_gpgme_io_waitpid ( int pid, int hang, int *r_status, int *r_signal ) +{ + HANDLE proc = fd_to_handle (pid); + int code, ret = 0; + DWORD exc; + + *r_status = 0; + *r_signal = 0; + code = WaitForSingleObject ( proc, hang? INFINITE : 0 ); + switch (code) { + case WAIT_FAILED: + DEBUG2 ("WFSO pid=%d failed: %d\n", (int)pid, (int)GetLastError () ); + break; + + case WAIT_OBJECT_0: + if (!GetExitCodeProcess (proc, &exc)) { + DEBUG2 ("** GECP pid=%d failed: ec=%d\n", + (int)pid, (int)GetLastError () ); + *r_status = 4; + } + else { + DEBUG2 ("GECP pid=%d exit code=%d\n", (int)pid, exc); + *r_status = exc; + } + ret = 1; + break; + + case WAIT_TIMEOUT: + if (hang) + DEBUG1 ("WFSO pid=%d timed out\n", (int)pid); + break; + + default: + DEBUG2 ("WFSO pid=%d returned %d\n", (int)pid, code ); + break; + } + return ret; +} + +int +_gpgme_io_kill ( int pid, int hard ) +{ + HANDLE proc = fd_to_handle (pid); + + #warning I am not sure how to kill a process + /* fixme: figure out how this can be done */ + return 0; +} + + + +/* + * Select on the list of fds. + * Returns: -1 = error + * 0 = timeout or nothing to select + * >0 = number of signaled fds + */ +int +_gpgme_io_select ( struct io_select_fd_s *fds, size_t nfds ) +{ + HANDLE waitbuf[MAXIMUM_WAIT_OBJECTS]; + int waitidx[MAXIMUM_WAIT_OBJECTS]; + int code, nwait; + int i, any; + int count; + void *dbg_help; + + restart: + DEBUG_BEGIN (dbg_help, "select on [ "); + any = 0; + nwait = 0; + count = 0; + for ( i=0; i < nfds; i++ ) { + if ( fds[i].fd == -1 ) + continue; + fds[i].signaled = 0; + if ( fds[i].for_read || fds[i].for_write ) { + if ( fds[i].frozen ) { + DEBUG_ADD1 (dbg_help, "f%d ", fds[i].fd ); + } + else if ( fds[i].for_read ) { + struct reader_context_s *c = find_reader (fds[i].fd,1); + + if (!c) { + DEBUG1 ("oops: no reader thread for fd %d", fds[i].fd); + } + else { + if ( nwait >= DIM (waitbuf) ) { + DEBUG_END (dbg_help, "oops ]"); + DEBUG0 ("Too many objects for WFMO!" ); + return -1; + } + waitidx[nwait] = i; + waitbuf[nwait++] = c->have_data_ev; + } + DEBUG_ADD1 (dbg_help, "r%d ", fds[i].fd ); + any = 1; + } + else if ( fds[i].for_write ) { + struct writer_context_s *c = find_writer (fds[i].fd,1); + + if (!c) { + DEBUG1 ("oops: no writer thread for fd %d", fds[i].fd); + } + else { + if ( nwait >= DIM (waitbuf) ) { + DEBUG_END (dbg_help, "oops ]"); + DEBUG0 ("Too many objects for WFMO!" ); + return -1; + } + LOCK (c->mutex); + if ( !c->nbytes ) { + waitidx[nwait] = i; + waitbuf[nwait++] = c->is_empty; + DEBUG_ADD1 (dbg_help, "w%d ", fds[i].fd ); + any = 1; + } + else { + DEBUG_ADD1 (dbg_help, "w%d(ignored) ", fds[i].fd ); + } + UNLOCK (c->mutex); + } + } + } + } + DEBUG_END (dbg_help, "]"); + if (!any) + return 0; + + code = WaitForMultipleObjects ( nwait, waitbuf, 0, 1000); + if ( code >= WAIT_OBJECT_0 && code < WAIT_OBJECT_0 + nwait ) { + /* This WFMO is a really silly function: It does return either + * the index of the signaled object or if 2 objects have been + * signalled at the same time, the index of the object with the + * lowest object is returned - so and how do we find out + * how many objects have been signaled???. + * The only solution I can imagine is to test each object starting + * with the returned index individually - how dull. + */ + any = 0; + for (i=code - WAIT_OBJECT_0; i < nwait; i++ ) { + if (WaitForSingleObject ( waitbuf[i], NULL ) == WAIT_OBJECT_0) { + assert (waitidx[i] >=0 && waitidx[i] < nfds); + fds[waitidx[i]].signaled = 1; + any = 1; + count++; + } + } + if (!any) { + DEBUG0 ("Oops: No signaled objects found after WFMO"); + count = -1; + } + } + else if ( code == WAIT_TIMEOUT ) { + DEBUG0 ("WFMO timed out\n" ); + } + else if (code == WAIT_FAILED ) { + int le = (int)GetLastError (); + if ( le == ERROR_INVALID_HANDLE ) { + int k, j = handle_to_fd (waitbuf[i]); + + DEBUG1 ("WFMO invalid handle %d removed\n", j); + for (k=0 ; k < nfds; i++ ) { + if ( fds[k].fd == j ) { + fds[k].for_read = fds[k].for_write = 0; + goto restart; + } + } + DEBUG0 (" oops, or not???\n"); + } + DEBUG1 ("WFMO failed: %d\n", le ); + count = -1; + } + else { + DEBUG1 ("WFMO returned %d\n", code ); + count = -1; + } + + if ( count ) { + DEBUG_BEGIN (dbg_help, " signaled [ "); + for ( i=0; i < nfds; i++ ) { + if ( fds[i].fd == -1 ) + continue; + if ( (fds[i].for_read || fds[i].for_write) && fds[i].signaled ) { + DEBUG_ADD2 (dbg_help, "%c%d ", + fds[i].for_read? 'r':'w',fds[i].fd ); + } + } + DEBUG_END (dbg_help, "]"); + } + + return count; +} + +#endif /*HAVE_DOSISH_SYSTEM*/ + + + + + + + + + diff --git a/tags/V0-3-4/gpgme/w32-sema.c b/tags/V0-3-4/gpgme/w32-sema.c new file mode 100644 index 0000000..b8507f8 --- /dev/null +++ b/tags/V0-3-4/gpgme/w32-sema.c @@ -0,0 +1,124 @@ +/* w32-sema.c + * Copyright (C) 2001 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + + +#include +#ifdef HAVE_DOSISH_SYSTEM + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "syshdr.h" + +#include "util.h" +#include "sema.h" + +static void +sema_fatal (const char *text) +{ + fprintf (stderr, "sema.c: %s\n", text); + abort (); +} + + +static void +critsect_init (struct critsect_s *s) +{ + CRITICAL_SECTION *mp; + static CRITICAL_SECTION init_lock; + static int initialized; + + if (!initialized) { + /* the very first time we call this function, we assume that only + * one thread is running, so that we can bootstrap the semaphore code + */ + InitializeCriticalSection (&init_lock); + initialized = 1; + } + if (!s) + return; /* we just want to initialize ourself */ + + /* first test whether it is really not initialized */ + EnterCriticalSection (&init_lock); + if ( s->private ) { + LeaveCriticalSection (&init_lock); + return; + } + /* now init it */ + mp = xtrymalloc ( sizeof *mp ); + if (!mp) { + LeaveCriticalSection (&init_lock); + sema_fatal ("out of core while creating critical section lock"); + } + InitializeCriticalSection (mp); + s->private = mp; + LeaveCriticalSection (&init_lock); +} + +void +_gpgme_sema_subsystem_init () +{ + /* fixme: we should check that there is only one thread running */ + critsect_init (NULL); +} + + +void +_gpgme_sema_cs_enter ( struct critsect_s *s ) +{ + if (!s->private) + critsect_init (s); + EnterCriticalSection ( (CRITICAL_SECTION*)s->private ); +} + +void +_gpgme_sema_cs_leave (struct critsect_s *s) +{ + if (!s->private) + critsect_init (s); + LeaveCriticalSection ( (CRITICAL_SECTION*)s->private ); +} + +void +_gpgme_sema_cs_destroy ( struct critsect_s *s ) +{ + if (s && s->private) { + DeleteCriticalSection ((CRITICAL_SECTION*)s->private); + xfree (s->private); + s->private = NULL; + } +} + + + +#endif /*HAVE_DOSISH_SYSTEM*/ + + + + + diff --git a/tags/V0-3-4/gpgme/w32-util.c b/tags/V0-3-4/gpgme/w32-util.c new file mode 100644 index 0000000..2cbf6c2 --- /dev/null +++ b/tags/V0-3-4/gpgme/w32-util.c @@ -0,0 +1,140 @@ +/* w32-util.c - Utility functions for the W32 API + * Copyright (C) 1999 Free Software Foundation, Inc + * Copyright (C) 2001 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + + +#include +#ifdef HAVE_DOSISH_SYSTEM + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "syshdr.h" + +#include "util.h" + +/**************** + * Return a string from the Win32 Registry or NULL in case of + * error. Caller must release the return value. A NULL for root + * is an alias for HKEY_CURRENT_USER. + */ +static char * +read_w32_registry_string ( const char *root, + const char *dir, const char *name ) +{ + HKEY root_key, key_handle; + DWORD n1, nbytes; + char *result = NULL; + + if( !root ) + root_key = HKEY_CURRENT_USER; + else if( !strcmp( root, "HKEY_CLASSES_ROOT" ) ) + root_key = HKEY_CLASSES_ROOT; + else if( !strcmp( root, "HKEY_CURRENT_USER" ) ) + root_key = HKEY_CURRENT_USER; + else if( !strcmp( root, "HKEY_LOCAL_MACHINE" ) ) + root_key = HKEY_LOCAL_MACHINE; + else if( !strcmp( root, "HKEY_USERS" ) ) + root_key = HKEY_USERS; + else if( !strcmp( root, "HKEY_PERFORMANCE_DATA" ) ) + root_key = HKEY_PERFORMANCE_DATA; + else if( !strcmp( root, "HKEY_CURRENT_CONFIG" ) ) + root_key = HKEY_CURRENT_CONFIG; + else + return NULL; + + if( RegOpenKeyEx( root_key, dir, 0, KEY_READ, &key_handle ) ) + return NULL; /* no need for a RegClose, so return direct */ + + nbytes = 1; + if( RegQueryValueEx( key_handle, name, 0, NULL, NULL, &nbytes ) ) + goto leave; + result = xtrymalloc( (n1=nbytes+1) ); + if( !result ) + goto leave; + if( RegQueryValueEx( key_handle, name, 0, NULL, result, &n1 ) ) { + xfree(result); result = NULL; + goto leave; + } + result[nbytes] = 0; /* make sure it is really a string */ + + leave: + RegCloseKey( key_handle ); + return result; +} + +static const char * +find_program_in_registry (const char *name) +{ + char *program = NULL; + + program = read_w32_registry_string (NULL, "Software\\GNU\\GnuPG", name); + if (program) + { + int i; + + DEBUG1 ("found %s in registry: `%s'", name, program ); + for (i = 0; program[i]; i++) + { + if (program[i] == '/') + program[i] = '\\'; + } + } + return program; +} + +const char * +_gpgme_get_gpg_path (void) +{ + static char *gpg_program = NULL; + + if (!gpg_program) + gpg_program = find_program_in_registry ("gpgProgram"); +#ifdef GPG_PATH + if (!gpg_program) + gpg_program = GPG_PATH; +#endif + return gpg_program; +} + +const char * +_gpgme_get_gpgsm_path (void) +{ + static char *gpgsm_program = NULL; + + if (!gpgsm_program) + gpgsm_program = find_program_in_registry ("gpgsmProgram"); +#ifdef GPGSM_PATH + if (!gpgsm_program) + gpgsm_program = GPGSM_PATH; +#endif + return gpgsm_program; +} + + +#endif /*HAVE_DOSISH_SYSTEM*/ diff --git a/tags/V0-3-4/gpgme/wait.c b/tags/V0-3-4/gpgme/wait.c new file mode 100644 index 0000000..e7ce286 --- /dev/null +++ b/tags/V0-3-4/gpgme/wait.c @@ -0,0 +1,449 @@ +/* wait.c + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include "syshdr.h" + +#include "util.h" +#include "context.h" +#include "ops.h" +#include "wait.h" +#include "sema.h" +#include "io.h" +#include "engine.h" + +struct wait_item_s; +struct proc_s; + +static struct proc_s *proc_queue; +DEFINE_STATIC_LOCK (proc_queue_lock); + +static int fd_table_size; +static struct io_select_fd_s *fd_table; +DEFINE_STATIC_LOCK (fd_table_lock); + +static GpgmeIdleFunc idle_function; + + +struct proc_s +{ + struct proc_s *next; + int pid; + GpgmeCtx ctx; + struct wait_item_s *handler_list; + /* Non-zero if the process has been completed. */ + int done; + /* Non-zero if the status for this process has been returned + already. */ + int reported; +}; + +struct wait_item_s { + struct wait_item_s *next; + int (*handler)(void*,int,int); + void *handler_value; + int inbound; /* this is an inbound data handler fd */ + struct proc_s *proc; /* backlink */ + int done; + int frozen; /* copy of the frozen flag from the fd_table */ +}; + + + +static int do_select ( void ); +static void run_idle (void); + + +/* only to be called with a locked proc_queue */ +static int +count_running_fds (struct proc_s *proc) +{ + struct wait_item_s *q; + int count = 0; + + for (q = proc->handler_list; q; q=q->next) + { + if (!q->frozen && !q->done) + count++; + } + return count; +} + +/* only to be called with a locked proc_queue */ +static void +set_process_done (struct proc_s *proc) +{ + struct wait_item_s *q, *q2; + int i; + + assert (proc); + DEBUG2 ("set_process_done(%p) pid=%d", proc, proc->pid); + LOCK (fd_table_lock); + for (q = proc->handler_list; q; q=q2) + { + q2 = q->next; + for (i = 0; i < fd_table_size; i++) + { + if (fd_table[i].fd != -1 && q == fd_table[i].opaque) + { + fd_table[i].opaque = NULL; + fd_table[i].fd = -1; + } + } + xfree (q); + } + UNLOCK (fd_table_lock); + proc->handler_list = NULL; + proc->done = 1; +} + +void +_gpgme_remove_proc_from_wait_queue (int pid) +{ + struct proc_s *proc, *last; + + DEBUG1 ("removing process %d", pid); + LOCK (proc_queue_lock); + for (last = NULL, proc = proc_queue; proc; last = proc, proc = proc->next) + { + if (proc->pid == pid) + { + set_process_done (proc); + if (!last) + proc_queue = proc->next; + else + last->next = proc->next; + xfree (proc); + break; + } + } + UNLOCK (proc_queue_lock); +} + + +/** + * gpgme_wait: + * @c: + * @hang: + * + * Wait for a finished request, if @c is given the function does only + * wait on a finished request for that context, otherwise it will return + * on any request. When @hang is true the function will wait, otherwise + * it will return immediately when there is no pending finished request. + * + * Return value: Context of the finished request or NULL if @hang is false + * and no (or the given) request has finished. + **/ +GpgmeCtx +gpgme_wait (GpgmeCtx ctx, GpgmeError *status, int hang) +{ + GpgmeCtx retctx = _gpgme_wait_on_condition (ctx, hang, NULL); + if (status) + *status = retctx->error; + return retctx; +} + +GpgmeCtx +_gpgme_wait_on_condition (GpgmeCtx ctx, int hang, volatile int *cond) +{ + DEBUG3 ("waiting... ctx=%p hang=%d cond=%p", ctx, hang, cond); + do + { + int any = 0; + struct proc_s *proc; + + do_select (); + + if (cond && *cond) + hang = 0; + else + { + LOCK (proc_queue_lock); + for (proc = proc_queue; proc; proc = proc->next) + { + /* A process is done if it has completed voluntarily, or + if the context it lived in was canceled. */ + if (!proc->done && !count_running_fds (proc)) + set_process_done (proc); + else if (!proc->done && proc->ctx->cancel) + { + set_process_done (proc); + proc->ctx->cancel = 0; + proc->ctx->error = mk_error (Canceled); + } + /* A process that is done is eligible for election if it + is in the requested context or if it was not yet + reported. */ + if (proc->done && (proc->ctx == ctx || (!ctx && !proc->reported))) + { + if (!ctx) + ctx = proc->ctx; + hang = 0; + ctx->pending = 0; + proc->reported = 1; + } + if (!proc->done) + any = 1; + } + UNLOCK (proc_queue_lock); + if (!any) + hang = 0; + } + /* fixme: We should check here for hanging processes. */ + + if (hang) + run_idle (); + } + while (hang && (!ctx || !ctx->cancel)); + if (ctx && ctx->cancel) + { + /* FIXME: Paranoia? */ + ctx->cancel = 0; + ctx->pending = 0; + ctx->error = mk_error (Canceled); + } + return ctx; +} + + +/* + * We use this function to do the select stuff for all running + * gpgs. A future version might provide a facility to delegate + * those selects to the GDK select stuff. + * This function must be called only by one thread!! + * Returns: 0 = nothing to run + * 1 = did run something + */ + +static int +do_select (void) +{ + int i, n; + int any = 0; + + n = _gpgme_io_select (fd_table, fd_table_size); + if (n <= 0) + return 0; /* error or timeout */ + + for (i = 0; i < fd_table_size && n; i++) + { + if (fd_table[i].fd != -1 && fd_table[i].signaled + && !fd_table[i].frozen) + { + struct wait_item_s *q; + + assert (n); + n--; + + q = fd_table[i].opaque; + assert (q); + assert (q->proc); + assert (!q->done); + any = 1; + if (q->handler (q->handler_value, + q->proc->pid, fd_table[i].fd)) + { + DEBUG2 ("setting fd %d (q=%p) done", fd_table[i].fd, q); + q->done = 1; + /* Free the table entry. */ + LOCK (fd_table_lock); + fd_table[i].for_read = 0; + fd_table[i].for_write = 0; + fd_table[i].fd = -1; + fd_table[i].opaque = NULL; + UNLOCK (fd_table_lock); + } + } + } + + return any; +} + + +/* + * called by rungpg.c to register something for select() + */ +GpgmeError +_gpgme_register_pipe_handler (void *opaque, + int (*handler)(void*,int,int), + void *handler_value, + int pid, int fd, int inbound) +{ + GpgmeCtx ctx = opaque; + struct wait_item_s *q; + struct proc_s *proc; + int i; + + assert (opaque); + assert (handler); + + /* Allocate a structure to hold info about the handler. */ + q = xtrycalloc (1, sizeof *q); + if (!q) + return mk_error (Out_Of_Core); + q->inbound = inbound; + q->handler = handler; + q->handler_value = handler_value; + + /* Put this into the process queue. */ + LOCK (proc_queue_lock); + for (proc = proc_queue; proc && proc->pid != pid; proc = proc->next) + ; + if (!proc) + { + /* A new process. */ + proc = xtrycalloc (1, sizeof *proc); + if (!proc) + { + UNLOCK (proc_queue_lock); + return mk_error (Out_Of_Core); + } + proc->pid = pid; + proc->ctx = ctx; + proc->next = proc_queue; + proc_queue = proc; + } + assert (proc->ctx == ctx); + q->proc = proc; + q->next = proc->handler_list; + proc->handler_list = q; + UNLOCK (proc_queue_lock); + + LOCK (fd_table_lock); + again: + for (i=0; i < fd_table_size; i++) + { + if (fd_table[i].fd == -1) + { + fd_table[i].fd = fd; + fd_table[i].for_read = inbound; + fd_table[i].for_write = !inbound; + fd_table[i].signaled = 0; + fd_table[i].frozen = 0; + fd_table[i].opaque = q; + UNLOCK (fd_table_lock); + return 0; + } + } + if ( fd_table_size < 50 ) { + /* FIXME: We have to wait until there are no other readers of the + * table, i.e that the io_select is not active in another thread */ + struct io_select_fd_s *tmp; + + tmp = xtryrealloc (fd_table, (fd_table_size + 10) * sizeof *tmp); + if (tmp) + { + for (i = 0; i < 10; i++) + tmp[fd_table_size+i].fd = -1; + fd_table_size += i; + fd_table = tmp; + goto again; + } + } + + UNLOCK (fd_table_lock); + xfree (q); + /* FIXME: Remove the proc table entry. */ + return mk_error (Too_Many_Procs); +} + + +void +_gpgme_freeze_fd (int fd) +{ + int i; + + LOCK (fd_table_lock); + for (i = 0; i < fd_table_size; i++) + { + if (fd_table[i].fd == fd) + { + struct wait_item_s *q; + + fd_table[i].frozen = 1; + q = fd_table[i].opaque; + if (q) + q->frozen = 1; + DEBUG2 ("fd %d frozen (q=%p)", fd, q); + break; + } + } + UNLOCK (fd_table_lock); +} + +void +_gpgme_thaw_fd (int fd) +{ + int i; + + LOCK (fd_table_lock); + for (i = 0; i < fd_table_size; i++) + { + if (fd_table[i].fd == fd) + { + struct wait_item_s *q; + + fd_table[i].frozen = 0; + q = fd_table[i].opaque; + if (q) + q->frozen = 0; + DEBUG2 ("fd %d thawed (q=%p)", fd, q); + break; + } + } + UNLOCK (fd_table_lock); +} + + +/** + * gpgme_register_idle: + * @fnc: Callers idle function + * + * Register a function with GPGME called by GPGME whenever it feels + * that is is idle. NULL may be used to remove this function. + * + * Return value: The idle function pointer that was passed to the + * function at the last time it was invoked, or NULL if the function + * is invoked the first time. + **/ +GpgmeIdleFunc +gpgme_register_idle (GpgmeIdleFunc idle) +{ + GpgmeIdleFunc old_idle = idle_function; + + idle_function = idle; + return old_idle; +} + + +static void +run_idle () +{ + _gpgme_engine_housecleaning (); + if (idle_function) + idle_function (); +} diff --git a/tags/V0-3-4/gpgme/wait.h b/tags/V0-3-4/gpgme/wait.h new file mode 100644 index 0000000..857e5d5 --- /dev/null +++ b/tags/V0-3-4/gpgme/wait.h @@ -0,0 +1,40 @@ +/* wait.h - definitions for wait.c + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef WAIT_H +#define WAIT_H + +#include "gpgme.h" + +void _gpgme_remove_proc_from_wait_queue ( int pid ); + +GpgmeError _gpgme_register_pipe_handler ( + void *opaque, + int (*handler)(void*,int,int), + void *handler_value, + int pid, int fd, int inbound ); + +#endif /* WAIT_H */ + + + + + diff --git a/tags/V0-3-4/gpgmeplug/.cvsignore b/tags/V0-3-4/gpgmeplug/.cvsignore new file mode 100644 index 0000000..95fd8ee --- /dev/null +++ b/tags/V0-3-4/gpgmeplug/.cvsignore @@ -0,0 +1,2 @@ +Makefile.in Makefile .deps .libs +*.lo *.la diff --git a/tags/V0-3-4/gpgmeplug/ChangeLog b/tags/V0-3-4/gpgmeplug/ChangeLog new file mode 100644 index 0000000..220dea9 --- /dev/null +++ b/tags/V0-3-4/gpgmeplug/ChangeLog @@ -0,0 +1,75 @@ +2002-02-28 Kalle Dalheimer + + * gpgmeplug.c (signMessage): Implemented warning when signature + certificates are about to expire + (isEmailInCertificate): Added support for checking whether the + signer's email address is contained in his certificate. + + * cryptplug.h: Implemented warning when signature + certificates are about to expire + +2002-02-27 Marcus Brinkmann + + * gpgmeplug.c (signMessage): Fix code syntax. + +2002-02-01 Marcus Brinkmann + + * Makefile.am (EXTRA_gpgme_openpgp_la_SOURCES): New variable. + (EXTRA_gpgme_smime_la_SOURCES): Likewise. + + * gpgmeplug.c (passphrase_cb): Fix type of third argument. + +2002-01-16 Marcus Brinkmann + + * gpgme-openpgp.c: New file. + * Makefile.am (gpgme_openpgp_la_SOURCES): Replace gpgmeplug.c with + gpgme-openpgp.c. + +2002-01-15 Marcus Brinkmann + + * gpgmeplug.c: Renamed to ... + * gpgme-openpgp.c: ... this. New file. + * gpgsmplug.c: Renamed to ... + * gpgme-smime.c: ... this. new file. + * Makefile.am: Rewritten to use libtool's module functionality. + +2001-12-19 Marcus Brinkmann + + * Makefile.am (lib_LTLIBRARIES): Rename to ... + (noinst_LTLIBRARIES): ... this target. + +2001-12-19 Marcus Brinkmann + + * Makefile.am (libgpgmeplug_la_SOURCES): Remove gpgme.h. + (libgpgsmplug_la_SOURCES): Likewise. + +2001-11-29 Marcus Brinkmann + + * gpgmeplug.c (checkMessageSignature): Add call to gpgme_set_protocol. + +2001-11-24 Marcus Brinkmann + + * Makefile.am (libgpgsmplug_la_SOURCES): Fix source file. + +2001-11-22 Marcus Brinkmann + + * Makefile.am (libgpgsmplug_la_LIBADD): New variable. + (libgpgsmplug_la_LDFLAGS): Likewise. + (libgpgsmplug_la_SOURCES): Likewise. + (lib_LTLIBRARIES): Add libgpgsmplug.la. + (INCLUDES): Include the local gpgme.h. + + * gpgmeplug.c (signMessage): Set protocol. + (GPGMEPLUG_PROTOCOL) [!GPGMEPLUG_PROTOCOL]: Set + GPGMEPLUG_PROTOCOL. + * gpgsmplug.c: New file. + +2001-11-21 Marcus Brinkmann + + * gpgmeplug.c: Include config.h only if [HAVE_CONFIG_H]. Do not + include util.h. + (deinitialize): Use free, not _gpgme_free. + (setDirectoryServers): Use calloc, not xtrycalloc. Use free, not + _gpgme_free. Use malloc instead xtrymalloc. + (appendDirectoryServer): Use realloc, not xtryrealloc. + diff --git a/tags/V0-3-4/gpgmeplug/Makefile.am b/tags/V0-3-4/gpgmeplug/Makefile.am new file mode 100644 index 0000000..78422a0 --- /dev/null +++ b/tags/V0-3-4/gpgmeplug/Makefile.am @@ -0,0 +1,39 @@ +# $Id$ +# +# Makefile.am - Automake specification file for GPGMEPLUG. +# GPGMEPLUG is a GPGME based cryptography plug-in +# following the common CRYPTPLUG specification. +# +# Copyright (C) 2001 by Klar?lvdalens Datakonsult AB +# Copyright (C) 2002 g10 Code GmbH +# +# GPGMEPLUG is free software; you can redistribute it and/or modify +# it under the terms of GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# GPGMEPLUG is distributed in the hope that it will be useful, +# it under the terms of GNU General Public License as published by +# the Free Software Foundation; version 2 of the License +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA +# +## Process this file with automake to produce Makefile.in + +INCLUDES = -I$(top_srcdir)/gpgme + +pkglib_LTLIBRARIES = gpgme-openpgp.la gpgme-smime.la + +gpgme_openpgp_la_SOURCES = cryptplug.h gpgme-openpgp.c +EXTRA_gpgme_openpgp_la_SOURCES = gpgmeplug.c +gpgme_openpgp_la_LIBADD = ../gpgme/libgpgme.la +gpgme_openpgp_la_LDFLAGS = -module -avoid-version + +gpgme_smime_la_SOURCES = cryptplug.h gpgme-smime.c +EXTRA_gpgme_smime_la_SOURCES = gpgmeplug.c +gpgme_smime_la_LIBADD = ../gpgme/libgpgme.la +gpgme_smime_la_LDFLAGS = -module -avoid-version diff --git a/tags/V0-3-4/gpgmeplug/cryptplug.h b/tags/V0-3-4/gpgmeplug/cryptplug.h new file mode 100644 index 0000000..9cdeb07 --- /dev/null +++ b/tags/V0-3-4/gpgmeplug/cryptplug.h @@ -0,0 +1,1634 @@ +/* -*- Mode: C -*- + + $Id$ + + CRYPTPLUG - an independent cryptography plug-in API + + Copyright (C) 2001 by Klarälvdalens Datakonsult AB + + CRYPTPLUG is free software; you can redistribute it and/or modify + it under the terms of GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + CRYPTPLUG is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA +*/ + +#ifndef CRYPTPLUG_H +#define CRYPTPLUG_H + +#ifdef __cplusplus +extern "C" { +#else +typedef char bool; +#define true 1 +#define false 0 +#endif + +#include +//#include +//#include + + +/*! \file cryptplug.h + \brief Common API header for CRYPTPLUG. + + CRYPTPLUG is an independent cryptography plug-in API + developed for Sphinx-enabeling KMail and Mutt. + + CRYPTPLUG was designed for the Aegypten project, but it may + be used by 3rd party developers as well to design pluggable + crypto backends for the above mentioned MUAs. + + \note All string parameters appearing in this API are to be + interpreted as UTF-8 encoded. + + \see pgpplugin.c + \see gpgplugin.c +*/ + +/*! \defgroup groupGeneral Loading and Unloading the Plugin, General Functionality + + The functions in this section are used for loading and + unloading plugins. Note that the actual locating of the plugin + and the loading and unloading of the dynamic library is not + covered here; this is MUA-specific code for which support code + might already exist in the programming environments. +*/ + +/*! \defgroup groupDisplay Graphical Display Functionality + + The functions in this section return stationery that the + MUAs can use in order to display security functionality + graphically. This can be toolbar icons, shortcuts, tooltips, + etc. Not all MUAs will use all this functionality. +*/ + +/*! \defgroup groupConfig Configuration Support + + The functions in this section provide the necessary + functionality to configure the security functionality as well + as to query configuration settings. Since all configuration + settings will not be saved with the plugin, but rather with + the MUA, there are also functions to set configuration + settings programmatically; these will be used on startup of + the plugin when the MUA transfers the configuration values it + has read into the plugin. Usually, the functions to query and + set the configuration values are not needed for anything but + saving to and restoring from configuration files. +*/ + + +/*! \defgroup groupConfigSign Signature Configuration + \ingroup groupConfig + + The functions in this section provide the functionality + to configure signature handling and set and query the + signature configuration. +*/ + +/*! \defgroup groupConfigCrypt Encryption Configuration + \ingroup groupConfig + + The functions in this section provide the functionality + to configure encryption handling and set and query the + encryption configuration. + + \note Whenever the term encryption is used here, + it is supposed to mean both encryption and decryption, + unless otherwise specified. +*/ + +/*! \defgroup groupConfigDir Directory Service Configuration + \ingroup groupConfig + + This section contains messages for configuring the + directory service. +*/ + + +/*! \defgroup groupCertHand Certificate Handling + + The following methods are used to maintain and query certificates. +*/ + + +/*! \defgroup groupSignCryptAct Signing and Encrypting Actions + + This section describes methods and structures + used for signing and/or encrypting your mails. +*/ + + +/*! \defgroup groupSignAct Signature Actions + \ingroup groupSignCryptAct + + This section describes methods that are used for working + with signatures. +*/ + +/*! \defgroup groupCryptAct Encryption and Decryption + \ingroup groupSignCryptAct + + The following methods are used to encrypt and decrypt + email messages. +*/ + +/*! \defgroup groupCertAct Certificate Handling Actions + + The functions in this section provide local certificate management. +*/ + +/*! \defgroup groupCRLAct CRL Handling Actions + + This section describes functions for managing CRLs. +*/ + +/*! \defgroup groupAdUsoInterno Important functions to be used by plugin implementors ONLY. + + This section describes functions that have to be used by + plugin implementors but should not be used by plugin users + directly. + + If you are not planning to write your own cryptography + plugin you should ignore this section! +*/ + + +// dummy values: +typedef enum { + CryptPlugFeat_undef = 0, + + CryptPlugFeat_SignMessages = 1, + CryptPlugFeat_VerifySignatures = 2, + CryptPlugFeat_EncryptMessages = 3, + CryptPlugFeat_DecryptMessages = 4 // more to follow ... +} Feature; + +// dummy values +typedef enum { + PinRequest_undef = 0, + + PinRequest_Always = 1, + PinRequest_WhenAddingCerts = 2, + PinRequest_AlwaysWhenSigning = 3, + PinRequest_OncePerSession = 4, + PinRequest_AfterMinutes = 5 +} PinRequests; + +// dummy values: +typedef enum { + SendCert_undef = 0, + + SendCert_DontSend = 1, + SendCert_SendOwn = 2, + SendCert_SendChainWithoutRoot = 3, + SendCert_SendChainWithRoot = 4 +} SendCertificates; + +// dummy values: +typedef enum { + SignAlg_undef = 0, + + SignAlg_SHA1 = 1 +} SignatureAlgorithm; + + + +typedef enum { + EncryptAlg_undef = 0, + + EncryptAlg_RSA = 1, + EncryptAlg_SHA1 = 2, + EncryptAlg_TripleDES = 3 +} EncryptionAlgorithm; + +typedef enum { + SignEmail_undef = 0, + + SignEmail_SignAll = 1, + SignEmail_Ask = 2, + SignEmail_DontSign = 3 +} SignEmail; + +typedef enum { + EncryptEmail_undef = 0, + + EncryptEmail_EncryptAll = 1, + EncryptEmail_Ask = 2, + EncryptEmail_DontEncrypt = 3 +} EncryptEmail; + +typedef enum { + CertSrc_undef = 0, + + CertSrc_Server = 1, + CertSrc_Local = 2, + CertSrc_ServerLocal = CertSrc_Server | CertSrc_Local +} CertificateSource; + + + + + + +/*! \ingroup groupGeneral + \brief This function returns a URL to be used for reporting a bug that + you found (or suspect, resp.) in this cryptography plug-in. + + If the plugins for some reason cannot specify an appropriate URL you + should at least be provided with a text giving you some advise on + how to report a bug. + + \note This function must be implemented by each plug-in using + this API specification. +*/ +const char* bugURL( void ); + +/*! \ingroup groupGeneral + \brief This function sets up all internal structures. + + Plugins that need no initialization should provide an empty + implementation. The method returns \c true if the initialization was + successful and \c false otherwise. Before this function is called, + no other plugin functions should be called; the behavior is + undefined in this case. + + \note This function must be implemented by each plug-in using + this API specification. +*/ +bool initialize( void ); + +/*! \ingroup groupGeneral + \brief This function frees all internal structures. + + Plugins that do not keep any internal structures should provide an + empty implementation. After this function has been called, + no other plugin functions should be called; the behavior is + undefined in this case. + + \note This function must be implemented by each plug-in using + this API specification. +*/ +void deinitialize( void ); + +/*! \ingroup groupGeneral + \brief This function returns \c true if the + specified feature is available in the plugin, and + \c false otherwise. + + Not all plugins will support all features; a complete Sphinx + implementation will support all features contained in the enum, + however. + + \note This function must be implemented by each plug-in using + this API specification. +*/ +bool hasFeature( Feature ); + + +/*! \ingroup groupDisplay + \brief Returns stationery to indicate unsafe emails. +*/ +void unsafeStationery( void** pixmap, const char** menutext, char* accel, + const char** tooltip, const char** statusbartext ); + +/*! \ingroup groupDisplay + \brief Returns stationery to indicate signed emails. +*/ +void signedStationery( void** pixmap, const char** menutext, char* accel, + const char** tooltip, const char** statusbartext ); + +/*! \ingroup groupDisplay + \brief Returns stationery to indicate encrypted emails. +*/ +void encryptedStationery( void** pixmap, const char** + menutext, char* accel, + const char** tooltip, const char** statusbartext ); + +/*! \ingroup groupDisplay + \brief Returns stationery to indicate signed and encrypted emails. +*/ +void signedEncryptedStationery( void** pixmap, const char** + menutext, char* accel, + const char** tooltip, const char** statusbartext ); + +/*! \ingroup groupConfigSign + \brief This function returns an XML representation of a + configuration dialog for configuring signature + handling. + + The syntax is that of .ui + files as specified in the Imhotep + documentation. This function does not execute or show the + dialog in any way; this is up to the MUA. Also, what the + MUA makes of the information provided highly depends on + the MUA itself. A GUI-based MUA will probably create a + dialog window (possibly integrated into an existing + configuration dialog in the application), while a + terminal-based MUA might generate a series of questions or + a terminal based menu selection. +*/ +const char* signatureConfigurationDialog( void ); + +/*! \ingroup groupConfigSign + \brief This function returns an XML representation of a + configuration dialog for selecting a signature key. + + This will typically be used when the user wants to select a + signature key for one specific message only; the defaults + are set in the dialog returned by + signatureConfigurationDialog(). +*/ +const char* signatureKeySelectionDialog( void ); + +/*! \ingroup groupConfigSign + \brief This function returns an XML representation of a + configuration dialog for selecting a signature + algorithm. + + This will typically be used when the user wants + to select a signature algorithm for one specific message only; the + defaults are set in the dialog returned by + signatureConfigurationDialog(). +*/ +const char* signatureAlgorithmDialog( void ); + +/*! \ingroup groupConfigSign + \brief This function returns an XML representation of a + configuration dialog for selecting whether an email + message and its attachments should be sent with or + without signatures. + + This will typically be used when the + user wants to select a signature key for one specific + message only; the defaults are set in the dialog returned + by signatureConfigurationDialog(). +*/ +const char* signatureHandlingDialog( void ); + +/*! \ingroup groupConfigSign + \brief Sets the signature key certificate that identifies the + role of the signer. +*/ +void setSignatureKeyCertificate( const char* certificate ); + +/*! \ingroup groupConfigSign + \brief Returns the signature key certificate that identifies + the role of the signer. +*/ +const char* signatureKeyCertificate( void ); + +/*! \ingroup groupConfigSign + \brief Sets the algorithm used for signing. +*/ +void setSignatureAlgorithm( SignatureAlgorithm ); + +/*! \ingroup groupConfigSign + \brief Returns the algorithm used for signing. +*/ +SignatureAlgorithm signatureAlgorithm( void ); + +/*! \ingroup groupConfigSign + \brief Sets which certificates should be sent with the + message. +*/ +void setSendCertificates( SendCertificates ); +/*! \ingroup groupConfigSign + \brief Returns which certificates should be sent with the + message. +*/ +SendCertificates sendCertificates( void ); + +/*! \ingroup groupConfigSign + \brief Specifies whether email should be automatically + signed, signed after confirmation, signed after + confirmation for each part or not signed at all. +*/ +void setSignEmail( SignEmail ); + +/*! \ingroup groupConfigSign + \brief Returns whether email should be automatically + signed, signed after confirmation, signed after + confirmation for each part or not signed at all. +*/ +SignEmail signEmail( void ); + + +/*! \ingroup groupConfigSign + \brief Specifies whether a warning should be emitted when the user + tries to send an email message unsigned. +*/ +void setWarnSendUnsigned( bool ); + + +/*! \ingroup groupConfigSign + \brief Returns whether a warning should be emitted when the user + tries to send an email message unsigned. +*/ +bool warnSendUnsigned( void ); + + +/*! \ingroup groupConfigSign + \brief Specifies whether sent email messages should be stored + with or without their signatures. +*/ +void setSaveSentSignatures( bool ); + +/*! \ingroup groupConfigSign + \brief Returns whether sent email messages should be stored + with or without their signatures. +*/ +bool saveSentSignatures( void ); + +/*! \ingroup groupConfigSign + \brief Specifies whether a warning should be emitted if the + email address of the sender is not contained in the + certificate. +*/ +void setWarnNoCertificate( bool ); + +/*! \ingroup groupConfigSign + \brief Returns whether a warning should be emitted if the + email address of the sender is not contained in the + certificate. +*/ +bool warnNoCertificate( void ); + +/*! + \ingroup groupConfigSign + \brief Returns true if the specified email address is contained + in the specified certificate. +*/ +bool isEmailInCertificate( const char* email, const char* certificate ); + +/*! \ingroup groupConfigSign + \brief Specifies how often the PIN is requested when + accessing the secret signature key. +*/ +void setNumPINRequests( PinRequests ); + +/*! \ingroup groupConfigSign + \brief Returns how often the PIN is requested when + accessing the secret signature key. +*/ +PinRequests numPINRequests( void ); + +/*! \ingroup groupConfigSign + \brief Specifies the interval in minutes the PIN must be reentered if + numPINRequests() is PinRequest_AfterMinutes. +*/ +void setNumPINRequestsInterval( int ); + + +/*! \ingroup groupConfigSign + \brief Returns the interval in minutes the PIN must be reentered if + numPINRequests() is PinRequest_AfterMinutes. +*/ +int numPINRequestsInterval( void ); + + +/*! \ingroup groupConfigSign + \brief Specifies whether the certificate path should be + followed to the root certificate or whether locally stored + certificates may be used. +*/ +void setCheckSignatureCertificatePathToRoot( bool ); + +/*! \ingroup groupConfigSign + \brief Returns whether the certificate path should be + followed to the root certificate or whether locally stored + certificates may be used. +*/ +bool checkSignatureCertificatePathToRoot( void ); + +/*! \ingroup groupConfigSign + \brief Specifies whether certificate revocation lists should + be used. +*/ +void setSignatureUseCRLs( bool ); + +/*! \ingroup groupConfigSign + \brief Returns whether certificate revocation lists should + be used. +*/ +bool signatureUseCRLs( void ); + +/*! \ingroup groupConfigSign + \brief Specifies whether a warning should be emitted if the + signature certificate expires in the near future. +*/ +void setSignatureCertificateExpiryNearWarning( bool ); + +/*! \ingroup groupConfigSign + \brief Returns whether a warning should be emitted if + the signature certificate expires in the near future. +*/ +bool signatureCertificateExpiryNearWarning( void ); + + /*! \ingroup groupConfigSign + \brief Returns the number of days that are left until the + specified certificate expires. + \param certificate the certificate to check + */ + int signatureCertificateDaysLeftToExpiry( const char* certificate ); + +/*! \ingroup groupConfigSign + \brief Specifies the number of days which a signature certificate must + be valid before it is considered to expire in the near + future. +*/ +void setSignatureCertificateExpiryNearInterval( int ); + +/*! \ingroup groupConfigSign + \brief Returns the number of days which a signature certificate must + be valid before it is considered to expire in the near + future. +*/ +int signatureCertificateExpiryNearInterval( void ); + +/*! \ingroup groupConfigSign + \brief Specifies whether a warning should be emitted if the + CA certificate expires in the near future. +*/ +void setCACertificateExpiryNearWarning( bool ); + +/*! \ingroup groupConfigSign + \brief Returns whether a warning should be emitted if + the CA certificate expires in the near future. +*/ +bool caCertificateExpiryNearWarning( void ); + + /*! \ingroup groupConfigSign + \brief Returns the number of days that are left until the + CA certificate of the specified certificate expires. + \param certificate the certificate to check + */ + int caCertificateDaysLeftToExpiry( const char* certificate ); + +/*! \ingroup groupConfigSign + \brief Specifies the number of days which a CA certificate must + be valid before it is considered to expire in the near + future. +*/ +void setCACertificateExpiryNearInterval( int ); + +/*! \ingroup groupConfigSign + \brief Returns the number of days which a CA certificate must + be valid before it is considered to expire in the near + future. +*/ +int caCertificateExpiryNearInterval( void ); + +/*! \ingroup groupConfigSign + \brief Specifies whether a warning should be emitted if the + root certificate expires in the near future. +*/ +void setRootCertificateExpiryNearWarning( bool ); + +/*! \ingroup groupConfigSign + \brief Returns whether a warning should be emitted if + the root certificate expires in the near future. +*/ +bool rootCertificateExpiryNearWarning( void ); + + /*! \ingroup groupConfigSign + \brief Returns the number of days that are left until the + root certificate of the specified certificate expires. + \param certificate the certificate to check + */ + int rootCertificateDaysLeftToExpiry( const char* certificate ); + +/*! \ingroup groupConfigSign + \brief Specifies the number of days which a root certificate must + be valid before it is considered to expire in the near + future. +*/ +void setRootCertificateExpiryNearInterval( int ); + +/*! \ingroup groupConfigSign + \brief Returns the number of days which a signature certificate must + be valid before it is considered to expire in the near + future. +*/ +int rootCertificateExpiryNearInterval( void ); + + + + +/*! \ingroup groupConfigCrypt + \brief This function returns an XML representation of a + configuration dialog for configuring encryption + handling. + + The syntax is that of .ui + files as specified in the Imhotep + documentation. This function does not execute or show the + dialog in any way; this is up to the MUA. Also, what the + MUA makes of the information provided highly depends on + the MUA itself. A GUI-based MUA will probably create a + dialog window (possibly integrated into an existing + configuration dialog in the application), while a + terminal-based MUA might generate a series of questions or + a terminal based menu selection. +*/ +const char* encryptionConfigurationDialog( void ); + +/*! \ingroup groupConfigCrypt + \brief This function returns an XML representation of a + configuration dialog for selecting an encryption + algorithm. + + This will typically be used when the user wants + to select an encryption algorithm for one specific message only; the + defaults are set in the dialog returned by + encryptionConfigurationDialog(). +*/ +const char* encryptionAlgorithmDialog( void ); + +/*! \ingroup groupConfigCrypt + \brief This function returns an XML representation of a + configuration dialog for selecting whether an email + message and its attachments should be encrypted. + + This will typically be used when the + user wants to select an encryption key for one specific + message only; the defaults are set in the dialog returned + by encryptionConfigurationDialog(). +*/ +const char* encryptionHandlingDialog( void ); + +/*! \ingroup groupConfigCrypt + \brief This function returns an XML representation of a + dialog that lets the user select the certificate to use + for encrypting. + + If it was not possible to determine the + correct certificate from the information in the email + message, the user is presented with a list of possible + certificates to choose from. If a unique certificate was + found, this is presented to the user, who needs to confirm + the selection of the certificate. This procedure is repeated + for each recipient of the email message. +*/ +const char* encryptionReceiverDialog( void ); + +/*! \ingroup groupConfigCrypt + \brief Sets the algorithm used for encrypting. +*/ +void setEncryptionAlgorithm( EncryptionAlgorithm ); + +/*! \ingroup groupConfigCrypt + \brief Returns the algorithm used for encrypting. +*/ +EncryptionAlgorithm encryptionAlgorithm( void ); + +/*! \ingroup groupConfigCrypt + \brief Specifies whether email should be automatically + encrypted, encrypted after confirmation, encrypted after + confirmation for each part or not encrypted at all. +*/ +void setEncryptEmail( EncryptEmail ); + +/*! \ingroup groupConfigCrypt + \brief Returns whether email should be automatically + encrypted, encrypted after confirmation, encrypted after + confirmation for each part or not encrypted at all. +*/ +EncryptEmail encryptEmail( void ); + +/*! \ingroup groupConfigSign + \brief Specifies whether a warning should be emitted when the user + tries to send an email message unencrypted. +*/ +void setWarnSendUnencrypted( bool ); + + +/*! \ingroup groupConfigSign + \brief Returns whether a warning should be emitted when the user + tries to send an email message unencrypted. +*/ +bool warnSendUnencrypted( void ); + + +/*! \ingroup groupConfigCrypt + \brief Specifies whether encrypted email messages should be + stored encrypted or decrypted. +*/ +void setSaveMessagesEncrypted( bool ); + +/*! \ingroup groupConfigCrypt + \brief Returns whether encrypted email messages should be stored + encrypted or decrypted. +*/ +bool saveMessagesEncrypted( void ); + + +/*! \ingroup groupConfigCrypt + \brief Specifies whether the certificate path should be checked + during encryption. +*/ +void setCheckCertificatePath( bool ); + +/*! \ingroup groupConfigCrypt + \brief Returns whether the certificate path should be checked + during encryption. +*/ +bool checkCertificatePath( void ); + + +/*! \ingroup groupConfigCrypt + \brief Specifies whether the certificate path should be + followed to the root certificate or whether locally stored + certificates may be used. +*/ +void setCheckEncryptionCertificatePathToRoot( bool ); + +/*! \ingroup groupConfigCrypt + \brief Returns whether the certificate path should be + followed to the root certificate or whether locally stored + certificates may be used. +*/ +bool checkEncryptionCertificatePathToRoot( void ); + + +/*! \ingroup groupConfigCrypt + \brief Specifies whether a warning should be emitted if the + certificate of the receiver expires in the near future. +*/ +void setReceiverCertificateExpiryNearWarning( bool ); + +/*! \ingroup groupConfigCrypt + \brief Returns whether a warning should be emitted if the + certificate of the receiver expires in the near future. +*/ +bool receiverCertificateExpiryNearWarning( void ); + + +/*! \ingroup groupConfigCrypt + \brief Specifies the number of days which a receiver certificate + must be valid before it is considered to expire in the near future. +*/ +void setReceiverCertificateExpiryNearWarningInterval( int ); + +/*! \ingroup groupConfigCrypt + \brief Returns the number of days which a receiver certificate + must be valid before it is considered to expire in the near future. +*/ +int receiverCertificateExpiryNearWarningInterval( void ); + +/*! \ingroup groupConfigCrypt + \brief Specifies whether a warning should be emitted if + a certificate in the chain expires in the near future. +*/ +void setCertificateInChainExpiryNearWarning( bool ); + + +/*! \ingroup groupConfigCrypt + \brief Returns whether a warning should be emitted if a + certificate in the chain expires in the near future. +*/ +bool certificateInChainExpiryNearWarning( void ); + + + +/*! \ingroup groupConfigCrypt + \brief Specifies the number of days which a certificate in the chain + must be valid before it is considered to expire in the near future. +*/ +void setCertificateInChainExpiryNearWarningInterval( int ); + +/*! \ingroup groupConfigCrypt + \brief Returns the number of days which a certificate in the chain + must be valid before it is considered to expire in the near future. +*/ +int certificateInChainExpiryNearWarningInterval( void ); + + +/*! \ingroup groupConfigCrypt + \brief Specifies whether a warning is emitted if the email address + of the receiver does not appear in the certificate. +*/ +void setReceiverEmailAddressNotInCertificateWarning( bool ); + +/*! \ingroup groupConfigCrypt + \brief Returns whether a warning is emitted if the email address + of the receiver does not appear in the certificate. +*/ +bool receiverEmailAddressNotInCertificateWarning( void ); + + +/*! \ingroup groupConfigCrypt + \brief Specifies whether certificate revocation lists should + be used. +*/ +void setEncryptionUseCRLs( bool ); + +/*! \ingroup groupConfigCrypt + \brief Returns whether certificate revocation lists should + be used. +*/ +bool encryptionUseCRLs( void ); + +/*! \ingroup groupConfigCrypt + \brief Specifies whether a warning should be emitted if any + of the certificates involved in the signing process + expires in the near future. +*/ +void setEncryptionCRLExpiryNearWarning( bool ); + +/*! \ingroup groupConfigCrypt + \brief Returns whether a warning should be emitted if any + of the certificates involved in the signing process + expires in the near future. +*/ +bool encryptionCRLExpiryNearWarning( void ); + +/*! \ingroup groupConfigCrypt + \brief Specifies the number of days which a certificate must + be valid before it is considered to expire in the near + future. +*/ +void setEncryptionCRLNearExpiryInterval( int ); + +/*! \ingroup groupConfigCrypt + \brief Returns the number of days which a certificate must + be valid before it is considered to expire in the near + future. +*/ +int encryptionCRLNearExpiryInterval( void ); + + +/*! \ingroup groupConfigCrypt + \brief Returns the number of days the currently active certification + list is still valid. +*/ +int encryptionCRLsDaysLeftToExpiry( void ); + + + +/*! \ingroup groupConfigDir + \brief This function returns an XML representation of a + configuration dialog for selecting a directory + server. +*/ +const char* directoryServiceConfigurationDialog( void ); + +/*! \ingroup groupConfigDir + \brief Lets you configure how certificates and certificate + revocation lists are retrieved (both locally and from directory + services). + + Will mainly be used for restoring + configuration data; interactive configuration will be done + via the configuration dialog returned by + \c directoryServiceConfigurationDialog(). +*/ +void appendDirectoryServer( const char* servername, int port, + const char* description ); + + + + +/*! \ingroup groupConfigDir +*/ +struct DirectoryServer { + char* servername; + int port; + char* description; +}; + + +/*! \ingroup groupConfigDir + \brief Specifies a list of directory servers. + + Will mainly be used for restoring + configuration data; interactive configuration will be done + via the configuration dialog returned by + \c directoryServiceConfigurationDialog(). +*/ +void setDirectoryServers( struct DirectoryServer[], unsigned int size ); + +/*! \ingroup groupConfigDir + \brief Returns the list of directory servers. + + Will mainly be used for saving configuration data; interactive + configuration will be done via the configuration dialog + returned by + \c directoryServiceConfigurationDialog(). +*/ +struct DirectoryServer* directoryServers( int* numServers ); + +/*! \ingroup groupConfigDir + \brief Specifies whether certificates should be retrieved + from a directory server, only locally, or both. +*/ +void setCertificateSource( CertificateSource ); + +/*! \ingroup groupConfigDir + \brief Returns whether certificates should be retrieved + from a directory server, only locally, or both. +*/ +CertificateSource certificateSource( void ); + +/*! \ingroup groupConfigDir + \brief Specifies whether certificates should be retrieved + from a directory server, only locally, or both. +*/ +void setCRLSource( CertificateSource ); + +/*! \ingroup groupConfigDir + \brief Returns whether certificates should be retrieved + from a directory server, only locally, or both. +*/ +CertificateSource crlSource( void ); + + +/*! \ingroup groupCertHand + \brief Returns \c true if and only if the + certificates in the certificate chain starting at + \c certificate are valid. + + If \c level is non-null, the parameter contains + the degree of trust on a backend-specific scale. In an X.509 + implementation, this will either be \c 1 + (valid up to the root certificate) or \c 0 + (not valid up to the root certificate). +*/ +bool certificateValidity( const char* certificate, int* level ); + + +/*! \ingroup groupSignCryptAct + \brief Information record returned by signing and by encrypting + functions - this record should be used together with a + corresponding \c free_StructuringInfo() function call. + + Use this information to compose a MIME object containing signed + and/or encrypted content (or to build a text frame around your + flat non-MIME message body, resp.) + + If value returned in \c makeMimeObject is TRUE the + text strings returned in \c contentTypeMain and \c contentDispMain + and \c contentTEncMain (and, if required, \c content[..]Version and + \c bodyTextVersion and \c content[..]Sig) should be used to compose + a respective MIME object.
+ If FALSE the texts returned in \c flatTextPrefix and + \c flatTextSeparator and \c flatTextPostfix are to be used instead.
+ Allways either the \c content[..] and \c bodyTextVersion + parameters or the \c flatText[..] parameters are holding + valid data - never both of them may be used simultaneously + as plugins will just ignore the parameters not matching their + \c makeMimeObject setting. + + When creating your MIME object please observe these common rules: + \li Parameters named \c contentType[..] and \c contentDisp[..] and + \c contentTEnc[..] will return the values for the respective MIME + headers 'Content-Type' and 'Content-Disposition' and + 'Content-Transfer-Encoding'. The following applies to these parameters: + \li The relevant MIME part may only be created if the respective + \c contentType[..] parameter is holding a non-zero-length string. If the + \c contentType[..] parameter value is invalid or holding an empty string + the respective \c contentDisp[..] and \c contentTEnc[..] parameters + should be ignored. + \li If the respective \c contentDisp[..] or \c contentTEnc[..] parameter + is NULL or holding a zero-length string it is up to you whether you want + to add the relevant MIME header yourself, but since it in in the + responsibility of the plugin implementors to provide you with all + neccessary 'Content-[..]' header information you should not need + to define them if they are not returned by the signing or encrypting + function - otherwise this may be considered as a bug in the plugin and + you could report the missing MIME header information to the address + returned by the \c bugURL() function. + + If \c makeMultiMime returns FALSE the \c contentTypeMain returned must + not be altered but used to specify a single part mime object holding the + code bloc, e.g. this is used for 'enveloped-data' single part MIME + objects. In this case you should ignore both the \c content[..]Version + and \c content[..]Code parameters. + + If \c makeMultiMime returns TRUE also the following rules apply: + \li If \c includeCleartext is TRUE you should include the cleartext + as first part of our multipart MIME object, typically this is TRUE + when signing mails but FALSE when encrypting. + \li The \c contentTypeMain returned typically starts with + "multipart/" while providing a "protocol" and a "micalg" parameter: just + add an appropriate \c "; boundary=[your \c boundary \c string]" to get + the complete Content-Type value to be used for the MIME object embedding + both the signed part and the signature part (or - in case of + encrypting - the version part and the code part, resp.). + \li If \c contentTypeVersion is holding a non-zero-length string an + additional MIME part must added immediately before the code part, this + version part's MIME headers must have the unaltered values of + \c contentTypeVersion and (if they are holding non-zero-length strings) + \c contentDispVersion and \c contentTEncVersion, the unaltered contents + of \c bodyTextVersion must be it's body. + \li The value returned in \c contentTypeCode is specifying the complete + Content-Type to be used for this multipart MIME object's signature part + (or - in case of encrypting - for the code part following after the + version part, resp.), you should not add/change/remove anything here + but just use it's unaltered value for specifying the Content-Type header + of the respective MIME part. + \li The same applies to the \c contentDispCode value: just use it's + unaltered value to specify the Content-Disposition header entry of + the respective MIME part. + \li The same applies to the \c contentTEncCode value: just use it's + unaltered value to specify the Content-Transfer-Encoding header of + the respective MIME part. + + If value returned in \c makeMimeObject is FALSE the + text strings returned in \c flatTextPrefix and \c flatTextPostfix + should be used to build a frame around the cleartext and the code + bloc holding the signature (or - in case of encrypting - the encoded + data bloc, resp.).
+ If \c includeCleartext is TRUE this frame should also include the + cleartext as first bloc, this bloc should be divided from the code bloc + by the contents of \c flatTextSeparator - typically this is used for + signing but not when encrypting.
+ If \c includeCleartext is FALSE you should ignore both the cleartext + and the \c flatTextSeparator parameter. + + How to use StructuringInfo data in your program: + \li To compose a signed message please act as described below. + \li For constructing an encrypted message just replace the + \c signMessage() call by the respective \c encryptMessage() call + and then proceed exactly the same way. + \li In any case make sure to free your \c ciphertext and + to call \c free_StructuringInfo() when you are done with processing + the data returned by the signing (or encrypting, resp.) function. + +\verbatim + + char* ciphertext; + StructuringInfo structInf; + + if( ! signMessage( cleartext, &ciphertext, certificate, + &structuring ) ) { + + myErrorDialog( "Error: could not sign the message!" ); + + } else { + if( structInf.makeMimeObject ) { + + // Build the main MIME object. + // This is done by + // using the header values returned in + // structInf.contentTypeMain and in + // structInf.contentDispMain and in + // structInf.contentTEncMain. + .. + + if( ! structInf.makeMultiMime ) { + + // Build the main MIME object's body. + // This is done by + // using the code bloc returned in + // ciphertext. + .. + + } else { + + // Build the encapsulated MIME parts. + if( structInf.includeCleartext ) { + + // Build a MIME part holding the cleartext. + // This is done by + // using the original cleartext's headers and by + // taking it's original body text. + .. + + } + if( structInf.contentTypeVersion + && 0 < strlen( structInf.contentTypeVersion ) ) { + + // Build a MIME part holding the version information. + // This is done by + // using the header values returned in + // structInf.contentTypeVersion and + // structInf.contentDispVersion and + // structInf.contentTEncVersion and by + // taking the body contents returned in + // structInf.bodyTextVersion. + .. + + } + if( structInf.contentTypeCode + && 0 < strlen( structInf.contentTypeCode ) ) { + + // Build a MIME part holding the code information. + // This is done by + // using the header values returned in + // structInf.contentTypeCode and + // structInf.contentDispCode and + // structInf.contentTEncCode and by + // taking the body contents returned in + // ciphertext. + .. + + } else { + + // Plugin error! + myErrorDialog( "Error: Cryptography plugin returned a main" + "Content-Type=Multipart/.. but did not " + "specify the code bloc's Content-Type header." + "\nYou may report this bug:" + "\n" + cryptplug.bugURL() ); + } + } + } else { + + // Build a plain message body + // based on the values returned in structInf. + // Note: We do _not_ insert line breaks between the parts since + // it is the plugin job to provide us with ready-to-use + // texts containing all neccessary line breaks. + strcpy( myMessageBody, structInf.plainTextPrefix ); + if( structInf.includeCleartext ) { + strcat( myMessageBody, cleartext ); + strcat( myMessageBody, structInf.plainTextSeparator ); + } + strcat( myMessageBody, *ciphertext ); + strcat( myMessageBody, structInf.plainTextPostfix ); + } + + // free the memory that was allocated + // for the ciphertext + free( ciphertext ); + + // free the memory that was allocated + // for our StructuringInfo's char* members + free_StructuringInfo( &structuring ); + } + +\endverbatim + + \note Make sure to call \c free_StructuringInfo() when you are done + with processing the StructuringInfo data! + + \see free_StructuringInfo + \see signMessage, encryptMessage, encryptAndSignMessage +*/ +struct StructuringInfo { + bool includeCleartext; /*!< specifies whether we should include the + cleartext as first part of our multipart + MIME object (or - for non-MIME + messages - as flat text to be set before + the ciphertext, resp.), typically this + is TRUE when signing mails but FALSE + when encrypting
+ (this parameter is relevant no matter + whether \c makeMimeObject is TRUE or + FALSE) */ + bool makeMimeObject; /*!< specifies whether we should create a MIME + object or a flat text message body */ + // the following are used for MIME messages only + bool makeMultiMime; /*!< specifies whether we should create a + 'Multipart' MIME object or a single part + object, if FALSE only \c contentTypeMain, + \c contentDispMain and \c contentTEncMain + may be used and all other parameters have + to be ignored
+ (ignore this parameter if \c makeMimeObject + is FALSE) */ + char* contentTypeMain; /*!< value of the main 'Content-Type' + header
+ (ignore this parameter if \c makeMimeObject + is FALSE) */ + char* contentDispMain; /*!< value of the main 'Content-Disposition' + header
+ (ignore this parameter if \c makeMimeObject + is FALSE) */ + char* contentTEncMain; /*!< value of the main + 'Content-TransferEncoding' header
+ (ignore this parameter if \c makeMimeObject + is FALSE) */ + char* contentTypeVersion; /*!< 'Content-Type' of the additional version + part that might preceed the code part - + if NULL or zero length no version part + must be created
+ (ignore this parameter if either + \c makeMimeObject or \c makeMultiMime + is FALSE) */ + char* contentDispVersion; /*!< 'Content-Disposition' of the additional + preceeding the code part (only valid if + \c contentTypeVersion holds a + non-zero-length string)
+ (ignore this parameter if either + \c makeMimeObject or \c makeMultiMime + is FALSE or if \c contentTypeVersion does + not return a non-zero-length string) */ + char* contentTEncVersion; /*!< 'Content-Transfer-Encoding' of the + additional version part (only valid if + \c contentTypeVersion holds a + non-zero-length string)
+ (ignore this parameter if either + \c makeMimeObject or \c makeMultiMime + is FALSE or if \c contentTypeVersion does + not return a non-zero-length string) */ + char* bodyTextVersion; /*!< body text of the additional version part + (only valid if \c contentTypeVersion + holds a non-zero-length string)
+ (ignore this parameter if either + \c makeMimeObject or \c makeMultiMime + is FALSE or if \c contentTypeVersion does + not return a non-zero-length string) */ + char* contentTypeCode; /*!< 'Content-Type' of the code part holding + the signature code (or the encrypted + data, resp.)
+ (ignore this parameter if either + \c makeMimeObject or \c makeMultiMime + is FALSE) */ + char* contentDispCode; /*!< 'Content-Disposition' of the code part
+ (ignore this parameter if either + \c makeMimeObject or \c makeMultiMime + is FALSE or if \c contentTypeCode does + not return a non-zero-length string) */ + char* contentTEncCode; /*!< 'Content-Type' of the code part
+ (ignore this parameter if either + \c makeMimeObject or \c makeMultiMime + is FALSE or if \c contentTypeCode does + not return a non-zero-length string) */ + // the following are used for flat non-MIME messages only + char* flatTextPrefix; /*!< text to preceed the main text (or the + code bloc containing the encrypted main + text, resp.)
+ (ignore this parameter if + \c makeMimeObject is TRUE) */ + char* flatTextSeparator; /*!< text to be put between the main text and + the signature code bloc (not used when + encrypting)
+ (ignore this parameter if + \c makeMimeObject is TRUE or if + \c includeCleartext is FALSE) */ + char* flatTextPostfix; /*!< text to follow the signature code bloc + (or the encrypted data bloc, resp.)
+ (ignore this parameter if + \c makeMimeObject is TRUE) */ +}; + + +/*! \ingroup groupAdUsoInterno + \brief If you are not planning to write your own cryptography + plugin you should ignore this function! + + Usage of this function is depreciated for plugin users but highly + recommended for plugin implementors since this is an internal + function for initializing all char* members of a \c StructuringInfo + struct.
+ This function must be called in any plugin's + implementations of the following functions: + + \c signMessage()
+ \c encryptMessage()
+ \c encryptAndSignMessage() + + Calling this function makes sure the corresponding + \c free_StructuringInfo() calls which will be embedded by + your plugin's users into their code will be able to + determine which of the char* members belonging to the + respective's StructuringInfo had been allocated memory + for during previous signing or encrypting actions. + + \see free_StructuringInfo, StructuringInfo + \see signMessage, encryptMessage, encryptAndSignMessage +*/ + void init_StructuringInfo( struct StructuringInfo* s ) + { + if( ! s ) return; + + s->includeCleartext = false; + + s->makeMimeObject = false; + s->makeMultiMime = false; + + s->contentTypeMain = 0; + s->contentDispMain = 0; + s->contentTEncMain = 0; + + s->contentTypeVersion = 0; + s->contentDispVersion = 0; + s->contentTEncVersion = 0; + s->bodyTextVersion = 0; + + s->contentTypeCode = 0; + s->contentDispCode = 0; + s->contentTEncCode = 0; + + s->flatTextPrefix = 0; + s->flatTextSeparator = 0; + s->flatTextPostfix = 0; + } + +/*! \ingroup groupSignCryptAct + \brief Important method for freeing all memory that was allocated + for the char* members of a \c StructuringInfo struct - use + this function after each signing or encrypting function + call. + + \note Even when intending to call \c encryptMessage() immediately + after having called \c signMessage() you first must call + the \c free_StructuringInfo() function to make sure all memory is + set free that was allocated for your StructuringInfo's char* members + by the \c signMessage() function! + + \see StructuringInfo +*/ + void free_StructuringInfo( struct StructuringInfo* s ) + { + if( ! s ) return; + if( s->contentTypeMain ) free( s->contentTypeMain ); + if( s->contentDispMain ) free( s->contentDispMain ); + if( s->contentTEncMain ) free( s->contentTEncMain ); + if( s->contentTypeVersion ) free( s->contentTypeVersion ); + if( s->contentDispVersion ) free( s->contentDispVersion ); + if( s->contentTEncVersion ) free( s->contentTEncVersion ); + if( s->bodyTextVersion ) free( s->bodyTextVersion ); + if( s->contentTypeCode ) free( s->contentTypeCode ); + if( s->contentDispCode ) free( s->contentDispCode ); + if( s->contentTEncCode ) free( s->contentTEncCode ); + if( s->flatTextPrefix ) free( s->flatTextPrefix ); + if( s->flatTextSeparator ) free( s->flatTextSeparator ); + if( s->flatTextPostfix ) free( s->flatTextPostfix ); + } + + +/*! \ingroup groupSignAct + \brief Signs a message \c cleartext and returns + in \c *ciphertext the signature data bloc that + is to be added to the message. + + The signature role is specified by \c certificate. + If \c certificate is \c NULL, the default certificate is used. + + If the message could be signed, the function returns + \c true, otherwise + \c false. + + Use the StructuringInfo data returned in parameter \c structuring + to find out how to build the respective MIME object (or the plain + text message body, resp.). + + \note The function allocates memory for the \c *ciphertext, so + make sure you set free that memory when no longer needing + it (as shown in example code provided with documentation + of the struct \c StructuringInfo). + + \note The function also allocates memory for some char* members + of the StructuringInfo* parameter that you are providing, + therefore you must call the \c free_StructuringInfo() function + to make sure all memory is set free that was allocated. This must be + done before calling the next cryptography function - even if + you intend to call \c encryptMessage() immediately after + \c signMessage(). + + \see StructuringInfo, free_StructuringInfo +*/ +bool signMessage( const char* cleartext, + const char** ciphertext, + const char* certificate, + struct StructuringInfo* structuring ); + + +/*! \ingroup groupSignAct + */ +struct SignatureMetaDataExtendedInfo +{ + struct tm* creation_time; + char* status_text; + char* fingerprint; +}; + +/*! \ingroup groupSignAct +*/ +struct SignatureMetaData { + char* status; + struct SignatureMetaDataExtendedInfo* extended_info; + int extended_info_count; + char* nota_xml; + int status_code; +}; + +/*! \ingroup groupSignAct + \brief Checks whether the signature of a message is + valid. \c ciphertext specifies the signed message + as it was received by the MUA, \c signaturetext is the + signature itself. + + Depending on the configuration, MUAs might not need to use this. + If \c sigmeta is non-null, the + \c SignatureMetaData object pointed to will + contain meta information about the signature after the + function call. +*/ +bool checkMessageSignature( const char* ciphertext, + const char* signaturetext, + struct SignatureMetaData* sigmeta ); + +/*! \ingroup groupSignAct + \brief Stores the certificates that follow with the message + \c ciphertext locally. +*/ +bool storeCertificatesFromMessage( const char* ciphertext ); + + +/*! \ingroup groupCryptAct + \brief Encrypts an email message in + \c cleartext according to the \c addressee and + the current settings (algorithm, etc.) and + returns the encoded data bloc in \c *ciphertext. + + If the message could be encrypted, the function returns + \c true, otherwise + \c false. + + Use the StructuringInfo data returned in parameter \c structuring + to find out how to build the respective MIME object (or the plain + text message body, resp.). + + \note The function allocates memory for the \c *ciphertext, so + make sure you set free that memory when no longer needing + it (as shown in example code provided with documentation + of the struct \c StructuringInfo). + + \note The function also allocates memory for some char* members + of the StructuringInfo* parameter that you are providing, + therefore you must call the \c free_StructuringInfo() function + to make sure all memory is set free that was allocated. This must be + done before calling the next cryptography function! + + \see StructuringInfo, free_StructuringInfo +*/ +bool encryptMessage( const char* cleartext, + const char** ciphertext, + const char* addressee, + struct StructuringInfo* structuring ); + + +/*! \ingroup groupCryptAct + \brief Combines the functionality of + \c encryptMessage() and + \c signMessage(). + + If \c certificate is \c NULL, + the default certificate will be used. + + If the message could be signed and encrypted, the function returns + \c true, otherwise + \c false. + + Use the StructuringInfo data returned in parameter \c structuring + to find out how to build the respective MIME object (or the plain + text message body, resp.). + + \note The function allocates memory for the \c *ciphertext, so + make sure you set free that memory when no longer needing + it (as shown in example code provided with documentation + of the struct \c StructuringInfo). + + \note The function also allocates memory for some char* members + of the StructuringInfo* parameter that you are providing, + therefore you must call the \c free_StructuringInfo() function + to make sure all memory is set free that was allocated. This must be + done before calling the next cryptography function! + + \see StructuringInfo, free_StructuringInfo +*/ +bool encryptAndSignMessage( const char* cleartext, + const char** ciphertext, + const char* certificate, + struct StructuringInfo* structuring ); + +/*! \ingroup groupCryptAct + \brief Tries to decrypt an email message + \c ciphertext and returns the decrypted + message in \c cleartext. + + The \c certificate is used for decryption. If + the message could be decrypted, the function returns + \c true, otherwise + \c false. +*/ +bool decryptMessage( const char* ciphertext, const + char** cleartext, const char* certificate ); + +/*! \ingroup groupCryptAct + \brief Combines the functionality of + \c checkMessageSignature() and + \c decryptMessage(). + + If \c certificate is \c NULL, + the default certificate will be used. + If \c sigmeta is non-null, the \c SignatureMetaData + object pointed to will contain meta information about + the signature after the function call. +*/ +bool decryptAndCheckMessage( const char* ciphertext, + const char** cleartext, + const char* certificate, + struct SignatureMetaData* sigmeta ); + + +/*! \ingroup groupCertAct + \brief This function returns an XML representation of a dialog + that can be used to fill in the data for requesting a + certificate (which in turn is done with the function + \c requestCertificate() described + next. +*/ +const char* requestCertificateDialog( void ); + +/*! \ingroup groupCertAct + \brief Generates a prototype certificate with the data provided + in the first four parameters and sends it via email to the CA + specified in \c ca_address. +*/ +bool requestDecentralCertificate( const char* name, const char* + email, const char* organization, const char* department, + const char* ca_address ); + +/*! \ingroup groupCertAct + \brief Requests a certificate in a PSE from the CA + specified in \c ca_address. +*/ +bool requestCentralCertificateAndPSE( const char* name, + const char* email, const char* organization, const char* department, + const char* ca_address ); + +/*! \ingroup groupCertAct + \brief Creates a local PSE. +*/ +bool createPSE( void ); + +/*! \ingroup groupCertAct + \brief Parses and adds a certificate returned by a CA upon + request with + \c requestDecentralCertificate() or + \c requestCentralCertificate(). + + If the certificate was requested with + \c requestCentralCertificate(), the + certificate returned will come complete with a PSE which is + also registered with this method. +*/ +bool registerCertificate( const char* ); + +/*! \ingroup groupCertAct + \brief Requests the prolongation of the certificate + \c certificate from the CA + \c ca_address. +*/ +bool requestCertificateProlongation( const char* + certificate, const char* ca_address ); + +/*! \ingroup groupCertAct + \brief Returns an HTML 2-formatted string that describes the + certificate chain of the user's certificate. + + Data displayed is at least the issuer of the certificate, the serial number + of the certificate, the owner of the certificate, the checksum + of the certificate, the validity duration of the certificate, + the usage of the certificate, and the contained email + addresses, if any. +*/ +const char* certificateChain( void ); + +/*! \ingroup groupCertAct + \brief Deletes the specified user certificate from the current + PSE. +*/ +bool deleteCertificate( const char* certificate ); + +/*! \ingroup groupCertAct + \brief Archives the specified user certificate in the current PSE. + + The certificate cannot be used any longer after this + operation unless it is unarchived. +*/ +bool archiveCertificate( const char* certificate ); + + +/*! \ingroup groupCRLAct + \brief Returns a HTML 2-formatted string that describes the + CRL, suitable for display in the MUA. +*/ +const char* displayCRL( void ); + +/*! \ingroup groupCRLAct + \brief Manually update the CRL. CRLs will also be automatically + updated on demand by the backend. + + If there is a local version of a CRL saved, it will be overwritten + with the new CRL from the CA. +*/ +void updateCRL( void ); + +#ifdef __cplusplus +} +#endif +#endif /*CRYPTPLUG_H*/ + diff --git a/tags/V0-3-4/gpgmeplug/gpgme-openpgp.c b/tags/V0-3-4/gpgmeplug/gpgme-openpgp.c new file mode 100644 index 0000000..dce22be --- /dev/null +++ b/tags/V0-3-4/gpgmeplug/gpgme-openpgp.c @@ -0,0 +1,37 @@ +#define GPGMEPLUG_PROTOCOL GPGME_PROTOCOL_OpenPGP + +#define GPGMEPLUG_SIGN_INCLUDE_CLEARTEXT true +#define GPGMEPLUG_SIGN_MAKE_MIME_OBJECT true +#define GPGMEPLUG_SIGN_MAKE_MULTI_MIME true +#define GPGMEPLUG_SIGN_CTYPE_MAIN "multipart/signed;protocol=application/pgp-signature;micalg=pgp-sha1" +#define GPGMEPLUG_SIGN_CDISP_MAIN "" +#define GPGMEPLUG_SIGN_CTENC_MAIN "" +#define GPGMEPLUG_SIGN_CTYPE_VERSION "" +#define GPGMEPLUG_SIGN_CDISP_VERSION "" +#define GPGMEPLUG_SIGN_CTENC_VERSION "" +#define GPGMEPLUG_SIGN_BTEXT_VERSION "" +#define GPGMEPLUG_SIGN_CTYPE_CODE "application/pgp-signature" +#define GPGMEPLUG_SIGN_CDISP_CODE "" +#define GPGMEPLUG_SIGN_CTENC_CODE "" +#define GPGMEPLUG_SIGN_FLAT_PREFIX "" +#define GPGMEPLUG_SIGN_FLAT_SEPARATOR "" +#define GPGMEPLUG_SIGN_FLAT_POSTFIX "" + +#define GPGMEPLUG_ENC_INCLUDE_CLEARTEXT false +#define GPGMEPLUG_ENC_MAKE_MIME_OBJECT true +#define GPGMEPLUG_ENC_MAKE_MULTI_MIME true +#define GPGMEPLUG_ENC_CTYPE_MAIN "multipart/encrypted; protocol=application/pgp-encrypted" +#define GPGMEPLUG_ENC_CDISP_MAIN "" +#define GPGMEPLUG_ENC_CTENC_MAIN "" +#define GPGMEPLUG_ENC_CTYPE_VERSION "application/pgp-encrypted" +#define GPGMEPLUG_ENC_CDISP_VERSION "attachment" +#define GPGMEPLUG_ENC_CTENC_VERSION "" +#define GPGMEPLUG_ENC_BTEXT_VERSION "Version: 1" +#define GPGMEPLUG_ENC_CTYPE_CODE "application/octet-stream" +#define GPGMEPLUG_ENC_CDISP_CODE "inline; filename=\"msg.asc\"" +#define GPGMEPLUG_ENC_CTENC_CODE "" +#define GPGMEPLUG_ENC_FLAT_PREFIX "" +#define GPGMEPLUG_ENC_FLAT_SEPARATOR "" +#define GPGMEPLUG_ENC_FLAT_POSTFIX "" + +#include "gpgmeplug.c" diff --git a/tags/V0-3-4/gpgmeplug/gpgme-smime.c b/tags/V0-3-4/gpgmeplug/gpgme-smime.c new file mode 100644 index 0000000..088c8d5 --- /dev/null +++ b/tags/V0-3-4/gpgmeplug/gpgme-smime.c @@ -0,0 +1,37 @@ +#define GPGMEPLUG_PROTOCOL GPGME_PROTOCOL_CMS + +#define GPGMEPLUG_SIGN_INCLUDE_CLEARTEXT true +#define GPGMEPLUG_SIGN_MAKE_MIME_OBJECT true +#define GPGMEPLUG_SIGN_MAKE_MULTI_MIME true +#define GPGMEPLUG_SIGN_CTYPE_MAIN "multipart/signed; protocol=application/pkcs7-signature; micalg=pgp-sha1" +#define GPGMEPLUG_SIGN_CDISP_MAIN "" +#define GPGMEPLUG_SIGN_CTENC_MAIN "" +#define GPGMEPLUG_SIGN_CTYPE_VERSION "" +#define GPGMEPLUG_SIGN_CDISP_VERSION "" +#define GPGMEPLUG_SIGN_CTENC_VERSION "" +#define GPGMEPLUG_SIGN_BTEXT_VERSION "" +#define GPGMEPLUG_SIGN_CTYPE_CODE "application/pkcs7-signature; name=\"smime.p7s\"" +#define GPGMEPLUG_SIGN_CDISP_CODE "attachment; filename=\"smime.p7s\"" +#define GPGMEPLUG_SIGN_CTENC_CODE "base64" +#define GPGMEPLUG_SIGN_FLAT_PREFIX "" +#define GPGMEPLUG_SIGN_FLAT_SEPARATOR "" +#define GPGMEPLUG_SIGN_FLAT_POSTFIX "" + +#define GPGMEPLUG_ENC_INCLUDE_CLEARTEXT false +#define GPGMEPLUG_ENC_MAKE_MIME_OBJECT true +#define GPGMEPLUG_ENC_MAKE_MULTI_MIME false +#define GPGMEPLUG_ENC_CTYPE_MAIN "application/pkcs7-mime; smime-type=enveloped-data; name=\"smime.p7m\"" +#define GPGMEPLUG_ENC_CDISP_MAIN "attachment; filename=\"smime.p7m\"" +#define GPGMEPLUG_ENC_CTENC_MAIN "base64" +#define GPGMEPLUG_ENC_CTYPE_VERSION "" +#define GPGMEPLUG_ENC_CDISP_VERSION "" +#define GPGMEPLUG_ENC_CTENC_VERSION "" +#define GPGMEPLUG_ENC_BTEXT_VERSION "" +#define GPGMEPLUG_ENC_CTYPE_CODE "" +#define GPGMEPLUG_ENC_CDISP_CODE "" +#define GPGMEPLUG_ENC_CTENC_CODE "" +#define GPGMEPLUG_ENC_FLAT_PREFIX "" +#define GPGMEPLUG_ENC_FLAT_SEPARATOR "" +#define GPGMEPLUG_ENC_FLAT_POSTFIX "" + +#include "gpgmeplug.c" diff --git a/tags/V0-3-4/gpgmeplug/gpgmeplug.c b/tags/V0-3-4/gpgmeplug/gpgmeplug.c new file mode 100644 index 0000000..0de5d49 --- /dev/null +++ b/tags/V0-3-4/gpgmeplug/gpgmeplug.c @@ -0,0 +1,1296 @@ +/* -*- Mode: C -*- + + $Id$ + + GPGMEPLUG - an GPGME based cryptography plug-in following + the common CRYPTPLUG specification. + + Copyright (C) 2001 by Klarälvdalens Datakonsult AB + + GPGMEPLUG is free software; you can redistribute it and/or modify + it under the terms of GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + GPGMEPLUG is distributed in the hope that it will be useful, + it under the terms of GNU General Public License as published by + the Free Software Foundation; version 2 of the License + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA +*/ + + + +/*! \file gpgmeplug.c + \brief GPGME implementation of CRYPTPLUG following the + specification located in common API header cryptplug.h. + + CRYPTPLUG is an independent cryptography plug-in API + developed for Sphinx-enabeling KMail and Mutt. + + CRYPTPLUG was designed for the Aegypten project, but it may + be used by 3rd party developers as well to design pluggable + crypto backends for the above mentioned MUAs. + + \note All string parameters appearing in this API are to be + interpreted as UTF-8 encoded. + + \see cryptplug.h +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include +#include +#include + +#ifndef BUG_URL +#define BUG_URL "http:://www.gnupg.org/aegypten/" +#endif + +#include "gpgme.h" +#ifndef GPGMEPLUG_PROTOCOL +#define GPGMEPLUG_PROTOCOL GPGME_PROTOCOL_OpenPGP +#endif + +// definitions for signing +#ifndef GPGMEPLUG_SIGN_MAKE_MIME_OBJECT +#define GPGMEPLUG_SIGN_INCLUDE_CLEARTEXT true +#define GPGMEPLUG_SIGN_MAKE_MIME_OBJECT true +#define GPGMEPLUG_SIGN_MAKE_MULTI_MIME true +#define GPGMEPLUG_SIGN_CTYPE_MAIN "multipart/signed;protocol=application/pgp-signature;micalg=pgp-sha1" +#define GPGMEPLUG_SIGN_CDISP_MAIN "" +#define GPGMEPLUG_SIGN_CTENC_MAIN "" +#define GPGMEPLUG_SIGN_CTYPE_VERSION "" +#define GPGMEPLUG_SIGN_CDISP_VERSION "" +#define GPGMEPLUG_SIGN_CTENC_VERSION "" +#define GPGMEPLUG_SIGN_BTEXT_VERSION "" +#define GPGMEPLUG_SIGN_CTYPE_CODE "application/pgp-signature" +#define GPGMEPLUG_SIGN_CDISP_CODE "" +#define GPGMEPLUG_SIGN_CTENC_CODE "" +#define GPGMEPLUG_SIGN_FLAT_PREFIX "" +#define GPGMEPLUG_SIGN_FLAT_SEPARATOR "" +#define GPGMEPLUG_SIGN_FLAT_POSTFIX "" +#endif +// definitions for encoding +#ifndef GPGMEPLUG_ENC_MAKE_MIME_OBJECT +#define GPGMEPLUG_ENC_INCLUDE_CLEARTEXT false +#define GPGMEPLUG_ENC_MAKE_MIME_OBJECT true +#define GPGMEPLUG_ENC_MAKE_MULTI_MIME true +#define GPGMEPLUG_ENC_CTYPE_MAIN "multipart/encrypted; protocol=application/pgp-encrypted" +#define GPGMEPLUG_ENC_CDISP_MAIN "" +#define GPGMEPLUG_ENC_CTENC_MAIN "" +#define GPGMEPLUG_ENC_CTYPE_VERSION "application/pgp-encrypted" +#define GPGMEPLUG_ENC_CDISP_VERSION "attachment" +#define GPGMEPLUG_ENC_CTENC_VERSION "" +#define GPGMEPLUG_ENC_BTEXT_VERSION "Version: 1" +#define GPGMEPLUG_ENC_CTYPE_CODE "application/octet-stream" +#define GPGMEPLUG_ENC_CDISP_CODE "inline; filename=\"msg.asc\"" +#define GPGMEPLUG_ENC_CTENC_CODE "" +#define GPGMEPLUG_ENC_FLAT_PREFIX "" +#define GPGMEPLUG_ENC_FLAT_SEPARATOR "" +#define GPGMEPLUG_ENC_FLAT_POSTFIX "" +#endif +// Note: The following specification will result in +// function encryptAndSignMessage() producing +// _empty_ mails. +// This must be changed as soon as our plugin +// is supporting the encryptAndSignMessage() function. +#ifndef GPGMEPLUG_ENCSIGN_MAKE_MIME_OBJECT +#define GPGMEPLUG_ENCSIGN_INCLUDE_CLEARTEXT false +#define GPGMEPLUG_ENCSIGN_MAKE_MIME_OBJECT false +#define GPGMEPLUG_ENCSIGN_MAKE_MULTI_MIME false +#define GPGMEPLUG_ENCSIGN_CTYPE_MAIN "" +#define GPGMEPLUG_ENCSIGN_CDISP_MAIN "" +#define GPGMEPLUG_ENCSIGN_CTENC_MAIN "" +#define GPGMEPLUG_ENCSIGN_CTYPE_VERSION "" +#define GPGMEPLUG_ENCSIGN_CDISP_VERSION "" +#define GPGMEPLUG_ENCSIGN_CTENC_VERSION "" +#define GPGMEPLUG_ENCSIGN_BTEXT_VERSION "" +#define GPGMEPLUG_ENCSIGN_CTYPE_CODE "" +#define GPGMEPLUG_ENCSIGN_CDISP_CODE "" +#define GPGMEPLUG_ENCSIGN_CTENC_CODE "" +#define GPGMEPLUG_ENCSIGN_FLAT_PREFIX "" +#define GPGMEPLUG_ENCSIGN_FLAT_SEPARATOR "" +#define GPGMEPLUG_ENCSIGN_FLAT_POSTFIX "" +#endif + +#include "cryptplug.h" + + +typedef struct { + const char* bugURL; + const char* signatureKeyCertificate; + SignatureAlgorithm signatureAlgorithm; + SendCertificates sendCertificates; + SignEmail signEmail; + bool saveSentSignatures; + bool warnNoCertificate; + PinRequests numPINRequests; + bool checkSignatureCertificatePathToRoot; + bool signatureUseCRLs; + EncryptionAlgorithm encryptionAlgorithm; + EncryptEmail encryptEmail; + bool saveMessagesEncrypted; + bool checkEncryptionCertificatePathToRoot; + bool encryptionUseCRLs; + bool encryptionCRLExpiryNearWarning; + int encryptionCRLNearExpiryInterval; + struct DirectoryServer *directoryServers; + unsigned int numDirectoryServers; + CertificateSource certificateSource; + CertificateSource cRLSource; + bool warnSendUnsigned; + int numPINRequestsInterval; + bool signatureCertificateExpiryNearWarning; + int signatureCertificateExpiryNearInterval; + bool cACertificateExpiryNearWarning; + int cACertificateExpiryNearInterval; + bool rootCertificateExpiryNearWarning; + int rootCertificateExpiryNearInterval; + bool warnSendUnencrypted; + bool checkCertificatePath; + bool receiverCertificateExpiryNearWarning; + int receiverCertificateExpiryNearWarningInterval; + bool certificateInChainExpiryNearWarning; + int certificateInChainExpiryNearWarningInterval; + bool receiverEmailAddressNotInCertificateWarning; +} Config; + + +Config config; + +#define NEAR_EXPIRY 14 + +bool initialize() +{ + config.bugURL = malloc( strlen( BUG_URL ) + 1 ); + strcpy( (char* )config.bugURL, BUG_URL ); + config.signatureKeyCertificate = malloc( 1 ); + strcpy( (char* )config.signatureKeyCertificate, "" ); + config.signatureAlgorithm = SignAlg_SHA1; + config.sendCertificates = SendCert_SendChainWithRoot; + config.signEmail = SignEmail_SignAll; + config.saveSentSignatures = true; + config.warnNoCertificate = true; + config.numPINRequests = PinRequest_Always; + config.checkSignatureCertificatePathToRoot = true; + config.signatureUseCRLs = true; + config.encryptionAlgorithm = EncryptAlg_RSA; + config.encryptEmail = EncryptEmail_Ask; + config.saveMessagesEncrypted = true; + config.checkEncryptionCertificatePathToRoot = true; + config.encryptionUseCRLs = true; + config.encryptionCRLExpiryNearWarning = true; + config.encryptionCRLNearExpiryInterval = NEAR_EXPIRY; + config.directoryServers = NULL; + config.numDirectoryServers = 0; + config.certificateSource = CertSrc_Server; + config.cRLSource = CertSrc_Server; + config.warnSendUnsigned = true; + config.numPINRequestsInterval = NEAR_EXPIRY; + config.signatureCertificateExpiryNearWarning = true; + config.signatureCertificateExpiryNearInterval = NEAR_EXPIRY; + config.cACertificateExpiryNearWarning = true; + config.cACertificateExpiryNearInterval = NEAR_EXPIRY; + config.rootCertificateExpiryNearWarning = true; + config.rootCertificateExpiryNearInterval = NEAR_EXPIRY; + config.warnSendUnencrypted = false; + config.checkCertificatePath = true; + config.receiverCertificateExpiryNearWarning = true; + config.receiverCertificateExpiryNearWarningInterval = NEAR_EXPIRY; + config.certificateInChainExpiryNearWarning = true; + config.certificateInChainExpiryNearWarningInterval = NEAR_EXPIRY; + config.receiverEmailAddressNotInCertificateWarning = true; + + return true; +}; + + +void deinitialize() +{ + unsigned int i; + for( i = 0; i < config.numDirectoryServers; ++i ) { + free( (char *)config.directoryServers[i].servername ); + free( (char *)config.directoryServers[i].description ); + } + free( config.directoryServers ); +} + + +bool hasFeature( Feature flag ) +{ + switch ( flag ) { + case CryptPlugFeat_SignMessages: return true; + case CryptPlugFeat_VerifySignatures: return true; + case CryptPlugFeat_EncryptMessages: return true; + case CryptPlugFeat_DecryptMessages: return true; + // undefined or not yet implemented: + case CryptPlugFeat_undef: return false; + default: return false; + } +} + + +const char* bugURL(){ return config.bugURL; } + + +void unsafeStationery( void** pixmap, const char** menutext, char* accel, + const char** tooltip, const char** statusbartext ){} + +void signedStationery( void** pixmap, const char** menutext, char* accel, + const char** tooltip, const char** statusbartext ){} + +void encryptedStationery( void** pixmap, const char** + menutext, char* accel, + const char** tooltip, const char** statusbartext ){} + +void signedEncryptedStationery( void** pixmap, const char** + menutext, char* accel, + const char** tooltip, const char** statusbartext ){} + +const char* signatureConfigurationDialog(){ return 0; } + +const char* signatureKeySelectionDialog(){ return 0; } + +const char* signatureAlgorithmDialog(){ return 0; } + +const char* signatureHandlingDialog(){ return 0; } + +void setSignatureKeyCertificate( const char* certificate ) +{ + config.signatureKeyCertificate = certificate; +} + +const char* signatureKeyCertificate() +{ + return config.signatureKeyCertificate; +} + +void setSignatureAlgorithm( SignatureAlgorithm sigAlg ) +{ + config.signatureAlgorithm = sigAlg; +} + +SignatureAlgorithm signatureAlgorithm() +{ + return config.signatureAlgorithm; +} + +void setSendCertificates( SendCertificates sendCert ) +{ + config.sendCertificates = sendCert; +} + +SendCertificates sendCertificates() +{ + return config.sendCertificates; +} + +void setSignEmail( SignEmail signMail ) +{ + config.signEmail = signMail; +} + +SignEmail signEmail() +{ + return config.signEmail; +} + + + + + +void setWarnSendUnsigned( bool flag ) +{ + config.warnSendUnsigned = flag; +} + +bool warnSendUnsigned() +{ + return config.warnSendUnsigned; +} + + + + + + +void setSaveSentSignatures( bool flag ) +{ + config.saveSentSignatures = flag; +} + +bool saveSentSignatures() +{ + return config.saveSentSignatures; +} + +void setWarnNoCertificate( bool flag ) +{ + config.warnNoCertificate = flag; +} + +bool warnNoCertificate() +{ + return config.warnNoCertificate; +} + + +bool isEmailInCertificate( const char* email, const char* certificate ) +{ + /* PENDING(g10) this function should return true if the email + address passed as the first parameter is contained in the + certificate passed as the second parameter, and false + otherwise. This is used to alert the user if his own email + address is not contained in the certificate he uses for + signing. + Note that the parameter email can be anything that is allowed + in a From: line. + Another note: OK, OK, we'll handle that in the MUA. You can + assume that you only get the email address. + */ + return false; // dummy +} + + +void setNumPINRequests( PinRequests reqMode ) +{ + config.numPINRequests = reqMode; + + /* PENDING(g10) Put this value into gpg and make it ask for the pin + according to this. Note that there is also + setNumPINRequestsInterval() which is only used if reqMode == + PinRequest_AfterMinutes. + */ +} + +PinRequests numPINRequests() +{ + return config.numPINRequests; +} + + + +void setNumPINRequestsInterval( int interval ) +{ + config.numPINRequestsInterval = interval; + + /* PENDING(g10) Put this value into gpg and make it ask for the pin + according to this. Note that this should only be used if + config.numPINRequests (set with setNumPINRequests()) has the + value PinRequest_AfterMinutes. + */ +} + +int numPINRequestsInterval() +{ + return config.numPINRequestsInterval; +} + + + +void setCheckSignatureCertificatePathToRoot( bool flag ) +{ + config.checkSignatureCertificatePathToRoot = flag; +} + +bool checkSignatureCertificatePathToRoot() +{ + return config.checkSignatureCertificatePathToRoot; +} + +void setSignatureUseCRLs( bool flag ) +{ + config.signatureUseCRLs = flag; +} + +bool signatureUseCRLs() +{ + return config.signatureUseCRLs; +} + + + + + + +void setSignatureCertificateExpiryNearWarning( bool flag ) +{ + config.signatureCertificateExpiryNearWarning = flag; +} + +bool signatureCertificateExpiryNearWarning( void ) +{ + return config.signatureCertificateExpiryNearWarning; +} + + +int signatureCertificateDaysLeftToExpiry( const char* certificate ) +{ + /* PENDING(g10) + Please return the number of days that are left until the + certificate specified in the parameter certificate expires. + */ + return 10; // dummy that triggers a warning in the MUA +} + + +void setSignatureCertificateExpiryNearInterval( int interval ) +{ + config.signatureCertificateExpiryNearInterval = interval; +} + +int signatureCertificateExpiryNearInterval( void ) +{ + return config.signatureCertificateExpiryNearInterval; +} + +void setCACertificateExpiryNearWarning( bool flag ) +{ + config.cACertificateExpiryNearWarning = flag; +} + +bool caCertificateExpiryNearWarning( void ) +{ + return config.cACertificateExpiryNearWarning; +} + +int caCertificateDaysLeftToExpiry( const char* certificate ) +{ + /* PENDING(g10) + Please return the number of days that are left until the + CA certificate for the certificate specified in the parameter + certificate expires. + */ + return 10; // dummy that triggers a warning in the MUA +} + +void setCACertificateExpiryNearInterval( int interval ) +{ + config.cACertificateExpiryNearInterval = interval; +} + +int caCertificateExpiryNearInterval( void ) +{ + return config.cACertificateExpiryNearInterval; +} + +void setRootCertificateExpiryNearWarning( bool flag ) +{ + config.rootCertificateExpiryNearWarning = flag; +} + +bool rootCertificateExpiryNearWarning( void ) +{ + return config.rootCertificateExpiryNearWarning; +} + +int rootCertificateDaysLeftToExpiry( const char* certificate ) +{ + /* PENDING(g10) + Please return the number of days that are left until the + root certificate for the certificate specified in the parameter + certificate expires. + */ + return 10; // dummy that triggers a warning in the MUA +} + + +void setRootCertificateExpiryNearInterval( int interval ) +{ + config.rootCertificateExpiryNearInterval = interval; +} + +int rootCertificateExpiryNearInterval( void ) +{ + return config.rootCertificateExpiryNearInterval; +} + + + + + + + + +const char* encryptionConfigurationDialog(){ return 0; } + +const char* encryptionAlgorithmDialog(){ return 0; } + +const char* encryptionHandlingDialog(){ return 0; } + +const char* encryptionReceiverDialog(){ return 0; } + +void setEncryptionAlgorithm( EncryptionAlgorithm cryptAlg ) +{ + config.encryptionAlgorithm = cryptAlg; +} + +EncryptionAlgorithm encryptionAlgorithm() +{ + return config.encryptionAlgorithm; +} + +void setEncryptEmail( EncryptEmail cryptMode ) +{ + config.encryptEmail = cryptMode; +} + +EncryptEmail encryptEmail() +{ + return config.encryptEmail; +} + + + + + + +void setWarnSendUnencrypted( bool flag ) +{ + config.warnSendUnencrypted = flag; +} + +bool warnSendUnencrypted() +{ + return config.warnSendUnencrypted; +} + + + + + + + + + +void setSaveMessagesEncrypted( bool flag ) +{ + config.saveMessagesEncrypted = flag; +} + +bool saveMessagesEncrypted() +{ + return config.saveMessagesEncrypted; +} + + + + + + + +void setCheckCertificatePath( bool flag ) +{ + config.checkCertificatePath = flag; +} + +bool checkCertificatePath() +{ + return config.checkCertificatePath; +} + + + + + + + + +void setCheckEncryptionCertificatePathToRoot( bool flag ) +{ + config.checkEncryptionCertificatePathToRoot = flag; +} + +bool checkEncryptionCertificatePathToRoot() +{ + return config.checkEncryptionCertificatePathToRoot; +} + + + + + + + +void setReceiverCertificateExpiryNearWarning( bool flag ) +{ + config.receiverCertificateExpiryNearWarning = flag; +} + +bool receiverCertificateExpiryNearWarning() +{ + return config.receiverCertificateExpiryNearWarning; +} + +void setReceiverCertificateExpiryNearWarningInterval( int interval ) +{ + config.receiverCertificateExpiryNearWarningInterval = interval; +} + +int receiverCertificateExpiryNearWarningInterval() +{ + return config.receiverCertificateExpiryNearWarningInterval; +} + +void setCertificateInChainExpiryNearWarning( bool flag ) +{ + config.certificateInChainExpiryNearWarning = flag; +} + +bool certificateInChainExpiryNearWarning() +{ + return config.certificateInChainExpiryNearWarning; +} + +void setCertificateInChainExpiryNearWarningInterval( int interval ) +{ + config.certificateInChainExpiryNearWarningInterval = interval; +} + +int certificateInChainExpiryNearWarningInterval() +{ + return config.certificateInChainExpiryNearWarningInterval; +} + +void setReceiverEmailAddressNotInCertificateWarning( bool flag ) +{ + config.receiverEmailAddressNotInCertificateWarning = flag; +} + +bool receiverEmailAddressNotInCertificateWarning() +{ + return config.receiverEmailAddressNotInCertificateWarning; +} + + + + + + + + +void setEncryptionUseCRLs( bool flag ) +{ + config.encryptionUseCRLs = flag; + + /* PENDING(g10) Store this setting in gpgme and use it. If true, + every certificate used for encryption should be checked against + applicable CRLs. + */ +} + +bool encryptionUseCRLs() +{ + return config.encryptionUseCRLs; +} + + +int encryptionCRLsDaysLeftToExpiry() +{ + /* PENDING(g10) + Please return the number of days that are left until the + CRL used for encryption expires. + */ + return 10; // dummy that triggers a warning in the MUA +} + +void setEncryptionCRLExpiryNearWarning( bool flag ) +{ + config.encryptionCRLExpiryNearWarning = flag; +} + +bool encryptionCRLExpiryNearWarning() +{ + return config.encryptionCRLExpiryNearWarning; +} + +void setEncryptionCRLNearExpiryInterval( int interval ) +{ + config.encryptionCRLNearExpiryInterval = interval; +} + +int encryptionCRLNearExpiryInterval() +{ + return config.encryptionCRLNearExpiryInterval; +} + + +const char* directoryServiceConfigurationDialog(){ return 0; } + +void appendDirectoryServer( const char* servername, + int port, + const char* description ) +{ + struct DirectoryServer *newServers = NULL; + newServers = realloc( config.directoryServers, + (1+config.numDirectoryServers) * sizeof *newServers ); + if( newServers ) { + config.directoryServers = newServers; + newServers[ config.numDirectoryServers ].servername = + malloc( 1+strlen( servername ) ); + if( newServers[ config.numDirectoryServers ].servername ) { + strcpy( (char *)newServers[ config.numDirectoryServers ].servername, + servername ); + newServers[ config.numDirectoryServers ].description = + malloc( 1+strlen( description ) ); + if( newServers[ config.numDirectoryServers ].description ) { + strcpy( (char *)newServers[ config.numDirectoryServers ].description, + description ); + newServers[ config.numDirectoryServers ].port = port; + config.numDirectoryServers += 1; + } + } + } +} + +void setDirectoryServers( struct DirectoryServer server[], unsigned int size ) +{ + unsigned int i; + int oldSize = config.numDirectoryServers; + struct DirectoryServer *newServers = NULL; + newServers = calloc ( size, sizeof *newServers ); + if( newServers ) { + for( i=0; i < oldSize; ++i ) { + free( (char *)config.directoryServers[i].servername ); + free( (char *)config.directoryServers[i].description ); + } + free( config.directoryServers ); + for( i=0; i < size; ++i ) { + newServers[ i ].servername = malloc( 1+strlen( server[i].servername ) ); + if( newServers[ i ].servername ) { + strcpy( (char *)newServers[ i ].servername, server[i].servername ); + newServers[ i ].description = malloc( 1+strlen( server[i].description ) ); + if( newServers[ i ].description ) { + strcpy( (char *)newServers[ i ].description, server[i].description ); + newServers[ i ].port = server[i].port; + } + } + } + config.directoryServers = newServers; + config.numDirectoryServers = size; + } +} + +struct DirectoryServer * directoryServers( int* numServers ) +{ + if( numServers ) + *numServers = config.numDirectoryServers; + return config.directoryServers; +}; + +void setCertificateSource( CertificateSource source ) +{ + config.certificateSource = source; +} + +CertificateSource certificateSource() +{ + return config.certificateSource; +} + +void setCRLSource( CertificateSource source ) +{ + config.cRLSource = source; +} + +CertificateSource crlSource() +{ + return config.cRLSource; +} + + +bool certificateValidity( const char* certificate, + int* level ){ return true; } + + +void storeNewCharPtr( char** dest, const char* src ) +{ + int sLen = strlen( src ); + *dest = malloc( sLen + 1 ); + strcpy( *dest, src ); + (*dest)[sLen] = '\0'; +} + + +bool signMessage( const char* cleartext, + const char** ciphertext, + const char* certificate, + struct StructuringInfo* structuring ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData data, sig; + size_t rSLen = 0; + char* rSig = 0; + bool bOk = false; + int sendCerts = 1; + + init_StructuringInfo( structuring ); + + if( !ciphertext ) + return false; + + err = gpgme_new (&ctx); + gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL); + + gpgme_set_armor (ctx, 1); + gpgme_set_textmode (ctx, 1); + + switch ( config.sendCertificates ) { + case SendCert_undef: + break; + case SendCert_DontSend: + sendCerts = 0; + break; + case SendCert_SendOwn: + sendCerts = 1; + break; + case SendCert_SendChainWithoutRoot: + sendCerts = -2; + break; + case SendCert_SendChainWithRoot: + sendCerts = -1; + break; + default: + sendCerts = 0; + break; + } + gpgme_set_include_certs (ctx, sendCerts); + + // PENDING(g10) Implement this + //gpgme_set_signature_algorithm( ctx, config.signatureAlgorithm ); + + gpgme_data_new_from_mem (&data, cleartext, + 1+strlen( cleartext ), 1 ); + gpgme_data_new ( &sig ); + err = gpgme_op_sign (ctx, data, sig, GPGME_SIG_MODE_DETACH ); + + if (!err) { + rSig = gpgme_data_release_and_get_mem( sig, &rSLen ); + *ciphertext = malloc( rSLen + 1 ); + if( *ciphertext ) { + if( rSLen ) { + bOk = true; + strncpy((char*)*ciphertext, rSig, rSLen ); + } + ((char*)(*ciphertext))[rSLen] = '\0'; + } + free( rSig ); + } + else { + gpgme_data_release( sig ); + *ciphertext = 0; + // hier fehlt eine Fehlerbehandlung, falls das + // Signieren schiefging + } + gpgme_data_release( data ); + gpgme_release (ctx); + + if( bOk && structuring ) { + structuring->includeCleartext = GPGMEPLUG_SIGN_INCLUDE_CLEARTEXT; + structuring->makeMimeObject = GPGMEPLUG_SIGN_MAKE_MIME_OBJECT; + if( structuring->makeMimeObject ) { + structuring->makeMultiMime = GPGMEPLUG_SIGN_MAKE_MULTI_MIME; + storeNewCharPtr( &structuring->contentTypeMain, + GPGMEPLUG_SIGN_CTYPE_MAIN ); + storeNewCharPtr( &structuring->contentDispMain, + GPGMEPLUG_SIGN_CDISP_MAIN ); + storeNewCharPtr( &structuring->contentTEncMain, + GPGMEPLUG_SIGN_CTENC_MAIN ); + if( structuring->makeMultiMime ) { + storeNewCharPtr( &structuring->contentTypeVersion, + GPGMEPLUG_SIGN_CTYPE_VERSION ); + storeNewCharPtr( &structuring->contentDispVersion, + GPGMEPLUG_SIGN_CDISP_VERSION ); + storeNewCharPtr( &structuring->contentTEncVersion, + GPGMEPLUG_SIGN_CTENC_VERSION ); + storeNewCharPtr( &structuring->bodyTextVersion, + GPGMEPLUG_SIGN_BTEXT_VERSION ); + storeNewCharPtr( &structuring->contentTypeCode, + GPGMEPLUG_SIGN_CTYPE_CODE ); + storeNewCharPtr( &structuring->contentDispCode, + GPGMEPLUG_SIGN_CDISP_CODE ); + storeNewCharPtr( &structuring->contentTEncCode, + GPGMEPLUG_SIGN_CTENC_CODE ); + } + } else { + storeNewCharPtr( &structuring->flatTextPrefix, + GPGMEPLUG_SIGN_FLAT_PREFIX ); + storeNewCharPtr( &structuring->flatTextSeparator, + GPGMEPLUG_SIGN_FLAT_SEPARATOR ); + storeNewCharPtr( &structuring->flatTextPostfix, + GPGMEPLUG_SIGN_FLAT_POSTFIX ); + } + } + return bOk; +} + + +static const char* +sig_status_to_string( GpgmeSigStat status ) +{ + const char *result; + + switch (status) { + case GPGME_SIG_STAT_NONE: + result = "Oops: Signature not verified"; + break; + case GPGME_SIG_STAT_NOSIG: + result = "No signature found"; + break; + case GPGME_SIG_STAT_GOOD: + result = "Good signature"; + break; + case GPGME_SIG_STAT_BAD: + result = "BAD signature"; + break; + case GPGME_SIG_STAT_NOKEY: + result = "No public key to verify the signature"; + break; + case GPGME_SIG_STAT_ERROR: + result = "Error verifying the signature"; + break; + case GPGME_SIG_STAT_DIFF: + result = "Different results for signatures"; + break; + default: + result = "Error: Unknown status"; + break; + } + + return result; +} + + +bool checkMessageSignature( const char* ciphertext, + const char* signaturetext, + struct SignatureMetaData* sigmeta ) +{ + GpgmeCtx ctx; + GpgmeSigStat status; + GpgmeData datapart, sigpart; + GpgmeError err; + GpgmeKey key; + time_t created; + int sig_idx = 0; + const char* statusStr; + const char* fpr; + + gpgme_new( &ctx ); + gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL); + gpgme_data_new_from_mem( &datapart, ciphertext, + 1+strlen( ciphertext ), 1 ); + gpgme_data_new_from_mem( &sigpart, signaturetext, + 1+strlen( signaturetext ), 1 ); + + gpgme_op_verify( ctx, sigpart, datapart, &status ); + gpgme_data_release( datapart ); + gpgme_data_release( sigpart ); + + /* Provide information in the sigmeta struct */ + /* the status string */ + statusStr = sig_status_to_string( status ); + sigmeta->status = malloc( strlen( statusStr ) + 1 ); + if( sigmeta->status ) { + strcpy( sigmeta->status, statusStr ); + sigmeta->status[strlen( statusStr )] = '\0'; + } else + ; // nothing to do, is already 0 + + // Extended information for any number of signatures. + fpr = gpgme_get_sig_status( ctx, sig_idx, &status, &created ); + sigmeta->extended_info = 0; + while( fpr != NULL ) { + struct tm* ctime_val; + const char* sig_status; + + void* realloc_return = realloc( sigmeta->extended_info, + sizeof( struct SignatureMetaDataExtendedInfo ) * ( sig_idx + 1 ) ); + if( realloc_return ) { + sigmeta->extended_info = realloc_return; + // the creation time + sigmeta->extended_info[sig_idx].creation_time = malloc( sizeof( struct tm ) ); + if( sigmeta->extended_info[sig_idx].creation_time ) { + ctime_val = localtime( &created ); + memcpy( sigmeta->extended_info[sig_idx].creation_time, + ctime_val, sizeof( struct tm ) ); + } + + err = gpgme_get_sig_key (ctx, sig_idx, &key); + sig_status = sig_status_to_string( status ); + sigmeta->extended_info[sig_idx].status_text = malloc( strlen( sig_status ) + 1 ); + if( sigmeta->extended_info[sig_idx].status_text ) { + strcpy( sigmeta->extended_info[sig_idx].status_text, + sig_status ); + sigmeta->extended_info[sig_idx].status_text[strlen( sig_status )] = '\0'; + } + + sigmeta->extended_info[sig_idx].fingerprint = malloc( strlen( fpr ) + 1 ); + if( sigmeta->extended_info[sig_idx].fingerprint ) { + strcpy( sigmeta->extended_info[sig_idx].fingerprint, fpr ); + sigmeta->extended_info[sig_idx].fingerprint[strlen( fpr )] = '\0'; + } + } else + break; // if allocation fails once, it isn't likely to + // succeed the next time either + + fpr = gpgme_get_sig_status (ctx, ++sig_idx, &status, &created); + } + sigmeta->extended_info_count = sig_idx; + sigmeta->nota_xml = gpgme_get_notation( ctx ); + sigmeta->status_code = status; + + gpgme_release( ctx ); + return ( status == GPGME_SIG_STAT_GOOD ); +} + +bool storeCertificatesFromMessage( + const char* ciphertext ){ return true; } + + +bool encryptMessage( const char* cleartext, + const char** ciphertext, + const char* addressee, + struct StructuringInfo* structuring ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData gCiphertext, gPlaintext; + GpgmeRecipients rset; + size_t rCLen = 0; + char* rCiph = 0; + bool bOk = false; + + init_StructuringInfo( structuring ); + + gpgme_new (&ctx); + gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL); + + gpgme_set_armor (ctx, 1); + gpgme_set_textmode (ctx, 1); + + gpgme_data_new_from_mem (&gPlaintext, cleartext, + 1+strlen( cleartext ), 1 ); + err = gpgme_data_new ( &gCiphertext ); + + gpgme_recipients_new (&rset); + + + if( GPGMEPLUG_PROTOCOL == GPGME_PROTOCOL_CMS ) + { + gpgme_recipients_add_name_with_validity (rset, + "/CN=test cert 1,OU=Aegypten Project,O=g10 Code GmbH,L=Düsseldorf,C=DE", + GPGME_VALIDITY_FULL ); + fputs( "\nGPGSMPLUG encryptMessage() using test key of Aegypten Project\n", stderr ); + } + else + { + gpgme_recipients_add_name (rset, addressee); + fprintf( stderr, "\nGPGMEPLUG encryptMessage() using addressee %s\n", addressee ); + } + + + err = gpgme_op_encrypt (ctx, rset, gPlaintext, gCiphertext ); + if( err ) + fprintf( stderr, "gpgme_op_encrypt() returned this error code: %i\n\n", err ); + + gpgme_recipients_release (rset); + gpgme_data_release (gPlaintext); + + if( !err ) { + rCiph = gpgme_data_release_and_get_mem( gCiphertext, &rCLen ); + *ciphertext = malloc( rCLen + 1 ); + if( *ciphertext ) { + if( rCLen ) { + bOk = true; + strncpy((char*)*ciphertext, rCiph, rCLen ); + } + ((char*)(*ciphertext))[rCLen] = 0; + } + free( rCiph ); + } + else { + gpgme_data_release ( gCiphertext ); + *ciphertext = 0; + // hier fehlt eine Fehlerbehandlung: fuer einen Recipient nur ein + // untrusted key (oder gar keiner) gefunden wurde, verweigert gpg + // das signieren. + } + + gpgme_release (ctx); + + fflush( stderr ); + + if( bOk && structuring ) { + structuring->includeCleartext = GPGMEPLUG_ENC_INCLUDE_CLEARTEXT; + structuring->makeMimeObject = GPGMEPLUG_ENC_MAKE_MIME_OBJECT; + if( structuring->makeMimeObject ) { + structuring->makeMultiMime = GPGMEPLUG_ENC_MAKE_MULTI_MIME; + storeNewCharPtr( &structuring->contentTypeMain, + GPGMEPLUG_ENC_CTYPE_MAIN ); + storeNewCharPtr( &structuring->contentDispMain, + GPGMEPLUG_ENC_CDISP_MAIN ); + storeNewCharPtr( &structuring->contentTEncMain, + GPGMEPLUG_ENC_CTENC_MAIN ); + if( structuring->makeMultiMime ) { + storeNewCharPtr( &structuring->contentTypeVersion, + GPGMEPLUG_ENC_CTYPE_VERSION ); + storeNewCharPtr( &structuring->contentDispVersion, + GPGMEPLUG_ENC_CDISP_VERSION ); + storeNewCharPtr( &structuring->contentTEncVersion, + GPGMEPLUG_ENC_CTENC_VERSION ); + storeNewCharPtr( &structuring->bodyTextVersion, + GPGMEPLUG_ENC_BTEXT_VERSION ); + storeNewCharPtr( &structuring->contentTypeCode, + GPGMEPLUG_ENC_CTYPE_CODE ); + storeNewCharPtr( &structuring->contentDispCode, + GPGMEPLUG_ENC_CDISP_CODE ); + storeNewCharPtr( &structuring->contentTEncCode, + GPGMEPLUG_ENC_CTENC_CODE ); + } + } else { + storeNewCharPtr( &structuring->flatTextPrefix, + GPGMEPLUG_ENC_FLAT_PREFIX ); + storeNewCharPtr( &structuring->flatTextSeparator, + GPGMEPLUG_ENC_FLAT_SEPARATOR ); + storeNewCharPtr( &structuring->flatTextPostfix, + GPGMEPLUG_ENC_FLAT_POSTFIX ); + } + } + return bOk; +} + + +bool encryptAndSignMessage( const char* cleartext, + const char** ciphertext, + const char* certificate, + struct StructuringInfo* structuring ) +{ + bool bOk; + + init_StructuringInfo( structuring ); + + bOk = false; + + // implementation of this function is still missing + + if( bOk && structuring ) { + structuring->includeCleartext = GPGMEPLUG_ENCSIGN_INCLUDE_CLEARTEXT; + structuring->makeMimeObject = GPGMEPLUG_ENCSIGN_MAKE_MIME_OBJECT; + if( structuring->makeMimeObject ) { + structuring->makeMultiMime = GPGMEPLUG_ENCSIGN_MAKE_MULTI_MIME; + storeNewCharPtr( &structuring->contentTypeMain, + GPGMEPLUG_ENCSIGN_CTYPE_MAIN ); + storeNewCharPtr( &structuring->contentDispMain, + GPGMEPLUG_ENCSIGN_CDISP_MAIN ); + storeNewCharPtr( &structuring->contentTEncMain, + GPGMEPLUG_ENCSIGN_CTENC_MAIN ); + if( structuring->makeMultiMime ) { + storeNewCharPtr( &structuring->contentTypeVersion, + GPGMEPLUG_ENCSIGN_CTYPE_VERSION ); + storeNewCharPtr( &structuring->contentDispVersion, + GPGMEPLUG_ENCSIGN_CDISP_VERSION ); + storeNewCharPtr( &structuring->contentTEncVersion, + GPGMEPLUG_ENCSIGN_CTENC_VERSION ); + storeNewCharPtr( &structuring->bodyTextVersion, + GPGMEPLUG_ENCSIGN_BTEXT_VERSION ); + storeNewCharPtr( &structuring->contentTypeCode, + GPGMEPLUG_ENCSIGN_CTYPE_CODE ); + storeNewCharPtr( &structuring->contentDispCode, + GPGMEPLUG_ENCSIGN_CDISP_CODE ); + storeNewCharPtr( &structuring->contentTEncCode, + GPGMEPLUG_ENCSIGN_CTENC_CODE ); + } + } else { + storeNewCharPtr( &structuring->flatTextPrefix, + GPGMEPLUG_ENCSIGN_FLAT_PREFIX ); + storeNewCharPtr( &structuring->flatTextSeparator, + GPGMEPLUG_ENCSIGN_FLAT_SEPARATOR ); + storeNewCharPtr( &structuring->flatTextPostfix, + GPGMEPLUG_ENCSIGN_FLAT_POSTFIX ); + } + } + return bOk; +} + +bool decryptMessage( const char* ciphertext, + const char** cleartext, + const char* certificate ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData gCiphertext, gPlaintext; + size_t rCLen = 0; + char* rCiph = 0; + bool bOk = false; + + if( !ciphertext ) + return false; + + err = gpgme_new (&ctx); + gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL); + + gpgme_data_new_from_mem( &gCiphertext, ciphertext, + 1+strlen( ciphertext ), 1 ); + gpgme_data_new( &gPlaintext ); + + gpgme_op_decrypt( ctx, gCiphertext, gPlaintext ); + gpgme_data_release( gCiphertext ); + + rCiph = gpgme_data_release_and_get_mem( gPlaintext, &rCLen ); + + *cleartext = malloc( rCLen + 1 ); + if( *cleartext ) { + if( rCLen ) { + bOk = true; + strncpy((char*)*cleartext, rCiph, rCLen ); + } + ((char*)(*cleartext))[rCLen] = 0; + } + + free( rCiph ); + gpgme_release( ctx ); + return bOk; +} + +bool decryptAndCheckMessage( const char* ciphertext, + const char** cleartext, const char* certificate, + struct SignatureMetaData* sigmeta ){ return true; } + + +const char* requestCertificateDialog(){ return 0; } + +bool requestDecentralCertificate( const char* name, const char* + email, const char* organization, const char* department, + const char* ca_address ){ return true; } + +bool requestCentralCertificateAndPSE( const char* name, + const char* email, const char* organization, const char* department, + const char* ca_address ){ return true; } + +bool createPSE(){ return true; } + +bool registerCertificate( const char* certificate ){ return true; } + +bool requestCertificateProlongation( const char* certificate, + const char* ca_address ){ return true; } + +const char* certificateChain(){ return 0; } + +bool deleteCertificate( const char* certificate ){ return true; } + +bool archiveCertificate( const char* certificate ){ return true; } + + +const char* displayCRL(){ return 0; } + +void updateCRL(){} diff --git a/tags/V0-3-4/gpgmeplug/gpgmeplug.dox b/tags/V0-3-4/gpgmeplug/gpgmeplug.dox new file mode 100644 index 0000000..3dd9d54 --- /dev/null +++ b/tags/V0-3-4/gpgmeplug/gpgmeplug.dox @@ -0,0 +1,121 @@ +# Doxygen configuration generated by Doxywizard version 0.1 +#--------------------------------------------------------------------------- +# General configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = GPGMEPLUG +PROJECT_NUMBER = 0 +OUTPUT_DIRECTORY = doc/ +OUTPUT_LANGUAGE = English +QUIET = NO +WARNINGS = YES +DISABLE_INDEX = NO +EXTRACT_ALL = NO +EXTRACT_PRIVATE = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ALWAYS_DETAILED_SEC = NO +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = +INTERNAL_DOCS = NO +CLASS_DIAGRAMS = YES +SOURCE_BROWSER = NO +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +CASE_SENSE_NAMES = NO +VERBATIM_HEADERS = YES +SHOW_INCLUDE_FILES = YES +JAVADOC_AUTOBRIEF = YES +INHERIT_DOCS = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +TAB_SIZE = 8 +ENABLED_SECTIONS = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = . +FILE_PATTERNS = *.h \ + *.c +RECURSIVE = YES +EXCLUDE = +EXCLUDE_PATTERNS = moc_* +EXAMPLE_PATH = +EXAMPLE_PATTERNS = +IMAGE_PATH = +INPUT_FILTER = +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = NO +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = YES +LATEX_OUTPUT = latex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = NO +LATEX_BATCHMODE = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = YES +MAN_OUTPUT = man +MAN_EXTENSION = .3 +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +PREDEFINED = +EXPAND_ONLY_PREDEF = NO +#--------------------------------------------------------------------------- +# Configuration::addtions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +HAVE_DOT = NO +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +INCLUDE_GRAPH = YES +GRAPHICAL_HIERARCHY = YES +#--------------------------------------------------------------------------- +# Configuration::addtions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = NO +CGI_NAME = search.cgi +CGI_URL = +DOC_URL = +DOC_ABSPATH = +BIN_ABSPATH = /usr/local/bin/ +EXT_DOC_PATHS = diff --git a/tags/V0-3-4/jnlib/.cvsignore b/tags/V0-3-4/jnlib/.cvsignore new file mode 100644 index 0000000..3f85e61 --- /dev/null +++ b/tags/V0-3-4/jnlib/.cvsignore @@ -0,0 +1 @@ +Makefile.in Makefile .deps diff --git a/tags/V0-3-4/jnlib/ChangeLog b/tags/V0-3-4/jnlib/ChangeLog new file mode 100644 index 0000000..b5f723c --- /dev/null +++ b/tags/V0-3-4/jnlib/ChangeLog @@ -0,0 +1,84 @@ +2001-11-01 Marcus Brinkmann + + * logging.c (log_printf): Do not initialize ARG_PTR with 0, we + don't know the correct type. Instead, run va_start and va_end + unconditionally. + Reported by Jose Carlos Garcia Sogo . + +2002-01-19 Werner Koch + + * logging.c (log_get_stream): New. + +2001-12-05 Werner Koch + + * logging.c (log_set_prefix): New. + (do_logv): Include prefix and pid only if enabled. Print time only + when explicitly enabled. + (log_logv): New. + * logging.h: Include log_logv() only when requested. + +2001-11-06 Werner Koch + + * strlist.c, strlist.h: New. Taken from pgnupg/util/strgutil.c + +2001-08-30 Werner Koch + + * logging.c (log_printf): Don't pass NULL instead of arg_ptr. + +2001-07-19 Werner Koch + + * stringhelp.c (ascii_memistr,ascii_isupper,ascii_islower, + ascii_toupper,ascii_tolower, ascii_strcasecmp, ascii_memcasecmp): New. + +2000-07-26 10:02:51 Werner Koch (wk@habibti.openit.de) + + * stringhelp.c.: Add stdarg.h + * argparse.h: s/ulong/unsigned long/ although this should be defined + by types.h. + +2000-06-28 19:40:23 Werner Koch (wk@habibti.openit.de) + + * Makefile.am: Replaced second logging.c by .h + +2000-05-24 08:58:15 Werner Koch (wk@habibti.openit.de) + + * logging.c (log_get_errorcount): New. + +2000-05-24 08:44:47 Werner Koch (wk@habibti.openit.de) + + * stringhelp.c: Added a few filename related helper functions. + +2000-05-11 18:04:43 Werner Koch (wk@habibti.openit.de) + + * xmalloc.c (xstrcat2): Replaced stpcpy to quickly address W32 + problems. + +2000-05-02 19:43:38 Werner Koch (wk@habibti.openit.de) + + * xmalloc.c (xstrcat2): New. + +Mon Jan 24 13:04:28 CET 2000 Werner Koch + + * README: New. + * Makefile.am: new. + * argparse.c argparse.h logging.c logging.h + mischelp.h stringhelp.c stringhelp.h xmalloc.c + xmalloc.h dotlock.c: Moved from ../util to here. + * dotlock.h: New. + * libjnlib-config.h: New. + + * logging.c (log_set_file): New. + (log_printf): New. + (do_logv): Add kludge to insert LFs. + + + Copyright 2000 Werner Koch (dd9jn) + Copyright 2001 g10 Code GmbH + + This file is free software; as a special exception the author gives + unlimited permission to copy and/or distribute it, with or without + modifications, as long as this notice is preserved. + + This file is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, to the extent permitted by law; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/tags/V0-3-4/jnlib/Makefile.am b/tags/V0-3-4/jnlib/Makefile.am new file mode 100644 index 0000000..1049f3c --- /dev/null +++ b/tags/V0-3-4/jnlib/Makefile.am @@ -0,0 +1,36 @@ +# Copyright (C) 1999, 2000, 2001 Feee Software Soundation, Inc. +# +# This file is part of GnuPG +# +# GnuPG is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# GnuPG is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +## Process this file with automake to produce Makefile.in + +EXTRA_DIST = README + +INCLUDES = -I$(top_srcdir)/intl + +noinst_LIBRARIES = libjnlib.a + + +#libjnlib_a_LDFLAGS = +libjnlib_a_SOURCES = libjnlib-config.h \ + xmalloc.c xmalloc.h \ + stringhelp.c stringhelp.h \ + argparse.c argparse.h \ + logging.c logging.h \ + types.h mischelp.h + + diff --git a/tags/V0-3-4/jnlib/README b/tags/V0-3-4/jnlib/README new file mode 100644 index 0000000..e49ef44 --- /dev/null +++ b/tags/V0-3-4/jnlib/README @@ -0,0 +1,7 @@ +jnlib - this is a collection of utility function which are +too small to put into a library. + +libjnlib-config.h should be be modified for each project +to make these functions fit into the software. Mainly these +are memory functions in case you need another allocator. + diff --git a/tags/V0-3-4/jnlib/argparse.c b/tags/V0-3-4/jnlib/argparse.c new file mode 100644 index 0000000..0e353e4 --- /dev/null +++ b/tags/V0-3-4/jnlib/argparse.c @@ -0,0 +1,995 @@ +/* [argparse.c wk 17.06.97] Argument Parser for option handling + * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "libjnlib-config.h" +#include "mischelp.h" +#include "stringhelp.h" +#include "logging.h" +#include "argparse.h" + + +/********************************* + * @Summary arg_parse + * #include + * + * typedef struct { + * char *argc; pointer to argc (value subject to change) + * char ***argv; pointer to argv (value subject to change) + * unsigned flags; Global flags (DO NOT CHANGE) + * int err; print error about last option + * 1 = warning, 2 = abort + * int r_opt; return option + * int r_type; type of return value (0 = no argument found) + * union { + * int ret_int; + * long ret_long + * ulong ret_ulong; + * char *ret_str; + * } r; Return values + * struct { + * int idx; + * const char *last; + * void *aliases; + * } internal; DO NOT CHANGE + * } ARGPARSE_ARGS; + * + * typedef struct { + * int short_opt; + * const char *long_opt; + * unsigned flags; + * } ARGPARSE_OPTS; + * + * int arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts ); + * + * @Description + * This is my replacement for getopt(). See the example for a typical usage. + * Global flags are: + * Bit 0 : Do not remove options form argv + * Bit 1 : Do not stop at last option but return other args + * with r_opt set to -1. + * Bit 2 : Assume options and real args are mixed. + * Bit 3 : Do not use -- to stop option processing. + * Bit 4 : Do not skip the first arg. + * Bit 5 : allow usage of long option with only one dash + * Bit 6 : ignore --version + * all other bits must be set to zero, this value is modified by the + * function, so assume this is write only. + * Local flags (for each option): + * Bit 2-0 : 0 = does not take an argument + * 1 = takes int argument + * 2 = takes string argument + * 3 = takes long argument + * 4 = takes ulong argument + * Bit 3 : argument is optional (r_type will the be set to 0) + * Bit 4 : allow 0x etc. prefixed values. + * Bit 7 : this is a command and not an option + * You stop the option processing by setting opts to NULL, the function will + * then return 0. + * @Return Value + * Returns the args.r_opt or 0 if ready + * r_opt may be -2/-7 to indicate an unknown option/command. + * @See Also + * ArgExpand + * @Notes + * You do not need to process the options 'h', '--help' or '--version' + * because this function includes standard help processing; but if you + * specify '-h', '--help' or '--version' you have to do it yourself. + * The option '--' stops argument processing; if bit 1 is set the function + * continues to return normal arguments. + * To process float args or unsigned args you must use a string args and do + * the conversion yourself. + * @Example + * + * ARGPARSE_OPTS opts[] = { + * { 'v', "verbose", 0 }, + * { 'd', "debug", 0 }, + * { 'o', "output", 2 }, + * { 'c', "cross-ref", 2|8 }, + * { 'm', "my-option", 1|8 }, + * { 500, "have-no-short-option-for-this-long-option", 0 }, + * {0} }; + * ARGPARSE_ARGS pargs = { &argc, &argv, 0 } + * + * while( ArgParse( &pargs, &opts) ) { + * switch( pargs.r_opt ) { + * case 'v': opt.verbose++; break; + * case 'd': opt.debug++; break; + * case 'o': opt.outfile = pargs.r.ret_str; break; + * case 'c': opt.crf = pargs.r_type? pargs.r.ret_str:"a.crf"; break; + * case 'm': opt.myopt = pargs.r_type? pargs.r.ret_int : 1; break; + * case 500: opt.a_long_one++; break + * default : pargs.err = 1; break; -- force warning output -- + * } + * } + * if( argc > 1 ) + * log_fatal( "Too many args"); + * + */ + +typedef struct alias_def_s *ALIAS_DEF; +struct alias_def_s { + ALIAS_DEF next; + char *name; /* malloced buffer with name, \0, value */ + const char *value; /* ptr into name */ +}; + +static const char *(*strusage_handler)( int ) = NULL; + +static int set_opt_arg(ARGPARSE_ARGS *arg, unsigned flags, char *s); +static void show_help(ARGPARSE_OPTS *opts, unsigned flags); +static void show_version(void); + + +static void +initialize( ARGPARSE_ARGS *arg, const char *filename, unsigned *lineno ) +{ + if( !(arg->flags & (1<<15)) ) { /* initialize this instance */ + arg->internal.idx = 0; + arg->internal.last = NULL; + arg->internal.inarg = 0; + arg->internal.stopped = 0; + arg->internal.aliases = NULL; + arg->internal.cur_alias = NULL; + arg->err = 0; + arg->flags |= 1<<15; /* mark initialized */ + if( *arg->argc < 0 ) + jnlib_log_bug("Invalid argument for ArgParse\n"); + } + + + if( arg->err ) { /* last option was erroneous */ + const char *s; + + if( filename ) { + if( arg->r_opt == -6 ) + s = "%s:%u: argument not expected\n"; + else if( arg->r_opt == -5 ) + s = "%s:%u: read error\n"; + else if( arg->r_opt == -4 ) + s = "%s:%u: keyword too long\n"; + else if( arg->r_opt == -3 ) + s = "%s:%u: missing argument\n"; + else if( arg->r_opt == -7 ) + s = "%s:%u: invalid command\n"; + else if( arg->r_opt == -10 ) + s = "%s:%u: invalid alias definition\n"; + else + s = "%s:%u: invalid option\n"; + jnlib_log_error(s, filename, *lineno ); + } + else { + if( arg->r_opt == -3 ) + s = "Missing argument for option \"%.50s\"\n"; + else if( arg->r_opt == -6 ) + s = "Option \"%.50s\" does not expect an argument\n"; + else if( arg->r_opt == -7 ) + s = "Invalid command \"%.50s\"\n"; + else if( arg->r_opt == -8 ) + s = "Option \"%.50s\" is ambiguous\n"; + else if( arg->r_opt == -9 ) + s = "Command \"%.50s\" is ambiguous\n"; + else + s = "Invalid option \"%.50s\"\n"; + jnlib_log_error(s, arg->internal.last? arg->internal.last:"[??]" ); + } + if( arg->err != 1 ) + exit(2); + arg->err = 0; + } + + /* clearout the return value union */ + arg->r.ret_str = NULL; + arg->r.ret_long= 0; +} + + +static void +store_alias( ARGPARSE_ARGS *arg, char *name, char *value ) +{ + /* TODO: replace this dummy function with a rea one + * and fix the probelms IRIX has with (ALIAS_DEV)arg.. + * used as lvalue + */ +#if 0 + ALIAS_DEF a = jnlib_xmalloc( sizeof *a ); + a->name = name; + a->value = value; + a->next = (ALIAS_DEF)arg->internal.aliases; + (ALIAS_DEF)arg->internal.aliases = a; +#endif +} + +/**************** + * Get options from a file. + * Lines starting with '#' are comment lines. + * Syntax is simply a keyword and the argument. + * Valid keywords are all keywords from the long_opt list without + * the leading dashes. The special keywords "help", "warranty" and "version" + * are not valid here. + * The special keyword "alias" may be used to store alias definitions, + * which are later expanded like long options. + * Caller must free returned strings. + * If called with FP set to NULL command line args are parse instead. + * + * Q: Should we allow the syntax + * keyword = value + * and accept for boolean options a value of 1/0, yes/no or true/false? + * Note: Abbreviation of options is here not allowed. + */ +int +optfile_parse( FILE *fp, const char *filename, unsigned *lineno, + ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts) +{ + int state, i, c; + int idx=0; + char keyword[100]; + char *buffer = NULL; + size_t buflen = 0; + int inverse=0; + int in_alias=0; + + if( !fp ) /* same as arg_parse() in this case */ + return arg_parse( arg, opts ); + + initialize( arg, filename, lineno ); + + /* find the next keyword */ + state = i = 0; + for(;;) { + c=getc(fp); + if( c == '\n' || c== EOF ) { + if( c != EOF ) + ++*lineno; + if( state == -1 ) + break; + else if( state == 2 ) { + keyword[i] = 0; + for(i=0; opts[i].short_opt; i++ ) + if( opts[i].long_opt && !strcmp( opts[i].long_opt, keyword) ) + break; + idx = i; + arg->r_opt = opts[idx].short_opt; + if( inverse ) /* this does not have an effect, hmmm */ + arg->r_opt = -arg->r_opt; + if( !opts[idx].short_opt ) /* unknown command/option */ + arg->r_opt = (opts[idx].flags & 256)? -7:-2; + else if( (opts[idx].flags & 8) ) /* no argument */ + arg->r_opt = -3; /* error */ + else /* no or optional argument */ + arg->r_type = 0; /* okay */ + break; + } + else if( state == 3 ) { /* no argument found */ + if( in_alias ) + arg->r_opt = -3; /* error */ + else if( !(opts[idx].flags & 7) ) /* does not take an arg */ + arg->r_type = 0; /* okay */ + else if( (opts[idx].flags & 8) ) /* no optional argument */ + arg->r_type = 0; /* okay */ + else /* no required argument */ + arg->r_opt = -3; /* error */ + break; + } + else if( state == 4 ) { /* have an argument */ + if( in_alias ) { + if( !buffer ) + arg->r_opt = -6; + else { + char *p; + + buffer[i] = 0; + p = strpbrk( buffer, " \t" ); + if( p ) { + *p++ = 0; + trim_spaces( p ); + } + if( !p || !*p ) { + jnlib_free( buffer ); + arg->r_opt = -10; + } + else { + store_alias( arg, buffer, p ); + } + } + } + else if( !(opts[idx].flags & 7) ) /* does not take an arg */ + arg->r_opt = -6; /* error */ + else { + char *p; + if( !buffer ) { + keyword[i] = 0; + buffer = jnlib_xstrdup(keyword); + } + else + buffer[i] = 0; + + trim_spaces( buffer ); + p = buffer; + if( *p == '"' ) { /* remove quotes */ + p++; + if( *p && p[strlen(p)-1] == '"' ) + p[strlen(p)-1] = 0; + } + if( !set_opt_arg(arg, opts[idx].flags, p) ) + jnlib_free(buffer); + } + break; + } + else if( c == EOF ) { + if( ferror(fp) ) + arg->r_opt = -5; /* read error */ + else + arg->r_opt = 0; /* eof */ + break; + } + state = 0; + i = 0; + } + else if( state == -1 ) + ; /* skip */ + else if( !state && isspace(c) ) + ; /* skip leading white space */ + else if( !state && c == '#' ) + state = 1; /* start of a comment */ + else if( state == 1 ) + ; /* skip comments */ + else if( state == 2 && isspace(c) ) { + keyword[i] = 0; + for(i=0; opts[i].short_opt; i++ ) + if( opts[i].long_opt && !strcmp( opts[i].long_opt, keyword) ) + break; + idx = i; + arg->r_opt = opts[idx].short_opt; + if( !opts[idx].short_opt ) { + if( !strcmp( keyword, "alias" ) ) { + in_alias = 1; + state = 3; + } + else { + arg->r_opt = (opts[idx].flags & 256)? -7:-2; + state = -1; /* skip rest of line and leave */ + } + } + else + state = 3; + } + else if( state == 3 ) { /* skip leading spaces of the argument */ + if( !isspace(c) ) { + i = 0; + keyword[i++] = c; + state = 4; + } + } + else if( state == 4 ) { /* collect the argument */ + if( buffer ) { + if( i < buflen-1 ) + buffer[i++] = c; + else { + buflen += 50; + buffer = jnlib_xrealloc(buffer, buflen); + buffer[i++] = c; + } + } + else if( i < DIM(keyword)-1 ) + keyword[i++] = c; + else { + buflen = DIM(keyword)+50; + buffer = jnlib_xmalloc(buflen); + memcpy(buffer, keyword, i); + buffer[i++] = c; + } + } + else if( i >= DIM(keyword)-1 ) { + arg->r_opt = -4; /* keyword to long */ + state = -1; /* skip rest of line and leave */ + } + else { + keyword[i++] = c; + state = 2; + } + } + + return arg->r_opt; +} + + + +static int +find_long_option( ARGPARSE_ARGS *arg, + ARGPARSE_OPTS *opts, const char *keyword ) +{ + int i; + size_t n; + + /* Would be better if we can do a binary search, but it is not + possible to reorder our option table because we would mess + up our help strings - What we can do is: Build a nice option + lookup table wehn this function is first invoked */ + if( !*keyword ) + return -1; + for(i=0; opts[i].short_opt; i++ ) + if( opts[i].long_opt && !strcmp( opts[i].long_opt, keyword) ) + return i; + #if 0 + { + ALIAS_DEF a; + /* see whether it is an alias */ + for( a = args->internal.aliases; a; a = a->next ) { + if( !strcmp( a->name, keyword) ) { + /* todo: must parse the alias here */ + args->internal.cur_alias = a; + return -3; /* alias available */ + } + } + } + #endif + /* not found, see whether it is an abbreviation */ + /* aliases may not be abbreviated */ + n = strlen( keyword ); + for(i=0; opts[i].short_opt; i++ ) { + if( opts[i].long_opt && !strncmp( opts[i].long_opt, keyword, n ) ) { + int j; + for(j=i+1; opts[j].short_opt; j++ ) { + if( opts[j].long_opt + && !strncmp( opts[j].long_opt, keyword, n ) ) + return -2; /* abbreviation is ambiguous */ + } + return i; + } + } + return -1; +} + +int +arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts) +{ + int idx; + int argc; + char **argv; + char *s, *s2; + int i; + + initialize( arg, NULL, NULL ); + argc = *arg->argc; + argv = *arg->argv; + idx = arg->internal.idx; + + if( !idx && argc && !(arg->flags & (1<<4)) ) { /* skip the first entry */ + argc--; argv++; idx++; + } + + next_one: + if( !argc ) { /* no more args */ + arg->r_opt = 0; + goto leave; /* ready */ + } + + s = *argv; + arg->internal.last = s; + + if( arg->internal.stopped && (arg->flags & (1<<1)) ) { + arg->r_opt = -1; /* not an option but a argument */ + arg->r_type = 2; + arg->r.ret_str = s; + argc--; argv++; idx++; /* set to next one */ + } + else if( arg->internal.stopped ) { /* ready */ + arg->r_opt = 0; + goto leave; + } + else if( *s == '-' && s[1] == '-' ) { /* long option */ + char *argpos; + + arg->internal.inarg = 0; + if( !s[2] && !(arg->flags & (1<<3)) ) { /* stop option processing */ + arg->internal.stopped = 1; + argc--; argv++; idx++; + goto next_one; + } + + argpos = strchr( s+2, '=' ); + if( argpos ) + *argpos = 0; + i = find_long_option( arg, opts, s+2 ); + if( argpos ) + *argpos = '='; + + if( i < 0 && !strcmp( "help", s+2) ) + show_help(opts, arg->flags); + else if( i < 0 && !strcmp( "version", s+2) ) { + if( !(arg->flags & (1<<6)) ) { + show_version(); + exit(0); + } + } + else if( i < 0 && !strcmp( "warranty", s+2) ) { + puts( strusage(16) ); + exit(0); + } + else if( i < 0 && !strcmp( "dump-options", s+2) ) { + for(i=0; opts[i].short_opt; i++ ) { + if( opts[i].long_opt ) + printf( "--%s\n", opts[i].long_opt ); + } + fputs("--dump-options\n--help\n--version\n--warranty\n", stdout ); + exit(0); + } + + if( i == -2 ) /* ambiguous option */ + arg->r_opt = -8; + else if( i == -1 ) { + arg->r_opt = -2; + arg->r.ret_str = s+2; + } + else + arg->r_opt = opts[i].short_opt; + if( i < 0 ) + ; + else if( (opts[i].flags & 7) ) { + if( argpos ) { + s2 = argpos+1; + if( !*s2 ) + s2 = NULL; + } + else + s2 = argv[1]; + if( !s2 && (opts[i].flags & 8) ) { /* no argument but it is okay*/ + arg->r_type = 0; /* because it is optional */ + } + else if( !s2 ) { + arg->r_opt = -3; /* missing argument */ + } + else if( !argpos && *s2 == '-' && (opts[i].flags & 8) ) { + /* the argument is optional and the next seems to be + * an option. We do not check this possible option + * but assume no argument */ + arg->r_type = 0; + } + else { + set_opt_arg(arg, opts[i].flags, s2); + if( !argpos ) { + argc--; argv++; idx++; /* skip one */ + } + } + } + else { /* does not take an argument */ + if( argpos ) + arg->r_type = -6; /* argument not expected */ + else + arg->r_type = 0; + } + argc--; argv++; idx++; /* set to next one */ + } + else if( (*s == '-' && s[1]) || arg->internal.inarg ) { /* short option */ + int dash_kludge = 0; + i = 0; + if( !arg->internal.inarg ) { + arg->internal.inarg++; + if( arg->flags & (1<<5) ) { + for(i=0; opts[i].short_opt; i++ ) + if( opts[i].long_opt && !strcmp( opts[i].long_opt, s+1)) { + dash_kludge=1; + break; + } + } + } + s += arg->internal.inarg; + + if( !dash_kludge ) { + for(i=0; opts[i].short_opt; i++ ) + if( opts[i].short_opt == *s ) + break; + } + + if( !opts[i].short_opt && ( *s == 'h' || *s == '?' ) ) + show_help(opts, arg->flags); + + arg->r_opt = opts[i].short_opt; + if( !opts[i].short_opt ) { + arg->r_opt = (opts[i].flags & 256)? -7:-2; + arg->internal.inarg++; /* point to the next arg */ + arg->r.ret_str = s; + } + else if( (opts[i].flags & 7) ) { + if( s[1] && !dash_kludge ) { + s2 = s+1; + set_opt_arg(arg, opts[i].flags, s2); + } + else { + s2 = argv[1]; + if( !s2 && (opts[i].flags & 8) ) { /* no argument but it is okay*/ + arg->r_type = 0; /* because it is optional */ + } + else if( !s2 ) { + arg->r_opt = -3; /* missing argument */ + } + else if( *s2 == '-' && s2[1] && (opts[i].flags & 8) ) { + /* the argument is optional and the next seems to be + * an option. We do not check this possible option + * but assume no argument */ + arg->r_type = 0; + } + else { + set_opt_arg(arg, opts[i].flags, s2); + argc--; argv++; idx++; /* skip one */ + } + } + s = "x"; /* so that !s[1] yields false */ + } + else { /* does not take an argument */ + arg->r_type = 0; + arg->internal.inarg++; /* point to the next arg */ + } + if( !s[1] || dash_kludge ) { /* no more concatenated short options */ + arg->internal.inarg = 0; + argc--; argv++; idx++; + } + } + else if( arg->flags & (1<<2) ) { + arg->r_opt = -1; /* not an option but a argument */ + arg->r_type = 2; + arg->r.ret_str = s; + argc--; argv++; idx++; /* set to next one */ + } + else { + arg->internal.stopped = 1; /* stop option processing */ + goto next_one; + } + + leave: + *arg->argc = argc; + *arg->argv = argv; + arg->internal.idx = idx; + return arg->r_opt; +} + + + +static int +set_opt_arg(ARGPARSE_ARGS *arg, unsigned flags, char *s) +{ + int base = (flags & 16)? 0 : 10; + + switch( arg->r_type = (flags & 7) ) { + case 1: /* takes int argument */ + arg->r.ret_int = (int)strtol(s,NULL,base); + return 0; + case 3: /* takes long argument */ + arg->r.ret_long= strtol(s,NULL,base); + return 0; + case 4: /* takes ulong argument */ + arg->r.ret_ulong= strtoul(s,NULL,base); + return 0; + case 2: /* takes string argument */ + default: + arg->r.ret_str = s; + return 1; + } +} + + +static size_t +long_opt_strlen( ARGPARSE_OPTS *o ) +{ + size_t n = strlen(o->long_opt); + + if( o->description && *o->description == '|' ) { + const char *s; + + s=o->description+1; + if( *s != '=' ) + n++; + for(; *s && *s != '|'; s++ ) + n++; + } + return n; +} + +/**************** + * Print formatted help. The description string has some special + * meanings: + * - A description string which is "@" suppresses help output for + * this option + * - a description,ine which starts with a '@' and is followed by + * any other characters is printed as is; this may be used for examples + * ans such. + * - A description which starts with a '|' outputs the string between this + * bar and the next one as arguments of the long option. + */ +static void +show_help( ARGPARSE_OPTS *opts, unsigned flags ) +{ + const char *s; + + show_version(); + putchar('\n'); + s = strusage(41); + puts(s); + if( opts[0].description ) { /* auto format the option description */ + int i,j, indent; + /* get max. length of long options */ + for(i=indent=0; opts[i].short_opt; i++ ) { + if( opts[i].long_opt ) + if( !opts[i].description || *opts[i].description != '@' ) + if( (j=long_opt_strlen(opts+i)) > indent && j < 35 ) + indent = j; + } + /* example: " -v, --verbose Viele Sachen ausgeben" */ + indent += 10; + if( *opts[0].description != '@' ) + puts("Options:"); + for(i=0; opts[i].short_opt; i++ ) { + s = _( opts[i].description ); + if( s && *s== '@' && !s[1] ) /* hide this line */ + continue; + if( s && *s == '@' ) { /* unindented comment only line */ + for(s++; *s; s++ ) { + if( *s == '\n' ) { + if( s[1] ) + putchar('\n'); + } + else + putchar(*s); + } + putchar('\n'); + continue; + } + + j = 3; + if( opts[i].short_opt < 256 ) { + printf(" -%c", opts[i].short_opt ); + if( !opts[i].long_opt ) { + if(s && *s == '|' ) { + putchar(' '); j++; + for(s++ ; *s && *s != '|'; s++, j++ ) + putchar(*s); + if( *s ) + s++; + } + } + } + else + fputs(" ", stdout); + if( opts[i].long_opt ) { + j += printf("%c --%s", opts[i].short_opt < 256?',':' ', + opts[i].long_opt ); + if(s && *s == '|' ) { + if( *++s != '=' ) { + putchar(' '); + j++; + } + for( ; *s && *s != '|'; s++, j++ ) + putchar(*s); + if( *s ) + s++; + } + fputs(" ", stdout); + j += 3; + } + for(;j < indent; j++ ) + putchar(' '); + if( s ) { + if( *s && j > indent ) { + putchar('\n'); + for(j=0;j < indent; j++ ) + putchar(' '); + } + for(; *s; s++ ) { + if( *s == '\n' ) { + if( s[1] ) { + putchar('\n'); + for(j=0;j < indent; j++ ) + putchar(' '); + } + } + else + putchar(*s); + } + } + putchar('\n'); + } + if( flags & 32 ) + puts("\n(A single dash may be used instead of the double ones)"); + } + if( (s=strusage(19)) ) { /* bug reports to ... */ + putchar('\n'); + fputs(s, stdout); + } + fflush(stdout); + exit(0); +} + +static void +show_version() +{ + const char *s; + int i; + /* version line */ + fputs(strusage(11), stdout); + if( (s=strusage(12)) ) + printf(" (%s)", s ); + printf(" %s\n", strusage(13) ); + /* additional version lines */ + for(i=20; i < 30; i++ ) + if( (s=strusage(i)) ) + printf("%s\n", s ); + /* copyright string */ + if( (s=strusage(14)) ) + printf("%s\n", s ); + /* copying conditions */ + if( (s=strusage(15)) ) + fputs(s, stdout); + /* thanks */ + if( (s=strusage(18)) ) + fputs(s, stdout); + /* additional program info */ + for(i=30; i < 40; i++ ) + if( (s=strusage(i)) ) + fputs( (const byte*)s, stdout); + fflush(stdout); +} + + +void +usage( int level ) +{ + if( !level ) { + fprintf(stderr,"%s %s; %s\n", strusage(11), strusage(13), + strusage(14) ); + fflush(stderr); + } + else if( level == 1 ) { + fputs(strusage(40),stderr); + exit(2); + } + else if( level == 2 ) { + puts(strusage(41)); + exit(0); + } +} + +/* Level + * 0: Copyright String auf stderr ausgeben + * 1: Kurzusage auf stderr ausgeben und beenden + * 2: Langusage auf stdout ausgeben und beenden + * 11: name of program + * 12: optional name of package which includes this program. + * 13: version string + * 14: copyright string + * 15: Short copying conditions (with LFs) + * 16: Long copying conditions (with LFs) + * 17: Optional printable OS name + * 18: Optional thanks list (with LFs) + * 19: Bug report info + *20..29: Additional lib version strings. + *30..39: Additional program info (with LFs) + * 40: short usage note (with LF) + * 41: long usage note (with LF) + */ +const char * +strusage( int level ) +{ + const char *p = strusage_handler? strusage_handler(level) : NULL; + + if( p ) + return p; + + switch( level ) { + case 11: p = "foo"; break; + case 13: p = "0.0"; break; + case 14: p = "Copyright (C) 2001 Free Software Foundation, Inc."; break; + case 15: p = +"This program comes with ABSOLUTELY NO WARRANTY.\n" +"This is free software, and you are welcome to redistribute it\n" +"under certain conditions. See the file COPYING for details.\n"; break; + case 16: p = +"This is free software; you can redistribute it and/or modify\n" +"it under the terms of the GNU General Public License as published by\n" +"the Free Software Foundation; either version 2 of the License, or\n" +"(at your option) any later version.\n\n" +"It is distributed in the hope that it will be useful,\n" +"but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +"GNU General Public License for more details.\n\n" +"You should have received a copy of the GNU General Public License\n" +"along with this program; if not, write to the Free Software\n" +"Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n"; + break; + case 40: /* short and long usage */ + case 41: p = ""; break; + } + + return p; +} + +void +set_strusage( const char *(*f)( int ) ) +{ + strusage_handler = f; +} + + +#ifdef TEST +static struct { + int verbose; + int debug; + char *outfile; + char *crf; + int myopt; + int echo; + int a_long_one; +}opt; + +int +main(int argc, char **argv) +{ + ARGPARSE_OPTS opts[] = { + { 'v', "verbose", 0 , "Laut sein"}, + { 'e', "echo" , 0 , "Zeile ausgeben, damit wir sehen, was wir einegegeben haben"}, + { 'd', "debug", 0 , "Debug\nfalls mal etasws\nSchief geht"}, + { 'o', "output", 2 }, + { 'c', "cross-ref", 2|8, "cross-reference erzeugen\n" }, + { 'm', "my-option", 1|8 }, + { 500, "a-long-option", 0 }, + {0} }; + ARGPARSE_ARGS pargs = { &argc, &argv, 2|4|32 }; + int i; + + while( ArgParse( &pargs, opts) ) { + switch( pargs.r_opt ) { + case -1 : printf( "arg=`%s'\n", pargs.r.ret_str); break; + case 'v': opt.verbose++; break; + case 'e': opt.echo++; break; + case 'd': opt.debug++; break; + case 'o': opt.outfile = pargs.r.ret_str; break; + case 'c': opt.crf = pargs.r_type? pargs.r.ret_str:"a.crf"; break; + case 'm': opt.myopt = pargs.r_type? pargs.r.ret_int : 1; break; + case 500: opt.a_long_one++; break; + default : pargs.err = 1; break; /* force warning output */ + } + } + for(i=0; i < argc; i++ ) + printf("%3d -> (%s)\n", i, argv[i] ); + puts("Options:"); + if( opt.verbose ) + printf(" verbose=%d\n", opt.verbose ); + if( opt.debug ) + printf(" debug=%d\n", opt.debug ); + if( opt.outfile ) + printf(" outfile=`%s'\n", opt.outfile ); + if( opt.crf ) + printf(" crffile=`%s'\n", opt.crf ); + if( opt.myopt ) + printf(" myopt=%d\n", opt.myopt ); + if( opt.a_long_one ) + printf(" a-long-one=%d\n", opt.a_long_one ); + if( opt.echo ) + printf(" echo=%d\n", opt.echo ); + return 0; +} +#endif + +/**** bottom of file ****/ diff --git a/tags/V0-3-4/jnlib/argparse.h b/tags/V0-3-4/jnlib/argparse.h new file mode 100644 index 0000000..e8922fa --- /dev/null +++ b/tags/V0-3-4/jnlib/argparse.h @@ -0,0 +1,67 @@ +/* argparse.h + * Copyright (C) 1998,1999,2000,2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef LIBJNLIB_ARGPARSE_H +#define LIBJNLIB_ARGPARSE_H + +#include +#include "types.h" + +typedef struct { + int *argc; /* pointer to argc (value subject to change) */ + char ***argv; /* pointer to argv (value subject to change) */ + unsigned flags; /* Global flags (DO NOT CHANGE) */ + int err; /* print error about last option */ + /* 1 = warning, 2 = abort */ + int r_opt; /* return option */ + int r_type; /* type of return value (0 = no argument found)*/ + union { + int ret_int; + long ret_long; + unsigned long ret_ulong; + char *ret_str; + } r; /* Return values */ + struct { + int idx; + int inarg; + int stopped; + const char *last; + void *aliases; + const void *cur_alias; + } internal; /* DO NOT CHANGE */ +} ARGPARSE_ARGS; + +typedef struct { + int short_opt; + const char *long_opt; + unsigned flags; + const char *description; /* optional option description */ +} ARGPARSE_OPTS; + + + +int arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts); +int optfile_parse( FILE *fp, const char *filename, unsigned *lineno, + ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts); +void usage( int level ); +const char *strusage( int level ); +void set_strusage( const char *(*f)( int ) ); + +#endif /*LIBJNLIB_ARGPARSE_H*/ diff --git a/tags/V0-3-4/jnlib/dotlock.c b/tags/V0-3-4/jnlib/dotlock.c new file mode 100644 index 0000000..772c770 --- /dev/null +++ b/tags/V0-3-4/jnlib/dotlock.c @@ -0,0 +1,346 @@ +/* dotlock.c - dotfile locking + * Copyright (C) 1998,2000,2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#ifndef HAVE_DOSISH_SYSTEM +#include +#endif +#include +#include +#include +#include +#include + +#include "libjnlib-config.h" +#include "dotlock.h" + +struct dotlock_handle { + struct dotlock_handle *next; + char *tname; /* name of lockfile template */ + char *lockname; /* name of the real lockfile */ + int locked; /* lock status */ +}; + + +static DOTLOCK all_lockfiles; + +static int read_lockfile( const char *name ); +static void remove_lockfiles(void); + +/**************** + * Create a lockfile with the given name and return an object of + * type DOTLOCK which may be used later to actually do the lock. + * A cleanup routine gets installed to cleanup left over locks + * or other files used together with the lockmechanism. + * Althoug the function is called dotlock, this does not necessarily + * mean that real lockfiles are used - the function may decide to + * use fcntl locking. Calling the function with NULL only install + * the atexit handler and maybe used to assure that the cleanup + * is called after all other atexit handlers. + * + * Notes: This function creates a lock file in the same directory + * as file_to_lock with the name "file_to_lock.lock" + * A temporary file ".#lk..pid[.threadid] is used. + * This function does nothing for Windoze. + */ +DOTLOCK +create_dotlock( const char *file_to_lock ) +{ + static int initialized; + DOTLOCK h; + int fd = -1; + char pidstr[16]; + #ifndef HAVE_DOSISH_SYSTEM + struct utsname utsbuf; + #endif + const char *nodename; + const char *dirpart; + int dirpartlen; + + if( !initialized ) { + atexit( remove_lockfiles ); + initialized = 1; + } + if( !file_to_lock ) + return NULL; + + h = jnlib_xcalloc( 1, sizeof *h ); +#ifndef HAVE_DOSISH_SYSTEM + sprintf( pidstr, "%10d\n", (int)getpid() ); + /* fixme: add the hostname to the second line (FQDN or IP addr?) */ + + /* create a temporary file */ + if( uname( &utsbuf ) ) + nodename = "unknown"; + else + nodename = utsbuf.nodename; + + if( !(dirpart = strrchr( file_to_lock, '/' )) ) { + dirpart = "."; + dirpartlen = 1; + } + else { + dirpartlen = dirpart - file_to_lock; + dirpart = file_to_lock; + } + + #ifdef _REENTRANT + /* fixme: aquire mutex on all_lockfiles */ + #endif + h->next = all_lockfiles; + all_lockfiles = h; + + h->tname = jnlib_xmalloc( dirpartlen + 6+30+ strlen(nodename) + 11 ); + sprintf( h->tname, "%.*s/.#lk%p.%s.%d", + dirpartlen, dirpart, h, nodename, (int)getpid() ); + + do { + errno = 0; + fd = open( h->tname, O_WRONLY|O_CREAT|O_EXCL, + S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR ); + } while( fd == -1 && errno == EINTR ); + if( fd == -1 ) { + all_lockfiles = h->next; + log_error( "failed to create temporary file `%s': %s\n", + h->tname, strerror(errno)); + jnlib_free(h->tname); + jnlib_free(h); + return NULL; + } + if( write(fd, pidstr, 11 ) != 11 ) { + all_lockfiles = h->next; + #ifdef _REENTRANT + /* release mutex */ + #endif + log_fatal( "error writing to `%s': %s\n", h->tname, strerror(errno) ); + close(fd); + unlink(h->tname); + jnlib_free(h->tname); + jnlib_free(h); + return NULL; + } + if( close(fd) ) { + all_lockfiles = h->next; + #ifdef _REENTRANT + /* release mutex */ + #endif + log_error( "error closing `%s': %s\n", h->tname, strerror(errno)); + unlink(h->tname); + jnlib_free(h->tname); + jnlib_free(h); + return NULL; + } + + #ifdef _REENTRANT + /* release mutex */ + #endif +#endif /* !HAVE_DOSISH_SYSTEM */ + h->lockname = jnlib_xmalloc( strlen(file_to_lock) + 6 ); + strcpy(stpcpy(h->lockname, file_to_lock), ".lock"); + return h; +} + +static int +maybe_deadlock( DOTLOCK h ) +{ + DOTLOCK r; + + for( r=all_lockfiles; r; r = r->next ) { + if( r != h && r->locked ) + return 1; + } + return 0; +} + +/**************** + * Do a lock on H. A TIMEOUT of 0 returns immediately, + * -1 waits forever (hopefully not), other + * values are timeouts in milliseconds. + * Returns: 0 on success + */ +int +make_dotlock( DOTLOCK h, long timeout ) +{ +#ifdef HAVE_DOSISH_SYSTEM + return 0; +#else + int pid; + const char *maybe_dead=""; + int backoff=0; + + if( h->locked ) { + log_debug("oops, `%s' is already locked\n", h->lockname ); + return 0; + } + + for(;;) { + if( !link(h->tname, h->lockname) ) { + /* fixme: better use stat to check the link count */ + h->locked = 1; + return 0; /* okay */ + } + if( errno != EEXIST ) { + log_error( "lock not made: link() failed: %s\n", strerror(errno) ); + return -1; + } + if( (pid = read_lockfile(h->lockname)) == -1 ) { + if( errno != ENOENT ) { + log_info("cannot read lockfile\n"); + return -1; + } + log_info( "lockfile disappeared\n"); + continue; + } + else if( pid == getpid() ) { + log_info( "Oops: lock already hold by us\n"); + h->locked = 1; + return 0; /* okay */ + } + else if( kill(pid, 0) && errno == ESRCH ) { + maybe_dead = " - probably dead"; + #if 0 /* we should not do this without checking the permissions */ + /* and the hostname */ + log_info( "removing stale lockfile (created by %d)", pid ); + #endif + } + if( timeout == -1 ) { + struct timeval tv; + log_info( "waiting for lock (hold by %d%s) %s...\n", + pid, maybe_dead, maybe_deadlock(h)? "(deadlock?) ":""); + + + /* can't use sleep, cause signals may be blocked */ + tv.tv_sec = 1 + backoff; + tv.tv_usec = 0; + select(0, NULL, NULL, NULL, &tv); + if( backoff < 10 ) + backoff++ ; + } + else + return -1; + } + /*not reached */ +#endif /* !HAVE_DOSISH_SYSTEM */ +} + + +/**************** + * release a lock + * Returns: 0 := success + */ +int +release_dotlock( DOTLOCK h ) +{ +#ifdef HAVE_DOSISH_SYSTEM + return 0; +#else + int pid; + + if( !h->locked ) { + log_debug("oops, `%s' is not locked\n", h->lockname ); + return 0; + } + + pid = read_lockfile( h->lockname ); + if( pid == -1 ) { + log_error( "release_dotlock: lockfile error\n"); + return -1; + } + if( pid != getpid() ) { + log_error( "release_dotlock: not our lock (pid=%d)\n", pid); + return -1; + } + if( unlink( h->lockname ) ) { + log_error( "release_dotlock: error removing lockfile `%s'", + h->lockname); + return -1; + } + /* fixme: check that the link count is now 1 */ + h->locked = 0; + return 0; +#endif /* !HAVE_DOSISH_SYSTEM */ +} + + +/**************** + * Read the lock file and return the pid, returns -1 on error. + */ +static int +read_lockfile( const char *name ) +{ + #ifdef HAVE_DOSISH_SYSTEM + return 0; + #else + int fd, pid; + char pidstr[16]; + + if( (fd = open(name, O_RDONLY)) == -1 ) { + int e = errno; + log_debug("error opening lockfile `%s': %s\n", name, strerror(errno) ); + errno = e; + return -1; + } + if( read(fd, pidstr, 10 ) != 10 ) { /* Read 10 digits w/o newline */ + log_debug("error reading lockfile `%s'", name ); + close(fd); + errno = 0; + return -1; + } + pidstr[10] = 0; /* terminate pid string */ + close(fd); + pid = atoi(pidstr); + if( !pid || pid == -1 ) { + log_error("invalid pid %d in lockfile `%s'", pid, name ); + errno = 0; + return -1; + } + return pid; + #endif +} + + +static void +remove_lockfiles() +{ + #ifndef HAVE_DOSISH_SYSTEM + DOTLOCK h, h2; + + h = all_lockfiles; + all_lockfiles = NULL; + + while( h ) { + h2 = h->next; + if( h->locked ) + unlink( h->lockname ); + unlink(h->tname); + jnlib_free(h->tname); + jnlib_free(h->lockname); + jnlib_free(h); + h = h2; + } + #endif +} + diff --git a/tags/V0-3-4/jnlib/dotlock.h b/tags/V0-3-4/jnlib/dotlock.h new file mode 100644 index 0000000..7d45c82 --- /dev/null +++ b/tags/V0-3-4/jnlib/dotlock.h @@ -0,0 +1,32 @@ +/* dotlock.h + * Copyright (C) 2000, 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef LIBJNLIB_DOTLOCK_H +#define LIBJNLIB_DOTLOCK_H + +struct dotlock_handle; +typedef struct dotlock_handle *DOTLOCK; + +DOTLOCK create_dotlock( const char *file_to_lock ); +int make_dotlock( DOTLOCK h, long timeout ); +int release_dotlock( DOTLOCK h ); + + +#endif /*LIBJNLIB_DOTLOCK_H*/ diff --git a/tags/V0-3-4/jnlib/libjnlib-config.h b/tags/V0-3-4/jnlib/libjnlib-config.h new file mode 100644 index 0000000..de8e6a4 --- /dev/null +++ b/tags/V0-3-4/jnlib/libjnlib-config.h @@ -0,0 +1,75 @@ +/* libjnlib-config.h - local configuration of the jnlib functions + * Copyright (C) 2000, 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +/**************** + * This header is to be included only by the files in this directory + * it should not be used by other modules. + */ + +#ifndef LIBJNLIB_CONFIG_H +#define LIBJNLIB_CONFIG_H + +#include "xmalloc.h" +#include "logging.h" + + + +#ifdef USE_SIMPLE_GETTEXT + int set_gettext_file( const char *filename ); + const char *gettext( const char *msgid ); + + #define _(a) gettext (a) + #define N_(a) (a) + +#else +#ifdef HAVE_LOCALE_H + #include +#endif + +#ifdef ENABLE_NLS + #include + #define _(a) gettext (a) + #ifdef gettext_noop + #define N_(a) gettext_noop (a) + #else + #define N_(a) (a) + #endif +#else + #define _(a) (a) + #define N_(a) (a) +#endif +#endif /* !USE_SIMPLE_GETTEXT */ + + +#define jnlib_xmalloc(a) xmalloc( (a) ) +#define jnlib_xcalloc(a,b) xcalloc( (a), (b) ) +#define jnlib_xrealloc(a,n) xrealloc( (a), (n) ) +#define jnlib_xstrdup(a) xstrdup( (a) ) +#define jnlib_free(a) free( (a) ) + +#define jnlib_log_debug log_debug +#define jnlib_log_info log_info +#define jnlib_log_error log_error +#define jnlib_log_fatal log_fatal +#define jnlib_log_bug log_bug + + +#endif /*LIBJNUTIL_CONFIG_H*/ + diff --git a/tags/V0-3-4/jnlib/logging.c b/tags/V0-3-4/jnlib/logging.c new file mode 100644 index 0000000..2e0d53a --- /dev/null +++ b/tags/V0-3-4/jnlib/logging.c @@ -0,0 +1,305 @@ +/* logging.c - useful logging functions + * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + + +/* This file should replace logger.c in the future - for now it is not + * used by GnuPG but by GPA. + * It is a quite simple implemenation but sufficient for most purposes. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __MINGW32__ + #include +#endif + +#define JNLIB_NEED_LOG_LOGV 1 +#include "libjnlib-config.h" +#include "logging.h" + + +static FILE *logstream; +static char prefix_buffer[80]; +static int with_time; +static int with_prefix; +static int with_pid; + +static int missing_lf; +static int errorcount; + +#if 0 +static void +write2stderr( const char *s ) +{ + write( 2, s, strlen(s) ); +} + + +static void +do_die(int rc, const char *text ) +{ + write2stderr("\nFatal error: "); + write2stderr(text); + write2stderr("\n"); + abort(); +} +#endif + +int +log_get_errorcount (int clear) +{ + int n = errorcount; + if( clear ) + errorcount = 0; + return n; +} + +void +log_set_file( const char *name ) +{ + FILE *fp = (name && strcmp(name,"-"))? fopen(name, "a") : stderr; + if( !fp ) { + fprintf(stderr, "failed to open log file `%s': %s\n", + name, strerror(errno)); + return; + } + setvbuf( fp, NULL, _IOLBF, 0 ); + + if( logstream && logstream != stderr ) + fclose( logstream ); + logstream = fp; + missing_lf = 0; +} + + +void +log_set_prefix (const char *text, unsigned int flags) +{ + if (text) + { + strncpy (prefix_buffer, text, sizeof (prefix_buffer)-1); + prefix_buffer[sizeof (prefix_buffer)-1] = 0; + } + + with_prefix = (flags & 1); + with_time = (flags & 2); + with_pid = (flags & 4); +} + +int +log_get_fd() +{ + return fileno(logstream?logstream:stderr); +} + +FILE * +log_get_stream () +{ + return logstream?logstream:stderr; +} + + +static void +do_logv( int level, const char *fmt, va_list arg_ptr ) +{ + if (!logstream) + logstream = stderr; + + if (missing_lf && level != JNLIB_LOG_CONT) + putc('\n', logstream ); + missing_lf = 0; + + if (level != JNLIB_LOG_CONT) + { /* Note this does not work for multiple line logging as we would + * need to print to a buffer first */ + if (with_time) + { + struct tm *tp; + time_t atime = time (NULL); + + tp = localtime (&atime); + fprintf (logstream, "%04d-%02d-%02d %02d:%02d:%02d ", + 1900+tp->tm_year, tp->tm_mon+1, tp->tm_mday, + tp->tm_hour, tp->tm_min, tp->tm_sec ); + } + if (with_prefix) + fputs (prefix_buffer, logstream); + if (with_pid) + fprintf (logstream, "[%u]", (unsigned int)getpid ()); + if (!with_time) + putc (':', logstream); + putc (' ', logstream); + } + + switch (level) + { + case JNLIB_LOG_BEGIN: break; + case JNLIB_LOG_CONT: break; + case JNLIB_LOG_INFO: break; + case JNLIB_LOG_WARN: break; + case JNLIB_LOG_ERROR: break; + case JNLIB_LOG_FATAL: fputs("Fatal: ",logstream ); break; + case JNLIB_LOG_BUG: fputs("Ohhhh jeeee: ", logstream); break; + case JNLIB_LOG_DEBUG: fputs("DBG: ", logstream ); break; + default: fprintf(logstream,"[Unknown log level %d]: ", level ); break; + } + + if (fmt) + { + vfprintf(logstream,fmt,arg_ptr) ; + if (*fmt && fmt[strlen(fmt)-1] != '\n') + missing_lf = 1; + } + + if (level == JNLIB_LOG_FATAL) + exit(2); + if (level == JNLIB_LOG_BUG) + abort(); +} + +static void +do_log( int level, const char *fmt, ... ) +{ + va_list arg_ptr ; + + va_start( arg_ptr, fmt ) ; + do_logv( level, fmt, arg_ptr ); + va_end(arg_ptr); +} + + +void +log_logv (int level, const char *fmt, va_list arg_ptr) +{ + do_logv (level, fmt, arg_ptr); +} + +void +log_info( const char *fmt, ... ) +{ + va_list arg_ptr ; + + va_start( arg_ptr, fmt ) ; + do_logv( JNLIB_LOG_INFO, fmt, arg_ptr ); + va_end(arg_ptr); +} + +void +log_error( const char *fmt, ... ) +{ + va_list arg_ptr ; + + va_start( arg_ptr, fmt ) ; + do_logv( JNLIB_LOG_ERROR, fmt, arg_ptr ); + va_end(arg_ptr); + /* protect against counter overflow */ + if( errorcount < 30000 ) + errorcount++; +} + + +void +log_fatal( const char *fmt, ... ) +{ + va_list arg_ptr ; + + va_start( arg_ptr, fmt ) ; + do_logv( JNLIB_LOG_FATAL, fmt, arg_ptr ); + va_end(arg_ptr); + abort(); /* never called, bugs it makes the compiler happy */ +} + +void +log_bug( const char *fmt, ... ) +{ + va_list arg_ptr ; + + va_start( arg_ptr, fmt ) ; + do_logv( JNLIB_LOG_BUG, fmt, arg_ptr ); + va_end(arg_ptr); + abort(); /* never called, but it makes the compiler happy */ +} + +void +log_debug( const char *fmt, ... ) +{ + va_list arg_ptr ; + + va_start( arg_ptr, fmt ) ; + do_logv( JNLIB_LOG_DEBUG, fmt, arg_ptr ); + va_end(arg_ptr); +} + + +void +log_printf (const char *fmt, ...) +{ + va_list arg_ptr; + + va_start (arg_ptr, fmt); + do_logv (fmt ? JNLIB_LOG_CONT : JNLIB_LOG_BEGIN, fmt, arg_ptr); + va_end (arg_ptr); +} + +/* Print a hexdump of BUFFER. With TEXT of NULL print just the raw + dump, with TEXT just an empty string, print a trailing linefeed, + otherwise print an entire debug line. */ +void +log_printhex (const char *text, const void *buffer, size_t length) +{ + if (text && *text) + log_debug ("%s ", text); + if (length) + { + const unsigned char *p = buffer; + log_printf ("%02X", *p); + for (length--, p++; length--; p++) + log_printf (" %02X", *p); + } + if (text) + log_printf ("\n"); +} + + +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ) +void +bug_at( const char *file, int line, const char *func ) +{ + do_log( JNLIB_LOG_BUG, + ("... this is a bug (%s:%d:%s)\n"), file, line, func ); + abort(); /* never called, but it makes the compiler happy */ +} +#else +void +bug_at( const char *file, int line ) +{ + do_log( JNLIB_LOG_BUG, + _("you found a bug ... (%s:%d)\n"), file, line); + abort(); /* never called, but it makes the compiler happy */ +} +#endif + diff --git a/tags/V0-3-4/jnlib/logging.h b/tags/V0-3-4/jnlib/logging.h new file mode 100644 index 0000000..7b7b8c8 --- /dev/null +++ b/tags/V0-3-4/jnlib/logging.h @@ -0,0 +1,74 @@ +/* logging.h + * Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef LIBJNLIB_LOGGING_H +#define LIBJNLIB_LOGGING_H + +#include +#include "mischelp.h" + + +int log_get_errorcount (int clear); +void log_set_file( const char *name ); +void log_set_prefix (const char *text, unsigned int flags); +int log_get_fd(void); +FILE *log_get_stream (void); + +#ifdef JNLIB_GCC_M_FUNCTION + void bug_at( const char *file, int line, const char *func ) JNLIB_GCC_A_NR; +# define BUG() bug_at( __FILE__ , __LINE__, __FUNCTION__ ) +#else + void bug_at( const char *file, int line ); +# define BUG() bug_at( __FILE__ , __LINE__ ) +#endif + +/* To avoid mandatory inclusion of stdarg and other stuff, do it only + if explicitly requested to do so. */ +#ifdef JNLIB_NEED_LOG_LOGV +#include +enum jnlib_log_levels { + JNLIB_LOG_BEGIN, + JNLIB_LOG_CONT, + JNLIB_LOG_INFO, + JNLIB_LOG_WARN, + JNLIB_LOG_ERROR, + JNLIB_LOG_FATAL, + JNLIB_LOG_BUG, + JNLIB_LOG_DEBUG +}; +void log_logv (int level, const char *fmt, va_list arg_ptr); +#endif /*JNLIB_NEED_LOG_LOGV*/ + + +void log_bug( const char *fmt, ... ) JNLIB_GCC_A_NR_PRINTF(1,2); +void log_fatal( const char *fmt, ... ) JNLIB_GCC_A_NR_PRINTF(1,2); +void log_error( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2); +void log_info( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2); +void log_debug( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2); +void log_printf( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2); +void log_printhex (const char *text, const void *buffer, size_t length); + + +#endif /*LIBJNLIB_LOGGING_H*/ + + + + + diff --git a/tags/V0-3-4/jnlib/mischelp.h b/tags/V0-3-4/jnlib/mischelp.h new file mode 100644 index 0000000..58c9250 --- /dev/null +++ b/tags/V0-3-4/jnlib/mischelp.h @@ -0,0 +1,43 @@ +/* mischelp.h + * Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef LIBJNLIB_MISCHELP_H +#define LIBJNLIB_MISCHHELP_H + + +#define DIM(v) (sizeof(v)/sizeof((v)[0])) +#define DIMof(type,member) DIM(((type *)0)->member) + + +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ) +# define JNLIB_GCC_M_FUNCTION 1 +# define JNLIB_GCC_A_NR __attribute__ ((noreturn)) +# define JNLIB_GCC_A_PRINTF( f, a ) __attribute__ ((format (printf,f,a))) +# define JNLIB_GCC_A_NR_PRINTF( f, a ) \ + __attribute__ ((noreturn, format (printf,f,a))) +#else +# define JNLIB_GCC_A_NR +# define JNLIB_GCC_A_PRINTF( f, a ) +# define JNLIB_GCC_A_NR_PRINTF( f, a ) +#endif + + + +#endif /*LIBJNLIB_MISCHELP_H*/ diff --git a/tags/V0-3-4/jnlib/stringhelp.c b/tags/V0-3-4/jnlib/stringhelp.c new file mode 100644 index 0000000..0d3035e --- /dev/null +++ b/tags/V0-3-4/jnlib/stringhelp.c @@ -0,0 +1,396 @@ +/* stringhelp.c - standard string helper functions + * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "libjnlib-config.h" +#include "stringhelp.h" + + +/**************** + * look for the substring SUB in buffer and return a pointer to that + * substring in BUF or NULL if not found. + * Comparison is case-insensitive. + */ +const char * +memistr( const char *buf, size_t buflen, const char *sub ) +{ + const byte *t, *s ; + size_t n; + + for( t=buf, n=buflen, s=sub ; n ; t++, n-- ) + if( toupper(*t) == toupper(*s) ) { + for( buf=t++, buflen = n--, s++; + n && toupper(*t) == toupper(*s); t++, s++, n-- ) + ; + if( !*s ) + return buf; + t = buf; n = buflen; s = sub ; + } + + return NULL ; +} + +/**************** + * Wie strncpy(), aber es werden maximal n-1 zeichen kopiert und ein + * '\0' angehängt. Ist n = 0, so geschieht nichts, ist Destination + * gleich NULL, so wird via jnlib_xmalloc Speicher besorgt, ist dann nicht + * genügend Speicher vorhanden, so bricht die funktion ab. + */ +char * +mem2str( char *dest , const void *src , size_t n ) +{ + char *d; + const char *s; + + if( n ) { + if( !dest ) + dest = jnlib_xmalloc( n ) ; + d = dest; + s = src ; + for(n--; n && *s; n-- ) + *d++ = *s++; + *d = '\0' ; + } + + return dest ; +} + + +/**************** + * remove leading and trailing white spaces + */ +char * +trim_spaces( char *str ) +{ + char *string, *p, *mark; + + string = str; + /* find first non space character */ + for( p=string; *p && isspace( *(byte*)p ) ; p++ ) + ; + /* move characters */ + for( (mark = NULL); (*string = *p); string++, p++ ) + if( isspace( *(byte*)p ) ) { + if( !mark ) + mark = string ; + } + else + mark = NULL ; + if( mark ) + *mark = '\0' ; /* remove trailing spaces */ + + return str ; +} + +/**************** + * remove trailing white spaces + */ +char * +trim_trailing_spaces( char *string ) +{ + char *p, *mark; + + for( mark = NULL, p = string; *p; p++ ) { + if( isspace( *(byte*)p ) ) { + if( !mark ) + mark = p; + } + else + mark = NULL; + } + if( mark ) + *mark = '\0' ; + + return string ; +} + + + +unsigned +trim_trailing_chars( byte *line, unsigned len, const char *trimchars ) +{ + byte *p, *mark; + unsigned n; + + for(mark=NULL, p=line, n=0; n < len; n++, p++ ) { + if( strchr(trimchars, *p ) ) { + if( !mark ) + mark = p; + } + else + mark = NULL; + } + + if( mark ) { + *mark = 0; + return mark - line; + } + return len; +} + +/**************** + * remove trailing white spaces and return the length of the buffer + */ +unsigned +trim_trailing_ws( byte *line, unsigned len ) +{ + return trim_trailing_chars( line, len, " \t\r\n" ); +} + + +/*************** + * Extract from a given path the filename component. + * + */ +char * +make_basename(const char *filepath) +{ + char *p; + + if ( !(p=strrchr(filepath, '/')) ) + #ifdef HAVE_DRIVE_LETTERS + if ( !(p=strrchr(filepath, '\\')) ) + if ( !(p=strrchr(filepath, ':')) ) + #endif + { + return jnlib_xstrdup(filepath); + } + + return jnlib_xstrdup(p+1); +} + + + +/*************** + * Extract from a given filename the path prepended to it. + * If their isn't a path prepended to the filename, a dot + * is returned ('.'). + * + */ +char * +make_dirname(const char *filepath) +{ + char *dirname; + int dirname_length; + char *p; + + if ( !(p=strrchr(filepath, '/')) ) + #ifdef HAVE_DRIVE_LETTERS + if ( !(p=strrchr(filepath, '\\')) ) + if ( !(p=strrchr(filepath, ':')) ) + #endif + { + return jnlib_xstrdup("."); + } + + dirname_length = p-filepath; + dirname = jnlib_xmalloc(dirname_length+1); + strncpy(dirname, filepath, dirname_length); + dirname[dirname_length] = 0; + + return dirname; +} + + + +/**************** + * Construct a filename from the NULL terminated list of parts. + * Tilde expansion is done here. + */ +char * +make_filename( const char *first_part, ... ) +{ + va_list arg_ptr ; + size_t n; + const char *s; + char *name, *home, *p; + + va_start( arg_ptr, first_part ) ; + n = strlen(first_part)+1; + while( (s=va_arg(arg_ptr, const char *)) ) + n += strlen(s) + 1; + va_end(arg_ptr); + + home = NULL; + if( *first_part == '~' && first_part[1] == '/' + && (home = getenv("HOME")) && *home ) + n += strlen(home); + + name = jnlib_xmalloc(n); + p = home ? stpcpy(stpcpy(name,home), first_part+1) + : stpcpy(name, first_part); + va_start( arg_ptr, first_part ) ; + while( (s=va_arg(arg_ptr, const char *)) ) + p = stpcpy(stpcpy(p,"/"), s); + va_end(arg_ptr); + + return name; +} + + +int +compare_filenames( const char *a, const char *b ) +{ + /* ? check whether this is an absolute filename and + * resolve symlinks? + */ + #ifdef HAVE_DRIVE_LETTERS + return stricmp(a,b); + #else + return strcmp(a,b); + #endif +} + + +/**************************************************** + ******** locale insensitive ctype functions ******** + ****************************************************/ +/* FIXME: replace them by a table lookup and macros */ +int +ascii_isupper (int c) +{ + return c >= 'A' && c <= 'Z'; +} + +int +ascii_islower (int c) +{ + return c >= 'a' && c <= 'z'; +} + +int +ascii_toupper (int c) +{ + if (c >= 'a' && c <= 'z') + c &= ~0x20; + return c; +} + +int +ascii_tolower (int c) +{ + if (c >= 'A' && c <= 'Z') + c |= 0x20; + return c; +} + + +int +ascii_strcasecmp( const char *a, const char *b ) +{ + if (a == b) + return 0; + + for (; *a && *b; a++, b++) { + if (*a != *b && ascii_toupper(*a) != ascii_toupper(*b)) + break; + } + return *a == *b? 0 : (ascii_toupper (*a) - ascii_toupper (*b)); +} + +int +ascii_memcasecmp( const char *a, const char *b, size_t n ) +{ + if (a == b) + return 0; + for ( ; n; n--, a++, b++ ) { + if( *a != *b && ascii_toupper (*a) != ascii_toupper (*b) ) + return *a == *b? 0 : (ascii_toupper (*a) - ascii_toupper (*b)); + } + return 0; +} + +int +ascii_strcmp( const char *a, const char *b ) +{ + if (a == b) + return 0; + + for (; *a && *b; a++, b++) { + if (*a != *b ) + break; + } + return *a == *b? 0 : (*(signed char *)a - *(signed char *)b); +} + + + +/********************************************* + ********** missing string functions ********* + *********************************************/ + +#ifndef HAVE_STPCPY +char * +stpcpy(char *a,const char *b) +{ + while( *b ) + *a++ = *b++; + *a = 0; + + return (char*)a; +} +#endif + +#ifndef HAVE_STRLWR +char * +strlwr(char *s) +{ + char *p; + for(p=s; *p; p++ ) + *p = tolower(*p); + return s; +} +#endif + + +#ifndef HAVE_STRCASECMP +int +strcasecmp( const char *a, const char *b ) +{ + for( ; *a && *b; a++, b++ ) { + if( *a != *b && toupper(*a) != toupper(*b) ) + break; + } + return *(const byte*)a - *(const byte*)b; +} +#endif + + +/**************** + * mingw32/cpd has a memicmp() + */ +#ifndef HAVE_MEMICMP +int +memicmp( const char *a, const char *b, size_t n ) +{ + for( ; n; n--, a++, b++ ) + if( *a != *b && toupper(*(const byte*)a) != toupper(*(const byte*)b) ) + return *(const byte *)a - *(const byte*)b; + return 0; +} +#endif + + + diff --git a/tags/V0-3-4/jnlib/stringhelp.h b/tags/V0-3-4/jnlib/stringhelp.h new file mode 100644 index 0000000..17a6ad0 --- /dev/null +++ b/tags/V0-3-4/jnlib/stringhelp.h @@ -0,0 +1,74 @@ +/* stringhelp.h + * Copyright (C) 1998,1999,2000,2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef LIBJNLIB_STRINGHELP_H +#define LIBJNLIB_STRINGHELP_H + +#include "types.h" + +const char *memistr( const char *buf, size_t buflen, const char *sub ); +char *mem2str( char *, const void *, size_t); +char *trim_spaces( char *string ); +char *trim_trailing_spaces( char *string ); +unsigned int trim_trailing_chars( unsigned char *line, unsigned len, + const char *trimchars); +unsigned int trim_trailing_ws( unsigned char *line, unsigned len ); + + +char *make_basename(const char *filepath); +char *make_dirname(const char *filepath); +char *make_filename( const char *first_part, ... ); +int compare_filenames( const char *a, const char *b ); + +const char *ascii_memistr( const char *buf, size_t buflen, const char *sub ); +int ascii_isupper (int c); +int ascii_islower (int c); +int ascii_toupper (int c); +int ascii_tolower (int c); +int ascii_strcasecmp( const char *a, const char *b ); +int ascii_memcasecmp( const char *a, const char *b, size_t n ); + + +#ifndef HAVE_MEMICMP +int memicmp( const char *a, const char *b, size_t n ); +#endif +#ifndef HAVE_STPCPY +char *stpcpy(char *a,const char *b); +#endif +#ifndef HAVE_STRLWR +char *strlwr(char *a); +#endif +#ifndef HAVE_STRTOUL + #define strtoul(a,b,c) ((unsigned long)strtol((a),(b),(c))) +#endif +#ifndef HAVE_MEMMOVE + #define memmove(d, s, n) bcopy((s), (d), (n)) +#endif +#ifndef HAVE_STRICMP + #define stricmp(a,b) strcasecmp( (a), (b) ) +#endif + +#ifndef STR + #define STR(v) #v +#endif +#define STR2(v) STR(v) + + +#endif /*LIBJNLIB_STRINGHELP_H*/ diff --git a/tags/V0-3-4/jnlib/strlist.c b/tags/V0-3-4/jnlib/strlist.c new file mode 100644 index 0000000..7cbaf5e --- /dev/null +++ b/tags/V0-3-4/jnlib/strlist.c @@ -0,0 +1,133 @@ +/* strlist.c - string helpers + * Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "libjnlib-config.h" +#include "strlist.h" + + +void +free_strlist( STRLIST sl ) +{ + STRLIST sl2; + + for(; sl; sl = sl2 ) { + sl2 = sl->next; + jnlib_free(sl); + } +} + + +STRLIST +add_to_strlist( STRLIST *list, const char *string ) +{ + STRLIST sl; + + sl = jnlib_xmalloc( sizeof *sl + strlen(string)); + sl->flags = 0; + strcpy(sl->d, string); + sl->next = *list; + *list = sl; + return sl; +} + +#if 0 +/**************** + * same as add_to_strlist() but if is_utf8 is *not* set a conversion + * to UTF8 is done + */ +STRLIST +add_to_strlist2( STRLIST *list, const char *string, int is_utf8 ) +{ + STRLIST sl; + + if( is_utf8 ) + sl = add_to_strlist( list, string ); + else { + char *p = native_to_utf8( string ); + sl = add_to_strlist( list, p ); + m_free( p ); + } + return sl; +} +#endif + +STRLIST +append_to_strlist( STRLIST *list, const char *string ) +{ + STRLIST r, sl; + + sl = jnlib_xmalloc( sizeof *sl + strlen(string)); + sl->flags = 0; + strcpy(sl->d, string); + sl->next = NULL; + if( !*list ) + *list = sl; + else { + for( r = *list; r->next; r = r->next ) + ; + r->next = sl; + } + return sl; +} + +#if 0 +STRLIST +append_to_strlist2( STRLIST *list, const char *string, int is_utf8 ) +{ + STRLIST sl; + + if( is_utf8 ) + sl = append_to_strlist( list, string ); + else { + char *p = native_to_utf8( string ); + sl = append_to_strlist( list, p ); + m_free( p ); + } + return sl; +} +#endif + +STRLIST +strlist_prev( STRLIST head, STRLIST node ) +{ + STRLIST n; + + for(n=NULL; head && head != node; head = head->next ) + n = head; + return n; +} + +STRLIST +strlist_last( STRLIST node ) +{ + if( node ) + for( ; node->next ; node = node->next ) + ; + return node; +} + + + diff --git a/tags/V0-3-4/jnlib/strlist.h b/tags/V0-3-4/jnlib/strlist.h new file mode 100644 index 0000000..53c0bc7 --- /dev/null +++ b/tags/V0-3-4/jnlib/strlist.h @@ -0,0 +1,43 @@ +/* strlist.h + * Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef LIBJNLIB_STRLIST_H +#define LIBJNLIB_STRLIST_H + +struct string_list { + struct string_list *next; + unsigned int flags; + char d[1]; +}; +typedef struct string_list *STRLIST; + + +void free_strlist( STRLIST sl ); +STRLIST add_to_strlist( STRLIST *list, const char *string ); +STRLIST add_to_strlist2( STRLIST *list, const char *string, int is_utf8 ); +STRLIST append_to_strlist( STRLIST *list, const char *string ); +STRLIST append_to_strlist2( STRLIST *list, const char *string, int is_utf8 ); +STRLIST strlist_prev( STRLIST head, STRLIST node ); +STRLIST strlist_last( STRLIST node ); + +#define FREE_STRLIST(a) do { free_strlist((a)); (a) = NULL ; } while(0) + + +#endif /*LIBJNLIB_STRLIST_H*/ diff --git a/tags/V0-3-4/jnlib/types.h b/tags/V0-3-4/jnlib/types.h new file mode 100644 index 0000000..230d150 --- /dev/null +++ b/tags/V0-3-4/jnlib/types.h @@ -0,0 +1,101 @@ +/* types.h + * Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef LIBJNLIB_TYPES_H +#define LIBJNLIB_TYPES_H + +/* The AC_CHECK_SIZEOF() in configure fails for some machines. + * we provide some fallback values here */ +#if !SIZEOF_UNSIGNED_SHORT + #undef SIZEOF_UNSIGNED_SHORT + #define SIZEOF_UNSIGNED_SHORT 2 +#endif +#if !SIZEOF_UNSIGNED_INT + #undef SIZEOF_UNSIGNED_INT + #define SIZEOF_UNSIGNED_INT 4 +#endif +#if !SIZEOF_UNSIGNED_LONG + #undef SIZEOF_UNSIGNED_LONG + #define SIZEOF_UNSIGNED_LONG 4 +#endif + + +#include + + +#ifndef HAVE_BYTE_TYPEDEF + #undef byte /* maybe there is a macro with this name */ + typedef unsigned char byte; + #define HAVE_BYTE_TYPEDEF +#endif + +#ifndef HAVE_USHORT_TYPEDEF + #undef ushort /* maybe there is a macro with this name */ + typedef unsigned short ushort; + #define HAVE_USHORT_TYPEDEF +#endif + +#ifndef HAVE_ULONG_TYPEDEF + #undef ulong /* maybe there is a macro with this name */ + typedef unsigned long ulong; + #define HAVE_ULONG_TYPEDEF +#endif + +#ifndef HAVE_U16_TYPEDEF + #undef u16 /* maybe there is a macro with this name */ + #if SIZEOF_UNSIGNED_INT == 2 + typedef unsigned int u16; + #elif SIZEOF_UNSIGNED_SHORT == 2 + typedef unsigned short u16; + #else + #error no typedef for u16 + #endif + #define HAVE_U16_TYPEDEF +#endif + +#ifndef HAVE_U32_TYPEDEF + #undef u32 /* maybe there is a macro with this name */ + #if SIZEOF_UNSIGNED_INT == 4 + typedef unsigned int u32; + #elif SIZEOF_UNSIGNED_LONG == 4 + typedef unsigned long u32; + #else + #error no typedef for u32 + #endif + #define HAVE_U32_TYPEDEF +#endif + +#ifndef HAVE_U64_TYPEDEF + #undef u64 /* maybe there is a macro with this name */ + #if SIZEOF_UNSIGNED_INT == 8 + typedef unsigned int u64; + #define HAVE_U64_TYPEDEF + #elif SIZEOF_UNSIGNED_LONG == 8 + typedef unsigned long u64; + #define HAVE_U64_TYPEDEF + #elif __GNUC__ >= 2 || defined(__SUNPRO_C) + typedef unsigned long long u64; + #define HAVE_U64_TYPEDEF + #endif +#endif + + + +#endif /*LIBJNLIB_TYPES_H*/ diff --git a/tags/V0-3-4/jnlib/xmalloc.c b/tags/V0-3-4/jnlib/xmalloc.c new file mode 100644 index 0000000..1cfaab9 --- /dev/null +++ b/tags/V0-3-4/jnlib/xmalloc.c @@ -0,0 +1,88 @@ +/* xmalloc.c - standard malloc wrappers + * Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include "libjnlib-config.h" +#include "xmalloc.h" + +static void +out_of_core(void) +{ + fputs("\nfatal: out of memory\n", stderr ); + exit(2); +} + + +void * +xmalloc( size_t n ) +{ + void *p = malloc( n ); + if( !p ) + out_of_core(); + return p; +} + +void * +xrealloc( void *a, size_t n ) +{ + void *p = realloc( a, n ); + if( !p ) + out_of_core(); + return p; +} + +void * +xcalloc( size_t n, size_t m ) +{ + void *p = calloc( n, m ); + if( !p ) + out_of_core(); + return p; +} + +char * +xstrdup( const char *string ) +{ + void *p = xmalloc( strlen(string)+1 ); + strcpy( p, string ); + return p; +} + + +char * +xstrcat2( const char *a, const char *b ) +{ + size_t n1; + char *p; + + if( !b ) + return xstrdup( a ); + + n1 = strlen(a); + p = xmalloc( n1 + strlen(b) + 1 ); + memcpy(p, a, n1 ); + strcpy(p+n1, b ); + return p; +} + diff --git a/tags/V0-3-4/jnlib/xmalloc.h b/tags/V0-3-4/jnlib/xmalloc.h new file mode 100644 index 0000000..150ef36 --- /dev/null +++ b/tags/V0-3-4/jnlib/xmalloc.h @@ -0,0 +1,31 @@ +/* xmalloc.h + * Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef LIBJNLIB_XMALLOC_H +#define LIBJNLIB_XMALLOC_H + +void *xmalloc( size_t n ); +void *xrealloc( void *a, size_t n ); +void *xcalloc( size_t n, size_t m ); +char *xstrdup( const char *string ); +char *xstrcat2( const char *a, const char *b ); + + +#endif /*LIBJNLIB_XMALLOC_H*/ diff --git a/tags/V0-3-4/tests/.cvsignore b/tags/V0-3-4/tests/.cvsignore new file mode 100644 index 0000000..a980df2 --- /dev/null +++ b/tags/V0-3-4/tests/.cvsignore @@ -0,0 +1,28 @@ +.gdb_history +Alpha +Bravo +Charlie +Delta +Echo +Foxtrot +Golf +Hotel +India +Juliet +Kilo +Lima +Makefile.in Makefile .deps .libs t-data t-version +Mike +November +Oscar +Papa +Quebec +Romeo +Sierra +Tango +Uniform +Victor +Whisky +XRay +Yankee +Zulu diff --git a/tags/V0-3-4/tests/ChangeLog b/tags/V0-3-4/tests/ChangeLog new file mode 100644 index 0000000..5769802 --- /dev/null +++ b/tags/V0-3-4/tests/ChangeLog @@ -0,0 +1,234 @@ +2002-03-04 Werner Koch + + * gpg/Makefile.am (DISTCLEANFILES): Added. + +2002-03-03 Marcus Brinkmann + + * gpg/t-verify.c (main): Add a few more sanity checks, and a check + for normal signatures. + +2002-02-26 Marcus Brinkmann + + * gpg/t-encrypt-sign.c: New file. + * gpg/Makefile.am (TESTS): Add t-encrypt-sign. + +2002-02-13 Werner Koch + + * gpgsm/Makefile.am (private-keys-v1.d): Don't + fail when the directory already exists. + +2002-02-12 Marcus Brinkmann + + * gpg/Makefile.am (CLEANFILES): New target. + (distclean-local): Rename to ... + (clean-local): ... this. + +2002-02-09 Marcus Brinkmann + + * gpgsm/Makefile.am (./private-keys-v1.d/$(key_id).key): Fix rule. + +2002-02-09 Marcus Brinkmann + + * gpgsm/t-genkey.c: New file (not added to Makefile.am because of + gpg-agent bug). + +2002-02-08 Marcus Brinkmann + + * gpgsm/Makefile.am (key_id): Update value. + (all-local): Add .key to keyid filename. + (./private-keys-v1.d/$(key_id)): Renamed to ... + (./private-keys-v1.d/$(key_id).key): ... this. + (all-local): Add ./gpgsm.conf, ./trustlist.txt. + (./gpgsm.conf, ./trustlist.txt): New target. + * gpgsm/567064FE6D14A17B2D811ABB407728BC558AA455: Renamed to ... + * gpgsm/32100C27173EF6E9C4E9A25D3D69F86D37A4F939: ... this. + +2002-01-30 Marcus Brinkmann + + * gpg/t-import.c (print_op_info): New function. + (main): Use it. + +2002-01-22 Marcus Brinkmann + + * gpg/t-signers.c (passphrase_cb): Change type of r_hd to void**. + * gpg/t-sign.c (passphrase_cb): Likewise. + * gpg/t-decrypt-verify.c (passphrase_cb): Likewise. + * gpg/t-decrypt.c (passphrase_cb): Likewise. + +2001-12-19 Marcus Brinkmann + + * gpg/t-decrypt-verify.c: Don't include `mcheck.h'. Reported by + Stéphane Corthésy. + +2001-12-19 Marcus Brinkmann + + * gpg/Makefile.am (EXTRA_DIST): Add missing line continuation. + +2001-12-19 Marcus Brinkmann + + * gpgsm/Makefile.am (EXTRA_DIST): Add $(key_id). + +2001-12-16 Marcus Brinkmann + + * gpgsm/Makefile: Rename `pubcerts.kbx' to `pubring.kbx'. + +2001-12-15 Marcus Brinkmann + + * gpgsm/t-keylist.c (check_two_contexts): Set protocols. + +2001-12-14 Marcus Brinkmann + + * gpgsm/t-sign.c: New file. + * gpgsm/Makefile.am (TESTS): Add t-sign. + +2001-12-14 Marcus Brinkmann + + * gpgsm/t-decrypt.c: New file. + * gpgsm/567064FE6D14A17B2D811ABB407728BC558AA455: Likewise. + * gpgsm/Makefile.am (TESTS): Add t-decrypt. + (key_id): New variable. + (all-local): New target ./private-keys-v1.d/$(key_id) added. + (./private-keys-v1.d/$(key_id)): New target. + +2001-12-14 Marcus Brinkmann + + * gpgsm/t-verify.c: New file. + * gpgsm/Makefile.am (TESTS): Add t-verify. + +2001-12-14 Marcus Brinkmann + + * gpg/Makefile.am (GPG): Set to @GPG_PATH@. + (./pubring.gpg): Use $(GPG) instead gpg. + (./secring.gpg): Likewise. + + * gpgsm/t-import.c (main): Remove third test case. + * gpgsm/Makefile.am (GPGSM): Set to @GPGSM@. + (all-local): New target. + (./pubcerts.kbx): Likewise. + * gpgsm/t-encrypt.c: New file. + * gpgsm/Makefile.am (TESTS): Add t-encrypt. + +2001-12-14 Marcus Brinkmann + + * gpgsm/t-keylist.c: New file. + * gpgsm/Makefile.am (TESTS): Add t-keylist. + +2001-12-13 Marcus Brinkmann + + * gpgsm/cert_dfn_pca01.der: New file. + * gpgsm/cert_dfn_pca15.der: Likewise. + * gpgsm/cert_g10code_test1.der: Likewise. + * gpgsm/t-import.c: Likewise. + * gpgsm/Makefile.am (EXTRADIST): Add new files. + (TESTS): Add t-import. + +2001-11-22 Marcus Brinkmann + + * gpg/: New directory. + * Makefile.am, t-verify.c, t-encrypt.c, t-signers.c, t-trustlist.c, + t-sign.c, t-keylist.c, t-import.c, t-genkey.c, t-export.c, + t-decrypt-verify.c, t-decrypt.c, t-version.c, t-data.c, mkdemodirs. + cipher-1.asc, cipher-2.asc, geheim.txt, pubdemo.asc, pubkey-1.asc, + secdemo.asc, seckey-1.asc): Move to sub directory gpg/. + + * gpg/Makefile.am (INCLUDES): Include gpgme/, not include/ and + intl/. + (LDD): Correct relative path to gpgme library. + (TESTS): Remove t-version and t-data. + * gpg/t-verify.c, gpg/t-encrypt.c, gpg/t-signers.c, gpg/t-trustlist.c, + gpg/t-sign.c, gpg/t-keylist.c, gpg/t-import.c, gpg/t-genkey.c, + gpg/t-export.c, gpg/t-decrypt-verify.c, gpg/t-decrypt.c, + t-version.c, t-data.c): Include gpgme.h, not "../gpgme/gpgme.h". + + * Makefile.am: New file. + * gpgsm/: New directory. + * gpgsm/Makefile.am: New file. + +2001-11-16 Marcus Brinkmann + + * Makefile.am (TESTS): Add t-decrypt-verify. + * t-decrypt-verify.c: New file. + * cipher-2.asc: Likewise. + +2001-11-02 Marcus Brinkmann + + * t-data.c: Include stddef.h. + (read_once_test): Change type of READ to size_t. + (read_test): Likewise. + (write_test): Likewise. + +2001-10-29 Marcus Brinkmann + + * t-signers.c: New file. + * Makefile.am (TESTS): Add t-signers. + +2001-10-22 Marcus Brinkmann + + * Makefile.am (TEST_ENVIRONMENT): Revert last change. + +2001-10-22 Marcus Brinkmann + + * Makefile.am (TEST_ENVIRONMENT): Set environment to $(srcdir), + not current directory. + +2001-10-22 Marcus Brinkmann + + * t-data.c (write_test): New function. + (main): Invoke write_test for all rounds except TEST_OUT_CB. + +2001-10-22 Marcus Brinkmann + + * Makefile.am (INCLUDES): Remove spurious duplicate to silence + automake. + +2001-10-16 Marcus Brinkmann + + * t-version.c: New file. + * t-data.c: Likewise. + * t-data-1.txt: Likewise. + * t-data-2.txt: Likewise. + * Makefile.am (TESTS): Add t-version, t-data. + +2001-09-17 Werner Koch + + * t-keylist.c (check_two_contexts): New. + +2001-09-03 Werner Koch + + * t-encrypt.c (print_op_info): New and use it after each operation.. + +2001-08-28 Werner Koch + + * t-sign.c (print_op_info): New and use it after each operation. + +2001-03-15 Werner Koch + + * t-keylist.c (doit): List subkeys too, show caps. + +2001-02-13 Werner Koch + + * t-verify.c (print_sig_stat): Repaled ulong by unsigned long + because we don't use the config stuff here. + +2001-02-12 Werner Koch + + * tests/t-verify.c (print_sig_stat): Print info about the keys. + + + Copyright 2001 g10 Code GmbH + + This file is free software; as a special exception the author gives + unlimited permission to copy and/or distribute it, with or without + modifications, as long as this notice is preserved. + + This file is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, to the extent permitted by law; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + + + + + + + \ No newline at end of file diff --git a/tags/V0-3-4/tests/Makefile.am b/tags/V0-3-4/tests/Makefile.am new file mode 100644 index 0000000..b367917 --- /dev/null +++ b/tags/V0-3-4/tests/Makefile.am @@ -0,0 +1,46 @@ +# Copyright (C) 2000 Werner Koch (dd9jn) +# Copyright (C) 2001 g10 Code GmbH +# +# This file is part of GPGME. +# +# GPGME is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# GPGME is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +## Process this file with automake to produce Makefile.in + +TESTS_ENVIRONMENT = GNUPGHOME=. + +TESTS = t-version t-data + +EXTRA_DIST = t-data-1.txt t-data-2.txt + +INCLUDES = -I$(top_srcdir)/gpgme + +LDADD = ../gpgme/libgpgme.la + +noinst_PROGRAMS = $(TESTS) + +if RUN_GPG_TESTS +gpgtests = gpg +else +gpgtests = +endif + +if RUN_GPGSM_TESTS +gpgsmtests = gpgsm +else +gpgsmtests = +endif + +SUBDIRS = ${gpgtests} ${gpgsmtests} diff --git a/tags/V0-3-4/tests/gpg/.cvsignore b/tags/V0-3-4/tests/gpg/.cvsignore new file mode 100644 index 0000000..c6c0c8e --- /dev/null +++ b/tags/V0-3-4/tests/gpg/.cvsignore @@ -0,0 +1,7 @@ +Makefile Makefile.in .deps .libs +Alpha Bravo Charlie Delta Echo Foxtrot Golf Hotel India Juliet Kilo +Lima Mike November Oscar Papa Quebec Romeo Sierra Tango Uniform Victor +Whisky XRay Yankee Zulu +pubring.gpg secring.gpg random_seed trustdb.gpg +t-decrypt t-decrypt-verify t-encrypt t-export t-genkey t-import +t-keylist t-sign t-signers t-trustlist t-verify diff --git a/tags/V0-3-4/tests/gpg/Makefile.am b/tags/V0-3-4/tests/gpg/Makefile.am new file mode 100644 index 0000000..f0c6f2b --- /dev/null +++ b/tags/V0-3-4/tests/gpg/Makefile.am @@ -0,0 +1,54 @@ +# Copyright (C) 2000 Werner Koch (dd9jn) +# Copyright (C) 2001 g10 Code GmbH +# +# This file is part of GPGME. +# +# GPGME is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# GPGME is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +## Process this file with automake to produce Makefile.in + +GPG = @GPG@ + +TESTS_ENVIRONMENT = GNUPGHOME=. + +TESTS = t-encrypt t-encrypt-sign t-sign t-signers t-decrypt t-verify \ + t-decrypt-verify t-keylist t-export t-import t-trustlist + +CLEANFILES = secring.gpg pubring.gpg trustdb.gpg random_seed +DISTCLEANFILES = pubring.gpg~ random_seed + +EXTRA_DIST = mkdemodirs pubdemo.asc secdemo.asc cipher-1.asc cipher-2.asc \ + geheim.txt pubkey-1.asc seckey-1.asc + +INCLUDES = -I$(top_srcdir)/gpgme + +LDADD = ../../gpgme/libgpgme.la + +# We don't run t-genkey in the test suite, because it takes too long +noinst_PROGRAMS = $(TESTS) t-genkey + +clean-local: + $(srcdir)/mkdemodirs --clean + +all-local: ./pubring.gpg ./secring.gpg + +./pubring.gpg: $(srcdir)/pubdemo.asc + $(GPG) --homedir . --import $(srcdir)/pubdemo.asc + +./secring.gpg: ./Alpha/Secret.gpg + $(GPG) --homedir . --allow-secret-key-import --import Alpha/Secret.gpg Zulu/Secret.gpg + +./Alpha/Secret.gpg: secdemo.asc + srcdir=$(srcdir) $(srcdir)/mkdemodirs diff --git a/tags/V0-3-4/tests/gpg/cipher-1.asc b/tags/V0-3-4/tests/gpg/cipher-1.asc new file mode 100644 index 0000000..f0a8ca4 --- /dev/null +++ b/tags/V0-3-4/tests/gpg/cipher-1.asc @@ -0,0 +1,15 @@ +-----BEGIN PGP MESSAGE----- +Version: GnuPG v1.0.4-2 (GNU/Linux) +Comment: For info see http://www.gnupg.org + +hQEOA2rm1+5GqHH4EAP/Tcqiuhvrjj+RFBKnWn2A7f1ztV17U2EngYFy8TbZYGNp +JoMNdpA7GNZs7iqc/x1epaZDKfaQwWEtARZmK/4nlhB48N+oZeKTm7PXIkRPqrCZ +3fxJjCJaU0yrNGuO345DOr0QwDImVhubVEkfgs8yXK2Szx2G8X3LmiaILHAqA2oD +/1ZqjY8k+ovrLL/qe8un/NTwzSjKIPVGR6mhLFXmj8fnp2kSsbo+Bhh4MczTRR6l +SA32z25vcakKu2qn5Wa4yDcx9NcMt8RHXzmfMDLj6UFq99QqKeLK2ywcIpY9p/GL +fQyaf7r3HTVugBSaoOzegLJ+L7MfWohrStkMeLnJQnro0nYBjADVcUQuSS4N3lst +Df3XrxxA/iJvxt4F9K27u4tp5U1HDg1CIxVrkMs92LBri3S6ZtfjdoqQ7QghFwGP +Kw1lKiWayM6NH9rcCKSgk4kl4P/2l3f78XeFgiywN7UGeSoH3BLMSv9gSxl5KrAz +d2imhTMrfEvZ +=y4ng +-----END PGP MESSAGE----- diff --git a/tags/V0-3-4/tests/gpg/cipher-2.asc b/tags/V0-3-4/tests/gpg/cipher-2.asc new file mode 100644 index 0000000..210f3e9 --- /dev/null +++ b/tags/V0-3-4/tests/gpg/cipher-2.asc @@ -0,0 +1,16 @@ +-----BEGIN PGP MESSAGE----- +Version: GnuPG v1.0.6 (GNU/Linux) +Comment: Weitere Infos: siehe http://www.gnupg.org + +hQEOA++dwnahcsiBEAP9HgkC1ElQwZRX1X/MBF54Q28dpXKr84IviO4QcbnnhmYk +2IlaNe6mr8R7kNM1aqJFK3fnobqnSWwM/VBObMqqYnzZSfclCNsy66sojQJxwXcz +DKQKi69BLaC6aTMnX048tOl8pJpR72fkffUOUa5ywDHVVVUClDG3XkIrfM1du3YD +/A6vFSrRylupKhQBxdtSUx5IDmpDYwG2vqqbYKoMaQ4pPSKLYV2zskU+pQWRlk6y +nwPGY5h9eGz0xYHMPxhe9VnwljeTEDwz5U4CHF3wQ8h5WBxOVx5QN/H/UyjpmoJT +ddrIu+8GgajhBVKVYAOqr577exkiSDA60/JrYbKZBvzL0sAJAUu+HoeMPJ+5/RYF +pLSdz/3MbVDRJJqzV2TJnEBvFtPa6urzx99P0u4xr+RJMFmR9/99YXhYz7+Y6d/B +44F6B3YouYxiK39IoOUcYPZTwb5kaudD5a3mU3XxEhSDUpnyvowPiKQO1T8CPd2u +2HsD3KeaOc2VFE0gnvqECvUTQfSCZCk/kil8XVAMHZrEA0bWAYiaHfHEOB8SRCy8 +rW0wsON4uDXmZpUkfOjFoYZdpJI7fDKkb5uYUzFZDasharEaXb1X/5xSAclx +=+eYk +-----END PGP MESSAGE----- diff --git a/tags/V0-3-4/tests/gpg/geheim.txt b/tags/V0-3-4/tests/gpg/geheim.txt new file mode 100644 index 0000000..99a5478 --- /dev/null +++ b/tags/V0-3-4/tests/gpg/geheim.txt @@ -0,0 +1,2 @@ +Wenn Sie dies lesen können, ist es wohl nicht +geheim genug. diff --git a/tags/V0-3-4/tests/gpg/mkdemodirs b/tags/V0-3-4/tests/gpg/mkdemodirs new file mode 100755 index 0000000..7c3bd04 --- /dev/null +++ b/tags/V0-3-4/tests/gpg/mkdemodirs @@ -0,0 +1,44 @@ +#!/bin/sh + +set -e + +GPG="gpg --batch --quiet --no-secmem-warning" +NAMES='Alpha Bravo Charlie Delta Echo Foxtrot Golf Hotel India + Juliet Kilo Lima Mike November Oscar Papa Quebec Romeo + Sierra Tango Uniform Victor Whisky XRay Yankee Zulu' + +if [ "$1" = "--clean" ]; then + (for i in $NAMES; do + [ -d $i ] && rm -r $i || true + done) || true + exit 0 +fi + +[ -z "$srcdir" ] && srcdir="../tests" + + +$GPG --dearmor -o secdemo.gpg --yes $srcdir/secdemo.asc +$GPG --dearmor -o pubdemo.gpg --yes $srcdir/pubdemo.asc +[ -f ./tdb.tmp ] && rm ./tdb.tmp +GPGDEMO="$GPG --homedir . --trustdb-name ./tdb.tmp --no-default-keyring + --keyring pubdemo.gpg --secret-keyring secdemo.gpg" +echo -n "Creating:" +for name in $NAMES; do + echo -n " $name" + [ -d $name ] && rm -r $name + mkdir $name + $GPGDEMO --export-secret-key -o - $name > $name/Secret.gpg + $GPG --homedir $name --allow-secret-key-import --import $name/Secret.gpg + $GPGDEMO --export -o - $name > $name/Public.gpg + $GPG --homedir $name --import $name/Public.gpg + [ -f $name/pubring.gpg~ ] && rm $name/pubring.gpg~ +done +echo "." +[ -f ./tdb.tmp ] && rm ./tdb.tmp +rm pubdemo.gpg secdemo.gpg + + + + + + diff --git a/tags/V0-3-4/tests/gpg/pubdemo.asc b/tags/V0-3-4/tests/gpg/pubdemo.asc new file mode 100644 index 0000000..d550f1a --- /dev/null +++ b/tags/V0-3-4/tests/gpg/pubdemo.asc @@ -0,0 +1,566 @@ +26 demo keys: + +pub 1024D/68697734 1999-03-08 Alpha Test (demo key) +uid Alice (demo key) +uid Alfa Test (demo key) +sub 1024g/46A871F8 1999-03-08 +pub 1024D/1AFDAB6C 1999-03-08 Charlie Test (demo key) +sub 1024g/BC43DA60 1999-03-08 +pub 1024D/FAEF6D1B 1999-03-08 Echo Test (demo key) +uid Eve (demo key) +uid Echelon (demo key) +sub 1024g/7272144D 1999-03-08 +pub 1024D/8FC282E6 1999-03-08 Golf Test (demo key) +sub 1024g/9DCAD354 1999-03-08 +pub 1024D/04259677 1999-03-08 India Test (demo key) +sub 1024g/61F76C73 1999-03-08 +pub 1024D/43C2D0C7 1999-03-08 Kilo Test (demo key) +sub 1024g/9AF64D02 1999-03-08 +pub 1024D/A9E3B0B2 1999-03-08 Bravo Test (demo key) +uid Bob (demo key) +sub 1024g/E29BA37F 1999-03-08 +pub 1024D/EB9DC9E6 1999-03-08 Delta Test (demo key) +sub 1024g/B0C45424 1999-03-08 +pub 1024D/7372E243 1999-03-08 Foxtrot Test (demo key) +sub 1024g/EE45198E 1999-03-08 +pub 1024D/34C6E3F1 1999-03-08 Hotel Test (demo key) +sub 1024g/D622AD0A 1999-03-08 +pub 1024D/D2699313 1999-03-08 Juliet Test (demo key) +sub 1024g/35F8F136 1999-03-08 +pub 1024D/B79103F8 1999-03-08 Lima Test (demo key) +sub 1024g/FE56350C 1999-03-08 +pub 1024D/BE5CF886 1999-03-08 Mike Test (demo key) +uid Mallory (demo key) +sub 1024g/4F31EAE8 1999-03-08 +pub 1024D/30CEC684 1999-03-08 November Test (demo key) +sub 1024g/8B70E472 1999-03-08 +pub 1024D/6D9732AC 1999-03-08 Oscar Test (demo key) +sub 1024g/2681619F 1999-03-08 +pub 1024D/3FF13206 1999-03-08 Papa test (demo key) +sub 1024g/63330D9C 1999-03-08 +pub 1024D/3C661C84 1999-03-08 Quebec Test (demo key) +sub 1024g/A029ACF4 1999-03-08 +pub 1024D/777FBED3 1999-03-08 Romeo Test (demo key) +sub 1024g/11D102EA 1999-03-08 +pub 1024D/A3AE3EA1 1999-03-08 Sierra Test (demo key) +sub 1024g/0F1B50B4 1999-03-08 +pub 1024D/85A81F38 1999-03-08 Tango Test (demo key) +sub 1024g/101C0402 1999-03-08 +pub 1024D/653244D6 1999-03-08 Uniform Test (demo key) +sub 1024g/5522BDB9 1999-03-08 +pub 1024D/61F04784 1999-03-08 Victor Test (demo key) +sub 1024g/07287134 1999-03-08 +pub 1024D/EC67DBDE 1999-03-08 Whisky Test (demo key) +sub 1024g/FD6E27F6 1999-03-08 +pub 1024D/567FB34A 1999-03-08 XRay Test (demo key) +sub 1024g/41E408BE 1999-03-08 +pub 1024D/4B11B25F 1999-03-08 Yankee Test (demo key) +sub 1024g/F7B080AD 1999-03-08 +pub 1024D/54ACD246 1999-03-08 Zulu Test (demo key) +sub 1024g/A172C881 1999-03-08 + +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v0.9.3 (GNU/Linux) +Comment: For info see http://www.gnupg.org + +mQGiBDbjjp4RBAC2ZbFDX0wmJI8yLDYQdIiZeAuHLmfyHsqXaLGUMZtWiAvn/hNp +ctwahmzKm5oXinHUvUkLOQ0s8rOlu15nhw4azc30rTP1LsIkn5zORNnFdgYC6RKy +hOeim/63+/yGtdnTm49lVfaCqwsEmBCEkXaeWDGq+ie1b89J89T6n/JquwCgoQkj +VeVGG+B/SzJ6+yifdHWQVkcD/RXDyLXX4+WHGP2aet51XlKojWGwsZmc9LPPYhwU +/RcUO7ce1QQb0XFlUVFBhY0JQpM/ty/kNi+aGWFzigbQ+HAWZkUvA8+VIAVneN+p ++SHhGIyLTXKpAYTq46AwvllZ5Cpvf02Cp/+W1aVyA0qnBWMyeIxXmR9HOi6lxxn5 +cjajA/9VZufOXWqCXkBvz4Oy3Q5FbjQQ0/+ty8rDn8OTaiPi41FyUnEi6LO+qyBS +09FjnZj++PkcRcXW99SNxmEJRY7MuNHt5wIvEH2jNEOJ9lszzZFBDbuwsjXHK35+ +lPbGEy69xCP26iEafysKKbRXJhE1C+tk8SnK+Gm62sivmK/5arQpQWxwaGEgVGVz +dCAoZGVtbyBrZXkpIDxhbHBoYUBleGFtcGxlLm5ldD6IVQQTEQIAF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D/kYcJ9/1ngY7C9pbbNWoV70PkEMO/qj67OIViWVPzUhIdURorbp +Ghuc3oBzUxOgial7IbISPRItDgg2oZoY4hqyQNx8Cj2ZZAzDpM2vCrQnWnVsdSBU +ZXN0IChkZW1vIGtleSkgPHp1bHVAZXhhbXBsZS5uZXQ+iFUEExECABUFAjbjtcsD +CwoDAxUDAgMWAgECF4AACgkQa8R3gFSs0kZA6wCeJUyRzuFbsZ0uQulvpgOIRTLT +KscAoLd3InVEj20peTUQ5b2NOimSXnKxuQENBDbjtfIQBADMfPDBQoMzv52Mmjb8 +SdaYKKNzqDd9K1oY2hcMSi+LcHag+KJFOyKBf3SoHmcU/vCEN+LyTgljYSKDmEf4 +wZ2+eLfqFgSdBJp2xm55ih+9CHXg3dXx9SbHiGJCIxfJaIsnNz3VmJGPDDjBlaf/ +hjl/7SZvR+MJpVLFPGjj7uOhTwADBQP/Sgv0abeCXVdVXwGEmhdV0VDo833IQRdR +u1yt+QLnWRMGTY1oQapsH6QLwYSZfDJlxbsBA3tfqKStpRSbdGNNTsK+RIehsGdd +i3sWGplRGm5Xt5KpkY/mc/tLFaYJNMqAgfWQcKlZHBp7EoWMgiRiDJUWq0TH1wRD +oPaRc+H5GdqIRgQYEQIABgUCNuO18gAKCRBrxHeAVKzSRn1jAKC5Gp5sHM9sWdZe +M6qfu54F2OwMQACfTjYXfpMApAROPkjhhFNqH0d8x5E= +=1N8S +-----END PGP PUBLIC KEY BLOCK----- diff --git a/tags/V0-3-4/tests/gpg/pubkey-1.asc b/tags/V0-3-4/tests/gpg/pubkey-1.asc new file mode 100644 index 0000000..bed1da3 --- /dev/null +++ b/tags/V0-3-4/tests/gpg/pubkey-1.asc @@ -0,0 +1,26 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v1.0.4b (GNU/Linux) +Comment: For info see http://www.gnupg.org + +mQGiBDo41NoRBADSfQazKGYf8nokq6zUKH/6INtV6MypSzSGmX2XErnARkIIPPYj +cQRQ8zCbGV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gRAgAGBQI6ONTdAAoJ +EK+CJE+c2f1VVJoAn36uPWUhCdGXbSLxGibYfBt7et71AJ9JgWeRlTDTIoXYN8J+ +qsPN0YCxtg== +=4+Yp +-----END PGP PUBLIC KEY BLOCK----- diff --git a/tags/V0-3-4/tests/gpg/secdemo.asc b/tags/V0-3-4/tests/gpg/secdemo.asc new file mode 100644 index 0000000..343453c --- /dev/null +++ b/tags/V0-3-4/tests/gpg/secdemo.asc @@ -0,0 +1,737 @@ +26 demo keys (passphrase is "abc"): + +sec 1024D/68697734 1999-03-08 Alpha Test (demo key) +uid Alice (demo key) +uid Alfa Test (demo key) +ssb 1024g/46A871F8 1999-03-08 +sec 1024D/1AFDAB6C 1999-03-08 Charlie Test (demo key) +ssb 1024g/BC43DA60 1999-03-08 +sec 1024D/FAEF6D1B 1999-03-08 Echo Test (demo key) +uid Eve (demo key) +uid Echelon (demo key) +ssb 1024g/7272144D 1999-03-08 +sec 1024D/8FC282E6 1999-03-08 Golf Test (demo key) +ssb 1024g/9DCAD354 1999-03-08 +sec 1024D/04259677 1999-03-08 India Test (demo key) +ssb 1024g/61F76C73 1999-03-08 +sec 1024D/43C2D0C7 1999-03-08 Kilo Test (demo key) +ssb 1024g/9AF64D02 1999-03-08 +sec 1024D/A9E3B0B2 1999-03-08 Bravo Test (demo key) +uid Bob (demo key) +ssb 1024g/E29BA37F 1999-03-08 +sec 1024D/EB9DC9E6 1999-03-08 Delta Test (demo key) +ssb 1024g/B0C45424 1999-03-08 +sec 1024D/7372E243 1999-03-08 Foxtrot Test (demo key) +ssb 1024g/EE45198E 1999-03-08 +sec 1024D/34C6E3F1 1999-03-08 Hotel Test (demo key) +ssb 1024g/D622AD0A 1999-03-08 +sec 1024D/D2699313 1999-03-08 Juliet Test (demo key) +ssb 1024g/35F8F136 1999-03-08 +sec 1024D/B79103F8 1999-03-08 Lima Test (demo key) +ssb 1024g/FE56350C 1999-03-08 +sec 1024D/BE5CF886 1999-03-08 Mike Test (demo key) +uid Mallory (demo key) +ssb 1024g/4F31EAE8 1999-03-08 +sec 1024D/30CEC684 1999-03-08 November Test (demo key) +ssb 1024g/8B70E472 1999-03-08 +sec 1024D/6D9732AC 1999-03-08 Oscar Test (demo key) +ssb 1024g/2681619F 1999-03-08 +sec 1024D/3FF13206 1999-03-08 Papa test (demo key) +ssb 1024g/63330D9C 1999-03-08 +sec 1024D/3C661C84 1999-03-08 Quebec Test (demo key) +ssb 1024g/A029ACF4 1999-03-08 +sec 1024D/777FBED3 1999-03-08 Romeo Test (demo key) +ssb 1024g/11D102EA 1999-03-08 +sec 1024D/A3AE3EA1 1999-03-08 Sierra Test (demo key) +ssb 1024g/0F1B50B4 1999-03-08 +sec 1024D/85A81F38 1999-03-08 Tango Test (demo key) +ssb 1024g/101C0402 1999-03-08 +sec 1024D/653244D6 1999-03-08 Uniform Test (demo key) +ssb 1024g/5522BDB9 1999-03-08 +sec 1024D/61F04784 1999-03-08 Victor Test (demo key) +ssb 1024g/07287134 1999-03-08 +sec 1024D/EC67DBDE 1999-03-08 Whisky Test (demo key) +ssb 1024g/FD6E27F6 1999-03-08 +sec 1024D/567FB34A 1999-03-08 XRay Test (demo key) +ssb 1024g/41E408BE 1999-03-08 +sec 1024D/4B11B25F 1999-03-08 Yankee Test (demo key) +ssb 1024g/F7B080AD 1999-03-08 +sec 1024D/54ACD246 1999-03-08 Zulu Test (demo key) +ssb 1024g/A172C881 1999-03-08 + +-----BEGIN PGP PRIVATE KEY BLOCK----- +Version: GnuPG v0.9.3 (GNU/Linux) +Comment: For info see http://www.gnupg.org + +lQHOBDbjjp4RBAC2ZbFDX0wmJI8yLDYQdIiZeAuHLmfyHsqXaLGUMZtWiAvn/hNp +ctwahmzKm5oXinHUvUkLOQ0s8rOlu15nhw4azc30rTP1LsIkn5zORNnFdgYC6RKy +hOeim/63+/yGtdnTm49lVfaCqwsEmBCEkXaeWDGq+ie1b89J89T6n/JquwCgoQkj +VeVGG+B/SzJ6+yifdHWQVkcD/RXDyLXX4+WH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5nFP7whDfi8k4JY2Eig5hH ++MGdvni36hYEnQSadsZueYofvQh14N3V8fUmx4hiQiMXyWiLJzc91ZiRjww4wZWn +/4Y5f+0mb0fjCaVSxTxo4+7joU8AAwUD/0oL9Gm3gl1XVV8BhJoXVdFQ6PN9yEEX +UbtcrfkC51kTBk2NaEGqbB+kC8GEmXwyZcW7AQN7X6ikraUUm3RjTU7CvkSHobBn +XYt7FhqZURpuV7eSqZGP5nP7SxWmCTTKgIH1kHCpWRwaexKFjIIkYgyVFqtEx9cE +Q6D2kXPh+Rna/wQBA3GTFCmP28PloZW7fHe9ipQEjson+R8J0cZFxO8B2k6Fas1C +pLvP8P0NdTIyitaiBUatIGDI8N22I6mqelpWZpTKZZymrDKe0n8h+rTNqb0uIt8F +R+6/1qFnL1k3E/+QxqS7VGkRz6xnT+la7OVrexXz18ynbpvzJMPe2SAPyqY+RSzW +wf5Z/bgM+A/ftNFfEencn7KIRgQYEQIABgUCNuO18gAKCRBrxHeAVKzSRn1jAJsF +3zuwZ09o7T0yZNm4zWcRGZvteACgroLrVdUuNxbdEllH4BbcvFB06zA= +=P9+G +-----END PGP PRIVATE KEY BLOCK----- diff --git a/tags/V0-3-4/tests/gpg/seckey-1.asc b/tags/V0-3-4/tests/gpg/seckey-1.asc new file mode 100644 index 0000000..3934804 --- /dev/null +++ b/tags/V0-3-4/tests/gpg/seckey-1.asc @@ -0,0 +1,30 @@ +-----BEGIN PGP PRIVATE KEY BLOCK----- +Version: GnuPG v1.0.4b (GNU/Linux) +Comment: For info see http://www.gnupg.org + +lQHPBDo41NoRBADSfQazKGYf8nokq6zUKH/6INtV6MypSzSGmX2XErnARkIIPPYj +cQRQ8zCbGV7ZU2ezVbzhFLUSJveE8PZUzzCrLp1O2NSyBTRcR5HVSXW95nJfY8eV +pOvZRAKul0BVLh81kYTsrfzaaCjh9VWNP26LoeN2r+PjZyktXe7gM3C4SwCgoTxK +WUVi9HoT2HCLY7p7oig5hEcEALdCJal0UYomX3nJapIVLVZ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bLDyIJkpt4fyD+6OaRoui9KZqXMNwt7i/XFIto/sWd/OK3S +IgZkAf8DAwKVpe92I5n5JGAHRuEKSSvGU+0my6zTf17bLWPpFPnICNJdaMfyx24Y +RZZa+nDpYrRznJ89vohGBBgRAgAGBQI6ONTeAAoJEK+CJE+c2f1V7iIAn0WsYyUV +Huz4ZZ/WxxN57Ku2Eqs9AJ9Klz9imzvZoUjuE9/Ihr0y56tVng== +=lKvj +-----END PGP PRIVATE KEY BLOCK----- diff --git a/tags/V0-3-4/tests/gpg/t-decrypt-verify.c b/tags/V0-3-4/tests/gpg/t-decrypt-verify.c new file mode 100644 index 0000000..bf407ee --- /dev/null +++ b/tags/V0-3-4/tests/gpg/t-decrypt-verify.c @@ -0,0 +1,146 @@ +/* t-decrypt-verify.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include + +struct passphrase_cb_info_s +{ + GpgmeCtx c; + int did_it; +}; + + +#define fail_if_err(a) do { if(a) { int my_errno = errno; \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + if ((a) == GPGME_File_Error) \ + fprintf (stderr, "\terrno=`%s'\n", strerror (my_errno)); \ + exit (1); } \ + } while(0) + +static void +print_data (GpgmeData dh) +{ + char buf[100]; + size_t nread; + GpgmeError err; + + err = gpgme_data_rewind (dh); + fail_if_err (err); + while (!(err = gpgme_data_read (dh, buf, 100, &nread))) + fwrite ( buf, nread, 1, stdout ); + if (err != GPGME_EOF) + fail_if_err (err); +} + +static const char * +passphrase_cb (void *opaque, const char *desc, void **r_hd) +{ + const char *pass; + + if ( !desc ) + { + /* Cleanup by looking at *r_hd. */ + return NULL; + } + + pass = "abc"; + fprintf (stderr, "%% requesting passphrase for `%s': ", desc); + fprintf (stderr, "sending `%s'\n", pass); + + return pass; +} + +static char * +mk_fname (const char *fname) +{ + const char *srcdir = getenv ("srcdir"); + char *buf; + + if (!srcdir) + srcdir = "."; + buf = malloc (strlen(srcdir) + strlen(fname) + 2); + if (!buf) + exit (8); + strcpy (buf, srcdir); + strcat (buf, "/"); + strcat (buf, fname); + return buf; +} + +int +main (int argc, char **argv) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in, out, pwdata = NULL; + struct passphrase_cb_info_s info; + const char *cipher_2_asc = mk_fname ("cipher-2.asc"); + GpgmeSigStat stat; + + do + { + err = gpgme_new (&ctx); + fail_if_err (err); + if (!getenv("GPG_AGENT_INFO")) + { + memset (&info, 0, sizeof info); + info.c = ctx; + gpgme_set_passphrase_cb (ctx, passphrase_cb, &info); + } + + err = gpgme_data_new_from_file (&in, cipher_2_asc, 1); + fail_if_err (err); + + err = gpgme_data_new (&out); + fail_if_err (err); + + err = gpgme_op_decrypt_verify (ctx, in, out, &stat); + fail_if_err (err); + + fflush (NULL); + fputs ("Begin Result:\n", stdout); + print_data (out); + fputs ("End Result.\n", stdout); + + if (stat != GPGME_SIG_STAT_GOOD) + { + fprintf (stderr, "Signature check failed unexpectedly.\n"); + exit (1); + } + + gpgme_data_release (in); + gpgme_data_release (out); + gpgme_data_release (pwdata); + gpgme_release (ctx); + } + while (argc > 1 && !strcmp (argv[1], "--loop")); + + return 0; +} + + diff --git a/tags/V0-3-4/tests/gpg/t-decrypt.c b/tags/V0-3-4/tests/gpg/t-decrypt.c new file mode 100644 index 0000000..e6bc099 --- /dev/null +++ b/tags/V0-3-4/tests/gpg/t-decrypt.c @@ -0,0 +1,139 @@ +/* t-encrypt.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include + +struct passphrase_cb_info_s { + GpgmeCtx c; + int did_it; +}; + + +#define fail_if_err(a) do { if(a) { int my_errno = errno; \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + if ((a) == GPGME_File_Error) \ + fprintf (stderr, "\terrno=`%s'\n", strerror (my_errno)); \ + exit (1); } \ + } while(0) + +static void +print_data ( GpgmeData dh ) +{ + char buf[100]; + size_t nread; + GpgmeError err; + + err = gpgme_data_rewind ( dh ); + fail_if_err (err); + while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { + fwrite ( buf, nread, 1, stdout ); + } + if (err != GPGME_EOF) + fail_if_err (err); +} + + +static const char * +passphrase_cb ( void *opaque, const char *desc, void **r_hd ) +{ + const char *pass; + + if ( !desc ) { + /* cleanup by looking at *r_hd */ + + + return NULL; + } + + pass = "abc"; + fprintf (stderr, "%% requesting passphrase for `%s': ", desc ); + fprintf (stderr, "sending `%s'\n", pass ); + + return pass; +} + + +static char * +mk_fname ( const char *fname ) +{ + const char *srcdir = getenv ("srcdir"); + char *buf; + + if (!srcdir) + srcdir = "."; + buf = malloc (strlen(srcdir) + strlen(fname) + 2 ); + if (!buf ) + exit (8); + strcpy (buf, srcdir); + strcat (buf, "/"); + strcat (buf, fname ); + return buf; +} + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in, out, pwdata = NULL; + struct passphrase_cb_info_s info; + const char *cipher_1_asc = mk_fname ("cipher-1.asc"); + + do { + err = gpgme_new (&ctx); + fail_if_err (err); + if ( !getenv("GPG_AGENT_INFO") ) { + memset ( &info, 0, sizeof info ); + info.c = ctx; + gpgme_set_passphrase_cb ( ctx, passphrase_cb, &info ); + } + + err = gpgme_data_new_from_file ( &in, cipher_1_asc, 1 ); + fail_if_err (err); + + err = gpgme_data_new ( &out ); + fail_if_err (err); + + err = gpgme_op_decrypt (ctx, in, out ); + fail_if_err (err); + + fflush (NULL); + fputs ("Begin Result:\n", stdout ); + print_data (out); + fputs ("End Result.\n", stdout ); + + gpgme_data_release (in); + gpgme_data_release (out); + gpgme_data_release (pwdata); + gpgme_release (ctx); + } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); + + return 0; +} + + diff --git a/tags/V0-3-4/tests/gpg/t-encrypt-sign.c b/tags/V0-3-4/tests/gpg/t-encrypt-sign.c new file mode 100644 index 0000000..a4620d2 --- /dev/null +++ b/tags/V0-3-4/tests/gpg/t-encrypt-sign.c @@ -0,0 +1,139 @@ +/* t-encrypt-sign.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + +static void +print_op_info (GpgmeCtx c) +{ + char *s = gpgme_get_op_info (c, 0); + + if (!s) + puts (""); + else { + puts (s); + free (s); + } +} + + +static void +print_data ( GpgmeData dh ) +{ + char buf[100]; + size_t nread; + GpgmeError err; + + err = gpgme_data_rewind ( dh ); + fail_if_err (err); + while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { + fwrite ( buf, nread, 1, stdout ); + } + if (err != GPGME_EOF) + fail_if_err (err); +} + + +static const char * +passphrase_cb ( void *opaque, const char *desc, void **r_hd ) +{ + const char *pass; + + if ( !desc ) { + /* cleanup by looking at *r_hd */ + + + return NULL; + } + + pass = "abc"; + fprintf (stderr, "%% requesting passphrase for `%s': ", desc ); + fprintf (stderr, "sending `%s'\n", pass ); + + return pass; +} + + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in, out; + GpgmeRecipients rset; + + err = gpgme_check_engine (); + fail_if_err (err); + puts ( gpgme_get_engine_info() ); + + do { + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_armor (ctx, 1); + if (!getenv("GPG_AGENT_INFO")) + gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL); + + err = gpgme_data_new_from_mem ( &in, "Hallo Leute\n", 12, 0 ); + fail_if_err (err); + + err = gpgme_data_new ( &out ); + fail_if_err (err); + + err = gpgme_recipients_new (&rset); + fail_if_err (err); + err = gpgme_recipients_add_name_with_validity (rset, "Bob", + GPGME_VALIDITY_FULL); + fail_if_err (err); + err = gpgme_recipients_add_name_with_validity (rset, "Alpha", + GPGME_VALIDITY_FULL); + fail_if_err (err); + + + err = gpgme_op_encrypt_sign (ctx, rset, in, out); + print_op_info (ctx); + fail_if_err (err); + + fflush (NULL); + fputs ("Begin Result:\n", stdout ); + print_data (out); + fputs ("End Result.\n", stdout ); + + gpgme_recipients_release (rset); + gpgme_data_release (in); + gpgme_data_release (out); + gpgme_release (ctx); + } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); + + return 0; +} + + diff --git a/tags/V0-3-4/tests/gpg/t-encrypt.c b/tags/V0-3-4/tests/gpg/t-encrypt.c new file mode 100644 index 0000000..06736b3 --- /dev/null +++ b/tags/V0-3-4/tests/gpg/t-encrypt.c @@ -0,0 +1,118 @@ +/* t-encrypt.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + +static void +print_op_info (GpgmeCtx c) +{ + char *s = gpgme_get_op_info (c, 0); + + if (!s) + puts (""); + else { + puts (s); + free (s); + } +} + + +static void +print_data ( GpgmeData dh ) +{ + char buf[100]; + size_t nread; + GpgmeError err; + + err = gpgme_data_rewind ( dh ); + fail_if_err (err); + while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { + fwrite ( buf, nread, 1, stdout ); + } + if (err != GPGME_EOF) + fail_if_err (err); +} + + + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in, out; + GpgmeRecipients rset; + + err = gpgme_check_engine (); + fail_if_err (err); + puts ( gpgme_get_engine_info() ); + + do { + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_armor (ctx, 1); + + err = gpgme_data_new_from_mem ( &in, "Hallo Leute\n", 12, 0 ); + fail_if_err (err); + + err = gpgme_data_new ( &out ); + fail_if_err (err); + + err = gpgme_recipients_new (&rset); + fail_if_err (err); + err = gpgme_recipients_add_name_with_validity (rset, "Bob", + GPGME_VALIDITY_FULL); + fail_if_err (err); + err = gpgme_recipients_add_name_with_validity (rset, "Alpha", + GPGME_VALIDITY_FULL); + fail_if_err (err); + + + err = gpgme_op_encrypt (ctx, rset, in, out ); + print_op_info (ctx); + fail_if_err (err); + + fflush (NULL); + fputs ("Begin Result:\n", stdout ); + print_data (out); + fputs ("End Result.\n", stdout ); + + gpgme_recipients_release (rset); + gpgme_data_release (in); + gpgme_data_release (out); + gpgme_release (ctx); + } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); + + return 0; +} + + diff --git a/tags/V0-3-4/tests/gpg/t-export.c b/tags/V0-3-4/tests/gpg/t-export.c new file mode 100644 index 0000000..373e9f5 --- /dev/null +++ b/tags/V0-3-4/tests/gpg/t-export.c @@ -0,0 +1,92 @@ +/* t-export.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + +static void +print_data ( GpgmeData dh ) +{ + char buf[100]; + size_t nread; + GpgmeError err; + + err = gpgme_data_rewind ( dh ); + fail_if_err (err); + while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { + fwrite ( buf, nread, 1, stdout ); + } + if (err != GPGME_EOF) + fail_if_err (err); +} + + + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData out; + GpgmeRecipients rset; + + do { + err = gpgme_new (&ctx); + fail_if_err (err); + + err = gpgme_data_new ( &out ); + fail_if_err (err); + + err = gpgme_recipients_new (&rset); + fail_if_err (err); + err = gpgme_recipients_add_name (rset, "Bob"); + fail_if_err (err); + err = gpgme_recipients_add_name (rset, "Alpha"); + fail_if_err (err); + + gpgme_set_armor (ctx, 1 ); + err = gpgme_op_export (ctx, rset, out ); + fail_if_err (err); + + fflush (NULL); + fputs ("Begin Result:\n", stdout ); + print_data (out); + fputs ("End Result.\n", stdout ); + + gpgme_recipients_release (rset); + gpgme_data_release (out); + gpgme_release (ctx); + } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); + + return 0; +} + + diff --git a/tags/V0-3-4/tests/gpg/t-genkey.c b/tags/V0-3-4/tests/gpg/t-genkey.c new file mode 100644 index 0000000..09206fb --- /dev/null +++ b/tags/V0-3-4/tests/gpg/t-genkey.c @@ -0,0 +1,84 @@ +/* t-genkey.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + + +static void +progress ( void *self, const char *what, int type, int current, int total) +{ + fprintf (stderr, "progress `%s' %d %d %d\n", what, type, current, total); +} + + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + const char *format; + char *parms; + int count = 0; + + do { + err = gpgme_new (&ctx); + fail_if_err (err); + + gpgme_set_progress_cb (ctx, progress, NULL); + + format = "\n" + "Key-Type: DSA\n" + "Key-Length: 1024\n" + "Subkey-Type: ELG-E\n" + "Subkey-Length: 1024\n" + "Name-Real: Joe Tester\n" + "Name-Comment: (pp=abc,try=%d)\n" + "Name-Email: joe@foo.bar\n" + "Expire-Date: 0\n" + "Passphrase: abc\n" + "\n"; + parms = malloc ( strlen (format) + 1 + 20 ); + if (!parms) + exit (8); + sprintf (parms, format, ++count ); + err = gpgme_op_genkey (ctx, parms, NULL, NULL ); + fail_if_err (err); + free (parms); + + gpgme_release (ctx); + } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); + + return 0; +} + + + diff --git a/tags/V0-3-4/tests/gpg/t-import.c b/tags/V0-3-4/tests/gpg/t-import.c new file mode 100644 index 0000000..7bf2124 --- /dev/null +++ b/tags/V0-3-4/tests/gpg/t-import.c @@ -0,0 +1,108 @@ +/* t-import.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include + + +#define fail_if_err(a) do { if(a) { int my_errno = errno; \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + if ((a) == GPGME_File_Error) \ + fprintf (stderr, "\terrno=`%s'\n", strerror (my_errno)); \ + exit (1); } \ + } while(0) + + +static char * +mk_fname ( const char *fname ) +{ + const char *srcdir = getenv ("srcdir"); + char *buf; + + if (!srcdir) + srcdir = "."; + buf = malloc (strlen(srcdir) + strlen(fname) + 2 ); + if (!buf ) + exit (8); + strcpy (buf, srcdir); + strcat (buf, "/"); + strcat (buf, fname ); + return buf; +} + + +static void +print_op_info (GpgmeCtx c) +{ + char *s = gpgme_get_op_info (c, 0); + + if (!s) + puts (""); + else { + puts (s); + free (s); + } +} + + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in; + const char *pubkey_1_asc = mk_fname ("pubkey-1.asc"); + const char *seckey_1_asc = mk_fname ("seckey-1.asc"); + + do { + err = gpgme_new (&ctx); + fail_if_err (err); + + err = gpgme_data_new_from_file ( &in, pubkey_1_asc, 1 ); + fail_if_err (err); + + err = gpgme_op_import (ctx, in ); + fail_if_err (err); + print_op_info (ctx); + + gpgme_data_release (in); + + err = gpgme_data_new_from_file ( &in, seckey_1_asc, 1 ); + fail_if_err (err); + + err = gpgme_op_import (ctx, in ); + fail_if_err (err); + print_op_info (ctx); + + gpgme_data_release (in); + gpgme_release (ctx); + } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); + + return 0; +} + + diff --git a/tags/V0-3-4/tests/gpg/t-keylist.c b/tags/V0-3-4/tests/gpg/t-keylist.c new file mode 100644 index 0000000..532a3ec --- /dev/null +++ b/tags/V0-3-4/tests/gpg/t-keylist.c @@ -0,0 +1,158 @@ +/* t-keylist.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + +static void +doit ( GpgmeCtx ctx, const char *pattern ) +{ + GpgmeError err; + GpgmeKey key; + + err = gpgme_op_keylist_start (ctx, pattern, 0 ); + fail_if_err (err); + + while ( !(err = gpgme_op_keylist_next ( ctx, &key )) ) { + char *p; + const char *s; + int i; + + printf ("\n", key ); + p = gpgme_key_get_as_xml ( key ); + if ( p ) { + fputs ( p, stdout ); + free (p); + } + else + fputs("\n", stdout ); + + + for (i=0; ; i++ ) { + s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, i ); + if (!s) + break; + printf ("\n", i, s ); + s = gpgme_key_get_string_attr (key, GPGME_ATTR_ALGO, NULL, i ); + printf ("\n", i, s ); + s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEY_CAPS, NULL, i ); + printf ("\n", i, s ); + } + for (i=0; ; i++ ) { + s = gpgme_key_get_string_attr (key, GPGME_ATTR_NAME, NULL, i ); + if (!s) + break; + printf ("\n", i, s ); + s = gpgme_key_get_string_attr (key, GPGME_ATTR_EMAIL, NULL, i ); + printf ("\n", i, s ); + s = gpgme_key_get_string_attr (key, GPGME_ATTR_COMMENT, NULL, i ); + printf ("\n", i, s ); + } + + fputs ("\n", stdout ); + + printf ("\n", key ); + gpgme_key_release (key); + } + if ( err != GPGME_EOF ) + fail_if_err (err); +} + + +/* + * Check that there are no problems when we are using two context for + * listing keys. + */ +static void +check_two_contexts (void) +{ + GpgmeError err; + GpgmeCtx ctx1, ctx2; + GpgmeKey key; + + err = gpgme_new(&ctx1); fail_if_err (err); + err = gpgme_op_keylist_start(ctx1, "", 1); fail_if_err (err); + err = gpgme_new(&ctx2); fail_if_err (err); + err = gpgme_op_keylist_start(ctx2, "", 1); fail_if_err (err); + + while ( (err=gpgme_op_keylist_next(ctx2, &key)) != GPGME_EOF) { + gpgme_key_release (key); + } + if (err != GPGME_EOF) + fail_if_err (err); + while ( (err=gpgme_op_keylist_next(ctx1, &key)) != GPGME_EOF) { + gpgme_key_release (key); + } + if (err != GPGME_EOF) + fail_if_err (err); +} + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + int loop = 0; + const char *pattern; + + if( argc ) { + argc--; argv++; + } + + if (argc && !strcmp( *argv, "--loop" ) ) { + loop = 1; + argc--; argv++; + } + pattern = argc? *argv : NULL; + + err = gpgme_check_engine(); + fail_if_err (err); + + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_keylist_mode (ctx, 1); /* no validity calculation */ + do { + fprintf (stderr, "** pattern=`%s'\n", pattern ); + doit ( ctx, pattern ); + } while ( loop ); + gpgme_release (ctx); + + check_two_contexts (); + + return 0; +} diff --git a/tags/V0-3-4/tests/gpg/t-sign.c b/tags/V0-3-4/tests/gpg/t-sign.c new file mode 100644 index 0000000..28c34dc --- /dev/null +++ b/tags/V0-3-4/tests/gpg/t-sign.c @@ -0,0 +1,154 @@ +/* t-sign.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + +static void +print_op_info (GpgmeCtx c) +{ + char *s = gpgme_get_op_info (c, 0); + + if (!s) + puts (""); + else { + puts (s); + free (s); + } +} + +static void +print_data ( GpgmeData dh ) +{ + char buf[100]; + size_t nread; + GpgmeError err; + + err = gpgme_data_rewind ( dh ); + fail_if_err (err); + while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { + fwrite ( buf, nread, 1, stdout ); + } + if (err != GPGME_EOF) + fail_if_err (err); +} + +static const char * +passphrase_cb ( void *opaque, const char *desc, void **r_hd ) +{ + const char *pass; + + if ( !desc ) { + /* cleanup by looking at *r_hd */ + + + return NULL; + } + + pass = "abc"; + fprintf (stderr, "%% requesting passphrase for `%s': ", desc ); + fprintf (stderr, "sending `%s'\n", pass ); + + return pass; +} + + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in, out; + + do { + err = gpgme_new (&ctx); + fail_if_err (err); + if ( !getenv("GPG_AGENT_INFO") ) { + gpgme_set_passphrase_cb ( ctx, passphrase_cb, NULL ); + } + + gpgme_set_textmode (ctx, 1); + gpgme_set_armor (ctx, 1); + + err = gpgme_data_new_from_mem ( &in, "Hallo Leute\n", 12, 0 ); + fail_if_err (err); + + /* first a normal signature */ + err = gpgme_data_new ( &out ); + fail_if_err (err); + err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_NORMAL ); + fail_if_err (err); + fflush (NULL); + fputs ("Begin Result:\n", stdout ); + print_op_info (ctx); + print_data (out); + fputs ("End Result.\n", stdout ); + gpgme_data_release (out); + gpgme_data_rewind (in); + + /* now a detached signature */ + err = gpgme_data_new ( &out ); + fail_if_err (err); + err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_DETACH ); + fail_if_err (err); + fflush (NULL); + print_op_info (ctx); + fputs ("Begin Result:\n", stdout ); + print_data (out); + fputs ("End Result.\n", stdout ); + gpgme_data_release (out); + gpgme_data_rewind (in); + + + /* And finally a cleartext signature */ + err = gpgme_data_new ( &out ); + fail_if_err (err); + err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_CLEAR ); + fail_if_err (err); + fflush (NULL); + print_op_info (ctx); + fputs ("Begin Result:\n", stdout ); + print_data (out); + fputs ("End Result.\n", stdout ); + gpgme_data_release (out); + gpgme_data_rewind (in); + + /* ready */ + gpgme_data_release (in); + gpgme_release (ctx); + } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); + + return 0; +} + + + + diff --git a/tags/V0-3-4/tests/gpg/t-signers.c b/tags/V0-3-4/tests/gpg/t-signers.c new file mode 100644 index 0000000..f3fa6f5 --- /dev/null +++ b/tags/V0-3-4/tests/gpg/t-signers.c @@ -0,0 +1,167 @@ +/* t-signers.c - Regression tests for the Gpgme multiple signers interface. + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + +static void +print_op_info (GpgmeCtx c) +{ + char *s = gpgme_get_op_info (c, 0); + + if (!s) + puts (""); + else + { + puts (s); + free (s); + } +} + +static void +print_data (GpgmeData dh) +{ + char buf[100]; + size_t nread; + GpgmeError err; + + err = gpgme_data_rewind (dh); + fail_if_err (err); + while (!(err = gpgme_data_read (dh, buf, 100, &nread))) + fwrite (buf, nread, 1, stdout); + if (err != GPGME_EOF) + fail_if_err (err); +} + +static const char * +passphrase_cb (void *opaque, const char *desc, void **r_hd) +{ + const char *pass; + + if (!desc) + { + /* cleanup by looking at *r_hd */ + return NULL; + } + + pass = "abc"; + fprintf (stderr, "%% requesting passphrase for `%s': ", desc); + fprintf (stderr, "sending `%s'\n", pass); + + return pass; +} + +int +main (int argc, char *argv[]) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in, out; + GpgmeKey key[2]; /* There are two secret keys in the test area. */ + + err = gpgme_new (&ctx); + fail_if_err (err); + err = gpgme_op_keylist_start (ctx, NULL, 1); + fail_if_err (err); + err = gpgme_op_keylist_next (ctx, &key[0]); + fail_if_err (err); + err = gpgme_op_keylist_next (ctx, &key[1]); + fail_if_err (err); + gpgme_release (ctx); + + do + { + err = gpgme_new (&ctx); + fail_if_err (err); + if (!getenv ("GPG_AGENT_INFO")) + gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL); + err = gpgme_signers_add (ctx, key[0]); + fail_if_err (err); + err = gpgme_signers_add (ctx, key[1]); + fail_if_err (err); + + gpgme_set_textmode (ctx, 1); + gpgme_set_armor (ctx, 1); + + err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0); + fail_if_err (err); + + + /* First a normal signature. */ + err = gpgme_data_new (&out); + fail_if_err (err); + err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_NORMAL); + fail_if_err (err); + fflush (NULL); + fputs ("Begin Result:\n", stdout); + print_op_info (ctx); + print_data (out); + fputs ("End Result.\n", stdout); + gpgme_data_release (out); + gpgme_data_rewind (in); + + /* Now a detached signature. */ + err = gpgme_data_new (&out); + fail_if_err (err); + err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_DETACH); + fail_if_err (err); + fflush (NULL); + print_op_info (ctx); + fputs ("Begin Result:\n", stdout); + print_data (out); + fputs ("End Result.\n", stdout); + gpgme_data_release (out); + gpgme_data_rewind (in); + + /* And finally a cleartext signature. */ + err = gpgme_data_new (&out); + fail_if_err (err); + err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_CLEAR); + fail_if_err (err); + fflush (NULL); + print_op_info (ctx); + fputs ("Begin Result:\n", stdout); + print_data (out); + fputs ("End Result.\n", stdout); + gpgme_data_release (out); + gpgme_data_rewind (in); + + /* Ready. */ + gpgme_data_release (in); + gpgme_release (ctx); + } + while (argc > 1 && !strcmp (argv[1], "--loop")); + + gpgme_key_release (key[0]); + gpgme_key_release (key[1]); + + return 0; +} diff --git a/tags/V0-3-4/tests/gpg/t-trustlist.c b/tags/V0-3-4/tests/gpg/t-trustlist.c new file mode 100644 index 0000000..a3c8152 --- /dev/null +++ b/tags/V0-3-4/tests/gpg/t-trustlist.c @@ -0,0 +1,90 @@ +/* t-trustlist.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + +static void +doit ( GpgmeCtx ctx, const char *pattern ) +{ + GpgmeError err; + GpgmeTrustItem item; + + err = gpgme_op_trustlist_start (ctx, pattern, 0 ); + fail_if_err (err); + + while ( !(err = gpgme_op_trustlist_next ( ctx, &item )) ) { + printf ("l=%d k=%s t=%d o=%s v=%s u=%s\n", + gpgme_trust_item_get_int_attr (item, GPGME_ATTR_LEVEL, NULL, 0 ), + gpgme_trust_item_get_string_attr (item, GPGME_ATTR_KEYID, NULL, 0 ), + gpgme_trust_item_get_int_attr (item, GPGME_ATTR_TYPE, NULL, 0 ), + gpgme_trust_item_get_string_attr (item, GPGME_ATTR_OTRUST, NULL, 0 ), + gpgme_trust_item_get_string_attr (item, GPGME_ATTR_VALIDITY, NULL, 0 ), + gpgme_trust_item_get_string_attr (item, GPGME_ATTR_USERID, NULL, 0 ) + ); + gpgme_trust_item_release (item); + } + if ( err != GPGME_EOF ) + fail_if_err (err); +} + + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + int loop = 0; + const char *pattern; + + if( argc ) { + argc--; argv++; + } + + if (argc && !strcmp( *argv, "--loop" ) ) { + loop = 1; + argc--; argv++; + } + pattern = argc? *argv : "alice"; + + err = gpgme_new (&ctx); + fail_if_err (err); + do { + fprintf (stderr, "** pattern=`%s'\n", pattern ); + doit ( ctx, pattern ); + } while ( loop ); + gpgme_release (ctx); + + return 0; +} + + + diff --git a/tags/V0-3-4/tests/gpg/t-verify.c b/tags/V0-3-4/tests/gpg/t-verify.c new file mode 100644 index 0000000..9e1b4bf --- /dev/null +++ b/tags/V0-3-4/tests/gpg/t-verify.c @@ -0,0 +1,226 @@ +/* t-verify.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include + +static const char test_text1[] = "Just GNU it!\n"; +static const char test_text1f[]= "Just GNU it?\n"; +static const char test_sig1[] = +#if 0 +"-----BEGIN PGP SIGNATURE-----\n" +"\n" +"iEYEABECAAYFAjoKgjIACgkQLXJ8x2hpdzQMSwCeO/xUrhysZ7zJKPf/FyXA//u1\n" +"ZgIAn0204PBR7yxSdQx6CFxugstNqmRv\n" +"=yku6\n" +"-----END PGP SIGNATURE-----\n" +#elif 0 +"-----BEGIN PGP SIGNATURE-----\n" +"Version: GnuPG v1.0.4-2 (GNU/Linux)\n" +"Comment: For info see http://www.gnupg.org\n" +"\n" +"iJcEABECAFcFAjoS8/E1FIAAAAAACAAkZm9vYmFyLjF0aGlzIGlzIGEgbm90YXRp\n" +"b24gZGF0YSB3aXRoIDIgbGluZXMaGmh0dHA6Ly93d3cuZ3Uub3JnL3BvbGljeS8A\n" +"CgkQLXJ8x2hpdzQLyQCbBW/fgU8ZeWSlWPM1F8umHX17bAAAoIfSNDSp5zM85XcG\n" +"iwxMrf+u8v4r\n" +"=88Zo\n" +"-----END PGP SIGNATURE-----\n" +#elif 1 +"-----BEGIN PGP SIGNATURE-----\n" +"\n" +"iN0EABECAJ0FAjoS+i9FFIAAAAAAAwA5YmFyw7bDpMO8w58gZGFzIHdhcmVuIFVt\n" +"bGF1dGUgdW5kIGpldHp0IGVpbiBwcm96ZW50JS1aZWljaGVuNRSAAAAAAAgAJGZv\n" +"b2Jhci4xdGhpcyBpcyBhIG5vdGF0aW9uIGRhdGEgd2l0aCAyIGxpbmVzGhpodHRw\n" +"Oi8vd3d3Lmd1Lm9yZy9wb2xpY3kvAAoJEC1yfMdoaXc0JBIAoIiLlUsvpMDOyGEc\n" +"dADGKXF/Hcb+AKCJWPphZCphduxSvrzH0hgzHdeQaA==\n" +"=nts1\n" +"-----END PGP SIGNATURE-----\n" +#endif +; +static const char test_sig2[] = +"-----BEGIN PGP MESSAGE-----\n" +"\n" +"owGbwMvMwCSoW1RzPCOz3IRxjXQSR0lqcYleSUWJTZOvjVdpcYmCu1+oQmaJIleH\n" +"GwuDIBMDGysTSIqBi1MApi+nlGGuwDeHao53HBr+FoVGP3xX+kvuu9fCMJvl6IOf\n" +"y1kvP4y+8D5a11ang0udywsA\n" +"=Crq6\n" +"-----END PGP MESSAGE-----\n"; + + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + + +static const char * +status_string (GpgmeSigStat status) +{ + const char *s = "?"; + + switch ( status ) { + case GPGME_SIG_STAT_NONE: + s = "None"; + break; + case GPGME_SIG_STAT_NOSIG: + s = "No Signature"; + break; + case GPGME_SIG_STAT_GOOD: + s = "Good"; + break; + case GPGME_SIG_STAT_BAD: + s = "Bad"; + break; + case GPGME_SIG_STAT_NOKEY: + s = "No Key"; + break; + case GPGME_SIG_STAT_ERROR: + s = "Error"; + break; + case GPGME_SIG_STAT_DIFF: + s = "More than one signature"; + break; + } + return s; +} + + +static void +print_sig_stat ( GpgmeCtx ctx, GpgmeSigStat status ) +{ + const char *s; + time_t created; + int idx; + GpgmeKey key; + + printf ("Verification Status: %s\n", status_string (status)); + + for(idx=0; (s=gpgme_get_sig_status (ctx, idx, &status, &created)); idx++ ) { + printf ("sig %d: created: %lu status: %s\n", idx, (unsigned long)created, + status_string(status) ); + printf ("sig %d: fpr/keyid=`%s'\n", idx, s ); + if ( !gpgme_get_sig_key (ctx, idx, &key) ) { + char *p = gpgme_key_get_as_xml ( key ); + printf ("sig %d: key object:\n%s\n", idx, p ); + free (p); + gpgme_key_release (key); + } + } +} + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData sig, text; + GpgmeSigStat status; + char *nota; + int n = 0; + int i, j; + + err = gpgme_new (&ctx); + fail_if_err (err); + + do { + err = gpgme_data_new_from_mem ( &text, + test_text1, strlen (test_text1), 0 ); + fail_if_err (err); + #if 1 + err = gpgme_data_new_from_mem ( &sig, + test_sig1, strlen (test_sig1), 0 ); + #else + err = gpgme_data_new_from_file ( &sig, "xx1", 1 ); + #endif + fail_if_err (err); + + puts ("checking a valid message:\n"); + err = gpgme_op_verify (ctx, sig, text, &status ); + fail_if_err (err); + print_sig_stat ( ctx, status ); + if (status != GPGME_SIG_STAT_GOOD) + { + fprintf (stderr, "%s:%d: Wrong sig stat\n", __FILE__, __LINE__); + exit (1); + } + + if ( (nota=gpgme_get_notation (ctx)) ) + printf ("---Begin Notation---\n%s---End Notation---\n", nota ); + + puts ("checking a manipulated message:\n"); + gpgme_data_release (text); + err = gpgme_data_new_from_mem ( &text, + test_text1f, strlen (test_text1f), 0 ); + fail_if_err (err); + gpgme_data_rewind ( sig ); + err = gpgme_op_verify (ctx, sig, text, &status ); + fail_if_err (err); + + print_sig_stat (ctx, status); + if (status != GPGME_SIG_STAT_BAD) + { + fprintf (stderr, "%s:%d: Wrong sig stat\n", __FILE__, __LINE__); + exit (1); + } + if ( (nota=gpgme_get_notation (ctx)) ) + printf ("---Begin Notation---\n%s---End Notation---\n", nota ); + + puts ("checking a normal signature:"); + gpgme_data_release (sig); + gpgme_data_release (text); + err = gpgme_data_new_from_mem (&sig, test_sig2, strlen (test_sig2), 0); + fail_if_err (err); + err = gpgme_data_new (&text); + fail_if_err (err); + err = gpgme_op_verify (ctx, sig, text, &status); + fail_if_err (err); + + nota = gpgme_data_release_and_get_mem (text, &i); + for (j = 0; j < i; j++) + putchar (nota[j]); + if (strncmp (nota, test_text1, strlen (test_text1))) + { + fprintf (stderr, "%s:%d: Wrong plaintext\n", __FILE__, __LINE__); + exit (1); + } + + print_sig_stat (ctx, status); + if (status != GPGME_SIG_STAT_GOOD) + { + fprintf (stderr, "%s:%d: Wrong sig stat\n", __FILE__, __LINE__); + exit (1); + } + + if ((nota = gpgme_get_notation (ctx))) + printf ("---Begin Notation---\n%s---End Notation---\n", nota); + + gpgme_data_release (sig); + +} while ( argc > 1 && !strcmp( argv[1], "--loop" ) && ++n < 20 ); + gpgme_release (ctx); + + return 0; +} diff --git a/tags/V0-3-4/tests/gpgsm/.cvsignore b/tags/V0-3-4/tests/gpgsm/.cvsignore new file mode 100644 index 0000000..66f7baa --- /dev/null +++ b/tags/V0-3-4/tests/gpgsm/.cvsignore @@ -0,0 +1,12 @@ +Makefile Makefile.in .deps .libs +gpg-agent.conf +private-keys-v1.d +pubring.gpg +pubring.kbx +secring.gpg +t-decrypt +t-encrypt +t-import +t-keylist +t-sign +t-verify diff --git a/tags/V0-3-4/tests/gpgsm/32100C27173EF6E9C4E9A25D3D69F86D37A4F939 b/tags/V0-3-4/tests/gpgsm/32100C27173EF6E9C4E9A25D3D69F86D37A4F939 new file mode 100644 index 0000000..cf0535f --- /dev/null +++ b/tags/V0-3-4/tests/gpgsm/32100C27173EF6E9C4E9A25D3D69F86D37A4F939 @@ -0,0 +1,18 @@ +(private-key + (oid.1.2.840.113549.1.1.1 + (n #00e0ce96f90b6c9e02f3922beada93fe50a875eac6bcc18bb9a9cf2e84965caa2d1ff95a7f542465c6c0c19d276e4526ce048868a7a914fd343cc3a87dd74291ffc565506d5bbb25cbac6a0e2dd1f8bcaab0d4a29c2f37c950f363484bf269f7891440464baf79827e03a36e70b814938eebdc63e964247be75dc58b014b7ea251#) + (e #010001#) + (d #046129F2489D71579BE0A75FE029BD6CDB574EBF57EA8A5B0FDA942CAB943B117D7BB95E5D28875E0F9FC5FCC06A72F6D502464DABDED78EF6B716177B83D5BDC543DC5D3FED932E59F5897E92E6F58A0F33424106A3B6FA2CBF877510E4AC21C3EE47851E97D12996222AC3566D4CCB0B83D164074ABF7DE655FC2446DA1781#) + (p #00e861b700e17e8afe6837e7512e35b6ca11d0ae47d8b85161c67baf64377213fe52d772f2035b3ca830af41d8a4120e1c1c70d12cc22f00d28d31dd48a8d424f1#) + (q #00f7a7ca5367c661f8e62df34f0d05c10c88e5492348dd7bddc942c9a8f369f935a07785d2db805215ed786e4285df1658eed3ce84f469b81b50d358407b4ad361#) + (u #304559a9ead56d2309d203811a641bb1a09626bc8eb36fffa23c968ec5bd891eebbafc73ae666e01ba7c8990bae06cc2bbe10b75e69fcacb353a6473079d8e9b#) + ) +) + + + + + + + + diff --git a/tags/V0-3-4/tests/gpgsm/Makefile.am b/tags/V0-3-4/tests/gpgsm/Makefile.am new file mode 100644 index 0000000..6985f8c --- /dev/null +++ b/tags/V0-3-4/tests/gpgsm/Makefile.am @@ -0,0 +1,54 @@ +# Copyright (C) 2000 Werner Koch (dd9jn) +# Copyright (C) 2001 g10 Code GmbH +# +# This file is part of GPGME. +# +# GPGME is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# GPGME is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +## Process this file with automake to produce Makefile.in + +GPGSM = @GPGSM@ + +TESTS_ENVIRONMENT = GNUPGHOME=. + +TESTS = t-import t-keylist t-encrypt t-verify t-decrypt t-sign + +EXTRA_DIST = cert_dfn_pca01.der cert_dfn_pca15.der cert_g10code_test1.der $(key_id) + +INCLUDES = -I$(top_srcdir)/gpgme + +LDADD = ../../gpgme/libgpgme.la + +noinst_PROGRAMS = $(TESTS) + +key_id := 32100C27173EF6E9C4E9A25D3D69F86D37A4F939 + +all-local: ./pubring.kbx ./gpg-agent.conf ./gpgsm.conf ./private-keys-v1.d/$(key_id).key ./trustlist.txt + +./pubring.kbx: $(srcdir)/cert_g10code_test1.der + $(GPGSM) --homedir . --import $(srcdir)/cert_g10code_test1.der + +./gpg-agent.conf: + echo batch > ./gpg-agent.conf + +./gpgsm.conf: + echo disable-crl-checks > ./gpgsm.conf + +./private-keys-v1.d/$(key_id).key: $(srcdir)/$(key_id) + test -d ./private-keys-v1.d || mkdir ./private-keys-v1.d + cp $(srcdir)/$(key_id) private-keys-v1.d/$(key_id).key + +./trustlist.txt: + echo $(key_id) > ./trustlist.txt diff --git a/tags/V0-3-4/tests/gpgsm/cert_dfn_pca01.der b/tags/V0-3-4/tests/gpgsm/cert_dfn_pca01.der new file mode 100644 index 0000000000000000000000000000000000000000..f8b61d339cc47f9028b5dc7b5709b57042ca891a GIT binary patch literal 1224 zcmXqLVmV^a#Jpw!GZP~d6Cdm#~COYH3Mvaz<*gf?IwOkWreKUYwU&Qe`M$zz0&oEzIuX=BFFr>}aTGpaT+N z7FGp{D1_t}DEOq7rRFF&rxulDre!84mSpDVDL9svWaJlRmQ;c*fw_W{QA{Wqtgh0b zAURPlB`r@cCDlMqoXgU}(7?#j(89pj&>%{j%fQgk$k-6d9klLlVpKv7Vn$X5<|amd z27@L>E~X|%MushUHzs|pzwzt(tPY90hhKdt&b~Zl_MQV}n}d%T6&+U2+_>CP*2F_r zxJK){K9|+AbHOQ_tv4PJe{)-?jO*Ork8eMgxV*3R5nrbLU#PCxQ~2tYpC?2fQ^#r}<{ZpE(;YZ*mapY>i>icscQq z)clTjCI1>P+hmu0ug^WvVtTw|!v3r|f23b(yiU;+dvo0K{zTu+Q{u09yU%|jHf7Gm zD}nF5I1Jue6~5dQa((NDHLeO`Tb?s9GcqtPZeo-MhKRUFeiK7MElu>mibezJVh`DF=&*m=Q=RP-S^}IkGZff&yyN zFUZfyOs)h;LRfkkCAm2U76>D_ShU47Lo!koh)Tl-iU^&|EF!=(oSvx<%q_{;x<#pF zdO)7Nfh0l+3k#1J7sMrc$wfH^{J{JoE6m9FpM}+c8Aus$g9P}&VZer*fPi@vn1C1= z6cXa1tt?`iQ_ZJ~AJm$v`ZlmtYKybImHscUEk|Dqc7~-N@7`D*Fg2As%(y7= N`o<=IH_=T~ngQcOx!V8$ literal 0 HcmV?d00001 diff --git a/tags/V0-3-4/tests/gpgsm/cert_dfn_pca15.der b/tags/V0-3-4/tests/gpgsm/cert_dfn_pca15.der new file mode 100644 index 0000000000000000000000000000000000000000..8d96650653bba1b4b41886f1f2bd8e332ec30173 GIT binary patch literal 1560 zcmXqLViPfFV)?UxnTe5!iBZ&mi;YvO&79)&ShX=XlP($Xl7z=WD*7B8X6iI8yH#`06~;N<0LA$TiZYr;%+67 zyMt4U%2JCcadZ=-5_0%5vNA9?G4eAQG%<29H8CPGAGQ`aI&S84_> zJ$GZ*$?ey^M0(`@Ibz8Ds^qI=?83<=Yj0hXwXe~gJ6*5gpOZ%B!@t7iZ12o^4Lg@URjS}x2n9GBP3 zyeNB_v&^6#BrVTUVNhmZxxjpZX`69INlAf~zJ7UmxgH`N=>wA!kf#q#Vfw|zIZz?J zN|4VWEWM19+#Fz{VnGnSgep) zTwI!(qL5UnP?C|V0L`;HU=A>=a^cOY3i)YZh3=_ExruoSL8-;5iABj7Tz;t~<@rU~ z3L3ad2_29{ntEIzKr6FTD;4s~^HPh{fsRQ@%_{+x0brLU0!suC7v$6wh0Hvz#N_1s zqLjqEWT4A4OEO>%RtV28%1KcO2WnObPfbz?00)SULK(2+F;GN=0yB#UurNu_)CU$@ z$=SL^sbzXVo;`A&1eSTgJjuwgF~(W*cT%r98pr=DO7xZ>F+IM-&b(DhvUxUeLJof0|2UKDhvPs literal 0 HcmV?d00001 diff --git a/tags/V0-3-4/tests/gpgsm/cert_g10code_test1.der b/tags/V0-3-4/tests/gpgsm/cert_g10code_test1.der new file mode 100644 index 0000000000000000000000000000000000000000..a2199d27b39d313f5a52ee04a004b2d2fcc13766 GIT binary patch literal 793 zcmXqLViq-MVyauf%*4pV#K>U4#m1@C=F#?@i; zEoPOj{LiTR5S7$p2M*3v&vR8f$I_9pe5J@=6Pv>;YOgy@{C_kxAUArq>ghFEe7YBZ z>{+$p%Az^?<|hL_Cwq8*%KY9b;^5}JzOt!~d2wFB4w1=yukR$kOi`(R9(%N#(YtO@ zAQLkq1LNYx69$b(4P=1D-YYcmKuBS;MLb99{*~T8`%FF?G)@J{E3-8A z8Z>q_U{$j)e@QM~!?p>S&Uir15@umFU}j|ej~vp#RL2Yq;+%FCxh{(px1`0>#atAk zxTaosSuQRe>7(=PwXgb)tfO4NAO8GSus>UVgHgfNwP`g?KAhG;Yh-e2Kfh4UP^p{p z&;P%orS;*%Z;e-ecrhb2X2U=3b&j1sR=!d%Q@avyC{9KFxBqha{g0FNCh2|(39e&t TY_*$Y)p{wdJ@E7ANE=B2c=iHE literal 0 HcmV?d00001 diff --git a/tags/V0-3-4/tests/gpgsm/t-decrypt.c b/tags/V0-3-4/tests/gpgsm/t-decrypt.c new file mode 100644 index 0000000..212fcf8 --- /dev/null +++ b/tags/V0-3-4/tests/gpgsm/t-decrypt.c @@ -0,0 +1,103 @@ +/* t-encrypt.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include + +static const char test_text1[] = "Hallo Leute!\n"; +static const char test_cip1[] = +"-----BEGIN CMS OBJECT-----\n" +"MIAGCSqGSIb3DQEHA6CAMIACAQAxggEJMIIBBQIBADBwMGsxCzAJBgNVBAYTAkRF\n" +"MRMwEQYDVQQHFApE/HNzZWxkb3JmMRYwFAYDVQQKEw1nMTAgQ29kZSBHbWJIMRkw\n" +"FwYDVQQLExBBZWd5cHRlbiBQcm9qZWN0MRQwEgYDVQQDEwt0ZXN0IGNlcnQgMQIB\n" +"ADALBgkqhkiG9w0BAQEEgYBOFcOfUtAav+XjKGM1RJtF+8JLkbnu46S3T3709Iok\n" +"u+Z9dwpOyfHwxXOmjzkSKQSBBxxi6ar+sKjU/KfPIvaMpARwT+NfIVSCZRWIJ27z\n" +"wbSrav/kcRRDDA0wXV7dHVmSLPUJNCpiFMNZbkYtI+ai15g0PVeDw+szYd9zdsjJ\n" +"2zCABgkqhkiG9w0BBwEwFAYIKoZIhvcNAwcECA8gPQY2NtJToIAECAeoY3MIcz9h\n" +"BAiiytWtOSmqnwAA\n" +"-----END CMS OBJECT-----\n"; + +#define fail_if_err(a) do { if(a) { int my_errno = errno; \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + if ((a) == GPGME_File_Error) \ + fprintf (stderr, "\terrno=`%s'\n", strerror (my_errno)); \ + exit (1); } \ + } while(0) + +static void +print_data ( GpgmeData dh ) +{ + char buf[100]; + size_t nread; + GpgmeError err; + + err = gpgme_data_rewind ( dh ); + fail_if_err (err); + while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { + fwrite ( buf, nread, 1, stdout ); + } + if (err != GPGME_EOF) + fail_if_err (err); +} + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in, out, pwdata = NULL; + + do { + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + + err = gpgme_data_new_from_mem ( &in, + test_cip1, strlen (test_cip1), 0 ); + fail_if_err (err); + + err = gpgme_data_new ( &out ); + fail_if_err (err); + + err = gpgme_op_decrypt (ctx, in, out ); + fail_if_err (err); + + fflush (NULL); + fputs ("Begin Result:\n", stdout ); + print_data (out); + fputs ("End Result.\n", stdout ); + + gpgme_data_release (in); + gpgme_data_release (out); + gpgme_data_release (pwdata); + gpgme_release (ctx); + } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); + + return 0; +} + + diff --git a/tags/V0-3-4/tests/gpgsm/t-encrypt.c b/tags/V0-3-4/tests/gpgsm/t-encrypt.c new file mode 100644 index 0000000..7b848d3 --- /dev/null +++ b/tags/V0-3-4/tests/gpgsm/t-encrypt.c @@ -0,0 +1,116 @@ +/* t-encrypt.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + +static void +print_op_info (GpgmeCtx c) +{ + char *s = gpgme_get_op_info (c, 0); + + if (!s) + puts (""); + else { + puts (s); + free (s); + } +} + + +static void +print_data ( GpgmeData dh ) +{ + char buf[100]; + size_t nread; + GpgmeError err; + + err = gpgme_data_rewind ( dh ); + fail_if_err (err); + while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { + fwrite ( buf, nread, 1, stdout ); + } + if (err != GPGME_EOF) + fail_if_err (err); +} + + + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in, out; + GpgmeRecipients rset; + + err = gpgme_check_engine (); + fail_if_err (err); + puts ( gpgme_get_engine_info() ); + + do { + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + gpgme_set_armor (ctx, 1); + + err = gpgme_data_new_from_mem ( &in, "Hallo Leute\n", 12, 0 ); + fail_if_err (err); + + err = gpgme_data_new ( &out ); + fail_if_err (err); + + err = gpgme_recipients_new (&rset); + fail_if_err (err); + err = gpgme_recipients_add_name_with_validity (rset, + "/CN=test cert 1,OU=Aegypten Project,O=g10 Code GmbH,L=Düsseldorf,C=DE", + GPGME_VALIDITY_FULL); + fail_if_err (err); + + err = gpgme_op_encrypt (ctx, rset, in, out ); + print_op_info (ctx); + fail_if_err (err); + + fflush (NULL); + fputs ("Begin Result:\n", stdout ); + print_data (out); + fputs ("End Result.\n", stdout ); + + gpgme_recipients_release (rset); + gpgme_data_release (in); + gpgme_data_release (out); + gpgme_release (ctx); + } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); + + return 0; +} + + diff --git a/tags/V0-3-4/tests/gpgsm/t-genkey.c b/tags/V0-3-4/tests/gpgsm/t-genkey.c new file mode 100644 index 0000000..3849f9e --- /dev/null +++ b/tags/V0-3-4/tests/gpgsm/t-genkey.c @@ -0,0 +1,85 @@ +/* t-genkey.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + + +static void +progress ( void *self, const char *what, int type, int current, int total) +{ + fprintf (stderr, "progress `%s' %d %d %d\n", what, type, current, total); +} + + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData pub; + char *result; + const char *format; + char *parms; + int count = 0; + int len, i; + + do { + err = gpgme_data_new (&pub); + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + gpgme_set_armor (ctx, 1); + gpgme_set_progress_cb (ctx, progress, NULL); + + format = "\n" + "Key-Type: RSA\n" + "Key-Length: 1024\n" + "Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe %d Tester\n" + "Name-Email: joe@foo.bar\n" + "\n"; + parms = malloc ( strlen (format) + 1 + 20 ); + if (!parms) + exit (8); + sprintf (parms, format, ++count ); + err = gpgme_op_genkey (ctx, parms, pub, NULL ); + fail_if_err (err); + free (parms); + + gpgme_release (ctx); + result = gpgme_data_release_and_get_mem (pub, &len); + for (i = 0; i < len; i++) + printf ("%c", result[i]); + free (result); + } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); + + return 0; +} diff --git a/tags/V0-3-4/tests/gpgsm/t-import.c b/tags/V0-3-4/tests/gpgsm/t-import.c new file mode 100644 index 0000000..f62ff00 --- /dev/null +++ b/tags/V0-3-4/tests/gpgsm/t-import.c @@ -0,0 +1,95 @@ +/* t-import.c - regression test + * Copyright (C) 2000 Werner Koch + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include + + +#define fail_if_err(a) do { if(a) { int my_errno = errno; \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + if ((a) == GPGME_File_Error) \ + fprintf (stderr, "\terrno=`%s'\n", strerror (my_errno)); \ + exit (1); } \ + } while(0) + +static char * +make_filename (const char *fname) +{ + const char *srcdir = getenv ("srcdir"); + char *buf; + + if (!srcdir) + srcdir = "."; + buf = malloc (strlen(srcdir) + strlen(fname) + 2 ); + if (!buf) + { + fprintf (stderr, "%s:%d: could not allocate string: %s\n", + __FILE__, __LINE__, strerror (errno)); + exit (1); + } + strcpy (buf, srcdir); + strcat (buf, "/"); + strcat (buf, fname); + return buf; +} + +int +main (int argc, char **argv) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in; + const char *cert_1 = make_filename ("cert_dfn_pca01.der"); + const char *cert_2 = make_filename ("cert_dfn_pca15.der"); + + do + { + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + + err = gpgme_data_new_from_file (&in, cert_1, 1); + fail_if_err (err); + + err = gpgme_op_import (ctx, in); + fail_if_err (err); + + gpgme_data_release (in); + + err = gpgme_data_new_from_file (&in, cert_2, 1); + fail_if_err (err); + + err = gpgme_op_import (ctx, in); + fail_if_err (err); + + gpgme_data_release (in); + gpgme_release (ctx); + } + while (argc > 1 && !strcmp (argv[1], "--loop")); + + return 0; +} diff --git a/tags/V0-3-4/tests/gpgsm/t-keylist.c b/tags/V0-3-4/tests/gpgsm/t-keylist.c new file mode 100644 index 0000000..7aafd84 --- /dev/null +++ b/tags/V0-3-4/tests/gpgsm/t-keylist.c @@ -0,0 +1,166 @@ +/* t-keylist.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + +static void +doit ( GpgmeCtx ctx, const char *pattern ) +{ + GpgmeError err; + GpgmeKey key; + + err = gpgme_op_keylist_start (ctx, pattern, 0 ); + fail_if_err (err); + + while ( !(err = gpgme_op_keylist_next ( ctx, &key )) ) { + char *p; + const char *s; + int i; + + printf ("\n", key ); + p = gpgme_key_get_as_xml ( key ); + if ( p ) { + fputs ( p, stdout ); + free (p); + } + else + fputs("\n", stdout ); + + + for (i=0; ; i++ ) { + s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, i ); + if (!s) + break; + printf ("\n", i, s ); + s = gpgme_key_get_string_attr (key, GPGME_ATTR_ALGO, NULL, i ); + printf ("\n", i, s ); + s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEY_CAPS, NULL, i ); + printf ("\n", i, s ); + } + for (i=0; ; i++ ) { + s = gpgme_key_get_string_attr (key, GPGME_ATTR_NAME, NULL, i ); + if (!s) + break; + printf ("\n", i, s ); + s = gpgme_key_get_string_attr (key, GPGME_ATTR_EMAIL, NULL, i ); + printf ("\n", i, s ); + s = gpgme_key_get_string_attr (key, GPGME_ATTR_COMMENT, NULL, i ); + printf ("\n", i, s ); + } + + fputs ("\n", stdout ); + + printf ("\n", key ); + gpgme_key_release (key); + } + if ( err != GPGME_EOF ) + fail_if_err (err); +} + + +/* + * Check that there are no problems when we are using two context for + * listing keys. + */ +static void +check_two_contexts (void) +{ + GpgmeError err; + GpgmeCtx ctx1, ctx2; + GpgmeKey key; + + err = gpgme_new(&ctx1); + fail_if_err (err); + gpgme_set_protocol (ctx1, GPGME_PROTOCOL_CMS); + + err = gpgme_op_keylist_start(ctx1, "", 1); + fail_if_err (err); + err = gpgme_new(&ctx2); fail_if_err (err); + gpgme_set_protocol (ctx2, GPGME_PROTOCOL_CMS); + err = gpgme_op_keylist_start(ctx2, "", 1); + fail_if_err (err); + + while ( (err=gpgme_op_keylist_next(ctx2, &key)) != GPGME_EOF) { + gpgme_key_release (key); + } + if (err != GPGME_EOF) + fail_if_err (err); + while ( (err=gpgme_op_keylist_next(ctx1, &key)) != GPGME_EOF) { + gpgme_key_release (key); + } + if (err != GPGME_EOF) + fail_if_err (err); +} + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + int loop = 0; + const char *pattern; + + if( argc ) { + argc--; argv++; + } + + if (argc && !strcmp( *argv, "--loop" ) ) { + loop = 1; + argc--; argv++; + } + pattern = argc? *argv : NULL; + + err = gpgme_check_engine(); + fail_if_err (err); + + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + + gpgme_set_keylist_mode (ctx, 1); /* no validity calculation */ + do { + fprintf (stderr, "** pattern=`%s'\n", pattern ); + doit ( ctx, pattern ); + } while ( loop ); + gpgme_release (ctx); + + check_two_contexts (); + + return 0; +} diff --git a/tags/V0-3-4/tests/gpgsm/t-sign.c b/tags/V0-3-4/tests/gpgsm/t-sign.c new file mode 100644 index 0000000..fd656a9 --- /dev/null +++ b/tags/V0-3-4/tests/gpgsm/t-sign.c @@ -0,0 +1,135 @@ +/* t-sign.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + +static void +print_op_info (GpgmeCtx c) +{ + char *s = gpgme_get_op_info (c, 0); + + if (!s) + puts (""); + else { + puts (s); + free (s); + } +} + +static void +print_data ( GpgmeData dh ) +{ + char buf[100]; + size_t nread; + GpgmeError err; + + err = gpgme_data_rewind ( dh ); + fail_if_err (err); + while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { + fwrite ( buf, nread, 1, stdout ); + } + if (err != GPGME_EOF) + fail_if_err (err); +} + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in, out; + + do { + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + gpgme_set_textmode (ctx, 1); + gpgme_set_armor (ctx, 1); + + err = gpgme_data_new_from_mem ( &in, "Hallo Leute!\n", 13, 0 ); + fail_if_err (err); + +#if 0 + /* first a normal signature */ + err = gpgme_data_new ( &out ); + fail_if_err (err); + err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_NORMAL ); + fail_if_err (err); + fflush (NULL); + fputs ("Begin Result:\n", stdout ); + print_op_info (ctx); + print_data (out); + fputs ("End Result.\n", stdout ); + gpgme_data_release (out); + gpgme_data_rewind (in); +#endif + + /* now a detached signature */ + err = gpgme_data_new ( &out ); + fail_if_err (err); + err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_DETACH ); + fail_if_err (err); + fflush (NULL); + print_op_info (ctx); + fputs ("Begin Result:\n", stdout ); + print_data (out); + fputs ("End Result.\n", stdout ); + gpgme_data_release (out); + gpgme_data_rewind (in); + + +#if 0 + /* And finally a cleartext signature */ + err = gpgme_data_new ( &out ); + fail_if_err (err); + err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_CLEAR ); + fail_if_err (err); + fflush (NULL); + print_op_info (ctx); + fputs ("Begin Result:\n", stdout ); + print_data (out); + fputs ("End Result.\n", stdout ); + gpgme_data_release (out); + gpgme_data_rewind (in); +#endif + + /* ready */ + gpgme_data_release (in); + gpgme_release (ctx); + } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); + + return 0; +} + + + + diff --git a/tags/V0-3-4/tests/gpgsm/t-verify.c b/tags/V0-3-4/tests/gpgsm/t-verify.c new file mode 100644 index 0000000..0fe94a2 --- /dev/null +++ b/tags/V0-3-4/tests/gpgsm/t-verify.c @@ -0,0 +1,161 @@ +/* t-verify.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include + +static const char test_text1[] = "Hallo Leute!\n"; +static const char test_text1f[]= "Hallo Leute?\n"; +static const char test_sig1[] = +"-----BEGIN CMS OBJECT-----\n" +"MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAA\n" +"MYIBOTCCATUCAQEwcDBrMQswCQYDVQQGEwJERTETMBEGA1UEBxQKRPxzc2VsZG9y\n" +"ZjEWMBQGA1UEChMNZzEwIENvZGUgR21iSDEZMBcGA1UECxMQQWVneXB0ZW4gUHJv\n" +"amVjdDEUMBIGA1UEAxMLdGVzdCBjZXJ0IDECAQAwBwYFKw4DAhqgJTAjBgkqhkiG\n" +"9w0BCQQxFgQU7FC/ibH3lC9GE24RJJxa8zqP7wEwCwYJKoZIhvcNAQEBBIGAA3oC\n" +"DUmKERmD1eoJYFw38y/qnncS/6ZPjWINDIphZeK8mzAANpvpIaRPf3sNBznb89QF\n" +"mRgCXIWcjlHT0DTRLBf192Ve22IyKH00L52CqFsSN3a2sajqRUlXH8RY2D+Al71e\n" +"MYdRclgjObCcoilA8fZ13VR4DiMJVFCxJL4qVWI=\n" +"-----END CMS OBJECT-----\n"; + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + + +static const char * +status_string (GpgmeSigStat status) +{ + const char *s = "?"; + + switch ( status ) { + case GPGME_SIG_STAT_NONE: + s = "None"; + break; + case GPGME_SIG_STAT_NOSIG: + s = "No Signature"; + break; + case GPGME_SIG_STAT_GOOD: + s = "Good"; + break; + case GPGME_SIG_STAT_BAD: + s = "Bad"; + break; + case GPGME_SIG_STAT_NOKEY: + s = "No Key"; + break; + case GPGME_SIG_STAT_ERROR: + s = "Error"; + break; + case GPGME_SIG_STAT_DIFF: + s = "More than one signature"; + break; + } + return s; +} + + +static void +print_sig_stat ( GpgmeCtx ctx, GpgmeSigStat status ) +{ + const char *s; + time_t created; + int idx; + GpgmeKey key; + + printf ("Verification Status: %s\n", status_string (status)); + + for(idx=0; (s=gpgme_get_sig_status (ctx, idx, &status, &created)); idx++ ) { + printf ("sig %d: created: %lu status: %s\n", idx, (unsigned long)created, + status_string(status) ); + printf ("sig %d: fpr/keyid=`%s'\n", idx, s ); + if ( !gpgme_get_sig_key (ctx, idx, &key) ) { + char *p = gpgme_key_get_as_xml ( key ); + printf ("sig %d: key object:\n%s\n", idx, p ); + free (p); + gpgme_key_release (key); + } + } +} + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData sig, text; + GpgmeSigStat status; + char *nota; + int n = 0; + + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + + do { + err = gpgme_data_new_from_mem ( &text, + test_text1, strlen (test_text1), 0 ); + fail_if_err (err); + err = gpgme_data_new_from_mem ( &sig, + test_sig1, strlen (test_sig1), 0 ); + fail_if_err (err); + + puts ("checking a valid message:\n"); + err = gpgme_op_verify (ctx, sig, text, &status ); + print_sig_stat ( ctx, status ); + print_sig_stat ( ctx, status ); + print_sig_stat ( ctx, status ); + print_sig_stat ( ctx, status ); + fail_if_err (err); + + if ( (nota=gpgme_get_notation (ctx)) ) + printf ("---Begin Notation---\n%s---End Notation---\n", nota ); + + puts ("checking a manipulated message:\n"); + gpgme_data_release (text); + err = gpgme_data_new_from_mem ( &text, + test_text1f, strlen (test_text1f), 0 ); + fail_if_err (err); + gpgme_data_rewind ( sig ); + err = gpgme_op_verify (ctx, sig, text, &status ); + + print_sig_stat ( ctx, status ); + fail_if_err (err); + if ( (nota=gpgme_get_notation (ctx)) ) + printf ("---Begin Notation---\n%s---End Notation---\n", nota ); + + gpgme_data_release (sig); + gpgme_data_release (text); + +} while ( argc > 1 && !strcmp( argv[1], "--loop" ) && ++n < 20 ); + gpgme_release (ctx); + + return 0; +} + + + diff --git a/tags/V0-3-4/tests/t-data-1.txt b/tags/V0-3-4/tests/t-data-1.txt new file mode 100644 index 0000000..16a15f2 --- /dev/null +++ b/tags/V0-3-4/tests/t-data-1.txt @@ -0,0 +1 @@ +Just GNU it! diff --git a/tags/V0-3-4/tests/t-data-2.txt b/tags/V0-3-4/tests/t-data-2.txt new file mode 100644 index 0000000..9ae851c --- /dev/null +++ b/tags/V0-3-4/tests/t-data-2.txt @@ -0,0 +1,3 @@ +Just GNU it! +Just GNU it! +Just GNU it! diff --git a/tags/V0-3-4/tests/t-data.c b/tags/V0-3-4/tests/t-data.c new file mode 100644 index 0000000..f3c769f --- /dev/null +++ b/tags/V0-3-4/tests/t-data.c @@ -0,0 +1,324 @@ +/* t-data - Regression tests for the GpgmeData abstraction. + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: (%i) GpgmeError " \ + "%s\n", __FILE__, __LINE__, round, \ + gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + +static char * +make_filename (const char *fname) +{ + const char *srcdir = getenv ("srcdir"); + char *buf; + + if (!srcdir) + srcdir = "."; + buf = malloc (strlen(srcdir) + strlen(fname) + 2 ); + if (!buf) + { + fprintf (stderr, "%s:%d: could not allocate string: %s\n", + __FILE__, __LINE__, strerror (errno)); + exit (1); + } + strcpy (buf, srcdir); + strcat (buf, "/"); + strcat (buf, fname); + return buf; +} + +typedef enum + { + TEST_INITIALIZER, + TEST_INVALID_ARGUMENT, + TEST_INOUT_NONE, + TEST_INOUT_MEM_NO_COPY, + TEST_INOUT_MEM_COPY, + TEST_INOUT_MEM_FROM_FILE_COPY, + TEST_INOUT_MEM_FROM_INEXISTANT_FILE, + TEST_INOUT_MEM_FROM_FILE_NO_COPY, + TEST_INOUT_MEM_FROM_FILE_PART_BY_NAME, + TEST_INOUT_MEM_FROM_INEXISTANT_FILE_PART, + TEST_INOUT_MEM_FROM_FILE_PART_BY_FP, + TEST_OUT_CB, + TEST_END + } round_t; + +const char *text = "Just GNU it!\n"; +const char *text2 = "Just GNU it!\nJust GNU it!\n"; + +int +read_cb (void *cb_value, char *buffer, size_t count, size_t *nread) +{ + static int off = 0; + int amount = strlen (text) - off; + /* round_t round = *((round_t *) cb_value); */ + + if (!buffer && !count && !nread) + { + /* Rewind requested. */ + off = 0; + return 0; + } + if (! buffer || !nread) + return -1; + if (amount <= 0) + { + /* End of file. */ + *nread = 0; + return -1; + } + if (amount > count) + amount = count; + memcpy (buffer, text, amount); + off += amount; + *nread = amount; + return 0; +} + +void +read_once_test (round_t round, GpgmeData data) +{ + GpgmeError err; + char buffer[1024]; + size_t read; + + err = gpgme_data_read (data, buffer, sizeof (buffer), &read); + fail_if_err (err); + + if (read != strlen (text) || strncmp (buffer, text, strlen (text))) + { + fprintf (stderr, "%s:%d: (%i) gpgme_data_read returned wrong data\n", + __FILE__, __LINE__, round); + exit (1); + } + + err = gpgme_data_read (data, buffer, sizeof (buffer), &read); + if (err != GPGME_EOF) + { + fprintf (stderr, "%s:%d: (%i) gpgme_data_read did not signal EOF\n", + __FILE__, __LINE__, round); + exit (1); + } +} + +void +read_test (round_t round, GpgmeData data) +{ + GpgmeError err; + char buffer[1024]; + size_t read; + + if (round == TEST_INOUT_NONE) + { + err = gpgme_data_read (data, buffer, sizeof (buffer), &read); + if (!err) + { + fprintf (stderr, "%s:%d: (%i) gpgme_data_read succeded unexpectedly\n", + __FILE__, __LINE__, round); + exit (1); + } + return; + } + + read_once_test (round, data); + err = gpgme_data_rewind (data); + fail_if_err (err); + read_once_test (round, data); +} + +void +write_test (round_t round, GpgmeData data) +{ + GpgmeError err; + char buffer[1024]; + size_t read; + + err = gpgme_data_write (data, text, strlen (text)); + fail_if_err (err); + + read_once_test (round, data); + err = gpgme_data_rewind (data); + fail_if_err (err); + + if (round == TEST_INOUT_NONE) + read_once_test (round, data); + else + { + err = gpgme_data_read (data, buffer, sizeof (buffer), &read); + fail_if_err (err); + + if (read != strlen (text2) || strncmp (buffer, text2, strlen (text2))) + { + fprintf (stderr, "%s:%d: (%i) gpgme_data_read returned wrong data\n", + __FILE__, __LINE__, round); + exit (1); + } + + err = gpgme_data_read (data, buffer, sizeof (buffer), &read); + if (err != GPGME_EOF) + { + fprintf (stderr, "%s:%d: (%i) gpgme_data_read did not signal EOF\n", + __FILE__, __LINE__, round); + exit (1); + } + } +} + +int +main (int argc, char **argv ) +{ + round_t round = TEST_INITIALIZER; + const char *text_filename = make_filename ("t-data-1.txt"); + const char *longer_text_filename = make_filename ("t-data-2.txt"); + const char *missing_filename = "this-file-surely-does-not-exist"; + GpgmeError err = GPGME_No_Error; + GpgmeData data; + + while (++round) + { + switch (round) + { + case TEST_INVALID_ARGUMENT: + err = gpgme_data_new (NULL); + if (!err) + { + fprintf (stderr, "%s:%d: gpgme_data_new on NULL pointer succeeded " + "unexpectedly\n", __FILE__, __LINE__); + exit (1); + } + if (gpgme_data_get_type (NULL) != GPGME_DATA_TYPE_NONE) + { + fprintf (stderr, "%s:%d: gpgme_data_get_type on NULL incorrect\n", + __FILE__, __LINE__); + exit (1); + } + continue; + case TEST_INOUT_NONE: + err = gpgme_data_new (&data); + break; + case TEST_INOUT_MEM_NO_COPY: + err = gpgme_data_new_from_mem (&data, text, strlen (text), 0); + break; + case TEST_INOUT_MEM_COPY: + err = gpgme_data_new_from_mem (&data, text, strlen (text), 1); + break; + case TEST_INOUT_MEM_FROM_FILE_COPY: + err = gpgme_data_new_from_file (&data, text_filename, 1); + break; + case TEST_INOUT_MEM_FROM_INEXISTANT_FILE: + err = gpgme_data_new_from_file (&data, missing_filename, 1); + if (!err) + { + fprintf (stderr, "%s:%d: gpgme_data_new_from_file on inexistant " + "file succeeded unexpectedly\n", __FILE__, __LINE__); + exit (1); + } + continue; + case TEST_INOUT_MEM_FROM_FILE_NO_COPY: + err = gpgme_data_new_from_file (&data, text_filename, 0); + /* This is not implemented yet. */ + if (err == GPGME_Not_Implemented) + continue; + break; + case TEST_INOUT_MEM_FROM_FILE_PART_BY_NAME: + err = gpgme_data_new_from_filepart (&data, longer_text_filename, 0, + strlen (text), strlen (text)); + break; + case TEST_INOUT_MEM_FROM_INEXISTANT_FILE_PART: + err = gpgme_data_new_from_filepart (&data, missing_filename, 0, + strlen (text), strlen (text)); + if (!err) + { + fprintf (stderr, "%s:%d: gpgme_data_new_from_file on inexistant " + "file succeeded unexpectedly\n", __FILE__, __LINE__); + exit (1); + } + continue; + case TEST_INOUT_MEM_FROM_FILE_PART_BY_FP: + { + FILE *fp = fopen (longer_text_filename, "rb"); + if (! fp) + { + fprintf (stderr, "%s:%d: fopen: %s\n", __FILE__, __LINE__, + strerror (errno)); + exit (1); + } + err = gpgme_data_new_from_filepart (&data, 0, fp, + strlen (text), strlen (text)); + } + break; + case TEST_OUT_CB: + err = gpgme_data_new_with_read_cb (&data, read_cb, &round); + break; + case TEST_END: + return 0; + case TEST_INITIALIZER: + /* Shouldn't happen. */ + fprintf (stderr, "%s:%d: impossible condition\n", __FILE__, __LINE__); + exit (1); + } + fail_if_err (err); + + switch (round) + { + case TEST_INOUT_NONE: + if (gpgme_data_get_type (data) != GPGME_DATA_TYPE_NONE) + err = GPGME_Invalid_Type; + break; + case TEST_INOUT_MEM_NO_COPY: + case TEST_INOUT_MEM_COPY: + case TEST_INOUT_MEM_FROM_FILE_COPY: + case TEST_INOUT_MEM_FROM_FILE_NO_COPY: + case TEST_INOUT_MEM_FROM_FILE_PART_BY_NAME: + case TEST_INOUT_MEM_FROM_FILE_PART_BY_FP: + if (gpgme_data_get_type (data) != GPGME_DATA_TYPE_MEM) + err = GPGME_Invalid_Type; + break; + case TEST_OUT_CB: + if (gpgme_data_get_type (data) != GPGME_DATA_TYPE_CB) + err = GPGME_Invalid_Type; + break; + case TEST_INITIALIZER: + case TEST_INVALID_ARGUMENT: + case TEST_INOUT_MEM_FROM_INEXISTANT_FILE: + case TEST_INOUT_MEM_FROM_INEXISTANT_FILE_PART: + case TEST_END: + /* Shouldn't happen. */ + fprintf (stderr, "%s:%d: impossible condition\n", __FILE__, __LINE__); + exit (1); + } + read_test (round, data); + if (round != TEST_OUT_CB) + write_test (round, data); + gpgme_data_release (data); + } + return 0; +} diff --git a/tags/V0-3-4/tests/t-version.c b/tags/V0-3-4/tests/t-version.c new file mode 100644 index 0000000..e674c2c --- /dev/null +++ b/tags/V0-3-4/tests/t-version.c @@ -0,0 +1,45 @@ +/* t-version.c - regression test + * Copyright (C) 2001 g10 Code GmbH + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +static const char version[] = VERSION; + +int +main (int argc, char **argv ) +{ + const char *null_result; + const char *current_result; + const char *future_result; + + null_result = gpgme_check_version (NULL); + current_result = gpgme_check_version (VERSION); + future_result = gpgme_check_version (VERSION ".1"); + + return !(null_result + && ! strcmp (null_result, VERSION) + && current_result + && ! strcmp (current_result, VERSION) + && ! future_result); +} -- 2.26.2