]> git.sommitrealweird.co.uk Git - onak.git/blob - sendsync.c
cscvs to tla changeset 120
[onak.git] / sendsync.c
1 /*
2  * sendsync.c - Routines to send a key sync mail.
3  *
4  * Jonathan McDowell <noodles@earth.li>
5  *
6  * Copyright 1999, 2002 Project Purple
7  *
8  * $Id: sendsync.c,v 1.2 2003/06/04 20:57:12 noodles Exp $
9  */
10
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <sys/types.h>
14 #include <sys/wait.h>
15
16 #include "armor.h"
17 #include "keystructs.h"
18 #include "ll.h"
19 #include "mem.h"
20 #include "onak-conf.h"
21 #include "parsekey.h"
22 #include "sendsync.h"
23
24 int fd_putchar(void *ctx, size_t count, unsigned char *c)
25 {
26         int i;
27
28         for (i = 0; i < count; i++) {
29                 fputc(c[i], ctx);
30         }
31         return 0;
32 }
33
34 /**
35  *      sendkeysync - Send a key sync mail to our peers.
36  *      keys: The list of keys to send.
37  *
38  *      Takes a list of keys and sends out a keysync mail to all our peers.
39  */
40 int sendkeysync(struct openpgp_publickey *keys)
41 {
42         FILE                       *fd = NULL;
43         struct ll                  *cursite = NULL;
44         struct openpgp_packet_list *packets = NULL;
45         struct openpgp_packet_list *list_end = NULL;
46
47         if (config.syncsites != NULL &&
48                         (fd=popen("sendmail -t", "w")) != NULL) {
49                 fprintf(fd, "From: %s\n", config.adminemail);
50
51                 fprintf(fd, "To: ");
52                 for (cursite = config.syncsites; cursite != NULL;
53                                 cursite = cursite->next) {
54                         fprintf(fd, "%s", (char *) cursite->object);
55                         if (cursite->next != NULL) {
56                                 fprintf(fd, ", ");
57                         }
58                 }
59                 fprintf(fd, "\n");
60
61                 fprintf(fd, "Subject: incremental\n");
62                 fprintf(fd, "X-Keyserver-Sent: %s\n", config.thissite);
63                 fprintf(fd, "Precedence: list\n");
64                 fprintf(fd, "MIME-Version: 1.0\n");
65                 fprintf(fd, "Content-Type: application/pgp-keys\n\n");
66
67                 flatten_publickey(keys,
68                                 &packets,
69                                 &list_end);
70                 armor_openpgp_stream(fd_putchar,
71                                 fd,
72                                 packets);
73                 free_packet_list(packets);
74                 packets = NULL;
75
76                 pclose(fd);
77         } else return 0;
78
79         return 1;
80 }