Back to index

courier  0.68.2
gpglib.h
Go to the documentation of this file.
00001 #ifndef       gpglib_h
00002 #define       gpglib_h
00003 /*
00004 ** Copyright 2001-2008 Double Precision, Inc.  See COPYING for
00005 ** distribution information.
00006 */
00007 
00008 
00009 #ifdef  __cplusplus
00010 extern "C" {
00011 #endif
00012 
00013 #include      "config.h"
00014 #include      <sys/types.h>
00015 #include      <stdlib.h>
00016 
00017 
00018 #define LIBMAIL_GPG_INDIVIDUAL     1
00019 #define LIBMAIL_GPG_ENCAPSULATE    2
00020 
00021 #define LIBMAIL_GPG_CHECKSIGN      1
00022 #define LIBMAIL_GPG_UNENCRYPT      2
00023 
00024 struct libmail_gpg_info {
00025 
00026        const char *gnupghome; /* May be NULL, sets GNUPGHOME */
00027 
00028        const char *passphrase_fd; /* NULL, or string giving */
00029 
00030        /*
00031        ** input_func gets called repeatedly to obtain the message to
00032        ** encrypt/sign/decrypt/check.  input_func() receives the same
00033        ** arguments as fgets(), with its third argument being input_func_arg.
00034        ** input_func should read up to cnt-1 bytes, or a newline, whichever
00035        ** comes first, and save read data in buf, appending a single null
00036        ** byte.  input_func should return 0, or -1 on EOF condition.
00037        */
00038        int (*input_func)(char *buf, size_t cnt, void *vp);
00039        void *input_func_arg;
00040 
00041        /*
00042        ** Output_func gets repeatedly invoked with the contents of the
00043        ** encrypted/signed/decrypted/verified message.
00044        */
00045 
00046        void (*output_func)(const char *output, size_t nbytes,
00047                          void *output_arg);
00048        void *output_func_arg; /* Passthru arg to output_func */
00049 
00050        /*
00051        ** In the event of an error, the error handler will be invoked with
00052        ** the error message text.  The error handler will be invoked
00053        ** just before libmail_gpg_*() exits.  Note that the memory used
00054        ** by the error message text will be destroyed by the time
00055        ** libmail_gpg_*() exits, so the application needs to make a copy of
00056        ** it, if it intends to use it later.
00057        */
00058 
00059        void (*errhandler_func)(const char *errmsg, void *errmsg_arg);
00060        void *errhandler_arg; /* Passthru arg to errhandler_func */
00061 
00062        /* Additional, arbitrary, arguments to GnuPG */
00063 
00064        int argc;
00065        char **argv;
00066 
00067        /* On exit, the following bits may be set: */
00068 
00069        int errstatus;
00070 
00071 #define LIBMAIL_ERR_VERIFYSIG 1
00072 #define LIBMAIL_ERR_DECRYPT 2
00073 
00074 };
00075 
00076 int libmail_gpg_signencode(int dosign,
00077                         int doencode,
00078                         /*
00079                         ** One of LIBMAIL_GPG_INDIVIDUAL or
00080                         ** LIBMAIL_GPG_ENCAPSULATE
00081                         */
00082                         struct libmail_gpg_info *options);
00083 
00084 int libmail_gpg_decode(int mode,
00085                      /*
00086                      ** LIBMAIL_GPG_UNENCRYPT OR LIBMAIL_GPG_CHECKSIGN
00087                      */
00088                      struct libmail_gpg_info *options);
00089 
00090 
00091        /* A convenient input_func, where vp is FILE * */
00092 
00093 int libmail_gpg_inputfunc_readfp(char *buf, size_t cnt, void *vp);
00094 
00095        /* Other functions: */
00096 
00097 int libmail_gpg_cleanup();
00098 int libmail_gpg_has_gpg(const char *gpgdir);
00099 
00100 int libmail_gpg_genkey(const char *gpgdir,
00101                      const char *charset,
00102                      const char *name,
00103                      const char *addr,
00104                      const char *comment,
00105                      int skeylen,
00106                      int ekeylen,
00107                      unsigned expire,
00108                      char expire_unit,
00109                      const char *passphrase,
00110 
00111                      int (*dump_func)(const char *, size_t, void *),
00112                      int (*timeout_func)(void *),
00113                      void *voidarg);
00114 
00115 struct gpg_list_info {
00116        const char *charset;
00117        const char *disabled_msg;
00118        const char *revoked_msg;
00119        const char *expired_msg;
00120        const char *group_msg;
00121        void *voidarg;
00122 } ;
00123 
00124 int libmail_gpg_listkeys(const char *gpgdir,
00125                int secret,
00126                int (*callback_func)(const char *, const char *,
00127                                   const char *, int,
00128                                   struct gpg_list_info *),
00129                int (*err_func)(const char *, size_t, void *),
00130                struct gpg_list_info *);
00131 
00132 int libmail_gpg_listgroups(const char *gpgdir,
00133                         int (*callback_func)(const char *, const char *,
00134                                           const char *,
00135                                           int,
00136                                           struct gpg_list_info *),
00137                         struct gpg_list_info *voidarg);
00138 
00139 int libmail_gpg_exportkey(const char *gpgdir,
00140                 int secret,
00141                 const char *fingerprint,
00142                 int (*out_func)(const char *, size_t, void *),
00143                 int (*err_func)(const char *, size_t, void *),
00144                 void *voidarg);
00145 
00146 int libmail_gpg_deletekey(const char *gpgdir, int secret, const char *fingerprint,
00147                 int (*dump_func)(const char *, size_t, void *),
00148                 void *voidarg);
00149 
00150 int libmail_gpg_signkey(const char *gpgdir, const char *signthis, const char *signwith,
00151               int passphrase_fd,
00152               int (*dump_func)(const char *, size_t, void *),
00153               int trustlevel,
00154               void *voidarg);
00155 
00156 int libmail_gpg_checksign(const char *gpgdir,
00157                 const char *content,      /* Filename, for now */
00158                 const char *signature, /* Filename, for now */
00159                 int (*dump_func)(const char *, size_t, void *),
00160                 void *voidarg);
00161 
00162        /* IMPORT A KEY */
00163 
00164 int libmail_gpg_import_start(const char *gpgdir, int issecret);
00165 
00166 int libmail_gpg_import_do(const char *p, size_t n,      /* Part of the key */
00167                 int (*dump_func)(const char *, size_t, void *),
00168                 /* gpg output callback */
00169 
00170                 void *voidarg);
00171 
00172 int libmail_gpg_import_finish(int (*dump_func)(const char *, size_t, void *),
00173                     void *voidarg);
00174 
00175 
00176 
00177             /* INTERNAL: */
00178 
00179 pid_t libmail_gpg_fork(int *, int *, int *, const char *, char **);
00180 
00181 #define GPGARGV_PASSPHRASE_FD(argv,i,fd,buf) \
00182        ((argv)[(i)++]="--passphrase-fd", \
00183         (argv)[(i)++]=libmail_str_size_t((fd),(buf)))
00184 
00185 int libmail_gpg_write(const char *, size_t,
00186              int (*)(const char *, size_t, void *),
00187              int (*)(const char *, size_t, void *),
00188              int (*)(void *),
00189              unsigned,
00190              void *);
00191 
00192 int libmail_gpg_read(int (*)(const char *, size_t, void *),
00193             int (*)(const char *, size_t, void *),
00194             int (*)(void *),
00195             unsigned,
00196             void *);
00197 
00198 char *libmail_gpg_options(const char *gpgdir);
00199        /* Filename of the options file.  If gpgdir is NULL try
00200        ** the environment variables. */
00201 
00202 
00203 struct rfc2045 *libmail_gpgmime_is_multipart_signed(const struct rfc2045 *);
00204        /*
00205        ** Return ptr to signed content if ptr is a multipart/signed.
00206        */
00207 
00208 struct rfc2045 *libmail_gpgmime_is_multipart_encrypted(const struct rfc2045 *);
00209        /*
00210        ** Return ptr to encrypted content if ptr is a multipart/encrypted.
00211        */
00212 
00213 int libmail_gpgmime_has_mimegpg(const struct rfc2045 *);
00214        /*
00215        ** Return non-zero if MIME content has any signed or encrypted
00216        ** content.
00217        */
00218 
00219 int libmail_gpgmime_is_decoded(const struct rfc2045 *, int *);
00220        /*
00221        ** Return non-zero if this is a multipart/mixed section generated
00222        ** by mimegpg, and return the GnuPG return code.
00223        */
00224 
00225 struct rfc2045 *libmail_gpgmime_decoded_content(const struct rfc2045 *);
00226        /*
00227        ** If is_decoded, then return the ptr to the decoded content.
00228        ** (note - if decryption failed, NULL is returned).
00229        */
00230 
00231 struct rfc2045 *libmail_gpgmime_signed_content(const struct rfc2045 *);
00232        /*
00233        ** If is_multipart_signed, return ptr to the signed content.
00234        */
00235 
00236 #ifdef  __cplusplus
00237 }
00238 #endif
00239 #endif