Back to index

courier  0.68.2
export.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2001-2003 Double Precision, Inc.  See COPYING for
00003 ** distribution information.
00004 */
00005 
00006 
00007 #include      "config.h"
00008 #include      <stdio.h>
00009 #include      <stdlib.h>
00010 #include      <string.h>
00011 #include      <unistd.h>
00012 #include      <signal.h>
00013 #include      <errno.h>
00014 #include      <sys/types.h>
00015 #include      <sys/stat.h>
00016 #include      <sys/time.h>
00017 
00018 #include      "gpg.h"
00019 #include      "gpglib.h"
00020 
00021 #include      "unicode/unicode.h"
00022 #include      "numlib/numlib.h"
00023 
00024 extern int libmail_gpg_stdin, libmail_gpg_stdout, libmail_gpg_stderr;
00025 extern pid_t libmail_gpg_pid;
00026 
00027 /*
00028 ** List keys
00029 */
00030 
00031 int libmail_gpg_exportkey(const char *gpgdir,
00032                 int secret,
00033                 const char *fingerprint,
00034                 int (*out_func)(const char *, size_t, void *),
00035                 int (*err_func)(const char *, size_t, void *),
00036                 void *voidarg)
00037 {
00038        char *argvec[6];
00039        int rc;
00040 
00041        argvec[0]="gpg";
00042        argvec[1]="--armor";
00043        argvec[2]="--no-tty";
00044        argvec[3]= secret ? "--export-secret-keys":"--export";
00045        argvec[4]=(char *)fingerprint;
00046        argvec[5]=0;
00047 
00048        if (libmail_gpg_fork(&libmail_gpg_stdin, &libmail_gpg_stdout,
00049                           &libmail_gpg_stderr, gpgdir, argvec) < 0)
00050               rc= -1;
00051        else
00052        {
00053               int rc2;
00054 
00055               close(libmail_gpg_stdin);
00056               libmail_gpg_stdin=-1;
00057 
00058               rc=libmail_gpg_read(out_func, err_func, NULL, 0, voidarg);
00059               rc2=libmail_gpg_cleanup();
00060               if (rc2)
00061                      rc=rc2;
00062        }
00063        return (rc);
00064 }