]> git.sommitrealweird.co.uk Git - onak.git/blob - sendsync.c
1d41d4d5434e5a542ba6a37be9638378943bf461
[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
9 #include <stdio.h>
10 #include <unistd.h>
11 #include <sys/types.h>
12 #include <sys/wait.h>
13
14 #include "armor.h"
15 #include "keystructs.h"
16 #include "ll.h"
17 #include "mem.h"
18 #include "onak-conf.h"
19 #include "parsekey.h"
20 #include "sendsync.h"
21
22 int fd_putchar(void *ctx, size_t count, void *c)
23 {
24         fwrite(c, sizeof(char), count, ctx);
25
26         return 0;
27 }
28
29 /**
30  *      sendkeysync - Send a key sync mail to our peers.
31  *      keys: The list of keys to send.
32  *
33  *      Takes a list of keys and sends out a keysync mail to all our peers.
34  */
35 int sendkeysync(struct openpgp_publickey *keys)
36 {
37         FILE                       *fd = NULL;
38         struct ll                  *cursite = NULL;
39         struct openpgp_packet_list *packets = NULL;
40         struct openpgp_packet_list *list_end = NULL;
41
42         if (config.syncsites != NULL &&
43                         (fd=popen(config.mta, "w")) != NULL) {
44                 fprintf(fd, "From: %s\n", config.adminemail);
45
46                 fprintf(fd, "To: ");
47                 for (cursite = config.syncsites; cursite != NULL;
48                                 cursite = cursite->next) {
49                         fprintf(fd, "%s", (char *) cursite->object);
50                         if (cursite->next != NULL) {
51                                 fprintf(fd, ", ");
52                         }
53                 }
54                 fprintf(fd, "\n");
55
56                 fprintf(fd, "Subject: incremental\n");
57                 fprintf(fd, "X-Keyserver-Sent: %s\n", config.thissite);
58                 fprintf(fd, "Precedence: list\n");
59                 fprintf(fd, "MIME-Version: 1.0\n");
60                 fprintf(fd, "Content-Type: application/pgp-keys\n\n");
61
62                 flatten_publickey(keys,
63                                 &packets,
64                                 &list_end);
65                 armor_openpgp_stream(fd_putchar,
66                                 fd,
67                                 packets);
68                 free_packet_list(packets);
69                 packets = NULL;
70
71                 pclose(fd);
72         } else return 0;
73
74         return 1;
75 }