Back to index

courier  0.68.2
import.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      <sys/types.h>
00013 #include      <sys/stat.h>
00014 #include      <sys/time.h>
00015 
00016 #include      "gpg.h"
00017 #include      "gpglib.h"
00018 
00019 #include      "unicode/unicode.h"
00020 #include      "numlib/numlib.h"
00021 
00022 extern int libmail_gpg_stdin, libmail_gpg_stdout, libmail_gpg_stderr;
00023 extern pid_t libmail_gpg_pid;
00024 
00025 
00026 /*
00027 ** Import a key.
00028 */
00029 
00030 int libmail_gpg_import_start(const char *gpgdir, int secret)
00031 {
00032        char *argvec[5];
00033 
00034        argvec[0]="gpg";
00035        argvec[1]="--import";
00036        argvec[2]="--no-tty";
00037        argvec[3]=0;
00038 
00039 #if GPG_HAS_ALLOW_SECRET_KEY_IMPORT
00040        if (secret)
00041        {
00042               argvec[3]="--allow-secret-key-import";
00043               argvec[4]=0;
00044        }
00045 #endif
00046 
00047        if (libmail_gpg_fork(&libmail_gpg_stdin, &libmail_gpg_stdout, NULL, gpgdir, argvec) < 0)
00048               return (-1);
00049        return (0);
00050 }
00051 
00052 int libmail_gpg_import_do(const char *p, size_t n,
00053                 int (*dump_func)(const char *, size_t, void *),
00054                 void *voidarg)
00055 {
00056        if (libmail_gpg_write(p, n, dump_func, dump_func, NULL, 0, voidarg))
00057        {
00058               libmail_gpg_cleanup();
00059               return (-1);
00060        }
00061        return (0);
00062 }
00063 
00064 int libmail_gpg_import_finish(int (*dump_func)(const char *, size_t, void *),
00065                     void *voidarg)
00066 {
00067        if (libmail_gpg_read(dump_func, dump_func, NULL, 0, voidarg))
00068               return (-1);
00069        return (libmail_gpg_cleanup());
00070 }