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