Update Debian Vcs-* fields to point to git repository
[onak.git] / sendsync.c
1 /*
2  * sendsync.c - Routines to send a key sync mail.
3  *
4  * Copyright 1999, 2002, 2005, 2011 Jonathan McDowell <noodles@earth.li>
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc., 51
17  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <sys/types.h>
23 #include <sys/wait.h>
24
25 #include "armor.h"
26 #include "keystructs.h"
27 #include "ll.h"
28 #include "mem.h"
29 #include "onak-conf.h"
30 #include "parsekey.h"
31 #include "sendsync.h"
32
33 int fd_putchar(void *ctx, size_t count, void *c)
34 {
35         fwrite(c, sizeof(char), count, ctx);
36
37         return 0;
38 }
39
40 /**
41  *      sendkeysync - Send a key sync mail to our peers.
42  *      keys: The list of keys to send.
43  *
44  *      Takes a list of keys and sends out a keysync mail to all our peers.
45  */
46 int sendkeysync(struct openpgp_publickey *keys)
47 {
48         FILE                       *fd = NULL;
49         struct ll                  *cursite = NULL;
50         struct openpgp_packet_list *packets = NULL;
51         struct openpgp_packet_list *list_end = NULL;
52
53         if (config.syncsites != NULL &&
54                         (fd=popen(config.mta, "w")) != NULL) {
55                 fprintf(fd, "From: %s\n", config.adminemail);
56
57                 fprintf(fd, "To: ");
58                 for (cursite = config.syncsites; cursite != NULL;
59                                 cursite = cursite->next) {
60                         fprintf(fd, "%s", (char *) cursite->object);
61                         if (cursite->next != NULL) {
62                                 fprintf(fd, ", ");
63                         }
64                 }
65                 fprintf(fd, "\n");
66
67                 fprintf(fd, "Subject: incremental\n");
68                 fprintf(fd, "X-Keyserver-Sent: %s\n", config.thissite);
69                 fprintf(fd, "Precedence: list\n");
70                 fprintf(fd, "MIME-Version: 1.0\n");
71                 fprintf(fd, "Content-Type: application/pgp-keys\n\n");
72
73                 flatten_publickey(keys,
74                                 &packets,
75                                 &list_end);
76                 armor_openpgp_stream(fd_putchar,
77                                 fd,
78                                 packets);
79                 free_packet_list(packets);
80                 packets = NULL;
81
82                 pclose(fd);
83         } else return 0;
84
85         return 1;
86 }