File: sendsync.c

package info (click to toggle)
onak 0.4.1-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,096 kB
  • sloc: ansic: 9,703; perl: 277; sh: 217; makefile: 152; sql: 21
file content (86 lines) | stat: -rw-r--r-- 2,337 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * sendsync.c - Routines to send a key sync mail.
 *
 * Copyright 1999, 2002, 2005, 2011 Jonathan McDowell <noodles@earth.li>
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

#include "armor.h"
#include "keystructs.h"
#include "ll.h"
#include "mem.h"
#include "onak-conf.h"
#include "parsekey.h"
#include "sendsync.h"

int fd_putchar(void *ctx, size_t count, void *c)
{
	fwrite(c, sizeof(char), count, ctx);

	return 0;
}

/**
 *	sendkeysync - Send a key sync mail to our peers.
 *	keys: The list of keys to send.
 *
 *	Takes a list of keys and sends out a keysync mail to all our peers.
 */
int sendkeysync(struct openpgp_publickey *keys)
{
	FILE                       *fd = NULL;
	struct ll                  *cursite = NULL;
	struct openpgp_packet_list *packets = NULL;
	struct openpgp_packet_list *list_end = NULL;

	if (config.syncsites != NULL &&
			(fd=popen(config.mta, "w")) != NULL) {
		fprintf(fd, "From: %s\n", config.adminemail);

		fprintf(fd, "To: ");
		for (cursite = config.syncsites; cursite != NULL;
				cursite = cursite->next) {
			fprintf(fd, "%s", (char *) cursite->object);
			if (cursite->next != NULL) {
				fprintf(fd, ", ");
			}
		}
		fprintf(fd, "\n");

		fprintf(fd, "Subject: incremental\n");
		fprintf(fd, "X-Keyserver-Sent: %s\n", config.thissite);
		fprintf(fd, "Precedence: list\n");
		fprintf(fd, "MIME-Version: 1.0\n");
		fprintf(fd, "Content-Type: application/pgp-keys\n\n");

		flatten_publickey(keys,
				&packets,
				&list_end);
		armor_openpgp_stream(fd_putchar,
				fd,
				packets);
		free_packet_list(packets);
		packets = NULL;

		pclose(fd);
	} else return 0;

	return 1;
}