No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / kuser / kdigest-commands.c
blob345f91dec8012b543369e08eec123104463e4955
1 #include <stdio.h>
2 #include <getarg.h>
3 #include <sl.h>
4 #include "kdigest-commands.h"
6 static int
7 digest_probe_wrap(int argc, char **argv)
9 struct digest_probe_options opt;
10 int ret;
11 int optidx = 0;
12 struct getargs args[] = {
13 { "realm", 0, arg_string, NULL, "Kerberos realm to communicate with", NULL },
14 { "help", 'h', arg_flag, NULL, NULL, NULL }
16 int help_flag = 0;
17 opt.realm_string = NULL;
18 args[0].value = &opt.realm_string;
19 args[1].value = &help_flag;
20 if(getarg(args, 2, argc, argv, &optidx))
21 goto usage;
22 if(argc - optidx > 0) {
23 fprintf(stderr, "Arguments given (%u) are more than expected (0).\n\n", argc - optidx);
24 goto usage;
26 if(help_flag)
27 goto usage;
28 ret = digest_probe(&opt, argc - optidx, argv + optidx);
29 return ret;
30 usage:
31 arg_printusage (args, 2, "digest-probe", "");
32 return 0;
35 static int
36 digest_server_init_wrap(int argc, char **argv)
38 struct digest_server_init_options opt;
39 int ret;
40 int optidx = 0;
41 struct getargs args[] = {
42 { "type", 0, arg_string, NULL, "digest type", NULL },
43 { "kerberos-realm", 0, arg_string, NULL, "", "realm" },
44 { "digest", 0, arg_string, NULL, "digest type to use in the algorithm", "digest-type" },
45 { "cb-type", 0, arg_string, NULL, "type of channel bindings", "type" },
46 { "cb-value", 0, arg_string, NULL, "value of channel bindings", "value" },
47 { "hostname", 0, arg_string, NULL, "hostname of the server", "hostname" },
48 { "realm", 0, arg_string, NULL, "Kerberos realm to communicate with", NULL },
49 { "help", 'h', arg_flag, NULL, NULL, NULL }
51 int help_flag = 0;
52 opt.type_string = "sasl";
53 opt.kerberos_realm_string = NULL;
54 opt.digest_string = NULL;
55 opt.cb_type_string = NULL;
56 opt.cb_value_string = NULL;
57 opt.hostname_string = NULL;
58 opt.realm_string = NULL;
59 args[0].value = &opt.type_string;
60 args[1].value = &opt.kerberos_realm_string;
61 args[2].value = &opt.digest_string;
62 args[3].value = &opt.cb_type_string;
63 args[4].value = &opt.cb_value_string;
64 args[5].value = &opt.hostname_string;
65 args[6].value = &opt.realm_string;
66 args[7].value = &help_flag;
67 if(getarg(args, 8, argc, argv, &optidx))
68 goto usage;
69 if(argc - optidx > 0) {
70 fprintf(stderr, "Arguments given (%u) are more than expected (0).\n\n", argc - optidx);
71 goto usage;
73 if(help_flag)
74 goto usage;
75 ret = digest_server_init(&opt, argc - optidx, argv + optidx);
76 return ret;
77 usage:
78 arg_printusage (args, 8, "digest-server-init", "");
79 return 0;
82 static int
83 digest_server_request_wrap(int argc, char **argv)
85 struct digest_server_request_options opt;
86 int ret;
87 int optidx = 0;
88 struct getargs args[] = {
89 { "type", 0, arg_string, NULL, "digest type", NULL },
90 { "kerberos-realm", 0, arg_string, NULL, "", "realm" },
91 { "username", 0, arg_string, NULL, "digest type", "name" },
92 { "server-nonce", 0, arg_string, NULL, "", "nonce" },
93 { "server-identifier", 0, arg_string, NULL, "", "nonce" },
94 { "client-nonce", 0, arg_string, NULL, "", "nonce" },
95 { "client-response", 0, arg_string, NULL, "", "response" },
96 { "opaque", 0, arg_string, NULL, "", "string" },
97 { "authentication-name", 0, arg_string, NULL, "", "name" },
98 { "realm", 0, arg_string, NULL, "", "realm" },
99 { "method", 0, arg_string, NULL, "", "method" },
100 { "uri", 0, arg_string, NULL, "", "uri" },
101 { "nounce-count", 0, arg_string, NULL, "", "count" },
102 { "qop", 0, arg_string, NULL, "", "qop" },
103 { "ccache", 0, arg_string, NULL, "Where the the credential cache is created when the KDC returns tickets", "ccache" },
104 { "help", 'h', arg_flag, NULL, NULL, NULL }
106 int help_flag = 0;
107 opt.type_string = "sasl";
108 opt.kerberos_realm_string = NULL;
109 opt.username_string = NULL;
110 opt.server_nonce_string = NULL;
111 opt.server_identifier_string = NULL;
112 opt.client_nonce_string = NULL;
113 opt.client_response_string = NULL;
114 opt.opaque_string = NULL;
115 opt.authentication_name_string = NULL;
116 opt.realm_string = NULL;
117 opt.method_string = NULL;
118 opt.uri_string = NULL;
119 opt.nounce_count_string = NULL;
120 opt.qop_string = NULL;
121 opt.ccache_string = NULL;
122 args[0].value = &opt.type_string;
123 args[1].value = &opt.kerberos_realm_string;
124 args[2].value = &opt.username_string;
125 args[3].value = &opt.server_nonce_string;
126 args[4].value = &opt.server_identifier_string;
127 args[5].value = &opt.client_nonce_string;
128 args[6].value = &opt.client_response_string;
129 args[7].value = &opt.opaque_string;
130 args[8].value = &opt.authentication_name_string;
131 args[9].value = &opt.realm_string;
132 args[10].value = &opt.method_string;
133 args[11].value = &opt.uri_string;
134 args[12].value = &opt.nounce_count_string;
135 args[13].value = &opt.qop_string;
136 args[14].value = &opt.ccache_string;
137 args[15].value = &help_flag;
138 if(getarg(args, 16, argc, argv, &optidx))
139 goto usage;
140 if(argc - optidx > 0) {
141 fprintf(stderr, "Arguments given (%u) are more than expected (0).\n\n", argc - optidx);
142 goto usage;
144 if(help_flag)
145 goto usage;
146 ret = digest_server_request(&opt, argc - optidx, argv + optidx);
147 return ret;
148 usage:
149 arg_printusage (args, 16, "digest-server-request", "");
150 return 0;
153 static int
154 digest_client_request_wrap(int argc, char **argv)
156 struct digest_client_request_options opt;
157 int ret;
158 int optidx = 0;
159 struct getargs args[] = {
160 { "type", 0, arg_string, NULL, "digest type", NULL },
161 { "username", 0, arg_string, NULL, "digest type", "name" },
162 { "password", 0, arg_string, NULL, NULL, "password" },
163 { "server-nonce", 0, arg_string, NULL, "", "nonce" },
164 { "server-identifier", 0, arg_string, NULL, "", "nonce" },
165 { "client-nonce", 0, arg_string, NULL, "", "nonce" },
166 { "opaque", 0, arg_string, NULL, "", "string" },
167 { "realm", 0, arg_string, NULL, "", "realm" },
168 { "method", 0, arg_string, NULL, "", "method" },
169 { "uri", 0, arg_string, NULL, "", "uri" },
170 { "nounce-count", 0, arg_string, NULL, "", "count" },
171 { "qop", 0, arg_string, NULL, "", "qop" },
172 { "help", 'h', arg_flag, NULL, NULL, NULL }
174 int help_flag = 0;
175 opt.type_string = "sasl";
176 opt.username_string = NULL;
177 opt.password_string = NULL;
178 opt.server_nonce_string = NULL;
179 opt.server_identifier_string = NULL;
180 opt.client_nonce_string = NULL;
181 opt.opaque_string = NULL;
182 opt.realm_string = NULL;
183 opt.method_string = NULL;
184 opt.uri_string = NULL;
185 opt.nounce_count_string = NULL;
186 opt.qop_string = NULL;
187 args[0].value = &opt.type_string;
188 args[1].value = &opt.username_string;
189 args[2].value = &opt.password_string;
190 args[3].value = &opt.server_nonce_string;
191 args[4].value = &opt.server_identifier_string;
192 args[5].value = &opt.client_nonce_string;
193 args[6].value = &opt.opaque_string;
194 args[7].value = &opt.realm_string;
195 args[8].value = &opt.method_string;
196 args[9].value = &opt.uri_string;
197 args[10].value = &opt.nounce_count_string;
198 args[11].value = &opt.qop_string;
199 args[12].value = &help_flag;
200 if(getarg(args, 13, argc, argv, &optidx))
201 goto usage;
202 if(argc - optidx > 0) {
203 fprintf(stderr, "Arguments given (%u) are more than expected (0).\n\n", argc - optidx);
204 goto usage;
206 if(help_flag)
207 goto usage;
208 ret = digest_client_request(&opt, argc - optidx, argv + optidx);
209 return ret;
210 usage:
211 arg_printusage (args, 13, "digest-client-request", "");
212 return 0;
215 static int
216 ntlm_server_init_wrap(int argc, char **argv)
218 struct ntlm_server_init_options opt;
219 int ret;
220 int optidx = 0;
221 struct getargs args[] = {
222 { "version", 0, arg_integer, NULL, "ntlm version", NULL },
223 { "kerberos-realm", 0, arg_string, NULL, "Kerberos realm to communicate with", NULL },
224 { "help", 'h', arg_flag, NULL, NULL, NULL }
226 int help_flag = 0;
227 opt.version_integer = 1;
228 opt.kerberos_realm_string = NULL;
229 args[0].value = &opt.version_integer;
230 args[1].value = &opt.kerberos_realm_string;
231 args[2].value = &help_flag;
232 if(getarg(args, 3, argc, argv, &optidx))
233 goto usage;
234 if(argc - optidx > 0) {
235 fprintf(stderr, "Arguments given (%u) are more than expected (0).\n\n", argc - optidx);
236 goto usage;
238 if(help_flag)
239 goto usage;
240 ret = ntlm_server_init(&opt, argc - optidx, argv + optidx);
241 return ret;
242 usage:
243 arg_printusage (args, 3, "ntlm-server-init", "");
244 return 0;
247 static int
248 help_wrap(int argc, char **argv)
250 int ret;
251 int optidx = 0;
252 struct getargs args[] = {
253 { "help", 'h', arg_flag, NULL, NULL, NULL }
255 int help_flag = 0;
256 args[0].value = &help_flag;
257 if(getarg(args, 1, argc, argv, &optidx))
258 goto usage;
259 if(argc - optidx > 1) {
260 fprintf(stderr, "Arguments given (%u) are more than expected (1).\n\n", argc - optidx);
261 goto usage;
263 if(argc - optidx < 0) {
264 fprintf(stderr, "Arguments given (%u) are less than expected (0).\n\n", argc - optidx);
265 goto usage;
267 if(help_flag)
268 goto usage;
269 ret = help(NULL, argc - optidx, argv + optidx);
270 return ret;
271 usage:
272 arg_printusage (args, 1, "help", "[command]");
273 return 0;
276 SL_cmd commands[] = {
277 { "digest-probe", digest_probe_wrap, "digest-probe", "probe what mech is allowed/supported for this server" },
279 { "digest-server-init", digest_server_init_wrap, "digest-server-init", "Sets up a digest context and return initial parameters" },
281 { "digest-server-request", digest_server_request_wrap, "digest-server-request", "Completes digest negotiation and return final parameters" },
283 { "digest-client-request", digest_client_request_wrap, "digest-client-request", "Client part of a digest exchange" },
285 { "ntlm-server-init", ntlm_server_init_wrap, "ntlm-server-init", "Sets up a digest context and return initial parameters" },
287 { "help", help_wrap, "help [command]", "Help! I need somebody." },
288 { "?" },
290 { NULL }