70c8d3efc3574d21942b7ac3c3d9c09a942dc0b0
[fides] / fides.c
1 #include <stdio.h>
2 #include <sysexits.h>
3
4 void help(FILE *out, const char *argv0) {
5         fprintf(out, "Usage: %s <command> [arguments]\n\n", argv0);
6         fprintf(out, "Available commands are:\n");
7         fprintf(out, "  init      Initialise fides, generate a public/private keypair.\n");
8         fprintf(out, "  version   Show version and copyright information.\n");
9         fprintf(out, "  help      Show this help message.\n");
10         fprintf(out, "  trust <keyid>\n");
11         fprintf(out, "            Trust allow/deny packets signed by the specified key.\n");
12         fprintf(out, "  distrust <keyid>\n");
13         fprintf(out, "            Distrust allow/deny packets signed by the specified key.\n");
14         fprintf(out, "  allow <keyid> <stuff ...>\n");
15         fprintf(out, "            Allow the entity identified by keyid some stuff.\n");
16         fprintf(out, "  deny <keyid> <stuff ...> \n");
17         fprintf(out, "            Deny the entity identified by keyid some stuff.\n");
18         fprintf(out, "  import [filename]\n");
19         fprintf(out, "            Import trust packets from file, or stdin if unspecified.\n");
20         fprintf(out, "  export [filename]\n");
21         fprintf(out, "            Export trust packets to file, or stdout if unspecified.\n"); 
22         fprintf(out, "  test <stuff ...>\n");
23         fprintf(out, "            Tell whether stuff is allowed or not, and why.\n");
24         fprintf(out, "  fsck      Verify the signature on all information collected.\n");
25 }
26
27 int version() {
28         fprintf(stdout, "fides version 0.1\n");
29         fprintf(stdout, "Copyright (c) 2008 Guus Sliepen <guus@tinc-vpn.org>\n\n");
30         fprintf(stdout, "This program is free software; you can redistribute it and/or modify\n"
31                         "it under the terms of the GNU General Public License as published by\n"
32                         "the Free Software Foundation; either version 2 of the License, or\n"
33                         "(at your option) any later version.\n");
34
35         return 0;
36 }
37
38 int init() {
39         // Generate a public/private keypair if it does not already exist
40         return 0;
41 }
42
43 int trust(int argc, char *argv[]) {
44         // Trust another key
45         return 0;
46 }
47
48 int distrust(int argc, char *argv[]) {
49         // Distrust another key
50         return 0;
51 }
52
53 int allow(int argc, char *argv[]) {
54         // Generate a certficate allowing something
55         return 0;
56 }
57
58 int deny(int argc, char *argv[]) {
59         // Generate a certificate denying something
60         return 0;
61 }
62
63 int import(int argc, char *argv[]) {
64         // Import certificates
65         return 0;
66 }
67
68 int export(int argc, char *argv[]) {
69         // Export certificates
70         return 0;
71 }
72
73 int test(int argc, char *argv[]) {
74         // Test something against all certificates
75         return 0;
76 }
77
78 int fsck() {
79         // Verify the integrity of all certificates
80         return 0;
81 }
82
83 main(int argc, char *argv[]) {
84         if(argc < 2) {
85                 help(stderr, argv[0]);
86                 return EX_USAGE;
87         }
88
89         if(!strcmp(argv[1], "help")) {
90                 help(stdout, argv[0]);
91                 return 0;
92         }
93
94         if(!strcmp(argv[1], "version"))
95                 return version();
96
97         if(!strcmp(argv[1], "init"))
98                 return init();
99
100         if(!strcmp(argv[1], "trust"))
101                 return trust(argc - 2, argv + 2);
102
103         if(!strcmp(argv[1], "distrust"))
104                 return distrust(argc - 2, argv + 2);
105
106         if(!strcmp(argv[1], "allow"))
107                 return allow(argc - 2, argv + 2);
108
109         if(!strcmp(argv[1], "deny"))
110                 return deny(argc - 2, argv + 2);
111
112         if(!strcmp(argv[1], "import"))
113                 return import(argc - 2, argv + 2);
114
115         if(!strcmp(argv[1], "export"))
116                 return export(argc - 2, argv + 2);
117
118         if(!strcmp(argv[1], "test"))
119                 return test(argc - 2, argv + 2);
120
121         if(!strcmp(argv[1], "fsck"))
122                 return fsck();
123
124         fprintf(stderr, "Unknown command '%s'\n", argv[1]);
125         return EX_USAGE;
126 }
127