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