]> the.earth.li Git - onak.git/blob - splitkeys.c
Fix handling of other signature requirement
[onak.git] / splitkeys.c
1 /*
2  * splitkeys.c - Split a keyring into smaller chunks.
3  *
4  * Copyright 2003 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 <fcntl.h>
20 #include <stdio.h>
21 #include <sys/stat.h>
22 #include <sys/types.h>
23 #include <unistd.h>
24
25 #include "charfuncs.h"
26 #include "keystructs.h"
27 #include "mem.h"
28 #include "openpgp.h"
29 #include "parsekey.h"
30
31 int main(int argc, char *argv[])
32 {
33         struct openpgp_packet_list      *packets = NULL;
34         struct openpgp_packet_list      *list_end = NULL;
35         struct openpgp_packet_list      *tmp = NULL;
36         int                              maxkeys = 10000;
37         int                              outfd = -1;
38         int                              count = 0;
39         char                             splitfile[1024];
40
41         if (argc > 1) {
42                 maxkeys = atoi(argv[1]);
43                 if (maxkeys == 0) {
44                         fprintf(stderr,
45                                 "Couldn't parse %s as a number of keys!\n",
46                                 argv[1]);
47                         exit(EXIT_FAILURE);
48                 }
49         }
50
51         do {
52                 read_openpgp_stream(stdin_getchar, NULL,
53                                  &packets, maxkeys);
54                 if (packets != NULL) {
55                         list_end = packets;
56                         while (list_end->next != NULL) {
57                                 tmp = list_end;
58                                 list_end = list_end->next;
59                                 if (list_end->next == NULL &&
60                                         list_end->packet->tag ==
61                                                 OPENPGP_PACKET_PUBLICKEY) {
62                                         tmp->next = NULL;
63                                 }
64                         }
65                         if (tmp != NULL && tmp->next != NULL) {
66                                 list_end = NULL;
67                         }
68
69                         snprintf(splitfile, 1023, "splitfile-%d.pgp", count);
70                         outfd = open(splitfile, O_WRONLY | O_CREAT, 0664);
71                         write_openpgp_stream(file_putchar, &outfd,
72                                         packets);
73                         close(outfd);
74                         free_packet_list(packets);
75                         packets = list_end;
76                         count++;
77                 }
78         } while (packets != NULL);
79
80         return 0;
81 }