Back to index

courier  0.68.2
delete.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 ** Delete a key.
00028 */
00029 
00030 static int dodeletekey(int (*)(const char *, size_t, void *),
00031                      void *);
00032 
00033 int libmail_gpg_deletekey(const char *gpgdir, int secret,
00034                        const char *fingerprint,
00035                        int (*dump_func)(const char *, size_t, void *),
00036                        void *voidarg)
00037 {
00038        char *argvec[8];
00039        int rc;
00040 
00041        argvec[0]="gpg";
00042        argvec[1]="--command-fd";
00043        argvec[2]="0";
00044        argvec[3]= secret ? "--delete-secret-key":"--delete-key";
00045        argvec[4]="-q";
00046        argvec[5]="--no-tty";
00047        argvec[6]=(char *)fingerprint;
00048        argvec[7]=0;
00049 
00050        if (libmail_gpg_fork(&libmail_gpg_stdin, &libmail_gpg_stdout, NULL,
00051                           gpgdir, argvec) < 0)
00052               rc= -1;
00053        else
00054        {
00055               int rc2;
00056 
00057               rc=dodeletekey(dump_func, voidarg);
00058               rc2=libmail_gpg_cleanup();
00059               if (rc2)
00060                      rc=rc2;
00061        }
00062        return (rc);
00063 }
00064 
00065 static int dodeletekey(int (*dump_func)(const char *, size_t, void *),
00066                   void *voidarg)
00067 {
00068        int rc=libmail_gpg_write("Y\n", 2, dump_func, NULL, NULL, 0, voidarg);
00069        int rc2;
00070 
00071        if (rc == 0)
00072               rc=libmail_gpg_read(dump_func, NULL, NULL, 0, voidarg);
00073        rc2=libmail_gpg_cleanup();
00074        if (rc == 0)
00075               rc=rc2;
00076        return (rc);
00077 }