No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / lib / kadm5 / iprop-commands.c
blob3f4311edbe5b00ef55a663fd3a23395c79c53e81
1 #include <stdio.h>
2 #include <getarg.h>
3 #include <sl.h>
4 #include "iprop-commands.h"
6 static int
7 dump_wrap(int argc, char **argv)
9 struct dump_options opt;
10 int ret;
11 int optidx = 0;
12 struct getargs args[] = {
13 { "config-file", 'c', arg_string, NULL, "configuration file", "file" },
14 { "realm", 'r', arg_string, NULL, "realm", NULL },
15 { "help", 'h', arg_flag, NULL, NULL, NULL }
17 int help_flag = 0;
18 opt.config_file_string = NULL;
19 opt.realm_string = NULL;
20 args[0].value = &opt.config_file_string;
21 args[1].value = &opt.realm_string;
22 args[2].value = &help_flag;
23 if(getarg(args, 3, argc, argv, &optidx))
24 goto usage;
25 if(argc - optidx > 0) {
26 fprintf(stderr, "Arguments given (%u) are more than expected (0).\n\n", argc - optidx);
27 goto usage;
29 if(help_flag)
30 goto usage;
31 ret = iprop_dump(&opt, argc - optidx, argv + optidx);
32 return ret;
33 usage:
34 arg_printusage (args, 3, "dump", "");
35 return 0;
38 static int
39 truncate_wrap(int argc, char **argv)
41 struct truncate_options opt;
42 int ret;
43 int optidx = 0;
44 struct getargs args[] = {
45 { "config-file", 'c', arg_string, NULL, "configuration file", "file" },
46 { "realm", 'r', arg_string, NULL, "realm", NULL },
47 { "help", 'h', arg_flag, NULL, NULL, NULL }
49 int help_flag = 0;
50 opt.config_file_string = NULL;
51 opt.realm_string = NULL;
52 args[0].value = &opt.config_file_string;
53 args[1].value = &opt.realm_string;
54 args[2].value = &help_flag;
55 if(getarg(args, 3, argc, argv, &optidx))
56 goto usage;
57 if(argc - optidx > 0) {
58 fprintf(stderr, "Arguments given (%u) are more than expected (0).\n\n", argc - optidx);
59 goto usage;
61 if(help_flag)
62 goto usage;
63 ret = iprop_truncate(&opt, argc - optidx, argv + optidx);
64 return ret;
65 usage:
66 arg_printusage (args, 3, "truncate", "");
67 return 0;
70 static int
71 replay_wrap(int argc, char **argv)
73 struct replay_options opt;
74 int ret;
75 int optidx = 0;
76 struct getargs args[] = {
77 { "start-version", 0, arg_integer, NULL, "start replay with this version", "version-number" },
78 { "end-version", 0, arg_integer, NULL, "end replay with this version", "version-number" },
79 { "config-file", 'c', arg_string, NULL, "configuration file", "file" },
80 { "realm", 'r', arg_string, NULL, "realm", NULL },
81 { "help", 'h', arg_flag, NULL, NULL, NULL }
83 int help_flag = 0;
84 opt.start_version_integer = -1;
85 opt.end_version_integer = -1;
86 opt.config_file_string = NULL;
87 opt.realm_string = NULL;
88 args[0].value = &opt.start_version_integer;
89 args[1].value = &opt.end_version_integer;
90 args[2].value = &opt.config_file_string;
91 args[3].value = &opt.realm_string;
92 args[4].value = &help_flag;
93 if(getarg(args, 5, argc, argv, &optidx))
94 goto usage;
95 if(argc - optidx > 0) {
96 fprintf(stderr, "Arguments given (%u) are more than expected (0).\n\n", argc - optidx);
97 goto usage;
99 if(help_flag)
100 goto usage;
101 ret = iprop_replay(&opt, argc - optidx, argv + optidx);
102 return ret;
103 usage:
104 arg_printusage (args, 5, "replay", "");
105 return 0;
108 static int
109 last_version_wrap(int argc, char **argv)
111 struct last_version_options opt;
112 int ret;
113 int optidx = 0;
114 struct getargs args[] = {
115 { "config-file", 'c', arg_string, NULL, "configuration file", "file" },
116 { "realm", 'r', arg_string, NULL, "realm", NULL },
117 { "help", 'h', arg_flag, NULL, NULL, NULL }
119 int help_flag = 0;
120 opt.config_file_string = NULL;
121 opt.realm_string = NULL;
122 args[0].value = &opt.config_file_string;
123 args[1].value = &opt.realm_string;
124 args[2].value = &help_flag;
125 if(getarg(args, 3, argc, argv, &optidx))
126 goto usage;
127 if(argc - optidx > 0) {
128 fprintf(stderr, "Arguments given (%u) are more than expected (0).\n\n", argc - optidx);
129 goto usage;
131 if(help_flag)
132 goto usage;
133 ret = last_version(&opt, argc - optidx, argv + optidx);
134 return ret;
135 usage:
136 arg_printusage (args, 3, "last-version", "");
137 return 0;
140 static int
141 help_wrap(int argc, char **argv)
143 int ret;
144 int optidx = 0;
145 struct getargs args[] = {
146 { "help", 'h', arg_flag, NULL, NULL, NULL }
148 int help_flag = 0;
149 args[0].value = &help_flag;
150 if(getarg(args, 1, argc, argv, &optidx))
151 goto usage;
152 if(argc - optidx > 1) {
153 fprintf(stderr, "Arguments given (%u) are more than expected (1).\n\n", argc - optidx);
154 goto usage;
156 if(help_flag)
157 goto usage;
158 ret = help(NULL, argc - optidx, argv + optidx);
159 return ret;
160 usage:
161 arg_printusage (args, 1, "help", "command");
162 return 0;
165 SL_cmd commands[] = {
166 { "dump", dump_wrap, "dump", "Prints the iprop transaction log in text." },
168 { "truncate", truncate_wrap, "truncate", "Truncate the log, preserve the version number." },
170 { "replay", replay_wrap, "replay", "Replay the log on the database." },
172 { "last-version", last_version_wrap, "last-version", "Print the last version of the log-file." },
174 { "help", help_wrap, "help command", NULL },
176 { NULL }