]> the.earth.li Git - onak.git/blob - sendsync.c
0.6.3 release
[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 size_t fd_putchar(void *ctx, size_t count, void *c)
33 {
34         return fwrite(c, sizeof(char), count, ctx);
35 }
36
37 /**
38  *      sendkeysync - Send a key sync mail to our peers.
39  *      keys: The list of keys to send.
40  *
41  *      Takes a list of keys and sends out a keysync mail to all our peers.
42  */
43 int sendkeysync(struct openpgp_publickey *keys)
44 {
45         FILE                       *fd = NULL;
46         struct ll                  *cursite = NULL;
47         struct openpgp_packet_list *packets = NULL;
48         struct openpgp_packet_list *list_end = NULL;
49
50         if (config.syncsites != NULL &&
51                         (fd=popen(config.mta, "w")) != NULL) {
52                 fprintf(fd, "From: %s\n", config.adminemail);
53
54                 fprintf(fd, "To: ");
55                 for (cursite = config.syncsites; cursite != NULL;
56                                 cursite = cursite->next) {
57                         fprintf(fd, "%s", (char *) cursite->object);
58                         if (cursite->next != NULL) {
59                                 fprintf(fd, ", ");
60                         }
61                 }
62                 fprintf(fd, "\n");
63
64                 fprintf(fd, "Subject: incremental\n");
65                 fprintf(fd, "X-Keyserver-Sent: %s\n", config.thissite);
66                 fprintf(fd, "Precedence: list\n");
67                 fprintf(fd, "MIME-Version: 1.0\n");
68                 fprintf(fd, "Content-Type: application/pgp-keys\n\n");
69
70                 flatten_publickey(keys,
71                                 &packets,
72                                 &list_end);
73                 armor_openpgp_stream(fd_putchar,
74                                 fd,
75                                 packets);
76                 free_packet_list(packets);
77                 packets = NULL;
78
79                 pclose(fd);
80         } else return 0;
81
82         return 1;
83 }