Back to index

courier  0.68.2
checksign.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 ** Check signature.
00028 */
00029 
00030 static int dochecksign(int (*)(const char *, size_t, void *),
00031                   void *);
00032 
00033 int libmail_gpg_checksign(const char *gpgdir, const char *content,
00034                 const char *signature,
00035                 int (*dump_func)(const char *, size_t, void *),
00036                 void *voidarg)
00037 {
00038        char *argvec[10];
00039        int rc;
00040 
00041        argvec[0]="gpg";
00042        argvec[1]="--no-tty";
00043        argvec[2]="--verify";
00044        argvec[3]=(char *)signature;
00045        argvec[4]=(char *)content;
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               rc=dochecksign(dump_func, voidarg);
00056               rc2=libmail_gpg_cleanup();
00057               if (rc2)
00058                      rc=rc2;
00059        }
00060        return (rc);
00061 }
00062 
00063 static int dochecksign(int (*dump_func)(const char *, size_t, void *),
00064                   void *voidarg)
00065 {
00066        int rc=libmail_gpg_write("Y\n", 2, dump_func, NULL, NULL, 0, voidarg);
00067        int rc2;
00068 
00069        if (rc == 0)
00070               rc=libmail_gpg_read(dump_func, dump_func, NULL, 0, voidarg);
00071        rc2=libmail_gpg_cleanup();
00072        if (rc == 0)
00073               rc=rc2;
00074        return (rc);
00075 }